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/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const std::string& name) { | 90 const std::string& name) { |
91 bool success = false; | 91 bool success = false; |
92 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 92 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
93 caller_frame, | 93 caller_frame, |
94 "window.domAutomationController.send(" | 94 "window.domAutomationController.send(" |
95 " !!window.open('" + url.spec() + "', '" + name + "'));", | 95 " !!window.open('" + url.spec() + "', '" + name + "'));", |
96 &success)); | 96 &success)); |
97 EXPECT_TRUE(success); | 97 EXPECT_TRUE(success); |
98 } | 98 } |
99 | 99 |
| 100 // Helper function to generate a click on the given RenderWidgetHost. The |
| 101 // mouse event is forwarded directly to the RenderWidgetHost without any |
| 102 // hit-testing. |
| 103 void SimulateMouseClick(RenderWidgetHost* rwh, int x, int y) { |
| 104 blink::WebMouseEvent mouse_event; |
| 105 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 106 mouse_event.button = blink::WebPointerProperties::ButtonLeft; |
| 107 mouse_event.x = x; |
| 108 mouse_event.y = y; |
| 109 rwh->ForwardMouseEvent(mouse_event); |
| 110 } |
| 111 |
100 class RedirectNotificationObserver : public NotificationObserver { | 112 class RedirectNotificationObserver : public NotificationObserver { |
101 public: | 113 public: |
102 // Register to listen for notifications of the given type from either a | 114 // Register to listen for notifications of the given type from either a |
103 // specific source, or from all sources if |source| is | 115 // specific source, or from all sources if |source| is |
104 // NotificationService::AllSources(). | 116 // NotificationService::AllSources(). |
105 RedirectNotificationObserver(int notification_type, | 117 RedirectNotificationObserver(int notification_type, |
106 const NotificationSource& source); | 118 const NotificationSource& source); |
107 ~RedirectNotificationObserver() override; | 119 ~RedirectNotificationObserver() override; |
108 | 120 |
109 // Wait until the specified notification occurs. If the notification was | 121 // Wait until the specified notification occurs. If the notification was |
(...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3481 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), | 3493 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), |
3482 "focusInputField()", &result)); | 3494 "focusInputField()", &result)); |
3483 EXPECT_EQ(result, "input-focus"); | 3495 EXPECT_EQ(result, "input-focus"); |
3484 | 3496 |
3485 // The main frame should be focused. | 3497 // The main frame should be focused. |
3486 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 3498 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
3487 | 3499 |
3488 DOMMessageQueue msg_queue; | 3500 DOMMessageQueue msg_queue; |
3489 | 3501 |
3490 // Click on the cross-process subframe. | 3502 // Click on the cross-process subframe. |
3491 blink::WebMouseEvent mouse_event; | 3503 SimulateMouseClick( |
3492 mouse_event.type = blink::WebInputEvent::MouseDown; | 3504 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
3493 mouse_event.button = blink::WebPointerProperties::ButtonLeft; | |
3494 mouse_event.x = 1; | |
3495 mouse_event.y = 1; | |
3496 RenderWidgetHost* rwh_child = | |
3497 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(); | |
3498 rwh_child->ForwardMouseEvent(mouse_event); | |
3499 | 3505 |
3500 // Check that the main frame lost focus and fired blur event on the input | 3506 // Check that the main frame lost focus and fired blur event on the input |
3501 // text field. | 3507 // text field. |
3502 std::string status; | 3508 std::string status; |
3503 while (msg_queue.WaitForMessage(&status)) { | 3509 while (msg_queue.WaitForMessage(&status)) { |
3504 if (status == "\"input-blur\"") | 3510 if (status == "\"input-blur\"") |
3505 break; | 3511 break; |
3506 } | 3512 } |
3507 | 3513 |
3508 // The subframe should now be focused. | 3514 // The subframe should now be focused. |
3509 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); | 3515 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); |
3510 | 3516 |
3511 // Click on the root frame. | 3517 // Click on the root frame. |
3512 shell()->web_contents()->GetRenderViewHost()->GetWidget()->ForwardMouseEvent( | 3518 SimulateMouseClick( |
3513 mouse_event); | 3519 shell()->web_contents()->GetRenderViewHost()->GetWidget(), 1, 1); |
3514 | 3520 |
3515 // Check that the subframe lost focus and fired blur event on its | 3521 // Check that the subframe lost focus and fired blur event on its |
3516 // document's body. | 3522 // document's body. |
3517 while (msg_queue.WaitForMessage(&status)) { | 3523 while (msg_queue.WaitForMessage(&status)) { |
3518 if (status == "\"document-blur\"") | 3524 if (status == "\"document-blur\"") |
3519 break; | 3525 break; |
3520 } | 3526 } |
3521 | 3527 |
3522 // The root frame should be focused again. | 3528 // The root frame should be focused again. |
3523 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 3529 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3619 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 3625 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
3620 | 3626 |
3621 // Use new window to navigate main window. | 3627 // Use new window to navigate main window. |
3622 std::string script = | 3628 std::string script = |
3623 "window.opener.location.href = '" + cross_url.spec() + "'"; | 3629 "window.opener.location.href = '" + cross_url.spec() + "'"; |
3624 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 3630 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); |
3625 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 3631 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
3626 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 3632 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
3627 } | 3633 } |
3628 | 3634 |
| 3635 // Ensure that a cross-process subframe can receive keyboard events when in |
| 3636 // focus. |
| 3637 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3638 SubframeKeyboardEventRouting) { |
| 3639 GURL main_url(embedded_test_server()->GetURL( |
| 3640 "a.com", "/frame_tree/page_with_one_frame.html")); |
| 3641 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3642 |
| 3643 WebContentsImpl* web_contents = |
| 3644 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 3645 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 3646 |
| 3647 GURL frame_url( |
| 3648 embedded_test_server()->GetURL("b.com", "/page_with_input_field.html")); |
| 3649 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3650 EXPECT_TRUE(WaitForRenderFrameReady(root->child_at(0)->current_frame_host())); |
| 3651 |
| 3652 // Click on the subframe to focus it. |
| 3653 SimulateMouseClick( |
| 3654 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| 3655 |
| 3656 // Focus the input field in the subframe. The return value "input-focus" |
| 3657 // will be sent once the input field's focus event fires. |
| 3658 std::string result; |
| 3659 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3660 root->child_at(0)->current_frame_host(), "focusInputField()", &result)); |
| 3661 EXPECT_EQ(result, "input-focus"); |
| 3662 |
| 3663 // The subframe should now be focused. |
| 3664 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); |
| 3665 |
| 3666 // Generate a few keyboard events and route them to currently focused frame. |
| 3667 SimulateKeyPress(web_contents, ui::VKEY_F, false, false, false, false); |
| 3668 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
| 3669 SimulateKeyPress(web_contents, ui::VKEY_O, false, false, false, false); |
| 3670 |
| 3671 // Verify that the input field in the subframe received the keystrokes. |
| 3672 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3673 root->child_at(0)->current_frame_host(), |
| 3674 "window.domAutomationController.send(getInputFieldText());", &result)); |
| 3675 EXPECT_EQ("FOO", result); |
| 3676 } |
| 3677 |
3629 } // namespace content | 3678 } // namespace content |
OLD | NEW |