Bug 1094218 - Intermittent browser_addons.js, simplify tests. a=test-only
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 02 Sep 2015 14:37:02 -0600
changeset 289073 ccbc0a055bbcc6adc2e02751484a1bc8a30cc902
parent 289072 1d9d6a7a958ab585f035582d7901e1071632339d
child 289074 d2fd0d87e052da6ef0b305b5fed4633c1c203898
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs1094218
milestone42.0a2
Bug 1094218 - Intermittent browser_addons.js, simplify tests. a=test-only
browser/base/content/test/social/browser_addons.js
--- a/browser/base/content/test/social/browser_addons.js
+++ b/browser/base/content/test/social/browser_addons.js
@@ -1,31 +1,32 @@
 let AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm", {}).AddonManager;
 let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
 
-const ADDON_TYPE_SERVICE     = "service";
-const ID_SUFFIX              = "@services.mozilla.org";
-const STRING_TYPE_NAME       = "type.%ID%.name";
-const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
-
 let manifest = {
   name: "provider 1",
   origin: "https://example.com",
-  sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
-  workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
+  sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar_empty.html",
   iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
 };
 let manifest2 = { // used for testing install
   name: "provider 2",
   origin: "https://test1.example.com",
-  sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html",
-  workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
+  sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar_empty.html",
   iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png",
   version: 1
 };
