4 https://bugzilla.mozilla.org/show_bug.cgi?id=725907
8 <title>Test for Bug
725907</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=725907">Mozilla Bug
725907</a>
15 <div id=
"content" style=
"display: none">
19 <span id=
"egg0"></span>
20 <span id=
"egg1"><span id=
"duckling1"></span></span>
21 <span id=
"egg2"></span>
24 <script type=
"application/javascript">
26 /** Test for Bug
725907 **/
29 function runTestsForDocument(document, msgSuffix) {
30 function is(a, b, msg) { SimpleTest.is(a, b, msg + msgSuffix); }
32 var basket = document.getElementById(
"basket");
33 var egg3 = document.createElement(
"span");
37 for (let x of basket.childNodes) {
38 if (x.nodeType != x.TEXT_NODE)
41 is(log,
"egg0;egg1;egg2;",
"'for (x of div.childNodes)' should iterate over child nodes");
44 for (let x of basket.childNodes) {
45 if (x.nodeType != x.TEXT_NODE) {
48 basket.appendChild(egg3);
51 is(log,
"egg0;egg1;egg2;egg3;",
"'for (x of div.childNodes)' should see elements added during iteration");
54 basket.appendChild(document.createTextNode(
"some text"));
55 for (let x of basket.children)
57 is(log,
"egg0;egg1;egg2;egg3;",
"'for (x of div.children)' should iterate over child elements");
60 // eslint-disable-next-line no-unused-vars
61 for (let x of document.getElementsByClassName(
"hazardous-materials"))
63 is(count,
0,
"'for (x of emptyNodeList)' loop should run zero times");
66 for (let x of document.querySelectorAll(
"span"))
68 is(log,
"egg0;egg1;duckling1;egg2;egg3;",
"for-of loop should work with a querySelectorAll() NodeList");
71 /* All the tests run twice. First, in this document, so without any wrappers. */
72 runTestsForDocument(document,
"");
74 /* And once using the document of an iframe, so working with cross-compartment wrappers. */
75 SimpleTest.waitForExplicitFinish();
76 function iframeLoaded(iframe) {
77 runTestsForDocument(iframe.contentWindow.document,
" (in iframe)");
83 <iframe src=
"forOf_iframe.html" onload=
"iframeLoaded(this)"></iframe>