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

Side by Side Diff: trunk/src/content/public/test/browser_test_utils.cc

Issue 23451030: Revert 222168 "Add a CodeToNativeKeycode helper that converts UI..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "grit/webui_resources.h" 27 #include "grit/webui_resources.h"
28 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
29 #include "net/cookies/cookie_store.h" 29 #include "net/cookies/cookie_store.h"
30 #include "net/test/python_utils.h" 30 #include "net/test/python_utils.h"
31 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h" 32 #include "net/url_request/url_request_context_getter.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34
35 #if defined(OS_WIN)
36 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code}
37 #elif defined(OS_LINUX)
38 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code}
39 #elif defined(OS_MACOSX)
40 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code}
41 #else
42 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code}
43 #endif
44 #include "ui/base/keycodes/usb_keycode_map.h"
45 #undef USB_KEYMAP
46
47 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
48 35
49 static const int kDefaultWsPort = 8880; 36 static const int kDefaultWsPort = 8880;
50 37
51 namespace content { 38 namespace content {
52 namespace { 39 namespace {
53 40
54 class DOMOperationObserver : public NotificationObserver, 41 class DOMOperationObserver : public NotificationObserver,
55 public WebContentsObserver { 42 public WebContentsObserver {
56 public: 43 public:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 result->reset(reader.ReadToValue(json)); 113 result->reset(reader.ReadToValue(json));
127 if (!result->get()) { 114 if (!result->get()) {
128 DLOG(ERROR) << reader.GetErrorMessage(); 115 DLOG(ERROR) << reader.GetErrorMessage();
129 return false; 116 return false;
130 } 117 }
131 118
132 return true; 119 return true;
133 } 120 }
134 121
135 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, 122 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
136 ui::KeyboardCode key_code, 123 ui::KeyboardCode key,
137 int native_key_code,
138 bool control, 124 bool control,
139 bool shift, 125 bool shift,
140 bool alt, 126 bool alt,
141 bool command, 127 bool command,
142 NativeWebKeyboardEvent* event) { 128 NativeWebKeyboardEvent* event) {
143 event->nativeKeyCode = native_key_code; 129 event->nativeKeyCode = 0;
144 event->windowsKeyCode = key_code; 130 event->windowsKeyCode = key;
145 event->setKeyIdentifierFromWindowsKeyCode(); 131 event->setKeyIdentifierFromWindowsKeyCode();
146 event->type = type; 132 event->type = type;
147 event->modifiers = 0; 133 event->modifiers = 0;
148 event->isSystemKey = false; 134 event->isSystemKey = false;
149 event->timeStampSeconds = base::Time::Now().ToDoubleT(); 135 event->timeStampSeconds = base::Time::Now().ToDoubleT();
150 event->skip_in_browser = true; 136 event->skip_in_browser = true;
151 137
152 if (type == WebKit::WebInputEvent::Char || 138 if (type == WebKit::WebInputEvent::Char ||
153 type == WebKit::WebInputEvent::RawKeyDown) { 139 type == WebKit::WebInputEvent::RawKeyDown) {
154 event->text[0] = key_code; 140 event->text[0] = key;
155 event->unmodifiedText[0] = key_code; 141 event->unmodifiedText[0] = key;
156 } 142 }
157 143
158 if (control) 144 if (control)
159 event->modifiers |= WebKit::WebInputEvent::ControlKey; 145 event->modifiers |= WebKit::WebInputEvent::ControlKey;
160 146
161 if (shift) 147 if (shift)
162 event->modifiers |= WebKit::WebInputEvent::ShiftKey; 148 event->modifiers |= WebKit::WebInputEvent::ShiftKey;
163 149
164 if (alt) 150 if (alt)
165 event->modifiers |= WebKit::WebInputEvent::AltKey; 151 event->modifiers |= WebKit::WebInputEvent::AltKey;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 WebKit::WebInputEvent::Type type, 258 WebKit::WebInputEvent::Type type,
273 const gfx::Point& point) { 259 const gfx::Point& point) {
274 WebKit::WebMouseEvent mouse_event; 260 WebKit::WebMouseEvent mouse_event;
275 mouse_event.type = type; 261 mouse_event.type = type;
276 mouse_event.x = point.x(); 262 mouse_event.x = point.x();
277 mouse_event.y = point.y(); 263 mouse_event.y = point.y();
278 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 264 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
279 } 265 }
280 266
281 void SimulateKeyPress(WebContents* web_contents, 267 void SimulateKeyPress(WebContents* web_contents,
282 ui::KeyboardCode key_code, 268 ui::KeyboardCode key,
283 bool control, 269 bool control,
284 bool shift, 270 bool shift,
285 bool alt, 271 bool alt,
286 bool command) { 272 bool command) {
287 SimulateKeyPressWithCode(
288 web_contents, key_code, NULL, control, shift, alt, command);
289 }
290
291 void SimulateKeyPressWithCode(WebContents* web_contents,
292 ui::KeyboardCode key_code,
293 const char* code,
294 bool control,
295 bool shift,
296 bool alt,
297 bool command) {
298 int native_key_code = CodeToNativeKeycode(code);
299
300 NativeWebKeyboardEvent event_down; 273 NativeWebKeyboardEvent event_down;
301 BuildSimpleWebKeyEvent( 274 BuildSimpleWebKeyEvent(
302 WebKit::WebInputEvent::RawKeyDown, 275 WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command,
303 key_code,
304 native_key_code,
305 control,
306 shift,
307 alt,
308 command,
309 &event_down); 276 &event_down);
310 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); 277 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
311 278
312 NativeWebKeyboardEvent char_event; 279 NativeWebKeyboardEvent char_event;
313 BuildSimpleWebKeyEvent( 280 BuildSimpleWebKeyEvent(
314 WebKit::WebInputEvent::Char, 281 WebKit::WebInputEvent::Char, key, control, shift, alt, command,
315 key_code,
316 native_key_code,
317 control,
318 shift,
319 alt,
320 command,
321 &char_event); 282 &char_event);
322 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); 283 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
323 284
324 NativeWebKeyboardEvent event_up; 285 NativeWebKeyboardEvent event_up;
325 BuildSimpleWebKeyEvent( 286 BuildSimpleWebKeyEvent(
326 WebKit::WebInputEvent::KeyUp, 287 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command,
327 key_code,
328 native_key_code,
329 control,
330 shift,
331 alt,
332 command,
333 &event_up); 288 &event_up);
334 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); 289 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
335 } 290 }
336 291
337 namespace internal { 292 namespace internal {
338 293
339 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) 294 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents)
340 : render_view_host_(web_contents->GetRenderViewHost()) { 295 : render_view_host_(web_contents->GetRenderViewHost()) {
341 } 296 }
342 297
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // The queue should not be empty, unless we were quit because of a timeout. 539 // The queue should not be empty, unless we were quit because of a timeout.
585 if (message_queue_.empty()) 540 if (message_queue_.empty())
586 return false; 541 return false;
587 if (message) 542 if (message)
588 *message = message_queue_.front(); 543 *message = message_queue_.front();
589 message_queue_.pop(); 544 message_queue_.pop();
590 return true; 545 return true;
591 } 546 }
592 547
593 } // namespace content 548 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/public/test/browser_test_utils.h ('k') | trunk/src/remoting/test/remote_desktop_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698