Chromium Code Reviews| 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 2442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2473 EXPECT_EQ(tree3, opener_frame_trees[2]); | 2474 EXPECT_EQ(tree3, opener_frame_trees[2]); |
| 2474 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2475 EXPECT_EQ(tree4, opener_frame_trees[3]); |
| 2475 | 2476 |
| 2476 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2477 EXPECT_EQ(2U, nodes_with_back_links.size()); |
| 2477 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2478 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
| 2478 nodes_with_back_links.end()); | 2479 nodes_with_back_links.end()); |
| 2479 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2480 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
| 2480 nodes_with_back_links.end()); | 2481 nodes_with_back_links.end()); |
| 2481 } | 2482 } |
| 2482 | 2483 |
| 2484 // Check that when a window is focused/blurred, the message that sets | |
|
nasko
2015/10/16 23:06:30
Shouldn't this test move to frame_tree_unittests.c
alexmos
2015/10/16 23:23:30
I couldn't move it due to a dependency on Navigate
| |
| 2485 // page-level focus updates is sent to each process involved in rendering the | |
| 2486 // current page. | |
| 2487 TEST_F(RenderFrameHostManagerTest, PageFocusPropagatesToSubframeProcesses) { | |
| 2488 // This test only makes sense when cross-site subframes use separate | |
| 2489 // processes. | |
| 2490 if (!AreAllSitesIsolatedForTesting()) | |
| 2491 return; | |
| 2492 | |
| 2493 const GURL kUrlA("http://a.com/"); | |
| 2494 const GURL kUrlB("http://b.com/"); | |
| 2495 const GURL kUrlC("http://c.com/"); | |
| 2496 | |
| 2497 // Set up a page at a.com with three subframes: two for b.com and one for | |
| 2498 // c.com. | |
| 2499 contents()->NavigateAndCommit(kUrlA); | |
| 2500 main_test_rfh()->OnCreateChildFrame( | |
| 2501 main_test_rfh()->GetProcess()->GetNextRoutingID(), | |
| 2502 blink::WebTreeScopeType::Document, "frame1", | |
| 2503 blink::WebSandboxFlags::None); | |
| 2504 main_test_rfh()->OnCreateChildFrame( | |
| 2505 main_test_rfh()->GetProcess()->GetNextRoutingID(), | |
| 2506 blink::WebTreeScopeType::Document, "frame2", | |
| 2507 blink::WebSandboxFlags::None); | |
| 2508 main_test_rfh()->OnCreateChildFrame( | |
| 2509 main_test_rfh()->GetProcess()->GetNextRoutingID(), | |
| 2510 blink::WebTreeScopeType::Document, "frame3", | |
| 2511 blink::WebSandboxFlags::None); | |
| 2512 | |
| 2513 FrameTreeNode* root = contents()->GetFrameTree()->root(); | |
| 2514 RenderFrameHostManager* child1 = root->child_at(0)->render_manager(); | |
| 2515 RenderFrameHostManager* child2 = root->child_at(1)->render_manager(); | |
| 2516 RenderFrameHostManager* child3 = root->child_at(2)->render_manager(); | |
| 2517 | |
| 2518 // Navigate first two subframes to B. | |
| 2519 NavigationEntryImpl entryB(nullptr /* instance */, -1 /* page_id */, kUrlB, | |
| 2520 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | |
| 2521 base::string16() /* title */, | |
| 2522 ui::PAGE_TRANSITION_LINK, | |
| 2523 false /* is_renderer_init */); | |
| 2524 TestRenderFrameHost* host1 = | |
| 2525 static_cast<TestRenderFrameHost*>(NavigateToEntry(child1, entryB)); | |
| 2526 TestRenderFrameHost* host2 = | |
| 2527 static_cast<TestRenderFrameHost*>(NavigateToEntry(child2, entryB)); | |
| 2528 child1->DidNavigateFrame(host1, true); | |
| 2529 child2->DidNavigateFrame(host2, true); | |
| 2530 | |
| 2531 // Navigate the third subframe to C. | |
| 2532 NavigationEntryImpl entryC(nullptr /* instance */, -1 /* page_id */, kUrlC, | |
| 2533 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | |
| 2534 base::string16() /* title */, | |
| 2535 ui::PAGE_TRANSITION_LINK, | |
| 2536 false /* is_renderer_init */); | |
| 2537 TestRenderFrameHost* host3 = | |
| 2538 static_cast<TestRenderFrameHost*>(NavigateToEntry(child3, entryC)); | |
| 2539 child3->DidNavigateFrame(host3, true); | |
| 2540 | |
| 2541 // Make sure the first two subframes and the third subframe are placed in | |
| 2542 // distinct processes. | |
| 2543 EXPECT_NE(host1->GetProcess(), main_test_rfh()->GetProcess()); | |
| 2544 EXPECT_EQ(host1->GetProcess(), host2->GetProcess()); | |
| 2545 EXPECT_NE(host3->GetProcess(), main_test_rfh()->GetProcess()); | |
| 2546 EXPECT_NE(host3->GetProcess(), host1->GetProcess()); | |
| 2547 | |
| 2548 // The main frame should have proxies for B and C. | |
| 2549 RenderFrameProxyHost* proxyB = | |
| 2550 root->render_manager()->GetRenderFrameProxyHost(host1->GetSiteInstance()); | |
| 2551 EXPECT_TRUE(proxyB); | |
| 2552 RenderFrameProxyHost* proxyC = | |
| 2553 root->render_manager()->GetRenderFrameProxyHost(host3->GetSiteInstance()); | |
| 2554 EXPECT_TRUE(proxyC); | |
| 2555 | |
| 2556 // Helper to check that the provided RenderProcessHost received exactly one | |
| 2557 // page focus message with the provided focus and routing ID values. | |
| 2558 auto verify_focus_message = [](MockRenderProcessHost* rph, | |
| 2559 bool expected_focus, | |
| 2560 int expected_routing_id) { | |
| 2561 const IPC::Message* message = | |
| 2562 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID); | |
| 2563 EXPECT_TRUE(message); | |
| 2564 EXPECT_EQ(expected_routing_id, message->routing_id()); | |
| 2565 InputMsg_SetFocus::Param params; | |
| 2566 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); | |
| 2567 EXPECT_EQ(expected_focus, base::get<0>(params)); | |
| 2568 }; | |
| 2569 | |
| 2570 // Focus the main page, and verify that the focus message was sent to all | |
| 2571 // processes. The message to A should be sent through the main frame's | |
| 2572 // RenderViewHost, and the message to B and C should be send through proxies | |
| 2573 // that the main frame has for B and C. | |
| 2574 main_test_rfh()->GetProcess()->sink().ClearMessages(); | |
| 2575 host1->GetProcess()->sink().ClearMessages(); | |
| 2576 host3->GetProcess()->sink().ClearMessages(); | |
| 2577 main_test_rfh()->GetRenderWidgetHost()->Focus(); | |
| 2578 verify_focus_message(main_test_rfh()->GetProcess(), true, | |
| 2579 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); | |
| 2580 verify_focus_message(host1->GetProcess(), true, proxyB->GetRoutingID()); | |
| 2581 verify_focus_message(host3->GetProcess(), true, proxyC->GetRoutingID()); | |
| 2582 | |
| 2583 // Similarly, simulate focus loss on main page, and verify that the focus | |
| 2584 // message was sent to all processes. | |
| 2585 main_test_rfh()->GetProcess()->sink().ClearMessages(); | |
| 2586 host1->GetProcess()->sink().ClearMessages(); | |
| 2587 host3->GetProcess()->sink().ClearMessages(); | |
| 2588 main_test_rfh()->GetRenderWidgetHost()->Blur(); | |
| 2589 verify_focus_message(main_test_rfh()->GetProcess(), false, | |
| 2590 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); | |
| 2591 verify_focus_message(host1->GetProcess(), false, proxyB->GetRoutingID()); | |
| 2592 verify_focus_message(host3->GetProcess(), false, proxyC->GetRoutingID()); | |
| 2593 } | |
| 2594 | |
| 2483 } // namespace content | 2595 } // namespace content |
| OLD | NEW |