Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1274)

Side by Side Diff: chrome/test/data/extensions/api_test/input_ime_nonchromeos/background.js

Issue 1780523006: Add tests for input.ime.* APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 20 matching lines...) Expand all
45 chrome.test.assertNoLastError() 46 chrome.test.assertNoLastError()
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 });
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 },
68 function testCommitText() {
69 var composition_bounds_change_count = 0;
70 var composition_left = 0;
71 var composition_top = 0;
72 var composition_width = 0;
73 var composition_height = 0;
74 chrome.input.ime.onCompositionBoundsChanged.addListener(
75 function(boundsList) {
76 if (composition_bounds_change_count == 0) {
77 ++composition_bounds_change_count;
78 for (var i = 0; i < boundsList.length; i++ ) {
79 composition_left = boundsList[i].left;
80 composition_top = boundsList[i].top;
81 composition_width = boundsList[i].width;
82 composition_height = boundsList[i].height;
83 }
84 }
85 else {
86 for (var i = 0; i < boundsList.length; i++ ) {
87 chrome.test.assertEq(boundsList[i].top, composition_top);
88 chrome.test.assertEq(boundsList[i].height, composition_height);
89 if (composition_left == boundsList[i].left ) {
90 composition_width = boundsList[i].width;
91 }
92 else {
93 chrome.test.assertEq(boundsList[i].left,
94 composition_left + composition_width);
95 composition_left = boundsList[i].left;
96 composition_width = boundsList[i].width;
97 }
98 }
99 }
100 chrome.test.succeed();
101 });
102 var commit_text_count = 0;
103 chrome.input.ime.commitText({
104 contextID: 1,
105 text: 'test_commit_text'
106 }, function () {
107 if (chrome.runtime.lastError) {
108 chrome.test.fail();
109 return;
110 }
111 chrome.test.succeed();
112 });
113 },
114 function testSetCompositionText() {
115 chrome.input.ime.setComposition({
116 contextID: 1,
117 text: 'test_composition_text',
118 cursor: 2
119 }, function () {
120 if (chrome.runtime.lastError) {
121 chrome.test.fail();
122 return;
123 }
124 chrome.test.succeed();
125 })
55 } 126 }
56 ]); 127 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698