Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1394383002: OOPIF: Send page-level focus messages to all processes rendering a page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
2485 // page-level focus updates is sent to each process involved in rendering the
2486 // current page.
2487 //
2488 // TODO(alexmos): Move this test to FrameTree unit tests once NavigateToEntry
2489 // is moved to a common place.
2490 TEST_F(RenderFrameHostManagerTest, PageFocusPropagatesToSubframeProcesses) {
2491 // This test only makes sense when cross-site subframes use separate
2492 // processes.
2493 if (!AreAllSitesIsolatedForTesting())
2494 return;
2495
2496 const GURL kUrlA("http://a.com/");
2497 const GURL kUrlB("http://b.com/");
2498 const GURL kUrlC("http://c.com/");
2499
2500 // Set up a page at a.com with three subframes: two for b.com and one for
2501 // c.com.
2502 contents()->NavigateAndCommit(kUrlA);
2503 main_test_rfh()->OnCreateChildFrame(
2504 main_test_rfh()->GetProcess()->GetNextRoutingID(),
2505 blink::WebTreeScopeType::Document, "frame1",
2506 blink::WebSandboxFlags::None);
2507 main_test_rfh()->OnCreateChildFrame(
2508 main_test_rfh()->GetProcess()->GetNextRoutingID(),
2509 blink::WebTreeScopeType::Document, "frame2",
2510 blink::WebSandboxFlags::None);
2511 main_test_rfh()->OnCreateChildFrame(
2512 main_test_rfh()->GetProcess()->GetNextRoutingID(),
2513 blink::WebTreeScopeType::Document, "frame3",
2514 blink::WebSandboxFlags::None);
2515
2516 FrameTreeNode* root = contents()->GetFrameTree()->root();
2517 RenderFrameHostManager* child1 = root->child_at(0)->render_manager();
2518 RenderFrameHostManager* child2 = root->child_at(1)->render_manager();
2519 RenderFrameHostManager* child3 = root->child_at(2)->render_manager();
2520
2521 // Navigate first two subframes to B.
2522 NavigationEntryImpl entryB(nullptr /* instance */, -1 /* page_id */, kUrlB,
2523 Referrer(kUrlA, blink::WebReferrerPolicyDefault),
2524 base::string16() /* title */,
2525 ui::PAGE_TRANSITION_LINK,
2526 false /* is_renderer_init */);
2527 TestRenderFrameHost* host1 =
2528 static_cast<TestRenderFrameHost*>(NavigateToEntry(child1, entryB));
2529 TestRenderFrameHost* host2 =
2530 static_cast<TestRenderFrameHost*>(NavigateToEntry(child2, entryB));
2531 child1->DidNavigateFrame(host1, true);
2532 child2->DidNavigateFrame(host2, true);
2533
2534 // Navigate the third subframe to C.
2535 NavigationEntryImpl entryC(nullptr /* instance */, -1 /* page_id */, kUrlC,
2536 Referrer(kUrlA, blink::WebReferrerPolicyDefault),
2537 base::string16() /* title */,
2538 ui::PAGE_TRANSITION_LINK,
2539 false /* is_renderer_init */);
2540 TestRenderFrameHost* host3 =
2541 static_cast<TestRenderFrameHost*>(NavigateToEntry(child3, entryC));
2542 child3->DidNavigateFrame(host3, true);
2543
2544 // Make sure the first two subframes and the third subframe are placed in
2545 // distinct processes.
2546 EXPECT_NE(host1->GetProcess(), main_test_rfh()->GetProcess());
2547 EXPECT_EQ(host1->GetProcess(), host2->GetProcess());
2548 EXPECT_NE(host3->GetProcess(), main_test_rfh()->GetProcess());
2549 EXPECT_NE(host3->GetProcess(), host1->GetProcess());
2550
2551 // The main frame should have proxies for B and C.
2552 RenderFrameProxyHost* proxyB =
2553 root->render_manager()->GetRenderFrameProxyHost(host1->GetSiteInstance());
2554 EXPECT_TRUE(proxyB);
2555 RenderFrameProxyHost* proxyC =
2556 root->render_manager()->GetRenderFrameProxyHost(host3->GetSiteInstance());
2557 EXPECT_TRUE(proxyC);
2558
2559 // Helper to check that the provided RenderProcessHost received exactly one
2560 // page focus message with the provided focus and routing ID values.
2561 auto verify_focus_message = [](MockRenderProcessHost* rph,
2562 bool expected_focus,
2563 int expected_routing_id) {
2564 const IPC::Message* message =
2565 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID);
2566 EXPECT_TRUE(message);
2567 EXPECT_EQ(expected_routing_id, message->routing_id());
2568 InputMsg_SetFocus::Param params;
2569 EXPECT_TRUE(InputMsg_SetFocus::Read(message, &params));
2570 EXPECT_EQ(expected_focus, base::get<0>(params));
2571 };
2572
2573 // Focus the main page, and verify that the focus message was sent to all
2574 // processes. The message to A should be sent through the main frame's
2575 // RenderViewHost, and the message to B and C should be send through proxies
2576 // that the main frame has for B and C.
2577 main_test_rfh()->GetProcess()->sink().ClearMessages();
2578 host1->GetProcess()->sink().ClearMessages();
2579 host3->GetProcess()->sink().ClearMessages();
2580 main_test_rfh()->GetRenderWidgetHost()->Focus();
2581 verify_focus_message(main_test_rfh()->GetProcess(), true,
2582 main_test_rfh()->GetRenderViewHost()->GetRoutingID());
2583 verify_focus_message(host1->GetProcess(), true, proxyB->GetRoutingID());
2584 verify_focus_message(host3->GetProcess(), true, proxyC->GetRoutingID());
2585
2586 // Similarly, simulate focus loss on main page, and verify that the focus
2587 // message was sent to all processes.
2588 main_test_rfh()->GetProcess()->sink().ClearMessages();
2589 host1->GetProcess()->sink().ClearMessages();
2590 host3->GetProcess()->sink().ClearMessages();
2591 main_test_rfh()->GetRenderWidgetHost()->Blur();
2592 verify_focus_message(main_test_rfh()->GetProcess(), false,
2593 main_test_rfh()->GetRenderViewHost()->GetRoutingID());
2594 verify_focus_message(host1->GetProcess(), false, proxyB->GetRoutingID());
2595 verify_focus_message(host3->GetProcess(), false, proxyC->GetRoutingID());
2596 }
2597
2483 } // namespace content 2598 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree.cc ('k') | content/browser/renderer_host/render_widget_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698