docshell/test/historyframes.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     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 function gState() {
    27   return location.hash.replace(/^#/, "");
    28 }
    30 function waitForLoad(aCallback) {
    31   function listener() {
    32     gFrame.removeEventListener("load", listener, false);
    33     SimpleTest.executeSoon(aCallback);
    34   }
    36   gFrame.addEventListener("load", listener, false);
    37 }
    39 function loadContent(aURL, aCallback) {
    40   waitForLoad(aCallback);
    42   gFrame.src = aURL;
    43 }
    45 function getURL() {
    46   return gFrame.contentDocument.documentURI;
    47 }
    49 function getContent() {
    50   return gFrame.contentDocument.getElementById("text").textContent;
    51 }
    53 var START = "data:text/html,<p%20id='text'>Start</p>";
    54 var URL1 = "data:text/html,<p%20id='text'>Test1</p>";
    55 var URL2 = "data:text/html,<p%20id='text'>Test2</p>";
    57 function run_test() {
    58   window.location.hash = "START";
    60   gFrame = document.getElementById("iframe");
    62   test_basic_inner_navigation();
    63 }
    65 function end_test() {
    66   testWin.done();
    67 }
    69 function test_basic_inner_navigation() {
    70   // Navigate the inner frame a few times
    71   loadContent(URL1, function() {
    72     is(getURL(), URL1, "URL should be correct");
    73     is(getContent(), "Test1", "Page should be correct");
    75     loadContent(URL2, function() {
    76       is(getURL(), URL2, "URL should be correct");
    77       is(getContent(), "Test2", "Page should be correct");
    79       // Test that history is working
    80       waitForLoad(function() {
    81         is(getURL(), URL1, "URL should be correct");
    82         is(getContent(), "Test1", "Page should be correct");
    84         waitForLoad(function() {
    85           is(getURL(), URL2, "URL should be correct");
    86           is(getContent(), "Test2", "Page should be correct");
    88           test_state_navigation();
    89         });
    90         window.history.forward();
    91       });
    92       window.history.back();
    93     });
    94   });
    95 }
    97 function test_state_navigation() {
    98   window.location.hash = "STATE1";
   100   is(getURL(), URL2, "URL should be correct");
   101   is(getContent(), "Test2", "Page should be correct");
   103   window.location.hash = "STATE2";
   105   is(getURL(), URL2, "URL should be correct");
   106   is(getContent(), "Test2", "Page should be correct");
   108   window.history.back();
   110   is(gState(), "STATE1", "State should be correct after going back");
   111   is(getURL(), URL2, "URL should be correct");
   112   is(getContent(), "Test2", "Page should be correct");
   114   window.history.forward();
   116   is(gState(), "STATE2", "State should be correct after going forward");
   117   is(getURL(), URL2, "URL should be correct");
   118   is(getContent(), "Test2", "Page should be correct");
   120   window.history.back();
   121   window.history.back();
   123   is(gState(), "START", "State should be correct");
   124   is(getURL(), URL2, "URL should be correct");
   125   is(getContent(), "Test2", "Page should be correct");
   127   waitForLoad(function() {
   128     is(getURL(), URL1, "URL should be correct");
   129     is(getContent(), "Test1", "Page should be correct");
   131     waitForLoad(function() {
   132       is(gState(), "START", "State should be correct");
   133       is(getURL(), START, "URL should be correct");
   134       is(getContent(), "Start", "Page should be correct");
   136       end_test();
   137     });
   139     window.history.back();
   141     is(gState(), "START", "State should be correct after going back twice");
   142   });
   144   window.history.back();
   145   is(gState(), "START", "State should be correct");
   146 }
   147 </script>
   148 </pre>
   149 </body>
   150 </html>

mercurial