Bug 1377578 - Fix TPS to keep it's addons and tabs tests passing r?markh.
MozReview-Commit-ID: LkFyMrD12Hk
--- 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