Bug 1377578 - Fix TPS to keep it's addons and tabs tests passing r?markh. draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Fri, 30 Jun 2017 15:15:24 -0700
changeset 602926 4e0796ffb2278fc1da34834b237865211b6907b3
parent 602783 d865e836f74aa1d4acf349c0a013895201ccada6
child 635775 a8855333040331d29280a70e838c18712cfaaa26
push id66615
push userbmo:tchiovoloni@mozilla.com
push dateFri, 30 Jun 2017 22:24:20 +0000
reviewersmarkh
bugs1377578
milestone56.0a1
Bug 1377578 - Fix TPS to keep it's addons and tabs tests passing r?markh. MozReview-Commit-ID: LkFyMrD12Hk
services/sync/tps/extensions/tps/resource/modules/addons.jsm
services/sync/tps/extensions/tps/resource/modules/tabs.jsm
--- a/services/sync/tps/extensions/tps/resource/modules/addons.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/addons.jsm
@@ -113,15 +113,13 @@ Addon.prototype = {
     if (flag == STATE_ENABLED) {
       userDisabled = false;
     } else if (flag == STATE_DISABLED) {
       userDisabled = true;
     } else {
       throw new Error("Unknown flag to setEnabled: " + flag);
     }
 
-    let cb = Async.makeSpinningCallback();
-    AddonUtils.updateUserDisabled(this.addon, userDisabled, cb);
-    cb.wait();
+    AddonUtils.updateUserDisabled(this.addon, userDisabled);
 
     return true;
   }
 };
--- a/services/sync/tps/extensions/tps/resource/modules/tabs.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/tabs.jsm
@@ -8,34 +8,52 @@
    and where imported. */
 
 const EXPORTED_SYMBOLS = ["BrowserTabs"];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://services-sync/main.js");
 
+// Unfortunately, due to where TPS is run, we can't directly reuse the logic from
+// BrowserTestUtils.jsm. Moreover, we can't resolve the URI it loads the content
+// frame script from ("chrome://mochikit/content/tests/BrowserTestUtils/content-utils.js"),
+// hence the hackiness here and in BrowserTabs.Add.
+Cc["@mozilla.org/globalmessagemanager;1"]
+.getService(Ci.nsIMessageListenerManager)
+.loadFrameScript("data:application/javascript;charset=utf-8," + encodeURIComponent(`
+  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+  addEventListener("load", function(event) {
+    let subframe = event.target != content.document;
+    sendAsyncMessage("tps:loadEvent", {subframe: subframe, url: event.target.documentURI});
+  }, true)`), true);
+
 var BrowserTabs = {
   /**
    * Add
    *
    * Opens a new tab in the current browser window for the
    * given uri.  Throws on error.
    *
    * @param uri The uri to load in the new tab
    * @return nothing
    */
   Add(uri, fn) {
+
     // Open the uri in a new tab in the current browser window, and calls
     // the callback fn from the tab's onload handler.
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                .getService(Ci.nsIWindowMediator);
     let mainWindow = wm.getMostRecentWindow("navigator:browser");
     let browser = mainWindow.getBrowser();
-    browser.addEventListener("load", fn, { once: true });
+    let mm = browser.ownerGlobal.messageManager;
+    mm.addMessageListener("tps:loadEvent", function onLoad(msg) {
+      mm.removeMessageListener("tps:loadEvent", onLoad);
+      fn();
+    });
     let newtab = browser.addTab(uri);
     browser.selectedTab = newtab;
   },
 
   /**
    * Find
    *
    * Finds the specified uri and title in Weave's list of remote tabs