tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

historyframes.html (4487B)


      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="start_historyframe.html"></iframe>
     13 </div>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 602256 */
     18 
     19 var testWin = window.opener ? window.opener : window.parent;
     20 
     21 var SimpleTest = testWin.SimpleTest;
     22 function is() { testWin.is.apply(testWin, arguments); }
     23 
     24 var gFrame = null;
     25 
     26 function gState() {
     27  return location.hash.replace(/^#/, "");
     28 }
     29 
     30 function waitForLoad(aCallback) {
     31  function listener() {
     32    gFrame.removeEventListener("load", listener);
     33    SimpleTest.executeSoon(aCallback);
     34  }
     35 
     36  gFrame.addEventListener("load", listener);
     37 }
     38 
     39 function loadContent(aURL, aCallback) {
     40  waitForLoad(aCallback);
     41 
     42  gFrame.src = aURL;
     43 }
     44 
     45 function getURL() {
     46  return gFrame.contentDocument.documentURI;
     47 }
     48 
     49 function getContent() {
     50  return gFrame.contentDocument.getElementById("text").textContent;
     51 }
     52 
     53 var BASE_URI = "http://mochi.test:8888/tests/docshell/test/mochitest/";
     54 var START = BASE_URI + "start_historyframe.html";
     55 var URL1 = BASE_URI + "url1_historyframe.html";
     56 var URL2 = BASE_URI + "url2_historyframe.html";
     57 
     58 function run_test() {
     59  window.location.hash = "START";
     60 
     61  gFrame = document.getElementById("iframe");
     62 
     63  test_basic_inner_navigation();
     64 }
     65 
     66 function end_test() {
     67  testWin.done();
     68 }
     69 
     70 var gTestContinuation = null;
     71 function continueAsync() {
     72  setTimeout(function() { gTestContinuation.next(); })
     73 }
     74 
     75 function test_basic_inner_navigation() {
     76  // Navigate the inner frame a few times
     77  loadContent(URL1, function() {
     78    is(getURL(), URL1, "URL should be correct");
     79    is(getContent(), "Test1", "Page should be correct");
     80 
     81    loadContent(URL2, function() {
     82      is(getURL(), URL2, "URL should be correct");
     83      is(getContent(), "Test2", "Page should be correct");
     84 
     85      // Test that history is working
     86      waitForLoad(function() {
     87        is(getURL(), URL1, "URL should be correct");
     88        is(getContent(), "Test1", "Page should be correct");
     89 
     90        waitForLoad(function() {
     91          is(getURL(), URL2, "URL should be correct");
     92          is(getContent(), "Test2", "Page should be correct");
     93 
     94          gTestContinuation = test_state_navigation();
     95          gTestContinuation.next();
     96        });
     97        window.history.forward();
     98      });
     99      window.history.back();
    100    });
    101  });
    102 }
    103 
    104 function* test_state_navigation() {
    105  window.location.hash = "STATE1";
    106 
    107  is(getURL(), URL2, "URL should be correct");
    108  is(getContent(), "Test2", "Page should be correct");
    109 
    110  window.location.hash = "STATE2";
    111 
    112  is(getURL(), URL2, "URL should be correct");
    113  is(getContent(), "Test2", "Page should be correct");
    114 
    115  window.addEventListener("popstate", () => {
    116    continueAsync();
    117  }, {once: true});
    118  window.history.back();
    119  yield;
    120 
    121  is(gState(), "STATE1", "State should be correct after going back");
    122  is(getURL(), URL2, "URL should be correct");
    123  is(getContent(), "Test2", "Page should be correct");
    124 
    125  window.addEventListener("popstate", () => {
    126    continueAsync();
    127  }, {once: true});
    128  window.history.forward();
    129  yield;
    130 
    131  is(gState(), "STATE2", "State should be correct after going forward");
    132  is(getURL(), URL2, "URL should be correct");
    133  is(getContent(), "Test2", "Page should be correct");
    134 
    135  window.addEventListener("popstate", () => {
    136    continueAsync();
    137  }, {once: true});
    138  window.history.back();
    139  yield;
    140 
    141  window.addEventListener("popstate", () => {
    142    continueAsync();
    143  }, {once: true});
    144  window.history.back();
    145  yield;
    146 
    147  is(gState(), "START", "State should be correct");
    148  is(getURL(), URL2, "URL should be correct");
    149  is(getContent(), "Test2", "Page should be correct");
    150 
    151  waitForLoad(function() {
    152    is(getURL(), URL1, "URL should be correct");
    153    is(getContent(), "Test1", "Page should be correct");
    154 
    155    waitForLoad(function() {
    156      is(gState(), "START", "State should be correct");
    157      is(getURL(), START, "URL should be correct");
    158      is(getContent(), "Start", "Page should be correct");
    159 
    160      end_test();
    161    });
    162 
    163    window.history.back();
    164 
    165    is(gState(), "START", "State should be correct after going back twice");
    166  });
    167 
    168  window.history.back();
    169  continueAsync();
    170  yield;
    171  is(gState(), "START", "State should be correct");
    172 }
    173 </script>
    174 </pre>
    175 </body>
    176 </html>