1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/cocoa_focus.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>NPCocoaEventFocusChanged Tests</title> 1.7 +</head> 1.8 +<body> 1.9 + <embed id="plugin1" type="application/x-test" width="100" height="100"></embed> 1.10 + <embed id="plugin2" type="application/x-test" width="100" height="100"></embed> 1.11 + <script type="application/javascript"> 1.12 + function is(aLeft, aRight, aMessage) { 1.13 + window.opener.SimpleTest.is(aLeft, aRight, aMessage); 1.14 + } 1.15 + 1.16 + function ok(aValue, aMessage) { 1.17 + window.opener.SimpleTest.ok(aValue, aMessage); 1.18 + } 1.19 + 1.20 + function runTests() { 1.21 + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 1.22 + var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). 1.23 + getInterface(Components.interfaces.nsIDOMWindowUtils); 1.24 + 1.25 + var plugin1 = document.getElementById("plugin1"); // What we're testing. 1.26 + var plugin2 = document.getElementById("plugin2"); // Dummy. 1.27 + 1.28 + var plugin1Bounds = plugin1.getBoundingClientRect(); 1.29 + var plugin2Bounds = plugin2.getBoundingClientRect(); 1.30 + 1.31 + var plugin1X = (window.mozInnerScreenX + plugin1Bounds.left + 10); 1.32 + var plugin1Y = (window.mozInnerScreenY + plugin1Bounds.top + 10); 1.33 + var plugin2X = (window.mozInnerScreenX + plugin2Bounds.left + 10); 1.34 + var plugin2Y = (window.mozInnerScreenY + plugin2Bounds.top + 10); 1.35 + 1.36 + const NSLeftMouseDown = 1, 1.37 + NSLeftMouseUp = 2; 1.38 + 1.39 + if (plugin1.getEventModel() != 1) { 1.40 + window.opener.todo(false, "Skipping this test when not testing the Cocoa event model"); 1.41 + window.opener.testsFinished(); 1.42 + return; 1.43 + } 1.44 + 1.45 + // Initialize to 0 since there is no initial state event, 1.46 + // plugins should assume they do not initially have focus. 1.47 + var expectedEventCount = 0; 1.48 + 1.49 + // Make sure initial event count is correct. 1.50 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.51 + 1.52 + // Make sure initial focus state is unknown (assumed false). 1.53 + var initialStateUnknown = false; 1.54 + try { 1.55 + plugin1.getFocusState(); 1.56 + } catch (e) { 1.57 + initialStateUnknown = true; 1.58 + } 1.59 + is(initialStateUnknown, true, "Initial state should be unknown, assumed false."); 1.60 + 1.61 + // Give the plugin focus (the window is already focused). 1.62 + utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1); 1.63 + utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1); 1.64 + expectedEventCount++; 1.65 + 1.66 + is(plugin1.getFocusState(), true, "Plugin should have focus."); 1.67 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.68 + 1.69 + // Make sure window activation state changes don't spontaneously 1.70 + // change plugin focus. 1.71 + 1.72 + // Blur the window. 1.73 + window.blur(); 1.74 + 1.75 + is(plugin1.getFocusState(), true, "Plugin should still have focus."); 1.76 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.77 + 1.78 + // Focus the window. 1.79 + window.focus(); 1.80 + 1.81 + is(plugin1.getFocusState(), true, "Plugin should still have focus."); 1.82 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.83 + 1.84 + // Take focus from the plugin. 1.85 + utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseDown, 0, plugin2); 1.86 + utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseUp, 0, plugin2); 1.87 + expectedEventCount++; 1.88 + 1.89 + is(plugin1.getFocusState(), false, "Plugin should not have focus."); 1.90 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.91 + 1.92 + // Make sure window activation causes the plugin to be informed of focus 1.93 + // changes that took place while the window was inactive. 1.94 + 1.95 + // Give the plugin focus (the window is already focused). 1.96 + utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1); 1.97 + utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1); 1.98 + expectedEventCount++; 1.99 + 1.100 + // Blur the window. 1.101 + window.blur(); 1.102 + 1.103 + // Take focus from the plugin while the window is blurred. 1.104 + plugin2.focus(); 1.105 + 1.106 + is(plugin1.getFocusState(), true, "Plugin should still have focus."); 1.107 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.108 + 1.109 + // Focus the window. 1.110 + window.focus(); 1.111 + expectedEventCount++; 1.112 + 1.113 + is(plugin1.getFocusState(), false, "Plugin should not have focus."); 1.114 + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); 1.115 + 1.116 + window.opener.testsFinished(); 1.117 + } 1.118 + 1.119 + // Onload hander doesn't work for these tests -- no events arrive at the plugin. 1.120 + window.opener.SimpleTest.waitForFocus(runTests, window); 1.121 + 1.122 + </script> 1.123 +</body> 1.124 +</html>