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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 web_contents, key_code, NULL, control, shift, alt, command); | 315 web_contents, key_code, NULL, control, shift, alt, command); |
316 } | 316 } |
317 | 317 |
318 void SimulateKeyPressWithCode(WebContents* web_contents, | 318 void SimulateKeyPressWithCode(WebContents* web_contents, |
319 ui::KeyboardCode key_code, | 319 ui::KeyboardCode key_code, |
320 const char* code, | 320 const char* code, |
321 bool control, | 321 bool control, |
322 bool shift, | 322 bool shift, |
323 bool alt, | 323 bool alt, |
324 bool command) { | 324 bool command) { |
325 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); | 325 int native_key_code = ui::KeycodeConverter::CodeToNativeKeycode(code); |
326 int native_key_code = key_converter->CodeToNativeKeycode(code); | |
327 | 326 |
328 int modifiers = 0; | 327 int modifiers = 0; |
329 | 328 |
330 // The order of these key down events shouldn't matter for our simulation. | 329 // The order of these key down events shouldn't matter for our simulation. |
331 // For our simulation we can use either the left keys or the right keys. | 330 // For our simulation we can use either the left keys or the right keys. |
332 if (control) { | 331 if (control) { |
333 modifiers |= blink::WebInputEvent::ControlKey; | 332 modifiers |= blink::WebInputEvent::ControlKey; |
334 InjectRawKeyEvent( | 333 InjectRawKeyEvent(web_contents, |
335 web_contents, | 334 blink::WebInputEvent::RawKeyDown, |
336 blink::WebInputEvent::RawKeyDown, | 335 ui::VKEY_CONTROL, |
337 ui::VKEY_CONTROL, | 336 ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"), |
338 key_converter->CodeToNativeKeycode("ControlLeft"), | 337 modifiers); |
339 modifiers); | |
340 } | 338 } |
341 | 339 |
342 if (shift) { | 340 if (shift) { |
343 modifiers |= blink::WebInputEvent::ShiftKey; | 341 modifiers |= blink::WebInputEvent::ShiftKey; |
344 InjectRawKeyEvent( | 342 InjectRawKeyEvent(web_contents, |
345 web_contents, | 343 blink::WebInputEvent::RawKeyDown, |
346 blink::WebInputEvent::RawKeyDown, | 344 ui::VKEY_SHIFT, |
347 ui::VKEY_SHIFT, | 345 ui::KeycodeConverter::CodeToNativeKeycode("ShiftLeft"), |
348 key_converter->CodeToNativeKeycode("ShiftLeft"), | 346 modifiers); |
349 modifiers); | |
350 } | 347 } |
351 | 348 |
352 if (alt) { | 349 if (alt) { |
353 modifiers |= blink::WebInputEvent::AltKey; | 350 modifiers |= blink::WebInputEvent::AltKey; |
354 InjectRawKeyEvent( | 351 InjectRawKeyEvent(web_contents, |
355 web_contents, | 352 blink::WebInputEvent::RawKeyDown, |
356 blink::WebInputEvent::RawKeyDown, | 353 ui::VKEY_MENU, |
357 ui::VKEY_MENU, | 354 ui::KeycodeConverter::CodeToNativeKeycode("AltLeft"), |
358 key_converter->CodeToNativeKeycode("AltLeft"), | 355 modifiers); |
359 modifiers); | |
360 } | 356 } |
361 | 357 |
362 if (command) { | 358 if (command) { |
363 modifiers |= blink::WebInputEvent::MetaKey; | 359 modifiers |= blink::WebInputEvent::MetaKey; |
364 InjectRawKeyEvent( | 360 InjectRawKeyEvent(web_contents, |
365 web_contents, | 361 blink::WebInputEvent::RawKeyDown, |
366 blink::WebInputEvent::RawKeyDown, | 362 ui::VKEY_COMMAND, |
367 ui::VKEY_COMMAND, | 363 ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"), |
368 key_converter->CodeToNativeKeycode("OSLeft"), | 364 modifiers); |
369 modifiers); | |
370 } | 365 } |
371 | 366 |
372 InjectRawKeyEvent( | 367 InjectRawKeyEvent( |
373 web_contents, | 368 web_contents, |
374 blink::WebInputEvent::RawKeyDown, | 369 blink::WebInputEvent::RawKeyDown, |
375 key_code, | 370 key_code, |
376 native_key_code, | 371 native_key_code, |
377 modifiers); | 372 modifiers); |
378 | 373 |
379 InjectRawKeyEvent( | 374 InjectRawKeyEvent( |
380 web_contents, | 375 web_contents, |
381 blink::WebInputEvent::Char, | 376 blink::WebInputEvent::Char, |
382 key_code, | 377 key_code, |
383 native_key_code, | 378 native_key_code, |
384 modifiers); | 379 modifiers); |
385 | 380 |
386 InjectRawKeyEvent( | 381 InjectRawKeyEvent( |
387 web_contents, | 382 web_contents, |
388 blink::WebInputEvent::KeyUp, | 383 blink::WebInputEvent::KeyUp, |
389 key_code, | 384 key_code, |
390 native_key_code, | 385 native_key_code, |
391 modifiers); | 386 modifiers); |
392 | 387 |
393 // The order of these key releases shouldn't matter for our simulation. | 388 // The order of these key releases shouldn't matter for our simulation. |
394 if (control) { | 389 if (control) { |
395 modifiers &= ~blink::WebInputEvent::ControlKey; | 390 modifiers &= ~blink::WebInputEvent::ControlKey; |
396 InjectRawKeyEvent( | 391 InjectRawKeyEvent(web_contents, |
397 web_contents, | 392 blink::WebInputEvent::KeyUp, |
398 blink::WebInputEvent::KeyUp, | 393 ui::VKEY_CONTROL, |
399 ui::VKEY_CONTROL, | 394 ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"), |
400 key_converter->CodeToNativeKeycode("ControlLeft"), | 395 modifiers); |
401 modifiers); | |
402 } | 396 } |
403 | 397 |
404 if (shift) { | 398 if (shift) { |
405 modifiers &= ~blink::WebInputEvent::ShiftKey; | 399 modifiers &= ~blink::WebInputEvent::ShiftKey; |
406 InjectRawKeyEvent( | 400 InjectRawKeyEvent(web_contents, |
407 web_contents, | 401 blink::WebInputEvent::KeyUp, |
408 blink::WebInputEvent::KeyUp, | 402 ui::VKEY_SHIFT, |
409 ui::VKEY_SHIFT, | 403 ui::KeycodeConverter::CodeToNativeKeycode("ShiftLeft"), |
410 key_converter->CodeToNativeKeycode("ShiftLeft"), | 404 modifiers); |
411 modifiers); | |
412 } | 405 } |
413 | 406 |
414 if (alt) { | 407 if (alt) { |
415 modifiers &= ~blink::WebInputEvent::AltKey; | 408 modifiers &= ~blink::WebInputEvent::AltKey; |
416 InjectRawKeyEvent( | 409 InjectRawKeyEvent(web_contents, |
417 web_contents, | 410 blink::WebInputEvent::KeyUp, |
418 blink::WebInputEvent::KeyUp, | 411 ui::VKEY_MENU, |
419 ui::VKEY_MENU, | 412 ui::KeycodeConverter::CodeToNativeKeycode("AltLeft"), |
420 key_converter->CodeToNativeKeycode("AltLeft"), | 413 modifiers); |
421 modifiers); | |
422 } | 414 } |
423 | 415 |
424 if (command) { | 416 if (command) { |
425 modifiers &= ~blink::WebInputEvent::MetaKey; | 417 modifiers &= ~blink::WebInputEvent::MetaKey; |
426 InjectRawKeyEvent( | 418 InjectRawKeyEvent(web_contents, |
427 web_contents, | 419 blink::WebInputEvent::KeyUp, |
428 blink::WebInputEvent::KeyUp, | 420 ui::VKEY_COMMAND, |
429 ui::VKEY_COMMAND, | 421 ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"), |
430 key_converter->CodeToNativeKeycode("OSLeft"), | 422 modifiers); |
431 modifiers); | |
432 } | 423 } |
433 | 424 |
434 ASSERT_EQ(modifiers, 0); | 425 ASSERT_EQ(modifiers, 0); |
435 } | 426 } |
436 | 427 |
437 namespace internal { | 428 namespace internal { |
438 | 429 |
439 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) | 430 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) |
440 : render_frame_host_(web_contents->GetMainFrame()) { | 431 : render_frame_host_(web_contents->GetMainFrame()) { |
441 } | 432 } |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 } | 726 } |
736 // The queue should not be empty, unless we were quit because of a timeout. | 727 // The queue should not be empty, unless we were quit because of a timeout. |
737 if (message_queue_.empty()) | 728 if (message_queue_.empty()) |
738 return false; | 729 return false; |
739 *message = message_queue_.front(); | 730 *message = message_queue_.front(); |
740 message_queue_.pop(); | 731 message_queue_.pop(); |
741 return true; | 732 return true; |
742 } | 733 } |
743 | 734 |
744 } // namespace content | 735 } // namespace content |
OLD | NEW |