+let manifestUpgrade = { // used for testing install
+  name: "provider 3",
+  origin: "https://test2.example.com",
+  sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html",
+  workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
+  iconURL: "https://test2.example.com/browser/browser/base/content/test/general/moz.png",
+  version: 1
+};
 
 function test() {
   waitForExplicitFinish();
 
   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");
@@ -78,32 +79,27 @@ function installListener(next, aManifest
       ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
       AddonManager.removeAddonListener(this);
     }
   };
 }
 
 var tests = {
   testHTTPInstallFailure: function(next) {
-    let activationURL = "http://example.com/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
-      let doc = tab.linkedBrowser.contentDocument;
-      let installFrom = doc.nodePrincipal.origin;
-      is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install");
-      let data = {
-        origin: doc.nodePrincipal.origin,
-        url: doc.location.href,
-        manifest: manifest,
-        window: window
-      }
-      Social.installProvider(data, function(addonManifest) {
-        ok(!addonManifest, "unable to install provider over http");
-        gBrowser.removeTab(tab);
-        next();
-      });
+    let installFrom = "http://example.com";
+    is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install");
+    let data = {
+      origin: installFrom,
+      url: installFrom+"/activate",
+      manifest: manifest,
+      window: window
+    }
+    Social.installProvider(data, function(addonManifest) {
+      ok(!addonManifest, "unable to install provider over http");
+      next();
     });
   },
   testAddonEnableToggle: function(next) {
     let expectEvent;
     let prefname = getManifestPrefname(manifest);
     let listener = {
       onEnabled: function(addon) {
         is(expectEvent, "onEnabled", "provider onEnabled");
@@ -131,17 +127,17 @@ var tests = {
       }
     };
     AddonManager.addAddonListener(listener);
 
     // we're only testing enable disable, so we quickly set the user-level pref
     // for this provider and test enable/disable toggling
     setManifestPref(prefname, manifest);
     ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
-    AddonManager.getAddonsByTypes([ADDON_TYPE_SERVICE], function(addons) {
+    AddonManager.getAddonsByTypes(["service"], function(addons) {
       for (let addon of addons) {
         if (addon.userDisabled) {
           expectEvent = "onEnabling";
           addon.userDisabled = false;
           // only test with one addon
           return;
         }
       }
@@ -186,99 +182,59 @@ var tests = {
       expectEvent = "onDisabling";
       SocialService.disableProvider(provider.origin, function() {
         AddonManager.removeAddonListener(listener);
         Services.prefs.clearUserPref(prefname);
         next();
       });
     });
   },
-  testForeignInstall: function(next) {
+  testDirectoryInstall: function(next) {
     AddonManager.addAddonListener(installListener(next, manifest2));
 
-    // we expect the addon install dialog to appear, we need to accept the
-    // install from the dialog.
-    info("Waiting for install dialog");
-    let panel = document.getElementById("servicesInstall-notification");
-    PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
-      PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
-      info("servicesInstall-notification panel opened");
-      panel.button.click();
-    })
-
-    let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    addTab(activationURL, function(tab) {
-      let doc = tab.linkedBrowser.contentDocument;
-      let installFrom = doc.nodePrincipal.origin;
-      Services.prefs.setCharPref("social.whitelist", "");
-      is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install");
-      let data = {
-        origin: doc.nodePrincipal.origin,
-        url: doc.location.href,
-        manifest: manifest2,
-        window: window
-      }
-      Social.installProvider(data, function(addonManifest) {
-        Services.prefs.clearUserPref("social.whitelist");
-        SocialService.enableProvider(addonManifest.origin, function(provider) {
-          Social.uninstallProvider(addonManifest.origin);
-          gBrowser.removeTab(tab);
-        });
-      });
-    });
-  },
-  testDirectoryInstall: function(next) {
-    AddonManager.addAddonListener(installListener(next, manifest2));
-    let panel = document.getElementById("servicesInstall-notification");
-    PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
-      PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
+    ensureEventFired(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"
-    addTab(activationURL, function(tab) {
-      let doc = tab.linkedBrowser.contentDocument;
-      let installFrom = doc.nodePrincipal.origin;
-      Services.prefs.setCharPref("social.directories", installFrom);
-      is(SocialService.getOriginActivationType(installFrom), "directory", "testing directory install");
-      let data = {
-        origin: installFrom,
-        url: doc.location.href,
-        manifest: manifest2,
-        window: window
-      }
-      Social.installProvider(data, function(addonManifest) {
-        Services.prefs.clearUserPref("social.directories");
-        SocialService.enableProvider(addonManifest.origin, function(provider) {
-          Social.uninstallProvider(addonManifest.origin);
-          gBrowser.removeTab(tab);
-        });
+    Services.prefs.setCharPref("social.directories", manifest2.origin);
+    is(SocialService.getOriginActivationType(manifest2.origin), "directory", "testing directory install");
+    let data = {
+      origin: manifest2.origin,
+      url: manifest2.origin + "/directory",
+      manifest: manifest2,
+      window: window
+    }
+    Social.installProvider(data, function(addonManifest) {
+      Services.prefs.clearUserPref("social.directories");
+      SocialService.enableProvider(addonManifest.origin, function(provider) {
+        Social.uninstallProvider(addonManifest.origin);
       });
     });
   },
   testUpgradeProviderFromWorker: function(next) {
     // add the provider, change the pref, add it again. The provider at that
     // point should be upgraded
-    let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
-    let panel = document.getElementById("servicesInstall-notification");
-    PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
-      PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
+    let activationURL = manifestUpgrade.origin + "/browser/browser/base/content/test/social/social_activate.html"
+    ensureEventFired(PopupNotifications.panel, "popupshown").then(() => {
+      let panel = document.getElementById("servicesInstall-notification");
       info("servicesInstall-notification panel opened");
       panel.button.click();
     });
 
     addTab(activationURL, function(tab) {
       let doc = tab.linkedBrowser.contentDocument;
       let installFrom = doc.nodePrincipal.origin;
       Services.prefs.setCharPref("social.whitelist", installFrom);
       let data = {
         origin: installFrom,
         url: doc.location.href,
-        manifest: manifest2,
+        manifest: manifestUpgrade,
         window: window
       }
       Social.installProvider(data, function(addonManifest) {
         SocialService.enableProvider(addonManifest.origin, function(provider) {
           is(provider.manifest.version, 1, "manifest version is 1");
 
           // watch for the provider-update and test the new version
           SocialService.registerProviderListener(function providerListener(topic, origin, providers) {
@@ -301,18 +257,17 @@ var tests = {
               let topic = e.data.topic;
               switch (topic) {
                 case "social.manifest":
                   let manifest = e.data.data;
                   is(manifest.version, 2, "manifest version is 2");
                   port.close();
                   Social.uninstallProvider(origin, function() {
                     Services.prefs.clearUserPref("social.whitelist");
-                    gBrowser.removeTab(tab);
-                    next();
+                    ensureBrowserTabClosed(tab).then(next);
                   });
                   break;
               }
             }
             port.postMessage({topic: "test-init"});
             port.postMessage({topic: "manifest-get"});
 
           });