widget/tests/test_key_event_counts.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <!-- We've had issues on Mac OS X where native key events either don't get processed
michael@0 6 or they get processed twice. This test tests some of those scenarios. -->
michael@0 7
michael@0 8 <window id="window1" title="Test Key Event Counts" onload="runTest()"
michael@0 9 xmlns:html="http://www.w3.org/1999/xhtml"
michael@0 10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 11
michael@0 12 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 13 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 14 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"/>
michael@0 15
michael@0 16 <!-- test results are displayed in the html:body -->
michael@0 17 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 18 <p id="display"></p>
michael@0 19 <div id="content" style="display: none"></div>
michael@0 20 <pre id="test"></pre>
michael@0 21 </body>
michael@0 22
michael@0 23 <script type="application/javascript"><![CDATA[
michael@0 24 var gKeyPressEventCount = 0;
michael@0 25
michael@0 26 function onKeyPress(e)
michael@0 27 {
michael@0 28 gKeyPressEventCount++;
michael@0 29 e.preventDefault();
michael@0 30 }
michael@0 31
michael@0 32 function runTest()
michael@0 33 {
michael@0 34 window.addEventListener("keypress", onKeyPress, false);
michael@0 35
michael@0 36 // Test ctrl-tab
michael@0 37 gKeyPressEventCount = 0;
michael@0 38 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_Tab, {ctrlKey:1}, "\t", "\t");
michael@0 39 is(gKeyPressEventCount, 1);
michael@0 40
michael@0 41 // Test cmd+shift+a
michael@0 42 gKeyPressEventCount = 0;
michael@0 43 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {metaKey:1, shiftKey:1}, "a", "A");
michael@0 44 is(gKeyPressEventCount, 1);
michael@0 45
michael@0 46 // Test cmd-;
michael@0 47 gKeyPressEventCount = 0;
michael@0 48 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_Semicolon, {metaKey:1}, ";", ";");
michael@0 49 is(gKeyPressEventCount, 1);
michael@0 50
michael@0 51 window.removeEventListener("keypress", onKeyPress, false);
michael@0 52 }
michael@0 53 ]]></script>
michael@0 54
michael@0 55 </window>

mercurial