|
1 <html> |
|
2 <head> |
|
3 <title>NPCocoaEventFocusChanged Tests</title> |
|
4 </head> |
|
5 <body> |
|
6 <embed id="plugin1" type="application/x-test" width="100" height="100"></embed> |
|
7 <embed id="plugin2" type="application/x-test" width="100" height="100"></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 runTests() { |
|
18 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
|
19 var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
|
20 getInterface(Components.interfaces.nsIDOMWindowUtils); |
|
21 |
|
22 var plugin1 = document.getElementById("plugin1"); // What we're testing. |
|
23 var plugin2 = document.getElementById("plugin2"); // Dummy. |
|
24 |
|
25 var plugin1Bounds = plugin1.getBoundingClientRect(); |
|
26 var plugin2Bounds = plugin2.getBoundingClientRect(); |
|
27 |
|
28 var plugin1X = (window.mozInnerScreenX + plugin1Bounds.left + 10); |
|
29 var plugin1Y = (window.mozInnerScreenY + plugin1Bounds.top + 10); |
|
30 var plugin2X = (window.mozInnerScreenX + plugin2Bounds.left + 10); |
|
31 var plugin2Y = (window.mozInnerScreenY + plugin2Bounds.top + 10); |
|
32 |
|
33 const NSLeftMouseDown = 1, |
|
34 NSLeftMouseUp = 2; |
|
35 |
|
36 if (plugin1.getEventModel() != 1) { |
|
37 window.opener.todo(false, "Skipping this test when not testing the Cocoa event model"); |
|
38 window.opener.testsFinished(); |
|
39 return; |
|
40 } |
|
41 |
|
42 // Initialize to 0 since there is no initial state event, |
|
43 // plugins should assume they do not initially have focus. |
|
44 var expectedEventCount = 0; |
|
45 |
|
46 // Make sure initial event count is correct. |
|
47 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
48 |
|
49 // Make sure initial focus state is unknown (assumed false). |
|
50 var initialStateUnknown = false; |
|
51 try { |
|
52 plugin1.getFocusState(); |
|
53 } catch (e) { |
|
54 initialStateUnknown = true; |
|
55 } |
|
56 is(initialStateUnknown, true, "Initial state should be unknown, assumed false."); |
|
57 |
|
58 // Give the plugin focus (the window is already focused). |
|
59 utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1); |
|
60 utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1); |
|
61 expectedEventCount++; |
|
62 |
|
63 is(plugin1.getFocusState(), true, "Plugin should have focus."); |
|
64 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
65 |
|
66 // Make sure window activation state changes don't spontaneously |
|
67 // change plugin focus. |
|
68 |
|
69 // Blur the window. |
|
70 window.blur(); |
|
71 |
|
72 is(plugin1.getFocusState(), true, "Plugin should still have focus."); |
|
73 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
74 |
|
75 // Focus the window. |
|
76 window.focus(); |
|
77 |
|
78 is(plugin1.getFocusState(), true, "Plugin should still have focus."); |
|
79 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
80 |
|
81 // Take focus from the plugin. |
|
82 utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseDown, 0, plugin2); |
|
83 utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseUp, 0, plugin2); |
|
84 expectedEventCount++; |
|
85 |
|
86 is(plugin1.getFocusState(), false, "Plugin should not have focus."); |
|
87 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
88 |
|
89 // Make sure window activation causes the plugin to be informed of focus |
|
90 // changes that took place while the window was inactive. |
|
91 |
|
92 // Give the plugin focus (the window is already focused). |
|
93 utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1); |
|
94 utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1); |
|
95 expectedEventCount++; |
|
96 |
|
97 // Blur the window. |
|
98 window.blur(); |
|
99 |
|
100 // Take focus from the plugin while the window is blurred. |
|
101 plugin2.focus(); |
|
102 |
|
103 is(plugin1.getFocusState(), true, "Plugin should still have focus."); |
|
104 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
105 |
|
106 // Focus the window. |
|
107 window.focus(); |
|
108 expectedEventCount++; |
|
109 |
|
110 is(plugin1.getFocusState(), false, "Plugin should not have focus."); |
|
111 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); |
|
112 |
|
113 window.opener.testsFinished(); |
|
114 } |
|
115 |
|
116 // Onload hander doesn't work for these tests -- no events arrive at the plugin. |
|
117 window.opener.SimpleTest.waitForFocus(runTests, window); |
|
118 |
|
119 </script> |
|
120 </body> |
|
121 </html> |