Bug 800018 - Part 4 - Fix plugin fallback tests for new events. r=josh, a=akeybl
authorJohn Schoenick <jschoenick@mozilla.com>
Wed, 07 Nov 2012 17:24:39 -0800
changeset 118348 cf573f12023aa9156efe079b1e7636583dda5864
parent 118347 8c83e26b3e0ac8971ccab72dfd3d1812c5677861
child 118349 f719a9c96ea98a1ba4e6d83fc3d3ddd824c16cce
push id2757
push userryanvm@gmail.com
push dateWed, 21 Nov 2012 23:19:56 +0000
treeherdermozilla-aurora@cf573f12023a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh, akeybl
bugs800018
milestone19.0a2
Bug 800018 - Part 4 - Fix plugin fallback tests for new events. r=josh, a=akeybl
browser/base/content/test/browser_bug797677.js
content/base/test/chrome/file_bug391728.html
content/base/test/chrome/file_bug391728_2.html
content/base/test/chrome/test_bug391728.html
content/base/test/test_bug425013.html
content/base/test/test_bug429157.html
--- a/browser/base/content/test/browser_bug797677.js
+++ b/browser/base/content/test/browser_bug797677.js
@@ -9,36 +9,36 @@ const Ci = Components.interfaces;
 var gTestBrowser = null;
 var gConsoleErrors = 0;
 
 function test() {
   waitForExplicitFinish();
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   gTestBrowser = gBrowser.selectedBrowser;
-  gTestBrowser.addEventListener("PluginNotFound", pluginNotFound, true);
+  gTestBrowser.addEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
   var consoleService = Cc["@mozilla.org/consoleservice;1"]
                          .getService(Ci.nsIConsoleService);
   var errorListener = {
     observe: function(aMessage) {
       if (aMessage.message.contains("NS_ERROR"))
         gConsoleErrors++;
     }
   };
   consoleService.registerListener(errorListener);
   registerCleanupFunction(function() {
-    gTestBrowser.removeEventListener("PluginNotFound", pluginNotFound, true);
+    gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true);
     consoleService.unregisterListener(errorListener);
     gBrowser.removeCurrentTab();
     window.focus();
   });
   gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug797677.html";
 }
 
