Bug 1172627: Update test_instance_re-parent to account for bug 1158761; r=jimm
authorAaron Klotz <aklotz@mozilla.com>
Mon, 08 Jun 2015 19:57:54 -0600
changeset 248083 2a981c61aa56f94067d23d2861b18757d10c3e32
parent 248082 01ae75cfedd0654fc85fd670cd7ac3844b18ef24
child 248084 91bb0d44384a95a106dae714d9b6c5bb7d364a96
push id28888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:29:45 +0000
treeherdermozilla-central@04c057942da4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1172627, 1158761
milestone41.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 1172627: Update test_instance_re-parent to account for bug 1158761; r=jimm
dom/plugins/test/mochitest/test_instance_re-parent.html
--- a/dom/plugins/test/mochitest/test_instance_re-parent.html
+++ b/dom/plugins/test/mochitest/test_instance_re-parent.html
@@ -7,16 +7,18 @@
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="utils.js"></script>
 </head>
 <body onload="begin()">
   <script type="application/javascript;version=1.8">
   SimpleTest.waitForExplicitFinish();
   setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
+  const MAX_CHECK_PLUGIN_STOPPED_ATTEMPTS = 5;
+  var numCheckPluginStoppedAttempts = 0;
   var exceptionThrown = false;
   var p = null;
   var d1 = null;
   var d2 = null;
 
   var destroyed = false;
 
   function begin() {
@@ -33,16 +35,30 @@
       destroyed = false;
       exceptionThrown = false;
       runTests(function () {
         SimpleTest.finish();
       });
     });
   }
 
+  function checkPluginStopped(callback, param) {
+    if (numCheckPluginStoppedAttempts < MAX_CHECK_PLUGIN_STOPPED_ATTEMPTS &&
+        !destroyed) {
+      ++numCheckPluginStoppedAttempts;
+      SimpleTest.executeSoon(function() {
+          checkPluginStopped(callback, param);
+      });
+    } else {
+      info("Number of check plugin stopped attempts: " +
+           numCheckPluginStoppedAttempts);
+      callback(param);
+    }
+  }
+
   function runTests(callback) {
     p = document.getElementById('plugin1');
     d1 = document.getElementById('div1');
     d2 = document.getElementById('div2');
 
     // First tests involve moving the instance from one div to another.
     p.startWatchingInstanceCount();
     p.callOnDestroy(function() {
@@ -66,32 +82,33 @@
     is(destroyed, false, "No instances should have been destroyed at this point.");
     is(p.getInstanceCount(), 0, "No new instances should have been created at this point.");
 
     // Wait for the event loop to spin and ensure the plugin still wasn't touched
     SimpleTest.executeSoon(function() {
       is(destroyed, false, "No instances should have been destroyed at this point.");
       is(p.getInstanceCount(), 0, "No new instances should have been created at this point.");
 
-      // Removing the instance for a full event loop *should* respawn
       d2.removeChild(p);
-      SimpleTest.executeSoon(function() {
-        d2.appendChild(p);
-        SimpleTest.executeSoon(function() {
-          try {
-            is(p.getInstanceCount(), 1, "One new instance should have been created at this point.");
-          } catch (e) {
-            exceptionThrown = true;
-          }
-          is(exceptionThrown, false, "Testing for exception getting instance count from plugin.");
+      checkPluginStopped(continueTestsAfterPluginDestruction, callback);
+    });
+  }
 
-          p.stopWatchingInstanceCount();
-          callback.apply(null);
-        });
-      });
+  function continueTestsAfterPluginDestruction(callback) {
+    d2.appendChild(p);
+    SimpleTest.executeSoon(function() {
+      try {
+        is(p.getInstanceCount(), 1, "One new instance should have been created at this point.");
+      } catch (e) {
+        exceptionThrown = true;
+      }
+      is(exceptionThrown, false, "Testing for exception getting instance count from plugin.");
+
+      p.stopWatchingInstanceCount();
+      callback.apply(null);
     });
   }
   </script>
 
   <p id="display"></p>
 
   <div id="div1">
     <!-- This embed has to have a "src" attribute. Part of this test involves seeing if we