|
1 <html> |
|
2 <head> |
|
3 <title>NPCocoaEventWindowFocusChanged Tests</title> |
|
4 </head> |
|
5 <body onload="runTests()"> |
|
6 <embed id="plugin1" type="application/x-test" width="400" height="400"></embed> |
|
7 <embed id="plugin2" type="application/x-test" width="400" height="400"></embed> |
|
8 <script type="application/javascript"> |
|
9 function is(aLeft, aRight, aMessage) { |
|
10 window.opener.SimpleTest.is(aLeft, aRight, aMessage); |
|
11 } |
|
12 |
|
13 function ok(aValue, aMessage) { |
|
14 window.opener.SimpleTest.ok(aValue, aMessage); |
|
15 } |
|
16 |
|
17 function executeSoon(func) { |
|
18 window.opener.SimpleTest.executeSoon(func); |
|
19 } |
|
20 |
|
21 function waitForFocus(aCb, aTarget, aBlank) { |
|
22 window.opener.SimpleTest.waitForFocus(aCb, aTarget, aBlank); |
|
23 } |
|
24 |
|
25 function runTests() { |
|
26 var plugin1 = document.getElementById("plugin1"); |
|
27 var plugin2 = document.getElementById("plugin2"); |
|
28 |
|
29 if (plugin1.getEventModel() != 1) { |
|
30 window.opener.todo(false, "Skipping this test when not testing the Cocoa event model"); |
|
31 window.opener.testsFinished(); |
|
32 return; |
|
33 } |
|
34 |
|
35 // The first plugin will have in-page focus for these tests. |
|
36 plugin1.focus(); |
|
37 |
|
38 // The expected event count which applies to all instances. |
|
39 // Initialize to 1 to account for the initial state event. |
|
40 var expectedEventCount = 1; |
|
41 |
|
42 // First make sure the plugins got an initial window focus event. |
|
43 // Since this window was just opened it should be in the front. If |
|
44 // the plugin has not been sent an initial window state then it will |
|
45 // be in an unknown state and it will throw an exception. |
|
46 try { |
|
47 is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); |
|
48 is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
49 |
|
50 is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); |
|
51 is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
52 } catch (e) { |
|
53 ok(false, "Plugin does not know its initial top-level window activation state!"); |
|
54 } |
|
55 |
|
56 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
|
57 var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"]. |
|
58 getService(SpecialPowers.Ci.nsIFocusManager); |
|
59 |
|
60 waitForFocus(function() { |
|
61 // Make sure the plugin handled the focus event before checking. |
|
62 executeSoon(function() { |
|
63 expectedEventCount++; |
|
64 |
|
65 is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated"); |
|
66 is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
67 |
|
68 is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated"); |
|
69 is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
70 |
|
71 // Bring our window back to the front and make sure plugins were properly notified. |
|
72 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
|
73 fm.focusedWindow = window; |
|
74 |
|
75 waitForFocus(function() { |
|
76 // Make sure the plugin handled the focus event before checking. |
|
77 executeSoon(function() { |
|
78 expectedEventCount++; |
|
79 |
|
80 is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); |
|
81 is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
82 |
|
83 is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated"); |
|
84 is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount); |
|
85 |
|
86 window.opener.testsFinished(); |
|
87 }); |
|
88 }, window); |
|
89 }); |
|
90 }, window.opener); |
|
91 |
|
92 // Send our window to the back and make sure plugins were properly notified. |
|
93 // Calling window.blur() is not allowed. |
|
94 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
|
95 fm.focusedWindow = window.opener; |
|
96 } |
|
97 </script> |
|
98 </body> |
|
99 </html> |