tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_forOf.html (2651B)


      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 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">
     16 
     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">
     25 
     26 /** Test for Bug 725907 */
     27 
     28 
     29 function runTestsForDocument(document, msgSuffix) {
     30    function is(a, b, msg) { SimpleTest.is(a, b, msg + msgSuffix); }
     31 
     32    var basket = document.getElementById("basket");
     33    var egg3 = document.createElement("span");
     34    egg3.id = "egg3";
     35 
     36    var log = "";
     37    for (let x of basket.childNodes) {
     38        if (x.nodeType != x.TEXT_NODE)
     39            log += x.id + ";";
     40    }
     41    is(log, "egg0;egg1;egg2;", "'for (x of div.childNodes)' should iterate over child nodes");
     42 
     43    log = "";
     44    for (let x of basket.childNodes) {
     45        if (x.nodeType != x.TEXT_NODE) {
     46            log += x.id + ";";
     47            if (x.id == "egg1")
     48                basket.appendChild(egg3);
     49        }
     50    }
     51    is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.childNodes)' should see elements added during iteration");
     52 
     53    log = "";
     54    basket.appendChild(document.createTextNode("some text"));
     55    for (let 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");
     58 
     59    var count = 0;
     60    // eslint-disable-next-line no-unused-vars
     61    for (let x of document.getElementsByClassName("hazardous-materials"))
     62        count++;
     63    is(count, 0, "'for (x of emptyNodeList)' loop should run zero times");
     64 
     65    log = "";
     66    for (let x of document.querySelectorAll("span"))
     67        log += x.id + ";";
     68    is(log, "egg0;egg1;duckling1;egg2;egg3;", "for-of loop should work with a querySelectorAll() NodeList");
     69 }
     70 
     71 /* All the tests run twice. First, in this document, so without any wrappers. */
     72 runTestsForDocument(document, "");
     73 
     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)");
     78    SimpleTest.finish();
     79 }
     80 
     81 </script>
     82 
     83 <iframe src="forOf_iframe.html" onload="iframeLoaded(this)"></iframe>
     84 
     85 </pre>
     86 </body>
     87 </html>