Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 }
13 function ok(aValue, aMessage) {
14 window.opener.SimpleTest.ok(aValue, aMessage);
15 }
17 function runTests() {
18 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
19 var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
20 getInterface(Components.interfaces.nsIDOMWindowUtils);
22 var plugin1 = document.getElementById("plugin1"); // What we're testing.
23 var plugin2 = document.getElementById("plugin2"); // Dummy.
25 var plugin1Bounds = plugin1.getBoundingClientRect();
26 var plugin2Bounds = plugin2.getBoundingClientRect();
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);
33 const NSLeftMouseDown = 1,
34 NSLeftMouseUp = 2;
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 }
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;
46 // Make sure initial event count is correct.
47 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
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.");
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++;
63 is(plugin1.getFocusState(), true, "Plugin should have focus.");
64 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
66 // Make sure window activation state changes don't spontaneously
67 // change plugin focus.
69 // Blur the window.
70 window.blur();
72 is(plugin1.getFocusState(), true, "Plugin should still have focus.");
73 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
75 // Focus the window.
76 window.focus();
78 is(plugin1.getFocusState(), true, "Plugin should still have focus.");
79 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
81 // Take focus from the plugin.
82 utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseDown, 0, plugin2);
83 utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseUp, 0, plugin2);
84 expectedEventCount++;
86 is(plugin1.getFocusState(), false, "Plugin should not have focus.");
87 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
89 // Make sure window activation causes the plugin to be informed of focus
90 // changes that took place while the window was inactive.
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++;
97 // Blur the window.
98 window.blur();
100 // Take focus from the plugin while the window is blurred.
101 plugin2.focus();
103 is(plugin1.getFocusState(), true, "Plugin should still have focus.");
104 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
106 // Focus the window.
107 window.focus();
108 expectedEventCount++;
110 is(plugin1.getFocusState(), false, "Plugin should not have focus.");
111 is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
113 window.opener.testsFinished();
114 }
116 // Onload hander doesn't work for these tests -- no events arrive at the plugin.
117 window.opener.SimpleTest.waitForFocus(runTests, window);
119 </script>
120 </body>
121 </html>