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 " |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "content/test/test_render_view_host.h" | 44 #include "content/test/test_render_view_host.h" |
45 #include "content/test/test_web_contents.h" | 45 #include "content/test/test_web_contents.h" |
46 #include "net/base/load_flags.h" | 46 #include "net/base/load_flags.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 48 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
49 #include "ui/base/page_transition_types.h" | 49 #include "ui/base/page_transition_types.h" |
50 | 50 |
51 namespace content { | 51 namespace content { |
52 namespace { | 52 namespace { |
53 | 53 |
54 // Helper to check that the provided RenderProcessHost received exactly one | |
55 // page focus message with the provided focus and routing ID values. | |
56 void VerifyPageFocusMessage(MockRenderProcessHost* rph, | |
57 bool expected_focus, | |
58 int expected_routing_id) { | |
59 const IPC::Message* message = | |
60 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID); | |
61 EXPECT_TRUE(message); | |
62 EXPECT_EQ(expected_routing_id, message->routing_id()); | |
63 InputMsg_SetFocus::Param params; | |
64 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); | |
65 EXPECT_EQ(expected_focus, base::get<0>(params)); | |
66 } | |
67 | |
54 class RenderFrameHostManagerTestWebUIControllerFactory | 68 class RenderFrameHostManagerTestWebUIControllerFactory |
55 : public WebUIControllerFactory { | 69 : public WebUIControllerFactory { |
56 public: | 70 public: |
57 RenderFrameHostManagerTestWebUIControllerFactory() | 71 RenderFrameHostManagerTestWebUIControllerFactory() |
58 : should_create_webui_(false) { | 72 : should_create_webui_(false) { |
59 } | 73 } |
60 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} | 74 ~RenderFrameHostManagerTestWebUIControllerFactory() override {} |
61 | 75 |
62 void set_should_create_webui(bool should_create_webui) { | 76 void set_should_create_webui(bool should_create_webui) { |
63 should_create_webui_ = should_create_webui; | 77 should_create_webui_ = should_create_webui; |
(...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2549 EXPECT_NE(host3->GetProcess(), host1->GetProcess()); | 2563 EXPECT_NE(host3->GetProcess(), host1->GetProcess()); |
2550 | 2564 |
2551 // The main frame should have proxies for B and C. | 2565 // The main frame should have proxies for B and C. |
2552 RenderFrameProxyHost* proxyB = | 2566 RenderFrameProxyHost* proxyB = |
2553 root->render_manager()->GetRenderFrameProxyHost(host1->GetSiteInstance()); | 2567 root->render_manager()->GetRenderFrameProxyHost(host1->GetSiteInstance()); |
2554 EXPECT_TRUE(proxyB); | 2568 EXPECT_TRUE(proxyB); |
2555 RenderFrameProxyHost* proxyC = | 2569 RenderFrameProxyHost* proxyC = |
2556 root->render_manager()->GetRenderFrameProxyHost(host3->GetSiteInstance()); | 2570 root->render_manager()->GetRenderFrameProxyHost(host3->GetSiteInstance()); |
2557 EXPECT_TRUE(proxyC); | 2571 EXPECT_TRUE(proxyC); |
2558 | 2572 |
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, ¶ms)); | |
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 | 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 | 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 | 2575 // RenderViewHost, and the message to B and C should be send through proxies |
2576 // that the main frame has for B and C. | 2576 // that the main frame has for B and C. |
2577 main_test_rfh()->GetProcess()->sink().ClearMessages(); | 2577 main_test_rfh()->GetProcess()->sink().ClearMessages(); |
2578 host1->GetProcess()->sink().ClearMessages(); | 2578 host1->GetProcess()->sink().ClearMessages(); |
2579 host3->GetProcess()->sink().ClearMessages(); | 2579 host3->GetProcess()->sink().ClearMessages(); |
2580 main_test_rfh()->GetRenderWidgetHost()->Focus(); | 2580 main_test_rfh()->GetRenderWidgetHost()->Focus(); |
2581 verify_focus_message(main_test_rfh()->GetProcess(), true, | 2581 VerifyPageFocusMessage(main_test_rfh()->GetProcess(), true, |
2582 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); | 2582 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); |
2583 verify_focus_message(host1->GetProcess(), true, proxyB->GetRoutingID()); | 2583 VerifyPageFocusMessage(host1->GetProcess(), true, proxyB->GetRoutingID()); |
2584 verify_focus_message(host3->GetProcess(), true, proxyC->GetRoutingID()); | 2584 VerifyPageFocusMessage(host3->GetProcess(), true, proxyC->GetRoutingID()); |
2585 | 2585 |
2586 // Similarly, simulate focus loss on main page, and verify that the focus | 2586 // Similarly, simulate focus loss on main page, and verify that the focus |
2587 // message was sent to all processes. | 2587 // message was sent to all processes. |
2588 main_test_rfh()->GetProcess()->sink().ClearMessages(); | 2588 main_test_rfh()->GetProcess()->sink().ClearMessages(); |
2589 host1->GetProcess()->sink().ClearMessages(); | 2589 host1->GetProcess()->sink().ClearMessages(); |
2590 host3->GetProcess()->sink().ClearMessages(); | 2590 host3->GetProcess()->sink().ClearMessages(); |
2591 main_test_rfh()->GetRenderWidgetHost()->Blur(); | 2591 main_test_rfh()->GetRenderWidgetHost()->Blur(); |
2592 verify_focus_message(main_test_rfh()->GetProcess(), false, | 2592 VerifyPageFocusMessage(main_test_rfh()->GetProcess(), false, |
2593 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); | 2593 main_test_rfh()->GetRenderViewHost()->GetRoutingID()); |
2594 verify_focus_message(host1->GetProcess(), false, proxyB->GetRoutingID()); | 2594 VerifyPageFocusMessage(host1->GetProcess(), false, proxyB->GetRoutingID()); |
2595 verify_focus_message(host3->GetProcess(), false, proxyC->GetRoutingID()); | 2595 VerifyPageFocusMessage(host3->GetProcess(), false, proxyC->GetRoutingID()); |
2596 } | |
2597 | |
2598 // Check that page-level focus state is preserved across subframe navigations. | |
2599 // | |
2600 // TODO(alexmos): Move this test to FrameTree unit tests once NavigateToEntry | |
2601 // is moved to a common place. | |
Charlie Reis
2015/10/23 21:41:53
Is there a bug on file for this move?
alexmos
2015/10/24 00:41:43
Nope, so I added one.
| |
2602 TEST_F(RenderFrameHostManagerTest, | |
2603 PageFocusIsPreservedAcrossSubframeNavigations) { | |
2604 // This test only makes sense when cross-site subframes use separate | |
2605 // processes. | |
2606 if (!AreAllSitesIsolatedForTesting()) | |
2607 return; | |
2608 | |
2609 const GURL kUrlA("http://a.com/"); | |
2610 const GURL kUrlB("http://b.com/"); | |
2611 const GURL kUrlC("http://c.com/"); | |
2612 | |
2613 // Set up a page at a.com with a b.com subframe. | |
2614 contents()->NavigateAndCommit(kUrlA); | |
2615 main_test_rfh()->OnCreateChildFrame( | |
2616 main_test_rfh()->GetProcess()->GetNextRoutingID(), | |
2617 blink::WebTreeScopeType::Document, "frame1", | |
2618 blink::WebSandboxFlags::None); | |
2619 | |
2620 FrameTreeNode* root = contents()->GetFrameTree()->root(); | |
2621 RenderFrameHostManager* child = root->child_at(0)->render_manager(); | |
2622 | |
2623 // Navigate subframe to B. | |
2624 NavigationEntryImpl entryB(nullptr /* instance */, -1 /* page_id */, kUrlB, | |
2625 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | |
2626 base::string16() /* title */, | |
2627 ui::PAGE_TRANSITION_LINK, | |
2628 false /* is_renderer_init */); | |
2629 TestRenderFrameHost* hostB = | |
2630 static_cast<TestRenderFrameHost*>(NavigateToEntry(child, entryB)); | |
2631 child->DidNavigateFrame(hostB, true); | |
2632 | |
2633 // Ensure that the main page is focused. | |
2634 main_test_rfh()->GetView()->Focus(); | |
2635 EXPECT_TRUE(main_test_rfh()->GetView()->HasFocus()); | |
2636 | |
2637 // Navigate the subframe to C. | |
2638 NavigationEntryImpl entryC(nullptr /* instance */, -1 /* page_id */, kUrlC, | |
2639 Referrer(kUrlA, blink::WebReferrerPolicyDefault), | |
2640 base::string16() /* title */, | |
2641 ui::PAGE_TRANSITION_LINK, | |
2642 false /* is_renderer_init */); | |
2643 TestRenderFrameHost* hostC = | |
2644 static_cast<TestRenderFrameHost*>(NavigateToEntry(child, entryC)); | |
2645 child->DidNavigateFrame(hostC, true); | |
2646 | |
2647 // The main frame should now have a proxy for C. | |
2648 RenderFrameProxyHost* proxy = | |
2649 root->render_manager()->GetRenderFrameProxyHost(hostC->GetSiteInstance()); | |
2650 EXPECT_TRUE(proxy); | |
2651 | |
2652 // Since the B->C navigation happened while the current page was focused, | |
2653 // page focus should propagate to the new subframe process. Check that | |
2654 // process C received the proper focus message. | |
2655 VerifyPageFocusMessage(hostC->GetProcess(), true, proxy->GetRoutingID()); | |
2596 } | 2656 } |
2597 | 2657 |
2598 } // namespace content | 2658 } // namespace content |
OLD | NEW |