method/enctype/formMethod/formEnctype properties should be limited to known values.
[WebKit-https.git] / LayoutTests / fast / dom / element-attribute-js-null.html
1 <html>
2 <head>
3     <style type="text/css">
4         .pass { color: green; }
5         .fail { color: red; }
6     </style>
7     <script>
8         function printOut(msg)
9         {
10             var console = document.getElementById("console");
11             var span = document.createElement('span');
12             span.innerHTML = msg + '<br>';
13             console.appendChild(span);
14         }
15
16         function resultStringifier(result)
17         {
18             if (result === "")
19                 return "<b>the empty string</b>";
20             else if (result === null)
21                 return "<b>null</b>";
22             else if (result === undefined)
23                 return "<b>undefined</b>";
24             return "the string '" + result + "'";
25         }
26
27         function nullTestElementAttribute(elementType, element, attr, expected)
28         {
29             var exceptionThrown;
30             try {
31                 element[attr] = null;
32             } catch (ec) {
33                 exceptionThrown = ec;
34             }
35             var result;
36             if (exceptionThrown) {
37                 if (expected === 'exception')
38                     result = "<span class='pass'>TEST SUCCEEDED:</span> Exception (" + exceptionThrown + ") was thrown as expected.";
39                 else
40                     result = "<span class='fail'>TEST FAILED:</span> An exception was thrown unexpectedly.";
41             } else {
42                 if (expected === 'exception')
43                     result = "<span class='fail'>TEST FAILED:</span> An exception should have been thrown.";
44                 else if (element[attr] === expected)
45                     result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
46                 else
47                     result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
48             }
49             result += " [tested " + elementType + "." + attr + "]";
50             printOut(result);
51         }
52
53         function runTests()
54         {
55             if (window.layoutTestController)
56                 layoutTestController.dumpAsText();
57
58             // Others to test:
59             //  Core DOM
60             //    Attr.value (expected: null)
61             //    CharacterData.data
62             //    ProcessingInstruction.data
63             //  Functions
64
65             var listing = [
66                 {
67                     type: 'Node',
68                     elementToUse: document.createElement('div'),
69                     attributes: [
70                         {name: 'nodeValue', expectedNull: null},
71                          // 'prefix' only works because this is an HTMLElement type node, if it were an
72                          // XML node (created using createElementNS()) this would throw an exception. We
73                          // should test this further as Firefox has a different behavior.
74                         {name: 'prefix', expectedNull: null},
75                         {name: 'textContent', expectedNull: ''}
76                     ]
77                 },
78                 {
79                     type: 'HTMLElement',
80                     elementToUse: document.createElement('div'),
81                     attributes: [
82                         {name: 'title', expectedNull: ''},
83                         {name: 'id', expectedNull: ''},
84                         {name: 'lang', expectedNull: ''},
85                         {name: 'dir', expectedNull: ''},
86                         {name: 'className', expectedNull: ''},
87                         {name: 'innerHTML', expectedNull: ''},
88                         {name: 'innerText', expectedNull: ''},
89                         // FIXME: TEST THESE
90                         // {name: 'outerHTML', expectedNull: ''},
91                         // {name: 'outerText', expectedNull: ''},
92                         {name: 'contentEditable', expectedNull: 'exception'}
93                     ]
94                 },
95                 {
96                     type: 'HTMLAnchorElement',
97                     elementToUse: document.createElement('a'),
98                     attributes: [
99                         {name: 'accessKey', expectedNull: ''},
100                         {name: 'charset', expectedNull: ''},
101                         {name: 'coords', expectedNull: ''},
102                         {name: 'href', expectedNull: ''},
103                         {name: 'hreflang', expectedNull: ''},
104                         {name: 'name', expectedNull: ''},
105                         {name: 'rel', expectedNull: ''},
106                         {name: 'rev', expectedNull: ''},
107                         {name: 'shape', expectedNull: ''},
108                         {name: 'target', expectedNull: ''},
109                         {name: 'type', expectedNull: ''}
110                     ]
111                 },
112                 {
113                     type: 'HTMLAppletElement',
114                     elementToUse: document.createElement('applet'),
115                     attributes: [
116                         {name: 'align', expectedNull: ''},
117                         {name: 'alt', expectedNull: ''},
118                         {name: 'archive', expectedNull: ''},
119                         {name: 'code', expectedNull: ''},
120                         {name: 'codeBase', expectedNull: ''},
121                         {name: 'height', expectedNull: ''},
122                         {name: 'hspace', expectedNull: ''},
123                         {name: 'name', expectedNull: ''},
124                         {name: 'object', expectedNull: ''},
125                         {name: 'vspace', expectedNull: ''},
126                         {name: 'width', expectedNull: ''}
127                     ]
128                 },
129                 {
130                     type: 'HTMLAreaElement',
131                     elementToUse: document.createElement('area'),
132                     attributes: [
133                         {name: 'accessKey', expectedNull: ''},
134                         {name: 'alt', expectedNull: ''},
135                         {name: 'coords', expectedNull: ''},
136                         {name: 'href', expectedNull: ''},
137                         {name: 'shape', expectedNull: ''},
138                         {name: 'target', expectedNull: ''}
139                     ]
140                 },
141                 {
142                     type: 'HTMLBaseElement',
143                     elementToUse: document.createElement('base'),
144                     attributes: [
145                         {name: 'href', expectedNull: ''},
146                         {name: 'target', expectedNull: ''}
147                     ]
148                 },
149                 {
150                     type: 'HTMLBaseFontElement',
151                     elementToUse: document.createElement('basefont'),
152                     attributes: [
153                         {name: 'color', expectedNull: ''},
154                         {name: 'face', expectedNull: ''}
155                     ]
156                 },
157                 {
158                     type: 'HTMLBlockquoteElement',
159                     elementToUse: document.createElement('blockquote'),
160                     attributes: [
161                         {name: 'cite', expectedNull: ''}
162                     ]
163                 },
164                 {
165                     type: 'HTMLBodyElement',
166                     elementToUse: document.createElement('body'),
167                     attributes: [
168                         {name: 'aLink', expectedNull: ''},
169                         {name: 'background', expectedNull: ''},
170                         {name: 'bgColor', expectedNull: ''},
171                         {name: 'link', expectedNull: ''},
172                         {name: 'text', expectedNull: ''},
173                         {name: 'vLink', expectedNull: ''}
174                     ]
175                 },
176                 {
177                     type: 'HTMLBRElement',
178                     elementToUse: document.createElement('br'),
179                     attributes: [
180                         {name: 'clear', expectedNull: ''}
181                     ]
182                 },
183                 {
184                     type: 'HTMLButtonElement',
185                     elementToUse: document.createElement('button'),
186                     attributes: [
187                         {name: 'accessKey', expectedNull: ''},
188                         {name: 'name', expectedNull: ''},
189                         {name: 'value', expectedNull: ''}
190                     ]
191                 },
192                 {
193                     type: 'HTMLDivElement',
194                     elementToUse: document.createElement('div'),
195                     attributes: [
196                         {name: 'align', expectedNull: ''}
197                     ]
198                 },
199
200                 // HTMLDListElement
201                 // NONE
202
203                 {
204                     type: 'HTMLEmbedElement',
205                     elementToUse: document.createElement('embed'),
206                     attributes: [
207                         {name: 'align', expectedNull: ''},
208                         {name: 'name', expectedNull: ''},
209                         {name: 'src', expectedNull: ''},
210                         {name: 'type', expectedNull: ''}
211                     ]
212                 },
213
214                 // HTMLFieldSetElement
215                 // NONE
216
217                 {
218                     type: 'HTMLFontElement',
219                     elementToUse: document.createElement('font'),
220                     attributes: [
221                         {name: 'color', expectedNull: ''},
222                         {name: 'face', expectedNull: ''},
223                         {name: 'size', expectedNull: ''}
224                     ]
225                 },
226                 {
227                     type: 'HTMLFormElement',
228                     elementToUse: document.createElement('form'),
229                     attributes: [
230                         {name: 'name', expectedNull: ''},
231                         {name: 'acceptCharset', expectedNull: ''},
232                         {name: 'action', expectedNull: ''},
233                         {name: 'encoding', expectedNull: 'application/x-www-form-urlencoded'},
234                         {name: 'enctype', expectedNull: 'application/x-www-form-urlencoded'},
235                         {name: 'method', expectedNull: 'get'},
236                         {name: 'target', expectedNull: ''}
237                     ]
238                 },
239                 {
240                     type: 'HTMLFrameElement',
241                     elementToUse: document.createElement('frame'),
242                     attributes: [
243                         {name: 'frameBorder', expectedNull: ''},
244                         {name: 'longDesc', expectedNull: ''},
245                         {name: 'marginHeight', expectedNull: ''},
246                         {name: 'marginWidth', expectedNull: ''},
247                         {name: 'name', expectedNull: ''},
248                         {name: 'scrolling', expectedNull: ''},
249                         {name: 'src', expectedNull: ''},
250                         {name: 'location', expectedNull: ''} // not a documented attribute
251                     ]
252                 },
253                 {
254                     type: 'HTMLFrameSetElement',
255                     elementToUse: document.createElement('frameset'),
256                     attributes: [
257                         {name: 'cols', expectedNull: ''},
258                         {name: 'rows', expectedNull: ''}
259                     ]
260                 },
261                 {
262                     type: 'HTMLHeadElement',
263                     elementToUse: document.createElement('head'),
264                     attributes: [
265                         {name: 'profile', expectedNull: ''}
266                     ]
267                 },
268                 {
269                     type: 'HTMLHeadingElement',
270                     // no need to test h2-h6
271                     elementToUse: document.createElement('h1'),
272                     attributes: [
273                         {name: 'align', expectedNull: ''}
274                     ]
275                 },
276                 {
277                     type: 'HTMLHRElement',
278                     elementToUse: document.createElement('hr'), // no need to test h2-h6
279                     attributes: [
280                         {name: 'align', expectedNull: ''},
281                         {name: 'size', expectedNull: ''},
282                         {name: 'width', expectedNull: ''}
283                     ]
284                 },
285                 {
286                     type: 'HTMLHtmlElement',
287                     elementToUse: document.createElement('html'),
288                     attributes: [
289                         {name: 'version', expectedNull: ''}
290                     ]
291                 },
292                 {
293                     type: 'HTMLIFrameElement',
294                     elementToUse: document.createElement('iframe'),
295                     attributes: [
296                         {name: 'align', expectedNull: ''},
297                         {name: 'frameBorder', expectedNull: ''},
298                         {name: 'height', expectedNull: ''},
299                         {name: 'longDesc', expectedNull: ''},
300                         {name: 'marginHeight', expectedNull: ''},
301                         {name: 'marginWidth', expectedNull: ''},
302                         {name: 'name', expectedNull: ''},
303                         {name: 'scrolling', expectedNull: ''},
304                         {name: 'src', expectedNull: ''},
305                         {name: 'width', expectedNull: ''}
306                     ]
307                 },
308                 {
309                     type: 'HTMLImageElement',
310                     elementToUse: document.createElement('img'),
311                     attributes: [
312                         {name: 'name', expectedNull: ''},
313                         {name: 'align', expectedNull: ''},
314                         {name: 'alt', expectedNull: ''},
315                         {name: 'border', expectedNull: ''},
316                         {name: 'longDesc', expectedNull: ''},
317                         {name: 'src', expectedNull: ''},
318                         {name: 'useMap', expectedNull: ''},
319                         {name: 'lowsrc', expectedNull: ''}
320                     ]
321                 },
322                 {
323                     type: 'HTMLInputElement',
324                     elementToUse: document.createElement('input'),
325                     attributes: [
326                         {name: 'accept', expectedNull: ''},
327                         {name: 'accessKey', expectedNull: ''},
328                         {name: 'align', expectedNull: ''},
329                         {name: 'alt', expectedNull: ''},
330                         {name: 'defaultValue', expectedNull: ''},
331                         {name: 'name', expectedNull: ''},
332                         {name: 'src', expectedNull: ''},
333                         {name: 'type', expectedNull: 'text'},
334                         {name: 'useMap', expectedNull: ''},
335                         {name: 'value', expectedNull: ''},
336                     ]
337                 },
338                 {
339                     type: 'HTMLIsIndexElement',
340                     elementToUse: document.createElement('isindex'),
341                     attributes: [
342                         {name: 'prompt', expectedNull: ''}
343                     ]
344                 },
345                 {
346                     type: 'HTMLLabelElement',
347                     elementToUse: document.createElement('label'),
348                     attributes: [
349                         {name: 'accessKey', expectedNull: ''},
350                         {name: 'htmlFor', expectedNull: ''}
351                     ]
352                 },
353                 {
354                     type: 'HTMLLegendElement',
355                     elementToUse: document.createElement('legend'),
356                     attributes: [
357                         {name: 'accessKey', expectedNull: ''},
358                         {name: 'align', expectedNull: ''}
359                     ]
360                 },
361                 {
362                     type: 'HTMLLIElement',
363                     elementToUse: document.createElement('li'),
364                     attributes: [
365                         {name: 'type', expectedNull: ''}
366                     ]
367                 },
368                 {
369                     type: 'HTMLLinkElement',
370                     elementToUse: document.createElement('link'),
371                     attributes: [
372                         {name: 'charset', expectedNull: ''},
373                         {name: 'href', expectedNull: ''},
374                         {name: 'hreflang', expectedNull: ''},
375                         {name: 'media', expectedNull: ''},
376                         {name: 'rel', expectedNull: ''},
377                         {name: 'rev', expectedNull: ''},
378                         {name: 'target', expectedNull: ''},
379                         {name: 'type', expectedNull: ''}
380                     ]
381                 },
382                 {
383                     type: 'HTMLMapElement',
384                     elementToUse: document.createElement('map'),
385                     attributes: [
386                         {name: 'name', expectedNull: ''}
387                     ]
388                 },
389
390                 // HTMLMenuElement
391                 // NONE
392
393                 {
394                     type: 'HTMLMetaElement',
395                     elementToUse: document.createElement('meta'),
396                     attributes: [
397                         {name: 'content', expectedNull: ''},
398                         {name: 'httpEquiv', expectedNull: ''},
399                         {name: 'name', expectedNull: ''},
400                         {name: 'scheme', expectedNull: ''}
401                     ]
402                 },
403                 {
404                     type: 'HTMLModElement',
405                     elementToUse: document.createElement('ins'), // same as 'del'
406                     attributes: [
407                         {name: 'cite', expectedNull: ''},
408                         {name: 'dateTime', expectedNull: ''}
409                     ]
410                 },
411                 {
412                     type: 'HTMLObjectElement',
413                     elementToUse: document.createElement('object'),
414                     attributes: [
415                         {name: 'code', expectedNull: ''},
416                         {name: 'align', expectedNull: ''},
417                         {name: 'archive', expectedNull: ''},
418                         {name: 'border', expectedNull: ''},
419                         {name: 'codeBase', expectedNull: ''},
420                         {name: 'codeType', expectedNull: ''},
421                         {name: 'data', expectedNull: ''},
422                         {name: 'height', expectedNull: ''},
423                         {name: 'name', expectedNull: ''},
424                         {name: 'standby', expectedNull: ''},
425                         {name: 'type', expectedNull: ''},
426                         {name: 'useMap', expectedNull: ''},
427                         {name: 'width', expectedNull: ''}
428                     ]
429                 },
430                 {
431                     type: 'HTMLOListElement',
432                     elementToUse: document.createElement('ol'),
433                     attributes: [
434                         {name: 'type', expectedNull: ''}
435                     ]
436                 },
437                 {
438                     type: 'HTMLOptGroupElement',
439                     elementToUse: document.createElement('optgroup'),
440                     attributes: [
441                         {name: 'label', expectedNull: ''}
442                     ]
443                 },
444                 {
445                     type: 'HTMLOptionElement',
446                     elementToUse: document.createElement('option'),
447                     attributes: [
448                         {name: 'text', expectedNull: ''},
449                         {name: 'label', expectedNull: ''},
450                         {name: 'value', expectedNull: ''}
451                     ]
452                 },
453                 {
454                     type: 'HTMLParagraphElement',
455                     elementToUse: document.createElement('p'),
456                     attributes: [
457                         {name: 'align', expectedNull: ''}
458                     ]
459                 },
460                 {
461                     type: 'HTMLParamElement',
462                     elementToUse: document.createElement('param'),
463                     attributes: [
464                         {name: 'name', expectedNull: ''},
465                         {name: 'type', expectedNull: ''},
466                         {name: 'value', expectedNull: ''},
467                         {name: 'valueType', expectedNull: ''}
468                     ]
469                 },
470
471                 // HTMLPreElement
472                 // NONE
473
474                 {
475                     type: 'HTMLQuoteElement',
476                     elementToUse: document.createElement('q'),
477                     attributes: [
478                         {name: 'cite', expectedNull: ''}
479                     ]
480                 },
481                 {
482                     type: 'HTMLScriptElement',
483                     elementToUse: document.createElement('script'),
484                     attributes: [
485                         {name: 'text', expectedNull: ''},
486                         {name: 'htmlFor', expectedNull: ''},
487                         {name: 'event', expectedNull: ''},
488                         {name: 'charset', expectedNull: ''},
489                         {name: 'src', expectedNull: ''},
490                         {name: 'type', expectedNull: ''}
491                     ]
492                 },
493                 {
494                     type: 'HTMLSelectElement',
495                     elementToUse: document.createElement('select'),
496                     attributes: [
497                         {name: 'value', expectedNull: ''},
498                         {name: 'name', expectedNull: ''}
499                     ]
500                 },
501                 {
502                     type: 'HTMLStyleElement',
503                     elementToUse: document.createElement('style'),
504                     attributes: [
505                         {name: 'media', expectedNull: ''},
506                         {name: 'type', expectedNull: ''}
507                     ]
508                 },
509                 {
510                     type: 'HTMLTableCaptionElement',
511                     elementToUse: document.createElement('caption'),
512                     attributes: [
513                         {name: 'align', expectedNull: ''}
514                     ]
515                 },
516                 {
517                     type: 'HTMLTableCellElement',
518                     elementToUse: document.createElement('td'),
519                     attributes: [
520                         {name: 'abbr', expectedNull: ''},
521                         {name: 'align', expectedNull: ''},
522                         {name: 'axis', expectedNull: ''},
523                         {name: 'bgColor', expectedNull: ''},
524                         {name: 'ch', expectedNull: ''},
525                         {name: 'chOff', expectedNull: ''},
526                         {name: 'headers', expectedNull: ''},
527                         {name: 'height', expectedNull: ''},
528                         {name: 'scope', expectedNull: ''},
529                         {name: 'vAlign', expectedNull: ''},
530                         {name: 'width', expectedNull: ''}
531                     ]
532                 },
533                 {
534                     type: 'HTMLTableColElement',
535                     elementToUse: document.createElement('col'),
536                     attributes: [
537                         {name: 'align', expectedNull: ''},
538                         {name: 'ch', expectedNull: ''},
539                         {name: 'chOff', expectedNull: ''},
540                         {name: 'vAlign', expectedNull: ''},
541                         {name: 'width', expectedNull: ''}
542                     ]
543                 },
544                 {
545                     type: 'HTMLTableElement',
546                     elementToUse: document.createElement('table'),
547                     attributes: [
548                         {name: 'align', expectedNull: ''},
549                         {name: 'bgColor', expectedNull: ''},
550                         {name: 'border', expectedNull: ''},
551                         {name: 'cellPadding', expectedNull: ''},
552                         {name: 'cellSpacing', expectedNull: ''},
553                         {name: 'frame', expectedNull: ''},
554                         {name: 'rules', expectedNull: ''},
555                         {name: 'summary', expectedNull: ''},
556                         {name: 'width', expectedNull: ''}
557                     ]
558                 },
559                 {
560                     type: 'HTMLTableRowElement',
561                     elementToUse: document.createElement('tr'),
562                     attributes: [
563                         {name: 'align', expectedNull: ''},
564                         {name: 'bgColor', expectedNull: ''},
565                         {name: 'ch', expectedNull: ''},
566                         {name: 'chOff', expectedNull: ''},
567                         {name: 'vAlign', expectedNull: ''}
568                     ]
569                 },
570                 {
571                     type: 'HTMLTableSectionElement',
572                     elementToUse: document.createElement('tbody'),
573                     attributes: [
574                         {name: 'align', expectedNull: ''},
575                         {name: 'ch', expectedNull: ''},
576                         {name: 'chOff', expectedNull: ''},
577                         {name: 'vAlign', expectedNull: ''}
578                     ]
579                 },
580                 {
581                     type: 'HTMLTextAreaElement',
582                     elementToUse: document.createElement('textarea'),
583                     attributes: [
584                         {name: 'defaultValue', expectedNull: ''},
585                         {name: 'accessKey', expectedNull: ''},
586                         {name: 'name', expectedNull: ''},
587                         {name: 'value', expectedNull: ''}
588                     ]
589                 },
590                 {
591                     type: 'HTMLTitleElement',
592                     elementToUse: document.createElement('title'),
593                     attributes: [
594                         {name: 'text', expectedNull: ''}
595                     ]
596                 },
597                 {
598                     type: 'HTMLUListElement',
599                     elementToUse: document.createElement('ul'),
600                     attributes: [
601                         {name: 'type', expectedNull: ''}
602                     ]
603                 }
604             ];
605
606             for (element in listing) {
607                 var type = listing[element].type;
608                 var elementToUse = listing[element].elementToUse;
609                 var attrs = listing[element].attributes;
610                 for (attr in attrs) {
611                     nullTestElementAttribute(type, elementToUse, attrs[attr].name, attrs[attr].expectedNull);
612                 }
613                 printOut('');
614             }
615         }
616     </script>
617 </head>
618 <body onload="runTests()">
619     <p>This test setting various attributes of a elements to JavaScript null.</p>
620     <div id="console"></div>
621 </body>
622 </html>