2010-04-25 13:58:03 -07:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>NPCocoaEventFocusChanged Tests</title>
|
|
|
|
</head>
|
2010-11-15 13:23:51 -08:00
|
|
|
<body>
|
|
|
|
<embed id="plugin1" type="application/x-test" width="100" height="100"></embed>
|
|
|
|
<embed id="plugin2" type="application/x-test" width="100" height="100"></embed>
|
2010-04-25 13:58:03 -07:00
|
|
|
<script type="application/javascript">
|
|
|
|
function is(aLeft, aRight, aMessage) {
|
|
|
|
window.opener.SimpleTest.is(aLeft, aRight, aMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ok(aValue, aMessage) {
|
|
|
|
window.opener.SimpleTest.ok(aValue, aMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTests() {
|
2010-11-15 13:23:51 -08:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
|
2010-04-25 13:58:03 -07:00
|
|
|
var plugin1 = document.getElementById("plugin1"); // What we're testing.
|
|
|
|
var plugin2 = document.getElementById("plugin2"); // Dummy.
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
var plugin1Bounds = plugin1.getBoundingClientRect();
|
|
|
|
var plugin2Bounds = plugin2.getBoundingClientRect();
|
|
|
|
|
|
|
|
var plugin1X = (window.mozInnerScreenX + plugin1Bounds.left + 10) * utils.screenPixelsPerCSSPixel;
|
|
|
|
var plugin1Y = (window.mozInnerScreenY + plugin1Bounds.top + 10) * utils.screenPixelsPerCSSPixel;
|
|
|
|
var plugin2X = (window.mozInnerScreenX + plugin2Bounds.left + 10) * utils.screenPixelsPerCSSPixel;
|
|
|
|
var plugin2Y = (window.mozInnerScreenY + plugin2Bounds.top + 10) * utils.screenPixelsPerCSSPixel;
|
|
|
|
|
|
|
|
const NSLeftMouseDown = 1,
|
|
|
|
NSLeftMouseUp = 2;
|
|
|
|
|
2010-04-25 13:58:03 -07:00
|
|
|
// Don't run any tests if we're not testing the Cocoa event model.
|
|
|
|
if (plugin1.getEventModel() != 1) {
|
|
|
|
window.opener.testsFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize to 0 since there is no initial state event,
|
|
|
|
// plugins should assume they do not initially have focus.
|
|
|
|
var expectedEventCount = 0;
|
|
|
|
|
|
|
|
// Make sure initial event count is correct.
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
// Make sure initial focus state is unknown (assumed false).
|
2010-04-25 13:58:03 -07:00
|
|
|
var initialStateUnknown = false;
|
|
|
|
try {
|
|
|
|
plugin1.getFocusState();
|
|
|
|
} catch (e) {
|
|
|
|
initialStateUnknown = true;
|
|
|
|
}
|
|
|
|
is(initialStateUnknown, true, "Initial state should be unknown, assumed false.");
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
// Give the plugin focus (the window is already focused).
|
|
|
|
utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1);
|
|
|
|
utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1);
|
2010-04-25 13:58:03 -07:00
|
|
|
expectedEventCount++;
|
|
|
|
|
|
|
|
is(plugin1.getFocusState(), true, "Plugin should have focus.");
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
// Make sure window activation state changes don't spontaneously
|
|
|
|
// change plugin focus.
|
2010-04-25 13:58:03 -07:00
|
|
|
|
|
|
|
// Blur the window.
|
|
|
|
window.blur();
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
is(plugin1.getFocusState(), true, "Plugin should still have focus.");
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
2010-04-25 13:58:03 -07:00
|
|
|
|
|
|
|
// Focus the window.
|
|
|
|
window.focus();
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
is(plugin1.getFocusState(), true, "Plugin should still have focus.");
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
2010-04-25 13:58:03 -07:00
|
|
|
|
|
|
|
// Take focus from the plugin.
|
2010-11-15 13:23:51 -08:00
|
|
|
utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseDown, 0, plugin2);
|
|
|
|
utils.sendNativeMouseEvent(plugin2X, plugin2Y, NSLeftMouseUp, 0, plugin2);
|
|
|
|
expectedEventCount++;
|
|
|
|
|
|
|
|
is(plugin1.getFocusState(), false, "Plugin should not have focus.");
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
|
|
|
|
|
|
|
// Make sure window activation causes the plugin to be informed of focus
|
|
|
|
// changes that took place while the window was inactive.
|
|
|
|
|
|
|
|
// Give the plugin focus (the window is already focused).
|
|
|
|
utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseDown, 0, plugin1);
|
|
|
|
utils.sendNativeMouseEvent(plugin1X, plugin1Y, NSLeftMouseUp, 0, plugin1);
|
|
|
|
expectedEventCount++;
|
|
|
|
|
|
|
|
// Blur the window.
|
|
|
|
window.blur();
|
|
|
|
|
|
|
|
// Take focus from the plugin while the window is blurred.
|
2010-04-25 13:58:03 -07:00
|
|
|
plugin2.focus();
|
|
|
|
|
2010-11-15 13:23:51 -08:00
|
|
|
is(plugin1.getFocusState(), true, "Plugin should still have focus.");
|
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
|
|
|
|
|
|
|
// Focus the window.
|
|
|
|
window.focus();
|
|
|
|
expectedEventCount++;
|
|
|
|
|
2010-04-25 13:58:03 -07:00
|
|
|
is(plugin1.getFocusState(), false, "Plugin should not have focus.");
|
2010-11-15 13:23:51 -08:00
|
|
|
is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
|
2010-04-25 13:58:03 -07:00
|
|
|
|
|
|
|
window.opener.testsFinished();
|
|
|
|
}
|
2010-11-15 13:23:51 -08:00
|
|
|
|
|
|
|
// Onload hander doesn't work for these tests -- no events arrive at the plugin.
|
|
|
|
window.opener.SimpleTest.waitForFocus(runTests, window);
|
|
|
|
|
2010-04-25 13:58:03 -07:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|