Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 709 |
| 710 protected: | 710 protected: |
| 711 void SetUpCommandLine(base::CommandLine* command_line) override { | 711 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 712 SitePerProcessBrowserTest::SetUpCommandLine(command_line); | 712 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| 713 // TODO(iclelland): Remove this switch when Feature Policy ships. | 713 // TODO(iclelland): Remove this switch when Feature Policy ships. |
| 714 // https://crbug.com/623682 | 714 // https://crbug.com/623682 |
| 715 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 715 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 716 "FeaturePolicy"); | 716 "FeaturePolicy"); |
| 717 } | 717 } |
| 718 | 718 |
| 719 ParsedFeaturePolicyHeader CreateFPHeader(const std::string& feature_name, | 719 ParsedFeaturePolicyHeader CreateFPHeader( |
| 720 const std::vector<GURL>& origins) { | 720 const blink::WebFeaturePolicyFeature feature, |
|
pfeldman
2017/03/17 01:12:20
drop the const - it is a value type enum
| |
| 721 const std::vector<GURL>& origins) { | |
| 721 ParsedFeaturePolicyHeader result(1); | 722 ParsedFeaturePolicyHeader result(1); |
| 722 result[0].feature_name = feature_name; | 723 result[0].feature = feature; |
| 723 result[0].matches_all_origins = false; | 724 result[0].matches_all_origins = false; |
| 724 DCHECK(!origins.empty()); | 725 DCHECK(!origins.empty()); |
| 725 for (const GURL& origin : origins) | 726 for (const GURL& origin : origins) |
| 726 result[0].origins.push_back(url::Origin(origin)); | 727 result[0].origins.push_back(url::Origin(origin)); |
| 727 return result; | 728 return result; |
| 728 } | 729 } |
| 729 | 730 |
| 730 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( | 731 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( |
| 731 const std::string& feature_name) { | 732 const blink::WebFeaturePolicyFeature feature) { |
|
pfeldman
2017/03/17 01:12:20
ditto
| |
| 732 ParsedFeaturePolicyHeader result(1); | 733 ParsedFeaturePolicyHeader result(1); |
| 733 result[0].feature_name = feature_name; | 734 result[0].feature = feature; |
| 734 result[0].matches_all_origins = true; | 735 result[0].matches_all_origins = true; |
| 735 return result; | 736 return result; |
| 736 } | 737 } |
| 737 }; | 738 }; |
| 738 | 739 |
| 739 bool operator==(const ParsedFeaturePolicyDeclaration& first, | 740 bool operator==(const ParsedFeaturePolicyDeclaration& first, |
| 740 const ParsedFeaturePolicyDeclaration& second) { | 741 const ParsedFeaturePolicyDeclaration& second) { |
| 741 return std::tie(first.feature_name, first.matches_all_origins, | 742 return std::tie(first.feature, first.matches_all_origins, first.origins) == |
| 742 first.origins) == std::tie(second.feature_name, | 743 std::tie(second.feature, second.matches_all_origins, second.origins); |
| 743 second.matches_all_origins, | |
| 744 second.origins); | |
| 745 } | 744 } |
| 746 | 745 |
| 747 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, | 746 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
| 748 SubframeLoadsWithCorrectDeviceScaleFactor) { | 747 SubframeLoadsWithCorrectDeviceScaleFactor) { |
| 749 GURL main_url(embedded_test_server()->GetURL( | 748 GURL main_url(embedded_test_server()->GetURL( |
| 750 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 749 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 751 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 750 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 752 | 751 |
| 753 // On Android forcing device scale factor does not work for tests, therefore | 752 // On Android forcing device scale factor does not work for tests, therefore |
| 754 // we ensure that make frame and iframe have the same DIP scale there, but | 753 // we ensure that make frame and iframe have the same DIP scale there, but |
| (...skipping 8328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9083 TestFeaturePolicyReplicationOnSameOriginNavigation) { | 9082 TestFeaturePolicyReplicationOnSameOriginNavigation) { |
| 9084 GURL start_url( | 9083 GURL start_url( |
| 9085 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 9084 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 9086 GURL first_nav_url( | 9085 GURL first_nav_url( |
| 9087 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); | 9086 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); |
| 9088 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); | 9087 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); |
| 9089 | 9088 |
| 9090 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 9089 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 9091 | 9090 |
| 9092 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 9091 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 9093 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), | 9092 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 9093 {start_url.GetOrigin()}), | |
| 9094 root->current_replication_state().feature_policy_header); | 9094 root->current_replication_state().feature_policy_header); |
| 9095 | 9095 |
| 9096 // When the main frame navigates to a page with a new policy, it should | 9096 // When the main frame navigates to a page with a new policy, it should |
| 9097 // overwrite the old one. | 9097 // overwrite the old one. |
| 9098 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 9098 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 9099 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), | 9099 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
| 9100 root->current_replication_state().feature_policy_header); | 9100 root->current_replication_state().feature_policy_header); |
| 9101 | 9101 |
| 9102 // When the main frame navigates to a page without a policy, the replicated | 9102 // When the main frame navigates to a page without a policy, the replicated |
| 9103 // policy header should be cleared. | 9103 // policy header should be cleared. |
| 9104 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 9104 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 9105 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); | 9105 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
| 9106 } | 9106 } |
| 9107 | 9107 |
| 9108 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 9108 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 9109 TestFeaturePolicyReplicationOnCrossOriginNavigation) { | 9109 TestFeaturePolicyReplicationOnCrossOriginNavigation) { |
| 9110 GURL start_url( | 9110 GURL start_url( |
| 9111 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 9111 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 9112 GURL first_nav_url( | 9112 GURL first_nav_url( |
| 9113 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 9113 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 9114 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 9114 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 9115 | 9115 |
| 9116 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 9116 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 9117 | 9117 |
| 9118 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 9118 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 9119 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), | 9119 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 9120 {start_url.GetOrigin()}), | |
| 9120 root->current_replication_state().feature_policy_header); | 9121 root->current_replication_state().feature_policy_header); |
| 9121 | 9122 |
| 9122 // When the main frame navigates to a page with a new policy, it should | 9123 // When the main frame navigates to a page with a new policy, it should |
| 9123 // overwrite the old one. | 9124 // overwrite the old one. |
| 9124 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 9125 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 9125 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), | 9126 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
| 9126 root->current_replication_state().feature_policy_header); | 9127 root->current_replication_state().feature_policy_header); |
| 9127 | 9128 |
| 9128 // When the main frame navigates to a page without a policy, the replicated | 9129 // When the main frame navigates to a page without a policy, the replicated |
| 9129 // policy header should be cleared. | 9130 // policy header should be cleared. |
| 9130 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 9131 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 9131 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); | 9132 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
| 9132 } | 9133 } |
| 9133 | 9134 |
| 9134 // Test that the replicated feature policy header is correct in subframes as | 9135 // Test that the replicated feature policy header is correct in subframes as |
| 9135 // they navigate. | 9136 // they navigate. |
| 9136 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 9137 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 9137 TestFeaturePolicyReplicationFromRemoteFrames) { | 9138 TestFeaturePolicyReplicationFromRemoteFrames) { |
| 9138 GURL main_url( | 9139 GURL main_url( |
| 9139 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); | 9140 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); |
| 9140 GURL first_nav_url( | 9141 GURL first_nav_url( |
| 9141 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 9142 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 9142 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 9143 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 9143 | 9144 |
| 9144 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 9145 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 9145 | 9146 |
| 9146 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 9147 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 9147 EXPECT_EQ(CreateFPHeader("vibrate", | 9148 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 9148 {main_url.GetOrigin(), GURL("http://example.com/")}), | 9149 {main_url.GetOrigin(), GURL("http://example.com/")}), |
| 9149 root->current_replication_state().feature_policy_header); | 9150 root->current_replication_state().feature_policy_header); |
| 9150 EXPECT_EQ(1UL, root->child_count()); | 9151 EXPECT_EQ(1UL, root->child_count()); |
| 9151 EXPECT_EQ( | 9152 EXPECT_EQ( |
| 9152 CreateFPHeader("vibrate", {main_url.GetOrigin()}), | 9153 CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 9154 {main_url.GetOrigin()}), | |
| 9153 root->child_at(0)->current_replication_state().feature_policy_header); | 9155 root->child_at(0)->current_replication_state().feature_policy_header); |
| 9154 | 9156 |
| 9155 // Navigate the iframe cross-site. | 9157 // Navigate the iframe cross-site. |
| 9156 NavigateFrameToURL(root->child_at(0), first_nav_url); | 9158 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 9157 EXPECT_EQ( | 9159 EXPECT_EQ( |
| 9158 CreateFPHeaderMatchesAll("vibrate"), | 9160 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
| 9159 root->child_at(0)->current_replication_state().feature_policy_header); | 9161 root->child_at(0)->current_replication_state().feature_policy_header); |
| 9160 | 9162 |
| 9161 // Navigate the iframe to another location, this one with no policy header | 9163 // Navigate the iframe to another location, this one with no policy header |
| 9162 NavigateFrameToURL(root->child_at(0), second_nav_url); | 9164 NavigateFrameToURL(root->child_at(0), second_nav_url); |
| 9163 EXPECT_TRUE(root->child_at(0) | 9165 EXPECT_TRUE(root->child_at(0) |
| 9164 ->current_replication_state() | 9166 ->current_replication_state() |
| 9165 .feature_policy_header.empty()); | 9167 .feature_policy_header.empty()); |
| 9166 | 9168 |
| 9167 // Navigate the iframe back to a page with a policy | 9169 // Navigate the iframe back to a page with a policy |
| 9168 NavigateFrameToURL(root->child_at(0), first_nav_url); | 9170 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 9169 EXPECT_EQ( | 9171 EXPECT_EQ( |
| 9170 CreateFPHeaderMatchesAll("vibrate"), | 9172 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
| 9171 root->child_at(0)->current_replication_state().feature_policy_header); | 9173 root->child_at(0)->current_replication_state().feature_policy_header); |
| 9172 } | 9174 } |
| 9173 | 9175 |
| 9174 // Ensure that an iframe that navigates cross-site doesn't use the same process | 9176 // Ensure that an iframe that navigates cross-site doesn't use the same process |
| 9175 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, | 9177 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, |
| 9176 // it must reuse its parent's process. | 9178 // it must reuse its parent's process. |
| 9177 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 9179 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 9178 IframeSrcdocAfterCrossSiteNavigation) { | 9180 IframeSrcdocAfterCrossSiteNavigation) { |
| 9179 GURL parent_url(embedded_test_server()->GetURL( | 9181 GURL parent_url(embedded_test_server()->GetURL( |
| 9180 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 9182 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9795 | 9797 |
| 9796 // Try the same navigation, but use the browser-initiated path. | 9798 // Try the same navigation, but use the browser-initiated path. |
| 9797 NavigateFrameToURL(root->child_at(0), frame_url); | 9799 NavigateFrameToURL(root->child_at(0), frame_url); |
| 9798 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); | 9800 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); |
| 9799 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); | 9801 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); |
| 9800 EXPECT_EQ(b_site_instance, | 9802 EXPECT_EQ(b_site_instance, |
| 9801 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 9803 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 9802 } | 9804 } |
| 9803 | 9805 |
| 9804 } // namespace content | 9806 } // namespace content |
| OLD | NEW |