docshell/test/historyframes.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/historyframes.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=602256
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 602256</title>
    1.11 +</head>
    1.12 +<body onload="SimpleTest.executeSoon(run_test)">
    1.13 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a>
    1.14 +<div id="content">
    1.15 +  <iframe id="iframe" src="data:text/html,<p%20id='text'>Start</p>"></iframe>
    1.16 +</div>
    1.17 +<pre id="test">
    1.18 +<script type="application/javascript">
    1.19 +
    1.20 +/** Test for Bug 602256 **/
    1.21 +
    1.22 +var testWin = window.opener ? window.opener : window.parent;
    1.23 +
    1.24 +var SimpleTest = testWin.SimpleTest;
    1.25 +function is() { testWin.is.apply(testWin, arguments); }
    1.26 +
    1.27 +var gFrame = null;
    1.28 +
    1.29 +function gState() {
    1.30 +  return location.hash.replace(/^#/, "");
    1.31 +}
    1.32 +
    1.33 +function waitForLoad(aCallback) {
    1.34 +  function listener() {
    1.35 +    gFrame.removeEventListener("load", listener, false);
    1.36 +    SimpleTest.executeSoon(aCallback);
    1.37 +  }
    1.38 +
    1.39 +  gFrame.addEventListener("load", listener, false);
    1.40 +}
    1.41 +
    1.42 +function loadContent(aURL, aCallback) {
    1.43 +  waitForLoad(aCallback);
    1.44 +
    1.45 +  gFrame.src = aURL;
    1.46 +}
    1.47 +
    1.48 +function getURL() {
    1.49 +  return gFrame.contentDocument.documentURI;
    1.50 +}
    1.51 +
    1.52 +function getContent() {
    1.53 +  return gFrame.contentDocument.getElementById("text").textContent;
    1.54 +}
    1.55 +
    1.56 +var START = "data:text/html,<p%20id='text'>Start</p>";
    1.57 +var URL1 = "data:text/html,<p%20id='text'>Test1</p>";
    1.58 +var URL2 = "data:text/html,<p%20id='text'>Test2</p>";
    1.59 +
    1.60 +function run_test() {
    1.61 +  window.location.hash = "START";
    1.62 +
    1.63 +  gFrame = document.getElementById("iframe");
    1.64 +
    1.65 +  test_basic_inner_navigation();
    1.66 +}
    1.67 +
    1.68 +function end_test() {
    1.69 +  testWin.done();
    1.70 +}
    1.71 +
    1.72 +function test_basic_inner_navigation() {
    1.73 +  // Navigate the inner frame a few times
    1.74 +  loadContent(URL1, function() {
    1.75 +    is(getURL(), URL1, "URL should be correct");
    1.76 +    is(getContent(), "Test1", "Page should be correct");
    1.77 +
    1.78 +    loadContent(URL2, function() {
    1.79 +      is(getURL(), URL2, "URL should be correct");
    1.80 +      is(getContent(), "Test2", "Page should be correct");
    1.81 +
    1.82 +      // Test that history is working
    1.83 +      waitForLoad(function() {
    1.84 +        is(getURL(), URL1, "URL should be correct");
    1.85 +        is(getContent(), "Test1", "Page should be correct");
    1.86 +
    1.87 +        waitForLoad(function() {
    1.88 +          is(getURL(), URL2, "URL should be correct");
    1.89 +          is(getContent(), "Test2", "Page should be correct");
    1.90 +
    1.91 +          test_state_navigation();
    1.92 +        });
    1.93 +        window.history.forward();
    1.94 +      });
    1.95 +      window.history.back();
    1.96 +    });
    1.97 +  });
    1.98 +}
    1.99 +
   1.100 +function test_state_navigation() {
   1.101 +  window.location.hash = "STATE1";
   1.102 +
   1.103 +  is(getURL(), URL2, "URL should be correct");
   1.104 +  is(getContent(), "Test2", "Page should be correct");
   1.105 +
   1.106 +  window.location.hash = "STATE2";
   1.107 +
   1.108 +  is(getURL(), URL2, "URL should be correct");
   1.109 +  is(getContent(), "Test2", "Page should be correct");
   1.110 +
   1.111 +  window.history.back();
   1.112 +
   1.113 +  is(gState(), "STATE1", "State should be correct after going back");
   1.114 +  is(getURL(), URL2, "URL should be correct");
   1.115 +  is(getContent(), "Test2", "Page should be correct");
   1.116 +
   1.117 +  window.history.forward();
   1.118 +
   1.119 +  is(gState(), "STATE2", "State should be correct after going forward");
   1.120 +  is(getURL(), URL2, "URL should be correct");
   1.121 +  is(getContent(), "Test2", "Page should be correct");
   1.122 +
   1.123 +  window.history.back();
   1.124 +  window.history.back();
   1.125 +
   1.126 +  is(gState(), "START", "State should be correct");
   1.127 +  is(getURL(), URL2, "URL should be correct");
   1.128 +  is(getContent(), "Test2", "Page should be correct");
   1.129 +
   1.130 +  waitForLoad(function() {
   1.131 +    is(getURL(), URL1, "URL should be correct");
   1.132 +    is(getContent(), "Test1", "Page should be correct");
   1.133 +
   1.134 +    waitForLoad(function() {
   1.135 +      is(gState(), "START", "State should be correct");
   1.136 +      is(getURL(), START, "URL should be correct");
   1.137 +      is(getContent(), "Start", "Page should be correct");
   1.138 +
   1.139 +      end_test();
   1.140 +    });
   1.141 +
   1.142 +    window.history.back();
   1.143 +
   1.144 +    is(gState(), "START", "State should be correct after going back twice");
   1.145 +  });
   1.146 +
   1.147 +  window.history.back();
   1.148 +  is(gState(), "START", "State should be correct");
   1.149 +}
   1.150 +</script>
   1.151 +</pre>
   1.152 +</body>
   1.153 +</html>

mercurial