Bug 926830 - Test cleanup for plugin enabledState usage, content. r=smaug
☠☠ backed out by 95e4bcfcd8dc ☠ ☠
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 17 Feb 2014 15:57:27 +0100
changeset 170183 97c8c8491b1738fc566d9ba559ec3bdd2ee15a12
parent 170182 775c66270625c26dc182c2e969f041ed0e4ec6ab
child 170184 18f6689b172d4b2c99a6ae812be47aa529eea237
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerssmaug
bugs926830
milestone30.0a1
Bug 926830 - Test cleanup for plugin enabledState usage, content. r=smaug
content/base/test/chrome/chrome.ini
content/base/test/chrome/head.js
content/base/test/chrome/test_bug391728.html
content/base/test/head_plain.js
content/base/test/mochitest.ini
content/base/test/test_mixed_content_blocker.html
content/base/test/test_object.html
content/base/test/test_plugin_freezing.html
content/html/content/test/mochitest.ini
content/html/content/test/test_iframe_sandbox_plugins.html
--- a/content/base/test/chrome/chrome.ini
+++ b/content/base/test/chrome/chrome.ini
@@ -6,16 +6,17 @@ support-files =
   cpows_parent.xul
   file_bug391728.html
   file_bug391728_2.html
   file_bug549682.xul
   file_bug616841.xul
   file_bug816340.xul
   fileconstructor_file.png
   frame_bug814638.xul
+  head.js
   host_bug814638.xul
   title_window.xul
 
 [test_bug206691.xul]
 [test_bug339494.xul]
 [test_bug357450.xul]
 [test_bug380418.html]
 [test_bug380418.html^headers^]
new file mode 100644
--- /dev/null
+++ b/content/base/test/chrome/head.js
@@ -0,0 +1,26 @@
+function getTestPlugin(aName) {
+  var pluginName = aName || "Test Plug-in";
+  var ph = Components.classes["@mozilla.org/plugin/host;1"]
+             .getService(Components.interfaces.nsIPluginHost);
+  var tags = ph.getPluginTags();
+
+  // Find the test plugin
+  for (var i = 0; i < tags.length; i++) {
+    if (tags[i].name == pluginName)
+      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 its previous value after the test
+// ends
+function setTestPluginEnabledState(newEnabledState, pluginName) {
+  var plugin = getTestPlugin(pluginName);
+  var oldEnabledState = plugin.enabledState;
+  plugin.enabledState = newEnabledState;
+  SimpleTest.registerCleanupFunction(function() {
+    getTestPlugin(pluginName).enabledState = oldEnabledState;
+  });
+}
--- a/content/base/test/chrome/test_bug391728.html
+++ b/content/base/test/chrome/test_bug391728.html
@@ -2,16 +2,17 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=391728
 -->
 <head>
   <title>Test for Bug 391728</title>
   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
+  <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391728">Mozilla Bug 391728</a>
 <p id="display"></p>
 <div id="content">
   <iframe id="testframe" width="150" height="250" src="about:blank"></iframe>
 </div>
@@ -95,17 +96,16 @@ function start_test(plugin) {
   var frame = document.getElementById("testframe");
   frame.addEventListener("load", frame_loaded, true);
   load_frame(test_normal, "file_bug391728");
 }
 
 function finish_test(plugin) {
   Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
   resetBlocklist();
-  plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
   SimpleTest.finish();
 }
 
 function load_frame(nextTest, file) {
   gNextTest = nextTest;
   gDisabled = [];
   gUnknown = [];
   gBlocked = [];
@@ -147,28 +147,28 @@ function test_list(list) {
   }
 }
 
 function test_normal(plugin) {
   is(gUnknown.length, 0, "Should not have been any unknown plugins");
   is(gDisabled.length, 0, "Should not have been any disabled plugins");
   is(gBlocked.length, 0, "Should not have been any blocked plugins");
   test_style("solid");
-  plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED;
+  setTestPluginEnabledState(Components.interfaces.nsIPluginTag.STATE_DISABLED);
   load_frame(test_disabled, "file_bug391728");
 }
 
 function test_disabled(plugin) {
   is(gUnknown.length, 0, "Should not have been any unknown plugins");
   is(gDisabled.length, PLUGIN_COUNT, "Should have been disabled plugins");
   test_list(gDisabled);
   is(gBlocked.length, 0, "Should not have been any blocked plugins");
   test_style("dotted");
   ok(plugin.disabled, "Plugin lost its disabled status");
-  plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
+  setTestPluginEnabledState(Components.interfaces.nsIPluginTag.STATE_ENABLED);
 
   setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml",
     function() {
       load_frame(test_blocked, "file_bug391728");
     });
 }
 
 function test_blocked(plugin) {
@@ -189,13 +189,14 @@ function test_unknown(plugin) {
   test_style("none");
   setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
     ok(!plugin.blocklisted, "Plugin shouldn't remain blocklisted");
     finish_test(plugin);
   });
 }
 
 SimpleTest.waitForExplicitFinish();
