docshell/test/chrome/bug449780_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug449780_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<window title="Mozilla Bug 449780" 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 449780 **/
    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 +
    1.39 +    function getDOM(id) {
    1.40 +      return $(id).contentDocument.documentElement.innerHTML;
    1.41 +    }
    1.42 +
    1.43 +    var tester = (function() {
    1.44 +      var origDOM = getDOM("f1");
    1.45 +      $("f1").contentDocument.body.textContent = "Modified";
    1.46 +      var modifiedDOM = getDOM("f1");
    1.47 +      isnot(origDOM, modifiedDOM, "DOM should be different");
    1.48 +      $("f1").contentWindow.location.href = doc2;
    1.49 +      yield undefined;
    1.50 +
    1.51 +      $("f1").goBack();
    1.52 +      yield undefined;
    1.53 +
    1.54 +      is(getDOM("f1"), modifiedDOM, "Should have been bfcached");
    1.55 +      $("f1").goForward();
    1.56 +      yield undefined;
    1.57 +
    1.58 +      // Ignore the notifications during swap
    1.59 +      $("f1").removeEventListener("pageshow", testDriver, false);
    1.60 +      $("f1").swapDocShells($("f2"));
    1.61 +      $("f2").addEventListener("pageshow", testDriver, false);
    1.62 +      $("f2").goBack();
    1.63 +      yield undefined;
    1.64 +
    1.65 +      is(getDOM("f2"), origDOM, "Should have not have been bfcached");
    1.66 +      window.close();
    1.67 +      SimpleTest.finish();
    1.68 +      yield undefined;
    1.69 +    })();
    1.70 +
    1.71 +    function testDriver() {
    1.72 +      setTimeout(function() { tester.next() }, 0);
    1.73 +    }
    1.74 +
    1.75 +    function doTheTest() {
    1.76 +      $("f1").addEventListener("pageshow", testDriver, false);
    1.77 +      $("f1").setAttribute("src", doc1);
    1.78 +    }
    1.79 +  ]]></script>
    1.80 +</window>

mercurial