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 | |
112 class RedirectNotificationObserver : public NotificationObserver { | 100 class RedirectNotificationObserver : public NotificationObserver { |
113 public: | 101 public: |
114 // Register to listen for notifications of the given type from either a | 102 // Register to listen for notifications of the given type from either a |
115 // specific source, or from all sources if |source| is | 103 // specific source, or from all sources if |source| is |
116 // NotificationService::AllSources(). | 104 // NotificationService::AllSources(). |
117 RedirectNotificationObserver(int notification_type, | 105 RedirectNotificationObserver(int notification_type, |
118 const NotificationSource& source); | 106 const NotificationSource& source); |
119 ~RedirectNotificationObserver() override; | 107 ~RedirectNotificationObserver() override; |
120 | 108 |
121 // Wait until the specified notification occurs. If the notification was | 109 // Wait until the specified notification occurs. If the notification was |
(...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), | 3481 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), |
3494 "focusInputField()", &result)); | 3482 "focusInputField()", &result)); |
3495 EXPECT_EQ(result, "input-focus"); | 3483 EXPECT_EQ(result, "input-focus"); |
3496 | 3484 |
3497 // The main frame should be focused. | 3485 // The main frame should be focused. |
3498 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 3486 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
3499 | 3487 |
3500 DOMMessageQueue msg_queue; | 3488 DOMMessageQueue msg_queue; |
3501 | 3489 |
3502 // Click on the cross-process subframe. | 3490 // Click on the cross-process subframe. |
3503 SimulateMouseClick( | 3491 blink::WebMouseEvent mouse_event; |
3504 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 3492 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 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); |
3505 | 3499 |
3506 // Check that the main frame lost focus and fired blur event on the input | 3500 // Check that the main frame lost focus and fired blur event on the input |
3507 // text field. | 3501 // text field. |
3508 std::string status; | 3502 std::string status; |
3509 while (msg_queue.WaitForMessage(&status)) { | 3503 while (msg_queue.WaitForMessage(&status)) { |
3510 if (status == "\"input-blur\"") | 3504 if (status == "\"input-blur\"") |
3511 break; | 3505 break; |
3512 } | 3506 } |
3513 | 3507 |
3514 // The subframe should now be focused. | 3508 // The subframe should now be focused. |
3515 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); | 3509 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); |
3516 | 3510 |
3517 // Click on the root frame. | 3511 // Click on the root frame. |
3518 SimulateMouseClick( | 3512 shell()->web_contents()->GetRenderViewHost()->GetWidget()->ForwardMouseEvent( |
3519 shell()->web_contents()->GetRenderViewHost()->GetWidget(), 1, 1); | 3513 mouse_event); |
3520 | 3514 |
3521 // Check that the subframe lost focus and fired blur event on its | 3515 // Check that the subframe lost focus and fired blur event on its |
3522 // document's body. | 3516 // document's body. |
3523 while (msg_queue.WaitForMessage(&status)) { | 3517 while (msg_queue.WaitForMessage(&status)) { |
3524 if (status == "\"document-blur\"") | 3518 if (status == "\"document-blur\"") |
3525 break; | 3519 break; |
3526 } | 3520 } |
3527 | 3521 |
3528 // The root frame should be focused again. | 3522 // The root frame should be focused again. |
3529 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 3523 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3625 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 3619 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
3626 | 3620 |
3627 // Use new window to navigate main window. | 3621 // Use new window to navigate main window. |
3628 std::string script = | 3622 std::string script = |
3629 "window.opener.location.href = '" + cross_url.spec() + "'"; | 3623 "window.opener.location.href = '" + cross_url.spec() + "'"; |
3630 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 3624 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); |
3631 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 3625 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
3632 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 3626 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
3633 } | 3627 } |
3634 | 3628 |
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 | |
3678 } // namespace content | 3629 } // namespace content |
OLD | NEW |