Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | |
michael@0 | 4 | <window id="301397Test" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 6 | width="600" |
michael@0 | 7 | height="600" |
michael@0 | 8 | onload="setTimeout(nextTest,0);" |
michael@0 | 9 | title="bug 301397 test"> |
michael@0 | 10 | |
michael@0 | 11 | <script type="text/javascript" |
michael@0 | 12 | src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/> |
michael@0 | 13 | <script type="text/javascript" |
michael@0 | 14 | src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/> |
michael@0 | 15 | <script type="text/javascript" |
michael@0 | 16 | src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/> |
michael@0 | 17 | <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> |
michael@0 | 18 | <script type="application/javascript" src="docshell_helpers.js" /> |
michael@0 | 19 | <script type="application/javascript"><![CDATA[ |
michael@0 | 20 | |
michael@0 | 21 | // Define the generator-iterator for the tests. |
michael@0 | 22 | var tests = testIterator(); |
michael@0 | 23 | |
michael@0 | 24 | //// |
michael@0 | 25 | // Execute the next test in the generator function. |
michael@0 | 26 | // |
michael@0 | 27 | function nextTest() { |
michael@0 | 28 | tests.next(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | //// |
michael@0 | 32 | // Return the document element with the specified id. |
michael@0 | 33 | // |
michael@0 | 34 | function $(id) { return TestWindow.getDocument().getElementById(id); } |
michael@0 | 35 | |
michael@0 | 36 | //// |
michael@0 | 37 | // Verifies that the given string exists in the innerHTML of the iframe |
michael@0 | 38 | // content. |
michael@0 | 39 | // |
michael@0 | 40 | function verifyIframeInnerHtml(string) { |
michael@0 | 41 | var iframeInnerHtml = $("iframe").contentDocument.body.innerHTML; |
michael@0 | 42 | ok(iframeInnerHtml.indexOf(string) != -1, |
michael@0 | 43 | "iframe contains wrong document: " + iframeInnerHtml); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | //// |
michael@0 | 47 | // Generator function for test steps for bug 301397: |
michael@0 | 48 | // The correct page should be displayed in an iframe when |
michael@0 | 49 | // navigating back and forwards, when the parent page |
michael@0 | 50 | // occupies multiple spots in the session history. |
michael@0 | 51 | // |
michael@0 | 52 | function testIterator() |
michael@0 | 53 | { |
michael@0 | 54 | // Make sure the bfcache is enabled. |
michael@0 | 55 | enableBFCache(8); |
michael@0 | 56 | |
michael@0 | 57 | // Load a dummy page. |
michael@0 | 58 | doPageNavigation({ |
michael@0 | 59 | uri: getHttpUrl("generic.html"), |
michael@0 | 60 | onNavComplete: nextTest |
michael@0 | 61 | }); |
michael@0 | 62 | yield undefined; |
michael@0 | 63 | |
michael@0 | 64 | // Load a page containing an iframe. |
michael@0 | 65 | doPageNavigation({ |
michael@0 | 66 | uri: getHttpUrl("bug301397_1.html"), |
michael@0 | 67 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 68 | expectedEvents: [ { type: "pagehide", |
michael@0 | 69 | title: "generic page", |
michael@0 | 70 | persisted: true }, |
michael@0 | 71 | { type: "pageshow", |
michael@0 | 72 | title: "iframe content #1", |
michael@0 | 73 | persisted: false }, // false on initial load |
michael@0 | 74 | { type: "pageshow", |
michael@0 | 75 | title: "iframe parent", |
michael@0 | 76 | persisted: false } ], // false on initial load |
michael@0 | 77 | onNavComplete: nextTest |
michael@0 | 78 | }); |
michael@0 | 79 | yield undefined; |
michael@0 | 80 | |
michael@0 | 81 | // Click a link in the iframe to cause the iframe to navigate |
michael@0 | 82 | // to a new page, and wait until the related pagehide/pageshow |
michael@0 | 83 | // events have occurred. |
michael@0 | 84 | waitForPageEvents({ |
michael@0 | 85 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 86 | expectedEvents: [ { type: "pagehide", |
michael@0 | 87 | title: "iframe content #1", |
michael@0 | 88 | persisted: false }, // false, subframe nav |
michael@0 | 89 | { type: "pageshow", |
michael@0 | 90 | title: "iframe content #2", |
michael@0 | 91 | persisted: false } ], // false on initial load |
michael@0 | 92 | onNavComplete: nextTest |
michael@0 | 93 | }); |
michael@0 | 94 | var link = $("iframe").contentDocument.getElementById("link"); |
michael@0 | 95 | var event = $("iframe").contentDocument.createEvent("MouseEvents"); |
michael@0 | 96 | event.initMouseEvent("click", true, true, $("iframe").contentWindow, |
michael@0 | 97 | 0, 0, 0, 0, 0, |
michael@0 | 98 | false, false, false, false, |
michael@0 | 99 | 0, null); |
michael@0 | 100 | link.dispatchEvent(event); |
michael@0 | 101 | yield undefined; |
michael@0 | 102 | |
michael@0 | 103 | // Load another dummy page. Verify that both the outgoing parent and |
michael@0 | 104 | // iframe pages are stored in the bfcache. |
michael@0 | 105 | doPageNavigation({ |
michael@0 | 106 | uri: getHttpUrl("bug301397_4.html"), |
michael@0 | 107 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 108 | expectedEvents: [ { type: "pagehide", |
michael@0 | 109 | title: "iframe parent", |
michael@0 | 110 | persisted: true }, |
michael@0 | 111 | { type: "pagehide", |
michael@0 | 112 | title: "iframe content #2", |
michael@0 | 113 | persisted: true }, |
michael@0 | 114 | { type: "pageshow", |
michael@0 | 115 | title: "dummy page, no iframe", |
michael@0 | 116 | persisted: false } ], // false on initial load |
michael@0 | 117 | onNavComplete: nextTest |
michael@0 | 118 | }); |
michael@0 | 119 | yield undefined; |
michael@0 | 120 | |
michael@0 | 121 | // Go back. The iframe should show the second page loaded in it. |
michael@0 | 122 | // Both the parent and the iframe pages should be loaded from |
michael@0 | 123 | // the bfcache. |
michael@0 | 124 | doPageNavigation({ |
michael@0 | 125 | back: true, |
michael@0 | 126 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 127 | expectedEvents: [ { type: "pagehide", |
michael@0 | 128 | title: "dummy page, no iframe", |
michael@0 | 129 | persisted: true }, |
michael@0 | 130 | { type: "pageshow", |
michael@0 | 131 | persisted: true, |
michael@0 | 132 | title: "iframe content #2" }, |
michael@0 | 133 | { type: "pageshow", |
michael@0 | 134 | persisted: true, |
michael@0 | 135 | title: "iframe parent" } ], |
michael@0 | 136 | onNavComplete: nextTest |
michael@0 | 137 | }); |
michael@0 | 138 | yield undefined; |
michael@0 | 139 | |
michael@0 | 140 | verifyIframeInnerHtml("You made it"); |
michael@0 | 141 | |
michael@0 | 142 | // Go gack again. The iframe should show the first page loaded in it. |
michael@0 | 143 | doPageNavigation({ |
michael@0 | 144 | back: true, |
michael@0 | 145 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 146 | expectedEvents: [ { type: "pagehide", |
michael@0 | 147 | title: "iframe content #2", |
michael@0 | 148 | persisted: false }, // false, subframe nav |
michael@0 | 149 | { type: "pageshow", |
michael@0 | 150 | title: "iframe content #1", |
michael@0 | 151 | // false since this page was never stored |
michael@0 | 152 | // in the bfcache in the first place |
michael@0 | 153 | persisted: false } ], |
michael@0 | 154 | onNavComplete: nextTest |
michael@0 | 155 | }); |
michael@0 | 156 | yield undefined; |
michael@0 | 157 | |
michael@0 | 158 | verifyIframeInnerHtml("go to next page"); |
michael@0 | 159 | |
michael@0 | 160 | // Go back to the generic page. Now go forward to the last page, |
michael@0 | 161 | // again verifying that the iframe shows the first and second |
michael@0 | 162 | // pages in order. |
michael@0 | 163 | doPageNavigation({ |
michael@0 | 164 | back: true, |
michael@0 | 165 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 166 | expectedEvents: [ { type: "pagehide", |
michael@0 | 167 | title: "iframe parent", |
michael@0 | 168 | persisted: true }, |
michael@0 | 169 | { type: "pagehide", |
michael@0 | 170 | title: "iframe content #1", |
michael@0 | 171 | persisted: true }, |
michael@0 | 172 | { type: "pageshow", |
michael@0 | 173 | title: "generic page", |
michael@0 | 174 | persisted: true } ], |
michael@0 | 175 | onNavComplete: nextTest |
michael@0 | 176 | }); |
michael@0 | 177 | yield undefined; |
michael@0 | 178 | |
michael@0 | 179 | doPageNavigation({ |
michael@0 | 180 | forward: true, |
michael@0 | 181 | eventsToListenFor: ["pageshow"], |
michael@0 | 182 | expectedEvents: [ {type: "pageshow", |
michael@0 | 183 | title: "iframe content #1", |
michael@0 | 184 | persisted: true}, |
michael@0 | 185 | {type: "pageshow", |
michael@0 | 186 | title: "iframe parent", |
michael@0 | 187 | persisted: true} ], |
michael@0 | 188 | onNavComplete: nextTest |
michael@0 | 189 | }); |
michael@0 | 190 | yield undefined; |
michael@0 | 191 | |
michael@0 | 192 | verifyIframeInnerHtml("go to next page"); |
michael@0 | 193 | |
michael@0 | 194 | doPageNavigation({ |
michael@0 | 195 | forward: true, |
michael@0 | 196 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 197 | expectedEvents: [ { type: "pagehide", |
michael@0 | 198 | title: "iframe content #1", |
michael@0 | 199 | persisted: false }, // false, subframe nav |
michael@0 | 200 | { type: "pageshow", |
michael@0 | 201 | title: "iframe content #2", |
michael@0 | 202 | // false because the page wasn't stored in |
michael@0 | 203 | // bfcache last time it was unloaded |
michael@0 | 204 | persisted: false } ], |
michael@0 | 205 | onNavComplete: nextTest |
michael@0 | 206 | }); |
michael@0 | 207 | yield undefined; |
michael@0 | 208 | |
michael@0 | 209 | verifyIframeInnerHtml("You made it"); |
michael@0 | 210 | |
michael@0 | 211 | doPageNavigation({ |
michael@0 | 212 | forward: true, |
michael@0 | 213 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 214 | expectedEvents: [ { type: "pagehide", |
michael@0 | 215 | title: "iframe parent", |
michael@0 | 216 | persisted: true }, |
michael@0 | 217 | { type: "pagehide", |
michael@0 | 218 | title: "iframe content #2", |
michael@0 | 219 | persisted: true }, |
michael@0 | 220 | { type: "pageshow", |
michael@0 | 221 | title: "dummy page, no iframe", |
michael@0 | 222 | persisted: true } ], |
michael@0 | 223 | onNavComplete: nextTest |
michael@0 | 224 | }); |
michael@0 | 225 | yield undefined; |
michael@0 | 226 | |
michael@0 | 227 | // Go back once more, and again verify that the iframe shows the |
michael@0 | 228 | // second page loaded in it. |
michael@0 | 229 | doPageNavigation({ |
michael@0 | 230 | back: true, |
michael@0 | 231 | eventsToListenFor: ["pageshow", "pagehide"], |
michael@0 | 232 | expectedEvents: [ { type: "pagehide", |
michael@0 | 233 | title: "dummy page, no iframe", |
michael@0 | 234 | persisted: true }, |
michael@0 | 235 | { type: "pageshow", |
michael@0 | 236 | persisted: true, |
michael@0 | 237 | title: "iframe content #2" }, |
michael@0 | 238 | { type: "pageshow", |
michael@0 | 239 | persisted: true, |
michael@0 | 240 | title: "iframe parent" } ], |
michael@0 | 241 | onNavComplete: nextTest |
michael@0 | 242 | }); |
michael@0 | 243 | yield undefined; |
michael@0 | 244 | |
michael@0 | 245 | verifyIframeInnerHtml("You made it"); |
michael@0 | 246 | |
michael@0 | 247 | // Tell the framework the test is finished. Include the final 'yield' |
michael@0 | 248 | // statement to prevent a StopIteration exception from being thrown. |
michael@0 | 249 | finish(); |
michael@0 | 250 | yield undefined; |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | ]]></script> |
michael@0 | 254 | |
michael@0 | 255 | <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
michael@0 | 256 | </window> |