Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / element-attribute-js-null.html
blob5253ada27557bcb80bc3e1d3ae74a88ae0bf3e68
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)
10 var console = document.getElementById("console");
11 var span = document.createElement('span');
12 span.innerHTML = msg + '<br>';
13 console.appendChild(span);
16 function resultStringifier(result)
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 + "'";
27 function resolve(url)
29 var a = document.createElement('a');
30 a.href = url;
31 return a.href;
34 function nullTestElementAttribute(elementType, element, attr, expected, isUrl)
36 var exceptionThrown;
37 try {
38 element[attr] = null;
39 } catch (ec) {
40 exceptionThrown = ec;
42 var result;
43 if (exceptionThrown) {
44 if (expected === 'exception')
45 result = "<span class='pass'>TEST SUCCEEDED:</span> Exception (" + exceptionThrown + ") was thrown as expected.";
46 else
47 result = "<span class='fail'>TEST FAILED:</span> An exception was thrown unexpectedly.";
48 } else {
49 if (expected === 'exception')
50 result = "<span class='fail'>TEST FAILED:</span> An exception should have been thrown.";
51 else if (isUrl && element[attr] === resolve(expected))
52 result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + " resolved as a URL.";
53 else if (!isUrl && element[attr] === expected)
54 result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
55 else
56 result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
58 result += " [tested " + elementType + "." + attr + "]";
59 printOut(result);
62 function runTests()
64 if (window.testRunner)
65 testRunner.dumpAsText();
67 // Others to test:
68 // Core DOM
69 // Attr.value (expected: null)
70 // CharacterData.data
71 // ProcessingInstruction.data
72 // Functions
74 var listing = [
76 type: 'Node',
77 elementToUse: document.createElement('div'),
78 attributes: [
79 {name: 'nodeValue', expectedNull: null},
80 {name: 'textContent', expectedNull: ''}
84 type: 'Element',
85 elementToUse: document.createElementNS('http://example.com/', 'example'),
86 attributes: [
87 {name: 'id', expectedNull: 'null'},
88 {name: 'className', expectedNull: 'null'},
89 {name: 'innerHTML', expectedNull: ''},
90 {name: 'outerHTML', expectedNull: 'exception'}
94 type: 'HTMLElement',
95 elementToUse: document.createElement('abbr'),
96 attributes: [
97 {name: 'accessKey', expectedNull: 'null'},
98 {name: 'title', expectedNull: 'null'},
99 {name: 'lang', expectedNull: 'null'},
100 {name: 'dir', expectedNull: ''},
101 {name: 'innerText', expectedNull: ''},
102 {name: 'outerText', expectedNull: 'exception'},
103 {name: 'contentEditable', expectedNull: 'exception'}
107 type: 'HTMLAnchorElement',
108 elementToUse: document.createElement('a'),
109 attributes: [
110 {name: 'charset', expectedNull: 'null'},
111 {name: 'coords', expectedNull: 'null'},
112 {name: 'download', expectedNull: 'null'},
113 {name: 'href', expectedNull: 'null', isUrl: true},
114 {name: 'hreflang', expectedNull: 'null'},
115 {name: 'name', expectedNull: 'null'},
116 {name: 'ping', expectedNull: 'null'},
117 {name: 'rel', expectedNull: 'null'},
118 {name: 'rev', expectedNull: 'null'},
119 {name: 'shape', expectedNull: 'null'},
120 {name: 'target', expectedNull: 'null'},
121 {name: 'type', expectedNull: 'null'}
125 type: 'HTMLAreaElement',
126 elementToUse: document.createElement('area'),
127 attributes: [
128 {name: 'alt', expectedNull: 'null'},
129 {name: 'coords', expectedNull: 'null'},
130 {name: 'href', expectedNull: 'null', isUrl: true},
131 {name: 'ping', expectedNull: 'null'},
132 {name: 'shape', expectedNull: 'null'},
133 {name: 'target', expectedNull: 'null'}
137 type: 'HTMLAudioElement',
138 elementToUse: document.createElement('audio'),
139 attributes: [
140 {name: 'mediaGroup', expectedNull: 'null'},
141 {name: 'preload', expectedNull: 'auto'},
142 {name: 'src', expectedNull: 'null', isUrl: true}
146 type: 'HTMLBaseElement',
147 elementToUse: document.createElement('base'),
148 attributes: [
149 {name: 'href', expectedNull: 'null', isUrl: true},
150 {name: 'target', expectedNull: 'null'}
154 type: 'HTMLBlockquoteElement',
155 elementToUse: document.createElement('blockquote'),
156 attributes: [
157 {name: 'cite', expectedNull: 'null', isUrl: true}
161 type: 'HTMLBodyElement',
162 elementToUse: document.createElement('body'),
163 attributes: [
164 {name: 'aLink', expectedNull: ''},
165 {name: 'background', expectedNull: 'null'},
166 {name: 'bgColor', expectedNull: ''},
167 {name: 'link', expectedNull: ''},
168 {name: 'text', expectedNull: ''},
169 {name: 'vLink', expectedNull: ''}
173 type: 'HTMLBRElement',
174 elementToUse: document.createElement('br'),
175 attributes: [
176 {name: 'clear', expectedNull: 'null'}
180 type: 'HTMLButtonElement',
181 elementToUse: document.createElement('button'),
182 attributes: [
183 {name: 'formAction', expectedNull: 'null', isUrl: true},
184 {name: 'formEnctype', expectedNull: 'application/x-www-form-urlencoded'},
185 {name: 'formMethod', expectedNull: 'get'},
186 {name: 'formTarget', expectedNull: 'null'},
187 {name: 'name', expectedNull: 'null'},
188 {name: 'type', expectedNull: 'submit'},
189 {name: 'value', expectedNull: 'null'}
193 type: 'HTMLDivElement',
194 elementToUse: document.createElement('div'),
195 attributes: [
196 {name: 'align', expectedNull: 'null'}
200 // HTMLDListElement
201 // NONE
204 type: 'HTMLEmbedElement',
205 elementToUse: document.createElement('embed'),
206 attributes: [
207 {name: 'align', expectedNull: 'null'},
208 {name: 'height', expectedNull: 'null'},
209 {name: 'name', expectedNull: 'null'},
210 {name: 'src', expectedNull: 'null', isUrl: true},
211 {name: 'type', expectedNull: 'null'},
212 {name: 'width', expectedNull: 'null'}
216 type: 'HTMLFieldSetElement',
217 elementToUse: document.createElement('fieldset'),
218 attributes: [
219 {name: 'name', expectedNull: 'null'}
223 type: 'HTMLFontElement',
224 elementToUse: document.createElement('font'),
225 attributes: [
226 {name: 'color', expectedNull: ''},
227 {name: 'face', expectedNull: 'null'},
228 {name: 'size', expectedNull: 'null'}
232 type: 'HTMLFormElement',
233 elementToUse: document.createElement('form'),
234 attributes: [
235 {name: 'acceptCharset', expectedNull: 'null'},
236 {name: 'action', expectedNull: 'null', isUrl: true},
237 {name: 'autocomplete', expectedNull: 'on'},
238 {name: 'enctype', expectedNull: 'application/x-www-form-urlencoded'},
239 {name: 'encoding', expectedNull: 'application/x-www-form-urlencoded'},
240 {name: 'method', expectedNull: 'get'},
241 {name: 'name', expectedNull: 'null'},
242 {name: 'target', expectedNull: 'null'}
246 type: 'HTMLFrameElement',
247 elementToUse: document.createElement('frame'),
248 attributes: [
249 {name: 'frameBorder', expectedNull: 'null'},
250 {name: 'longDesc', expectedNull: 'null', isUrl: true},
251 {name: 'marginHeight', expectedNull: ''},
252 {name: 'marginWidth', expectedNull: ''},
253 {name: 'name', expectedNull: 'null'},
254 {name: 'scrolling', expectedNull: 'null'},
255 {name: 'src', expectedNull: 'null', isUrl: true}
259 type: 'HTMLFrameSetElement',
260 elementToUse: document.createElement('frameset'),
261 attributes: [
262 {name: 'cols', expectedNull: 'null'},
263 {name: 'rows', expectedNull: 'null'}
267 type: 'HTMLHeadingElement',
268 // no need to test h2-h6
269 elementToUse: document.createElement('h1'),
270 attributes: [
271 {name: 'align', expectedNull: 'null'}
275 type: 'HTMLHRElement',
276 elementToUse: document.createElement('hr'),
277 attributes: [
278 {name: 'align', expectedNull: 'null'},
279 {name: 'color', expectedNull: 'null'},
280 {name: 'size', expectedNull: 'null'},
281 {name: 'width', expectedNull: 'null'}
285 type: 'HTMLHtmlElement',
286 elementToUse: document.createElement('html'),
287 attributes: [
288 {name: 'version', expectedNull: 'null'}
292 type: 'HTMLIFrameElement',
293 elementToUse: document.createElement('iframe'),
294 attributes: [
295 {name: 'align', expectedNull: 'null'},
296 {name: 'frameBorder', expectedNull: 'null'},
297 {name: 'height', expectedNull: 'null'},
298 {name: 'longDesc', expectedNull: 'null', isUrl: true},
299 {name: 'marginHeight', expectedNull: ''},
300 {name: 'marginWidth', expectedNull: ''},
301 {name: 'name', expectedNull: 'null'},
302 {name: 'scrolling', expectedNull: 'null'},
303 {name: 'src', expectedNull: 'null', isUrl: true},
304 {name: 'srcdoc', expectedNull: 'null'},
305 {name: 'width', expectedNull: 'null'}
309 type: 'HTMLImageElement',
310 elementToUse: document.createElement('img'),
311 attributes: [
312 {name: 'align', expectedNull: 'null'},
313 {name: 'alt', expectedNull: 'null'},
314 {name: 'border', expectedNull: ''},
315 {name: 'crossOrigin', expectedNull: null},
316 {name: 'longDesc', expectedNull: 'null', isUrl: true},
317 {name: 'lowsrc', expectedNull: 'null', isUrl: true},
318 {name: 'name', expectedNull: 'null'},
319 {name: 'src', expectedNull: 'null', isUrl: true},
320 {name: 'srcset', expectedNull: 'null'},
321 {name: 'useMap', expectedNull: 'null'}
325 type: 'HTMLInputElement',
326 elementToUse: document.createElement('input'),
327 attributes: [
328 {name: 'accept', expectedNull: 'null'},
329 {name: 'align', expectedNull: 'null'},
330 {name: 'alt', expectedNull: 'null'},
331 {name: 'autocomplete', expectedNull: 'null'},
332 {name: 'defaultValue', expectedNull: 'null'},
333 {name: 'dirName', expectedNull: 'null'},
334 {name: 'formAction', expectedNull: 'null', isUrl: true},
335 {name: 'formEnctype', expectedNull: 'application/x-www-form-urlencoded'},
336 {name: 'formMethod', expectedNull: 'get'},
337 {name: 'formTarget', expectedNull: 'null'},
338 {name: 'max', expectedNull: 'null'},
339 {name: 'min', expectedNull: 'null'},
340 {name: 'name', expectedNull: 'null'},
341 {name: 'pattern', expectedNull: 'null'},
342 {name: 'placeholder', expectedNull: 'null'},
343 {name: 'src', expectedNull: 'null', isUrl: true},
344 {name: 'step', expectedNull: 'null'},
345 {name: 'type', expectedNull: 'text'},
346 {name: 'useMap', expectedNull: 'null'}
349 // [TreatNullAs=NullString] is not identical to [TreatNullAs=EmptyString] because
350 // null and empty string can be distinguished. A side-effect is that setting
351 // HTMLInputElement.value to null does clear the old value. This would be fixed by
352 // using [TreatNullAs=EmptyString], but until then test value separately to avoid
353 // interference from the defaultValue test.
355 type: 'HTMLInputElement',
356 elementToUse: document.createElement('input'),
357 attributes: [
358 {name: 'value', expectedNull: ''}
362 type: 'HTMLKeygenElement',
363 elementToUse: document.createElement('keygen'),
364 attributes: [
365 {name: 'challenge', expectedNull: 'null'},
366 {name: 'keytype', expectedNull: ''},
367 {name: 'name', expectedNull: 'null'}
371 type: 'HTMLLabelElement',
372 elementToUse: document.createElement('label'),
373 attributes: [
374 {name: 'htmlFor', expectedNull: 'null'}
378 type: 'HTMLLegendElement',
379 elementToUse: document.createElement('legend'),
380 attributes: [
381 {name: 'align', expectedNull: 'null'}
385 type: 'HTMLLIElement',
386 elementToUse: document.createElement('li'),
387 attributes: [
388 {name: 'type', expectedNull: 'null'}
392 type: 'HTMLLinkElement',
393 elementToUse: document.createElement('link'),
394 attributes: [
395 {name: 'charset', expectedNull: 'null'},
396 {name: 'href', expectedNull: 'null', isUrl: true},
397 {name: 'hreflang', expectedNull: 'null'},
398 {name: 'media', expectedNull: 'null'},
399 {name: 'rel', expectedNull: 'null'},
400 {name: 'rev', expectedNull: 'null'},
401 {name: 'target', expectedNull: 'null'},
402 {name: 'type', expectedNull: 'null'}
406 type: 'HTMLMapElement',
407 elementToUse: document.createElement('map'),
408 attributes: [
409 {name: 'name', expectedNull: 'null'}
413 type: 'HTMLMarqueeElement',
414 elementToUse: document.createElement('marquee'),
415 attributes: [
416 {name: 'behavior', expectedNull: 'null'},
417 {name: 'bgColor', expectedNull: 'null'},
418 {name: 'direction', expectedNull: 'null'},
419 {name: 'height', expectedNull: 'null'},
420 {name: 'width', expectedNull: 'null'}
424 // HTMLMenuElement
425 // NONE
428 type: 'HTMLMetaElement',
429 elementToUse: document.createElement('meta'),
430 attributes: [
431 {name: 'content', expectedNull: 'null'},
432 {name: 'httpEquiv', expectedNull: 'null'},
433 {name: 'name', expectedNull: 'null'},
434 {name: 'scheme', expectedNull: 'null'}
438 type: 'HTMLModElement',
439 elementToUse: document.createElement('ins'), // same as 'del'
440 attributes: [
441 {name: 'cite', expectedNull: 'null', isUrl: true},
442 {name: 'dateTime', expectedNull: 'null'}
446 type: 'HTMLObjectElement',
447 elementToUse: document.createElement('object'),
448 attributes: [
449 {name: 'code', expectedNull: 'null'},
450 {name: 'align', expectedNull: 'null'},
451 {name: 'archive', expectedNull: 'null'},
452 {name: 'border', expectedNull: ''},
453 {name: 'codeBase', expectedNull: 'null', isUrl: true},
454 {name: 'codeType', expectedNull: 'null'},
455 {name: 'data', expectedNull: 'null', isUrl: true},
456 {name: 'height', expectedNull: 'null'},
457 {name: 'name', expectedNull: 'null'},
458 {name: 'standby', expectedNull: 'null'},
459 {name: 'type', expectedNull: 'null'},
460 {name: 'useMap', expectedNull: 'null'},
461 {name: 'width', expectedNull: 'null'}
465 type: 'HTMLOListElement',
466 elementToUse: document.createElement('ol'),
467 attributes: [
468 {name: 'type', expectedNull: 'null'}
472 type: 'HTMLOptGroupElement',
473 elementToUse: document.createElement('optgroup'),
474 attributes: [
475 {name: 'label', expectedNull: 'null'}
479 type: 'HTMLOptionElement',
480 elementToUse: document.createElement('option'),
481 attributes: [
482 {name: 'text', expectedNull: 'null'},
483 {name: 'label', expectedNull: 'null'},
484 {name: 'value', expectedNull: 'null'}
488 type: 'HTMLOutputElement',
489 elementToUse: document.createElement('output'),
490 attributes: [
491 {name: 'name', expectedNull: 'null'},
492 {name: 'defaultValue', expectedNull: 'null'},
493 {name: 'value', expectedNull: 'null'}
497 type: 'HTMLParagraphElement',
498 elementToUse: document.createElement('p'),
499 attributes: [
500 {name: 'align', expectedNull: 'null'}
504 type: 'HTMLParamElement',
505 elementToUse: document.createElement('param'),
506 attributes: [
507 {name: 'name', expectedNull: 'null'},
508 {name: 'type', expectedNull: 'null'},
509 {name: 'value', expectedNull: 'null'},
510 {name: 'valueType', expectedNull: 'null'}
514 // HTMLPreElement
515 // NONE
518 type: 'HTMLQuoteElement',
519 elementToUse: document.createElement('q'),
520 attributes: [
521 {name: 'cite', expectedNull: 'null', isUrl:true}
525 type: 'HTMLScriptElement',
526 elementToUse: document.createElement('script'),
527 attributes: [
528 {name: 'text', expectedNull: 'null'},
529 {name: 'htmlFor', expectedNull: 'null'},
530 {name: 'event', expectedNull: 'null'},
531 {name: 'charset', expectedNull: 'null'},
532 {name: 'src', expectedNull: 'null', isUrl: true},
533 {name: 'type', expectedNull: 'null'},
534 {name: 'crossOrigin', expectedNull: null},
535 {name: 'nonce', expectedNull: 'null'}
539 type: 'HTMLSelectElement',
540 elementToUse: document.createElement('select'),
541 attributes: [
542 {name: 'value', expectedNull: ''},
543 {name: 'name', expectedNull: 'null'}
547 type: 'HTMLSourceElement',
548 elementToUse: document.createElement('source'),
549 attributes: [
550 {name: 'src', expectedNull: 'null', isUrl: true},
551 {name: 'type', expectedNull: 'null'}
555 type: 'HTMLStyleElement',
556 elementToUse: document.createElement('style'),
557 attributes: [
558 {name: 'media', expectedNull: 'null'},
559 {name: 'type', expectedNull: 'null'}
563 type: 'HTMLTableCaptionElement',
564 elementToUse: document.createElement('caption'),
565 attributes: [
566 {name: 'align', expectedNull: 'null'}
570 type: 'HTMLTableCellElement',
571 elementToUse: document.createElement('td'),
572 attributes: [
573 {name: 'abbr', expectedNull: 'null'},
574 {name: 'align', expectedNull: 'null'},
575 {name: 'axis', expectedNull: 'null'},
576 {name: 'bgColor', expectedNull: ''},
577 {name: 'ch', expectedNull: 'null'},
578 {name: 'chOff', expectedNull: 'null'},
579 {name: 'headers', expectedNull: ''},
580 {name: 'height', expectedNull: 'null'},
581 {name: 'scope', expectedNull: 'null'},
582 {name: 'vAlign', expectedNull: 'null'},
583 {name: 'width', expectedNull: 'null'}
587 type: 'HTMLTableColElement',
588 elementToUse: document.createElement('col'),
589 attributes: [
590 {name: 'align', expectedNull: 'null'},
591 {name: 'ch', expectedNull: 'null'},
592 {name: 'chOff', expectedNull: 'null'},
593 {name: 'vAlign', expectedNull: 'null'},
594 {name: 'width', expectedNull: 'null'}
598 type: 'HTMLTableElement',
599 elementToUse: document.createElement('table'),
600 attributes: [
601 {name: 'align', expectedNull: 'null'},
602 {name: 'bgColor', expectedNull: ''},
603 {name: 'border', expectedNull: 'null'},
604 {name: 'cellPadding', expectedNull: ''},
605 {name: 'cellSpacing', expectedNull: ''},
606 {name: 'frame', expectedNull: 'null'},
607 {name: 'rules', expectedNull: 'null'},
608 {name: 'summary', expectedNull: 'null'},
609 {name: 'width', expectedNull: 'null'}
613 type: 'HTMLTableRowElement',
614 elementToUse: document.createElement('tr'),
615 attributes: [
616 {name: 'align', expectedNull: 'null'},
617 {name: 'bgColor', expectedNull: ''},
618 {name: 'ch', expectedNull: 'null'},
619 {name: 'chOff', expectedNull: 'null'},
620 {name: 'vAlign', expectedNull: 'null'}
624 type: 'HTMLTableSectionElement',
625 elementToUse: document.createElement('tbody'),
626 attributes: [
627 {name: 'align', expectedNull: 'null'},
628 {name: 'ch', expectedNull: 'null'},
629 {name: 'chOff', expectedNull: 'null'},
630 {name: 'vAlign', expectedNull: 'null'}
634 type: 'HTMLTextAreaElement',
635 elementToUse: document.createElement('textarea'),
636 attributes: [
637 {name: 'defaultValue', expectedNull: 'null'},
638 {name: 'dirName', expectedNull: 'null'},
639 {name: 'inputMode', expectedNull: 'null'},
640 {name: 'name', expectedNull: 'null'},
641 {name: 'placeholder', expectedNull: 'null'},
642 {name: 'value', expectedNull: ''},
643 {name: 'wrap', expectedNull: 'null'}
647 type: 'HTMLTitleElement',
648 elementToUse: document.createElement('title'),
649 attributes: [
650 {name: 'text', expectedNull: 'null'}
654 type: 'HTMLTrackElement',
655 elementToUse: document.createElement('track'),
656 attributes: [
657 {name: 'kind', expectedNull: 'subtitles'},
658 {name: 'label', expectedNull: 'null'},
659 {name: 'src', expectedNull: 'null', isUrl: true},
660 {name: 'srclang', expectedNull: 'null'}
664 type: 'HTMLUListElement',
665 elementToUse: document.createElement('ul'),
666 attributes: [
667 {name: 'type', expectedNull: 'null'}
671 type: 'HTMLVideoElement',
672 elementToUse: document.createElement('video'),
673 attributes: [
674 {name: 'mediaGroup', expectedNull: 'null'},
675 {name: 'poster', expectedNull: 'null', isUrl: true},
676 {name: 'preload', expectedNull: 'auto'},
677 {name: 'src', expectedNull: 'null', isUrl: true}
682 for (element in listing) {
683 var type = listing[element].type;
684 var elementToUse = listing[element].elementToUse;
685 var attrs = listing[element].attributes;
686 for (attr in attrs) {
687 nullTestElementAttribute(type, elementToUse, attrs[attr].name, attrs[attr].expectedNull, attrs[attr].isUrl);
689 printOut('');
692 </script>
693 </head>
694 <body onload="runTests()">
695 <p>This test setting various attributes of a elements to JavaScript null.</p>
696 <div id="console"></div>
697 </body>
698 </html>