Bug 1282768 - Part 4 - Fix intermittent browser_social_activation.js. r=past
MozReview-Commit-ID: IRRA1Ba2cBU
--- 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",