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

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

Issue 2077783002: Make limitations for input.ime.sendKeyEvents API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: onKeyEvent should not work in password. Created 4 years, 5 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 var failToSendKeyEvents = 'Could not send key events';
6
5 chrome.test.runTests([ 7 chrome.test.runTests([
6 // Tests input.ime.activate and input.ime.onFocus APIs. 8 // Tests input.ime.activate and input.ime.onFocus APIs.
7 function testActivateAndFocus() { 9 function testActivateAndFocus() {
8 var focused = false; 10 var focused = false;
9 var activated = false; 11 var activated = false;
10 chrome.input.ime.onFocus.addListener(function(context) { 12 chrome.input.ime.onFocus.addListener(function(context) {
11 if (context.type == 'none') { 13 if (context.type == 'none') {
12 chrome.test.fail(); 14 chrome.test.fail();
13 return; 15 return;
14 } 16 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 chrome.test.assertTrue(!!win); 50 chrome.test.assertTrue(!!win);
49 chrome.test.assertTrue(win instanceof Window); 51 chrome.test.assertTrue(win instanceof Window);
50 chrome.test.assertFalse(win.document.webkitHidden); 52 chrome.test.assertFalse(win.document.webkitHidden);
51 // test for security origin. 53 // test for security origin.
52 // If security origin is not correctly set, there will be securtiy 54 // If security origin is not correctly set, there will be securtiy
53 // exceptions when accessing DOM or add event listeners. 55 // exceptions when accessing DOM or add event listeners.
54 win.addEventListener('unload', function() {}); 56 win.addEventListener('unload', function() {});
55 chrome.test.succeed(); 57 chrome.test.succeed();
56 }); 58 });
57 }, 59 },
58 // Test input.ime.sendKeyEvents API.
59 function testSendKeyEvents() {
60 chrome.input.ime.sendKeyEvents({
61 'contextID': 1,
62 'keyData': [{
63 'type': 'keydown',
64 'requestId': '0',
65 'key': 'a',
66 'code': 'KeyA'
67 }, {
68 'type': 'keyup',
69 'requestId': '1',
70 'key': 'a',
71 'code': 'KeyA'
72 }]
73 });
74 chrome.test.succeed();
75 },
76 // Test input.ime.commitText API.
77 function testCommitText() { 60 function testCommitText() {
78 chrome.input.ime.commitText({ 61 chrome.input.ime.commitText({
79 contextID: 1, 62 contextID: 1,
80 text: 'test_commit_text' 63 text: 'test_commit_text'
81 }, function () { 64 }, function () {
82 if (chrome.runtime.lastError) { 65 if (chrome.runtime.lastError) {
83 chrome.test.fail(); 66 chrome.test.fail();
84 return; 67 return;
85 } 68 }
86 chrome.test.succeed(); 69 chrome.test.succeed();
87 }); 70 });
88 }, 71 },
89 // Tests input.ime.activate and input.ime.setComposition API. 72 // Tests input.ime.activate and input.ime.setComposition API.
90 function testSetComposition() { 73 function testSetComposition() {
91 chrome.input.ime.setComposition({ 74 chrome.input.ime.setComposition({
92 contextID: 1, 75 contextID: 1,
93 text: 'test_set_composition', 76 text: 'test_set_composition',
94 cursor: 2 77 cursor: 2
95 }, function() { 78 }, function() {
96 if(chrome.runtime.lastError) { 79 if(chrome.runtime.lastError) {
97 chrome.test.fail(); 80 chrome.test.fail();
98 return; 81 return;
99 } 82 }
100 chrome.test.succeed(); 83 chrome.test.succeed();
101 }); 84 });
102 }, 85 },
86 // Test input.ime.sendKeyEvents API.
87 function testSendKeyEvents() {
88 // Sends a normal character key.
89 chrome.input.ime.sendKeyEvents({
90 contextID: 1,
91 keyData: [{
92 type: 'keydown',
93 requestId: '0',
94 key: 'a',
95 code: 'KeyA'
96 }, {
97 type: 'keyup',
98 requestId: '1',
99 key: 'a',
100 code: 'KeyA'
101 }]
102 }, function() {
103 // Normal character key should be allowed to send on any page.
104 chrome.test.assertNoLastError();
105 });
106 // Sends Ctrl+A that should fail on special pages.
107 chrome.input.ime.sendKeyEvents({
108 contextID: 1,
109 keyData: [{
110 type: 'keydown',
111 requestId: '2',
112 key: 'a',
113 code: 'KeyA',
114 ctrlKey: true
115 }, {
116 type: 'keyup',
117 requestId: '3',
118 key: 'a',
119 code: 'KeyA',
120 ctrlKey: true
121 }]
122 }, function() {
123 if (chrome.runtime.lastError) {
124 chrome.test.assertEq(failToSendKeyEvents,
125 chrome.runtime.lastError.message);
126 }
127 });
128 // Sends Tab key that should fail on special pages.
129 chrome.input.ime.sendKeyEvents({
130 contextID: 1,
131 keyData: [{
132 type: 'keydown',
133 requestId: '4',
134 key: '\u0009', // Unicode value for Tab key.
135 code: 'Tab'
136 }]
137 }, function() {
138 if (chrome.runtime.lastError) {
139 chrome.test.assertEq(failToSendKeyEvents,
140 chrome.runtime.lastError.message);
141 }
142 });
143 chrome.test.succeed();
144 },
103 // Tests input.ime.onBlur API. 145 // Tests input.ime.onBlur API.
104 function testBlur() { 146 function testBlur() {
105 chrome.input.ime.onBlur.addListener(function(context) { 147 chrome.input.ime.onBlur.addListener(function(context) {
106 if (context.type == 'none') { 148 if (context.type != 'none') {
107 chrome.test.fail(); 149 // Waits for the 'get_blur_event' message in
108 return; 150 // InputImeApiTest.BasicApiTest.
151 chrome.test.sendMessage('get_blur_event');
109 } 152 }
110 // Waits for the 'get_blur_event' message in InputImeApiTest.BasicApiTest.
111 chrome.test.sendMessage('get_blur_event');
112 chrome.test.succeed(); 153 chrome.test.succeed();
113 }); 154 });
114 chrome.test.succeed(); 155 chrome.test.succeed();
115 }, 156 }
116 ]); 157 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698