Bug 1480244: Part 3b - Fix tests which rely on bad scoping assumptions for frame scripts. r=aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 03 Aug 2018 10:59:12 -0700
changeset 828430 2e65b3701fe59a10270663fd612b95cd6473522b
parent 828429 daf637730cfe4f8210a9f3c3a9fcc2322decb842
child 828431 93aa6a890d1a30dd044ad3d3c1acf69c82fcd9ce
push id118679
push usermaglione.k@gmail.com
push dateFri, 10 Aug 2018 21:19:41 +0000
reviewersaswan
bugs1480244
milestone63.0a1
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);