dom/tests/mochitest/general/historyframes.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/general/historyframes.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     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 +var gState = null;
    1.30 +
    1.31 +window.addEventListener("popstate", function(aEvent) {
    1.32 +  gState = aEvent.state;
    1.33 +}, false);
    1.34 +
    1.35 +function waitForLoad(aCallback) {
    1.36 +  function listener() {
    1.37 +    gFrame.removeEventListener("load", listener, false);
    1.38 +    SimpleTest.executeSoon(aCallback);
    1.39 +  }
    1.40 +
    1.41 +  gFrame.addEventListener("load", listener, false);
    1.42 +}
    1.43 +
    1.44 +function loadContent(aURL, aCallback) {
    1.45 +  waitForLoad(aCallback);
    1.46 +
    1.47 +  gFrame.src = aURL;
    1.48 +}
    1.49 +
    1.50 +function getURL() {
    1.51 +  return gFrame.contentDocument.documentURI;
    1.52 +}
    1.53 +
    1.54 +function getContent() {
    1.55 +  return gFrame.contentDocument.getElementById("text").textContent;
    1.56 +}
    1.57 +
    1.58 +var START = "data:text/html,<p%20id='text'>Start</p>";
    1.59 +var URL1 = "data:text/html,<p%20id='text'>Test1</p>";
    1.60 +var URL2 = "data:text/html,<p%20id='text'>Test2</p>";
    1.61 +
    1.62 +function run_test() {
    1.63 +  window.history.pushState("START", window.location);
    1.64 +
    1.65 +  gFrame = document.getElementById("iframe");
    1.66 +
    1.67 +  test_basic_inner_navigation();
    1.68 +}
    1.69 +
    1.70 +function end_test() {
    1.71 +  testWin.done();
    1.72 +}
    1.73 +
    1.74 +function test_basic_inner_navigation() {
    1.75 +  // Navigate the inner frame a few times
    1.76 +  loadContent(URL1, function() {
    1.77 +    is(getURL(), URL1, "URL should be correct");
    1.78 +    is(getContent(), "Test1", "Page should be correct");
    1.79 +
    1.80 +    loadContent(URL2, function() {
    1.81 +      is(getURL(), URL2, "URL should be correct");
    1.82 +      is(getContent(), "Test2", "Page should be correct");
    1.83 +
    1.84 +      // Test that history is working
    1.85 +      waitForLoad(function() {
    1.86 +        is(getURL(), URL1, "URL should be correct");
    1.87 +        is(getContent(), "Test1", "Page should be correct");
    1.88 +
    1.89 +        waitForLoad(function() {
    1.90 +          is(getURL(), URL2, "URL should be correct");
    1.91 +          is(getContent(), "Test2", "Page should be correct");
    1.92 +
    1.93 +          test_state_navigation();
    1.94 +        });
    1.95 +        window.history.forward();
    1.96 +      });
    1.97 +      window.history.back();
    1.98 +    });
    1.99 +  });
   1.100 +}
   1.101 +
   1.102 +function test_state_navigation() {
   1.103 +  window.history.pushState("STATE1", window.location);
   1.104 +
   1.105 +  is(getURL(), URL2, "URL should be correct");
   1.106 +  is(getContent(), "Test2", "Page should be correct");
   1.107 +
   1.108 +  window.history.pushState("STATE2", window.location);
   1.109 +
   1.110 +  is(getURL(), URL2, "URL should be correct");
   1.111 +  is(getContent(), "Test2", "Page should be correct");
   1.112 +
   1.113 +  window.history.back();
   1.114 +
   1.115 +  is(gState, "STATE1", "State should be correct");
   1.116 +  is(getURL(), URL2, "URL should be correct");
   1.117 +  is(getContent(), "Test2", "Page should be correct");
   1.118 +
   1.119 +  window.history.forward();
   1.120 +
   1.121 +  is(gState, "STATE2", "State should be correct");
   1.122 +  is(getURL(), URL2, "URL should be correct");
   1.123 +  is(getContent(), "Test2", "Page should be correct");
   1.124 +
   1.125 +  window.history.back();
   1.126 +  window.history.back();
   1.127 +
   1.128 +  is(gState, "START", "State should be correct");
   1.129 +  is(getURL(), URL2, "URL should be correct");
   1.130 +  is(getContent(), "Test2", "Page should be correct");
   1.131 +
   1.132 +  waitForLoad(function() {
   1.133 +    is(getURL(), URL1, "URL should be correct");
   1.134 +    is(getContent(), "Test1", "Page should be correct");
   1.135 +
   1.136 +    waitForLoad(function() {
   1.137 +      is(gState, "START", "State should be correct");
   1.138 +      is(getURL(), START, "URL should be correct");
   1.139 +      is(getContent(), "Start", "Page should be correct");
   1.140 +
   1.141 +      end_test();
   1.142 +    });
   1.143 +
   1.144 +    window.history.back();
   1.145 +
   1.146 +    is(gState, "START", "State should be correct");
   1.147 +  });
   1.148 +
   1.149 +  window.history.back();
   1.150 +  is(gState, "START", "State should be correct");
   1.151 +}
   1.152 +</script>
   1.153 +</pre>
   1.154 +</body>
   1.155 +</html>

mercurial