diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/dom/nodes/NodeList-Iterable.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/dom/nodes/NodeList-Iterable.html')
-rw-r--r-- | testing/web-platform/tests/dom/nodes/NodeList-Iterable.html | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/nodes/NodeList-Iterable.html b/testing/web-platform/tests/dom/nodes/NodeList-Iterable.html new file mode 100644 index 0000000000..fcbee175cb --- /dev/null +++ b/testing/web-platform/tests/dom/nodes/NodeList-Iterable.html @@ -0,0 +1,61 @@ +<!doctype html> +<meta charset="utf-8"> +<title>NodeList Iterable Test</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + <p id="1"></p> + <p id="2"></p> + <p id="3"></p> + <p id="4"></p> + <p id="5"></p> + + <div id="live"><b id="b1">1</b><b id="b2">2</b><b id="b3">3</b></div> +<script> + var paragraphs; + setup(function() { + paragraphs = document.querySelectorAll('p'); + }) + test(function() { + assert_true('length' in paragraphs); + }, 'NodeList has length method.'); + test(function() { + assert_true('values' in paragraphs); + }, 'NodeList has values method.'); + test(function() { + assert_true('entries' in paragraphs); + }, 'NodeList has entries method.'); + test(function() { + assert_true('forEach' in paragraphs); + }, 'NodeList has forEach method.'); + test(function() { + assert_true(Symbol.iterator in paragraphs); + }, 'NodeList has Symbol.iterator.'); + test(function() { + var ids = "12345", idx=0; + for(var node of paragraphs){ + assert_equals(node.getAttribute('id'), ids[idx++]); + } + }, 'NodeList is iterable via for-of loop.'); + + test(function() { + assert_array_equals(Object.keys(paragraphs), ['0', '1', '2', '3', '4']); + }, 'NodeList responds to Object.keys correctly'); + + test(function() { + var container = document.getElementById('live'); + var nodeList = container.childNodes; + + var ids = []; + for (var el of nodeList) { + ids.push(el.id); + assert_equals(el.localName, 'b'); + if (ids.length < 3) { + var newEl = document.createElement('b'); + newEl.id = 'after' + el.id; + container.appendChild(newEl); + } + } + + assert_array_equals(ids, ['b1', 'b2', 'b3', 'afterb1', 'afterb2']); + }, 'live NodeLists are for-of iterable and update appropriately'); +</script> |