dom/tests/mochitest/general/historyframes.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=602256
     5 -->
     6 <head>
     7   <title>Test for Bug 602256</title>
     8 </head>
     9 <body onload="SimpleTest.executeSoon(run_test)">
    10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a>
    11 <div id="content">
    12   <iframe id="iframe" src="data:text/html,<p%20id='text'>Start</p>"></iframe>
    13 </div>
    14 <pre id="test">
    15 <script type="application/javascript">
    17 /** Test for Bug 602256 **/
    19 var testWin = window.opener ? window.opener : window.parent;
    21 var SimpleTest = testWin.SimpleTest;
    22 function is() { testWin.is.apply(testWin, arguments); }
    24 var gFrame = null;
    26 var gState = null;
    28 window.addEventListener("popstate", function(aEvent) {
    29   gState = aEvent.state;
    30 }, false);
    32 function waitForLoad(aCallback) {
    33   function listener() {
    34     gFrame.removeEventListener("load", listener, false);
    35     SimpleTest.executeSoon(aCallback);
    36   }
    38   gFrame.addEventListener("load", listener, false);
    39 }
    41 function loadContent(aURL, aCallback) {
    42   waitForLoad(aCallback);
    44   gFrame.src = aURL;
    45 }
    47 function getURL() {
    48   return gFrame.contentDocument.documentURI;
    49 }
    51 function getContent() {
    52   return gFrame.contentDocument.getElementById("text").textContent;
    53 }
    55 var START = "data:text/html,<p%20id='text'>Start</p>";
    56 var URL1 = "data:text/html,<p%20id='text'>Test1</p>";
    57 var URL2 = "data:text/html,<p%20id='text'>Test2</p>";
    59 function run_test() {
    60   window.history.pushState("START", window.location);
    62   gFrame = document.getElementById("iframe");
    64   test_basic_inner_navigation();
    65 }
    67 function end_test() {
    68   testWin.done();
    69 }
    71 function test_basic_inner_navigation() {
    72   // Navigate the inner frame a few times
    73   loadContent(URL1, function() {
    74     is(getURL(), URL1, "URL should be correct");
    75     is(getContent(), "Test1", "Page should be correct");
    77     loadContent(URL2, function() {
    78       is(getURL(), URL2, "URL should be correct");
    79       is(getContent(), "Test2", "Page should be correct");
    81       // Test that history is working
    82       waitForLoad(function() {
    83         is(getURL(), URL1, "URL should be correct");
    84         is(getContent(), "Test1", "Page should be correct");
    86         waitForLoad(function() {
    87           is(getURL(), URL2, "URL should be correct");
    88           is(getContent(), "Test2", "Page should be correct");
    90           test_state_navigation();
    91         });
    92         window.history.forward();
    93       });
    94       window.history.back();
    95     });
    96   });
    97 }
    99 function test_state_navigation() {
   100   window.history.pushState("STATE1", window.location);
   102   is(getURL(), URL2, "URL should be correct");
   103   is(getContent(), "Test2", "Page should be correct");
   105   window.history.pushState("STATE2", window.location);
   107   is(getURL(), URL2, "URL should be correct");
   108   is(getContent(), "Test2", "Page should be correct");
   110   window.history.back();
   112   is(gState, "STATE1", "State should be correct");
   113   is(getURL(), URL2, "URL should be correct");
   114   is(getContent(), "Test2", "Page should be correct");
   116   window.history.forward();
   118   is(gState, "STATE2", "State should be correct");
   119   is(getURL(), URL2, "URL should be correct");
   120   is(getContent(), "Test2", "Page should be correct");
   122   window.history.back();
   123   window.history.back();
   125   is(gState, "START", "State should be correct");
   126   is(getURL(), URL2, "URL should be correct");
   127   is(getContent(), "Test2", "Page should be correct");
   129   waitForLoad(function() {
   130     is(getURL(), URL1, "URL should be correct");
   131     is(getContent(), "Test1", "Page should be correct");
   133     waitForLoad(function() {
   134       is(gState, "START", "State should be correct");
   135       is(getURL(), START, "URL should be correct");
   136       is(getContent(), "Start", "Page should be correct");
   138       end_test();
   139     });
   141     window.history.back();
   143     is(gState, "START", "State should be correct");
   144   });
   146   window.history.back();
   147   is(gState, "START", "State should be correct");
   148 }
   149 </script>
   150 </pre>
   151 </body>
   152 </html>

mercurial