docshell/test/chrome/bug364461_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug364461_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,277 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.9 +
    1.10 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
    1.11 +
    1.12 +<window id="364461Test"
    1.13 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.14 +        width="600"
    1.15 +        height="600"
    1.16 +        onload="onLoad();"
    1.17 +        title="364461 test">
    1.18 +
    1.19 +  <script type="application/javascript"><![CDATA[
    1.20 +
    1.21 +    const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
    1.22 +
    1.23 +    var gBrowser;
    1.24 +    var gTestsIterator;
    1.25 +    var gExpected = [];
    1.26 +
    1.27 +    function ok(condition, message) {
    1.28 +      window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    1.29 +    }
    1.30 +    function is(a, b, message) {
    1.31 +      window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
    1.32 +    }
    1.33 +    function finish() {
    1.34 +      for each (let eventType in LISTEN_EVENTS) {
    1.35 +        gBrowser.removeEventListener(eventType, eventListener, true);
    1.36 +      }
    1.37 +    
    1.38 +      window.close();
    1.39 +      window.opener.wrappedJSObject.SimpleTest.finish();
    1.40 +    }
    1.41 +
    1.42 +    function onLoad() {
    1.43 +      gBrowser = document.getElementById("content");
    1.44 +
    1.45 +      for each (let eventType in LISTEN_EVENTS) {
    1.46 +        gBrowser.addEventListener(eventType, eventListener, true);
    1.47 +      }
    1.48 +      
    1.49 +      gTestsIterator = testsIterator();
    1.50 +      nextTest();
    1.51 +    }
    1.52 +
    1.53 +    function eventListener(event) {
    1.54 +      ok(gExpected.length >= 1, "Unexpected event " + event.type);
    1.55 +      if (gExpected.length == 0) {
    1.56 +        // in case of unexpected event, try to continue anyway
    1.57 +        setTimeout(nextTest, 0);
    1.58 +        return;
    1.59 +      }
    1.60 +
    1.61 +      var exp = gExpected.shift();
    1.62 +      is(event.type, exp.type, "Invalid event received");
    1.63 +      if (typeof(exp.persisted) != "undefined") {
    1.64 +        is(event.persisted, exp.persisted, "Invalid persisted state");
    1.65 +      }
    1.66 +      if (exp.title) {
    1.67 +        ok(event.originalTarget instanceof HTMLDocument,
    1.68 +           "originalTarget not a HTMLDocument");
    1.69 +        is(event.originalTarget.title, exp.title, "titles don't match");
    1.70 +      }
    1.71 +
    1.72 +      if (gExpected.length == 0) {
    1.73 +        setTimeout(nextTest, 0);
    1.74 +      }
    1.75 +    }
    1.76 +
    1.77 +    function nextTest() {
    1.78 +      try {
    1.79 +        gTestsIterator.next();
    1.80 +      } catch (err if err instanceof StopIteration) {
    1.81 +        finish();
    1.82 +      }
    1.83 +    }
    1.84 +
    1.85 +    function testsIterator() {
    1.86 +
    1.87 +      // Tests 1 + 2:
    1.88 +      //  Back/forward between two simple documents. Bfcache will be used.
    1.89 +
    1.90 +      var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
    1.91 +                     "<body>test1</body></html>";
    1.92 +
    1.93 +      gExpected = [{type: "pagehide", persisted: true},
    1.94 +
    1.95 +                   {type: "load", title: "test1"},
    1.96 +                   {type: "pageshow", title: "test1", persisted: false}];
    1.97 +      gBrowser.loadURI(test1Doc);
    1.98 +      yield undefined;
    1.99 +
   1.100 +      var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
   1.101 +                     "<body>test2</body></html>";
   1.102 +
   1.103 +      gExpected = [{type: "pagehide", title: "test1", persisted: true},
   1.104 +                   {type: "load", title: "test2"},
   1.105 +                   {type: "pageshow", title: "test2", persisted: false}];
   1.106 +      gBrowser.loadURI(test2Doc);
   1.107 +      yield undefined;
   1.108 +
   1.109 +      gExpected = [{type: "pagehide", title: "test2", persisted: true},
   1.110 +                   {type: "pageshow", title: "test1", persisted: true}];
   1.111 +      gBrowser.goBack();
   1.112 +      yield undefined;
   1.113 +      
   1.114 +      gExpected = [{type: "pagehide", title: "test1", persisted: true},
   1.115 +                   {type: "pageshow", title: "test2", persisted: true}];
   1.116 +      gBrowser.goForward();
   1.117 +      yield undefined;
   1.118 +
   1.119 +      // Tests 3 + 4:
   1.120 +      //  Back/forward between a two-level deep iframed document and a simple
   1.121 +      //  document. Bfcache will be used and events should be dispatched to
   1.122 +      //  all frames.
   1.123 +
   1.124 +      var test3Doc = "data:text/html,<html><head><title>test3</title>" +
   1.125 +                      "</head><body>" +
   1.126 +                      "<iframe src='data:text/html," +
   1.127 +                        "<html><head><title>test3-nested1</title></head>" +
   1.128 +                        "<body>test3-nested1" +
   1.129 +                          "<iframe src=\"data:text/html," +
   1.130 +                            "<html><head><title>test3-nested2</title></head>" +
   1.131 +                            "<body>test3-nested2</body></html>\">" +
   1.132 +                          "</iframe>" +
   1.133 +                        "</body></html>'>" +
   1.134 +                      "</iframe>" +
   1.135 +                    "</body></html>";
   1.136 +
   1.137 +      gExpected = [{type: "pagehide", title: "test2", persisted: true},
   1.138 +                   {type: "load", title: "test3-nested2"},
   1.139 +                   {type: "pageshow", title: "test3-nested2", persisted: false},
   1.140 +                   {type: "load", title: "test3-nested1"},
   1.141 +                   {type: "pageshow", title: "test3-nested1", persisted: false},
   1.142 +                   {type: "load", title: "test3"},
   1.143 +                   {type: "pageshow", title: "test3", persisted: false}];
   1.144 +      gBrowser.loadURI(test3Doc);
   1.145 +      yield undefined;
   1.146 +
   1.147 +      var test4Doc = "data:text/html,<html><head><title>test4</title></head>" +
   1.148 +                     "<body>test4</body></html>";
   1.149 +
   1.150 +      gExpected = [{type: "pagehide", title: "test3", persisted: true},
   1.151 +                   {type: "pagehide", title: "test3-nested1", persisted: true},
   1.152 +                   {type: "pagehide", title: "test3-nested2", persisted: true},
   1.153 +                   {type: "load", title: "test4"},
   1.154 +                   {type: "pageshow", title: "test4", persisted: false}];
   1.155 +      gBrowser.loadURI(test4Doc);
   1.156 +      yield undefined;
   1.157 +
   1.158 +      gExpected = [{type: "pagehide", title: "test4", persisted: true},
   1.159 +                   {type: "pageshow", title: "test3-nested2", persisted: true},
   1.160 +                   {type: "pageshow", title: "test3-nested1", persisted: true},
   1.161 +                   {type: "pageshow", title: "test3", persisted: true}];
   1.162 +      gBrowser.goBack();
   1.163 +      yield undefined;
   1.164 +
   1.165 +      // This is where the two nested pagehide are not dispatched in bug 364461
   1.166 +      gExpected = [{type: "pagehide", title: "test3", persisted: true},
   1.167 +                   {type: "pagehide", title: "test3-nested1", persisted: true},
   1.168 +                   {type: "pagehide", title: "test3-nested2", persisted: true},
   1.169 +                   {type: "pageshow", title: "test4", persisted: true}];
   1.170 +      gBrowser.goForward();
   1.171 +      yield undefined;
   1.172 +
   1.173 +      // Tests 5 + 6:
   1.174 +      //  Back/forward between a document containing an unload handler and a
   1.175 +      //  a simple document. Bfcache won't be used for the first one (see
   1.176 +      //  http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching).
   1.177 +      
   1.178 +      var test5Doc = "data:text/html,<html><head><title>test5</title></head>" +
   1.179 +                     "<body onunload='while(false) { /* nop */ }'>" +
   1.180 +                     "test5</body></html>";
   1.181 +
   1.182 +      gExpected = [{type: "pagehide", title: "test4", persisted: true},
   1.183 +                   {type: "load", title: "test5"},
   1.184 +                   {type: "pageshow", title: "test5", persisted: false}];
   1.185 +      gBrowser.loadURI(test5Doc);
   1.186 +      yield undefined;
   1.187 +
   1.188 +      var test6Doc = "data:text/html,<html><head><title>test6</title></head>" +
   1.189 +                     "<body>test6</body></html>";
   1.190 +
   1.191 +      gExpected = [{type: "pagehide", title: "test5", persisted: false},
   1.192 +                   {type: "unload", title: "test5"},
   1.193 +                   {type: "load", title: "test6"},
   1.194 +                   {type: "pageshow", title: "test6", persisted: false}];
   1.195 +      gBrowser.loadURI(test6Doc);
   1.196 +      yield undefined;
   1.197 +
   1.198 +      gExpected = [{type: "pagehide", title: "test6", persisted: true},
   1.199 +                   {type: "load", title: "test5"},
   1.200 +                   {type: "pageshow", title: "test5", persisted: false}];
   1.201 +      gBrowser.goBack();
   1.202 +      yield undefined;
   1.203 +      
   1.204 +      gExpected = [{type: "pagehide", title: "test5", persisted: false},
   1.205 +                   {type: "unload", title: "test5"},
   1.206 +                   {type: "pageshow", title: "test6", persisted: true}];
   1.207 +      gBrowser.goForward();
   1.208 +      yield undefined;
   1.209 +
   1.210 +      // Test 7:
   1.211 +      //  Testcase from https://bugzilla.mozilla.org/show_bug.cgi?id=384977#c10
   1.212 +      //  Check that navigation is not blocked after a document is restored
   1.213 +      //  from bfcache
   1.214 +      
   1.215 +      var test7Doc = "data:text/html,<html><head><title>test7</title>" +
   1.216 +                      "</head><body>" +
   1.217 +                      "<iframe src='data:text/html," +
   1.218 +                        "<html><head><title>test7-nested1</title></head>" +
   1.219 +                        "<body>test7-nested1<br/>" +
   1.220 +                        "<a href=\"data:text/plain,aaa\" target=\"_main\">" +
   1.221 +                          "Click me, hit back, click me again</a>" +
   1.222 +                        "</body></html>'>" +
   1.223 +                      "</iframe>" +
   1.224 +                    "</body></html>";
   1.225 +      
   1.226 +      gExpected = [{type: "pagehide", title: "test6", persisted: true},
   1.227 +                   {type: "load", title: "test7-nested1"},
   1.228 +                   {type: "pageshow", title: "test7-nested1", persisted: false},
   1.229 +                   {type: "load", title: "test7"},
   1.230 +                   {type: "pageshow", title: "test7", persisted: false}];
   1.231 +      gBrowser.loadURI(test7Doc);
   1.232 +      yield undefined;
   1.233 +
   1.234 +      // Simulates a click on the link inside the iframe
   1.235 +      function clickIframeLink() {
   1.236 +        var iframe = gBrowser.contentDocument.getElementsByTagName("iframe")[0];
   1.237 +        var w = iframe.contentWindow;
   1.238 +        var d = iframe.contentDocument;
   1.239 +        
   1.240 +        var evt = d.createEvent("MouseEvents");
   1.241 +        evt.initMouseEvent("click", true, true, w,
   1.242 +                           0, 0, 0, 0, 0, false, false, false, false, 0, null);
   1.243 +        d.getElementsByTagName("a")[0].dispatchEvent(evt);
   1.244 +      }
   1.245 +
   1.246 +      gExpected = [{type: "pagehide", title: "test7", persisted: true},
   1.247 +                   {type: "pagehide", title: "test7-nested1", persisted: true},
   1.248 +                   {type: "load"},
   1.249 +                   {type: "pageshow", persisted: false}];
   1.250 +      clickIframeLink();
   1.251 +      yield undefined;
   1.252 +      
   1.253 +      is(gBrowser.currentURI.spec, "data:text/plain,aaa",
   1.254 +         "Navigation is blocked when clicking link");
   1.255 +      
   1.256 +      gExpected = [{type: "pagehide", persisted: true},
   1.257 +                   {type: "pageshow", title: "test7-nested1", persisted: true},
   1.258 +                   {type: "pageshow", title: "test7", persisted: true}];
   1.259 +      gBrowser.goBack();
   1.260 +      yield undefined;
   1.261 +      
   1.262 +      gExpected = [{type: "pagehide", title: "test7", persisted: true},
   1.263 +                   {type: "pagehide", title: "test7-nested1", persisted: true},
   1.264 +                   {type: "load"},
   1.265 +                   {type: "pageshow", persisted: false}];
   1.266 +      clickIframeLink();
   1.267 +      yield undefined;
   1.268 +      
   1.269 +      is(gBrowser.currentURI.spec, "data:text/plain,aaa",
   1.270 +         "Navigation is blocked when clicking link");
   1.271 +
   1.272 +      // nextTest has to be called from here, as no events are fired in this
   1.273 +      // step
   1.274 +      setTimeout(nextTest, 0);
   1.275 +      yield undefined;
   1.276 +    }
   1.277 +  ]]></script>
   1.278 +
   1.279 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.280 +</window>

mercurial