Bug 926830 - Test cleanup for plugin enabledState usage, toolkit. r=bsmedberg
☠☠ backed out by b994e8b4c369 ☠ ☠
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 17 Feb 2014 15:57:54 +0100
changeset 170185 44dbd2276837ebb221f5971a1c45b695518b2c51
parent 170184 18f6689b172d4b2c99a6ae812be47aa529eea237
child 170186 f2cade11e3c086de118a03b99fb8445d41b9c201
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbsmedberg
bugs926830
milestone30.0a1
Bug 926830 - Test cleanup for plugin enabledState usage, toolkit. r=bsmedberg
toolkit/mozapps/extensions/test/browser/browser_CTP_plugins.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/test/browser/browser_CTP_plugins.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_CTP_plugins.js
@@ -30,18 +30,17 @@ function setAndUpdateBlocklist(aURL, aCa
 function resetBlocklist(aCallback) {
   Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL);
 }
 
 function test() {
   waitForExplicitFinish();
   Services.prefs.setBoolPref("plugins.click_to_play", true);
   Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
-  let pluginTag = getTestPluginTag();
-  pluginTag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
+  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
   open_manager("addons://list/plugin", part1);
 }
 
 function part1(aWindow) {
   gManagerWindow = aWindow;
   AddonManager.getAddonsByTypes(["plugin"], part2);
 }
 
@@ -214,15 +213,13 @@ function part13() {
   setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
     run_next_test();
   });
 }
 
 function end_test() {
   Services.prefs.clearUserPref("plugins.click_to_play");
   Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
-  let pluginTag = getTestPluginTag();
-  pluginTag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   resetBlocklist();
   close_manager(gManagerWindow, function() {
     finish();
   });
 }
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -1263,8 +1263,22 @@ function getTestPluginTag() {
   // Find the test plugin
   for (let i = 0; i < tags.length; i++) {
     if (tags[i].name == "Test Plug-in")
       return tags[i];
   }
   ok(false, "Unable to find plugin");
   return null;
 }
+
+// Call this to set the test plugin(s) initially expected enabled state.
+// It will automatically be reset to it's previous value after the test
+// ends
+function setTestPluginEnabledState(newEnabledState, pluginTag) {
+  if (!pluginTag) {
+    pluginTag = getTestPluginTag();
+  }
+  var oldEnabledState = pluginTag.enabledState;
+  pluginTag.enabledState = newEnabledState;
+  SimpleTest.registerCleanupFunction(function() {
+    pluginTag.enabledState = oldEnabledState;
+  });
+}
\ No newline at end of file