-function pluginNotFound() {
+function pluginBindingAttached() {
   // Let browser-plugins.js handle the PluginNotFound event, then run the test
   executeSoon(runTest);
 }
 
 function runTest() {
   var doc = gTestBrowser.contentDocument;
   var plugin = doc.getElementById("plugin");
   ok(plugin, "plugin should be in the page");
--- a/content/base/test/chrome/file_bug391728.html
+++ b/content/base/test/chrome/file_bug391728.html
@@ -16,31 +16,20 @@ object:-moz-handler-blocked {
 }
 
 embed:-moz-type-unsupported,
 object:-moz-type-unsupported {
   border-style: none !important;
 }
 </style>
 <script type="text/javascript">
-function unknown_plugin_detected(event) {
-  window.parent.unknown_plugin_detected(event);
-}
-
-function blocked_plugin_detected(event) {
-  window.parent.blocked_plugin_detected(event);
+function plugin_binding_attached(event) {
+  window.parent.plugin_binding_attached(event);
 }
-
-function disabled_plugin_detected(event) {
-  window.parent.disabled_plugin_detected(event);
-}
-
-document.addEventListener("PluginNotFound", unknown_plugin_detected, true);
-document.addEventListener("PluginDisabled", disabled_plugin_detected, true);
-document.addEventListener("PluginBlocklisted", blocked_plugin_detected, true);
+document.addEventListener("PluginBindingAttached", plugin_binding_attached, true, true);
 </script>
 </head>
 <body>
 <!-- Embeds always fire events and have the pseudo class attached -->
 <div><embed id="plugin1" style="width: 100px; height: 100px" type="application/x-test"></div>
 <div><embed id="plugin2" style="width: 100px; height: 100px" src="data:application/x-test,test"></div>
 
 <!-- So do objects with a type/uri and no content -->
--- a/content/base/test/chrome/file_bug391728_2.html
+++ b/content/base/test/chrome/file_bug391728_2.html
@@ -16,31 +16,20 @@ object:-moz-handler-blocked {
 }
 
 embed:-moz-type-unsupported,
 object:-moz-type-unsupported {
   border-style: none !important;
 }
 </style>
 <script type="text/javascript">
-function unknown_plugin_detected(event) {
-  window.parent.unknown_plugin_detected(event);
-}
-
-function blocked_plugin_detected(event) {
-  window.parent.blocked_plugin_detected(event);
+function plugin_binding_attached(event) {
+  window.parent.plugin_binding_attached(event);
 }
-
-function disabled_plugin_detected(event) {
-  window.parent.disabled_plugin_detected(event);
-}
-
-document.addEventListener("PluginNotFound", unknown_plugin_detected, true);
-document.addEventListener("PluginDisabled", disabled_plugin_detected, true);
-document.addEventListener("PluginBlocklisted", blocked_plugin_detected, true);
+document.addEventListener("PluginBindingAttached", plugin_binding_attached, true, true);
 </script>
 </head>
 <body>
 <!-- Embeds always fire events and have the pseudo class attached -->
 <div><embed id="plugin1" style="width: 100px; height: 100px" type="application/x-unknown"></div>
 <div><embed id="plugin2" style="width: 100px; height: 100px" src="data:application/x-unknown,test"></div>
 
 <!-- So do objects with a type/uri and no content -->
--- a/content/base/test/chrome/test_bug391728.html
+++ b/content/base/test/chrome/test_bug391728.html
@@ -17,32 +17,37 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 /** Test for Bug 391728 **/
 // Plugins that should dispatch error events and have the pseudo classes set
 const PLUGIN_COUNT = 13;
 // Plugins that should neither dispatch error events or have the pseudo classes set
 const FALLBACK_COUNT = 5;
+const OBJLC = Components.interfaces.nsIObjectLoadingContent;
 
 var gNextTest = null;
 var gUnknown = [];
 var gBlocked = [];
 var gDisabled = [];
 
-function disabled_plugin_detected(event) {
-  gDisabled.push(event.target.id);
-}
-
-function blocked_plugin_detected(event) {
-  gBlocked.push(event.target.id);
-}
-
-function unknown_plugin_detected(event) {
-  gUnknown.push(event.target.id);
+function plugin_binding_attached(event) {
+  var plugin = event.target;
+  plugin instanceof OBJLC;
+  switch (SpecialPowers.wrap(plugin).pluginFallbackType) {
+    case OBJLC.PLUGIN_DISABLED:
+      gDisabled.push(plugin.id);
+      break;
+    case OBJLC.PLUGIN_BLOCKLISTED:
+      gBlocked.push(plugin.id);
+      break;
+    case OBJLC.PLUGIN_UNSUPPORTED:
+      gUnknown.push(plugin.id);
+      break;
+  }
 }
 
 function init_test() {
   // 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);
 
--- a/content/base/test/test_bug425013.html
+++ b/content/base/test/test_bug425013.html
@@ -8,25 +8,29 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="runtests();">
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=425013">Mozilla Bug 425013</a>
 <br>
 
-<script>
+<script type="text/javascript;version=1.7">
 var missingPlugins = new Array();
+var OBJLC = Components.interfaces.nsIObjectLoadingContent;
 
-function pluginNotFound(event)
+function pluginBinding(event)
 {
-  missingPlugins.push(event.target);
+  var plugin = event.target;
+  plugin instanceof OBJLC;
+  if (SpecialPowers.wrap(plugin).pluginFallbackType == OBJLC.PLUGIN_UNSUPPORTED)
+    missingPlugins.push(plugin);
 }
 
-document.addEventListener("PluginNotFound", pluginNotFound, false);
+document.addEventListener("PluginBindingAttached", pluginBinding, true);
 </script>
 
 <object type="foo/bar" id="obj1"></object>
 
 <object type="foo/bar" id="obj2">
   <embed type="a/b" id="embed1"></embed>
 </object>
 
@@ -50,23 +54,32 @@ document.addEventListener("PluginNotFoun
 <p>Alternate content</p>
 </object>
 
 <embed type="a/b" id="embed2"></embed>
 
 <script class="testbody" type="text/javascript">
 function runtests()
 {
-  ok(missingPlugins.indexOf(document.getElementById("obj1")) >= 0, "Missing plugin element obj1");
-  ok(missingPlugins.indexOf(document.getElementById("embed1")) >= 0, "Missing plugin element embed1");
-  ok(missingPlugins.indexOf(document.getElementById("embed2")) >= 0, "Missing plugin element embed2");
-  ok(missingPlugins.indexOf(document.getElementById("obj3")) >= 0, "Missing plugin element obj3");
+  // Force layout flush so the binding is attached and the event is fired
+  document.getElementById("obj1").clientTop;
+  document.getElementById("obj3").clientTop;
+  document.getElementById("embed1").clientTop;
+  document.getElementById("embed2").clientTop;
 
-  is(missingPlugins.length, 4, "Wrong number of missing plugins");
+  // Let pending events flush
+  SimpleTest.executeSoon(function () {
+    ok(missingPlugins.indexOf(document.getElementById("obj1")) >= 0, "Missing plugin element obj1");
+    ok(missingPlugins.indexOf(document.getElementById("embed1")) >= 0, "Missing plugin element embed1");
+    ok(missingPlugins.indexOf(document.getElementById("embed2")) >= 0, "Missing plugin element embed2");
+    ok(missingPlugins.indexOf(document.getElementById("obj3")) >= 0, "Missing plugin element obj3");
 
-  SimpleTest.finish();
+    is(missingPlugins.length, 4, "Wrong number of missing plugins");
+
+    SimpleTest.finish();
+  });
 }
 
 SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
 </body>
 </html>
--- a/content/base/test/test_bug429157.html
+++ b/content/base/test/test_bug429157.html
@@ -10,35 +10,45 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body onload="runtests();">
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429157">Mozilla Bug 429157</a>
 <br>
 
 <script>
 var missingPlugins = new Array();
+const OBJLC = Components.interfaces.nsIObjectLoadingContent;
 
-function pluginNotFound(event)
+function pluginBindingAttached(event)
 {
-  missingPlugins.push(event.target);
+  var plugin = event.target;
+  plugin instanceof OBJLC;
+  if (SpecialPowers.wrap(plugin).pluginFallbackType == OBJLC.PLUGIN_UNSUPPORTED)
+    missingPlugins.push(plugin);
 }
 
-document.addEventListener("PluginNotFound", pluginNotFound, false);
+document.addEventListener("PluginBindingAttached", pluginBindingAttached, true);
 </script>
 
 <object id="obj1" type="image/png"    >ALT image/png</object><br>
 <object id="obj2" type="image/svg+xml">ALT image/svg+xml</object><br>
 <object id="obj3" type="text/html"    >ALT text/html</object><br>
 <object id="obj4" type="text/plain"   >ALT text/plain</object><br>
 
 <script class="testbody" type="text/javascript">
 function runtests()
 {
-  is(missingPlugins.length, 0, "There should be no missing plugins for this page");
+  for (var obj of document.querySelectorAll("object")) {
+    obj.clientTop;
+  }
 
-  SimpleTest.finish();
+  SimpleTest.executeSoon(function () {
+    is(missingPlugins.length, 0, "There should be no missing plugins for this page");
+
+    SimpleTest.finish();
+  });
 }
 
 SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
 </body>
 </html>