From 8dc60ed6f0e374f526de8fa4c669e3cbba4024fd Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Wed, 3 Nov 2010 00:48:45 +0100 Subject: [PATCH] Fix intermittent failures in test_cocoa_focus.html. r=jst a=tests --- .../test/mochitest/cocoa_window_focus.html | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/plugin/test/mochitest/cocoa_window_focus.html b/modules/plugin/test/mochitest/cocoa_window_focus.html index ddb2f1de2c75..4e47e900f912 100644 --- a/modules/plugin/test/mochitest/cocoa_window_focus.html +++ b/modules/plugin/test/mochitest/cocoa_window_focus.html @@ -14,6 +14,10 @@ window.opener.SimpleTest.ok(aValue, aMessage); } + function executeSoon(func) { + window.opener.SimpleTest.executeSoon(func); + } + function runTests() { var plugin1 = document.getElementById("plugin1"); var plugin2 = document.getElementById("plugin2"); @@ -52,26 +56,35 @@ window.opener.addEventListener("focus", function() { window.opener.removeEventListener("focus", arguments.callee, false); - expectedEventCount++; + executeSoon(function() { + window.addEventListener("focus", function() { + window.removeEventListener("focus", arguments.callee, false); - is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated"); - is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); + executeSoon(function() { + expectedEventCount++; - is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated"); - 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); - // Bring our window back to the front and make sure plugins were properly notified. - window.focus(); + is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); + is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); - expectedEventCount++; + window.opener.testsFinished(); + }); + }, false); - is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); - is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); + expectedEventCount++; - is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); - is(plugin2.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); - window.opener.testsFinished(); + 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; + }); }, false); // Send our window to the back and make sure plugins were properly notified.