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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 key, |
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 = key; |
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] = key; |
141 event->unmodifiedText[0] = key; | 155 event->unmodifiedText[0] = key; |
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; |
152 | 166 |
153 if (command) | 167 if (command) |
154 event->modifiers |= WebKit::WebInputEvent::MetaKey; | 168 event->modifiers |= WebKit::WebInputEvent::MetaKey; |
155 } | 169 } |
156 | 170 |
171 void SimulateKeyPress(WebContents* web_contents, | |
172 ui::KeyboardCode key, | |
173 int nativeKeyCode, | |
174 bool control, | |
175 bool shift, | |
176 bool alt, | |
177 bool command) { | |
Wez
2013/09/05 00:16:33
Why do you need this extra SimulateKeyPress overri
weitao
2013/09/05 07:49:17
Done.
| |
178 NativeWebKeyboardEvent event_down; | |
179 BuildSimpleWebKeyEvent( | |
180 WebKit::WebInputEvent::RawKeyDown, | |
181 key, | |
182 nativeKeyCode, | |
183 control, | |
184 shift, | |
185 alt, | |
186 command, | |
187 &event_down); | |
188 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); | |
189 | |
190 NativeWebKeyboardEvent char_event; | |
191 BuildSimpleWebKeyEvent( | |
192 WebKit::WebInputEvent::RawKeyDown, | |
Wez
2013/09/05 00:16:33
This should be Char.
weitao
2013/09/05 07:49:17
Done.
| |
193 key, | |
194 nativeKeyCode, | |
195 control, | |
196 shift, | |
197 alt, | |
198 command, | |
199 &char_event); | |
200 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); | |
201 | |
202 NativeWebKeyboardEvent event_up; | |
203 BuildSimpleWebKeyEvent( | |
204 WebKit::WebInputEvent::RawKeyDown, | |
Wez
2013/09/05 00:16:33
This should be KeyUp.
weitao
2013/09/05 07:49:17
Done.
| |
205 key, | |
206 nativeKeyCode, | |
207 control, | |
208 shift, | |
209 alt, | |
210 command, | |
211 &event_up); | |
212 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); | |
213 } | |
214 | |
157 void GetCookiesCallback(std::string* cookies_out, | 215 void GetCookiesCallback(std::string* cookies_out, |
158 base::WaitableEvent* event, | 216 base::WaitableEvent* event, |
159 const std::string& cookies) { | 217 const std::string& cookies) { |
160 *cookies_out = cookies; | 218 *cookies_out = cookies; |
161 event->Signal(); | 219 event->Signal(); |
162 } | 220 } |
163 | 221 |
164 void GetCookiesOnIOThread(const GURL& url, | 222 void GetCookiesOnIOThread(const GURL& url, |
165 net::URLRequestContextGetter* context_getter, | 223 net::URLRequestContextGetter* context_getter, |
166 base::WaitableEvent* event, | 224 base::WaitableEvent* event, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 mouse_event.y = point.y(); | 321 mouse_event.y = point.y(); |
264 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 322 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
265 } | 323 } |
266 | 324 |
267 void SimulateKeyPress(WebContents* web_contents, | 325 void SimulateKeyPress(WebContents* web_contents, |
268 ui::KeyboardCode key, | 326 ui::KeyboardCode key, |
269 bool control, | 327 bool control, |
270 bool shift, | 328 bool shift, |
271 bool alt, | 329 bool alt, |
272 bool command) { | 330 bool command) { |
273 NativeWebKeyboardEvent event_down; | 331 SimulateKeyPress(web_contents, key, 0, control, shift, alt, command); |
Wez
2013/09/05 00:16:33
0 -> NULL, or better still, InvalidKeyboardEventCo
weitao
2013/09/05 07:49:17
Done.
| |
274 BuildSimpleWebKeyEvent( | 332 } |
275 WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command, | |
276 &event_down); | |
277 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); | |
278 | 333 |
279 NativeWebKeyboardEvent char_event; | 334 void SimulateKeyPress(WebContents* web_contents, |
280 BuildSimpleWebKeyEvent( | 335 ui::KeyboardCode key, |
281 WebKit::WebInputEvent::Char, key, control, shift, alt, command, | 336 const char* code, |
282 &char_event); | 337 bool control, |
283 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); | 338 bool shift, |
284 | 339 bool alt, |
285 NativeWebKeyboardEvent event_up; | 340 bool command) { |
286 BuildSimpleWebKeyEvent( | 341 int nativeKeyCode = CodeToNativeKeycode(code); |
287 WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command, | 342 SimulateKeyPress(web_contents, |
288 &event_up); | 343 key, |
289 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); | 344 nativeKeyCode, |
345 control, | |
346 shift, | |
347 alt, | |
348 command); | |
290 } | 349 } |
291 | 350 |
292 namespace internal { | 351 namespace internal { |
293 | 352 |
294 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) | 353 ToRenderViewHost::ToRenderViewHost(WebContents* web_contents) |
295 : render_view_host_(web_contents->GetRenderViewHost()) { | 354 : render_view_host_(web_contents->GetRenderViewHost()) { |
296 } | 355 } |
297 | 356 |
298 ToRenderViewHost::ToRenderViewHost(RenderViewHost* render_view_host) | 357 ToRenderViewHost::ToRenderViewHost(RenderViewHost* render_view_host) |
299 : render_view_host_(render_view_host) { | 358 : render_view_host_(render_view_host) { |
(...skipping 239 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. | 598 // The queue should not be empty, unless we were quit because of a timeout. |
540 if (message_queue_.empty()) | 599 if (message_queue_.empty()) |
541 return false; | 600 return false; |
542 if (message) | 601 if (message) |
543 *message = message_queue_.front(); | 602 *message = message_queue_.front(); |
544 message_queue_.pop(); | 603 message_queue_.pop(); |
545 return true; | 604 return true; |
546 } | 605 } |
547 | 606 |
548 } // namespace content | 607 } // namespace content |
OLD | NEW |