dom/inputmethod/mochitest/test_delete_focused_element.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=952741
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test focused element deletion for InputMethod API.</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=952741">Mozilla Bug 952741</a>
michael@0 14 <input type="text" />
michael@0 15 <p id="display"></p>
michael@0 16 <pre id="test">
michael@0 17 <script class="testbody" type="application/javascript;version=1.7">
michael@0 18
michael@0 19 inputmethod_setup(function() {
michael@0 20 runTest();
michael@0 21 });
michael@0 22
michael@0 23 // The frame script running in file_test_app.html.
michael@0 24 function appFrameScript() {
michael@0 25 let input = content.document.getElementById('test-input');
michael@0 26 let textarea = content.document.createElement('textarea');
michael@0 27 textarea.lang = 'en';
michael@0 28
michael@0 29 content.document.body.appendChild(textarea);
michael@0 30
michael@0 31 textarea.onfocus = function() {
michael@0 32 textarea.parentNode.removeChild(textarea);
michael@0 33 sendAsyncMessage('test:InputMethod:finished', {});
michael@0 34 };
michael@0 35
michael@0 36 content.setTimeout(function() {
michael@0 37 textarea.focus();
michael@0 38 input.parentNode.removeChild(input);
michael@0 39 }, 0);
michael@0 40 }
michael@0 41
michael@0 42 function runTest() {
michael@0 43 var timeoutId = null;
michael@0 44
michael@0 45 // Create an app frame to recieve keyboard inputs.
michael@0 46 let app = document.createElement('iframe');
michael@0 47 app.src = 'file_test_app.html';
michael@0 48 app.setAttribute('mozbrowser', true);
michael@0 49 document.body.appendChild(app);
michael@0 50 app.addEventListener('mozbrowserloadend', function() {
michael@0 51 let mm = SpecialPowers.getBrowserFrameMessageManager(app);
michael@0 52 mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
michael@0 53 mm.addMessageListener("test:InputMethod:finished", function() {
michael@0 54 timeoutId = setTimeout(function() {
michael@0 55 ok(false, 'No inputcontextchange event when textarea is deleted.');
michael@0 56 inputmethod_cleanup();
michael@0 57 }, 20000);
michael@0 58 });
michael@0 59 });
michael@0 60
michael@0 61 let im = navigator.mozInputMethod;
michael@0 62 let count = 0;
michael@0 63 im.oninputcontextchange = function() {
michael@0 64 switch (count++) {
michael@0 65 case 0:
michael@0 66 if (!im.inputcontext) {
michael@0 67 break;
michael@0 68 }
michael@0 69 is(im.inputcontext.lang, 'zh', 'input was focused.');
michael@0 70 return;
michael@0 71 case 1:
michael@0 72 if (im.inputcontext) {
michael@0 73 break;
michael@0 74 }
michael@0 75 ok(true, 'input was blurred.');
michael@0 76 return;
michael@0 77 case 2:
michael@0 78 if (!im.inputcontext) {
michael@0 79 break;
michael@0 80 }
michael@0 81 is(im.inputcontext.lang, 'en', 'textarea was focused.');
michael@0 82 return;
michael@0 83 case 3:
michael@0 84 if (im.inputcontext) {
michael@0 85 break;
michael@0 86 }
michael@0 87 ok(true, 'textarea was removed.');
michael@0 88 clearTimeout(timeoutId);
michael@0 89 inputmethod_cleanup();
michael@0 90 return;
michael@0 91 default:
michael@0 92 return;
michael@0 93 }
michael@0 94 count = 100;
michael@0 95 ok(false, 'Should not arrive here.');
michael@0 96 inputmethod_cleanup();
michael@0 97 };
michael@0 98
michael@0 99 // Set current page as an input method.
michael@0 100 SpecialPowers.wrap(im).setActive(true);
michael@0 101 }
michael@0 102
michael@0 103 </script>
michael@0 104 </pre>
michael@0 105 </body>
michael@0 106 </html>
michael@0 107

mercurial