1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/chrome/bug301397_window.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,256 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 + 1.7 +<window id="301397Test" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.9 + width="600" 1.10 + height="600" 1.11 + onload="setTimeout(nextTest,0);" 1.12 + title="bug 301397 test"> 1.13 + 1.14 + <script type="text/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> 1.16 + <script type="text/javascript" 1.17 + src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> 1.18 + <script type="text/javascript" 1.19 + src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> 1.20 + <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> 1.21 + <script type="application/javascript" src="docshell_helpers.js" /> 1.22 + <script type="application/javascript"><![CDATA[ 1.23 + 1.24 + // Define the generator-iterator for the tests. 1.25 + var tests = testIterator(); 1.26 + 1.27 + //// 1.28 + // Execute the next test in the generator function. 1.29 + // 1.30 + function nextTest() { 1.31 + tests.next(); 1.32 + } 1.33 + 1.34 + //// 1.35 + // Return the document element with the specified id. 1.36 + // 1.37 + function $(id) { return TestWindow.getDocument().getElementById(id); } 1.38 + 1.39 + //// 1.40 + // Verifies that the given string exists in the innerHTML of the iframe 1.41 + // content. 1.42 + // 1.43 + function verifyIframeInnerHtml(string) { 1.44 + var iframeInnerHtml = $("iframe").contentDocument.body.innerHTML; 1.45 + ok(iframeInnerHtml.indexOf(string) != -1, 1.46 + "iframe contains wrong document: " + iframeInnerHtml); 1.47 + } 1.48 + 1.49 + //// 1.50 + // Generator function for test steps for bug 301397: 1.51 + // The correct page should be displayed in an iframe when 1.52 + // navigating back and forwards, when the parent page 1.53 + // occupies multiple spots in the session history. 1.54 + // 1.55 + function testIterator() 1.56 + { 1.57 + // Make sure the bfcache is enabled. 1.58 + enableBFCache(8); 1.59 + 1.60 + // Load a dummy page. 1.61 + doPageNavigation({ 1.62 + uri: getHttpUrl("generic.html"), 1.63 + onNavComplete: nextTest 1.64 + }); 1.65 + yield undefined; 1.66 + 1.67 + // Load a page containing an iframe. 1.68 + doPageNavigation({ 1.69 + uri: getHttpUrl("bug301397_1.html"), 1.70 + eventsToListenFor: ["pageshow", "pagehide"], 1.71 + expectedEvents: [ { type: "pagehide", 1.72 + title: "generic page", 1.73 + persisted: true }, 1.74 + { type: "pageshow", 1.75 + title: "iframe content #1", 1.76 + persisted: false }, // false on initial load 1.77 + { type: "pageshow", 1.78 + title: "iframe parent", 1.79 + persisted: false } ], // false on initial load 1.80 + onNavComplete: nextTest 1.81 + }); 1.82 + yield undefined; 1.83 + 1.84 + // Click a link in the iframe to cause the iframe to navigate 1.85 + // to a new page, and wait until the related pagehide/pageshow 1.86 + // events have occurred. 1.87 + waitForPageEvents({ 1.88 + eventsToListenFor: ["pageshow", "pagehide"], 1.89 + expectedEvents: [ { type: "pagehide", 1.90 + title: "iframe content #1", 1.91 + persisted: false }, // false, subframe nav 1.92 + { type: "pageshow", 1.93 + title: "iframe content #2", 1.94 + persisted: false } ], // false on initial load 1.95 + onNavComplete: nextTest 1.96 + }); 1.97 + var link = $("iframe").contentDocument.getElementById("link"); 1.98 + var event = $("iframe").contentDocument.createEvent("MouseEvents"); 1.99 + event.initMouseEvent("click", true, true, $("iframe").contentWindow, 1.100 + 0, 0, 0, 0, 0, 1.101 + false, false, false, false, 1.102 + 0, null); 1.103 + link.dispatchEvent(event); 1.104 + yield undefined; 1.105 + 1.106 + // Load another dummy page. Verify that both the outgoing parent and 1.107 + // iframe pages are stored in the bfcache. 1.108 + doPageNavigation({ 1.109 + uri: getHttpUrl("bug301397_4.html"), 1.110 + eventsToListenFor: ["pageshow", "pagehide"], 1.111 + expectedEvents: [ { type: "pagehide", 1.112 + title: "iframe parent", 1.113 + persisted: true }, 1.114 + { type: "pagehide", 1.115 + title: "iframe content #2", 1.116 + persisted: true }, 1.117 + { type: "pageshow", 1.118 + title: "dummy page, no iframe", 1.119 + persisted: false } ], // false on initial load 1.120 + onNavComplete: nextTest 1.121 + }); 1.122 + yield undefined; 1.123 + 1.124 + // Go back. The iframe should show the second page loaded in it. 1.125 + // Both the parent and the iframe pages should be loaded from 1.126 + // the bfcache. 1.127 + doPageNavigation({ 1.128 + back: true, 1.129 + eventsToListenFor: ["pageshow", "pagehide"], 1.130 + expectedEvents: [ { type: "pagehide", 1.131 + title: "dummy page, no iframe", 1.132 + persisted: true }, 1.133 + { type: "pageshow", 1.134 + persisted: true, 1.135 + title: "iframe content #2" }, 1.136 + { type: "pageshow", 1.137 + persisted: true, 1.138 + title: "iframe parent" } ], 1.139 + onNavComplete: nextTest 1.140 + }); 1.141 + yield undefined; 1.142 + 1.143 + verifyIframeInnerHtml("You made it"); 1.144 + 1.145 + // Go gack again. The iframe should show the first page loaded in it. 1.146 + doPageNavigation({ 1.147 + back: true, 1.148 + eventsToListenFor: ["pageshow", "pagehide"], 1.149 + expectedEvents: [ { type: "pagehide", 1.150 + title: "iframe content #2", 1.151 + persisted: false }, // false, subframe nav 1.152 + { type: "pageshow", 1.153 + title: "iframe content #1", 1.154 + // false since this page was never stored 1.155 + // in the bfcache in the first place 1.156 + persisted: false } ], 1.157 + onNavComplete: nextTest 1.158 + }); 1.159 + yield undefined; 1.160 + 1.161 + verifyIframeInnerHtml("go to next page"); 1.162 + 1.163 + // Go back to the generic page. Now go forward to the last page, 1.164 + // again verifying that the iframe shows the first and second 1.165 + // pages in order. 1.166 + doPageNavigation({ 1.167 + back: true, 1.168 + eventsToListenFor: ["pageshow", "pagehide"], 1.169 + expectedEvents: [ { type: "pagehide", 1.170 + title: "iframe parent", 1.171 + persisted: true }, 1.172 + { type: "pagehide", 1.173 + title: "iframe content #1", 1.174 + persisted: true }, 1.175 + { type: "pageshow", 1.176 + title: "generic page", 1.177 + persisted: true } ], 1.178 + onNavComplete: nextTest 1.179 + }); 1.180 + yield undefined; 1.181 + 1.182 + doPageNavigation({ 1.183 + forward: true, 1.184 + eventsToListenFor: ["pageshow"], 1.185 + expectedEvents: [ {type: "pageshow", 1.186 + title: "iframe content #1", 1.187 + persisted: true}, 1.188 + {type: "pageshow", 1.189 + title: "iframe parent", 1.190 + persisted: true} ], 1.191 + onNavComplete: nextTest 1.192 + }); 1.193 + yield undefined; 1.194 + 1.195 + verifyIframeInnerHtml("go to next page"); 1.196 + 1.197 + doPageNavigation({ 1.198 + forward: true, 1.199 + eventsToListenFor: ["pageshow", "pagehide"], 1.200 + expectedEvents: [ { type: "pagehide", 1.201 + title: "iframe content #1", 1.202 + persisted: false }, // false, subframe nav 1.203 + { type: "pageshow", 1.204 + title: "iframe content #2", 1.205 + // false because the page wasn't stored in 1.206 + // bfcache last time it was unloaded 1.207 + persisted: false } ], 1.208 + onNavComplete: nextTest 1.209 + }); 1.210 + yield undefined; 1.211 + 1.212 + verifyIframeInnerHtml("You made it"); 1.213 + 1.214 + doPageNavigation({ 1.215 + forward: true, 1.216 + eventsToListenFor: ["pageshow", "pagehide"], 1.217 + expectedEvents: [ { type: "pagehide", 1.218 + title: "iframe parent", 1.219 + persisted: true }, 1.220 + { type: "pagehide", 1.221 + title: "iframe content #2", 1.222 + persisted: true }, 1.223 + { type: "pageshow", 1.224 + title: "dummy page, no iframe", 1.225 + persisted: true } ], 1.226 + onNavComplete: nextTest 1.227 + }); 1.228 + yield undefined; 1.229 + 1.230 + // Go back once more, and again verify that the iframe shows the 1.231 + // second page loaded in it. 1.232 + doPageNavigation({ 1.233 + back: true, 1.234 + eventsToListenFor: ["pageshow", "pagehide"], 1.235 + expectedEvents: [ { type: "pagehide", 1.236 + title: "dummy page, no iframe", 1.237 + persisted: true }, 1.238 + { type: "pageshow", 1.239 + persisted: true, 1.240 + title: "iframe content #2" }, 1.241 + { type: "pageshow", 1.242 + persisted: true, 1.243 + title: "iframe parent" } ], 1.244 + onNavComplete: nextTest 1.245 + }); 1.246 + yield undefined; 1.247 + 1.248 + verifyIframeInnerHtml("You made it"); 1.249 + 1.250 + // Tell the framework the test is finished. Include the final 'yield' 1.251 + // statement to prevent a StopIteration exception from being thrown. 1.252 + finish(); 1.253 + yield undefined; 1.254 + } 1.255 + 1.256 + ]]></script> 1.257 + 1.258 + <browser type="content-primary" flex="1" id="content" src="about:blank"/> 1.259 +</window>