docshell/test/chrome/bug215405_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug215405_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,166 @@
     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="215405Test"
    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="215405 test">
    1.18 +
    1.19 +  <script type="application/javascript"><![CDATA[
    1.20 +    var imports = [ "SimpleTest", "is", "isnot", "ok"];
    1.21 +    for each (var name in imports) {
    1.22 +      window[name] = window.opener.wrappedJSObject[name];
    1.23 +    }
    1.24 +
    1.25 +    const text="MOZILLA";
    1.26 +    const nostoreURI = "http://mochi.test:8888/tests/docshell/test/chrome/" +
    1.27 +                       "215405_nostore.html";
    1.28 +    const nocacheURI = "https://example.com:443/tests/docshell/test/chrome/" +
    1.29 +                       "215405_nocache.html";
    1.30 +
    1.31 +    var gBrowser;
    1.32 +    var gTestsIterator;
    1.33 +    var scrollX = 0;
    1.34 +    var scrollY = 0;
    1.35 +
    1.36 +    function finish() {
    1.37 +      gBrowser.removeEventListener("pageshow", eventListener, true);
    1.38 +      // Work around bug 467960
    1.39 +      var history = gBrowser.webNavigation.sessionHistory;
    1.40 +      history.PurgeHistory(history.count);
    1.41 +
    1.42 +      window.close();
    1.43 +      window.opener.wrappedJSObject.SimpleTest.finish();
    1.44 +    }
    1.45 +
    1.46 +    function onLoad(e) {
    1.47 +      gBrowser = document.getElementById("content");
    1.48 +      gBrowser.addEventListener("pageshow", eventListener, true);
    1.49 +       
    1.50 +      gTestsIterator = testsIterator();
    1.51 +      nextTest();
    1.52 +    }
    1.53 +
    1.54 +    function eventListener(event) {
    1.55 +      setTimeout(nextTest, 0);
    1.56 +    }
    1.57 +
    1.58 +    function nextTest() {
    1.59 +      try {
    1.60 +        gTestsIterator.next();
    1.61 +      } catch (err if err instanceof StopIteration) {
    1.62 +        finish();
    1.63 +      }
    1.64 +    }
    1.65 +
    1.66 +    function testsIterator() {
    1.67 +      // No-store tests
    1.68 +      var testName = "[nostore]";
    1.69 +
    1.70 +      // Load a page with a no-store header
    1.71 +      gBrowser.loadURI(nostoreURI);
    1.72 +      yield undefined;
    1.73 +
    1.74 +
    1.75 +      // Now that the page has loaded, amend the form contents
    1.76 +      var form = gBrowser.contentDocument.getElementById("inp");
    1.77 +      form.value = text;
    1.78 +
    1.79 +      // Attempt to scroll the page
    1.80 +      var originalXPosition = gBrowser.contentWindow.scrollX;
    1.81 +      var originalYPosition = gBrowser.contentWindow.scrollY;
    1.82 +      var scrollToX = gBrowser.contentWindow.scrollMaxX;
    1.83 +      var scrollToY = gBrowser.contentWindow.scrollMaxY;
    1.84 +      gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
    1.85 +      
    1.86 +      // Save the scroll position for future comparison
    1.87 +      scrollX = gBrowser.contentWindow.scrollX;
    1.88 +      scrollY = gBrowser.contentWindow.scrollY;
    1.89 +      isnot(scrollX, originalXPosition,
    1.90 +            testName + " failed to scroll window horizontally");
    1.91 +      isnot(scrollY, originalYPosition,
    1.92 +            testName + " failed to scroll window vertically");
    1.93 +
    1.94 +      // Load a new document into the browser
    1.95 +      var simple = "data:text/html,<html><head><title>test2</title></head>" +
    1.96 +                     "<body>test2</body></html>";
    1.97 +      gBrowser.loadURI(simple);
    1.98 +      yield undefined;
    1.99 +
   1.100 +
   1.101 +      // Now go back in history. First page should not have been cached.
   1.102 +      gBrowser.goBack();
   1.103 +      yield undefined;
   1.104 +
   1.105 +
   1.106 +      // First uncacheable page will now be reloaded. Check scroll position
   1.107 +      // restored, and form contents not
   1.108 +      is(gBrowser.contentWindow.scrollX, scrollX, testName +
   1.109 +         " horizontal axis scroll position not correctly restored");
   1.110 +      is(gBrowser.contentWindow.scrollY, scrollY, testName +
   1.111 +         " vertical axis scroll position not correctly restored");
   1.112 +      var formValue = gBrowser.contentDocument.getElementById("inp").value;
   1.113 +      isnot(formValue, text, testName + " form value incorrectly restored");
   1.114 +
   1.115 +    
   1.116 +      // https no-cache
   1.117 +      testName = "[nocache]";
   1.118 +
   1.119 +      // Load a page with a no-cache header
   1.120 +      gBrowser.loadURI(nocacheURI);
   1.121 +      yield undefined;
   1.122 +
   1.123 +
   1.124 +      // Now that the page has loaded, amend the form contents
   1.125 +      form = gBrowser.contentDocument.getElementById("inp");
   1.126 +      form.value = text;
   1.127 +
   1.128 +      // Attempt to scroll the page
   1.129 +      originalXPosition = gBrowser.contentWindow.scrollX;
   1.130 +      originalYPosition = gBrowser.contentWindow.scrollY;
   1.131 +      scrollToX = gBrowser.contentWindow.scrollMaxX;
   1.132 +      scrollToY = gBrowser.contentWindow.scrollMaxY;
   1.133 +      gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
   1.134 +      
   1.135 +      // Save the scroll position for future comparison
   1.136 +      scrollX = gBrowser.contentWindow.scrollX;
   1.137 +      scrollY = gBrowser.contentWindow.scrollY;
   1.138 +      isnot(scrollX, originalXPosition,
   1.139 +            testName + " failed to scroll window horizontally");
   1.140 +      isnot(scrollY, originalYPosition,
   1.141 +            testName + " failed to scroll window vertically");
   1.142 +
   1.143 +      gBrowser.loadURI(simple);
   1.144 +      yield undefined;
   1.145 +
   1.146 +
   1.147 +      // Now go back in history. First page should not have been cached.
   1.148 +      gBrowser.goBack();
   1.149 +      yield undefined;
   1.150 +
   1.151 +
   1.152 +      // First uncacheable page will now be reloaded. Check scroll position
   1.153 +      // restored, and form contents not
   1.154 +      is(gBrowser.contentWindow.scrollX, scrollX, testName +
   1.155 +         " horizontal axis scroll position not correctly restored");
   1.156 +      is(gBrowser.contentWindow.scrollY, scrollY, testName +
   1.157 +         " vertical axis scroll position not correctly restored");
   1.158 +      var formValue = gBrowser.contentDocument.getElementById("inp").value;
   1.159 +      isnot(formValue, text, testName + " form value incorrectly restored");
   1.160 +      
   1.161 +      // nextTest has to be called from here, as no events are fired in this
   1.162 +      // step
   1.163 +      setTimeout(nextTest, 0);
   1.164 +      yield undefined;
   1.165 +    }
   1.166 +  ]]></script>
   1.167 +
   1.168 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.169 +</window>

mercurial