OLD | NEW |
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 Loading... |
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 |
34 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
35 | 48 |
36 static const int kDefaultWsPort = 8880; | 49 static const int kDefaultWsPort = 8880; |
37 | 50 |
38 namespace content { | 51 namespace content { |
39 namespace { | 52 namespace { |
40 | 53 |
41 class DOMOperationObserver : public NotificationObserver, | 54 class DOMOperationObserver : public NotificationObserver, |
42 public WebContentsObserver { | 55 public WebContentsObserver { |
43 public: | 56 public: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 result->reset(reader.ReadToValue(json)); | 126 result->reset(reader.ReadToValue(json)); |
114 if (!result->get()) { | 127 if (!result->get()) { |
115 DLOG(ERROR) << reader.GetErrorMessage(); | 128 DLOG(ERROR) << reader.GetErrorMessage(); |
116 return false; | 129 return false; |
117 } | 130 } |
118 | 131 |
119 return true; | 132 return true; |
120 } | 133 } |
121 | 134 |
122 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, | 135 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
123 ui::KeyboardCode key, | 136 ui::KeyboardCode keyCode, |
| 137 int nativeKeyCode, |
124 bool control, | 138 bool control, |
125 bool shift, | 139 bool shift, |
126 bool alt, | 140 bool alt, |
127 bool command, | 141 bool command, |
128 NativeWebKeyboardEvent* event) { | 142 NativeWebKeyboardEvent* event) { |
129 event->nativeKeyCode = 0; | 143 event->nativeKeyCode = nativeKeyCode; |
130 event->windowsKeyCode = key; | 144 event->windowsKeyCode = keyCode; |
131 event->setKeyIdentifierFromWindowsKeyCode(); | 145 event->setKeyIdentifierFromWindowsKeyCode(); |
132 event->type = type; | 146 event->type = type; |
133 event->modifiers = 0; | 147 event->modifiers = 0; |
134 event->isSystemKey = false; | 148 event->isSystemKey = false; |
135 event->timeStampSeconds = base::Time::Now().ToDoubleT(); | 149 event->timeStampSeconds = base::Time::Now().ToDoubleT(); |
136 event->skip_in_browser = true; | 150 event->skip_in_browser = true; |
137 | 151 |
138 if (type == WebKit::WebInputEvent::Char || | 152 if (type == WebKit::WebInputEvent::Char || |
139 type == WebKit::WebInputEvent::RawKeyDown) { | 153 type == WebKit::WebInputEvent::RawKeyDown) { |
140 event->text[0] = key; | 154 event->text[0] = keyCode; |
141 event->unmodifiedText[0] = key; | 155 event->unmodifiedText[0] = keyCode; |
142 } | 156 } |
143 | 157 |
144 if (control) | 158 if (control) |
145 event->modifiers |= WebKit::WebInputEvent::ControlKey; | 159 event->modifiers |= WebKit::WebInputEvent::ControlKey; |
146 | 160 |
147 if (shift) | 161 if (shift) |
148 event->modifiers |= WebKit::WebInputEvent::ShiftKey; | 162 event->modifiers |= WebKit::WebInputEvent::ShiftKey; |
149 | 163 |
150 if (alt) | 164 if (alt) |
151 event->modifiers |= WebKit::WebInputEvent::AltKey; | 165 event->modifiers |= WebKit::WebInputEvent::AltKey; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 WebKit::WebInputEvent::Type type, | 272 WebKit::WebInputEvent::Type type, |
259 const gfx::Point& point) { | 273 const gfx::Point& point) { |
260 WebKit::WebMouseEvent mouse_event; | 274 WebKit::WebMouseEvent mouse_event; |
261 mouse_event.type = type; | 275 mouse_event.type = type; |
262 mouse_event.x = point.x(); | 276 mouse_event.x = point.x(); |
263 mouse_event.y = point.y(); | 277 mouse_event.y = point.y(); |
264 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 278 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
265 } | 279 } |
266 | 280 |
267 void SimulateKeyPress(WebContents* web_contents, | 281 void SimulateKeyPress(WebContents* web_contents, |
268 ui::KeyboardCode key, | 282 ui::KeyboardCode keyCode, |
269 bool control, | 283 bool control, |
270 bool shift, | 284 bool shift, |
271 bool alt, | 285 bool alt, |
272 bool command) { | 286 bool command) { |
| 287 SimulateKeyPressWithCode( |
| 288 web_contents, keyCode, NULL, control, shift, alt, command); |
| 289 } |
| 290 |
| 291 void SimulateKeyPressWithCode(WebContents* web_contents, |
| 292 ui::KeyboardCode keyCode, |
| 293 const char* code, |
| 294 bool control, |
| 295 bool shift, |
| 296 bool alt, |
| 297 bool command) { |
| 298 int nativeKeyCode = CodeToNativeKeycode(code); |
| 299 |
273 NativeWebKeyboardEvent event_down; | 300 NativeWebKeyboardEvent event_down; |
274 BuildSimpleWebKeyEvent( | 301 BuildSimpleWebKeyEvent( |
275 WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command, | 302 WebKit::WebInputEvent::RawKeyDown, |
| 303 keyCode, |
| 304 nativeKeyCode, |
| 305 control, |
| 306 shift, |
| 307 alt, |
| 308 command, |
276 &event_down); | 309 &event_down); |
277 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); | 310 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
278 | 311 |
279 NativeWebKeyboardEvent char_event; | 312 NativeWebKeyboardEvent char_event; |
280 BuildSimpleWebKeyEvent( | 313 BuildSimpleWebKeyEvent( |
281 WebKit::WebInputEvent::Char, key, control, shift, alt, command, | 314 WebKit::WebInputEvent::Char, |
| 315 keyCode, |
| 316 nativeKeyCode, |
| 317 control, |
| 318 shift, |
| 319 alt, |
| 320 command, |
282 &char_event); | 321 &char_event); |
283 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); | 322 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
284 | 323 |
285 NativeWebKeyboardEvent event_up; | 324 NativeWebKeyboardEvent event_up; |
286 BuildSimpleWebKeyEvent( | 325 BuildSimpleWebKeyEvent( |
287 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, | 326 WebKit::WebInputEvent::KeyUp, |
| 327 keyCode, |
| 328 nativeKeyCode, |
| 329 control, |
| 330 shift, |
| 331 alt, |
| 332 command, |
288 &event_up); | 333 &event_up); |
289 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); | 334 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
290 } | 335 } |
291 | 336 |
292 namespace internal { | 337 namespace internal { |
293 | 338 |
294 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) | 339 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) |
295 : render_view_host_(web_contents->GetRenderViewHost()) { | 340 : render_view_host_(web_contents->GetRenderViewHost()) { |
296 } | 341 } |
297 | 342 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 // The queue should not be empty, unless we were quit because of a timeout. | 584 // The queue should not be empty, unless we were quit because of a timeout. |
540 if (message_queue_.empty()) | 585 if (message_queue_.empty()) |
541 return false; | 586 return false; |
542 if (message) | 587 if (message) |
543 *message = message_queue_.front(); | 588 *message = message_queue_.front(); |
544 message_queue_.pop(); | 589 message_queue_.pop(); |
545 return true; | 590 return true; |
546 } | 591 } |
547 | 592 |
548 } // namespace content | 593 } // namespace content |
OLD | NEW |