docshell/test/chrome/bug449778_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug449778_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<window title="Mozilla Bug 449778" onload="doTheTest()"
     1.7 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     1.8 +
     1.9 +  <hbox id="parent">
    1.10 +  </hbox>
    1.11 +
    1.12 +  <!-- test code goes here -->
    1.13 +  <script type="application/javascript"><![CDATA[
    1.14 +    var imports = [ "SimpleTest", "is", "isnot", "ok", "onerror" ];
    1.15 +    for each (var name in imports) {
    1.16 +      window[name] = window.opener.wrappedJSObject[name];
    1.17 +    }
    1.18 +
    1.19 +    function $(id) {
    1.20 +      return document.getElementById(id);
    1.21 +    }
    1.22 +
    1.23 +    function addBrowser(parent, id, width, height) {
    1.24 +      var b =
    1.25 +        document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
    1.26 +      b.setAttribute("type", "content");
    1.27 +      b.setAttribute("id", id);
    1.28 +      b.setAttribute("width", width);
    1.29 +      b.setAttribute("height", height);
    1.30 +      $(parent).appendChild(b);
    1.31 +    }
    1.32 +    addBrowser("parent", "f1", 300, 200);
    1.33 +    addBrowser("parent", "f2", 300, 200);
    1.34 +
    1.35 +    /** Test for Bug 449778 **/
    1.36 +    var doc1 = "data:text/html,<html><body>This is a test</body></html>";
    1.37 +    var doc2 = "data:text/html,<html><body>This is a second test</body></html>";
    1.38 +    var doc3 = "data:text/html,<html><body>This is a <script>var evt = document.createEvent('Events'); evt.initEvent('testEvt', true, true); document.dispatchEvent(evt);</script>third test</body></html>";
    1.39 +
    1.40 +
    1.41 +    $("f1").setAttribute("src", doc1);
    1.42 +    $("f2").setAttribute("src", doc2);
    1.43 +
    1.44 +    function doTheTest() {
    1.45 +      var strs = { "f1": "", "f2" : "" };
    1.46 +      function attachListener(node, type) {
    1.47 +        var listener = function(e) {
    1.48 +          if (strs[node.id]) strs[node.id] += " ";
    1.49 +          strs[node.id] += node.id + ".page" + type;
    1.50 +        }
    1.51 +        node.addEventListener("page" + type, listener, false);
    1.52 +
    1.53 +        listener.detach = function() {
    1.54 +          node.removeEventListener("page" + type, listener, false);
    1.55 +        }
    1.56 +        return listener;
    1.57 +      }
    1.58 +
    1.59 +      var l1 = attachListener($("f1"), "show");
    1.60 +      var l2 = attachListener($("f1"), "hide");
    1.61 +      var l3 = attachListener($("f2"), "show");
    1.62 +      var l4 = attachListener($("f2"), "hide");
    1.63 +
    1.64 +      $("f1").swapDocShells($("f2"));
    1.65 +
    1.66 +      is(strs["f1"], "f1.pagehide f1.pageshow",
    1.67 +              "Expected hide then show on first loaded page");
    1.68 +      is(strs["f2"], "f2.pagehide f2.pageshow",
    1.69 +              "Expected hide then show on second loaded page");
    1.70 +
    1.71 +      function listener2() {
    1.72 +        $("f2").removeEventListener("testEvt", listener2, false);
    1.73 +
    1.74 +        strs = { "f1": "", "f2" : "" };
    1.75 +
    1.76 +        $("f1").swapDocShells($("f2"));
    1.77 +        is(strs["f1"], "f1.pagehide",
    1.78 +           "Expected hide on already-loaded page, then nothing");
    1.79 +        is(strs["f2"], "f2.pageshow f2.pagehide f2.pageshow",
    1.80 +           "Expected show on still-loading page, then hide on it, then show " +
    1.81 +           "on already-loaded page");
    1.82 +
    1.83 +        strs = { "f1": "", "f2" : "" };
    1.84 +
    1.85 +        $("f1").addEventListener("pageshow", listener3, false);
    1.86 +      }
    1.87 +
    1.88 +      function listener3() {
    1.89 +        $("f1").removeEventListener("pageshow", listener3, false);
    1.90 +
    1.91 +        is(strs["f1"], "f1.pageshow",
    1.92 +           "Expected show as our page finishes loading");
    1.93 +        is(strs["f2"], "", "Expected no more events here.");
    1.94 +
    1.95 +        l1.detach();
    1.96 +        l2.detach();
    1.97 +        l3.detach();
    1.98 +        l4.detach();
    1.99 +
   1.100 +        window.close();
   1.101 +        SimpleTest.finish();
   1.102 +      }
   1.103 +
   1.104 +      $("f2").addEventListener("testEvt", listener2, false, true);
   1.105 +      $("f2").setAttribute("src", doc3);
   1.106 +    }
   1.107 +
   1.108 +  ]]></script>
   1.109 +</window>

mercurial