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 "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 #include "content/public/test/test_notification_tracker.h" | 48 #include "content/public/test/test_notification_tracker.h" |
| 49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
| 50 #include "content/test/browser_side_navigation_test_utils.h" | 50 #include "content/test/browser_side_navigation_test_utils.h" |
| 51 #include "content/test/test_content_browser_client.h" | 51 #include "content/test/test_content_browser_client.h" |
| 52 #include "content/test/test_content_client.h" | 52 #include "content/test/test_content_client.h" |
| 53 #include "content/test/test_render_frame_host.h" | 53 #include "content/test/test_render_frame_host.h" |
| 54 #include "content/test/test_render_view_host.h" | 54 #include "content/test/test_render_view_host.h" |
| 55 #include "content/test/test_web_contents.h" | 55 #include "content/test/test_web_contents.h" |
| 56 #include "net/base/load_flags.h" | 56 #include "net/base/load_flags.h" |
| 57 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
| 58 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" | |
| 58 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" | 59 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
| 59 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 60 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 60 #include "ui/base/page_transition_types.h" | 61 #include "ui/base/page_transition_types.h" |
| 61 | 62 |
| 62 namespace content { | 63 namespace content { |
| 63 namespace { | 64 namespace { |
| 64 | 65 |
| 65 // Helper to check that the provided RenderProcessHost received exactly one | 66 // Helper to check that the provided RenderProcessHost received exactly one |
| 66 // page focus message with the provided focus and routing ID values. | 67 // page focus message with the provided focus and routing ID values. |
| 67 void VerifyPageFocusMessage(MockRenderProcessHost* rph, | 68 void VerifyPageFocusMessage(MockRenderProcessHost* rph, |
| 68 bool expected_focus, | 69 bool expected_focus, |
| 69 int expected_routing_id) { | 70 int expected_routing_id) { |
| 70 const IPC::Message* message = | 71 const IPC::Message* message = |
| 71 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID); | 72 rph->sink().GetUniqueMessageMatching(InputMsg_SetFocus::ID); |
| 72 EXPECT_TRUE(message); | 73 EXPECT_TRUE(message); |
| 73 EXPECT_EQ(expected_routing_id, message->routing_id()); | 74 EXPECT_EQ(expected_routing_id, message->routing_id()); |
| 74 InputMsg_SetFocus::Param params; | 75 InputMsg_SetFocus::Param params; |
| 75 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); | 76 EXPECT_TRUE(InputMsg_SetFocus::Read(message, ¶ms)); |
| 76 EXPECT_EQ(expected_focus, std::get<0>(params)); | 77 EXPECT_EQ(expected_focus, std::get<0>(params)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 // Helper function for strict mixed content checking tests. | 80 // Helper function for strict mixed content checking tests. |
| 80 void CheckMixedContentIPC(TestRenderFrameHost* rfh, | 81 void CheckInsecureRequestPolicyIPC( |
| 81 bool expected_param, | 82 TestRenderFrameHost* rfh, |
| 82 int expected_routing_id) { | 83 blink::WebInsecureRequestPolicy expected_param, |
| 84 int expected_routing_id) { | |
| 83 const IPC::Message* message = | 85 const IPC::Message* message = |
| 84 rfh->GetProcess()->sink().GetUniqueMessageMatching( | 86 rfh->GetProcess()->sink().GetUniqueMessageMatching( |
| 85 FrameMsg_EnforceStrictMixedContentChecking::ID); | 87 FrameMsg_EnforceInsecureRequestPolicy::ID); |
| 86 ASSERT_TRUE(message); | 88 ASSERT_TRUE(message); |
| 87 EXPECT_EQ(expected_routing_id, message->routing_id()); | 89 EXPECT_EQ(expected_routing_id, message->routing_id()); |
| 88 FrameMsg_EnforceStrictMixedContentChecking::Param params; | 90 FrameMsg_EnforceInsecureRequestPolicy::Param params; |
| 89 EXPECT_TRUE( | 91 EXPECT_TRUE(FrameMsg_EnforceInsecureRequestPolicy::Read(message, ¶ms)); |
| 90 FrameMsg_EnforceStrictMixedContentChecking::Read(message, ¶ms)); | |
| 91 EXPECT_EQ(expected_param, std::get<0>(params)); | 92 EXPECT_EQ(expected_param, std::get<0>(params)); |
| 92 } | 93 } |
| 93 | 94 |
| 94 class RenderFrameHostManagerTestWebUIControllerFactory | 95 class RenderFrameHostManagerTestWebUIControllerFactory |
| 95 : public WebUIControllerFactory { | 96 : public WebUIControllerFactory { |
| 96 public: | 97 public: |
| 97 RenderFrameHostManagerTestWebUIControllerFactory() | 98 RenderFrameHostManagerTestWebUIControllerFactory() |
| 98 : should_create_webui_(false), type_(1) { | 99 : should_create_webui_(false), type_(1) { |
| 99 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type_), WebUI::kNoWebUI); | 100 CHECK_NE(reinterpret_cast<WebUI::TypeID>(type_), WebUI::kNoWebUI); |
| 100 } | 101 } |
| (...skipping 2908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 // The RenderFrameHost committed. | 3010 // The RenderFrameHost committed. |
| 3010 manager->DidNavigateFrame(speculative_host, true); | 3011 manager->DidNavigateFrame(speculative_host, true); |
| 3011 EXPECT_EQ(speculative_host, manager->current_frame_host()); | 3012 EXPECT_EQ(speculative_host, manager->current_frame_host()); |
| 3012 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui()); | 3013 EXPECT_EQ(next_web_ui, manager->current_frame_host()->web_ui()); |
| 3013 EXPECT_FALSE(GetPendingFrameHost(manager)); | 3014 EXPECT_FALSE(GetPendingFrameHost(manager)); |
| 3014 EXPECT_FALSE(speculative_host->pending_web_ui()); | 3015 EXPECT_FALSE(speculative_host->pending_web_ui()); |
| 3015 EXPECT_FALSE(manager->GetNavigatingWebUI()); | 3016 EXPECT_FALSE(manager->GetNavigatingWebUI()); |
| 3016 } | 3017 } |
| 3017 | 3018 |
| 3018 // Tests that frame proxies receive updates when a frame's enforcement | 3019 // Tests that frame proxies receive updates when a frame's enforcement |
| 3019 // of strict mixed content checking changes. | 3020 // of insecure request policy changes. |
| 3020 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, | 3021 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, |
| 3021 ProxiesReceiveShouldEnforceStrictMixedContentChecking) { | 3022 ProxiesReceiveShouldEnforceInsecureRequestPolicy) { |
|
alexmos
2016/06/07 19:00:05
nit: can probably just shorten this to ProxiesRece
Mike West
2016/06/08 07:21:12
Done.
| |
| 3022 const GURL kUrl1("http://www.google.test"); | 3023 const GURL kUrl1("http://www.google.test"); |
| 3023 const GURL kUrl2("http://www.google2.test"); | 3024 const GURL kUrl2("http://www.google2.test"); |
| 3024 const GURL kUrl3("http://www.google2.test/foo"); | 3025 const GURL kUrl3("http://www.google2.test/foo"); |
| 3025 | 3026 |
| 3026 contents()->NavigateAndCommit(kUrl1); | 3027 contents()->NavigateAndCommit(kUrl1); |
| 3027 | 3028 |
| 3028 // Create a child frame and navigate it cross-site. | 3029 // Create a child frame and navigate it cross-site. |
| 3029 main_test_rfh()->OnCreateChildFrame( | 3030 main_test_rfh()->OnCreateChildFrame( |
| 3030 main_test_rfh()->GetProcess()->GetNextRoutingID(), | 3031 main_test_rfh()->GetProcess()->GetNextRoutingID(), |
| 3031 blink::WebTreeScopeType::Document, "frame1", "uniqueName1", | 3032 blink::WebTreeScopeType::Document, "frame1", "uniqueName1", |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 3043 TestRenderFrameHost* child_host = | 3044 TestRenderFrameHost* child_host = |
| 3044 static_cast<TestRenderFrameHost*>(NavigateToEntry(child, entry1)); | 3045 static_cast<TestRenderFrameHost*>(NavigateToEntry(child, entry1)); |
| 3045 child->DidNavigateFrame(child_host, true); | 3046 child->DidNavigateFrame(child_host, true); |
| 3046 | 3047 |
| 3047 // Verify that parent and child are in different processes. | 3048 // Verify that parent and child are in different processes. |
| 3048 EXPECT_NE(child_host->GetProcess(), main_test_rfh()->GetProcess()); | 3049 EXPECT_NE(child_host->GetProcess(), main_test_rfh()->GetProcess()); |
| 3049 | 3050 |
| 3050 // Change the parent's enforcement of strict mixed content checking, | 3051 // Change the parent's enforcement of strict mixed content checking, |
| 3051 // and check that the correct IPC is sent to the child frame's | 3052 // and check that the correct IPC is sent to the child frame's |
| 3052 // process. | 3053 // process. |
| 3053 EXPECT_FALSE(root->current_replication_state() | 3054 EXPECT_EQ(blink::kLeaveInsecureRequestsAlone, |
| 3054 .should_enforce_strict_mixed_content_checking); | 3055 root->current_replication_state().insecure_request_policy); |
| 3055 main_test_rfh()->DidEnforceStrictMixedContentChecking(); | 3056 main_test_rfh()->SetInsecureRequestPolicy(blink::kBlockAllMixedContent); |
|
alexmos
2016/06/07 19:00:05
DidEnforceInsecureRequestPolicy?
Mike West
2016/06/08 07:21:12
Done.
| |
| 3056 RenderFrameProxyHost* proxy_to_child = | 3057 RenderFrameProxyHost* proxy_to_child = |
| 3057 root->render_manager()->GetRenderFrameProxyHost( | 3058 root->render_manager()->GetRenderFrameProxyHost( |
| 3058 child_host->GetSiteInstance()); | 3059 child_host->GetSiteInstance()); |
| 3059 EXPECT_NO_FATAL_FAILURE( | 3060 EXPECT_NO_FATAL_FAILURE( |
| 3060 CheckMixedContentIPC(child_host, true, proxy_to_child->GetRoutingID())); | 3061 CheckInsecureRequestPolicyIPC(child_host, blink::kBlockAllMixedContent, |
| 3061 EXPECT_TRUE(root->current_replication_state() | 3062 proxy_to_child->GetRoutingID())); |
| 3062 .should_enforce_strict_mixed_content_checking); | 3063 EXPECT_EQ(blink::kBlockAllMixedContent, |
| 3064 root->current_replication_state().insecure_request_policy); | |
| 3063 | 3065 |
| 3064 // Do the same for the child's enforcement. In general, the parent | 3066 // Do the same for the child's enforcement. In general, the parent |
| 3065 // needs to know the status of the child's flag in case a grandchild | 3067 // needs to know the status of the child's flag in case a grandchild |
| 3066 // is created: if A.com embeds B.com, and B.com enforces strict mixed | 3068 // is created: if A.com embeds B.com, and B.com enforces strict mixed |
| 3067 // content checking, and B.com adds an iframe to A.com, then the | 3069 // content checking, and B.com adds an iframe to A.com, then the |
| 3068 // A.com process needs to know B.com's flag so that the grandchild | 3070 // A.com process needs to know B.com's flag so that the grandchild |
| 3069 // A.com frame can inherit it. | 3071 // A.com frame can inherit it. |
| 3070 EXPECT_FALSE(root->child_at(0) | 3072 EXPECT_EQ( |
| 3071 ->current_replication_state() | 3073 blink::kLeaveInsecureRequestsAlone, |
| 3072 .should_enforce_strict_mixed_content_checking); | 3074 root->child_at(0)->current_replication_state().insecure_request_policy); |
| 3073 child_host->DidEnforceStrictMixedContentChecking(); | 3075 child_host->SetInsecureRequestPolicy(blink::kBlockAllMixedContent); |
| 3074 RenderFrameProxyHost* proxy_to_parent = | 3076 RenderFrameProxyHost* proxy_to_parent = |
| 3075 child->GetRenderFrameProxyHost(main_test_rfh()->GetSiteInstance()); | 3077 child->GetRenderFrameProxyHost(main_test_rfh()->GetSiteInstance()); |
| 3076 EXPECT_NO_FATAL_FAILURE(CheckMixedContentIPC( | 3078 EXPECT_NO_FATAL_FAILURE(CheckInsecureRequestPolicyIPC( |
| 3077 main_test_rfh(), true, proxy_to_parent->GetRoutingID())); | 3079 main_test_rfh(), blink::kBlockAllMixedContent, |
| 3078 EXPECT_TRUE(root->child_at(0) | 3080 proxy_to_parent->GetRoutingID())); |
| 3079 ->current_replication_state() | 3081 EXPECT_EQ( |
| 3080 .should_enforce_strict_mixed_content_checking); | 3082 blink::kBlockAllMixedContent, |
| 3083 root->child_at(0)->current_replication_state().insecure_request_policy); | |
| 3081 | 3084 |
| 3082 // Check that the flag for the parent's proxy to the child is reset | 3085 // Check that the flag for the parent's proxy to the child is reset |
| 3083 // when the child navigates. | 3086 // when the child navigates. |
| 3084 main_test_rfh()->GetProcess()->sink().ClearMessages(); | 3087 main_test_rfh()->GetProcess()->sink().ClearMessages(); |
| 3085 FrameHostMsg_DidCommitProvisionalLoad_Params commit_params; | 3088 FrameHostMsg_DidCommitProvisionalLoad_Params commit_params; |
| 3086 commit_params.page_id = 0; | 3089 commit_params.page_id = 0; |
| 3087 commit_params.nav_entry_id = 0; | 3090 commit_params.nav_entry_id = 0; |
| 3088 commit_params.did_create_new_entry = false; | 3091 commit_params.did_create_new_entry = false; |
| 3089 commit_params.url = kUrl3; | 3092 commit_params.url = kUrl3; |
| 3090 commit_params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3093 commit_params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
| 3091 commit_params.should_update_history = false; | 3094 commit_params.should_update_history = false; |
| 3092 commit_params.gesture = NavigationGestureAuto; | 3095 commit_params.gesture = NavigationGestureAuto; |
| 3093 commit_params.was_within_same_page = false; | 3096 commit_params.was_within_same_page = false; |
| 3094 commit_params.method = "GET"; | 3097 commit_params.method = "GET"; |
| 3095 commit_params.page_state = PageState::CreateFromURL(kUrl3); | 3098 commit_params.page_state = PageState::CreateFromURL(kUrl3); |
| 3096 commit_params.should_enforce_strict_mixed_content_checking = false; | 3099 commit_params.insecure_request_policy = blink::kLeaveInsecureRequestsAlone; |
| 3097 child_host->SendNavigateWithParams(&commit_params); | 3100 child_host->SendNavigateWithParams(&commit_params); |
| 3098 EXPECT_NO_FATAL_FAILURE(CheckMixedContentIPC( | 3101 EXPECT_NO_FATAL_FAILURE(CheckInsecureRequestPolicyIPC( |
| 3099 main_test_rfh(), false, proxy_to_parent->GetRoutingID())); | 3102 main_test_rfh(), blink::kLeaveInsecureRequestsAlone, |
| 3100 EXPECT_FALSE(root->child_at(0) | 3103 proxy_to_parent->GetRoutingID())); |
| 3101 ->current_replication_state() | 3104 EXPECT_EQ( |
| 3102 .should_enforce_strict_mixed_content_checking); | 3105 blink::kLeaveInsecureRequestsAlone, |
| 3106 root->child_at(0)->current_replication_state().insecure_request_policy); | |
| 3103 } | 3107 } |
| 3104 | 3108 |
| 3105 } // namespace content | 3109 } // namespace content |
| OLD | NEW |