Bug 1219101 more updates to current infra for socialapi tests, fixes intermittent bug 1219101, r=markh
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 20 Jul 2016 13:53:09 -0700
changeset 346128 cd5af43f84b11096643c2418d3af263cf92c7bdd
parent 346127 115209d4f543a66994fa68ee9a187490cc60c17d
child 346129 67186c2d647ed2807eacc51cc834ca7932d38fba
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1219101
milestone50.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 1219101 more updates to current infra for socialapi tests, fixes intermittent bug 1219101, r=markh MozReview-Commit-ID: JOwtSkjIwQ1
browser/base/content/test/social/browser_addons.js
browser/base/content/test/social/browser_blocklist.js
browser/base/content/test/social/browser_share.js
browser/base/content/test/social/browser_social_activation.js
browser/base/content/test/social/browser_social_chatwindow.js
browser/base/content/test/social/browser_social_chatwindowfocus.js
browser/base/content/test/social/browser_social_contextmenu.js
browser/base/content/test/social/browser_social_errorPage.js
browser/base/content/test/social/browser_social_flyout.js
browser/base/content/test/social/browser_social_marks.js
browser/base/content/test/social/browser_social_marks_context.js
browser/base/content/test/social/browser_social_multiprovider.js
browser/base/content/test/social/browser_social_sidebar.js
browser/base/content/test/social/browser_social_status.js
browser/base/content/test/social/browser_social_window.js
browser/base/content/test/social/head.js
browser/base/content/test/social/social_activate_basic.html
--- a/browser/base/content/test/social/browser_addons.js
+++ b/browser/base/content/test/social/browser_addons.js
@@ -19,16 +19,20 @@ var manifestUpgrade = { // used for test
   origin: "https://test2.example.com",
   sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html",
   iconURL: "https://test2.example.com/browser/browser/base/content/test/general/moz.png",
   version: "1.0"
 };
 
 function test() {
   waitForExplicitFinish();
+  PopupNotifications.panel.setAttribute("animate", "false");
+  registerCleanupFunction(function () {
+    PopupNotifications.panel.removeAttribute("animate");
+  });
 
   let prefname = getManifestPrefname(manifest);
   // ensure that manifest2 is NOT showing as builtin
   is(SocialService.getOriginActivationType(manifest.origin), "foreign", "manifest is foreign");
   is(SocialService.getOriginActivationType(manifest2.origin), "foreign", "manifest2 is foreign");
 
   Services.prefs.setBoolPref("social.remote-install.enabled", true);
   runSocialTests(tests, undefined, undefined, function () {
@@ -184,17 +188,17 @@ var tests = {
         Services.prefs.clearUserPref(prefname);
         next();
       });
     });
   },
   testDirectoryInstall: function(next) {
     AddonManager.addAddonListener(installListener(next, manifest2));
 
-    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
       let panel = document.getElementById("servicesInstall-notification");
       info("servicesInstall-notification panel opened");
       panel.button.click();
     });
 
     let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
     Services.prefs.setCharPref("social.directories", manifest2.origin);
     is(SocialService.getOriginActivationType(manifest2.origin), "directory", "testing directory install");
--- a/browser/base/content/test/social/browser_blocklist.js
+++ b/browser/base/content/test/social/browser_blocklist.js
@@ -17,49 +17,79 @@ var manifest = { // normal provider
 };
 var manifest_bad = { // normal provider
   name: "provider blocked",
   origin: "https://test1.example.com",
   sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html",
   iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png"
 };
 
