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 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, the SetFocus message is sent to all | |
| 2438 // RenderWidgets involved in rendering the page, including those for | |
| 2439 // cross-process subframes. | |
| 2440 TEST_F(RenderFrameHostManagerTest, FocusPropagatesToAllRenderWidgets) { | |
| 2441 // This test only makes sense when cross-site subframes use separate | |
| 2442 // processes. | |
| 2443 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) | |
|
Charlie Reis
2015/10/09 21:21:51
I think you want AreAllSitesIsolatedForTesting. F
alexmos
2015/10/16 16:50:45
Indeed. Done.
| |
| 2444 return; | |
| 2445 | |
| 2446 const GURL kUrlA("http://www.google.com/"); | |
| 2447 const GURL kUrlB("http://chromium.org/"); | |
| 2448 | |
| 2449 // Create a page with two child frames. | |
| 2450 contents()->NavigateAndCommit(kUrlA); | |
| 2451 contents()->GetMainFrame()->OnCreateChildFrame( | |
| 2452 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | |
| 2453 blink::WebTreeScopeType::Document, "frame1", | |
| 2454 blink::WebSandboxFlags::None); | |
| 2455 contents()->GetMainFrame()->OnCreateChildFrame( | |
| 2456 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | |
| 2457 blink::WebTreeScopeType::Document, "frame2", | |
| 2458 blink::WebSandboxFlags::None); | |
| 2459 | |
| 2460 RenderFrameHostManager* child1 = | |
| 2461 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | |
| 2462 RenderFrameHostManager* child2 = | |
| 2463 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); | |
| 2464 | |
| 2465 // Navigate both frames cross-site. | |
| 2466 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrlB, | |
|
Charlie Reis
2015/10/09 21:21:50
nit: nullptr
alexmos
2015/10/16 16:50:44
Done.
| |
| 2467 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | |
| 2468 base::string16() /* title */, | |
| 2469 ui::PAGE_TRANSITION_LINK, | |
| 2470 false /* is_renderer_init */); | |
| 2471 TestRenderFrameHost* host1 = | |
| 2472 static_cast<TestRenderFrameHost*>(NavigateToEntry(child1, entry)); | |
| 2473 TestRenderFrameHost* host2 = | |
| 2474 static_cast<TestRenderFrameHost*>(NavigateToEntry(child2, entry)); | |
| 2475 child1->DidNavigateFrame(host1, true); | |
| 2476 child2->DidNavigateFrame(host2, true); | |
| 2477 | |
| 2478 // Make sure three RenderWidgetHosts are created. | |
| 2479 EXPECT_NE(main_test_rfh()->GetRenderWidgetHost(), | |
| 2480 host1->GetRenderWidgetHost()); | |
| 2481 EXPECT_NE(main_test_rfh()->GetRenderWidgetHost(), | |
| 2482 host2->GetRenderWidgetHost()); | |
| 2483 EXPECT_NE(host1->GetRenderWidgetHost(), host2->GetRenderWidgetHost()); | |
| 2484 | |
| 2485 // Make sure the two child frames are placed in a distinct process from their | |
| 2486 // parent. | |
| 2487 EXPECT_NE(host1->GetProcess(), main_test_rfh()->GetProcess()); | |
| 2488 EXPECT_EQ(host1->GetProcess(), host2->GetProcess()); | |
| 2489 | |
| 2490 // Helper to check that the SetFocus message was sent to main frame's | |
| 2491 // process and to the two RenderWidgets in the child process. | |
| 2492 auto verify_focus_messages = [this, host1, host2](bool enable_focus) { | |
|
Charlie Reis
2015/10/09 21:21:51
Wow, first time I've come across lambdas in Chrome
alexmos
2015/10/16 16:50:44
I saw it used in lazyboy's CL (https://codereview.
Charlie Reis
2015/10/16 18:56:09
Acknowledged.
| |
| 2493 const IPC::Message* message = | |
| 2494 main_test_rfh()->GetProcess()->sink().GetUniqueMessageMatching( | |
| 2495 InputMsg_SetFocus::ID); | |
| 2496 EXPECT_TRUE(message); | |
| 2497 EXPECT_EQ(main_test_rfh()->GetRenderWidgetHost()->GetRoutingID(), | |
| 2498 message->routing_id()); | |
| 2499 InputMsg_SetFocus::Param params; | |
| 2500 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); | |
| 2501 EXPECT_EQ(enable_focus, base::get<0>(params)); | |
|
Charlie Reis
2015/10/09 21:21:51
nit: enable_focus -> focus_expected?
alexmos
2015/10/16 16:50:44
Changed to expected_focus in the updated test.
| |
| 2502 | |
| 2503 EXPECT_EQ(2U, host1->GetProcess()->sink().message_count()); | |
| 2504 std::set<int> routing_ids; | |
| 2505 for (size_t i = 0; i < host1->GetProcess()->sink().message_count(); ++i) { | |
| 2506 const IPC::Message* message = host1->GetProcess()->sink().GetMessageAt(i); | |
| 2507 EXPECT_EQ(InputMsg_SetFocus::ID, message->type()); | |
| 2508 routing_ids.insert(message->routing_id()); | |
| 2509 InputMsg_SetFocus::Param params; | |
| 2510 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); | |
| 2511 EXPECT_EQ(enable_focus, base::get<0>(params)); | |
|
Charlie Reis
2015/10/09 21:21:51
I'm puzzled. Why would we tell the subframes that
alexmos
2015/10/16 16:50:44
Yes, this message means that the whole page was fo
Charlie Reis
2015/10/16 18:56:09
Acknowledged.
| |
| 2512 } | |
| 2513 EXPECT_NE(routing_ids.find(host1->GetRenderWidgetHost()->GetRoutingID()), | |
| 2514 routing_ids.end()); | |
| 2515 EXPECT_NE(routing_ids.find(host2->GetRenderWidgetHost()->GetRoutingID()), | |
| 2516 routing_ids.end()); | |
| 2517 }; | |
| 2518 | |
| 2519 // Focus the main page, and verify that the focus message was sent to all | |
| 2520 // widgets. | |
| 2521 main_test_rfh()->GetProcess()->sink().ClearMessages(); | |
| 2522 host1->GetProcess()->sink().ClearMessages(); | |
| 2523 main_test_rfh()->GetRenderWidgetHost()->Focus(); | |
| 2524 verify_focus_messages(true); | |
| 2525 | |
| 2526 // Simulate focus loss on main page, and verify that the focus message was | |
| 2527 // sent to all widgets. | |
| 2528 main_test_rfh()->GetProcess()->sink().ClearMessages(); | |
| 2529 host1->GetProcess()->sink().ClearMessages(); | |
| 2530 main_test_rfh()->GetRenderWidgetHost()->Blur(); | |
| 2531 verify_focus_messages(false); | |
| 2532 } | |
|
Charlie Reis
2015/10/09 21:21:51
Should we be testing the case where one of the sub
alexmos
2015/10/16 16:50:44
I added a test for some of that in https://coderev
Charlie Reis
2015/10/16 18:56:09
Acknowledged.
| |
| 2533 | |
| 2436 } // namespace content | 2534 } // namespace content |
| OLD | NEW |