Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=960946
5 -->
6 <head>
7 <title>Basic test for repeat sendKey events</title>
8 <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960946">Mozilla Bug 960946</a>
14 <p id="display"></p>
15 <pre id="test">
16 <script class="testbody" type="application/javascript;version=1.7">
18 // The input context.
19 var gContext = null;
20 var gCounter = 0;
21 var result = ["keydown", "keypress", "keydown","keypress",
22 "keydown", "keypress", "keyup"
23 ];
25 inputmethod_setup(function() {
26 runTest();
27 });
29 // The frame script running in file_test_backspace_event.html.
30 function appFrameScript() {
31 let input = content.document.getElementById('test-input');
32 input.onkeydown = input.onkeypress = input.onkeyup = function(event) {
33 dump('key event was fired in file_test_backspace_event.html.');
34 sendAsyncMessage('test:KeyBoard:keyEvent', {'type':event.type});
35 };
36 }
38 function runTest() {
39 let im = navigator.mozInputMethod;
41 im.oninputcontextchange = function() {
42 ok(true, 'inputcontextchange event was fired.');
43 im.oninputcontextchange = null;
45 gContext = im.inputcontext;
46 if (!gContext) {
47 ok(false, 'Should have a non-null inputcontext.');
48 inputmethod_cleanup();
49 return;
50 }
52 test_sendKey();
53 };
55 // Set current page as an input method.
56 SpecialPowers.wrap(im).setActive(true);
58 // Create an app frame to recieve keyboard inputs.
59 let app = document.createElement('iframe');
60 app.src = 'file_test_app.html';
61 app.setAttribute('mozbrowser', true);
62 document.body.appendChild(app);
63 app.addEventListener('mozbrowserloadend', function() {
64 let mm = SpecialPowers.getBrowserFrameMessageManager(app);
65 mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
66 mm.addMessageListener("test:KeyBoard:keyEvent", function(event) {
67 ok(true, 'Keyboard input was received.');
68 is(SpecialPowers.wrap(event).json.type, result[gCounter], "expected event");
69 gCounter++;
70 if (gCounter == 7) {
71 inputmethod_cleanup();
72 }
73 });
74 });
75 }
77 function test_sendKey() {
78 // Move cursor position to 4.
79 gContext.setSelectionRange(4, 0).then(function() {
80 is(gContext.selectionStart, 4, 'selectionStart was set successfully.');
81 is(gContext.selectionEnd, 4, 'selectionEnd was set successfully.');
82 for(let i = 0; i < 2; i++) {
83 test_sendBackspace(true);
84 }
85 test_sendBackspace(false);
86 }, function(e) {
87 ok(false, 'setSelectionRange failed:' + e.name);
88 inputmethod_cleanup();
89 });
90 }
92 function test_sendBackspace(repeat) {
93 // Send backspace
94 gContext.sendKey(KeyEvent.DOM_VK_BACK_SPACE, 0, 0, repeat).then(function() {
95 ok(true, 'sendKey success');
96 }, function(e) {
97 ok(false, 'sendKey failed:' + e.name);
98 inputmethod_cleanup();
99 });
100 }
101 </script>
102 </pre>
103 </body>
104 </html>