2010-08-17 07:26:17 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
|
|
|
|
|
|
|
<!-- We've had issues on Mac OS X where native key events either don't get processed
|
|
|
|
or they get processed twice. This test tests some of those scenarios. -->
|
|
|
|
|
|
|
|
<window id="window1" title="Test Key Event Counts" onload="runTest()"
|
|
|
|
xmlns:html="http://www.w3.org/1999/xhtml"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
2019-04-15 23:56:58 +03:00
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"/>
|
2010-08-17 07:26:17 +04:00
|
|
|
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<script type="application/javascript"><![CDATA[
|
|
|
|
var gKeyPressEventCount = 0;
|
2014-06-05 06:57:54 +04:00
|
|
|
var gKeyDownEventCound = 0;
|
|
|
|
|
|
|
|
function onKeyDown(e)
|
|
|
|
{
|
|
|
|
gKeyDownEventCount++;
|
|
|
|
}
|
2010-08-17 07:26:17 +04:00
|
|
|
|
|
|
|
function onKeyPress(e)
|
|
|
|
{
|
|
|
|
gKeyPressEventCount++;
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2015-04-14 18:36:36 +03:00
|
|
|
function* testBody()
|
2010-08-17 07:26:17 +04:00
|
|
|
{
|
2014-06-05 06:57:54 +04:00
|
|
|
window.addEventListener("keydown", onKeyDown, false);
|
2010-08-17 07:26:17 +04:00
|
|
|
window.addEventListener("keypress", onKeyPress, false);
|
|
|
|
|
|
|
|
// Test ctrl-tab
|
2014-06-05 06:57:54 +04:00
|
|
|
gKeyDownEventCount = 0;
|
2010-08-17 07:26:17 +04:00
|
|
|
gKeyPressEventCount = 0;
|
2015-04-14 18:36:36 +03:00
|
|
|
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Tab, {ctrlKey:1}, "\t", "\t", continueTest);
|
2014-06-05 06:57:54 +04:00
|
|
|
is(gKeyDownEventCount, 1);
|
|
|
|
is(gKeyPressEventCount, 0, "ctrl-tab should be consumed by tabbox of tabbrowser at keydown");
|
2010-08-17 07:26:17 +04:00
|
|
|
|
|
|
|
// Test cmd+shift+a
|
2014-06-05 06:57:54 +04:00
|
|
|
gKeyDownEventCount = 0;
|
2010-08-17 07:26:17 +04:00
|
|
|
gKeyPressEventCount = 0;
|
2015-04-14 18:36:36 +03:00
|
|
|
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {metaKey:1, shiftKey:1}, "a", "A", continueTest);
|
2014-06-05 06:57:54 +04:00
|
|
|
is(gKeyDownEventCount, 1);
|
2010-08-17 07:26:17 +04:00
|
|
|
is(gKeyPressEventCount, 1);
|
|
|
|
|
|
|
|
// Test cmd-;
|
2014-06-05 06:57:54 +04:00
|
|
|
gKeyDownEventCount = 0;
|
2010-08-17 07:26:17 +04:00
|
|
|
gKeyPressEventCount = 0;
|
2015-04-14 18:36:36 +03:00
|
|
|
yield synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Semicolon, {metaKey:1}, ";", ";", continueTest);
|
2014-06-05 06:57:54 +04:00
|
|
|
is(gKeyDownEventCount, 1);
|
2010-08-17 07:26:17 +04:00
|
|
|
is(gKeyPressEventCount, 1);
|
|
|
|
|
2014-06-05 06:57:54 +04:00
|
|
|
window.removeEventListener("keydown", onKeyDown, false);
|
2010-08-17 07:26:17 +04:00
|
|
|
window.removeEventListener("keypress", onKeyPress, false);
|
|
|
|
}
|
2015-04-14 18:36:36 +03:00
|
|
|
|
|
|
|
var gTestContinuation = null;
|
|
|
|
|
|
|
|
function continueTest()
|
|
|
|
{
|
|
|
|
if (!gTestContinuation) {
|
|
|
|
gTestContinuation = testBody();
|
|
|
|
}
|
|
|
|
var ret = gTestContinuation.next();
|
|
|
|
if (ret.done) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
} else {
|
|
|
|
is(ret.value, true, "Key synthesized successfully");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTest()
|
|
|
|
{
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
continueTest();
|
|
|
|
}
|
2010-08-17 07:26:17 +04:00
|
|
|
]]></script>
|
|
|
|
|
|
|
|
</window>
|