1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/inputmethod/mochitest/test_bug960946.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=960946 1.8 +--> 1.9 +<head> 1.10 + <title>Basic test for repeat sendKey events</title> 1.11 + <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960946">Mozilla Bug 960946</a> 1.17 +<p id="display"></p> 1.18 +<pre id="test"> 1.19 +<script class="testbody" type="application/javascript;version=1.7"> 1.20 + 1.21 +// The input context. 1.22 +var gContext = null; 1.23 +var gCounter = 0; 1.24 +var result = ["keydown", "keypress", "keydown","keypress", 1.25 + "keydown", "keypress", "keyup" 1.26 + ]; 1.27 + 1.28 +inputmethod_setup(function() { 1.29 + runTest(); 1.30 +}); 1.31 + 1.32 +// The frame script running in file_test_backspace_event.html. 1.33 +function appFrameScript() { 1.34 + let input = content.document.getElementById('test-input'); 1.35 + input.onkeydown = input.onkeypress = input.onkeyup = function(event) { 1.36 + dump('key event was fired in file_test_backspace_event.html.'); 1.37 + sendAsyncMessage('test:KeyBoard:keyEvent', {'type':event.type}); 1.38 + }; 1.39 +} 1.40 + 1.41 +function runTest() { 1.42 + let im = navigator.mozInputMethod; 1.43 + 1.44 + im.oninputcontextchange = function() { 1.45 + ok(true, 'inputcontextchange event was fired.'); 1.46 + im.oninputcontextchange = null; 1.47 + 1.48 + gContext = im.inputcontext; 1.49 + if (!gContext) { 1.50 + ok(false, 'Should have a non-null inputcontext.'); 1.51 + inputmethod_cleanup(); 1.52 + return; 1.53 + } 1.54 + 1.55 + test_sendKey(); 1.56 + }; 1.57 + 1.58 + // Set current page as an input method. 1.59 + SpecialPowers.wrap(im).setActive(true); 1.60 + 1.61 + // Create an app frame to recieve keyboard inputs. 1.62 + let app = document.createElement('iframe'); 1.63 + app.src = 'file_test_app.html'; 1.64 + app.setAttribute('mozbrowser', true); 1.65 + document.body.appendChild(app); 1.66 + app.addEventListener('mozbrowserloadend', function() { 1.67 + let mm = SpecialPowers.getBrowserFrameMessageManager(app); 1.68 + mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false); 1.69 + mm.addMessageListener("test:KeyBoard:keyEvent", function(event) { 1.70 + ok(true, 'Keyboard input was received.'); 1.71 + is(SpecialPowers.wrap(event).json.type, result[gCounter], "expected event"); 1.72 + gCounter++; 1.73 + if (gCounter == 7) { 1.74 + inputmethod_cleanup(); 1.75 + } 1.76 + }); 1.77 + }); 1.78 +} 1.79 + 1.80 +function test_sendKey() { 1.81 + // Move cursor position to 4. 1.82 + gContext.setSelectionRange(4, 0).then(function() { 1.83 + is(gContext.selectionStart, 4, 'selectionStart was set successfully.'); 1.84 + is(gContext.selectionEnd, 4, 'selectionEnd was set successfully.'); 1.85 + for(let i = 0; i < 2; i++) { 1.86 + test_sendBackspace(true); 1.87 + } 1.88 + test_sendBackspace(false); 1.89 + }, function(e) { 1.90 + ok(false, 'setSelectionRange failed:' + e.name); 1.91 + inputmethod_cleanup(); 1.92 + }); 1.93 +} 1.94 + 1.95 +function test_sendBackspace(repeat) { 1.96 + // Send backspace 1.97 + gContext.sendKey(KeyEvent.DOM_VK_BACK_SPACE, 0, 0, repeat).then(function() { 1.98 + ok(true, 'sendKey success'); 1.99 + }, function(e) { 1.100 + ok(false, 'sendKey failed:' + e.name); 1.101 + inputmethod_cleanup(); 1.102 + }); 1.103 +} 1.104 +</script> 1.105 +</pre> 1.106 +</body> 1.107 +</html> 1.108 +