Bug 926830 - Test cleanup for plugin enabledState usage, widget. r=roc
☠☠ backed out by 203b1197d413 ☠ ☠
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 17 Feb 2014 15:58:06 +0100
changeset 169824 f2cade11e3c086de118a03b99fb8445d41b9c201
parent 169823 44dbd2276837ebb221f5971a1c45b695518b2c51
child 169825 9112c3abc3eaf65a6e6770ad3063dd081a535fab
push id40083
push usergeorg.fritzsche@googlemail.com
push dateFri, 21 Feb 2014 11:26:20 +0000
treeherdermozilla-inbound@4efc93b3c345 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs926830
milestone30.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 926830 - Test cleanup for plugin enabledState usage, widget. r=roc
widget/tests/chrome.ini
widget/tests/mochitest.ini
widget/tests/test_plugin_input_event.html
widget/tests/test_plugin_scroll_consistency.html
widget/tests/test_plugin_scroll_invalidation.html
widget/tests/utils.js
--- a/widget/tests/chrome.ini
+++ b/widget/tests/chrome.ini
@@ -1,10 +1,12 @@
 [DEFAULT]
-support-files = empty_window.xul
+support-files =
+  empty_window.xul
+  utils.js
 
 [test_bug343416.xul]
 [test_bug429954.xul]
 support-files = window_bug429954.xul
 [test_bug444800.xul]
 [test_bug478536.xul]
 skip-if = true # Bug 561929
 support-files = window_bug478536.xul
--- a/widget/tests/mochitest.ini
+++ b/widget/tests/mochitest.ini
@@ -1,8 +1,11 @@
+[DEFAULT]
+support-files = utils.js
+
 [test_assign_event_data.html]
 skip-if = toolkit == "cocoa" # Bug 933303
 [test_bug565392.html]
 skip-if = toolkit != "windows"
 [test_picker_no_crash.html]
 skip-if = toolkit != "windows"
 support-files = window_picker_no_crash_child.html
 [test_plugin_scroll_invalidation.html]
--- a/widget/tests/test_plugin_input_event.html
+++ b/widget/tests/test_plugin_input_event.html
@@ -3,29 +3,23 @@
 <head>
   <title>Test for plugin input event</title>
   <script type="text/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
   <script type="text/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
+  <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css"
           href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 </head>
 <body>
 <script type="application/javascript">
-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);
 </script>
 
 <p id="display">
   <embed id="plugin" type="application/x-test" wmode="opaque">
 </p>
 <div id="content" style="display: none">
 
 </div>
--- a/widget/tests/test_plugin_scroll_consistency.html
+++ b/widget/tests/test_plugin_scroll_consistency.html
@@ -1,26 +1,20 @@
 <html>
 <head>
   <title>Test for plugin child widgets not being messed up by scrolling</title>
   <script type="text/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css"
           href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 </head>
 <body onload="setTimeout(runTests, 0)">
 <script type="application/javascript">
-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);
 </script>
 
 <p id="display">
   <div style="overflow:hidden; height:100px;" id="scroll">
     <embed type="application/x-test" wmode="window" width="100" height="800" id="plugin"></object>
     <div style="height:1000px;"></div>
   </div>
 </p>
--- a/widget/tests/test_plugin_scroll_invalidation.html
+++ b/widget/tests/test_plugin_scroll_invalidation.html
@@ -1,25 +1,19 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for plugin child widgets not being invalidated by scrolling</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="initialize()">
 <script type="application/javascript">
-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);
 </script>
 
 <p id="display">
   <iframe id="i" src="plugin_scroll_invalidation.html"
    width="50" height="50" scrolling="no"></iframe>
 </p>
 <div id="content" style="display: none">
 
new file mode 100644
--- /dev/null
+++ b/widget/tests/utils.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 it's 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;
+  });
+}