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

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

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/public/test/layouttest_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); 111 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
112 result->reset(reader.ReadToValue(json)); 112 result->reset(reader.ReadToValue(json));
113 if (!result->get()) { 113 if (!result->get()) {
114 DLOG(ERROR) << reader.GetErrorMessage(); 114 DLOG(ERROR) << reader.GetErrorMessage();
115 return false; 115 return false;
116 } 116 }
117 117
118 return true; 118 return true;
119 } 119 }
120 120
121 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, 121 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type,
122 ui::KeyboardCode key_code, 122 ui::KeyboardCode key_code,
123 int native_key_code, 123 int native_key_code,
124 int modifiers, 124 int modifiers,
125 NativeWebKeyboardEvent* event) { 125 NativeWebKeyboardEvent* event) {
126 event->nativeKeyCode = native_key_code; 126 event->nativeKeyCode = native_key_code;
127 event->windowsKeyCode = key_code; 127 event->windowsKeyCode = key_code;
128 event->setKeyIdentifierFromWindowsKeyCode(); 128 event->setKeyIdentifierFromWindowsKeyCode();
129 event->type = type; 129 event->type = type;
130 event->modifiers = modifiers; 130 event->modifiers = modifiers;
131 event->isSystemKey = false; 131 event->isSystemKey = false;
132 event->timeStampSeconds = base::Time::Now().ToDoubleT(); 132 event->timeStampSeconds = base::Time::Now().ToDoubleT();
133 event->skip_in_browser = true; 133 event->skip_in_browser = true;
134 134
135 if (type == WebKit::WebInputEvent::Char || 135 if (type == blink::WebInputEvent::Char ||
136 type == WebKit::WebInputEvent::RawKeyDown) { 136 type == blink::WebInputEvent::RawKeyDown) {
137 event->text[0] = key_code; 137 event->text[0] = key_code;
138 event->unmodifiedText[0] = key_code; 138 event->unmodifiedText[0] = key_code;
139 } 139 }
140 } 140 }
141 141
142 void InjectRawKeyEvent(WebContents* web_contents, 142 void InjectRawKeyEvent(WebContents* web_contents,
143 WebKit::WebInputEvent::Type type, 143 blink::WebInputEvent::Type type,
144 ui::KeyboardCode key_code, 144 ui::KeyboardCode key_code,
145 int native_key_code, 145 int native_key_code,
146 int modifiers) { 146 int modifiers) {
147 NativeWebKeyboardEvent event; 147 NativeWebKeyboardEvent event;
148 BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event); 148 BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event);
149 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event); 149 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event);
150 } 150 }
151 151
152 void GetCookiesCallback(std::string* cookies_out, 152 void GetCookiesCallback(std::string* cookies_out,
153 base::WaitableEvent* event, 153 base::WaitableEvent* event,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 RenderProcessHost* rph = web_contents->GetRenderProcessHost(); 215 RenderProcessHost* rph = web_contents->GetRenderProcessHost();
216 WindowedNotificationObserver observer( 216 WindowedNotificationObserver observer(
217 NOTIFICATION_RENDERER_PROCESS_CLOSED, 217 NOTIFICATION_RENDERER_PROCESS_CLOSED,
218 Source<RenderProcessHost>(rph)); 218 Source<RenderProcessHost>(rph));
219 base::KillProcess(rph->GetHandle(), 0, false); 219 base::KillProcess(rph->GetHandle(), 0, false);
220 observer.Wait(); 220 observer.Wait();
221 } 221 }
222 222
223 void SimulateMouseClick(WebContents* web_contents, 223 void SimulateMouseClick(WebContents* web_contents,
224 int modifiers, 224 int modifiers,
225 WebKit::WebMouseEvent::Button button) { 225 blink::WebMouseEvent::Button button) {
226 int x = web_contents->GetView()->GetContainerSize().width() / 2; 226 int x = web_contents->GetView()->GetContainerSize().width() / 2;
227 int y = web_contents->GetView()->GetContainerSize().height() / 2; 227 int y = web_contents->GetView()->GetContainerSize().height() / 2;
228 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y)); 228 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y));
229 } 229 }
230 230
231 void SimulateMouseClickAt(WebContents* web_contents, 231 void SimulateMouseClickAt(WebContents* web_contents,
232 int modifiers, 232 int modifiers,
233 WebKit::WebMouseEvent::Button button, 233 blink::WebMouseEvent::Button button,
234 const gfx::Point& point) { 234 const gfx::Point& point) {
235 WebKit::WebMouseEvent mouse_event; 235 blink::WebMouseEvent mouse_event;
236 mouse_event.type = WebKit::WebInputEvent::MouseDown; 236 mouse_event.type = blink::WebInputEvent::MouseDown;
237 mouse_event.button = button; 237 mouse_event.button = button;
238 mouse_event.x = point.x(); 238 mouse_event.x = point.x();
239 mouse_event.y = point.y(); 239 mouse_event.y = point.y();
240 mouse_event.modifiers = modifiers; 240 mouse_event.modifiers = modifiers;
241 // Mac needs globalX/globalY for events to plugins. 241 // Mac needs globalX/globalY for events to plugins.
242 gfx::Rect offset; 242 gfx::Rect offset;
243 web_contents->GetView()->GetContainerBounds(&offset); 243 web_contents->GetView()->GetContainerBounds(&offset);
244 mouse_event.globalX = point.x() + offset.x(); 244 mouse_event.globalX = point.x() + offset.x();
245 mouse_event.globalY = point.y() + offset.y(); 245 mouse_event.globalY = point.y() + offset.y();
246 mouse_event.clickCount = 1; 246 mouse_event.clickCount = 1;
247 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 247 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
248 mouse_event.type = WebKit::WebInputEvent::MouseUp; 248 mouse_event.type = blink::WebInputEvent::MouseUp;
249 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 249 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
250 } 250 }
251 251
252 void SimulateMouseEvent(WebContents* web_contents, 252 void SimulateMouseEvent(WebContents* web_contents,
253 WebKit::WebInputEvent::Type type, 253 blink::WebInputEvent::Type type,
254 const gfx::Point& point) { 254 const gfx::Point& point) {
255 WebKit::WebMouseEvent mouse_event; 255 blink::WebMouseEvent mouse_event;
256 mouse_event.type = type; 256 mouse_event.type = type;
257 mouse_event.x = point.x(); 257 mouse_event.x = point.x();
258 mouse_event.y = point.y(); 258 mouse_event.y = point.y();
259 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 259 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
260 } 260 }
261 261
262 void SimulateKeyPress(WebContents* web_contents, 262 void SimulateKeyPress(WebContents* web_contents,
263 ui::KeyboardCode key_code, 263 ui::KeyboardCode key_code,
264 bool control, 264 bool control,
265 bool shift, 265 bool shift,
(...skipping 11 matching lines...) Expand all
277 bool alt, 277 bool alt,
278 bool command) { 278 bool command) {
279 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); 279 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance();
280 int native_key_code = key_converter->CodeToNativeKeycode(code); 280 int native_key_code = key_converter->CodeToNativeKeycode(code);
281 281
282 int modifiers = 0; 282 int modifiers = 0;
283 283
284 // The order of these key down events shouldn't matter for our simulation. 284 // The order of these key down events shouldn't matter for our simulation.
285 // For our simulation we can use either the left keys or the right keys. 285 // For our simulation we can use either the left keys or the right keys.
286 if (control) { 286 if (control) {
287 modifiers |= WebKit::WebInputEvent::ControlKey; 287 modifiers |= blink::WebInputEvent::ControlKey;
288 InjectRawKeyEvent( 288 InjectRawKeyEvent(
289 web_contents, 289 web_contents,
290 WebKit::WebInputEvent::RawKeyDown, 290 blink::WebInputEvent::RawKeyDown,
291 ui::VKEY_CONTROL, 291 ui::VKEY_CONTROL,
292 key_converter->CodeToNativeKeycode("ControlLeft"), 292 key_converter->CodeToNativeKeycode("ControlLeft"),
293 modifiers); 293 modifiers);
294 } 294 }
295 295
296 if (shift) { 296 if (shift) {
297 modifiers |= WebKit::WebInputEvent::ShiftKey; 297 modifiers |= blink::WebInputEvent::ShiftKey;
298 InjectRawKeyEvent( 298 InjectRawKeyEvent(
299 web_contents, 299 web_contents,
300 WebKit::WebInputEvent::RawKeyDown, 300 blink::WebInputEvent::RawKeyDown,
301 ui::VKEY_SHIFT, 301 ui::VKEY_SHIFT,
302 key_converter->CodeToNativeKeycode("ShiftLeft"), 302 key_converter->CodeToNativeKeycode("ShiftLeft"),
303 modifiers); 303 modifiers);
304 } 304 }
305 305
306 if (alt) { 306 if (alt) {
307 modifiers |= WebKit::WebInputEvent::AltKey; 307 modifiers |= blink::WebInputEvent::AltKey;
308 InjectRawKeyEvent( 308 InjectRawKeyEvent(
309 web_contents, 309 web_contents,
310 WebKit::WebInputEvent::RawKeyDown, 310 blink::WebInputEvent::RawKeyDown,
311 ui::VKEY_MENU, 311 ui::VKEY_MENU,
312 key_converter->CodeToNativeKeycode("AltLeft"), 312 key_converter->CodeToNativeKeycode("AltLeft"),
313 modifiers); 313 modifiers);
314 } 314 }
315 315
316 if (command) { 316 if (command) {
317 modifiers |= WebKit::WebInputEvent::MetaKey; 317 modifiers |= blink::WebInputEvent::MetaKey;
318 InjectRawKeyEvent( 318 InjectRawKeyEvent(
319 web_contents, 319 web_contents,
320 WebKit::WebInputEvent::RawKeyDown, 320 blink::WebInputEvent::RawKeyDown,
321 ui::VKEY_COMMAND, 321 ui::VKEY_COMMAND,
322 key_converter->CodeToNativeKeycode("OSLeft"), 322 key_converter->CodeToNativeKeycode("OSLeft"),
323 modifiers); 323 modifiers);
324 } 324 }
325 325
326 InjectRawKeyEvent( 326 InjectRawKeyEvent(
327 web_contents, 327 web_contents,
328 WebKit::WebInputEvent::RawKeyDown, 328 blink::WebInputEvent::RawKeyDown,
329 key_code, 329 key_code,
330 native_key_code, 330 native_key_code,
331 modifiers); 331 modifiers);
332 332
333 InjectRawKeyEvent( 333 InjectRawKeyEvent(
334 web_contents, 334 web_contents,
335 WebKit::WebInputEvent::Char, 335 blink::WebInputEvent::Char,
336 key_code, 336 key_code,
337 native_key_code, 337 native_key_code,
338 modifiers); 338 modifiers);
339 339
340 InjectRawKeyEvent( 340 InjectRawKeyEvent(
341 web_contents, 341 web_contents,
342 WebKit::WebInputEvent::KeyUp, 342 blink::WebInputEvent::KeyUp,
343 key_code, 343 key_code,
344 native_key_code, 344 native_key_code,
345 modifiers); 345 modifiers);
346 346
347 // The order of these key releases shouldn't matter for our simulation. 347 // The order of these key releases shouldn't matter for our simulation.
348 if (control) { 348 if (control) {
349 modifiers &= ~WebKit::WebInputEvent::ControlKey; 349 modifiers &= ~blink::WebInputEvent::ControlKey;
350 InjectRawKeyEvent( 350 InjectRawKeyEvent(
351 web_contents, 351 web_contents,
352 WebKit::WebInputEvent::KeyUp, 352 blink::WebInputEvent::KeyUp,
353 ui::VKEY_CONTROL, 353 ui::VKEY_CONTROL,
354 key_converter->CodeToNativeKeycode("ControlLeft"), 354 key_converter->CodeToNativeKeycode("ControlLeft"),
355 modifiers); 355 modifiers);
356 } 356 }
357 357
358 if (shift) { 358 if (shift) {
359 modifiers &= ~WebKit::WebInputEvent::ShiftKey; 359 modifiers &= ~blink::WebInputEvent::ShiftKey;
360 InjectRawKeyEvent( 360 InjectRawKeyEvent(
361 web_contents, 361 web_contents,
362 WebKit::WebInputEvent::KeyUp, 362 blink::WebInputEvent::KeyUp,
363 ui::VKEY_SHIFT, 363 ui::VKEY_SHIFT,
364 key_converter->CodeToNativeKeycode("ShiftLeft"), 364 key_converter->CodeToNativeKeycode("ShiftLeft"),
365 modifiers); 365 modifiers);
366 } 366 }
367 367
368 if (alt) { 368 if (alt) {
369 modifiers &= ~WebKit::WebInputEvent::AltKey; 369 modifiers &= ~blink::WebInputEvent::AltKey;
370 InjectRawKeyEvent( 370 InjectRawKeyEvent(
371 web_contents, 371 web_contents,
372 WebKit::WebInputEvent::KeyUp, 372 blink::WebInputEvent::KeyUp,
373 ui::VKEY_MENU, 373 ui::VKEY_MENU,
374 key_converter->CodeToNativeKeycode("AltLeft"), 374 key_converter->CodeToNativeKeycode("AltLeft"),
375 modifiers); 375 modifiers);
376 } 376 }
377 377
378 if (command) { 378 if (command) {
379 modifiers &= ~WebKit::WebInputEvent::MetaKey; 379 modifiers &= ~blink::WebInputEvent::MetaKey;
380 InjectRawKeyEvent( 380 InjectRawKeyEvent(
381 web_contents, 381 web_contents,
382 WebKit::WebInputEvent::KeyUp, 382 blink::WebInputEvent::KeyUp,
383 ui::VKEY_COMMAND, 383 ui::VKEY_COMMAND,
384 key_converter->CodeToNativeKeycode("OSLeft"), 384 key_converter->CodeToNativeKeycode("OSLeft"),
385 modifiers); 385 modifiers);
386 } 386 }
387 387
388 ASSERT_EQ(modifiers, 0); 388 ASSERT_EQ(modifiers, 0);
389 } 389 }
390 390
391 namespace internal { 391 namespace internal {
392 392
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 // The queue should not be empty, unless we were quit because of a timeout. 634 // The queue should not be empty, unless we were quit because of a timeout.
635 if (message_queue_.empty()) 635 if (message_queue_.empty())
636 return false; 636 return false;
637 if (message) 637 if (message)
638 *message = message_queue_.front(); 638 *message = message_queue_.front();
639 message_queue_.pop(); 639 message_queue_.pop();
640 return true; 640 return true;
641 } 641 }
642 642
643 } // namespace content 643 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/public/test/layouttest_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698