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