Bug 1480244: Part 3b - Fix tests which rely on bad scoping assumptions for frame scripts. r=aswan
With the new loading model for frame scripts, lexical variables defined in a
global frame script are not available to other frame scripts.
Additionally, scripts loaded into a context object by the subscript loader
should not depend on being able to access properties of the message manager as
if they were globals.
MozReview-Commit-ID: 6QEyA1sBVOV
--- a/dom/browser-element/BrowserElementChild.js
+++ b/dom/browser-element/BrowserElementChild.js
@@ -36,24 +36,24 @@ var BrowserElementIsReady;
debug(`Might load BE scripts: BEIR: ${BrowserElementIsReady}`);
if (!BrowserElementIsReady) {
debug("Loading BE scripts")
if (!("BrowserElementIsPreloaded" in this)) {
if(Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
// general content apps
if (isTopBrowserElement(docShell)) {
- Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementCopyPaste.js");
+ Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementCopyPaste.js", this);
}
} else {
// rocketbar in system app and other in-process case (ex. B2G desktop client)
- Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementCopyPaste.js");
+ Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementCopyPaste.js", this);
}
- Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementChildPreload.js");
+ Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementChildPreload.js", this);
}
function onDestroy() {
removeMessageListener("browser-element-api:destroy", onDestroy);
if (api) {
api.destroy();
}
--- a/modules/libpref/test/unit_ipc/test_sharedMap.js
+++ b/modules/libpref/test/unit_ipc/test_sharedMap.js
@@ -16,18 +16,18 @@ ExtensionTestUtils.init(this);
let contentPage;
const {prefs} = Services;
const defaultPrefs = prefs.getDefaultBranch("");
const FRAME_SCRIPT_INIT = `
ChromeUtils.import("resource://gre/modules/Services.jsm");
- const {prefs} = Services;
- const defaultPrefs = prefs.getDefaultBranch("");
+ var {prefs} = Services;
+ var defaultPrefs = prefs.getDefaultBranch("");
`;
function try_(fn) {
try {
return fn();
} catch (e) {
return undefined;
}
--- a/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js
+++ b/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js
@@ -3,24 +3,29 @@
* Generally it just delegates to EventUtils.js.
*/
ChromeUtils.import("resource://gre/modules/Services.jsm");
// Set up a dummy environment so that EventUtils works. We need to be careful to
// pass a window object into each EventUtils method we call rather than having
// it rely on the |window| global.
-var EventUtils = {};
+var EventUtils = {
+ get KeyboardEvent() {
+ return content.KeyboardEvent;
+ },
+ // EventUtils' `sendChar` function relies on the navigator to synthetize events.
+ get navigator() {
+ return content.navigator;
+ },
+};
EventUtils.window = {};
EventUtils.parent = EventUtils.window;
EventUtils._EU_Ci = Ci;
EventUtils._EU_Cc = Cc;
-// EventUtils' `sendChar` function relies on the navigator to synthetize events.
-EventUtils.navigator = content.document.defaultView.navigator;
-EventUtils.KeyboardEvent = content.document.defaultView.KeyboardEvent;
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
addMessageListener("Test:SynthesizeMouse", (message) => {
let data = message.data;
let target = data.target;
if (typeof target == "string") {
target = content.document.querySelector(target);