dom/bindings/test/test_forOf.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/test/test_forOf.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=725907
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 725907</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=725907">Mozilla Bug 725907</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<div id="basket">
    1.22 +  <span id="egg0"></span>
    1.23 +  <span id="egg1"><span id="duckling1"></span></span>
    1.24 +  <span id="egg2"></span>
    1.25 +</div>
    1.26 +<pre id="test">
    1.27 +<script type="application/javascript">
    1.28 +
    1.29 +/** Test for Bug 725907 **/
    1.30 +
    1.31 +function runTestsForDocument(document, msgSuffix) {
    1.32 +    function is(a, b, msg) { SimpleTest.is(a, b, msg + msgSuffix); }
    1.33 +    function isnot(a, b, msg) { SimpleTest.isnot(a, b, msg + msgSuffix); }
    1.34 +
    1.35 +    var basket = document.getElementById("basket");
    1.36 +    var egg3 = document.createElement("span");
    1.37 +    egg3.id = "egg3";
    1.38 +
    1.39 +    var log = '';
    1.40 +    for (var x of basket.childNodes) {
    1.41 +        if (x.nodeType != x.TEXT_NODE)
    1.42 +            log += x.id + ";";
    1.43 +    }
    1.44 +    is(log, "egg0;egg1;egg2;", "'for (x of div.childNodes)' should iterate over child nodes");
    1.45 +
    1.46 +    log = '';
    1.47 +    for (var x of basket.childNodes) {
    1.48 +        if (x.nodeType != x.TEXT_NODE) {
    1.49 +            log += x.id + ";";
    1.50 +            if (x.id == "egg1")
    1.51 +                basket.appendChild(egg3);
    1.52 +        }
    1.53 +    }
    1.54 +    is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.childNodes)' should see elements added during iteration");
    1.55 +
    1.56 +    log = '';
    1.57 +    basket.appendChild(document.createTextNode("some text"));
    1.58 +    for (var x of basket.children)
    1.59 +        log += x.id + ";";
    1.60 +    is(log, "egg0;egg1;egg2;egg3;", "'for (x of div.children)' should iterate over child elements");
    1.61 +
    1.62 +    var count = 0;
    1.63 +    for (var x of document.getElementsByClassName("hazardous-materials"))
    1.64 +        count++;
    1.65 +    is(count, 0, "'for (x of emptyNodeList)' loop should run zero times");
    1.66 +
    1.67 +    var log = '';
    1.68 +    for (var x of document.querySelectorAll("span"))
    1.69 +        log += x.id + ";";
    1.70 +    is(log, "egg0;egg1;duckling1;egg2;egg3;", "for-of loop should work with a querySelectorAll() NodeList");
    1.71 +}
    1.72 +
    1.73 +/* All the tests run twice. First, in this document, so without any wrappers. */
    1.74 +runTestsForDocument(document, "");
    1.75 +
    1.76 +/* And once using the document of an iframe, so working with cross-compartment wrappers. */
    1.77 +SimpleTest.waitForExplicitFinish();
    1.78 +function iframeLoaded(iframe) {
    1.79 +    runTestsForDocument(iframe.contentWindow.document, " (in iframe)");
    1.80 +    SimpleTest.finish();
    1.81 +}
    1.82 +
    1.83 +</script>
    1.84 +
    1.85 +<iframe src="forOf_iframe.html" onload="iframeLoaded(this)"></iframe>
    1.86 +
    1.87 +</pre>
    1.88 +</body>
    1.89 +</html>

mercurial