OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 chrome.test.runTests([ | 5 chrome.test.runTests([ |
6 function testActivate() { | 6 function testActivate() { |
7 var focused = false; | 7 var focused = false; |
8 var activated = false; | 8 var activated = false; |
9 chrome.input.ime.onFocus.addListener(function(context) { | 9 chrome.input.ime.onFocus.addListener(function(context) { |
10 if (context.type == 'none') { | 10 if (context.type == 'none') { |
11 chrome.test.fail(); | 11 chrome.test.fail(); |
12 return; | 12 return; |
13 } | 13 } |
14 focused = true; | 14 focused = true; |
15 chrome.test.sendMessage('get_focus_event'); | |
15 if (activated) | 16 if (activated) |
16 chrome.test.succeed(); | 17 chrome.test.succeed(); |
17 }); | 18 }); |
18 chrome.input.ime.activate(function() { | 19 chrome.input.ime.activate(function() { |
19 if (chrome.runtime.lastError) { | 20 if (chrome.runtime.lastError) { |
20 chrome.test.fail(); | 21 chrome.test.fail(); |
21 return; | 22 return; |
22 } | 23 } |
23 activated = true; | 24 activated = true; |
24 if (focused) | 25 if (focused) |
(...skipping 21 matching lines...) Expand all Loading... | |
46 chrome.test.assertTrue(!!win); | 47 chrome.test.assertTrue(!!win); |
47 chrome.test.assertTrue(win instanceof Window); | 48 chrome.test.assertTrue(win instanceof Window); |
48 chrome.test.assertFalse(win.document.webkitHidden); | 49 chrome.test.assertFalse(win.document.webkitHidden); |
49 // test for security origin. | 50 // test for security origin. |
50 // If security origin is not correctly set, there will be securtiy | 51 // If security origin is not correctly set, there will be securtiy |
51 // exceptions when accessing DOM or add event listeners. | 52 // exceptions when accessing DOM or add event listeners. |
52 win.addEventListener('unload', function() {}); | 53 win.addEventListener('unload', function() {}); |
53 chrome.test.succeed(); | 54 chrome.test.succeed(); |
54 }); | 55 }); |
55 }, | 56 }, |
56 | 57 function testBlur() { |
58 chrome.input.ime.onBlur.addListener(function(context) { | |
59 if (context.type == 'none') { | |
60 chrome.test.fail(); | |
61 return; | |
62 } | |
63 chrome.test.sendMessage('get_blur_event'); | |
64 chrome.test.succeed(); | |
65 }); | |
66 chrome.test.succeed(); | |
67 }, | |
57 function testSendKeyEvents() { | 68 function testSendKeyEvents() { |
58 chrome.input.ime.sendKeyEvents({ | 69 chrome.input.ime.sendKeyEvents({ |
59 'contextID': 1, | 70 'contextID': 1, |
60 'keyData': [{ | 71 'keyData': [{ |
61 'type': 'keydown', | 72 'type': 'keydown', |
62 'requestId': '0', | 73 'requestId': '0', |
63 'key': 'a', | 74 'key': 'a', |
64 'code': 'KeyA' | 75 'code': 'KeyA' |
65 }, { | 76 }, { |
66 'type': 'keyup', | 77 'type': 'keyup', |
67 'requestId': '1', | 78 'requestId': '1', |
68 'key': 'a', | 79 'key': 'a', |
69 'code': 'KeyA' | 80 'code': 'KeyA' |
70 }] | 81 }] |
71 }); | 82 }); |
72 chrome.test.succeed(); | 83 chrome.test.succeed(); |
73 } | 84 }, |
85 function testCommitText() { | |
86 chrome.input.ime.commitText({ | |
87 contextID: 1, | |
88 text: 'test_commit_text' | |
89 }, function () { | |
90 if (chrome.runtime.lastError) { | |
91 chrome.test.fail(); | |
92 return; | |
93 } | |
94 chrome.test.succeed(); | |
95 }); | |
96 }, | |
97 function testComposition() { | |
98 chrome.input.ime.onCompositionBoundsChanged.addListener( | |
99 function(boundsList) { | |
100 if (boundsList.length > 0 && boundsList[0].width > 1 ){ | |
101 for (var i = 0; i < boundsList.length; i++ ) { | |
102 if (i==0) { | |
103 composition_left = boundsList[i].left; | |
104 composition_top = boundsList[i].top; | |
105 composition_width = boundsList[i].width; | |
106 composition_height = boundsList[i].height; | |
107 } | |
108 else { | |
109 chrome.test.assertEq(boundsList[i].top, composition_top); | |
110 chrome.test.assertEq(boundsList[i].height, composition_height); | |
111 chrome.test.assertEq(boundsList[i].left, | |
112 composition_left + composition_width); | |
113 composition_left = boundsList[i].left; | |
114 composition_width = boundsList[i].width; | |
115 } | |
116 } | |
117 } | |
118 if (boundsList.length > 20) { | |
119 chrome.test.sendMessage('finish_composition_test'); | |
120 } | |
121 chrome.test.succeed(); | |
122 }); | |
123 chrome.input.ime.setComposition({ | |
124 contextID: 1, | |
125 text: 'test_composition_text', | |
126 cursor: 2 | |
127 }, function() { | |
128 if(chrome.runtime.lastError) { | |
129 chrome.test.fail(); | |
130 return; | |
131 } | |
132 chrome.test.succeed(); | |
Shu Chen
2016/03/16 05:55:39
remove this line.
| |
133 }); | |
134 } | |
74 ]); | 135 ]); |
OLD | NEW |