Bumping manifests a=b2g-bump
[gecko.git] / dom / bindings / test / test_forOf.html
blob53969a23e7e69d677cc86494555d37bf96b323c1
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=725907
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 725907</title>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=725907">Mozilla Bug 725907</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
17 </div>
18 <div id="basket">
19 <span id="egg0"></span>
20 <span id="egg1"><span id="duckling1"></span></span>
21 <span id="egg2"></span>
22 </div>
23 <pre id="test">
24 <script type="application/javascript">
26 /** Test for Bug 725907 **/
28 function runTestsForDocument(document, msgSuffix) {
29 function is(a, b, msg) { SimpleTest.is(a, b, msg + msgSuffix); }
30 function isnot(a, b, msg) { SimpleTest.isnot(a, b, msg + msgSuffix); }
32 var basket = document.getElementById("basket");
33 var egg3 = document.createElement("span");
34 egg3.id = "egg3";
36 var log = '';
37 for (var x of basket.childNodes) {
38 if (x.nodeType != x.TEXT_NODE)
39 log += x.id + ";";
41 is(log, "egg0;egg1;egg2;", "'for (x of div.childNodes)' should iterate over child nodes");
43 log = '';
44 for (var x of basket.childNodes) {
45 if (x.nodeType != x.TEXT_NODE) {
46 log += x.id + ";";
47 if (x.id == "egg1")
48 basket.appendChild(egg3);
51 is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.childNodes)' should see elements added during iteration");
53 log = '';
54 basket.appendChild(document.createTextNode("some text"));
55 for (var x of basket.children)
56 log += x.id + ";";
57 is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.children)' should iterate over child elements");
59 var count = 0;
60 for (var x of document.getElementsByClassName("hazardous-materials"))
61 count++;
62 is(count, 0, "'for (x of emptyNodeList)' loop should run zero times");
64 var log = '';
65 for (var x of document.querySelectorAll("span"))
66 log += x.id + ";";
67 is(log, "egg0;egg1;duckling1;egg2;egg3;", "for-of loop should work with a querySelectorAll() NodeList");
70 /* All the tests run twice. First, in this document, so without any wrappers. */
71 runTestsForDocument(document, "");
73 /* And once using the document of an iframe, so working with cross-compartment wrappers. */
74 SimpleTest.waitForExplicitFinish();
75 function iframeLoaded(iframe) {
76 runTestsForDocument(iframe.contentWindow.document, " (in iframe)");
77 SimpleTest.finish();
80 </script>
82 <iframe src="forOf_iframe.html" onload="iframeLoaded(this)"></iframe>
84 </pre>
85 </body>
86 </html>