gecko-dev/docshell/test/chrome/bug364461_window.xhtml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

270 строки
11 KiB
HTML
Исходник Обычный вид История

<?xml version="1.0"?>
2012-05-21 15:12:37 +04:00
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window id="364461Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="600"
height="600"
onload="onLoad();"
title="364461 test">
<script type="application/javascript"><![CDATA[
Bug 1514594: Part 3 - Change ChromeUtils.import API. *** Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8 This changes the behavior of ChromeUtils.import() to return an exports object, rather than a module global, in all cases except when `null` is passed as a second argument, and changes the default behavior not to pollute the global scope with the module's exports. Thus, the following code written for the old model: ChromeUtils.import("resource://gre/modules/Services.jsm"); is approximately the same as the following, in the new model: var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); Since the two behaviors are mutually incompatible, this patch will land with a scripted rewrite to update all existing callers to use the new model rather than the old. *** Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs This was done using the followng script: https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm *** Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16747 *** Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16748 *** Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16749 *** Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs *** Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D16750 --HG-- extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895 extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 21:18:31 +03:00
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
var gBrowser;
var gTestsIterator;
var gExpected = [];
function ok(condition, message) {
window.arguments[0].SimpleTest.ok(condition, message);
}
function is(a, b, message) {
window.arguments[0].SimpleTest.is(a, b, message);
}
function finish() {
for (let eventType of LISTEN_EVENTS) {
gBrowser.removeEventListener(eventType, eventListener, true);
}
window.close();
window.arguments[0].SimpleTest.finish();
}
function onLoad() {
gBrowser = document.getElementById("content");
for (let eventType of LISTEN_EVENTS) {
gBrowser.addEventListener(eventType, eventListener, true);
}
gTestsIterator = testsIterator();
nextTest();
}
function eventListener(event) {
ok(gExpected.length >= 1, "Unexpected event " + event.type);
if (gExpected.length == 0) {
// in case of unexpected event, try to continue anyway
setTimeout(nextTest, 0);
return;
}
var exp = gExpected.shift();
is(event.type, exp.type, "Invalid event received");
if (typeof(exp.persisted) != "undefined") {
is(event.persisted, exp.persisted, "Invalid persisted state");
}
if (exp.title) {
ok(event.originalTarget instanceof HTMLDocument,
"originalTarget not a HTMLDocument");
is(event.originalTarget.title, exp.title, "titles don't match");
}
if (gExpected.length == 0) {
setTimeout(nextTest, 0);
}
}
function nextTest() {
gTestsIterator.next();
}
function* testsIterator() {
// Tests 1 + 2:
// Back/forward between two simple documents. Bfcache will be used.
var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
"<body>test1</body></html>";
gExpected = [{type: "pagehide", persisted: true},
{type: "load", title: "test1"},
{type: "pageshow", title: "test1", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test1Doc);
yield undefined;
var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
"<body>test2</body></html>";
gExpected = [{type: "pagehide", title: "test1", persisted: true},
{type: "load", title: "test2"},
{type: "pageshow", title: "test2", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test2Doc);
yield undefined;
gExpected = [{type: "pagehide", title: "test2", persisted: true},
{type: "pageshow", title: "test1", persisted: true}];
gBrowser.goBack();
yield undefined;
gExpected = [{type: "pagehide", title: "test1", persisted: true},
{type: "pageshow", title: "test2", persisted: true}];
gBrowser.goForward();
yield undefined;
// Tests 3 + 4:
// Back/forward between a two-level deep iframed document and a simple
// document. Bfcache will be used and events should be dispatched to
// all frames.
var test3Doc = "data:text/html,<html><head><title>test3</title>" +
"</head><body>" +
"<iframe src='data:text/html," +
"<html><head><title>test3-nested1</title></head>" +
"<body>test3-nested1" +
"<iframe src=\"data:text/html," +
"<html><head><title>test3-nested2</title></head>" +
"<body>test3-nested2</body></html>\">" +
"</iframe>" +
"</body></html>'>" +
"</iframe>" +
"</body></html>";
gExpected = [{type: "pagehide", title: "test2", persisted: true},
{type: "load", title: "test3-nested2"},
{type: "pageshow", title: "test3-nested2", persisted: false},
{type: "load", title: "test3-nested1"},
{type: "pageshow", title: "test3-nested1", persisted: false},
{type: "load", title: "test3"},
{type: "pageshow", title: "test3", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test3Doc);
yield undefined;
var test4Doc = "data:text/html,<html><head><title>test4</title></head>" +
"<body>test4</body></html>";
gExpected = [{type: "pagehide", title: "test3", persisted: true},
{type: "pagehide", title: "test3-nested1", persisted: true},
{type: "pagehide", title: "test3-nested2", persisted: true},
{type: "load", title: "test4"},
{type: "pageshow", title: "test4", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test4Doc);
yield undefined;
gExpected = [{type: "pagehide", title: "test4", persisted: true},
{type: "pageshow", title: "test3-nested2", persisted: true},
{type: "pageshow", title: "test3-nested1", persisted: true},
{type: "pageshow", title: "test3", persisted: true}];
gBrowser.goBack();
yield undefined;
// This is where the two nested pagehide are not dispatched in bug 364461
gExpected = [{type: "pagehide", title: "test3", persisted: true},
{type: "pagehide", title: "test3-nested1", persisted: true},
{type: "pagehide", title: "test3-nested2", persisted: true},
{type: "pageshow", title: "test4", persisted: true}];
gBrowser.goForward();
yield undefined;
// Tests 5 + 6:
// Back/forward between a document containing an unload handler and a
// a simple document. Bfcache won't be used for the first one (see
// http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching).
var test5Doc = "data:text/html,<html><head><title>test5</title></head>" +
"<body onunload='while(false) { /* nop */ }'>" +
"test5</body></html>";
gExpected = [{type: "pagehide", title: "test4", persisted: true},
{type: "load", title: "test5"},
{type: "pageshow", title: "test5", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test5Doc);
yield undefined;
var test6Doc = "data:text/html,<html><head><title>test6</title></head>" +
"<body>test6</body></html>";
gExpected = [{type: "pagehide", title: "test5", persisted: false},
{type: "unload", title: "test5"},
{type: "load", title: "test6"},
{type: "pageshow", title: "test6", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test6Doc);
yield undefined;
gExpected = [{type: "pagehide", title: "test6", persisted: true},
{type: "load", title: "test5"},
{type: "pageshow", title: "test5", persisted: false}];
gBrowser.goBack();
yield undefined;
gExpected = [{type: "pagehide", title: "test5", persisted: false},
{type: "unload", title: "test5"},
{type: "pageshow", title: "test6", persisted: true}];
gBrowser.goForward();
yield undefined;
// Test 7:
// Testcase from https://bugzilla.mozilla.org/show_bug.cgi?id=384977#c10
// Check that navigation is not blocked after a document is restored
// from bfcache
var test7Doc = "data:text/html,<html><head><title>test7</title>" +
"</head><body>" +
"<iframe src='data:text/html," +
"<html><head><title>test7-nested1</title></head>" +
"<body>test7-nested1<br/>" +
"<a href=\"data:text/plain,aaa\" target=\"_top\">" +
"Click me, hit back, click me again</a>" +
"</body></html>'>" +
"</iframe>" +
"</body></html>";
gExpected = [{type: "pagehide", title: "test6", persisted: true},
{type: "load", title: "test7-nested1"},
{type: "pageshow", title: "test7-nested1", persisted: false},
{type: "load", title: "test7"},
{type: "pageshow", title: "test7", persisted: false}];
BrowserTestUtils.loadURI(gBrowser, test7Doc);
yield undefined;
// Simulates a click on the link inside the iframe
function clickIframeLink() {
var iframe = gBrowser.contentDocument.getElementsByTagName("iframe")[0];
var w = iframe.contentWindow;
var d = iframe.contentDocument;
var evt = d.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, w,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
d.getElementsByTagName("a")[0].dispatchEvent(evt);
}
gExpected = [{type: "pagehide", title: "test7", persisted: true},
{type: "pagehide", title: "test7-nested1", persisted: true},
{type: "load"},
{type: "pageshow", persisted: false}];
clickIframeLink();
yield undefined;
is(gBrowser.currentURI.spec, "data:text/plain,aaa",
"Navigation is blocked when clicking link");
gExpected = [{type: "pagehide", persisted: true},
{type: "pageshow", title: "test7-nested1", persisted: true},
{type: "pageshow", title: "test7", persisted: true}];
gBrowser.goBack();
yield undefined;
gExpected = [{type: "pagehide", title: "test7", persisted: true},
{type: "pagehide", title: "test7-nested1", persisted: true},
{type: "load"},
{type: "pageshow", persisted: false}];
clickIframeLink();
yield undefined;
is(gBrowser.currentURI.spec, "data:text/plain,aaa",
"Navigation is blocked when clicking link");
finish();
}
]]></script>
<browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
</window>