| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 *result = reader.ReadToValue(json); | 209 *result = reader.ReadToValue(json); |
| 210 if (!*result) { | 210 if (!*result) { |
| 211 DLOG(ERROR) << reader.GetErrorMessage(); | 211 DLOG(ERROR) << reader.GetErrorMessage(); |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 | 214 |
| 215 return true; | 215 return true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, | 218 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, |
| 219 ui::DomKey key, |
| 220 ui::DomCode code, |
| 219 ui::KeyboardCode key_code, | 221 ui::KeyboardCode key_code, |
| 220 int native_key_code, | |
| 221 int modifiers, | 222 int modifiers, |
| 222 NativeWebKeyboardEvent* event) { | 223 NativeWebKeyboardEvent* event) { |
| 223 event->nativeKeyCode = native_key_code; | 224 event->domKey = key; |
| 225 event->domCode = static_cast<int>(code); |
| 226 event->nativeKeyCode = ui::KeycodeConverter::DomCodeToNativeKeycode(code); |
| 224 event->windowsKeyCode = key_code; | 227 event->windowsKeyCode = key_code; |
| 225 event->setKeyIdentifierFromWindowsKeyCode(); | 228 event->setKeyIdentifierFromWindowsKeyCode(); |
| 226 event->type = type; | 229 event->type = type; |
| 227 event->modifiers = modifiers; | 230 event->modifiers = modifiers; |
| 228 event->isSystemKey = false; | 231 event->isSystemKey = false; |
| 229 event->timeStampSeconds = | 232 event->timeStampSeconds = |
| 230 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 233 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 231 event->skip_in_browser = true; | 234 event->skip_in_browser = true; |
| 232 | 235 |
| 233 if (type == blink::WebInputEvent::Char || | 236 if (type == blink::WebInputEvent::Char || |
| 234 type == blink::WebInputEvent::RawKeyDown) { | 237 type == blink::WebInputEvent::RawKeyDown) { |
| 235 event->text[0] = key_code; | 238 event->text[0] = key_code; |
| 236 event->unmodifiedText[0] = key_code; | 239 event->unmodifiedText[0] = key_code; |
| 237 } | 240 } |
| 238 } | 241 } |
| 239 | 242 |
| 240 void InjectRawKeyEvent(WebContents* web_contents, | 243 void InjectRawKeyEvent(WebContents* web_contents, |
| 241 blink::WebInputEvent::Type type, | 244 blink::WebInputEvent::Type type, |
| 245 ui::DomKey key, |
| 246 ui::DomCode code, |
| 242 ui::KeyboardCode key_code, | 247 ui::KeyboardCode key_code, |
| 243 int native_key_code, | |
| 244 int modifiers) { | 248 int modifiers) { |
| 245 NativeWebKeyboardEvent event; | 249 NativeWebKeyboardEvent event; |
| 246 BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event); | 250 BuildSimpleWebKeyEvent(type, key, code, key_code, modifiers, &event); |
| 247 WebContentsImpl* web_contents_impl = | 251 WebContentsImpl* web_contents_impl = |
| 248 static_cast<WebContentsImpl*>(web_contents); | 252 static_cast<WebContentsImpl*>(web_contents); |
| 249 RenderWidgetHostImpl* main_frame_rwh = | 253 RenderWidgetHostImpl* main_frame_rwh = |
| 250 web_contents_impl->GetMainFrame()->GetRenderWidgetHost(); | 254 web_contents_impl->GetMainFrame()->GetRenderWidgetHost(); |
| 251 web_contents_impl->GetFocusedRenderWidgetHost(main_frame_rwh) | 255 web_contents_impl->GetFocusedRenderWidgetHost(main_frame_rwh) |
| 252 ->ForwardKeyboardEvent(event); | 256 ->ForwardKeyboardEvent(event); |
| 253 } | 257 } |
| 254 | 258 |
| 255 void GetCookiesCallback(std::string* cookies_out, | 259 void GetCookiesCallback(std::string* cookies_out, |
| 256 base::WaitableEvent* event, | 260 base::WaitableEvent* event, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 #if defined(USE_AURA) | 587 #if defined(USE_AURA) |
| 584 void SimulateTouchPressAt(WebContents* web_contents, const gfx::Point& point) { | 588 void SimulateTouchPressAt(WebContents* web_contents, const gfx::Point& point) { |
| 585 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, point, 0, base::TimeDelta()); | 589 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, point, 0, base::TimeDelta()); |
| 586 static_cast<RenderWidgetHostViewAura*>( | 590 static_cast<RenderWidgetHostViewAura*>( |
| 587 web_contents->GetRenderWidgetHostView()) | 591 web_contents->GetRenderWidgetHostView()) |
| 588 ->OnTouchEvent(&touch); | 592 ->OnTouchEvent(&touch); |
| 589 } | 593 } |
| 590 #endif | 594 #endif |
| 591 | 595 |
| 592 void SimulateKeyPress(WebContents* web_contents, | 596 void SimulateKeyPress(WebContents* web_contents, |
| 597 ui::DomKey key, |
| 598 ui::DomCode code, |
| 593 ui::KeyboardCode key_code, | 599 ui::KeyboardCode key_code, |
| 594 bool control, | 600 bool control, |
| 595 bool shift, | 601 bool shift, |
| 596 bool alt, | 602 bool alt, |
| 597 bool command) { | 603 bool command) { |
| 598 SimulateKeyPressWithCode( | |
| 599 web_contents, key_code, std::string(), control, shift, alt, command); | |
| 600 } | |
| 601 | |
| 602 void SimulateKeyPressWithCode(WebContents* web_contents, | |
| 603 ui::KeyboardCode key_code, | |
| 604 const std::string& code, | |
| 605 bool control, | |
| 606 bool shift, | |
| 607 bool alt, | |
| 608 bool command) { | |
| 609 int native_key_code = ui::KeycodeConverter::DomCodeToNativeKeycode( | |
| 610 ui::KeycodeConverter::CodeStringToDomCode(code)); | |
| 611 | |
| 612 int modifiers = 0; | 604 int modifiers = 0; |
| 613 | 605 |
| 614 // The order of these key down events shouldn't matter for our simulation. | 606 // The order of these key down events shouldn't matter for our simulation. |
| 615 // For our simulation we can use either the left keys or the right keys. | 607 // For our simulation we can use either the left keys or the right keys. |
| 616 if (control) { | 608 if (control) { |
| 617 modifiers |= blink::WebInputEvent::ControlKey; | 609 modifiers |= blink::WebInputEvent::ControlKey; |
| 618 InjectRawKeyEvent( | 610 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, |
| 619 web_contents, blink::WebInputEvent::RawKeyDown, ui::VKEY_CONTROL, | 611 ui::DomKey::CONTROL, ui::DomCode::CONTROL_LEFT, |
| 620 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), | 612 ui::VKEY_CONTROL, modifiers); |
| 621 modifiers); | |
| 622 } | 613 } |
| 623 | 614 |
| 624 if (shift) { | 615 if (shift) { |
| 625 modifiers |= blink::WebInputEvent::ShiftKey; | 616 modifiers |= blink::WebInputEvent::ShiftKey; |
| 626 InjectRawKeyEvent( | 617 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, |
| 627 web_contents, blink::WebInputEvent::RawKeyDown, ui::VKEY_SHIFT, | 618 ui::DomKey::SHIFT, ui::DomCode::SHIFT_LEFT, |
| 628 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::SHIFT_LEFT), | 619 ui::VKEY_SHIFT, modifiers); |
| 629 modifiers); | |
| 630 } | 620 } |
| 631 | 621 |
| 632 if (alt) { | 622 if (alt) { |
| 633 modifiers |= blink::WebInputEvent::AltKey; | 623 modifiers |= blink::WebInputEvent::AltKey; |
| 634 InjectRawKeyEvent( | 624 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, |
| 635 web_contents, blink::WebInputEvent::RawKeyDown, ui::VKEY_MENU, | 625 ui::DomKey::ALT, ui::DomCode::ALT_LEFT, ui::VKEY_MENU, |
| 636 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::ALT_LEFT), | 626 modifiers); |
| 637 modifiers); | |
| 638 } | 627 } |
| 639 | 628 |
| 640 if (command) { | 629 if (command) { |
| 641 modifiers |= blink::WebInputEvent::MetaKey; | 630 modifiers |= blink::WebInputEvent::MetaKey; |
| 642 InjectRawKeyEvent( | 631 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, |
| 643 web_contents, blink::WebInputEvent::RawKeyDown, ui::VKEY_COMMAND, | 632 ui::DomKey::META, ui::DomCode::META_LEFT, |
| 644 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::META_LEFT), | 633 ui::VKEY_COMMAND, modifiers); |
| 645 modifiers); | |
| 646 } | 634 } |
| 647 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, key_code, | 635 InjectRawKeyEvent(web_contents, blink::WebInputEvent::RawKeyDown, key, code, |
| 648 native_key_code, modifiers); | 636 key_code, modifiers); |
| 649 | 637 |
| 650 InjectRawKeyEvent(web_contents, blink::WebInputEvent::Char, key_code, | 638 InjectRawKeyEvent(web_contents, blink::WebInputEvent::Char, key, code, |
| 651 native_key_code, modifiers); | 639 key_code, modifiers); |
| 652 | 640 |
| 653 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, key_code, | 641 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, key, code, |
| 654 native_key_code, modifiers); | 642 key_code, modifiers); |
| 655 | 643 |
| 656 // The order of these key releases shouldn't matter for our simulation. | 644 // The order of these key releases shouldn't matter for our simulation. |
| 657 if (control) { | 645 if (control) { |
| 658 modifiers &= ~blink::WebInputEvent::ControlKey; | 646 modifiers &= ~blink::WebInputEvent::ControlKey; |
| 659 InjectRawKeyEvent( | 647 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, |
| 660 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL, | 648 ui::DomKey::CONTROL, ui::DomCode::CONTROL_LEFT, |
| 661 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), | 649 ui::VKEY_CONTROL, modifiers); |
| 662 modifiers); | |
| 663 } | 650 } |
| 664 | 651 |
| 665 if (shift) { | 652 if (shift) { |
| 666 modifiers &= ~blink::WebInputEvent::ShiftKey; | 653 modifiers &= ~blink::WebInputEvent::ShiftKey; |
| 667 InjectRawKeyEvent( | 654 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, |
| 668 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_SHIFT, | 655 ui::DomKey::SHIFT, ui::DomCode::SHIFT_LEFT, |
| 669 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::SHIFT_LEFT), | 656 ui::VKEY_SHIFT, modifiers); |
| 670 modifiers); | |
| 671 } | 657 } |
| 672 | 658 |
| 673 if (alt) { | 659 if (alt) { |
| 674 modifiers &= ~blink::WebInputEvent::AltKey; | 660 modifiers &= ~blink::WebInputEvent::AltKey; |
| 675 InjectRawKeyEvent( | 661 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, |
| 676 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_MENU, | 662 ui::DomKey::ALT, ui::DomCode::ALT_LEFT, ui::VKEY_MENU, |
| 677 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::ALT_LEFT), | 663 modifiers); |
| 678 modifiers); | |
| 679 } | 664 } |
| 680 | 665 |
| 681 if (command) { | 666 if (command) { |
| 682 modifiers &= ~blink::WebInputEvent::MetaKey; | 667 modifiers &= ~blink::WebInputEvent::MetaKey; |
| 683 InjectRawKeyEvent( | 668 InjectRawKeyEvent(web_contents, blink::WebInputEvent::KeyUp, |
| 684 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND, | 669 ui::DomKey::META, ui::DomCode::META_LEFT, |
| 685 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::META_LEFT), | 670 ui::VKEY_COMMAND, modifiers); |
| 686 modifiers); | |
| 687 } | 671 } |
| 688 | 672 |
| 689 ASSERT_EQ(modifiers, 0); | 673 ASSERT_EQ(modifiers, 0); |
| 690 } | 674 } |
| 691 | 675 |
| 692 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) | 676 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) |
| 693 : render_frame_host_(web_contents->GetMainFrame()) { | 677 : render_frame_host_(web_contents->GetMainFrame()) { |
| 694 } | 678 } |
| 695 | 679 |
| 696 ToRenderFrameHost::ToRenderFrameHost(RenderViewHost* render_view_host) | 680 ToRenderFrameHost::ToRenderFrameHost(RenderViewHost* render_view_host) |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1273 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1290 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) | 1274 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
| 1291 return ack_result_; | 1275 return ack_result_; |
| 1292 base::RunLoop run_loop; | 1276 base::RunLoop run_loop; |
| 1293 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1277 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
| 1294 run_loop.Run(); | 1278 run_loop.Run(); |
| 1295 return ack_result_; | 1279 return ack_result_; |
| 1296 } | 1280 } |
| 1297 | 1281 |
| 1298 } // namespace content | 1282 } // namespace content |
| OLD | NEW |