| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../../resources/js-test.js"></script> |
| <a id="id1" name="name1"></a> |
| <a id="id2" name="name1"></a> |
| <a id="id3"></a> |
| <a id="id4" name="name4"></a> |
| <a name="name5"></a> |
| <a id="id4" name="name6"></a> |
| |
| <script> |
| description("This tests verifies the enumerated properties on HTMLCollection and their order."); |
| |
| var testLink = document.getElementById("testLink"); |
| var htmlCollection = document.getElementsByTagName("a"); |
| shouldBe("htmlCollection.__proto__", "HTMLCollection.prototype"); |
| shouldBe("htmlCollection.length", "6"); |
| |
| // As per https://dom.spec.whatwg.org/#htmlcollection: |
| // - The object's supported property indices are the numbers in the range zero to one less than the |
| // number of nodes represented by the collection. If there are no such elements, then there are no |
| // supported property indices. |
| // - The supported property names are the values from the list returned by these steps: |
| // 1. Let result be an empty list. |
| // 2. For each element represented by the collection, in tree order, run these substeps: |
| // 1. If element has an ID which is neither the empty string nor is in result, append element's ID to result. |
| // 2. If element is in the HTML namespace and has a name attribute whose value is neither the empty string |
| // nor is in result, append element's name attribute value to result. |
| // 3. Return result. |
| var expectedEnumeratedProperties = ["0", "1" , "2", "3", "4", "5", "length", "id1", "name1", "id2", "id3", "id4", "name4", "name5", "name6", "item", "namedItem"].sort(); |
| |
| var enumeratedProperties = []; |
| for (var property in htmlCollection) { |
| enumeratedProperties[enumeratedProperties.length] = property; |
| } |
| enumeratedProperties.sort(); |
| shouldBe("enumeratedProperties", "expectedEnumeratedProperties"); |
| </script> |
| </body> |
| </html> |