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

Side by Side Diff: remoting/test/remote_desktop_browsertest.cc

Issue 23542008: Add a CodeToNativeKeycode helper that converts UIEvent code to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "remote_desktop_browsertest.h" 5 #include "remote_desktop_browsertest.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_file_util.h" 11 #include "chrome/common/extensions/extension_file_util.h"
12 #include "content/public/browser/native_web_keyboard_event.h" 12 #include "content/public/browser/native_web_keyboard_event.h"
13 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 15
16 using extensions::Extension; 16 using extensions::Extension;
17 17
18 namespace remoting { 18 namespace remoting {
19 19
20 // BuildSimpleWebKeyEvent and SimulateKeyPress below are adapted from
21 // content/public/test/browser_test_utils.cc.
22 // TODO: Move this to browser_test_utils.cc after the support is added for
23 // the UIEvent key |code|.
24 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
25 ui::KeyboardCode key,
26 int nativeKeyCode,
27 bool control,
28 bool shift,
29 bool alt,
30 bool command,
31 content::NativeWebKeyboardEvent* event) {
32 event->nativeKeyCode = nativeKeyCode;
33 event->windowsKeyCode = key;
34 event->setKeyIdentifierFromWindowsKeyCode();
35 event->type = type;
36 event->modifiers = 0;
37 event->isSystemKey = false;
38 event->timeStampSeconds = base::Time::Now().ToDoubleT();
39 event->skip_in_browser = true;
40
41 if (type == WebKit::WebInputEvent::Char ||
42 type == WebKit::WebInputEvent::RawKeyDown) {
43 event->text[0] = key;
44 event->unmodifiedText[0] = key;
45 }
46
47 if (control)
48 event->modifiers |= WebKit::WebInputEvent::ControlKey;
49
50 if (shift)
51 event->modifiers |= WebKit::WebInputEvent::ShiftKey;
52
53 if (alt)
54 event->modifiers |= WebKit::WebInputEvent::AltKey;
55
56 if (command)
57 event->modifiers |= WebKit::WebInputEvent::MetaKey;
58 }
59
60 void SimulateKeyPress(content::WebContents* web_contents,
61 ui::KeyboardCode key,
62 int nativeKeyCode,
63 bool control,
64 bool shift,
65 bool alt,
66 bool command) {
67 content::NativeWebKeyboardEvent event_down;
68 BuildSimpleWebKeyEvent(
69 WebKit::WebInputEvent::RawKeyDown,
70 key, nativeKeyCode,
71 control,
72 shift,
73 alt,
74 command,
75 &event_down);
76 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
77
78 content::NativeWebKeyboardEvent char_event;
79 BuildSimpleWebKeyEvent(
80 WebKit::WebInputEvent::Char,
81 key, nativeKeyCode,
82 control,
83 shift,
84 alt,
85 command,
86 &char_event);
87 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
88
89 content::NativeWebKeyboardEvent event_up;
90 BuildSimpleWebKeyEvent(
91 WebKit::WebInputEvent::KeyUp,
92 key,
93 nativeKeyCode,
94 control,
95 shift,
96 alt,
97 command,
98 &event_up);
99 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
100 }
101
102 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {} 20 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {}
103 21
104 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} 22 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {}
105 23
106 void RemoteDesktopBrowserTest::SetUp() { 24 void RemoteDesktopBrowserTest::SetUp() {
107 ParseCommandLine(); 25 ParseCommandLine();
108 ExtensionBrowserTest::SetUp(); 26 ExtensionBrowserTest::SetUp();
109 } 27 }
110 28
111 // Change behavior of the default host resolver to avoid DNS lookup errors, 29 // Change behavior of the default host resolver to avoid DNS lookup errors,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 195
278 // Starting Me2Me. 196 // Starting Me2Me.
279 ExecuteScript("remoting.showMe2MeUiAndSave();"); 197 ExecuteScript("remoting.showMe2MeUiAndSave();");
280 198
281 EXPECT_TRUE(HtmlElementVisible("me2me-content")); 199 EXPECT_TRUE(HtmlElementVisible("me2me-content"));
282 EXPECT_FALSE(HtmlElementVisible("me2me-first-run")); 200 EXPECT_FALSE(HtmlElementVisible("me2me-first-run"));
283 } 201 }
284 202
285 void RemoteDesktopBrowserTest::SimulateKeyPress( 203 void RemoteDesktopBrowserTest::SimulateKeyPress(
286 ui::KeyboardCode key, 204 ui::KeyboardCode key,
287 int nativeKeyCode) { 205 const char* code) {
288 SimulateKeyPress(key, nativeKeyCode, false, false, false, false); 206 SimulateKeyPress(key, code, false, false, false, false);
289 } 207 }
290 208
291 void RemoteDesktopBrowserTest::SimulateKeyPress( 209 void RemoteDesktopBrowserTest::SimulateKeyPress(
292 ui::KeyboardCode key, 210 ui::KeyboardCode key,
293 int nativeKeyCode, 211 const char* code,
294 bool control, 212 bool control,
295 bool shift, 213 bool shift,
296 bool alt, 214 bool alt,
297 bool command) { 215 bool command) {
298 // TODO: Switch to content::SimulateKeyPress when an overload of it is 216 content::SimulateKeyPress(
299 // added to take the UIEvent key |code| string.
300 remoting::SimulateKeyPress(
301 browser()->tab_strip_model()->GetActiveWebContents(), 217 browser()->tab_strip_model()->GetActiveWebContents(),
302 key, 218 key,
303 nativeKeyCode, 219 code,
304 control, 220 control,
305 shift, 221 shift,
306 alt, 222 alt,
307 command); 223 command);
308 } 224 }
309 225
310 void RemoteDesktopBrowserTest::Install() { 226 void RemoteDesktopBrowserTest::Install() {
311 // TODO: add support for installing unpacked extension (the v2 app needs it). 227 // TODO: add support for installing unpacked extension (the v2 app needs it).
312 if (!NoInstall()) { 228 if (!NoInstall()) {
313 VerifyChromotingLoaded(false); 229 VerifyChromotingLoaded(false);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 // Wait until the client has connected to the server. 442 // Wait until the client has connected to the server.
527 // This can take a while. 443 // This can take a while.
528 // TODO: Instead of polling, can we register a callback to 444 // TODO: Instead of polling, can we register a callback to
529 // remoting.clientSession.onStageChange_? 445 // remoting.clientSession.onStageChange_?
530 while (ExecuteScriptAndExtractBool( 446 while (ExecuteScriptAndExtractBool(
531 "remoting.clientSession == null")) { 447 "remoting.clientSession == null")) {
532 } 448 }
533 } 449 }
534 450
535 } // namespace remoting 451 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698