dom/inputmethod/mochitest/test_bug960946.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial