Bug 595062 - Trying to fix intermittent mochitest-ipcplugins failureas in test_cocoa_focus.html. r=jst a=tests
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 15 Nov 2010 23:56:55 +0100
changeset 57549 68df5bb6da6c009aa0d656cbecbdff7ce7879d8c
parent 57548 f576b6e16d462b1872dadb3322d0b8560a3e7353
child 57550 344597f66c3ef020d722bf98b4a1cfb411ef4476
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjst, tests
bugs595062
milestone2.0b8pre
Bug 595062 - Trying to fix intermittent mochitest-ipcplugins failureas 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
@@ -13,16 +13,20 @@
     function ok(aValue, aMessage) {
       window.opener.SimpleTest.ok(aValue, aMessage);
     }
 
     function executeSoon(func) {
       window.opener.SimpleTest.executeSoon(func);
     }
 
+    function waitForFocus(aCb, aTarget, aBlank) {
+      window.opener.SimpleTest.waitForFocus(aCb, aTarget, aBlank);
+    }
+
     function runTests() {
       var plugin1 = document.getElementById("plugin1");
       var plugin2 = document.getElementById("plugin2");
 
       // Don't run any tests if we're not testing the Cocoa event model.
       if (plugin1.getEventModel() != 1) {
         window.opener.testsFinished();
         return;
@@ -48,49 +52,47 @@
       } catch (e) {
         ok(false, "Plugin does not know its initial top-level window activation state!");
       }
 
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var fm = Components.classes["@mozilla.org/focus-manager;1"].
                           getService(Components.interfaces.nsIFocusManager);
 
-      window.opener.addEventListener("focus", function() {
-        window.opener.removeEventListener("focus", arguments.callee, false);
-
+      waitForFocus(function() {
+        // Make sure the plugin handled the focus event before checking.
         executeSoon(function() {
-          window.addEventListener("focus", function() {
-            window.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(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.
+          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+          fm.focusedWindow = window;
+
+          waitForFocus(function() {
+            // Make sure the plugin handled the focus event before checking.
             executeSoon(function() {
               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);
 
               window.opener.testsFinished();
             });
-          }, false);
-
-          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);
-
-          // Bring our window back to the front and make sure plugins were properly notified.
-          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-          fm.focusedWindow = window;
+          }, window);
         });
-      }, false);
+      }, window.opener);
 
       // 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>