Bug 781386: add pref to avoid loading built-in providers during test runs, r=markh/mixedpuppy
authorGavin Sharp <gavin@gavinsharp.com>
Wed, 08 Aug 2012 18:09:37 -0700
changeset 102021 b6e70e92f758699092cd0e914feb240f2875d485
parent 102020 a461b5f53b201af25c7d4f5dab2c59404581052b
child 102022 296192b98fa218e848e152286d6d4fd495702c63
push id13278
push usergsharp@mozilla.com
push dateThu, 09 Aug 2012 23:57:09 +0000
treeherdermozilla-inbound@b6e70e92f758 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, mixedpuppy
bugs781386
milestone17.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 781386: add pref to avoid loading built-in providers during test runs, r=markh/mixedpuppy
browser/base/content/test/Makefile.in
browser/base/content/test/browser_shareButton.js
browser/base/content/test/browser_social_mozSocial_API.js
browser/base/content/test/browser_social_shareButton.js
browser/base/content/test/browser_social_sidebar.js
browser/base/content/test/browser_social_toolbar.js
browser/base/content/test/head.js
browser/modules/Social.jsm
build/automation.py.in
toolkit/components/social/SocialService.jsm
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -151,17 +151,17 @@ endif
                  browser_bug710878.js \
                  browser_bug719271.js \
                  browser_bug724239.js \
                  browser_bug735471.js \
                  browser_bug743421.js \
                  browser_bug749738.js \
                  browser_bug763468.js \
                  browser_bug767836.js \
-                 browser_shareButton.js \
+                 browser_social_shareButton.js \
                  browser_canonizeURL.js \
                  browser_customize.js \
                  browser_findbarClose.js \
                  browser_homeDrop.js \
                  browser_keywordBookmarklets.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
                  browser_customize_popupNotification.js \
--- a/browser/base/content/test/browser_social_mozSocial_API.js
+++ b/browser/base/content/test/browser_social_mozSocial_API.js
@@ -1,28 +1,24 @@
 /* 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/. */
 
