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 3437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3448 | 3448 |
3449 // Simulate that the dropped SwapOut ACK message arrives now on the original | 3449 // Simulate that the dropped SwapOut ACK message arrives now on the original |
3450 // RenderFrameHost, which should now get deleted. | 3450 // RenderFrameHost, which should now get deleted. |
3451 rfh->OnSwappedOut(); | 3451 rfh->OnSwappedOut(); |
3452 EXPECT_TRUE(deleted_observer.deleted()); | 3452 EXPECT_TRUE(deleted_observer.deleted()); |
3453 | 3453 |
3454 // Make sure the last navigation finishes without crashing. | 3454 // Make sure the last navigation finishes without crashing. |
3455 navigation_observer.Wait(); | 3455 navigation_observer.Wait(); |
3456 } | 3456 } |
3457 | 3457 |
| 3458 // Check that when a cross-process frame acquires focus, the old focused frame |
| 3459 // loses focus and fires blur events. Starting on a page with a cross-site |
| 3460 // subframe, simulate mouse clicks to switch focus from root frame to subframe |
| 3461 // and then back to root frame. |
| 3462 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3463 CrossProcessFocusChangeFiresBlurEvents) { |
| 3464 GURL main_url( |
| 3465 embedded_test_server()->GetURL("a.com", "/page_with_input_field.html")); |
| 3466 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3467 |
| 3468 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 3469 ->GetFrameTree() |
| 3470 ->root(); |
| 3471 |
| 3472 EXPECT_EQ( |
| 3473 " Site A ------------ proxies for B\n" |
| 3474 " +--Site B ------- proxies for A\n" |
| 3475 "Where A = http://a.com/\n" |
| 3476 " B = http://b.com/", |
| 3477 DepictFrameTree(root)); |
| 3478 |
| 3479 // Focus the main frame's text field. The return value "input-focus" |
| 3480 // indicates that the focus event was fired correctly. |
| 3481 std::string result; |
| 3482 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), |
| 3483 "focusInputField()", &result)); |
| 3484 EXPECT_EQ(result, "input-focus"); |
| 3485 |
| 3486 // The main frame should be focused. |
| 3487 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 3488 |
| 3489 DOMMessageQueue msg_queue; |
| 3490 |
| 3491 // Click on the cross-process subframe. |
| 3492 blink::WebMouseEvent mouse_event; |
| 3493 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 3494 mouse_event.button = blink::WebPointerProperties::ButtonLeft; |
| 3495 mouse_event.x = 1; |
| 3496 mouse_event.y = 1; |
| 3497 RenderWidgetHost* rwh_child = |
| 3498 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(); |
| 3499 rwh_child->ForwardMouseEvent(mouse_event); |
| 3500 |
| 3501 // Check that the main frame lost focus and fired blur event on the input |
| 3502 // text field. |
| 3503 std::string status; |
| 3504 while (msg_queue.WaitForMessage(&status)) { |
| 3505 if (status == "\"input-blur\"") |
| 3506 break; |
| 3507 } |
| 3508 |
| 3509 // The subframe should now be focused. |
| 3510 EXPECT_EQ(root->child_at(0), root->frame_tree()->GetFocusedFrame()); |
| 3511 |
| 3512 // Click on the root frame. |
| 3513 shell()->web_contents()->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 3514 |
| 3515 // Check that the subframe lost focus and fired blur event on its |
| 3516 // document's body. |
| 3517 while (msg_queue.WaitForMessage(&status)) { |
| 3518 if (status == "\"document-blur\"") |
| 3519 break; |
| 3520 } |
| 3521 |
| 3522 // The root frame should be focused again. |
| 3523 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 3524 } |
| 3525 |
3458 } // namespace content | 3526 } // namespace content |
OLD | NEW |