+setTestPluginEnabledState(Components.interfaces.nsIPluginTag.STATE_ENABLED);
 window.addEventListener("load", init_test, false);
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/content/base/test/head_plain.js
@@ -0,0 +1,27 @@
+
+function getTestPlugin(pluginName) {
+  var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
+                                 .getService(SpecialPowers.Ci.nsIPluginHost);
+  var tags = ph.getPluginTags();
+  var name = pluginName || "Test Plug-in";
+  for (var tag of tags) {
+    if (tag.name == name) {
+      return tag;
+    }
+  }
+
+  ok(false, "Could not find plugin tag with plugin name '" + name + "'");
+  return null;
+}
+
+// call this to set the test plugin(s) initially expected enabled state.
+// it will automatically be reset to its previous value after the test
+// ends
+function setTestPluginEnabledState(newEnabledState, pluginName) {
+  var plugin = getTestPlugin(pluginName);
+  var oldEnabledState = plugin.enabledState;
+  plugin.enabledState = newEnabledState;
+  SimpleTest.registerCleanupFunction(function() {
+    getTestPlugin(pluginName).enabledState = oldEnabledState;
+  });
+}
--- a/content/base/test/mochitest.ini
+++ b/content/base/test/mochitest.ini
@@ -195,16 +195,17 @@ support-files =
   file_xhtmlserializer_2_basic.xhtml
   file_xhtmlserializer_2_enthtml.xhtml
   file_xhtmlserializer_2_entw3c.xhtml
   file_xhtmlserializer_2_latin1.xhtml
   fileutils.js
   forRemoval.resource
   forRemoval.resource^headers^
   formReset.html
+  head_plain.js
   invalid_accesscontrol.resource
   invalid_accesscontrol.resource^headers^
   mutationobserver_dialog.html
   progressserver.sjs
   responseIdentical.sjs
   script-1_bug597345.sjs
   script-2_bug597345.js
   script_bug602838.sjs
--- a/content/base/test/test_mixed_content_blocker.html
+++ b/content/base/test/test_mixed_content_blocker.html
@@ -3,28 +3,21 @@
 <!--
 Tests for Mixed Content Blocker
 https://bugzilla.mozilla.org/show_bug.cgi?id=62178
 -->
 <head>
   <meta charset="utf-8">
   <title>Tests for Bug 62178</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head_plain.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 
   <script>
-  var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
-                        .getService(SpecialPowers.Ci.nsIPluginHost);
-  var tags = ph.getPluginTags();
-  for (var tag of tags) {
-    if (tag.name == "Test Plug-in") {
-      tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;;
-    }
-  }
-
+  setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
   var origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content");
   var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
 
   var counter = 0;
   var settings = [ [true, true], [true, false], [false, true], [false, false] ];
 
   var blockActive;
--- a/content/base/test/test_object.html
+++ b/content/base/test/test_object.html
@@ -1,29 +1,23 @@
 <!DOCTYPE html>
 <html>
   <head>
     <title>Plugin instantiation</title>
     <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     <script type="application/javascript" src="/tests/SimpleTest/SpecialPowers.js"></script>
+    <script type="application/javascript" src="head_plain.js"></script>
     <meta charset="utf-8">
   <body onload="onLoad()">
     <script class="testbody" type="text/javascript;version=1.8">
 
       "use strict";
       SimpleTest.waitForExplicitFinish();
 
-      var pluginHost = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
-                        .getService(SpecialPowers.Ci.nsIPluginHost);
-      var pluginTags = pluginHost.getPluginTags();
-      for (var tag of pluginTags) {
-        if (tag.name == "Test Plug-in") {
-          tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;;
-        }
-      }
+      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
       // This can go away once embed also is on WebIDL
       let OBJLC = SpecialPowers.Ci.nsIObjectLoadingContent;
 
       // Use string modes in this test to make the test easier to read/debug.
       // nsIObjectLoadingContent refers to this as "type", but I am using "mode"
       // in the test to avoid confusing with content-type.
       let prettyModes = {};
--- a/content/base/test/test_plugin_freezing.html
+++ b/content/base/test/test_plugin_freezing.html
@@ -1,19 +1,23 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for plugin freezing and thawing</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="head_plain.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <div id="content" style="display: none">
 </div>
+<script type="text/javascript">
+setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
+</script>
 <embed id='e1' type='application/x-test'></embed>
 <script>
 var e1 = document.getElementById('e1');
 var w;
 
 var testIndex = 0;
 var tests;
 
--- a/content/html/content/test/mochitest.ini
+++ b/content/html/content/test/mochitest.ini
@@ -12,16 +12,17 @@ support-files =
   bug277890_iframe.html
   bug277890_load.html
   bug340800_iframe.txt
   bug372098-link-target.html
   bug392567.jar
   bug392567.jar^headers^
   bug441930_iframe.html
   bug514856_iframe.html
+  enableTestPlugin.js
   file_bug209275_1.html
   file_bug209275_2.html
   file_bug209275_3.html
   file_bug297761.html
   file_bug417760.png
   file_bug893537.html
   file_formSubmission_img.jpg
   file_formSubmission_text.txt
--- a/content/html/content/test/test_iframe_sandbox_plugins.html
+++ b/content/html/content/test/test_iframe_sandbox_plugins.html
@@ -3,16 +3,17 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=341604
 Implement HTML5 sandbox attribute for IFRAMEs
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 341604 - plugins</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="enableTestPlugin.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <script type="application/javascript">
 /** Test for Bug 341604 - Implement HTML5 sandbox attribute for IFRAMEs **/
 /** Plugin tests **/
 SimpleTest.waitForExplicitFinish();
 
 function doTest() {