+// blocklist testing
+function updateBlocklist() {
+  var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
+                          .getService(Ci.nsITimerCallback);
+  let promise = promiseObserverNotified("blocklist-updated");
+  blocklistNotifier.notify(null);
+  return promise;
+}
+
+var _originalTestBlocklistURL = null;
+function setAndUpdateBlocklist(aURL) {
+  if (!_originalTestBlocklistURL)
+    _originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
+  Services.prefs.setCharPref("extensions.blocklist.url", aURL);
+  return updateBlocklist();
+}
+
+function resetBlocklist() {
+  // XXX - this has "forked" from the head.js helpers in our parent directory :(
+  // But let's reuse their blockNoPlugins.xml.  Later, we should arrange to
+  // use their head.js helpers directly
+  let noBlockedURL = "http://example.com/browser/browser/base/content/test/plugins/blockNoPlugins.xml";
+  return new Promise(resolve => {
+    setAndUpdateBlocklist(noBlockedURL).then(() => {
+      Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL);
+      resolve();
+    });
+  });
+}
+
 function test() {
   waitForExplicitFinish();
   // turn on logging for nsBlocklistService.js
   Services.prefs.setBoolPref("extensions.logging.enabled", true);
   registerCleanupFunction(function () {
     Services.prefs.clearUserPref("extensions.logging.enabled");
   });
 
   runSocialTests(tests, undefined, undefined, function () {
-    resetBlocklist(finish); //restore to original pref
+    resetBlocklist().then(finish); //restore to original pref
   });
 }
 
 var tests = {
   testSimpleBlocklist: function(next) {
     // this really just tests adding and clearing our blocklist for later tests
-    setAndUpdateBlocklist(blocklistURL, function() {
+    setAndUpdateBlocklist(blocklistURL).then(() => {
       ok(Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocking 'blocked'");
       ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest)), "not blocking 'good'");
-      resetBlocklist(function() {
+      resetBlocklist().then(() => {
         ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocklist cleared");
         next();
       });
     });
   },
   testAddingNonBlockedProvider: function(next) {
     function finishTest(isgood) {
       ok(isgood, "adding non-blocked provider ok");
       Services.prefs.clearUserPref("social.manifest.good");
-      resetBlocklist(next);
+      resetBlocklist().then(next);
     }
     setManifestPref("social.manifest.good", manifest);
-    setAndUpdateBlocklist(blocklistURL, function() {
+    setAndUpdateBlocklist(blocklistURL).then(() => {
       try {
         SocialService.addProvider(manifest, function(provider) {
           try {
             SocialService.disableProvider(provider.origin, function() {
               ok(true, "added and removed provider");
               finishTest(true);
             });
           } catch(e) {
@@ -72,65 +102,55 @@ var tests = {
         finishTest(false);
       }
     });
   },
   testAddingBlockedProvider: function(next) {
     function finishTest(good) {
       ok(good, "Unable to add blocklisted provider");
       Services.prefs.clearUserPref("social.manifest.blocked");
-      resetBlocklist(next);
+      resetBlocklist().then(next);
     }
     setManifestPref("social.manifest.blocked", manifest_bad);
-    setAndUpdateBlocklist(blocklistURL, function() {
+    setAndUpdateBlocklist(blocklistURL).then(() => {
       try {
         SocialService.addProvider(manifest_bad, function(provider) {
           SocialService.disableProvider(provider.origin, function() {
             ok(false, "SocialService.addProvider should throw blocklist exception");
             finishTest(false);
           });
         });
       } catch(e) {
         ok(true, "SocialService.addProvider should throw blocklist exception: " + e);
         finishTest(true);
       }
     });
   },
   testInstallingBlockedProvider: function(next) {
     function finishTest(good) {
-      ok(good, "Unable to add blocklisted provider");
-      Services.prefs.clearUserPref("social.whitelist");
-      resetBlocklist(next);
+      ok(good, "Unable to install blocklisted provider");
+      resetBlocklist().then(next);
     }
     let activationURL = manifest_bad.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
-      let doc = tab.linkedBrowser.contentDocument;
-      let installFrom = doc.nodePrincipal.origin;
-      // whitelist to avoid the 3rd party install dialog, we only want to test
-      // the blocklist inside installProvider.
-      Services.prefs.setCharPref("social.whitelist", installFrom);
-      setAndUpdateBlocklist(blocklistURL, function() {
-        try {
-          // expecting an exception when attempting to install a hard blocked
-          // provider
-          let data = {
-            origin: doc.nodePrincipal.origin,
-            url: doc.location.href,
-            manifest: manifest_bad,
-            window: window
-          }
-          Social.installProvider(data, function(addonManifest) {
-            gBrowser.removeTab(tab);
-            finishTest(false);
-          });
-        } catch(e) {
-          gBrowser.removeTab(tab);
-          finishTest(true);
+    setAndUpdateBlocklist(blocklistURL).then(() => {
+      try {
+        // expecting an exception when attempting to install a hard blocked
+        // provider
+        let data = {
+          origin: manifest_bad.origin,
+          url: activationURL,
+          manifest: manifest_bad,
+          window: window
         }
-      });
+        Social.installProvider(data, function(addonManifest) {
+          finishTest(false);
+        });
+      } catch(e) {
+        finishTest(true);
+      }
     });
   },
   testBlockingExistingProvider: function(next) {
     let listener = {
       _window: null,
       onOpenWindow: function(aXULWindow) {
         Services.wm.removeListener(this);
         this._window = aXULWindow;
--- a/browser/base/content/test/social/browser_share.js
+++ b/browser/base/content/test/social/browser_share.js
@@ -162,28 +162,27 @@ var tests = {
     // starting from *some* page, share should be visible and enabled when
     // activating provider
     // initialize the button into the navbar
     CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
     // ensure correct state
     SocialUI.onCustomizeEnd(window);
 
     let testData = corpus[0];
-    addTab(testData.url, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, testData.url).then(tab => {
       SocialService.addProvider(manifest, function(provider) {
         is(SocialUI.enabled, true, "SocialUI is enabled");
         checkSocialUI();
         // share should not be enabled since we only have about:blank page
         let shareButton = SocialShare.shareButton;
         // verify the attribute for proper css
         ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
         // button should be visible
         is(shareButton.hidden, false, "share button is visible");
-        gBrowser.removeTab(tab);
-        next();
+        BrowserTestUtils.removeTab(tab).then(next);
       });
     });
   },
   testSharePage: function(next) {
     let provider = Social._getProviderFromOrigin(manifest.origin);
 
     let testTab;
     let testIndex = 0;
@@ -191,32 +190,33 @@ var tests = {
 
     // initialize the button into the navbar
     CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
     // ensure correct state
     SocialUI.onCustomizeEnd(window);
 
     let mm = getGroupMessageManager("social");
     mm.addMessageListener("sharedata", function handler(msg) {
-      gBrowser.removeTab(testTab);
-      hasoptions(testData.options, JSON.parse(msg.data));
-      testData = corpus[testIndex++];
-      BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },"share panel closed").then(() => {
-        if (testData) {
-          runOneTest();
-        } else {
-          mm.removeMessageListener("sharedata", handler);
-          SocialService.disableProvider(manifest.origin, next);
-        }
+      BrowserTestUtils.removeTab(testTab).then(() => {
+        hasoptions(testData.options, JSON.parse(msg.data));
+        testData = corpus[testIndex++];
+        BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },"share panel closed").then(() => {
+          if (testData) {
+            runOneTest();
+          } else {
+            mm.removeMessageListener("sharedata", handler);
+            SocialService.disableProvider(manifest.origin, next);
+          }
+        });
+        SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
       });
-      SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
     });
 
     function runOneTest() {
-      addTab(testData.url, function(tab) {
+      BrowserTestUtils.openNewForegroundTab(gBrowser, testData.url).then(tab => {
         testTab = tab;
 
         let shareButton = SocialShare.shareButton;
         // verify the attribute for proper css
         ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
         // button should be visible
         is(shareButton.hidden, false, "share button is visible");
 
@@ -279,25 +279,26 @@ var tests = {
         }
       });
 
       let mm = getGroupMessageManager("social");
       mm.addMessageListener("sharedata", function handler(msg) {
         is(msg.data, expecting, "microformats data ok");
         BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
                                           "share panel closed").then(() => {
-          gBrowser.removeTab(testTab);
           mm.removeMessageListener("sharedata", handler);
-          SocialService.disableProvider(manifest.origin, next);
+          BrowserTestUtils.removeTab(testTab).then(() => {
+            SocialService.disableProvider(manifest.origin, next);
+          });
         });
         SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
       });
 
       let url = "https://example.com/browser/browser/base/content/test/social/microformats.html"
-      addTab(url, function(tab) {
+      BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
         testTab = tab;
 
         let shareButton = SocialShare.shareButton;
         // verify the attribute for proper css
         ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
         // button should be visible
         is(shareButton.hidden, false, "share button is visible");
 
@@ -316,39 +317,39 @@ var tests = {
     SocialShare._createFrame();
     let iframe = SocialShare.iframe;
 
     // initialize the button into the navbar
     CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
     // ensure correct state
     SocialUI.onCustomizeEnd(window);
 
-    ensureEventFired(iframe, "load").then(() => {
+    ensureFrameLoaded(iframe).then(() => {
       let subframe = iframe.contentDocument.getElementById("activation-frame");
       ensureFrameLoaded(subframe, activationPage).then(() => {
         is(subframe.contentDocument.location.href, activationPage, "activation page loaded");
         promiseObserverNotified("social:provider-enabled").then(() => {
           let mm = getGroupMessageManager("social");
           mm.addMessageListener("sharedata", function handler(msg) {
             ok(true, "share completed");
 
             BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
                                               "share panel closed").then(() => {
-              ensureBrowserTabClosed(testTab).then(() => {
+              BrowserTestUtils.removeTab(testTab).then(() => {
                 mm.removeMessageListener("sharedata", handler);
                 SocialService.uninstallProvider(manifest.origin, next);
               });
             });
             SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
           });
         });
         sendActivationEvent(subframe);
       });
     });
-    addTab(activationPage, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationPage).then(tab => {
       let shareButton = SocialShare.shareButton;
       // verify the attribute for proper css
       ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
       // button should be visible
       is(shareButton.hidden, false, "share button is visible");
 
       testTab = tab;
       SocialShare.sharePage();
@@ -358,31 +359,31 @@ var tests = {
     let testTab;
     // initialize the button into the navbar
     CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
     // ensure correct state
     SocialUI.onCustomizeEnd(window);
     SocialShare._createFrame();
 
     SocialService.addProvider(manifest, () => {
-      addTab(activationPage, (tab) => {
-        ensureEventFired(SocialShare.iframe, "load").then(() => {
+      BrowserTestUtils.openNewForegroundTab(gBrowser, activationPage).then(tab => {
+        ensureFrameLoaded(SocialShare.iframe).then(() => {
           // send keys to the input field.  An unexpected failure will happen
           // if the onbeforeunload handler is fired.
           EventUtils.sendKey("f");
           EventUtils.sendKey("a");
           EventUtils.sendKey("i");
           EventUtils.sendKey("l");
   
           SocialShare.panel.addEventListener("popuphidden", function hidden(evt) {
             SocialShare.panel.removeEventListener("popuphidden", hidden);
             let topwin = Services.wm.getMostRecentWindow(null);
             is(topwin, window, "no dialog is open");
 
-            ensureBrowserTabClosed(testTab).then(() => {
+            BrowserTestUtils.removeTab(testTab).then(() => {
               SocialService.disableProvider(manifest.origin, next);
             });
           });
           SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
         });
 
         let shareButton = SocialShare.shareButton;
         // verify the attribute for proper css
--- a/browser/base/content/test/social/browser_social_activation.js
+++ b/browser/base/content/test/social/browser_social_activation.js
@@ -9,98 +9,79 @@
 //
 thisTestLeaksUncaughtRejectionsAndShouldBeFixed("TypeError: Assert is null");
 
 
 var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
 
 var tabsToRemove = [];
 
-
-function removeAllProviders(callback) {
-  // all the providers may have been added.
-  function removeProviders() {
-    if (Social.providers.length < 1) {
-      executeSoon(function() {
-        is(Social.providers.length, 0, "all providers removed");
-        executeSoon(callback);
-      });
-      return;
-    }
-
+function removeProvider(provider) {
+  return new Promise(resolve => {
     // a full install sets the manifest into a pref, addProvider alone doesn't,
     // make sure we uninstall if the manifest was added.
-    if (Social.providers[0].manifest) {
-      SocialService.uninstallProvider(Social.providers[0].origin, removeProviders);
+    if (provider.manifest) {
+      SocialService.uninstallProvider(provider.origin, resolve);
     } else {
-      SocialService.disableProvider(Social.providers[0].origin, removeProviders);
+      SocialService.disableProvider(provider.origin, resolve);
     }
-  }
-  removeProviders();
+  });
 }
 
 function postTestCleanup(callback) {
-  // any tabs opened by the test.
-  for (let tab of tabsToRemove)
-    gBrowser.removeTab(tab);
-  tabsToRemove = [];
-  // theses tests use the notification panel but don't bother waiting for it
-  // to fully open - the end result is that the panel might stay open
-  //SocialUI.activationPanel.hidePopup();
-
-  // all the providers may have been added.
-  removeAllProviders(callback);
+  Task.spawn(function () {
+    // any tabs opened by the test.
+    for (let tab of tabsToRemove) {
+      yield BrowserTestUtils.removeTab(tab);
+    }
+    tabsToRemove = [];
+    // all the providers may have been added.
+    while (Social.providers.length > 0) {
+      yield removeProvider(Social.providers[0]);
+    }
+  }).then(callback);
 }
 
-function addTab(url, callback) {
-  let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true});
-  tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
-    tab.linkedBrowser.removeEventListener("load", tabLoad, true);
-    tabsToRemove.push(tab);
-    executeSoon(function() {callback(tab)});
-  }, true);
+function newTab(url) {
+  return new Promise(resolve => {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
+      tabsToRemove.push(tab);
+      resolve(tab);
+    });
+  });
 }
 
 function sendActivationEvent(tab, callback, nullManifest) {
   // hack Social.lastEventReceived so we don't hit the "too many events" check.
   Social.lastEventReceived = 0;
   BrowserTestUtils.synthesizeMouseAtCenter("#activation", {}, tab.linkedBrowser);
   executeSoon(callback);
 }
 
 function activateProvider(domain, callback, nullManifest) {
   let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_basic.html"
-  addTab(activationURL, function(tab) {
+  newTab(activationURL).then(tab => {
     sendActivationEvent(tab, callback, nullManifest);
   });
 }
 
 function activateIFrameProvider(domain, callback) {
   let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_iframe.html"
-  addTab(activationURL, function(tab) {
+  newTab(activationURL).then(tab => {
     sendActivationEvent(tab, callback, false);
   });
 }
 
-function waitForProviderLoad(cb) {
-    waitForCondition(function() {
-      let sbrowser = document.getElementById("social-sidebar-browser");
-      let provider = SocialSidebar.provider;
-      let postActivation = provider && gBrowser.currentURI &&
-                            gBrowser.currentURI.spec == provider.origin + "/browser/browser/base/content/test/social/social_postActivation.html";
-
-      return postActivation && sbrowser.docShellIsActive;
-    }, function() {
-      // executeSoon to let the browser UI observers run first
-      executeSoon(cb);
-    },
-    "waitForProviderLoad: provider was not loaded");
+function waitForProviderLoad(origin) {
+  return Promise.all([
+    ensureFrameLoaded(gBrowser, origin + "/browser/browser/base/content/test/social/social_postActivation.html"),
+    ensureFrameLoaded(SocialSidebar.browser)
+  ]);
 }
 
-
 function getAddonItemInList(aId, aList) {
   var item = aList.firstChild;
   while (item) {
     if ("mAddon" in item && item.mAddon.id == aId) {
       aList.ensureElementIsVisible(item);
       return item;
     }
     item = item.nextSibling;
@@ -128,32 +109,30 @@ function clickAddonRemoveButton(tab, aCa
     });
 
     BrowserTestUtils.synthesizeMouseAtCenter(button, {}, tab.linkedBrowser);
   });
 }
 
 function activateOneProvider(manifest, finishActivation, aCallback) {
   let panel = document.getElementById("servicesInstall-notification");
-  PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
-    PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
+  BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
     ok(!panel.hidden, "servicesInstall-notification panel opened");
     if (finishActivation)
       panel.button.click();
     else
       panel.closebutton.click();
   });
-  PopupNotifications.panel.addEventListener("popuphidden", function _hidden() {
-    PopupNotifications.panel.removeEventListener("popuphidden", _hidden);
+  BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden").then(() => {
     ok(panel.hidden, "servicesInstall-notification panel hidden");
     if (!finishActivation) {
       ok(panel.hidden, "activation panel is not showing");
       executeSoon(aCallback);
     } else {
-      waitForProviderLoad(function() {
+      waitForProviderLoad(manifest.origin).then(() => {
         is(SocialSidebar.provider.origin, manifest.origin, "new provider is active");
         ok(SocialSidebar.opened, "sidebar is open");
         checkSocialUI();
         executeSoon(aCallback);
       });
     }
   });
 
@@ -182,52 +161,56 @@ var gProviders = [
     origin: "https://test2.example.com",
     sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar_empty.html?provider2",
     iconURL: "chrome://branding/content/about-logo.png"
   }
 ];
 
 
 function test() {
+  PopupNotifications.panel.setAttribute("animate", "false");
+  registerCleanupFunction(function () {
+    PopupNotifications.panel.removeAttribute("animate");
+  });
   waitForExplicitFinish();
   runSocialTests(tests, undefined, postTestCleanup);
 }
 
 var tests = {
   testActivationWrongOrigin: function(next) {
     // At this stage none of our providers exist, so we expect failure.
     Services.prefs.setBoolPref("social.remote-install.enabled", false);
     activateProvider(gTestDomains[0], function() {
       is(SocialUI.enabled, false, "SocialUI is not enabled");
       let panel = document.getElementById("servicesInstall-notification");
       ok(panel.hidden, "activation panel still hidden");
       checkSocialUI();
       Services.prefs.clearUserPref("social.remote-install.enabled");
-      removeAllProviders(next);
+      next();
     });
   },
   
   testIFrameActivation: function(next) {
     activateIFrameProvider(gTestDomains[0], function() {
       is(SocialUI.enabled, false, "SocialUI is not enabled");
       ok(!SocialSidebar.provider, "provider is not installed");
       let panel = document.getElementById("servicesInstall-notification");
       ok(panel.hidden, "activation panel still hidden");
       checkSocialUI();
-      removeAllProviders(next);
+      next();
     });
   },
   
   testActivationFirstProvider: function(next) {
     // first up we add a manifest entry for a single provider.
     activateOneProvider(gProviders[0], false, function() {
       // we deactivated leaving no providers left, so Social is disabled.
       ok(!SocialSidebar.provider, "should be no provider left after disabling");
       checkSocialUI();
-      removeAllProviders(next);
+      next();
     });
   },
   
   testActivationMultipleProvider: function(next) {
     // The trick with this test is to make sure that Social.providers[1] is
     // the current provider when doing the undo - this makes sure that the
     // Social code doesn't fallback to Social.providers[0], which it will
     // do in some cases (but those cases do not include what this test does)
@@ -235,68 +218,57 @@ var tests = {
     SocialService.addProvider(gProviders[0], function() {
       SocialService.addProvider(gProviders[1], function() {
         checkSocialUI();
         // activate the last provider.
         activateOneProvider(gProviders[2], false, function() {
           // we deactivated - the first provider should be enabled.
           is(SocialSidebar.provider.origin, Social.providers[1].origin, "original provider should have been reactivated");
           checkSocialUI();
-          removeAllProviders(next);
+          next();
         });
       });
     });
   },
 
   testAddonManagerDoubleInstall: function(next) {
     // Create a new tab and load about:addons
-    let blanktab = gBrowser.addTab();
-    gBrowser.selectedTab = blanktab;
+    let addonsTab = gBrowser.addTab();
+    gBrowser.selectedTab = addonsTab;
     BrowserOpenAddonsMgr('addons://list/service');
-
-    is(blanktab, gBrowser.selectedTab, "Current tab should be blank tab");
-
     gBrowser.selectedBrowser.addEventListener("load", function tabLoad() {
       gBrowser.selectedBrowser.removeEventListener("load", tabLoad, true);
-      let browser = blanktab.linkedBrowser;
-      is(browser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
+      is(addonsTab.linkedBrowser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
 
       activateOneProvider(gProviders[0], true, function() {
         info("first activation completed");
         is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded");
-        gBrowser.removeTab(gBrowser.selectedTab);
-        is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_activate_basic.html", "activation page selected");
-        gBrowser.removeTab(gBrowser.selectedTab);
-        tabsToRemove.pop();
-        // uninstall the provider
-        clickAddonRemoveButton(blanktab, function(addon) {
-          checkSocialUI();
-          activateOneProvider(gProviders[0], true, function() {
-            info("second activation completed");
-            is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded");
-            gBrowser.removeTab(gBrowser.selectedTab);
+        BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
+          is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_activate_basic.html", "activation page selected");
+          BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
+            tabsToRemove.pop();
+            // uninstall the provider
+            clickAddonRemoveButton(addonsTab, function(addon) {
+              checkSocialUI();
+              activateOneProvider(gProviders[0], true, function() {
+                info("second activation completed");
+                is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded");
+                BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
 
-            // after closing the addons tab, verify provider is still installed
-            gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
-              gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
-              AddonManager.getAddonsByTypes(["service"], function(aAddons) {
-                is(aAddons.length, 1, "there can be only one");
-                removeAllProviders(next);
+                  // after closing the addons tab, verify provider is still installed
+                  AddonManager.getAddonsByTypes(["service"], function(aAddons) {
+                    is(aAddons.length, 1, "there can be only one");
+
+                    let doc = addonsTab.linkedBrowser.contentDocument;
+                    let list = doc.getElementById("addon-list");
+                    is(list.childNodes.length, 1, "only one addon is displayed");
+
+                    BrowserTestUtils.removeTab(addonsTab).then(next);
+                  });
+                });
               });
             });
-
-            // verify only one provider in list
-            AddonManager.getAddonsByTypes(["service"], function(aAddons) {
-              is(aAddons.length, 1, "there can be only one");
-
-              let doc = blanktab.linkedBrowser.contentDocument;
-              let list = doc.getElementById("addon-list");
-              is(list.childNodes.length, 1, "only one addon is displayed");
-
-              gBrowser.removeTab(blanktab);
-            });
-
           });
         });
       });
     }, true);
   }
 }
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -22,22 +22,22 @@ var manifests = [
     origin: "https://test2.example.com",
     sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2",
     iconURL: "chrome://branding/content/icon48.png"
   }
 ];
 
 var chatId = 0;
 function openChat(provider) {
-  let deferred = Promise.defer();
-  SocialSidebar.provider = provider;
-  let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
-  let url = chatUrl + "?id=" + (chatId++);
-  makeChat("normal", "chat " + chatId, (cb) => { deferred.resolve(cb); });
-  return deferred.promise;
+  return new Promise(resolve => {
+    SocialSidebar.provider = provider;
+    let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
+    let url = chatUrl + "?id=" + (chatId++);
+    makeChat("normal", "chat " + chatId, (cb) => { resolve(cb); });
+  });
 }
 
 function windowHasChats(win) {
   return !!getChatBar().firstElementChild;
 }
 
 function test() {
   requestLongerTimeout(2); // only debug builds seem to need more time...
@@ -69,33 +69,29 @@ function test() {
       finishcb();
     });
   });
 }
 
 var tests = {
   testOpenCloseChat: function(next) {
     openChat(SocialSidebar.provider).then((cb) => {
-      waitForCondition(function() {
-        return cb.minimized;
-      }, function() {
+      BrowserTestUtils.waitForCondition(() => { return cb.minimized; },
+                                        "chatbox is minimized").then(() => {
         ok(cb.minimized, "chat is minimized after toggle");
-        waitForCondition(function() {
-          return !cb.minimized;
-        }, function() {
+        BrowserTestUtils.waitForCondition(() => { return !cb.minimized; },
+                                          "chatbox is not minimized").then(() => {
           ok(!cb.minimized, "chat is not minimized after toggle");
           promiseNodeRemoved(cb).then(next);
           let mm = cb.content.messageManager;
           mm.sendAsyncMessage("socialTest-CloseSelf", {});
           info("close chat window requested");
-        },
-        "chatbox is not minimized");
+        });
         cb.toggle();
-      },
-      "chatbox is minimized");
+      });
 
       ok(!cb.minimized, "chat is not minimized on open");
       // toggle to minimize chat
       cb.toggle();
     });
   },
 
   // Check what happens when you close the only visible chat.
--- a/browser/base/content/test/social/browser_social_chatwindowfocus.js
+++ b/browser/base/content/test/social/browser_social_chatwindowfocus.js
@@ -37,29 +37,30 @@ function test() {
     }
     let postSubTest = function(cb) {
       Task.spawn(closeAllChats).then(cb);
     }
     // and run the tests.
     runSocialTestWithProvider(manifest, function (finishcb) {
       SocialSidebar.show();
       runSocialTests(tests, preSubTest, postSubTest, function () {
-        ensureBrowserTabClosed(tab).then(finishcb);
+        BrowserTestUtils.removeTab(tab).then(finishcb);
       });
     });
   }, true);
 }
 
 var tests = {
   // In this test we arrange for the sidebar to open the chat via a simulated
   // click.  This should cause the new chat to be opened and focused.
   testFocusWhenViaUser: function(next) {
     ensureFrameLoaded(document.getElementById("social-sidebar-browser")).then(() => {
       let chatbar = getChatBar();
       openChatViaUser();
       ok(chatbar.firstElementChild, "chat opened");
-      waitForCondition(() => isChatFocused(chatbar.selectedChat), function() {
+      BrowserTestUtils.waitForCondition(() => isChatFocused(chatbar.selectedChat),
+                                        "chat should be focused").then(() => {
         is(chatbar.selectedChat, chatbar.firstElementChild, "chat is selected");
         next();
-      }, "chat should be focused");
+      });
     });
   },
 };
--- a/browser/base/content/test/social/browser_social_contextmenu.js
+++ b/browser/base/content/test/social/browser_social_contextmenu.js
@@ -53,23 +53,22 @@ var tests = {
         ],
         "rels": {},
         "rel-urls": {}
       }
     });
 
     let mm = getGroupMessageManager("social");
     mm.addMessageListener("sharedata", function handler(msg) {
-      gBrowser.removeTab(testTab);
       is(msg.data, expecting, "microformats data ok");
       mm.removeMessageListener("sharedata", handler);
-      next();
+      BrowserTestUtils.removeTab(testTab).then(next);
     });
 
     let url = "https://example.com/browser/browser/base/content/test/social/microformats.html"
-    addTab(url, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
       testTab = tab;
       let doc = tab.linkedBrowser.contentDocument;
       target = doc.getElementById("test-review");
       SocialMarks.markLink(manifest.origin, url, target);
     });
   }
 }
--- a/browser/base/content/test/social/browser_social_errorPage.js
+++ b/browser/base/content/test/social/browser_social_errorPage.js
@@ -12,22 +12,20 @@ function gc() {
 var openChatWindow = Cu.import("resource://gre/modules/MozSocialAPI.jsm", {}).openChatWindow;
 
 function openPanel(url, panelCallback, loadCallback) {
   // open a flyout
   SocialFlyout.open(url, 0, panelCallback);
   // wait for both open and loaded before callback. Since the test doesn't close
   // the panel between opens, we cannot rely on events here. We need to ensure
   // popupshown happens before we finish out the tests.
-  waitForCondition(function() {
+  BrowserTestUtils.waitForCondition(function() {
                     return SocialFlyout.panel.state == "open" &&
                            SocialFlyout.iframe.contentDocument.readyState == "complete";
-                   },
-                   function () { executeSoon(loadCallback) },
-                   "flyout is open and loaded");
+                   },"flyout is open and loaded").then(() => { executeSoon(loadCallback) });
 }
 
 function openChat(url, panelCallback, loadCallback) {
   // open a chat window
   let chatbar = getChatBar();
   openChatWindow(null, SocialSidebar.provider, url, panelCallback);
   chatbar.firstChild.addEventListener("DOMContentLoaded", function panelLoad() {
     chatbar.firstChild.removeEventListener("DOMContentLoaded", panelLoad, true);
@@ -133,22 +131,21 @@ var tests = {
       openChat(
         manifest.sidebarURL, /* empty html page */
         function() { // the panel api callback
           panelCallbackCount++;
         },
         function() { // the "load" callback.
           todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads.");
           let chat = getChatBar().selectedChat;
-          waitForCondition(() => chat.content != null && chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
-                           function() {
-                            chat.close();
-                            next();
-                            },
-                           "error page didn't appear");
+          BrowserTestUtils.waitForCondition(() => chat.content != null && chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
+                           "error page didn't appear").then(() => {
+                              chat.close();
+                              next();
+                            });
         }
       );
     });
   },
 
   testChatWindowAfterTearOff: function(next) {
     todo(false, "Bug 1245799 is needed to make error pages work again for chat windows.");
     next();
@@ -162,32 +159,29 @@ var tests = {
     // open a chat while we are still online.
     openChat(
       url,
       null,
       function() { // the "load" callback.
         let chat = getChatBar().selectedChat;
         is(chat.contentDocument.documentURI, url, "correct url loaded");
         // toggle to a detached window.
-        chat.swapWindows().then(
-          chat => {
-            ok(!!chat.content, "we have chat content 1");
-            waitForCondition(() => chat.content != null && chat.contentDocument.readyState == "complete",
-                             function() {
-              // now go offline and reload the chat - about:socialerror should be loaded.
-              goOffline().then(function() {
-                ok(!!chat.content, "we have chat content 2");
-                chat.contentDocument.location.reload();
-                info("chat reload called");
-                waitForCondition(() => chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
-                                 function() {
-                                  chat.close();
-                                  next();
-                                  },
-                                 "error page didn't appear");
+        chat.swapWindows().then(chat => {
+          ok(!!chat.content, "we have chat content 1");
+          BrowserTestUtils.waitForCondition(() => chat.content != null && chat.contentDocument.readyState == "complete",
+                                            "swapped window loaded").then(() => {
+            // now go offline and reload the chat - about:socialerror should be loaded.
+            goOffline().then(() => {
+              ok(!!chat.content, "we have chat content 2");
+              chat.contentDocument.location.reload();
+              info("chat reload called");
+              BrowserTestUtils.waitForCondition(() => chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
+                                                "error page didn't appear").then(() => {
+                chat.close();
+                next();
               });
-            }, "swapped window loaded");
-          }
-        );
+            });
+          });
+        });
       }
     );
   }
 }
--- a/browser/base/content/test/social/browser_social_flyout.js
+++ b/browser/base/content/test/social/browser_social_flyout.js
@@ -3,19 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function test() {
   waitForExplicitFinish();
   let frameScript = "data:,(" + function frame_script() {
     addMessageListener("socialTest-CloseSelf", function(e) {
       content.close();
     });
-    addEventListener("visibilitychange", function() {
-      sendAsyncMessage("social-visibility", content.document.hidden ? "hidden" : "shown");
-    });
     addMessageListener("socialTest-sendEvent", function(msg) {
       let data = msg.data;
       let evt = content.document.createEvent("CustomEvent");
       evt.initCustomEvent(data.name, true, true, JSON.stringify(data.data));
       content.document.documentElement.dispatchEvent(evt);
     });
 
   }.toString() + ")();";
@@ -25,105 +22,81 @@ function test() {
   let manifest = { // normal provider
     name: "provider 1",
     origin: "https://example.com",
     sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
     iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
   };
   runSocialTestWithProvider(manifest, function (finishcb) {
     SocialSidebar.show();
-    ensureFrameLoaded(document.getElementById("social-sidebar-browser")).then(() => {
+    ensureFrameLoaded(SocialSidebar.browser, manifest.sidebarURL).then(() => {
       // disable transitions for the test
-      let panel = document.getElementById("social-flyout-panel");
       registerCleanupFunction(function () {
-        panel.removeAttribute("animate");
+        SocialFlyout.panel.removeAttribute("animate");
       });
-      panel.setAttribute("animate", "false");
+      SocialFlyout.panel.setAttribute("animate", "false");
       runSocialTests(tests, undefined, undefined, finishcb);
     });
   });
 }
 
 var tests = {
-  testOpenCloseFlyout: function(next) {
-    let panel = document.getElementById("social-flyout-panel");
-    ensureEventFired(panel, "popupshown").then(() => {
-      is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
-    });
-    let sidebar = document.getElementById("social-sidebar-browser")
-    let mm = getGroupMessageManager("social");
-    mm.addMessageListener("social-visibility", function handler(msg) {
-      if (msg.data == "shown") {
-        sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-close", data: {} });
-      } else if (msg.data == "hidden") {
-        mm.removeMessageListener("social-visibility", handler);
-        next();
-      }
-    });
-    sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
-  },
-
   testResizeFlyout: function(next) {
     let panel = document.getElementById("social-flyout-panel");
 
-    ensureEventFired(panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
       is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
       // The width of the flyout should be 400px initially
       let iframe = panel.firstChild;
       let body = iframe.contentDocument.body;
       let cs = iframe.contentWindow.getComputedStyle(body);
 
       is(cs.width, "400px", "should be 400px wide");
       is(iframe.boxObject.width, 400, "iframe should now be 400px wide");
       is(cs.height, "400px", "should be 400px high");
       is(iframe.boxObject.height, 400, "iframe should now be 400px high");
 
-      ensureEventFired(iframe.contentWindow, "resize").then(() => {
+      BrowserTestUtils.waitForEvent(iframe.contentWindow, "resize").then(() => {
         cs = iframe.contentWindow.getComputedStyle(body);
 
         is(cs.width, "500px", "should now be 500px wide");
         is(iframe.boxObject.width, 500, "iframe should now be 500px wide");
         is(cs.height, "500px", "should now be 500px high");
         is(iframe.boxObject.height, 500, "iframe should now be 500px high");
-        ensureEventFired(panel, "popuphidden").then(next);
+        BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
         panel.hidePopup();
       });
       SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
     });
 
-    let sidebar = document.getElementById("social-sidebar-browser");
-    sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
+    SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
   },
 
   testCloseSelf: function(next) {
     let panel = document.getElementById("social-flyout-panel");
-    ensureEventFired(panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
       is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
-      ensureEventFired(panel, "popuphidden").then(next);
+      BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
       let mm = panel.firstChild.messageManager;
       mm.sendAsyncMessage("socialTest-CloseSelf", {});
     });
-    let sidebar = document.getElementById("social-sidebar-browser");
-    sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
+    SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
   },
 
   testCloseOnLinkTraversal: function(next) {
 
-    function onTabOpen(event) {
-      gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
-      waitForCondition(function() { return panel.state == "closed" }, function() {
-        gBrowser.removeTab(event.target);
-        next();
-      }, "panel should close after tab open");
-    }
+    BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen", true).then(event => {
+      BrowserTestUtils.waitForCondition(function() { return panel.state == "closed" },
+                                        "panel should close after tab open").then(() => {
+        BrowserTestUtils.removeTab(event.target).then(next);
+      });
+    });
 
     let panel = document.getElementById("social-flyout-panel");
-    ensureEventFired(panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
       is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
       is(panel.state, "open", "flyout should be open");
-      gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
       let iframe = panel.firstChild;
       iframe.contentDocument.getElementById('traversal').click();
     });
-    let sidebar = document.getElementById("social-sidebar-browser");
-    sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
+    SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
   }
 }
--- a/browser/base/content/test/social/browser_social_marks.js
+++ b/browser/base/content/test/social/browser_social_marks.js
@@ -28,17 +28,19 @@ function test() {
   let frameScript = "data:,(" + function frame_script() {
     addEventListener("visibilitychange", function() {
       sendAsyncMessage("visibility", content.document.hidden ? "hidden" : "shown");
     });
   }.toString() + ")();";
   let mm = getGroupMessageManager("social");
   mm.loadFrameScript(frameScript, true);
 
+  PopupNotifications.panel.setAttribute("animate", "false");
   registerCleanupFunction(function () {
+    PopupNotifications.panel.removeAttribute("animate");
     mm.removeDelayedFrameScript(frameScript);
   });
 
   runSocialTests(tests, undefined, undefined, finish);
 }
 
 var tests = {
   testButtonDisabledOnActivate: function(next) {
@@ -62,56 +64,56 @@ var tests = {
       checkSocialUI(window);
       SocialService.disableProvider(manifest2.origin, next);
     });
   },
   testNoButtonOnEnable: function(next) {
     // we expect the addon install dialog to appear, we need to accept the
     // install from the dialog.
     let panel = document.getElementById("servicesInstall-notification");
-    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
       info("servicesInstall-notification panel opened");
       panel.button.click();
     });
 
     let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       let doc = tab.linkedBrowser.contentDocument;
       let data = {
         origin: doc.nodePrincipal.origin,
         url: doc.location.href,
         manifest: manifest3,
         window: window
       }
 
       Social.installProvider(data, function(addonManifest) {
         // enable the provider so we know the button would have appeared
         SocialService.enableProvider(manifest3.origin, function(provider) {
           is(provider.origin, manifest3.origin, "provider is installed");
           let id = SocialMarks._toolbarHelper.idFromOrigin(provider.origin);
           let widget = CustomizableUI.getWidget(id);
           ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
           Social.uninstallProvider(manifest3.origin, function() {
-            ensureBrowserTabClosed(tab).then(next);
+            BrowserTestUtils.removeTab(tab).then(next);
           });
         });
       });
     });
   },
 
   testButtonOnEnable: function(next) {
     let panel = document.getElementById("servicesInstall-notification");
-    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
       info("servicesInstall-notification panel opened");
       panel.button.click();
     });
 
     // enable the provider now
     let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       let doc = tab.linkedBrowser.contentDocument;
       let data = {
         origin: doc.nodePrincipal.origin,
         url: doc.location.href,
         manifest: manifest2,
         window: window
       }
 
@@ -126,106 +128,105 @@ var tests = {
           let button = document.getElementById(id);
           is(button.disabled, false, "mark button is disabled");
           // verify the attribute for proper css
           ok(!button.hasAttribute("disabled"), "mark button attribute is disabled");
           // button should be visible
           is(button.hidden, false, "mark button is visible");
 
           checkSocialUI(window);
-          ensureBrowserTabClosed(tab).then(next);
+          BrowserTestUtils.removeTab(tab).then(next);
         });
       });
     });
   },
 
   testMarkPanel: function(next) {
     // click on panel to open and wait for visibility
     let provider = Social._getProviderFromOrigin(manifest2.origin);
     ok(provider.enabled, "provider is enabled");
     let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
     let widget = CustomizableUI.getWidget(id);
     let btn = widget.forWindow(window).node;
     ok(btn, "got a mark button");
     let ourTab;
 
-    ensureEventFired(btn.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(btn.panel, "popupshown").then(() => {
       info("marks panel shown");
       let doc = btn.contentDocument;
       let unmarkBtn = doc.getElementById("unmark");
       ok(unmarkBtn, "testMarkPanel - got the panel unmark button");
       EventUtils.sendMouseEvent({type: "click"}, unmarkBtn, btn.contentWindow);
     });
 
-    ensureEventFired(btn.panel, "popuphidden").then(() => {
-      ensureBrowserTabClosed(ourTab).then(() => {
+    BrowserTestUtils.waitForEvent(btn.panel, "popuphidden").then(() => {
+      BrowserTestUtils.removeTab(ourTab).then(() => {
         ok(btn.disabled, "button is disabled");
         next();
       });
     });
 
     // verify markbutton is disabled when there is no browser url
     ok(btn.disabled, "button is disabled");
     let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       ourTab = tab;
       ok(!btn.disabled, "button is enabled");
       // first click marks the page, second click opens the page. We have to
       // synthesize so the command event happens
       EventUtils.synthesizeMouseAtCenter(btn, {});
       // wait for the button to be marked, click to open panel
       is(btn.panel.state, "closed", "panel should not be visible yet");
-      waitForCondition(() => btn.isMarked, function() {
+      BrowserTestUtils.waitForCondition(() => btn.isMarked, "button is marked").then(() => {
         EventUtils.synthesizeMouseAtCenter(btn, {});
-      }, "button is marked");
+      });
     });
   },
 
   testMarkPanelOffline: function(next) {
     // click on panel to open and wait for visibility
     let provider = Social._getProviderFromOrigin(manifest2.origin);
     ok(provider.enabled, "provider is enabled");
     let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
     let widget = CustomizableUI.getWidget(id);
     let btn = widget.forWindow(window).node;
     ok(btn, "got a mark button");
 
     // verify markbutton is disabled when there is no browser url
     ok(btn.disabled, "button is disabled");
-    let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html";
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       ok(!btn.disabled, "button is enabled");
       goOffline().then(function() {
         info("testing offline error page");
         // wait for popupshown
-        ensureEventFired(btn.panel, "popupshown").then(() => {
+        BrowserTestUtils.waitForEvent(btn.panel, "popupshown").then(() => {
           info("marks panel is open");
           ensureFrameLoaded(btn.content).then(() => {
             is(btn.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+btn.contentDocument.documentURI);
             // cleanup after the page has been unmarked
-            ensureBrowserTabClosed(tab).then(() => {
+            BrowserTestUtils.removeTab(tab).then(() => {
               ok(btn.disabled, "button is disabled");
               goOnline().then(next);
             });
           });
         });
         btn.markCurrentPage();
       });
     });
   },
 
   testButtonOnDisable: function(next) {
     // enable the provider now
     let provider = Social._getProviderFromOrigin(manifest2.origin);
     ok(provider, "provider is installed");
     SocialService.disableProvider(manifest2.origin, function() {
       let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
-      waitForCondition(function() {
+      BrowserTestUtils.waitForCondition(() => {
                         // getWidget now returns null since we've destroyed the widget
                         return !CustomizableUI.getWidget(id)
-                       },
-                       function() {
+                       }, "button does not exist after disabling the provider").then(() => {
                          checkSocialUI(window);
                          Social.uninstallProvider(manifest2.origin, next);
-                       }, "button does not exist after disabling the provider");
+                       });
     });
   }
 }
--- a/browser/base/content/test/social/browser_social_marks_context.js
+++ b/browser/base/content/test/social/browser_social_marks_context.js
@@ -9,16 +9,20 @@ function makeMarkProvider(origin) {
     unmarkedIcon: "https://" + origin + ".example.com/browser/browser/base/content/test/social/checked.jpg",
     iconURL: "https://" + origin + ".example.com/browser/browser/base/content/test/general/moz.png",
     version: "1.0"
   }
 }
 
 function test() {
   waitForExplicitFinish();
+  PopupNotifications.panel.setAttribute("animate", "false");
+  registerCleanupFunction(function () {
+    PopupNotifications.panel.removeAttribute("animate");
+  });
 
   runSocialTests(tests, undefined, undefined, finish);
 }
 
 var tests = {
   testContextSubmenu: function(next) {
     // install 4 providers to test that the menu's are added as submenus
     let manifests = [
@@ -35,46 +39,47 @@ var tests = {
       let manifest = manifests.pop();
       if (!manifest) {
         info("INSTALLATION FINISHED");
         executeSoon(callback);
         return;
       }
       info("INSTALLING " + manifest.origin);
       let panel = document.getElementById("servicesInstall-notification");
-      ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+      BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
         info("servicesInstall-notification panel opened");
         panel.button.click();
       });
 
       let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
       let id = SocialMarks._toolbarHelper.idFromOrigin(manifest.origin);
       let toolbar = document.getElementById("nav-bar");
-      addTab(activationURL, function(tab) {
+      BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
         let doc = tab.linkedBrowser.contentDocument;
         let data = {
           origin: doc.nodePrincipal.origin,
           url: doc.location.href,
           manifest: manifest,
           window: window
         }
 
         Social.installProvider(data, function(addonManifest) {
           // enable the provider so we know the button would have appeared
           SocialService.enableProvider(manifest.origin, function(provider) {
-            waitForCondition(function() { return CustomizableUI.getWidget(id) },
-                             function() {
-              gBrowser.removeTab(tab);
-              installed.push(manifest.origin);
-              // checkSocialUI will properly check where the menus are located
-              checkSocialUI(window);
-              executeSoon(function() {
-                addProviders(callback);
+            BrowserTestUtils.waitForCondition(() => { return CustomizableUI.getWidget(id) },
+                             "button exists after enabling social").then(() => {
+              BrowserTestUtils.removeTab(tab).then(() => {
+                installed.push(manifest.origin);
+                // checkSocialUI will properly check where the menus are located
+                checkSocialUI(window);
+                executeSoon(function() {
+                  addProviders(callback);
+                });
               });
-            }, "button exists after enabling social");
+            });
           });
         });
       });
     }
 
     function removeProviders(callback) {
       let origin = installed.pop();
       if (!origin) {
--- a/browser/base/content/test/social/browser_social_multiprovider.js
+++ b/browser/base/content/test/social/browser_social_multiprovider.js
@@ -37,33 +37,33 @@ var tests = {
       is(menuProviders.length, gProviders.length, "correct number of providers listed in the menu");
       // Find the selectedProvider's menu item
       let el = menu.getElementsByAttribute("origin", selectedProvider.origin);
       is(el.length, 1, "selected provider menu item exists");
       is(el[0].getAttribute("checked"), "true", "selected provider menu item is checked");
     }
 
     // the menu is not populated until onpopupshowing, so wait for popupshown
-    ensureEventFired(menu, "popupshown").then(()=>{
+    BrowserTestUtils.waitForEvent(menu, "popupshown", true).then(()=>{
       menu.hidePopup(); // doesn't need visibility
       // first provider should already be visible in the sidebar
       is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
       checkProviderMenu(Social.providers[0]);
 
       // Now activate "provider 2"
-      ensureEventFired(sbrowser, "load").then(()=>{
+      BrowserTestUtils.waitForEvent(sbrowser, "load", true).then(()=>{
         checkUIStateMatchesProvider(Social.providers[1]);
 
-        ensureEventFired(sbrowser, "load").then(()=>{
+        BrowserTestUtils.waitForEvent(sbrowser, "load", true).then(()=>{
           checkUIStateMatchesProvider(Social.providers[0]);
           next();
         });
 
         // show the menu again so the menu is updated with the correct commands
-        ensureEventFired(menu, "popupshown").then(()=>{
+        BrowserTestUtils.waitForEvent(menu, "popupshown", true).then(()=>{
           // click on the provider menuitem to switch providers
           let el = menu.getElementsByAttribute("origin", Social.providers[0].origin);
           is(el.length, 1, "selected provider menu item exists");
           EventUtils.synthesizeMouseAtCenter(el[0], {});
         });
         EventUtils.synthesizeMouseAtCenter(button, {});
       });
       SocialSidebar.provider = Social.providers[1];
--- a/browser/base/content/test/social/browser_social_sidebar.js
+++ b/browser/base/content/test/social/browser_social_sidebar.js
@@ -63,17 +63,17 @@ function doTest() {
         // should not have unloaded so will still be the provider URL.
         is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set");
       } else {
         // should have been an immediate unload.
         is(browser.getAttribute('src'), "about:blank", "sidebar url should be blank");
       }
     }
   }
-  ensureEventFired(browser, "load").then(() => {
+  ensureFrameLoaded(browser).then(() => {
     // First check the the sidebar is initially visible, and loaded
     ok(!command.hidden, "toggle command should be visible");
     let mm = getGroupMessageManager("social");
     mm.addMessageListener("visibility", function shown(msg) {
       if (msg.data == "shown") {
         mm.removeMessageListener("visibility", shown);
         checkShown(true);
         info("Toggling sidebar to closed");
--- a/browser/base/content/test/social/browser_social_status.js
+++ b/browser/base/content/test/social/browser_social_status.js
@@ -44,17 +44,19 @@ function test() {
       let evt = content.document.createEvent("CustomEvent");
       evt.initCustomEvent(data.name, true, true, JSON.stringify(data.data));
       content.document.documentElement.dispatchEvent(evt);
     });
   }.toString() + ")();";
   let mm = getGroupMessageManager("social");
   mm.loadFrameScript(frameScript, true);
 
+  PopupNotifications.panel.setAttribute("animate", "false");
   registerCleanupFunction(function () {
+    PopupNotifications.panel.removeAttribute("animate");
     mm.removeDelayedFrameScript(frameScript);
   });
 
   runSocialTestWithProvider(manifest, function (finishcb) {
     runSocialTests(tests, undefined, undefined, function () {
       Services.prefs.clearUserPref("social.remote-install.enabled");
       // just in case the tests failed, clear these here as well
       Services.prefs.clearUserPref("social.whitelist");
@@ -64,72 +66,70 @@ function test() {
   });
 }
 
 var tests = {
   testNoButtonOnEnable: function(next) {
     // we expect the addon install dialog to appear, we need to accept the
     // install from the dialog.
     let panel = document.getElementById("servicesInstall-notification");
-    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
       info("servicesInstall-notification panel opened");
       panel.button.click();
     })
 
     let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       let doc = tab.linkedBrowser.contentDocument;
       let data = {
         origin: doc.nodePrincipal.origin,
         url: doc.location.href,
         manifest: manifest3,
         window: window
       }
       Social.installProvider(data, function(addonManifest) {
         // enable the provider so we know the button would have appeared
         SocialService.enableProvider(manifest3.origin, function(provider) {
           is(provider.origin, manifest3.origin, "provider is installed");
           let id = SocialStatus._toolbarHelper.idFromOrigin(provider.origin);
           let widget = CustomizableUI.getWidget(id);
           ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
           Social.uninstallProvider(manifest3.origin, function() {
-            gBrowser.removeTab(tab);
-            next();
+            BrowserTestUtils.removeTab(tab).then(next);
           });
         });
       });
     });
   },
   testButtonOnEnable: function(next) {
     let panel = document.getElementById("servicesInstall-notification");
-    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
       info("servicesInstall-notification panel opened");
       panel.button.click();
     });
 
     // enable the provider now
     let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
+    BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
       let doc = tab.linkedBrowser.contentDocument;
       let data = {
         origin: doc.nodePrincipal.origin,
         url: doc.location.href,
         manifest: manifest2,
         window: window
       }
 
       Social.installProvider(data, function(addonManifest) {
         SocialService.enableProvider(manifest2.origin, function(provider) {
           is(provider.origin, manifest2.origin, "provider is installed");
           let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
           let widget = CustomizableUI.getWidget(id).forWindow(window);
           ok(widget.node, "button added to widget set");
           checkSocialUI(window);
-          gBrowser.removeTab(tab);
-          next();
+          BrowserTestUtils.removeTab(tab).then(next);
         });
       });
     });
   },
   testStatusPanel: function(next) {
     let icon = {
       name: "testIcon",
       iconURL: "chrome://browser/skin/Info.png",
@@ -140,28 +140,28 @@ var tests = {
     let provider = Social._getProviderFromOrigin(manifest2.origin);
     let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
     let widget = CustomizableUI.getWidget(id);
     let btn = widget.forWindow(window).node;
 
     // Disable the transition
     let panel = document.getElementById("social-notification-panel");
     panel.setAttribute("animate", "false");
-    ensureEventFired(panel, "popupshown").then(() => {
+    BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
       ensureFrameLoaded(panel.firstChild).then(() => {
         let mm = panel.firstChild.messageManager;
         mm.sendAsyncMessage("socialTest-sendEvent", { name: "Social:Notification", data: icon });
-        waitForCondition(function() { return btn.getAttribute("badge"); },
-                   function() {
-                     is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated");
-                     panel.hidePopup();
-                   }, "button updated by notification");
+        BrowserTestUtils.waitForCondition(
+          () => { return btn.getAttribute("badge"); }, "button updated by notification").then(() => {
+            is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated");
+            panel.hidePopup();
+          });
         });
     });
-    ensureEventFired(panel, "popuphidden").then(() => {
+    BrowserTestUtils.waitForEvent(panel, "popuphidden").then(() => {
       panel.removeAttribute("animate");
       next();
     });
     btn.click(); // open the panel
   },
 
   testPanelOffline: function(next) {
     // click on panel to open and wait for visibility
@@ -173,44 +173,44 @@ var tests = {
     ok(btn, "got a status button");
     let frameId = btn.getAttribute("notificationFrameId");
     let frame = document.getElementById(frameId);
 
     goOffline().then(function() {
       info("testing offline error page");
       // wait for popupshown
       let panel = document.getElementById("social-notification-panel");
-      ensureEventFired(panel, "popupshown").then(() => {
+      BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
         ensureFrameLoaded(frame).then(() => {
           is(frame.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+frame.contentDocument.documentURI);
           // We got our error page, reset to avoid test leak.
-          ensureEventFired(frame, "load").then(() => {
+          BrowserTestUtils.waitForEvent(frame, "load", true).then(() => {
             is(frame.contentDocument.documentURI, "about:blank", "closing error panel");
-            ensureEventFired(panel, "popuphidden").then(next);
+            BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
             panel.hidePopup();
           });
           goOnline().then(() => {
             info("resetting error panel");
             frame.setAttribute("src", "about:blank");
           });
         });
       });
       // reload after going offline, wait for unload to open panel
-      ensureEventFired(frame, "unload").then(() => {
+      BrowserTestUtils.waitForEvent(frame, "unload", true).then(() => {
         btn.click();
       });
       frame.contentDocument.location.reload();
     });
   },
 
   testButtonOnDisable: function(next) {
     // enable the provider now
     let provider = Social._getProviderFromOrigin(manifest2.origin);
     ok(provider, "provider is installed");
     SocialService.disableProvider(manifest2.origin, function() {
       let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
-      waitForCondition(function() { return !document.getElementById(id) },
-                       function() {
-                        Social.uninstallProvider(manifest2.origin, next);
-                       }, "button does not exist after disabling the provider");
+      BrowserTestUtils.waitForCondition(() => { return !document.getElementById(id) },
+                                        "button does not exist after disabling the provider").then(() => {
+        Social.uninstallProvider(manifest2.origin, next);
+       });
     });
   }
 }
--- a/browser/base/content/test/social/browser_social_window.js
+++ b/browser/base/content/test/social/browser_social_window.js
@@ -89,18 +89,18 @@ var tests = {
 
   // Check when providers are enabled and social is turned on at startup.
   testEnabledStartup: function(cbnext) {
     setManifestPref("social.manifest.test", manifest);
     ok(!SocialSidebar.opened, "sidebar is closed initially");
     SocialService.addProvider(manifest, function() {
       SocialService.addProvider(manifest2, function (provider) {
         SocialSidebar.show();
-        waitForCondition(() => SocialSidebar.opened,
-                     function() {
+        BrowserTestUtils.waitForCondition(
+          () => SocialSidebar.opened, "sidebar did not open").then(() => {
           ok(SocialSidebar.opened, "first window sidebar is open");
           openWindowAndWaitForInit(window, function(w1) {
             ok(w1.SocialSidebar.opened, "new window sidebar is open");
             ok(SocialService.hasEnabledProviders, "providers are enabled");
             checkSocialUI(w1);
             // now init is complete, open a second window
             openWindowAndWaitForInit(window, function(w2) {
               ok(w1.SocialSidebar.opened, "w1 sidebar is open");
@@ -118,33 +118,32 @@ var tests = {
                   checkSocialUI(w2);
                   checkSocialUI(w1);
                   Services.prefs.clearUserPref("social.manifest.test");
                   cbnext();
                 });
               });
             });
           });
-        }, "sidebar did not open");
+        });
       }, cbnext);
     }, cbnext);
   },
 
   testGlobalState: function(cbnext) {
     setManifestPref("social.manifest.test", manifest);
     ok(!SocialSidebar.opened, "sidebar is closed initially");
     ok(!Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state unset");
     // mimick no session state in opener so we exercise the global state via pref
     SessionStore.deleteWindowValue(window, "socialSidebar");
     ok(!SessionStore.getWindowValue(window, "socialSidebar"), "window state unset");
     SocialService.addProvider(manifest, function() {
       openWindowAndWaitForInit(window, function(w1) {
         w1.SocialSidebar.show();
-        waitForCondition(() => w1.SocialSidebar.opened,
-                     function() {
+        BrowserTestUtils.waitForCondition(() => w1.SocialSidebar.opened, "sidebar opened").then(() => {
           ok(Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state set");
           ok(!SocialSidebar.opened, "1. main sidebar is still closed");
           ok(w1.SocialSidebar.opened, "1. window sidebar is open");
           closeWindow(w1, function() {
             // this time, the global state should cause the sidebar to be opened
             // in the new window
             openWindowAndWaitForInit(window, function(w1) {
               ok(!SocialSidebar.opened, "2. main sidebar is still closed");
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -1,63 +1,40 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-  "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
   "resource://gre/modules/PlacesUtils.jsm");
 
-function waitForCondition(condition, nextTest, errorMsg, numTries = 30) {
-  var tries = 0;
-  var interval = setInterval(function() {
-    if (tries >= numTries) {
-      ok(false, errorMsg);
-      moveOn();
-    }
-    var conditionPassed;
-    try {
-      conditionPassed = condition();
-    } catch (e) {
-      ok(false, e + "\n" + e.stack);
-      conditionPassed = false;
-    }
-    if (conditionPassed) {
-      moveOn();
-    }
-    tries++;
-  }, 100);
-  var moveOn = function() { clearInterval(interval); nextTest(); };
-}
-
 
 function promiseObserverNotified(aTopic) {
-  let deferred = Promise.defer();
-  Services.obs.addObserver(function onNotification(aSubject, aTopic, aData) {
-    Services.obs.removeObserver(onNotification, aTopic);
-      deferred.resolve({subject: aSubject, data: aData});
+  return new Promise(resolve => {
+    Services.obs.addObserver(function onNotification(aSubject, aTopic, aData) {
+      dump("notification promised "+aTopic);
+      Services.obs.removeObserver(onNotification, aTopic);
+      TestUtils.executeSoon(() => resolve({subject: aSubject, data: aData}));
     }, aTopic, false);
-  return deferred.promise;
+  });
 }
 
 // Check that a specified (string) URL hasn't been "remembered" (ie, is not
 // in history, will not appear in about:newtab or auto-complete, etc.)
 function promiseSocialUrlNotRemembered(url) {
-  let deferred = Promise.defer();
-  let uri = Services.io.newURI(url, null, null);
-  PlacesUtils.asyncHistory.isURIVisited(uri, function(aURI, aIsVisited) {
-    ok(!aIsVisited, "social URL " + url + " should not be in global history");
-    deferred.resolve();
+  return new Promise(resolve => {
+    let uri = Services.io.newURI(url, null, null);
+    PlacesUtils.asyncHistory.isURIVisited(uri, function(aURI, aIsVisited) {
+      ok(!aIsVisited, "social URL " + url + " should not be in global history");
+      resolve();
+    });
   });
-  return deferred.promise;
 }
 
 var gURLsNotRemembered = [];
 
 
 function checkProviderPrefsEmpty(isError) {
   let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
   let prefs = MANIFEST_PREFS.getChildList("", []);
@@ -149,21 +126,21 @@ function runSocialTestWithProvider(manif
       }
 
       // If we've added all the providers we need, call the callback to start
       // the tests (and give it a callback it can call to finish them)
       if (providersAdded == manifests.length) {
         registerCleanupFunction(function () {
           finishSocialTest(true);
         });
-        waitForCondition(() => provider.enabled,
-                         function() {
+        BrowserTestUtils.waitForCondition(() => provider.enabled,
+                                          "providers added and enabled").then(() => {
           info("provider has been enabled");
           callback(finishSocialTest);
-        }, "providers added and enabled");
+        });
       }
     });
   });
 }
 
 function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
   let testIter = (function*() {
     for (let name in tests) {
@@ -302,49 +279,16 @@ function checkSocialUI(win) {
 function waitForNotification(topic, cb) {
   function observer(subject, topic, data) {
     Services.obs.removeObserver(observer, topic);
     cb();
   }
   Services.obs.addObserver(observer, topic, false);
 }
 
-// blocklist testing
-function updateBlocklist(aCallback) {
-  var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
-                          .getService(Ci.nsITimerCallback);
-  var observer = function() {
-    Services.obs.removeObserver(observer, "blocklist-updated");
-    if (aCallback)
-      executeSoon(aCallback);
-  };
-  Services.obs.addObserver(observer, "blocklist-updated", false);
-  blocklistNotifier.notify(null);
-}
-
-var _originalTestBlocklistURL = null;
-function setAndUpdateBlocklist(aURL, aCallback) {
-  if (!_originalTestBlocklistURL)
-    _originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
-  Services.prefs.setCharPref("extensions.blocklist.url", aURL);
-  updateBlocklist(aCallback);
-}
-
-function resetBlocklist(aCallback) {
-  // XXX - this has "forked" from the head.js helpers in our parent directory :(
-  // But let's reuse their blockNoPlugins.xml.  Later, we should arrange to
-  // use their head.js helpers directly
-  let noBlockedURL = "http://example.com/browser/browser/base/content/test/plugins/blockNoPlugins.xml";
-  setAndUpdateBlocklist(noBlockedURL, function() {
-    Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL);
-    if (aCallback)
-      aCallback();
-  });
-}
-
 function setManifestPref(name, manifest) {
   let string = Cc["@mozilla.org/supports-string;1"].
                createInstance(Ci.nsISupportsString);
   string.data = JSON.stringify(manifest);
   Services.prefs.setComplexValue(name, Ci.nsISupportsString, string);
 }
 
 function getManifestPrefname(aManifest) {
@@ -370,74 +314,34 @@ function setBuiltinManifestPref(name, ma
 }
 
 function resetBuiltinManifestPref(name) {
   Services.prefs.getDefaultBranch(null).deleteBranch(name);
   is(Services.prefs.getDefaultBranch(null).getPrefType(name),
      Services.prefs.PREF_INVALID, "default manifest removed");
 }
 
-function addTab(url, callback) {
-  let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true});
-  tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
-    tab.linkedBrowser.removeEventListener("load", tabLoad, true);
-    executeSoon(function() {callback(tab)});
-  }, true);
-}
-
-function selectBrowserTab(tab, callback) {
-  if (gBrowser.selectedTab == tab) {
-    executeSoon(function() {callback(tab)});
-    return;
-  }
-  gBrowser.tabContainer.addEventListener("TabSelect", function onTabSelect() {
-    gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false);
-    is(gBrowser.selectedTab, tab, "browser tab is selected");
-    executeSoon(function() {callback(tab)});
-  });
-  gBrowser.selectedTab = tab;
-}
-
 function ensureEventFired(elem, event) {
-  let deferred = Promise.defer();
-  elem.addEventListener(event, function handler() {
-    elem.removeEventListener(event, handler, true);
-    deferred.resolve()
-  }, true);
-  return deferred.promise;
-}
-
-function loadIntoTab(tab, url, callback) {
-  tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
-    tab.linkedBrowser.removeEventListener("load", tabLoad, true);
-    executeSoon(function() {callback(tab)});
-  }, true);
-  tab.linkedBrowser.loadURI(url);
-}
-
-function ensureBrowserTabClosed(tab) {
-  let promise = ensureEventFired(gBrowser.tabContainer, "TabClose");
-  gBrowser.removeTab(tab);
-  return promise;
+  return BrowserTestUtils.waitForEvent(elem, event, true);
 }
 
 function ensureFrameLoaded(frame, uri) {
-  let deferred = Promise.defer();
-  if (frame.contentDocument && frame.contentDocument.readyState == "complete" &&
-      (!uri || frame.contentDocument.location.href == uri)) {
-    deferred.resolve();
-  } else {
-    frame.addEventListener("load", function handler() {
-      if (uri && frame.contentDocument.location.href != uri)
-        return;
-      frame.removeEventListener("load", handler, true);
-      deferred.resolve()
-    }, true);
-  }
-  return deferred.promise;
+  return new Promise(resolve => {
+    if (frame.contentDocument && frame.contentDocument.readyState == "complete" &&
+        (!uri || frame.contentDocument.location.href == uri)) {
+      resolve();
+    } else {
+      frame.addEventListener("load", function handler() {
+        if (uri && frame.contentDocument.location.href != uri)
+          return;
+        frame.removeEventListener("load", handler, true);
+        resolve()
+      }, true);
+    }
+  });
 }
 
 // chat test help functions
 
 // And lots of helpers for the resize tests.
 function get3ChatsForCollapsing(mode, cb) {
   // We make one chat, then measure its size.  We then resize the browser to
   // ensure a second can be created fully visible but a third can not - then
@@ -625,33 +529,33 @@ function getPopupWidth() {
   let popup = chatbar.menupopup;
   ok(!popup.parentNode.collapsed, "asking for popup width when it is visible");
   let cs = document.defaultView.getComputedStyle(popup.parentNode);
   let margins = parseInt(cs.marginLeft) + parseInt(cs.marginRight);
   return popup.parentNode.getBoundingClientRect().width + margins;
 }
 
 function promiseNodeRemoved(aNode) {
-  let deferred = Promise.defer();
-  let parent = aNode.parentNode;
+  return new Promise(resolve => {
+    let parent = aNode.parentNode;
 
-  let observer = new MutationObserver(function onMutatations(mutations) {
-    for (let mutation of mutations) {
-      for (let i = 0; i < mutation.removedNodes.length; i++) {
-        let node = mutation.removedNodes.item(i);
-        if (node != aNode) {
-          continue;
+    let observer = new MutationObserver(function onMutatations(mutations) {
+      for (let mutation of mutations) {
+        for (let i = 0; i < mutation.removedNodes.length; i++) {
+          let node = mutation.removedNodes.item(i);
+          if (node != aNode) {
+            continue;
+          }
+          observer.disconnect();
+          resolve();
         }
-        observer.disconnect();
-        deferred.resolve();
       }
-    }
+    });
+    observer.observe(parent, {childList: true});
   });
-  observer.observe(parent, {childList: true});
-  return deferred.promise;
 }
 
 function promiseCloseChat(chat) {
   let promise = promiseNodeRemoved(chat);
   chat.close();
   return promise;
 }
 
@@ -673,39 +577,39 @@ function openChatViaUser() {
 
 
 // Support for going on and offline.
 // (via browser/base/content/test/browser_bookmark_titles.js)
 var origProxyType = Services.prefs.getIntPref('network.proxy.type');
 
 function toggleOfflineStatus(goOffline) {
   // Bug 968887 fix.  when going on/offline, wait for notification before continuing
-  let deferred = Promise.defer();
-  if (!goOffline) {
-    Services.prefs.setIntPref('network.proxy.type', origProxyType);
-  }
-  if (goOffline != Services.io.offline) {
-    info("initial offline state " + Services.io.offline);
-    let expect = !Services.io.offline;
-    Services.obs.addObserver(function offlineChange(subject, topic, data) {
-      Services.obs.removeObserver(offlineChange, "network:offline-status-changed");
-      info("offline state changed to " + Services.io.offline);
-      is(expect, Services.io.offline, "network:offline-status-changed successful toggle");
-      deferred.resolve();
-    }, "network:offline-status-changed", false);
-    BrowserOffline.toggleOfflineStatus();
-  } else {
-    deferred.resolve();
-  }
-  if (goOffline) {
-    Services.prefs.setIntPref('network.proxy.type', 0);
-    // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache.
-    Services.cache2.clear();
-  }
-  return deferred.promise;
+  return new Promise(resolve => {
+    if (!goOffline) {
+      Services.prefs.setIntPref('network.proxy.type', origProxyType);
+    }
+    if (goOffline != Services.io.offline) {
+      info("initial offline state " + Services.io.offline);
+      let expect = !Services.io.offline;
+      Services.obs.addObserver(function offlineChange(subject, topic, data) {
+        Services.obs.removeObserver(offlineChange, "network:offline-status-changed");
+        info("offline state changed to " + Services.io.offline);
+        is(expect, Services.io.offline, "network:offline-status-changed successful toggle");
+        resolve();
+      }, "network:offline-status-changed", false);
+      BrowserOffline.toggleOfflineStatus();
+    } else {
+      resolve();
+    }
+    if (goOffline) {
+      Services.prefs.setIntPref('network.proxy.type', 0);
+      // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache.
+      Services.cache2.clear();
+    }
+  });
 }
 
 function goOffline() {
   // Simulate a network outage with offline mode. (Localhost is still
   // accessible in offline mode, so disable the test proxy as well.)
   return toggleOfflineStatus(true);
 }
 
--- a/browser/base/content/test/social/social_activate_basic.html
+++ b/browser/base/content/test/social/social_activate_basic.html
@@ -1,11 +1,12 @@
 <html>
 <head>
-	<title>Activation test</title>
+    <meta charset="utf-8">
+    <title>Activation test</title>
 </head>
 <script>
 // icons from http://findicons.com/icon/158311/firefox?id=356182 by ipapun
 var data = {
   // currently required
   "name": "Demo Social Service",
   "iconURL": "chrome://branding/content/icon16.png",
   "icon32URL": "chrome://branding/content/favicon32.png",