OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
11 #include "content/browser/frame_host/cross_site_transferring_request.h" | 11 #include "content/browser/frame_host/cross_site_transferring_request.h" |
12 #include "content/browser/frame_host/navigation_controller_impl.h" | 12 #include "content/browser/frame_host/navigation_controller_impl.h" |
13 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
14 #include "content/browser/frame_host/navigation_request.h" | 14 #include "content/browser/frame_host/navigation_request.h" |
15 #include "content/browser/frame_host/navigator.h" | 15 #include "content/browser/frame_host/navigator.h" |
16 #include "content/browser/frame_host/render_frame_host_manager.h" | 16 #include "content/browser/frame_host/render_frame_host_manager.h" |
17 #include "content/browser/frame_host/render_frame_proxy_host.h" | 17 #include "content/browser/frame_host/render_frame_proxy_host.h" |
18 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
19 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 19 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
20 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
| 21 #include "content/common/input_messages.h" |
21 #include "content/common/site_isolation_policy.h" | 22 #include "content/common/site_isolation_policy.h" |
22 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
23 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/render_widget_host_iterator.h" | 29 #include "content/public/browser/render_widget_host_iterator.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 30 #include "content/public/browser/web_contents_delegate.h" |
30 #include "content/public/browser/web_contents_observer.h" | 31 #include "content/public/browser/web_contents_observer.h" |
(...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2426 EXPECT_EQ(tree3, opener_frame_trees[2]); | 2427 EXPECT_EQ(tree3, opener_frame_trees[2]); |
2427 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2428 EXPECT_EQ(tree4, opener_frame_trees[3]); |
2428 | 2429 |
2429 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2430 EXPECT_EQ(2U, nodes_with_back_links.size()); |
2430 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2431 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
2431 nodes_with_back_links.end()); | 2432 nodes_with_back_links.end()); |
2432 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2433 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
2433 nodes_with_back_links.end()); | 2434 nodes_with_back_links.end()); |
2434 } | 2435 } |
2435 | 2436 |
| 2437 // Check that when a window is focused/blurred, the message that sets |
| 2438 // page-level focus updates is sent to each process involved in rendering the |
| 2439 // current page. |
| 2440 TEST_F(RenderFrameHostManagerTest, PageFocusPropagatesToSubframeProcesses) { |
| 2441 // This test only makes sense when cross-site subframes use separate |
| 2442 // processes. |
| 2443 if (!AreAllSitesIsolatedForTesting()) |
| 2444 return; |
| 2445 |
| 2446 const GURL kUrlA("http://a.com/"); |
| 2447 const GURL kUrlB("http://b.com/"); |
| 2448 const GURL kUrlC("http://c.com/"); |
| 2449 |
| 2450 // Set up a page at a.com with three subframes: two for b.com and one for |
| 2451 // c.com. |
| 2452 contents()->NavigateAndCommit(kUrlA); |
| 2453 main_test_rfh()->OnCreateChildFrame( |
| 2454 main_test_rfh()->GetProcess()->GetNextRoutingID(), |
| 2455 blink::WebTreeScopeType::Document, "frame1", |
| 2456 blink::WebSandboxFlags::None); |
| 2457 main_test_rfh()->OnCreateChildFrame( |
| 2458 main_test_rfh()->GetProcess()->GetNextRoutingID(), |
| 2459 blink::WebTreeScopeType::Document, "frame2", |
| 2460 blink::WebSandboxFlags::None); |
| 2461 main_test_rfh()->OnCreateChildFrame( |
| 2462 main_test_rfh()->GetProcess()->GetNextRoutingID(), |
| 2463 blink::WebTreeScopeType::Document, "frame3", |
| 2464 blink::WebSandboxFlags::None); |
| 2465 |
| 2466 FrameTreeNode* root = contents()->GetFrameTree()->root(); |
| 2467 RenderFrameHostManager* child1 = root->child_at(0)->render_manager(); |
| 2468 RenderFrameHostManager* child2 = root->child_at(1)->render_manager(); |
| 2469 RenderFrameHostManager* child3 = root->child_at(2)->render_manager(); |
| 2470 |
| 2471 // Navigate first two subframes to B. |
| 2472 NavigationEntryImpl entryB(nullptr /* instance */, -1 /* page_id */, kUrlB, |
| 2473 Referrer(kUrlA, blink::WebReferrerPolicyDefault), |
| 2474 base::string16() /* title */, |
| 2475 ui::PAGE_TRANSITION_LINK, |
| 2476 false /* is_renderer_init */); |
| 2477 TestRenderFrameHost* host1 = |
| 2478 static_cast<TestRenderFrameHost*>(NavigateToEntry(child1, entryB)); |
| 2479 TestRenderFrameHost* host2 = |
| 2480 static_cast<TestRenderFrameHost*>(NavigateToEntry(child2, entryB)); |
| 2481 child1->DidNavigateFrame(host1, true); |
| 2482 child2->DidNavigateFrame(host2, true); |
| 2483 |
| 2484 // Navigate the third subframe to C. |
| 2485 NavigationEntryImpl entryC(nullptr /* instance */, -1 /* page_id */, kUrlC, |
| 2486 Referrer(kUrlA, blink::WebReferrerPolicyDefault), |
| 2487 base::string16() /* title */, |
| 2488 ui::PAGE_TRANSITION_LINK, |
| 2489 false /* is_renderer_init */); |
| 2490 TestRenderFrameHost* host3 = |
| 2491 static_cast<TestRenderFrameHost*>(NavigateToEntry(child3, entryC)); |
| 2492 child3->DidNavigateFrame(host3, true); |
| 2493 |
| 2494 // Make sure the first two subframes and the third subframe are placed in |
| 2495 // distinct processes. |
| 2496 EXPECT_NE(host1->GetProcess(), main_test_rfh()->GetProcess()); |
| 2497 EXPECT_EQ(host1->GetProcess(), host2->GetProcess()); |
| 2498 EXPECT_NE(host3->GetProcess(), main_test_rfh()->GetProcess()); |
| 2499 EXPECT_NE(host3->GetProcess(), host1->GetProcess()); |
| 2500 |
| 2501 // The main frame should have proxies for B and C. |
| 2502 RenderFrameProxyHost* proxyB = |
| 2503 root->render_manager()->GetRenderFrameProxyHost(host1->GetSiteInstance()); |
| 2504 EXPECT_TRUE(proxyB); |
| 2505 RenderFrameProxyHost* proxyC = |
| 2506 root->render_manager()->GetRenderFrameProxyHost(host3->GetSiteInstance()); |
| 2507 EXPECT_TRUE(proxyC); |
| 2508 |
| 2509 // Helper to check that the provided RenderProcessHost received exactly one |
| 2510 // page focus message with the provided focus and routing ID values. |
| 2511 auto verify_focus_message = [](MockRenderProcessHost* rph, |
| 2512 bool expected_focus, |
| 2513 int expected_routing_id) { |
| 2514 const IPC::Message* message = |
| 2515 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID); |
| 2516 EXPECT_TRUE(message); |
| 2517 EXPECT_EQ(expected_routing_id, message->routing_id()); |
| 2518 InputMsg_SetFocus::Param params; |
| 2519 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); |
| 2520 EXPECT_EQ(expected_focus, base::get<0>(params)); |
| 2521 }; |
| 2522 |
| 2523 // Focus the main page, and verify that the focus message was sent to all |
| 2524 // processes. The message to A should be sent through the main frame's |
| 2525 // RenderViewHost, and the message to B and C should be send through proxies |
| 2526 // that the main frame has for B and C. |
| 2527 main_test_rfh()->GetProcess()->sink().ClearMessages(); |
| 2528 host1->GetProcess()->sink().ClearMessages(); |
| 2529 host3->GetProcess()->sink().ClearMessages(); |
| 2530 main_test_rfh()->GetRenderWidgetHost()->Focus(); |
| 2531 verify_focus_message(main_test_rfh()->GetProcess(), true, |
| 2532 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); |
| 2533 verify_focus_message(host1->GetProcess(), true, proxyB->GetRoutingID()); |
| 2534 verify_focus_message(host3->GetProcess(), true, proxyC->GetRoutingID()); |
| 2535 |
| 2536 // Similarly, simulate focus loss on main page, and verify that the focus |
| 2537 // message was sent to all processes. |
| 2538 main_test_rfh()->GetProcess()->sink().ClearMessages(); |
| 2539 host1->GetProcess()->sink().ClearMessages(); |
| 2540 host3->GetProcess()->sink().ClearMessages(); |
| 2541 main_test_rfh()->GetRenderWidgetHost()->Blur(); |
| 2542 verify_focus_message(main_test_rfh()->GetProcess(), false, |
| 2543 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); |
| 2544 verify_focus_message(host1->GetProcess(), false, proxyB->GetRoutingID()); |
| 2545 verify_focus_message(host3->GetProcess(), false, proxyC->GetRoutingID()); |
| 2546 } |
| 2547 |
2436 } // namespace content | 2548 } // namespace content |
OLD | NEW |