forked from mirrors/gecko-dev
***
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
126 lines
4.1 KiB
JavaScript
126 lines
4.1 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
*/
|
|
|
|
const OPEN_LOCATION_PREF = "browser.link.open_newwindow";
|
|
const NON_REMOTE_PAGE = "about:welcomeback";
|
|
|
|
const {PrivateBrowsingUtils} = ChromeUtils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
requestLongerTimeout(2);
|
|
|
|
function frame_script() {
|
|
content.document.body.innerHTML = `
|
|
<a href="http://example.com/" target="_blank" rel="opener" id="testAnchor">Open a window</a>
|
|
`;
|
|
|
|
let element = content.document.getElementById("testAnchor");
|
|
element.click();
|
|
}
|
|
|
|
/**
|
|
* Takes some browser in some window, and forces that browser
|
|
* to become non-remote, and then navigates it to a page that
|
|
* we're not supposed to be displaying remotely. Returns a
|
|
* Promise that resolves when the browser is no longer remote.
|
|
*/
|
|
function prepareNonRemoteBrowser(aWindow, browser) {
|
|
BrowserTestUtils.loadURI(browser, NON_REMOTE_PAGE);
|
|
return BrowserTestUtils.browserLoaded(browser);
|
|
}
|
|
|
|
registerCleanupFunction(() => {
|
|
Services.prefs.clearUserPref(OPEN_LOCATION_PREF);
|
|
});
|
|
|
|
/**
|
|
* Test that if we open a new tab from a link in a non-remote
|
|
* browser in an e10s window, that the new tab will load properly.
|
|
*/
|
|
add_task(async function test_new_tab() {
|
|
let normalWindow = await BrowserTestUtils.openNewBrowserWindow({
|
|
remote: true,
|
|
});
|
|
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({
|
|
remote: true,
|
|
private: true,
|
|
});
|
|
|
|
for (let testWindow of [normalWindow, privateWindow]) {
|
|
await promiseWaitForFocus(testWindow);
|
|
let testBrowser = testWindow.gBrowser.selectedBrowser;
|
|
info("Preparing non-remote browser");
|
|
await prepareNonRemoteBrowser(testWindow, testBrowser);
|
|
info("Non-remote browser prepared - sending frame script");
|
|
|
|
// Get our framescript ready
|
|
let mm = testBrowser.messageManager;
|
|
mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", true);
|
|
|
|
let tabOpenEvent = await waitForNewTabEvent(testWindow.gBrowser);
|
|
let newTab = tabOpenEvent.target;
|
|
|
|
await promiseTabLoadEvent(newTab);
|
|
|
|
// Our framescript opens to a web page which means that the
|
|
// tab should eventually become remote.
|
|
ok(newTab.linkedBrowser.isRemoteBrowser,
|
|
"The opened browser never became remote.");
|
|
|
|
testWindow.gBrowser.removeTab(newTab);
|
|
}
|
|
|
|
normalWindow.close();
|
|
privateWindow.close();
|
|
});
|
|
|
|
/**
|
|
* Test that if we open a new window from a link in a non-remote
|
|
* browser in an e10s window, that the new window is not an e10s
|
|
* window. Also tests with a private browsing window.
|
|
*/
|
|
add_task(async function test_new_window() {
|
|
let normalWindow = await BrowserTestUtils.openNewBrowserWindow({
|
|
remote: true,
|
|
}, true);
|
|
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({
|
|
remote: true,
|
|
private: true,
|
|
}, true);
|
|
|
|
// Fiddle with the prefs so that we open target="_blank" links
|
|
// in new windows instead of new tabs.
|
|
Services.prefs.setIntPref(OPEN_LOCATION_PREF,
|
|
Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW);
|
|
|
|
for (let testWindow of [normalWindow, privateWindow]) {
|
|
await promiseWaitForFocus(testWindow);
|
|
let testBrowser = testWindow.gBrowser.selectedBrowser;
|
|
await prepareNonRemoteBrowser(testWindow, testBrowser);
|
|
|
|
// Get our framescript ready
|
|
let mm = testBrowser.messageManager;
|
|
mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", true);
|
|
|
|
// Click on the link in the browser, and wait for the new window.
|
|
let [newWindow] =
|
|
await TestUtils.topicObserved("browser-delayed-startup-finished");
|
|
|
|
is(PrivateBrowsingUtils.isWindowPrivate(testWindow),
|
|
PrivateBrowsingUtils.isWindowPrivate(newWindow),
|
|
"Private browsing state of new window does not match the original!");
|
|
|
|
let newTab = newWindow.gBrowser.selectedTab;
|
|
|
|
await promiseTabLoadEvent(newTab);
|
|
|
|
// Our framescript opens to a web page which means that the
|
|
// tab should eventually become remote.
|
|
ok(newTab.linkedBrowser.isRemoteBrowser,
|
|
"The opened browser never became remote.");
|
|
newWindow.close();
|
|
}
|
|
|
|
normalWindow.close();
|
|
privateWindow.close();
|
|
});
|