Bug 1158761 - Part 2: Update checks for plugin stop event in tests. r=jimm, a=sledru
authorAaron Klotz <aklotz@mozilla.com>
Wed, 06 May 2015 17:13:05 -0600
changeset 260537 aa884d29e93c
parent 260536 c163f5453215
child 260539 7f925ad5b331
child 260540 32c18a01a502
push id811
push userryanvm@gmail.com
push date2015-05-20 14:59 +0000
treeherdermozilla-release@aa884d29e93c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, sledru
bugs1158761
milestone38.0.5
Bug 1158761 - Part 2: Update checks for plugin stop event in tests. r=jimm, a=sledru
dom/plugins/test/mochitest/test_bug852315.html
dom/plugins/test/mochitest/test_instance_unparent1.html
dom/plugins/test/mochitest/test_instance_unparent2.html
dom/plugins/test/mochitest/test_instance_unparent3.html
--- a/dom/plugins/test/mochitest/test_bug852315.html
+++ b/dom/plugins/test/mochitest/test_bug852315.html
@@ -32,21 +32,31 @@ i.addEventListener("load", function load
     var e2 = d.createElement("embed");
     d.body.appendChild(e2);
     destroyran = true;
   });
 
   // Navigate the frame to cause the document with the plugin to go inactive
   i.removeEventListener("load", loadfunc);
   i.src = "about:blank";
-  SimpleTest.executeSoon(function() {
-    // Ensure this event doesn't race with CheckPluginStopEvent
-    SimpleTest.executeSoon(function() {
+
+  const MAX_ATTEMPTS = 5;
+  var attempts = 0;
+  function checkPluginDestroyRan() {
+    // We may need to retry a few times until the plugin stop event makes
+    // its way through the event queue.
+    if (attempts < MAX_ATTEMPTS && !destroyran) {
+      ++attempts;
+      SimpleTest.executeSoon(checkPluginDestroyRan);
+    } else {
+      info("Number of retry attempts: " + attempts);
       ok(destroyran, "OnDestroy callback ran and did not crash");
       SimpleTest.finish();
-    });
-  });
+    }
+  }
+
+  SimpleTest.executeSoon(checkPluginDestroyRan);
 });
 document.body.appendChild(i);
 
 </script>
 </body>
 </html>
--- a/dom/plugins/test/mochitest/test_instance_unparent1.html
+++ b/dom/plugins/test/mochitest/test_instance_unparent1.html
@@ -7,35 +7,43 @@
   <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="startTest()">
   <script type="application/javascript;version=1.8">
   SimpleTest.waitForExplicitFinish();
   setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
+  const MAX_ATTEMPTS = 5;
+  var attempts = 0;
   var destroyed = false;
   function onDestroy() {
     destroyed = true;
   }
 
   function checkPluginAlreadyDestroyed() {
-    is(destroyed, true, "Plugin instance should have been destroyed.");
-    SimpleTest.finish();
+    // We may need to retry a few times until the plugin stop event makes
+    // its way through the event queue.
+    if (attempts < MAX_ATTEMPTS && !destroyed) {
+      ++attempts;
+      SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
+    } else {
+      info("Number of retry attempts: " + attempts);
+      is(destroyed, true, "Plugin instance should have been destroyed.");
+      SimpleTest.finish();
+    }
   }
 
   function startTest() {
     var p1 = document.getElementById('plugin1');
     var d1 = document.getElementById('div1');
 
     p1.callOnDestroy(onDestroy);
-
-    setTimeout(checkPluginAlreadyDestroyed, 0);
-
     d1.removeChild(p1);
+    SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
   }
   </script>
 
   <p id="display"></p>
 
   <div id="div1">
     <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
   </div>
--- a/dom/plugins/test/mochitest/test_instance_unparent2.html
+++ b/dom/plugins/test/mochitest/test_instance_unparent2.html
@@ -7,38 +7,48 @@
   <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="startTest()">
   <script type="application/javascript;version=1.8">
   SimpleTest.waitForExplicitFinish();
   setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
+  const MAX_ATTEMPTS = 5;
+  var attempts = 0;
   var destroyed = false;
   function onDestroy() {
     destroyed = true;
   }
 
   function checkPluginAlreadyDestroyed() {
-    is(destroyed, true, "Plugin instance should have been destroyed.");
-    SimpleTest.finish();
+    // We may need to retry a few times until the plugin stop event makes
+    // its way through the event queue.
+    if (attempts < MAX_ATTEMPTS && !destroyed) {
+      ++attempts;
+      SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
+    } else {
+      info("Number of retry attempts: " + attempts);
+      is(destroyed, true, "Plugin instance should have been destroyed.");
+      SimpleTest.finish();
+    }
   }
 
   function startTest() {
     var p1 = document.getElementById('plugin1');
     var d1 = document.getElementById('div1');
 
     p1.callOnDestroy(onDestroy);
 
-    setTimeout(checkPluginAlreadyDestroyed, 0);
-
     // Get two parent check events to run.
     d1.removeChild(p1);
     d1.appendChild(p1);
     d1.removeChild(p1);
+
+    SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
   }
   </script>
 
   <p id="display"></p>
 
   <div id="div1">
     <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
   </div>
--- a/dom/plugins/test/mochitest/test_instance_unparent3.html
+++ b/dom/plugins/test/mochitest/test_instance_unparent3.html
@@ -7,36 +7,44 @@
   <script type="text/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="startTest()">
   <script type="application/javascript;version=1.8">
   SimpleTest.waitForExplicitFinish();
   setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
+  const MAX_ATTEMPTS = 5;
+  var attempts = 0;
   var destroyed = false;
   function onDestroy() {
     destroyed = true;
   }
 
   function checkPluginAlreadyDestroyed() {
-    is(destroyed, true, "Plugin instance should have been destroyed.");
-    SimpleTest.finish();
+    // We may need to retry a few times until the plugin stop event makes
+    // its way through the event queue.
+    if (attempts < MAX_ATTEMPTS && !destroyed) {
+      ++attempts;
+      SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
+    } else {
+      info("Number of retry attempts: " + attempts);
+      is(destroyed, true, "Plugin instance should have been destroyed.");
+      SimpleTest.finish();
+    }
   }
 
   function startTest() {
     var p1 = document.getElementById('plugin1');
     var d1 = document.getElementById('div1');
     var d2 = document.getElementById('div2');
 
     p1.callOnDestroy(onDestroy);
-
-    setTimeout(checkPluginAlreadyDestroyed, 0);
-
     d1.removeChild(d2);
+    SimpleTest.executeSoon(checkPluginAlreadyDestroyed);
   }
   </script>
 
   <p id="display"></p>
 
   <div id="div1">
     <div id="div2">
       <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>