| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
| 5 <div id="container"></div> | 5 <div id="container"></div> |
| 6 <form></form> | 6 <form></form> |
| 7 <script> | 7 <script> |
| 8 | 8 |
| 9 description("This tests verifies that namedItem and named getter returns the fir
st matched item for all but all, options, and form controls collections."); | 9 description("This tests verifies that namedItem and named getter returns the fir
st matched item for all but all, options, and form controls collections."); |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 var elements; | 30 var elements; |
| 31 debug('document.all'); | 31 debug('document.all'); |
| 32 shouldBeTrue("document.all instanceof HTMLAllCollection"); | 32 shouldBeTrue("document.all instanceof HTMLAllCollection"); |
| 33 shouldBeTrue("document.all instanceof HTMLCollection"); | 33 shouldBeTrue("document.all instanceof HTMLCollection"); |
| 34 shouldBe("initialLength = document.all.length; elements = [insertElementWithId('
b', 'foo'), insertElementWithId('q', 'foo')];\n" | 34 shouldBe("initialLength = document.all.length; elements = [insertElementWithId('
b', 'foo'), insertElementWithId('q', 'foo')];\n" |
| 35 + " document.all.length", "initialLength + 2;"); | 35 + " document.all.length", "initialLength + 2;"); |
| 36 shouldBe("document.all['foo'].length", "2"); | 36 shouldBe("document.all['foo'].length", "2"); |
| 37 shouldBe("document.all['foo'][0]", "elements[0]"); | 37 shouldBe("document.all['foo'][0]", "elements[0]"); |
| 38 shouldBe("document.all['foo'][1]", "elements[1]"); | 38 shouldBe("document.all['foo'][1]", "elements[1]"); |
| 39 shouldBe("elements[0].parentNode.removeChild(elements[0]); document.all['foo']",
'elements[1]'); | 39 shouldBe("elements[0].parentNode.removeChild(elements[0]); document.all['foo']",
'elements[1]'); |
| 40 shouldBeUndefined("document.all['no-such-element']"); |
| 40 debug(""); | 41 debug(""); |
| 41 | 42 |
| 42 var form = document.querySelector('form'); | 43 var form = document.querySelector('form'); |
| 43 debug("form.elements"); | 44 debug("form.elements"); |
| 44 shouldBeTrue("form.elements instanceof HTMLFormControlsCollection"); | 45 shouldBeTrue("form.elements instanceof HTMLFormControlsCollection"); |
| 45 shouldBeTrue("form.elements instanceof HTMLCollection"); | 46 shouldBeTrue("form.elements instanceof HTMLCollection"); |
| 46 shouldBe("form.elements.length", "0"); | 47 shouldBe("form.elements.length", "0"); |
| 47 shouldBe("elements = [createElementWithId('input', 'foo'), createElementWithId('
input', 'foo')];\n" | 48 shouldBe("elements = [createElementWithId('input', 'foo'), createElementWithId('
input', 'foo')];\n" |
| 48 + " form.appendChild(elements[0]); form.elements.length", "1"); | 49 + " form.appendChild(elements[0]); form.elements.length", "1"); |
| 49 shouldBe("form.elements['foo']", "elements[0]"); | 50 shouldBe("form.elements['foo']", "elements[0]"); |
| 50 shouldBe("form.appendChild(elements[1]); form.elements.length", "2"); | 51 shouldBe("form.appendChild(elements[1]); form.elements.length", "2"); |
| 51 shouldBe("form.elements['foo'].toString()", "'[object RadioNodeList]'"); | 52 shouldBe("form.elements['foo'].toString()", "'[object RadioNodeList]'"); |
| 52 shouldBe("form.elements['foo'].length", "2"); | 53 shouldBe("form.elements['foo'].length", "2"); |
| 53 shouldBe("form.elements['foo'][0]", "elements[0]"); | 54 shouldBe("form.elements['foo'][0]", "elements[0]"); |
| 54 shouldBe("form.elements['foo'][1]", "elements[1]"); | 55 shouldBe("form.elements['foo'][1]", "elements[1]"); |
| 55 shouldBe("form.removeChild(elements[0]); form.elements['foo']", "elements[1]"); | 56 shouldBe("form.removeChild(elements[0]); form.elements['foo']", "elements[1]"); |
| 56 shouldBe("removeTestElements(); form.elements.length", "0"); | 57 shouldBe("removeTestElements(); form.elements.length", "0"); |
| 58 shouldBeUndefined("form.elements['no-such-element']"); |
| 57 debug(""); | 59 debug(""); |
| 58 | 60 |
| 59 debug("select.options"); | 61 debug("select.options"); |
| 60 shouldBe("form.appendChild(createElementWithId('select', 'bar')); form.elements.
length", "1"); | 62 shouldBe("form.appendChild(createElementWithId('select', 'bar')); form.elements.
length", "1"); |
| 61 shouldBeTrue("select = form.elements[0]; select.options instanceof HTMLOptionsCo
llection"); | 63 shouldBeTrue("select = form.elements[0]; select.options instanceof HTMLOptionsCo
llection"); |
| 62 shouldBeTrue("select.options instanceof HTMLCollection"); | 64 shouldBeTrue("select.options instanceof HTMLCollection"); |
| 63 shouldBe("select.options.length", "0"); | 65 shouldBe("select.options.length", "0"); |
| 64 shouldBe("elements = [createElementWithId('option', 'foo'), createElementWithId(
'option', 'foo')];\n" | 66 shouldBe("elements = [createElementWithId('option', 'foo'), createElementWithId(
'option', 'foo')];\n" |
| 65 + " select.appendChild(elements[0]); select.options.length", "1"); | 67 + " select.appendChild(elements[0]); select.options.length", "1"); |
| 66 shouldBe("select.options['foo']", "elements[0]"); | 68 shouldBe("select.options['foo']", "elements[0]"); |
| 67 shouldBe("select.appendChild(elements[1]); select.options.length", "2"); | 69 shouldBe("select.appendChild(elements[1]); select.options.length", "2"); |
| 68 shouldBe("select.options['foo'].toString()", "'[object NodeList]'"); | 70 shouldBe("select.options['foo'].toString()", "'[object NodeList]'"); |
| 69 shouldBe("select.options['foo'].length", "2"); | 71 shouldBe("select.options['foo'].length", "2"); |
| 70 shouldBe("select.options['foo'][0]", "elements[0]"); | 72 shouldBe("select.options['foo'][0]", "elements[0]"); |
| 71 shouldBe("select.options['foo'][1]", "elements[1]"); | 73 shouldBe("select.options['foo'][1]", "elements[1]"); |
| 72 shouldBe("select.removeChild(elements[0]); select.options['foo']", "elements[1]"
); | 74 shouldBe("select.removeChild(elements[0]); select.options['foo']", "elements[1]"
); |
| 73 shouldBe("select.innerHTML = ''; select.options.length", "0"); | 75 shouldBe("select.innerHTML = ''; select.options.length", "0"); |
| 74 shouldBe("removeTestElements(); form.elements.length", "0"); | 76 shouldBe("removeTestElements(); form.elements.length", "0"); |
| 77 shouldBeUndefined("select.options['no-such-element']"); |
| 75 debug(""); | 78 debug(""); |
| 76 | 79 |
| 77 function testFirstItemReturnsFirstMatch(collection, initialLength, elementNames,
attributes) { | 80 function testFirstItemReturnsFirstMatch(collection, initialLength, elementNames,
attributes) { |
| 78 debug(collection); | 81 debug(collection); |
| 79 shouldBe(collection + ".length", initialLength.toString()); | 82 shouldBe(collection + ".length", initialLength.toString()); |
| 80 elements = []; | 83 elements = []; |
| 81 for (var i = 0; i < elementNames.length; i++) { | 84 for (var i = 0; i < elementNames.length; i++) { |
| 82 var attrs = attributes ? ", " + JSON.stringify(attributes) : ''; | 85 var attrs = attributes ? ", " + JSON.stringify(attributes) : ''; |
| 83 shouldBe("elements[" + i + "] = insertElementWithId('" + elementNames[i]
+ "', 'foo'" + attrs + "); " | 86 shouldBe("elements[" + i + "] = insertElementWithId('" + elementNames[i]
+ "', 'foo'" + attrs + "); " |
| 84 + collection + ".length", (initialLength + i + 1).toString()); | 87 + collection + ".length", (initialLength + i + 1).toString()); |
| 85 } | 88 } |
| 86 shouldBe(collection + "['foo']", "elements[0]"); | 89 shouldBe(collection + "['foo']", "elements[0]"); |
| 87 shouldBe("removeTestElements(); " + collection + ".length", initialLength.to
String()); | 90 shouldBe("removeTestElements(); " + collection + ".length", initialLength.to
String()); |
| 88 debug(""); | 91 debug(""); |
| 89 } | 92 } |
| 90 | 93 |
| 91 testFirstItemReturnsFirstMatch('document.images', 0, ['img', 'img']); | 94 testFirstItemReturnsFirstMatch('document.images', 0, ['img', 'img']); |
| 92 testFirstItemReturnsFirstMatch('document.applets', 0, ['applet', 'applet']); | 95 testFirstItemReturnsFirstMatch('document.applets', 0, ['applet', 'applet']); |
| 93 testFirstItemReturnsFirstMatch('document.embeds', 0, ['embed', 'embed']); | 96 testFirstItemReturnsFirstMatch('document.embeds', 0, ['embed', 'embed']); |
| 94 testFirstItemReturnsFirstMatch('document.forms', 1, ['form', 'form']); | 97 testFirstItemReturnsFirstMatch('document.forms', 1, ['form', 'form']); |
| 95 testFirstItemReturnsFirstMatch('document.links', 0, ['a', 'a', 'area'], {'href':
'some url'}); | 98 testFirstItemReturnsFirstMatch('document.links', 0, ['a', 'a', 'area'], {'href':
'some url'}); |
| 96 testFirstItemReturnsFirstMatch('document.anchors', 0, ['a', 'a'], {'name': 'some
name'}); | 99 testFirstItemReturnsFirstMatch('document.anchors', 0, ['a', 'a'], {'name': 'some
name'}); |
| 97 testFirstItemReturnsFirstMatch('document.scripts', 2, ['script', 'script']); | 100 testFirstItemReturnsFirstMatch('document.scripts', 2, ['script', 'script']); |
| 98 | 101 |
| 99 var successfullyParsed = true; | 102 var successfullyParsed = true; |
| 100 | 103 |
| 101 </script> | 104 </script> |
| 102 </body> | 105 </body> |
| 103 </html> | 106 </html> |
| OLD | NEW |