Bug 1480244: Part 3b - Fix tests which rely on bad scoping assumptions for frame scripts. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 03 Aug 2018 10:59:12 -0700
changeset 431545 7aa3ada140f74e48947a4c69a1fd53b84b39a51e
parent 431544 d17af8236abe8b1a53674955d2baee603abc2b62
child 431546 7d6c6e052339d90767d18403826f0a316521074f
push id34443
push usercsabou@mozilla.com
push dateWed, 15 Aug 2018 00:53:32 +0000
treeherdermozilla-central@b80906e2fbc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1480244
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/browser-element/BrowserElementChild.js
modules/libpref/test/unit_ipc/test_sharedMap.js
testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js
--- 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);