1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/inputmethod/mochitest/test_delete_focused_element.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=952741 1.8 +--> 1.9 +<head> 1.10 + <title>Test focused element deletion for InputMethod API.</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=952741">Mozilla Bug 952741</a> 1.17 +<input type="text" /> 1.18 +<p id="display"></p> 1.19 +<pre id="test"> 1.20 +<script class="testbody" type="application/javascript;version=1.7"> 1.21 + 1.22 +inputmethod_setup(function() { 1.23 + runTest(); 1.24 +}); 1.25 + 1.26 +// The frame script running in file_test_app.html. 1.27 +function appFrameScript() { 1.28 + let input = content.document.getElementById('test-input'); 1.29 + let textarea = content.document.createElement('textarea'); 1.30 + textarea.lang = 'en'; 1.31 + 1.32 + content.document.body.appendChild(textarea); 1.33 + 1.34 + textarea.onfocus = function() { 1.35 + textarea.parentNode.removeChild(textarea); 1.36 + sendAsyncMessage('test:InputMethod:finished', {}); 1.37 + }; 1.38 + 1.39 + content.setTimeout(function() { 1.40 + textarea.focus(); 1.41 + input.parentNode.removeChild(input); 1.42 + }, 0); 1.43 +} 1.44 + 1.45 +function runTest() { 1.46 + var timeoutId = null; 1.47 + 1.48 + // Create an app frame to recieve keyboard inputs. 1.49 + let app = document.createElement('iframe'); 1.50 + app.src = 'file_test_app.html'; 1.51 + app.setAttribute('mozbrowser', true); 1.52 + document.body.appendChild(app); 1.53 + app.addEventListener('mozbrowserloadend', function() { 1.54 + let mm = SpecialPowers.getBrowserFrameMessageManager(app); 1.55 + mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false); 1.56 + mm.addMessageListener("test:InputMethod:finished", function() { 1.57 + timeoutId = setTimeout(function() { 1.58 + ok(false, 'No inputcontextchange event when textarea is deleted.'); 1.59 + inputmethod_cleanup(); 1.60 + }, 20000); 1.61 + }); 1.62 + }); 1.63 + 1.64 + let im = navigator.mozInputMethod; 1.65 + let count = 0; 1.66 + im.oninputcontextchange = function() { 1.67 + switch (count++) { 1.68 + case 0: 1.69 + if (!im.inputcontext) { 1.70 + break; 1.71 + } 1.72 + is(im.inputcontext.lang, 'zh', 'input was focused.'); 1.73 + return; 1.74 + case 1: 1.75 + if (im.inputcontext) { 1.76 + break; 1.77 + } 1.78 + ok(true, 'input was blurred.'); 1.79 + return; 1.80 + case 2: 1.81 + if (!im.inputcontext) { 1.82 + break; 1.83 + } 1.84 + is(im.inputcontext.lang, 'en', 'textarea was focused.'); 1.85 + return; 1.86 + case 3: 1.87 + if (im.inputcontext) { 1.88 + break; 1.89 + } 1.90 + ok(true, 'textarea was removed.'); 1.91 + clearTimeout(timeoutId); 1.92 + inputmethod_cleanup(); 1.93 + return; 1.94 + default: 1.95 + return; 1.96 + } 1.97 + count = 100; 1.98 + ok(false, 'Should not arrive here.'); 1.99 + inputmethod_cleanup(); 1.100 + }; 1.101 + 1.102 + // Set current page as an input method. 1.103 + SpecialPowers.wrap(im).setActive(true); 1.104 +} 1.105 + 1.106 +</script> 1.107 +</pre> 1.108 +</body> 1.109 +</html> 1.110 +