-let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
-
 function test() {
   waitForExplicitFinish();
 
   let manifest = { // normal provider
     name: "provider 1",
     origin: "http://example.com",
     sidebarURL: "http://example.com/browser/browser/base/content/test/social_sidebar.html",
     workerURL: "http://example.com/browser/browser/base/content/test/social_worker.js",
     iconURL: "chrome://branding/content/icon48.png"
   };
-  runSocialTestWithProvider(manifest, function () {
-    runSocialTests(tests, undefined, undefined, function () {
-      SocialService.removeProvider(Social.provider.origin, finish);
-    });
+  runSocialTestWithProvider(manifest, function (finishcb) {
+    runSocialTests(tests, undefined, undefined, finishcb);
   });
 }
 
 var tests = {
   testStatusIcons: function(next) {
     let iconsReady = false;
     let gotSidebarMessage = false;
 
rename from browser/base/content/test/browser_shareButton.js
rename to browser/base/content/test/browser_social_shareButton.js
--- a/browser/base/content/test/browser_shareButton.js
+++ b/browser/base/content/test/browser_social_shareButton.js
@@ -1,53 +1,51 @@
 /* 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/. */
 
 let prefName = "social.enabled",
     shareButton,
     sharePopup,
     okButton,
-    undoButton;
+    undoButton,
+    gFinishCB;
 
 function test() {
   waitForExplicitFinish();
 
   // Need to load a non-empty page for the social share button to appear
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:", {skipAnimation: true});
   tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
     tab.linkedBrowser.removeEventListener("load", tabLoad, true);
     executeSoon(tabLoaded);
   }, true);
 
-  // Enable the service to start
-  Services.prefs.setBoolPref(prefName, true);
-
   registerCleanupFunction(function() {
-    Services.prefs.clearUserPref(prefName);
     gBrowser.removeTab(tab);
   });
 }
 
 function tabLoaded() {
   ok(Social, "Social module loaded");
 
-  // If the UI is already active, run the test immediately, otherwise wait
-  // for initialization.
-  if (Social.provider) {
-    executeSoon(testInitial);
-  } else {
-    Services.obs.addObserver(function obs() {
-      Services.obs.removeObserver(obs, "test-social-ui-ready");
-      executeSoon(testInitial);
-    }, "test-social-ui-ready", false);
-  }
+  let manifest = { // normal provider
+    name: "provider 1",
+    origin: "https://example.com",
+    sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
+    workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
+    iconURL: "chrome://branding/content/icon48.png"
+  };
+  runSocialTestWithProvider(manifest, function (finishcb) {
+    gFinishCB = finishcb;
+    testInitial();
+  });
 }
 
-function testInitial() {
+function testInitial(finishcb) {
   ok(Social.provider, "Social provider is active");
   ok(Social.provider.enabled, "Social provider is enabled");
   ok(Social.provider.port, "Social provider has a port to its FrameWorker");
 
   shareButton = SocialShareButton.shareButton;
   sharePopup = SocialShareButton.sharePopup;
   ok(shareButton, "share button exists");
   ok(sharePopup, "share popup exists");
@@ -111,29 +109,43 @@ function checkShortcutWorked(keyTarget) 
     ok(true, "popup was shown after second use of keyboard shortcut");
     executeSoon(checkOKButton);
   });
   EventUtils.synthesizeKey("l", {accelKey: true, shiftKey: true}, keyTarget);
 }
 
 function checkOKButton() {
   is(document.activeElement, okButton, "ok button should be focused by default");
-  checkNextInTabOrder(undoButton, function () {
-    checkNextInTabOrder(okButton, testCloseBySpace);
-  });
+
+  // This rest of particular test doesn't really apply on Mac, since buttons
+  // aren't focusable by default.
+  if (navigator.platform.indexOf("Mac") != -1) {
+    executeSoon(testCloseBySpace);
+    return;
+  }
+
+  let displayName = document.getElementById("socialUserDisplayName");
+
+  // Linux has the buttons in the [unshare] [ok] order, so displayName will come first.
+  if (navigator.platform.indexOf("Linux") != -1) {
+    checkNextInTabOrder(displayName, function () {
+      checkNextInTabOrder(undoButton, function () {
+        checkNextInTabOrder(okButton, testCloseBySpace);
+      });
+    });
+  } else {
+    checkNextInTabOrder(undoButton, function () {
+      checkNextInTabOrder(displayName, function () {
+        checkNextInTabOrder(okButton, testCloseBySpace);
+      });
+    });
+  }
 }
 
 function checkNextInTabOrder(element, next) {
-  // This particular test doesn't really apply on Mac, since buttons aren't
-  // focusable by default.
-  if (navigator.platform.indexOf("Mac") != -1) {
-    executeSoon(next);
-    return;
-  }
-
   function listener() {
     element.removeEventListener("focus", listener);
     is(document.activeElement, element, element.id + " should be next in tab order");
     executeSoon(next);
   }
   element.addEventListener("focus", listener);
   // Register a cleanup function to remove the listener in case this test fails
   registerCleanupFunction(function () {
@@ -150,10 +162,10 @@ function testCloseBySpace() {
     executeSoon(testDisable);
   });
   EventUtils.synthesizeKey("VK_SPACE", {});
 }
 
 function testDisable() {
   Services.prefs.setBoolPref(prefName, false);
   is(shareButton.hidden, true, "Share button should be hidden when pref is disabled");
-  finish();
+  gFinishCB();
 }
--- a/browser/base/content/test/browser_social_sidebar.js
+++ b/browser/base/content/test/browser_social_sidebar.js
@@ -1,28 +1,26 @@
 /* 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/. */
 
-let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
-
 function test() {
   waitForExplicitFinish();
 
   let manifest = { // normal provider
     name: "provider 1",
     origin: "https://example.com",
     sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
     workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
     iconURL: "chrome://branding/content/icon48.png"
   };
   runSocialTestWithProvider(manifest, doTest);
 }
 
-function doTest() {
+function doTest(finishcb) {
   ok(SocialSidebar.canShow, "social sidebar should be able to be shown");
   ok(SocialSidebar.enabled, "social sidebar should be on by default");
 
   let command = document.getElementById("Social:ToggleSidebar");
   let sidebar = document.getElementById("social-sidebar-box");
   let browser = sidebar.firstChild;
 
   function checkShown(shouldBeShown) {
@@ -45,18 +43,18 @@ function doTest() {
 
     checkShown(false);
 
     browser.addEventListener("sidebarshow", function sidebarshow() {
       browser.removeEventListener("sidebarshow", sidebarshow);
 
       checkShown(true);
 
-      // Remove the test provider
-      SocialService.removeProvider(Social.provider.origin, finish);
+      // Finish the test
+      finishcb();
     });
 
     // Toggle it back on
     info("Toggling sidebar back on");
     Social.toggleSidebar();
   });
 
   // Now toggle it off
--- a/browser/base/content/test/browser_social_toolbar.js
+++ b/browser/base/content/test/browser_social_toolbar.js
@@ -1,27 +1,23 @@
 /* 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/. */
 
-let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
-
 function test() {
   waitForExplicitFinish();
 
   let manifest = { // normal provider
     name: "provider 1",
     origin: "https://example1.com",
     workerURL: "https://example1.com/worker.js",
     iconURL: "chrome://branding/content/icon48.png"
   };
-  runSocialTestWithProvider(manifest, function () {
-    runSocialTests(tests, undefined, undefined, function () {
-      SocialService.removeProvider(Social.provider.origin, finish);
-    });
+  runSocialTestWithProvider(manifest, function (finishcb) {
+    runSocialTests(tests, undefined, undefined, finishcb);
   });
 }
 
 var tests = {
   testProfileSet: function(next) {
     let profile = {
       portrait: "https://example.com/portrait.jpg",
       userName: "trickster",
--- a/browser/base/content/test/head.js
+++ b/browser/base/content/test/head.js
@@ -84,43 +84,38 @@ function waitForCondition(condition, nex
       moveOn();
     }
     tries++;
   }, 100);
   var moveOn = function() { clearInterval(interval); nextTest(); };
 }
 
 function runSocialTestWithProvider(manifest, callback) {
+  let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
+
+  info("runSocialTestWithProvider: " + manifest.toSource());
+
   let oldProvider;
-  function saveOldProviderAndStartTestWith(provider) {
+  SocialService.addProvider(manifest, function(provider) {
+    info("runSocialTestWithProvider: provider added");
     oldProvider = Social.provider;
     Social.provider = provider;
 
     // Now that we've set the UI's provider, enable the social functionality
     Services.prefs.setBoolPref("social.enabled", true);
 
     registerCleanupFunction(function () {
       Social.provider = oldProvider;
       Services.prefs.clearUserPref("social.enabled");
     });
 
-    callback();
-  }
-
-  SocialService.addProvider(manifest, function(provider) {
-    // If the UI is already active, run the test immediately, otherwise wait
-    // for initialization.
-    if (Social.provider) {
-      saveOldProviderAndStartTestWith(provider);
-    } else {
-      Services.obs.addObserver(function obs() {
-        Services.obs.removeObserver(obs, "test-social-ui-ready");
-        saveOldProviderAndStartTestWith(provider);
-      }, "test-social-ui-ready", false);
+    function finishSocialTest() {
+      SocialService.removeProvider(provider.origin, finish);
     }
+    callback(finishSocialTest);
   });
 }
 
 
 function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
   let testIter = Iterator(tests);
 
   if (cbPreTest === undefined) {
--- a/browser/modules/Social.jsm
+++ b/browser/modules/Social.jsm
@@ -26,17 +26,16 @@ let Social = {
     }
 
     // Eventually this might want to retrieve a specific provider, but for now
     // just use the first available.
     SocialService.getProviderList(function (providers) {
       if (providers.length)
         this.provider = providers[0];
       callback();
-      Services.obs.notifyObservers(null, "test-social-ui-ready", "");
     }.bind(this));
   },
 
   get uiVisible() {
     return this.provider && this.provider.enabled && this.provider.port;
   },
 
   set enabled(val) {
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -351,16 +351,17 @@ class Automation(object):
     os.mkdir(profileDir)
 
     # Set up permissions database
     locations = self.readLocations()
     self.setupPermissionsDatabase(profileDir,
       {'allowXULXBL':[(l.host, 'noxul' not in l.options) for l in locations]});
 
     part = """\
+user_pref("social.skipLoadingProviders", true);
 user_pref("browser.console.showInPanel", true);
 user_pref("browser.dom.window.dump.enabled", true);
 user_pref("browser.firstrun.show.localepicker", false);
 user_pref("browser.firstrun.show.uidiscovery", false);
 user_pref("browser.startup.page", 0); // use about:blank, not browser.startup.homepage
 user_pref("browser.ui.layout.tablet", 0); // force tablet UI off
 user_pref("dom.allow_scripts_to_close_windows", true);
 user_pref("dom.disable_open_during_load", false);
--- a/toolkit/components/social/SocialService.jsm
+++ b/toolkit/components/social/SocialService.jsm
@@ -36,16 +36,25 @@ XPCOMUtils.defineLazyGetter(SocialServic
   Services.obs.addObserver(function xpcomShutdown() {
     Services.obs.removeObserver(xpcomShutdown, "xpcom-shutdown");
     Services.prefs.removeObserver("social.enabled", prefObserver);
   }, "xpcom-shutdown", false);
 
   // Initialize the MozSocialAPI
   MozSocialAPI.enabled = SocialServiceInternal.enabled;
 
+  // Don't load any providers from prefs if the test pref is set
+  let skipLoading = false;
+  try {
+    skipLoading = Services.prefs.getBoolPref("social.skipLoadingProviders");
+  } catch (ex) {}
+
+  if (skipLoading)
+    return {};
+
   // Now retrieve the providers
   let providers = {};
   let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
   let prefs = MANIFEST_PREFS.getChildList("", {});
   prefs.forEach(function (pref) {
     try {
       var manifest = JSON.parse(MANIFEST_PREFS.getCharPref(pref));
       if (manifest && typeof(manifest) == "object") {