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

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: Check lastError of sendKeyEvents. Created 4 years, 6 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 function testActivate() { 8 function testActivate() {
7 var focused = false; 9 var focused = false;
8 var activated = false; 10 var activated = false;
9 chrome.input.ime.onFocus.addListener(function(context) { 11 chrome.input.ime.onFocus.addListener(function(context) {
10 if (context.type == 'none') { 12 if (context.type == 'none') {
11 chrome.test.fail(); 13 chrome.test.fail();
12 return; 14 return;
13 } 15 }
14 focused = true; 16 focused = true;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 chrome.test.assertFalse(win.document.webkitHidden); 50 chrome.test.assertFalse(win.document.webkitHidden);
49 // test for security origin. 51 // test for security origin.
50 // If security origin is not correctly set, there will be securtiy 52 // If security origin is not correctly set, there will be securtiy
51 // exceptions when accessing DOM or add event listeners. 53 // exceptions when accessing DOM or add event listeners.
52 win.addEventListener('unload', function() {}); 54 win.addEventListener('unload', function() {});
53 chrome.test.succeed(); 55 chrome.test.succeed();
54 }); 56 });
55 }, 57 },
56 58
57 function testSendKeyEvents() { 59 function testSendKeyEvents() {
60 // Sends a normal character key.
58 chrome.input.ime.sendKeyEvents({ 61 chrome.input.ime.sendKeyEvents({
59 'contextID': 1, 62 'contextID': 1,
60 'keyData': [{ 63 'keyData': [{
61 'type': 'keydown', 64 'type': 'keydown',
62 'requestId': '0', 65 'requestId': '0',
63 'key': 'a', 66 'key': 'a',
64 'code': 'KeyA' 67 'code': 'KeyA'
65 }, { 68 }, {
66 'type': 'keyup', 69 'type': 'keyup',
67 'requestId': '1', 70 'requestId': '1',
68 'key': 'a', 71 'key': 'a',
69 'code': 'KeyA' 72 'code': 'KeyA'
70 }] 73 }]
74 }, function() {
75 // Normal character key should be allowed to send on any page.
76 chrome.test.assertNoLastError();
77 });
78
79 // Sends Ctrl+A that should fail on special pages.
80 chrome.input.ime.sendKeyEvents({
81 'contextID': 1,
82 'keyData': [{
83 'type': 'keydown',
84 'requestId': '2',
85 'key': 'a',
86 'code': 'KeyA',
87 'ctrlKey': true
88 }, {
89 'type': 'keyup',
90 'requestId': '3',
91 'key': 'a',
92 'code': 'KeyA',
93 'ctrlKey': true
94 }]
95 }, function() {
96 if (chrome.runtime.lastError) {
97 chrome.test.assertEq(failToSendKeyEvents,
Devlin 2016/06/23 18:43:22 nit: indentation chrome.test.assertEq(failToSendKe
Azure Wei 2016/06/24 06:38:19 Done. Thanks for the comments.
98 chrome.runtime.lastError.message);
99 }
100 });
101
102 // Sends Tab key that should fail on special pages.
103 chrome.input.ime.sendKeyEvents({
104 'contextID': 1,
105 'keyData': [{
106 'type': 'keydown',
107 'requestId': '4',
108 'key': '\u0009',
109 'code': 'Tab'
110 }]
111 }, function() {
112 if (chrome.runtime.lastError) {
113 chrome.test.assertEq(failToSendKeyEvents,
114 chrome.runtime.lastError.message);
115 }
71 }); 116 });
72 chrome.test.succeed(); 117 chrome.test.succeed();
73 } 118 }
74 ]); 119 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698