Bug 595062 - Fix Intermittent mochitest-ipcplugins failures in test_cocoa_focus.html. r=jst a=tests
authorMounir Lamouri <mounir.lamouri@gmail.com>
Fri, 29 Oct 2010 21:50:27 +0200
changeset 56697 dab8e1613a67626a57564b3b77fa8b2c77eab58b
parent 56696 b5faa770249f935c3d5bc4f2742dfacc7f988419
child 56698 b0132c16f57401769dca73cd1cbdb0d225a56d2d
push idunknown
push userunknown
push dateunknown
reviewersjst, tests
bugs595062
milestone2.0b8pre
Bug 595062 - Fix Intermittent mochitest-ipcplugins failures in test_cocoa_focus.html. r=jst a=tests
modules/plugin/test/mochitest/cocoa_window_focus.html
--- a/modules/plugin/test/mochitest/cocoa_window_focus.html
+++ b/modules/plugin/test/mochitest/cocoa_window_focus.html
@@ -40,38 +40,45 @@
         is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
 
         is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
         is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
       } catch (e) {
         ok(false, "Plugin does not know its initial top-level window activation state!");
       }
 
-      // Send our window to the back and make sure plugins were properly notified.
-      // Calling window.blur() is not allowed.
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var fm = Components.classes["@mozilla.org/focus-manager;1"].
                           getService(Components.interfaces.nsIFocusManager);
-      fm.focusedWindow = window.opener;
 
-      expectedEventCount++;
+      window.opener.addEventListener("focus", function() {
+        window.opener.removeEventListener("focus", arguments.callee, false);
+
+        expectedEventCount++;
 
-      is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
-      is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
+        is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
+        is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
 
-      is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
-      is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
+        is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
+        is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
+
+        // Bring our window back to the front and make sure plugins were properly notified.
+        window.focus();
 
-      // Bring our window back to the front and make sure plugins were properly notified.
-      window.focus();
-      expectedEventCount++;
+        expectedEventCount++;
+
+        is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
+        is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
+
+        is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
+        is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
 
-      is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
-      is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
+        window.opener.testsFinished();
+      }, false);
 
-      is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
-      is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
-
-      window.opener.testsFinished();
+      // Send our window to the back and make sure plugins were properly notified.
+      // Calling window.blur() is not allowed.
+      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+      fm.focusedWindow = window.opener;
     }
   </script>
 </body>
 </html>