Bug 478845 Disable mochitest of test plugin if test plugin is absent r=ted.mielczarek, jwalden
authorGinn Chen <ginn.chen@sun.com>
Thu, 23 Apr 2009 14:27:04 +0800
changeset 27661 f46bebbe48e605a25b5e11d256f3d6cab83babc3
parent 27660 ca32db7118169e53b0e79b6132442f8763cf0079
child 27662 69f84bd267008c385528fcb71c8fa9c842d6bde6
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted.mielczarek, jwalden
bugs478845
milestone1.9.2a1pre
Bug 478845 Disable mochitest of test plugin if test plugin is absent r=ted.mielczarek, jwalden
content/base/test/test_bug391728.html
modules/plugin/Makefile.in
testing/mochitest/tests/SimpleTest/Makefile.in
testing/mochitest/tests/SimpleTest/PluginUtils.js
--- a/content/base/test/test_bug391728.html
+++ b/content/base/test/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="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/PluginUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/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>
@@ -23,28 +24,16 @@ const PLUGIN_COUNT = 14;
 // Plugins that should neither dispatch error events or have the pseudo classes set
 const FALLBACK_COUNT = 4;
 
 var gNextTest = null;
 var gUnknown = [];
 var gBlocked = [];
 var gDisabled = [];
 
-function get_test_plugin() {
-  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 == "Test Plug-in")
-      return tags[i];
-  }
-}
-
 function disabled_plugin_detected(event) {
   gDisabled.push(event.target.id);
 }
 
 function blocked_plugin_detected(event) {
   gBlocked.push(event.target.id);
 }
 
@@ -54,31 +43,32 @@ function unknown_plugin_detected(event) 
 
 function init_test() {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   // Make sure the blocklist is off for the duration of this test
   var prefs = Components.classes["@mozilla.org/preferences-service;1"]
                         .getService(Components.interfaces.nsIPrefBranch);
   prefs.setBoolPref("extensions.blocklist.enabled", false);
 
-  var plugin = get_test_plugin();
-  ok(plugin, "Test plugin was not found");
-  
+  if (!PluginUtils.withTestPlugin(start_test))
+    SimpleTest.finish();
+}
+
+function start_test(plugin) {
   is(plugin.description, "Plug-in for testing purposes.", "Test plugin had an incorrect description");
   is(plugin.version, "1.0.0.0", "Test plugin had an incorrect version");
   ok(!plugin.disabled, "Test plugin should not be disabled");
   ok(!plugin.blocklisted, "Test plugin should not be blocklisted");
-  
+
   var frame = document.getElementById("testframe");
   frame.addEventListener("load", frame_loaded, true);
   load_frame(test_normal, "file_bug391728");
 }
 
-function finish_test() {
-  var plugin = get_test_plugin();
+function finish_test(plugin) {
   plugin.disabled = false;
   plugin.blocklisted = false;
   var prefs = Components.classes["@mozilla.org/preferences-service;1"]
                         .getService(Components.interfaces.nsIPrefBranch);
   prefs.clearUserPref("extensions.blocklist.enabled");
   SimpleTest.finish();
 }
 
@@ -86,19 +76,23 @@ function load_frame(nextTest, file) {
   gNextTest = nextTest;
   gDisabled = [];
   gUnknown = [];
   gBlocked = [];
   var frame = document.getElementById("testframe");
   frame.src = file + ".html?" + Math.random();
 }
 
+function next_text() {
+  PluginUtils.withTestPlugin(gNextTest);
+}
+
 function frame_loaded() {
   // We must delay to wait for the plugin sources to be loaded :(
-  setTimeout(gNextTest, 500);
+  setTimeout(next_text, 500);
 }
 
 function test_style(expected) {
   var frame = document.getElementById("testframe");
   for (var i = 1; i <= PLUGIN_COUNT; i++) {
     var tag = frame.contentDocument.getElementById("plugin" + i);
     ok(tag, "Plugin " + i + " did not exist");
     var style = frame.contentWindow.getComputedStyle(tag, null);
@@ -116,61 +110,58 @@ function test_list(list) {
   for (var i = 1; i <= PLUGIN_COUNT; i++) {
     ok(list.indexOf("plugin" + i) >= 0, "Plugin " + i + " did not send the event");
   }
   for (i = 1; i <= FALLBACK_COUNT; i++) {
     ok(list.indexOf("fallback" + i) < 0, "Fallback plugin " + i + " should not have sent the event");
   }
 }
 
-function test_normal() {
+function test_normal(plugin) {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   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");
-  var plugin = get_test_plugin();
   plugin.disabled = true;
   load_frame(test_disabled, "file_bug391728");
 }
 
-function test_disabled() {
+function test_disabled(plugin) {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   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");
-  var plugin = get_test_plugin();
   ok(plugin.disabled, "Plugin lost its disabled status");
   plugin.disabled = false;
   plugin.blocklisted = true;
   load_frame(test_blocked, "file_bug391728");
 }
 
-function test_blocked() {
+function test_blocked(plugin) {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   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, PLUGIN_COUNT, "Should have been blocked plugins");
   test_list(gBlocked);
   test_style("dashed");
-  var plugin = get_test_plugin();
   ok(plugin.blocklisted, "Plugin lost its blocklist status");
   load_frame(test_unknown, "file_bug391728_2");
 }
 
-function test_unknown() {
+function test_unknown(plugin) {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   is(gUnknown.length, PLUGIN_COUNT, "Should have been unknown plugins");
   test_list(gUnknown);
   is(gDisabled.length, 0, "Should not have been any disabled plugins");
   is(gBlocked.length, 0, "Should not have been any blocked plugins");
   test_style("none");
-  finish_test();
+  finish_test(plugin);
 }
 
 SimpleTest.waitForExplicitFinish();
 window.addEventListener("load", init_test, false);
 </script>
 </pre>
 </body>
 </html>
--- a/modules/plugin/Makefile.in
+++ b/modules/plugin/Makefile.in
@@ -68,17 +68,17 @@ ifeq ($(OS_ARCH),OS2)
 TOOL_DIRS += default/os2
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 TOOL_DIRS += default/mac
 endif
 
 ifdef ENABLE_TESTS
-ifneq (,$(filter WINNT Darwin Linux OS2,$(OS_ARCH)))
+ifneq (,$(filter WINNT Darwin Linux OS2 SunOS,$(OS_ARCH)))
 DIRS += test
 TOOL_DIRS += sdk
 endif
 endif
 
 endif # MOZ_PLUGINS
 
 include $(topsrcdir)/config/rules.mk
--- a/testing/mochitest/tests/SimpleTest/Makefile.in
+++ b/testing/mochitest/tests/SimpleTest/Makefile.in
@@ -47,13 +47,14 @@ include $(topsrcdir)/config/rules.mk
 _SIMPLETEST_FILES =	MozillaFileLogger.js \
 			quit.js \
 			SimpleTest.js \
 			test.css \
 			TestRunner.js \
 			setup.js \
 			EventUtils.js \
 			WindowSnapshot.js \
+			PluginUtils.js \
 			$(NULL)
 
 libs:: $(_SIMPLETEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/$(relativesrcdir)
 
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/SimpleTest/PluginUtils.js
@@ -0,0 +1,28 @@
+var PluginUtils =
+{
+  withTestPlugin : function(callback)
+  {
+    if (typeof Components == "undefined")
+    {
+      todo(false, "Not a Mozilla-based browser");
+      return false;
+    }
+
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    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 == "Test Plug-in")
+      {
+        callback(tags[i]);
+        return true;
+      }
+    }
+    todo(false, "Need a test plugin on this platform");
+    return false;
+  }
+};