dom/tests/mochitest/general/historyframes.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial