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
93 lines
3.6 KiB
JavaScript
93 lines
3.6 KiB
JavaScript
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
const TEST_URL = "data:text/html;charset=utf-8,<input%20id=txt>" +
|
|
"<input%20type=checkbox%20id=chk>";
|
|
|
|
const {SessionStore} = ChromeUtils.import("resource:///modules/sessionstore/SessionStore.jsm");
|
|
|
|
/**
|
|
* This test ensures that closing a window is a reversible action. We will
|
|
* close the the window, restore it and check that all data has been restored.
|
|
* This includes window-specific data as well as form data for tabs.
|
|
*/
|
|
function test() {
|
|
waitForExplicitFinish();
|
|
|
|
let uniqueKey = "bug 394759";
|
|
let uniqueValue = "unik" + Date.now();
|
|
let uniqueText = "pi != " + Math.random();
|
|
|
|
// Clear the list of closed windows.
|
|
forgetClosedWindows();
|
|
|
|
provideWindow(function onTestURLLoaded(newWin) {
|
|
BrowserTestUtils.addTab(newWin.gBrowser).linkedBrowser.stop();
|
|
|
|
// Mark the window with some unique data to be restored later on.
|
|
ss.setCustomWindowValue(newWin, uniqueKey, uniqueValue);
|
|
let [txt] = newWin.content.document.querySelectorAll("#txt");
|
|
txt.value = uniqueText;
|
|
|
|
let browser = newWin.gBrowser.selectedBrowser;
|
|
setInputChecked(browser, {id: "chk", checked: true}).then(() => {
|
|
BrowserTestUtils.closeWindow(newWin).then(() => {
|
|
is(ss.getClosedWindowCount(), 1,
|
|
"The closed window was added to Recently Closed Windows");
|
|
|
|
let data = SessionStore.getClosedWindowData(false);
|
|
|
|
// Verify that non JSON serialized data is the same as JSON serialized data.
|
|
is(JSON.stringify(data), ss.getClosedWindowData(),
|
|
"Non-serialized data is the same as serialized data");
|
|
|
|
ok(data[0].title == TEST_URL && JSON.stringify(data[0]).indexOf(uniqueText) > -1,
|
|
"The closed window data was stored correctly");
|
|
|
|
// Reopen the closed window and ensure its integrity.
|
|
let newWin2 = ss.undoCloseWindow(0);
|
|
|
|
ok(newWin2.isChromeWindow,
|
|
"undoCloseWindow actually returned a window");
|
|
is(ss.getClosedWindowCount(), 0,
|
|
"The reopened window was removed from Recently Closed Windows");
|
|
|
|
// SSTabRestored will fire more than once, so we need to make sure we count them.
|
|
let restoredTabs = 0;
|
|
let expectedTabs = data[0].tabs.length;
|
|
newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
|
|
++restoredTabs;
|
|
info("Restored tab " + restoredTabs + "/" + expectedTabs);
|
|
if (restoredTabs < expectedTabs) {
|
|
return;
|
|
}
|
|
|
|
is(restoredTabs, expectedTabs, "Correct number of tabs restored");
|
|
newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true);
|
|
|
|
is(newWin2.gBrowser.tabs.length, 2,
|
|
"The window correctly restored 2 tabs");
|
|
is(newWin2.gBrowser.currentURI.spec, TEST_URL,
|
|
"The window correctly restored the URL");
|
|
|
|
let chk;
|
|
[txt, chk] = newWin2.content.document.querySelectorAll("#txt, #chk");
|
|
ok(txt.value == uniqueText && chk.checked,
|
|
"The window correctly restored the form");
|
|
is(ss.getCustomWindowValue(newWin2, uniqueKey), uniqueValue,
|
|
"The window correctly restored the data associated with it");
|
|
|
|
// Clean up.
|
|
BrowserTestUtils.closeWindow(newWin2).then(finish);
|
|
}, true);
|
|
});
|
|
});
|
|
}, TEST_URL);
|
|
}
|
|
|
|
function setInputChecked(browser, data) {
|
|
return sendMessage(browser, "ss-test:setInputChecked", data);
|
|
}
|