mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 05:08:36 +02:00
***
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
136 lines
3.8 KiB
JavaScript
136 lines
3.8 KiB
JavaScript
"use strict";
|
|
|
|
var {WebNavigation} = ChromeUtils.import("resource://gre/modules/WebNavigation.jsm");
|
|
|
|
const BASE = "http://example.com/browser/toolkit/modules/tests/browser";
|
|
const URL = BASE + "/file_WebNavigation_page1.html";
|
|
const FRAME = BASE + "/file_WebNavigation_page2.html";
|
|
const FRAME2 = BASE + "/file_WebNavigation_page3.html";
|
|
|
|
const EVENTS = [
|
|
"onBeforeNavigate",
|
|
"onCommitted",
|
|
"onDOMContentLoaded",
|
|
"onCompleted",
|
|
"onErrorOccurred",
|
|
"onReferenceFragmentUpdated",
|
|
];
|
|
|
|
const REQUIRED = [
|
|
"onBeforeNavigate",
|
|
"onCommitted",
|
|
"onDOMContentLoaded",
|
|
"onCompleted",
|
|
];
|
|
|
|
var expectedBrowser;
|
|
var received = [];
|
|
var completedResolve;
|
|
var waitingURL, waitingEvent;
|
|
var rootWindowID;
|
|
|
|
function gotEvent(event, details) {
|
|
if (!details.url.startsWith(BASE)) {
|
|
return;
|
|
}
|
|
info(`Got ${event} ${details.url} ${details.windowId} ${details.parentWindowId}`);
|
|
|
|
is(details.browser, expectedBrowser, "correct <browser> element");
|
|
|
|
received.push({url: details.url, event});
|
|
|
|
if (typeof(rootWindowID) == "undefined") {
|
|
rootWindowID = details.windowId;
|
|
}
|
|
|
|
if (details.url == URL) {
|
|
is(details.windowId, rootWindowID, "root window ID correct");
|
|
} else {
|
|
is(details.parentWindowId, rootWindowID, "parent window ID correct");
|
|
isnot(details.windowId, rootWindowID, "window ID probably okay");
|
|
}
|
|
|
|
isnot(details.windowId, undefined);
|
|
isnot(details.parentWindowId, undefined);
|
|
|
|
if (details.url == waitingURL && event == waitingEvent) {
|
|
completedResolve();
|
|
}
|
|
}
|
|
|
|
function loadViaFrameScript(url, event, script) {
|
|
// Loading via a frame script ensures that the chrome process never
|
|
// "gets ahead" of frame scripts in non-e10s mode.
|
|
received = [];
|
|
waitingURL = url;
|
|
waitingEvent = event;
|
|
expectedBrowser.messageManager.loadFrameScript("data:," + script, false);
|
|
return new Promise(resolve => { completedResolve = resolve; });
|
|
}
|
|
|
|
add_task(async function webnav_ordering() {
|
|
let listeners = {};
|
|
for (let event of EVENTS) {
|
|
listeners[event] = gotEvent.bind(null, event);
|
|
WebNavigation[event].addListener(listeners[event]);
|
|
}
|
|
|
|
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
|
let browser = gBrowser.selectedBrowser;
|
|
expectedBrowser = browser;
|
|
|
|
await BrowserTestUtils.browserLoaded(browser);
|
|
|
|
await loadViaFrameScript(URL, "onCompleted", `content.location = "${URL}";`);
|
|
|
|
function checkRequired(url) {
|
|
for (let event of REQUIRED) {
|
|
let found = false;
|
|
for (let r of received) {
|
|
if (r.url == url && r.event == event) {
|
|
found = true;
|
|
}
|
|
}
|
|
ok(found, `Received event ${event} from ${url}`);
|
|
}
|
|
}
|
|
|
|
checkRequired(URL);
|
|
checkRequired(FRAME);
|
|
|
|
function checkBefore(action1, action2) {
|
|
function find(action) {
|
|
for (let i = 0; i < received.length; i++) {
|
|
if (received[i].url == action.url && received[i].event == action.event) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
let index1 = find(action1);
|
|
let index2 = find(action2);
|
|
ok(index1 != -1, `Action ${JSON.stringify(action1)} happened`);
|
|
ok(index2 != -1, `Action ${JSON.stringify(action2)} happened`);
|
|
ok(index1 < index2, `Action ${JSON.stringify(action1)} happened before ${JSON.stringify(action2)}`);
|
|
}
|
|
|
|
checkBefore({url: URL, event: "onCommitted"}, {url: FRAME, event: "onBeforeNavigate"});
|
|
checkBefore({url: FRAME, event: "onCompleted"}, {url: URL, event: "onCompleted"});
|
|
|
|
await loadViaFrameScript(FRAME2, "onCompleted", `content.frames[0].location = "${FRAME2}";`);
|
|
|
|
checkRequired(FRAME2);
|
|
|
|
await loadViaFrameScript(FRAME2 + "#ref", "onReferenceFragmentUpdated",
|
|
"content.frames[0].document.getElementById('elt').click();");
|
|
|
|
info("Received onReferenceFragmentUpdated from FRAME2");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
for (let event of EVENTS) {
|
|
WebNavigation[event].removeListener(listeners[event]);
|
|
}
|
|
});
|
|
|