Bug 820489: fix runSocialTestWithProvider to always disable social functionality entirely, before removing the selected provider, r=markh
authorGavin Sharp <gavin@gavinsharp.com>
Mon, 17 Dec 2012 15:39:49 -0800
changeset 125449 31735047f64420357c88ab4f0ba57539d9215a81
parent 125448 28dbf131791f86a1b69f09b5b393da149bac8101
child 125450 e14c7409ede7898aeb9eb123faef49bc96220cbd
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs820489
milestone20.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 820489: fix runSocialTestWithProvider to always disable social functionality entirely, before removing the selected provider, r=markh
browser/base/content/test/social/head.js
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -39,18 +39,47 @@ function runSocialTestWithProvider(manif
           ensureSocialUrlNotRemembered(m[what]);
         }
       }
     });
   });
 
   info("runSocialTestWithProvider: " + manifests.toSource());
 
+  let finishCount = 0;
+  function finishIfDone(callFinish) {
+    finishCount++;
+    if (finishCount == manifests.length)
+      finish();
+  }
+  function removeAddedProviders(cleanup) {
+    manifests.forEach(function (m) {
+      // If we're "cleaning up", don't call finish when done.
+      let callback = cleanup ? function () {} : finishIfDone;
+      // Similarly, if we're cleaning up, catch exceptions from removeProvider
+      let removeProvider = SocialService.removeProvider.bind(SocialService);
+      if (cleanup) {
+        removeProvider = function (origin, cb) {
+          try {
+            SocialService.removeProvider(origin, cb);
+          } catch (ex) {
+            // Ignore "provider doesn't exist" errors.
+            if (ex.message == "SocialService.removeProvider: no provider with this origin exists!")
+              return;
+            info("Failed to clean up provider " + origin + ": " + ex);
+          }
+        }
+      }
+      removeProvider(m.origin, callback);
+    });
+  }
+
   let providersAdded = 0;
   let firstProvider;
+
   manifests.forEach(function (m) {
     SocialService.addProvider(m, function(provider) {
       provider.active = true;
 
       providersAdded++;
       info("runSocialTestWithProvider: provider added");
 
       // we want to set the first specified provider as the UI's provider
@@ -60,33 +89,25 @@ 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) {
         // Set the UI's provider and enable the feature
         Social.provider = firstProvider;
         Social.enabled = true;
 
-        registerCleanupFunction(function () {
+        function finishSocialTest(cleanup) {
           // disable social before removing the providers to avoid providers
           // being activated immediately before we get around to removing it.
           Services.prefs.clearUserPref("social.enabled");
-          // if one test happens to fail, it is likely finishSocialTest will not
-          // be called, causing most future social tests to also fail as they
-          // attempt to add a provider which already exists - so work
-          // around that by also attempting to remove the test provider.
-          manifests.forEach(function (m) {
-            try {
-              SocialService.removeProvider(m.origin, finish);
-            } catch (ex) {}
-          });
+          removeAddedProviders(cleanup);
+        }
+        registerCleanupFunction(function () {
+          finishSocialTest(true);
         });
-        function finishSocialTest() {
-          SocialService.removeProvider(provider.origin, finish);
-        }
         callback(finishSocialTest);
       }
     });
   });
 }
 
 function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
   let testIter = Iterator(tests);