зеркало из https://github.com/mozilla/pjs.git
Test for bug 301397. r=bzbarsky
This commit is contained in:
Родитель
84e4974f59
Коммит
e1023f9b72
|
@ -73,6 +73,12 @@ _TEST_FILES = \
|
|||
bug294258_testcase.html \
|
||||
test_bug298622.xul \
|
||||
bug298622_window.xul \
|
||||
test_bug301397.xul \
|
||||
bug301397_window.xul \
|
||||
bug301397_1.html \
|
||||
bug301397_2.html \
|
||||
bug301397_3.html \
|
||||
bug301397_4.html \
|
||||
test_bug303267.xul \
|
||||
bug303267.html \
|
||||
bug303267_window.xul \
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>iframe parent</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="iframe" src="bug301397_2.html"/>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>iframe content #1</title>
|
||||
</head>
|
||||
<body>
|
||||
iframe page 1<br/>
|
||||
<a id="link" href="bug301397_3.html">go to next page</a>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>iframe content #2</title>
|
||||
</head>
|
||||
<body>
|
||||
iframe page 2<br/>
|
||||
You made it!
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>dummy page, no iframe</title>
|
||||
</head>
|
||||
<body>
|
||||
Just a boring test page, nothing special.
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,253 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
|
||||
<window id="301397Test"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
width="600"
|
||||
height="600"
|
||||
onload="setTimeout(nextTest,0);"
|
||||
title="bug 301397 test">
|
||||
|
||||
<script type="application/javascript"
|
||||
src=
|
||||
"chrome://mochikit/content/chrome/docshell/test/chrome/docshell_helpers.js">
|
||||
</script>
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
// Define the generator-iterator for the tests.
|
||||
var tests = testIterator();
|
||||
|
||||
////
|
||||
// Execute the next test in the generator function.
|
||||
//
|
||||
function nextTest() {
|
||||
tests.next();
|
||||
}
|
||||
|
||||
////
|
||||
// Return the document element with the specified id.
|
||||
//
|
||||
function $(id) { return TestWindow.getDocument().getElementById(id); }
|
||||
|
||||
////
|
||||
// Verifies that the given string exists in the innerHTML of the iframe
|
||||
// content.
|
||||
//
|
||||
function verifyIframeInnerHtml(string) {
|
||||
var iframeInnerHtml = $("iframe").contentDocument.body.innerHTML;
|
||||
ok(iframeInnerHtml.indexOf(string) != -1,
|
||||
"iframe contains wrong document: " + iframeInnerHtml);
|
||||
}
|
||||
|
||||
////
|
||||
// Generator function for test steps for bug 301397:
|
||||
// The correct page should be displayed in an iframe when
|
||||
// navigating back and forwards, when the parent page
|
||||
// occupies multiple spots in the session history.
|
||||
//
|
||||
function testIterator()
|
||||
{
|
||||
// Make sure the bfcache is enabled.
|
||||
enableBFCache(8);
|
||||
|
||||
// Load a dummy page.
|
||||
doPageNavigation({
|
||||
uri: getHttpUrl("generic.html"),
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
// Load a page containing an iframe.
|
||||
doPageNavigation({
|
||||
uri: getHttpUrl("bug301397_1.html"),
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "generic page",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
title: "iframe content #1",
|
||||
persisted: false }, // false on initial load
|
||||
{ type: "pageshow",
|
||||
title: "iframe parent",
|
||||
persisted: false } ], // false on initial load
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
// Click a link in the iframe to cause the iframe to navigate
|
||||
// to a new page, and wait until the related pagehide/pageshow
|
||||
// events have occurred.
|
||||
waitForPageEvents({
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe content #1",
|
||||
persisted: false }, // false, subframe nav
|
||||
{ type: "pageshow",
|
||||
title: "iframe content #2",
|
||||
persisted: false } ], // false on initial load
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
var link = $("iframe").contentDocument.getElementById("link");
|
||||
var event = $("iframe").contentDocument.createEvent("MouseEvents");
|
||||
event.initMouseEvent("click", true, true, $("iframe").contentWindow,
|
||||
0, 0, 0, 0, 0,
|
||||
false, false, false, false,
|
||||
0, null);
|
||||
link.dispatchEvent(event);
|
||||
yield;
|
||||
|
||||
// Load another dummy page. Verify that both the outgoing parent and
|
||||
// iframe pages are stored in the bfcache.
|
||||
doPageNavigation({
|
||||
uri: getHttpUrl("bug301397_4.html"),
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe parent",
|
||||
persisted: true },
|
||||
{ type: "pagehide",
|
||||
title: "iframe content #2",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
title: "dummy page, no iframe",
|
||||
persisted: false } ], // false on initial load
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
// Go back. The iframe should show the second page loaded in it.
|
||||
// Both the parent and the iframe pages should be loaded from
|
||||
// the bfcache.
|
||||
doPageNavigation({
|
||||
back: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "dummy page, no iframe",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
persisted: true,
|
||||
title: "iframe content #2" },
|
||||
{ type: "pageshow",
|
||||
persisted: true,
|
||||
title: "iframe parent" } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
verifyIframeInnerHtml("You made it");
|
||||
|
||||
// Go gack again. The iframe should show the first page loaded in it.
|
||||
doPageNavigation({
|
||||
back: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe content #2",
|
||||
persisted: false }, // false, subframe nav
|
||||
{ type: "pageshow",
|
||||
title: "iframe content #1",
|
||||
// false since this page was never stored
|
||||
// in the bfcache in the first place
|
||||
persisted: false } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
verifyIframeInnerHtml("go to next page");
|
||||
|
||||
// Go back to the generic page. Now go forward to the last page,
|
||||
// again verifying that the iframe shows the first and second
|
||||
// pages in order.
|
||||
doPageNavigation({
|
||||
back: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe parent",
|
||||
persisted: true },
|
||||
{ type: "pagehide",
|
||||
title: "iframe content #1",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
title: "generic page",
|
||||
persisted: true } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
doPageNavigation({
|
||||
forward: true,
|
||||
eventsToListenFor: ["pageshow"],
|
||||
expectedEvents: [ {type: "pageshow",
|
||||
title: "iframe content #1",
|
||||
persisted: true},
|
||||
{type: "pageshow",
|
||||
title: "iframe parent",
|
||||
persisted: true} ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
verifyIframeInnerHtml("go to next page");
|
||||
|
||||
doPageNavigation({
|
||||
forward: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe content #1",
|
||||
persisted: false }, // false, subframe nav
|
||||
{ type: "pageshow",
|
||||
title: "iframe content #2",
|
||||
// false because the page wasn't stored in
|
||||
// bfcache last time it was unloaded
|
||||
persisted: false } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
verifyIframeInnerHtml("You made it");
|
||||
|
||||
doPageNavigation({
|
||||
forward: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "iframe parent",
|
||||
persisted: true },
|
||||
{ type: "pagehide",
|
||||
title: "iframe content #2",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
title: "dummy page, no iframe",
|
||||
persisted: true } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
// Go back once more, and again verify that the iframe shows the
|
||||
// second page loaded in it.
|
||||
doPageNavigation({
|
||||
back: true,
|
||||
eventsToListenFor: ["pageshow", "pagehide"],
|
||||
expectedEvents: [ { type: "pagehide",
|
||||
title: "dummy page, no iframe",
|
||||
persisted: true },
|
||||
{ type: "pageshow",
|
||||
persisted: true,
|
||||
title: "iframe content #2" },
|
||||
{ type: "pageshow",
|
||||
persisted: true,
|
||||
title: "iframe parent" } ],
|
||||
onNavComplete: nextTest
|
||||
});
|
||||
yield;
|
||||
|
||||
verifyIframeInnerHtml("You made it");
|
||||
|
||||
// Tell the framework the test is finished. Include the final 'yield'
|
||||
// statement to prevent a StopIteration exception from being thrown.
|
||||
finish();
|
||||
yield;
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
||||
</window>
|
|
@ -16,14 +16,15 @@ const NAV_FORWARD = 2;
|
|||
const NAV_URI = 3;
|
||||
const NAV_RELOAD = 4;
|
||||
|
||||
var gExpectedEvents; // an array of events which are expected to be
|
||||
// triggered by this navigation
|
||||
var gFinalEvent; // true if the last expected event has occurred
|
||||
var gUrisNotInBFCache = []; // an array of uri's which shouldn't be stored
|
||||
// in the bfcache
|
||||
var gNavType = NAV_NONE; // defines the most recent navigation type
|
||||
// executed by doPageNavigation
|
||||
|
||||
var gExpectedEvents; // an array of events which are expected to
|
||||
// be triggered by this navigation
|
||||
var gFinalEvent; // true if the last expected event has fired
|
||||
var gUrisNotInBFCache = []; // an array of uri's which shouldn't be stored
|
||||
// in the bfcache
|
||||
var gNavType = NAV_NONE; // defines the most recent navigation type
|
||||
// executed by doPageNavigation
|
||||
var gOrigMaxTotalViewers = // original value of max_total_viewers,
|
||||
undefined; // to be restored at end of test
|
||||
|
||||
/**
|
||||
* The doPageNavigation() function performs page navigations asynchronously,
|
||||
|
@ -92,7 +93,9 @@ function doPageNavigation(params) {
|
|||
eventsToListenFor.length == 0 ? undefined : params.expectedEvents;
|
||||
let preventBFCache = (typeof[params.preventBFCache] == "undefined") ?
|
||||
false : params.preventBFCache;
|
||||
|
||||
let waitOnly = (typeof(params.waitForEventsOnly) == "boolean"
|
||||
&& params.waitForEventsOnly);
|
||||
|
||||
// Do some sanity checking on arguments.
|
||||
if (back && forward)
|
||||
throw "Can't specify both back and forward";
|
||||
|
@ -102,12 +105,18 @@ function doPageNavigation(params) {
|
|||
throw "Can't specify both forward and a uri";
|
||||
if (reload && (forward || back || uri))
|
||||
throw "Can't specify reload and another navigation type";
|
||||
if (!back && !forward && !uri && !reload)
|
||||
if (!back && !forward && !uri && !reload && !waitOnly)
|
||||
throw "Must specify back or foward or reload or uri";
|
||||
if (params.onNavComplete && eventsToListenFor.length == 0)
|
||||
throw "Can't use onNavComplete when eventsToListenFor == []";
|
||||
if (params.preventBFCache && eventsToListenFor.length == 0)
|
||||
throw "Can't use preventBFCache when eventsToListenFor == []";
|
||||
if (params.preventBFCache && waitOnly)
|
||||
throw "Can't prevent bfcaching when only waiting for events";
|
||||
if (waitOnly && typeof(params.onNavComplete) == "undefined")
|
||||
throw "Must specify onNavComplete when specifying waitForEventsOnly";
|
||||
if (waitOnly && (back || forward || reload || uri))
|
||||
throw "Can't specify a navigation type when using waitForEventsOnly";
|
||||
for each (let anEventType in eventsToListenFor) {
|
||||
let eventFound = false;
|
||||
if ( (anEventType == "pageshow") && (!gExpectedEvents) )
|
||||
|
@ -150,6 +159,9 @@ function doPageNavigation(params) {
|
|||
gNavType = NAV_RELOAD;
|
||||
TestWindow.getBrowser().reload();
|
||||
}
|
||||
else if (waitOnly) {
|
||||
gNavType = NAV_NONE;
|
||||
}
|
||||
else {
|
||||
throw "No valid navigation type passed to doPageNavigation!";
|
||||
}
|
||||
|
@ -211,6 +223,16 @@ function doPageNavigation_complete(eventsToListenFor, onNavComplete,
|
|||
onNavComplete.call();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a test to wait for page navigation events, and notify a
|
||||
* callback when they've all been received. This works exactly the
|
||||
* same as doPageNavigation(), except that no navigation is initiated.
|
||||
*/
|
||||
function waitForPageEvents(params) {
|
||||
params.waitForEventsOnly = true;
|
||||
doPageNavigation(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* The event listener which listens for expectedEvents.
|
||||
*/
|
||||
|
@ -287,6 +309,16 @@ function finish() {
|
|||
// Work around bug 467960.
|
||||
var history = TestWindow.getBrowser().webNavigation.sessionHistory;
|
||||
history.PurgeHistory(history.count);
|
||||
|
||||
// If the test changed the value of max_total_viewers via a call to
|
||||
// enableBFCache(), then restore it now.
|
||||
if (typeof(gOrigMaxTotalViewers) != "undefined") {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setIntPref("browser.sessionhistory.max_total_viewers",
|
||||
gOrigMaxTotalViewers);
|
||||
}
|
||||
|
||||
// Close the test window and signal the framework that the test is done.
|
||||
window.close();
|
||||
|
@ -353,6 +385,15 @@ function enableBFCache(enable) {
|
|||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
// If this is the first time the test called enableBFCache(),
|
||||
// store the original value of max_total_viewers, so it can
|
||||
// be restored at the end of the test.
|
||||
if (typeof(gOrigMaxTotalViewers) == "undefined") {
|
||||
gOrigMaxTotalViewers =
|
||||
prefs.getIntPref("browser.sessionhistory.max_total_viewers");
|
||||
}
|
||||
|
||||
if (typeof(enable) == "boolean") {
|
||||
if (enable)
|
||||
prefs.setIntPref("browser.sessionhistory.max_total_viewers", -1);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=301397.xul
|
||||
-->
|
||||
<window title="Mozilla Bug 301397"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<title>Test for Bug 301397</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=301397">
|
||||
Mozilla Bug 301397</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 301397 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
window.open("bug301397_window.xul", "bug301397",
|
||||
"chrome,width=600,height=600");
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче