Bug 1282768 - Part 4 - Fix intermittent browser_social_activation.js. r=past draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Sun, 20 Nov 2016 18:40:29 +0100
changeset 441676 d7089c38a63e2c53f6d31b72ea17a93e0372fc38
parent 441675 daf79cf7ab46e2605c1c86c0d2f0f6c9cd8c972e
child 441677 c6400aab1ab152dafccdd563df7c334d11c08b84
push id36489
push userpaolo.mozmail@amadzone.org
push dateSun, 20 Nov 2016 17:49:09 +0000
reviewerspast
bugs1282768
milestone53.0a1
Bug 1282768 - Part 4 - Fix intermittent browser_social_activation.js. r=past MozReview-Commit-ID: IRRA1Ba2cBU
browser/base/content/test/social/browser_social_activation.js
--- a/browser/base/content/test/social/browser_social_activation.js
+++ b/browser/base/content/test/social/browser_social_activation.js
@@ -106,42 +106,54 @@ function clickAddonRemoveButton(tab, aCa
       executeSoon(function() { aCallback(addon); });
     });
 
     BrowserTestUtils.synthesizeMouseAtCenter(button, {}, tab.linkedBrowser);
   });
 }
 
 function activateOneProvider(manifest, finishActivation, aCallback) {
-  info("activating provider " + manifest.name);
-  let panel = document.getElementById("servicesInstall-notification");
-  BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
-    ok(!panel.hidden, "servicesInstall-notification panel opened");
-    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(manifest.origin).then(() => {
-          checkSocialUI();
-          executeSoon(aCallback);
-        });
-      }
-    });
-    if (finishActivation)
-      panel.button.click();
-    else
-      panel.closebutton.click();
-  });
+  Task.spawn(function* () {
+    info("activating provider " + manifest.name);
+
+    // Wait for the helper callback and the popup shown event in any order.
+    let popupShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                   "popupshown");
+    yield new Promise(resolve => activateProvider(manifest.origin, resolve));
+    yield popupShown;
+
+    info("servicesInstall-notification panel opened");
+
+    // Start waiting for the activation event before the click on the button.
+    let providerLoaded = finishActivation ?
+                         waitForProviderLoad(manifest.origin) : null;
+    let popupHidden = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                    "popuphidden");
 
-  // the test will continue as the popup events fire...
-  activateProvider(manifest.origin, function() {
-    info("waiting on activation panel to open/close...");
-  });
+    // We need to wait for PopupNotifications.jsm to place the element.
+    let notification;
+    yield BrowserTestUtils.waitForCondition(
+          () => (notification = PopupNotifications.panel.childNodes[0]));
+    is(notification.id, "servicesInstall-notification");
+
+    if (finishActivation) {
+      notification.button.click();
+    } else {
+      notification.closebutton.click();
+    }
+
+    yield providerLoaded;
+    yield popupHidden;
+
+    info("servicesInstall-notification panel hidden");
+
+    if (finishActivation) {
+      checkSocialUI();
+    }
+  }).then(() => executeSoon(aCallback)).catch(ex => ok(false, ex));
 }
 
 var gTestDomains = ["https://example.com", "https://test1.example.com", "https://test2.example.com"];
 var gProviders = [
   {
     name: "provider 1",
     origin: "https://example.com",
     shareURL: "https://example.com/browser/browser/base/content/test/social/social_share.html?provider1",