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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 671 |
672 protected: | 672 protected: |
673 void SetUpCommandLine(base::CommandLine* command_line) override { | 673 void SetUpCommandLine(base::CommandLine* command_line) override { |
674 SitePerProcessBrowserTest::SetUpCommandLine(command_line); | 674 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
675 // TODO(iclelland): Remove this switch when Feature Policy ships. | 675 // TODO(iclelland): Remove this switch when Feature Policy ships. |
676 // https://crbug.com/623682 | 676 // https://crbug.com/623682 |
677 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 677 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
678 "FeaturePolicy"); | 678 "FeaturePolicy"); |
679 } | 679 } |
680 | 680 |
681 ParsedFeaturePolicyHeader CreateFPHeader(const std::string& feature_name, | 681 ParsedFeaturePolicyHeader CreateFPHeader( |
682 const std::vector<GURL>& origins) { | 682 const blink::WebFeaturePolicyFeature feature, |
| 683 const std::vector<GURL>& origins) { |
683 ParsedFeaturePolicyHeader result(1); | 684 ParsedFeaturePolicyHeader result(1); |
684 result[0].feature_name = feature_name; | 685 result[0].feature = feature; |
685 result[0].matches_all_origins = false; | 686 result[0].matches_all_origins = false; |
686 DCHECK(!origins.empty()); | 687 DCHECK(!origins.empty()); |
687 for (const GURL& origin : origins) | 688 for (const GURL& origin : origins) |
688 result[0].origins.push_back(url::Origin(origin)); | 689 result[0].origins.push_back(url::Origin(origin)); |
689 return result; | 690 return result; |
690 } | 691 } |
691 | 692 |
692 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( | 693 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( |
693 const std::string& feature_name) { | 694 const blink::WebFeaturePolicyFeature feature) { |
694 ParsedFeaturePolicyHeader result(1); | 695 ParsedFeaturePolicyHeader result(1); |
695 result[0].feature_name = feature_name; | 696 result[0].feature = feature; |
696 result[0].matches_all_origins = true; | 697 result[0].matches_all_origins = true; |
697 return result; | 698 return result; |
698 } | 699 } |
699 }; | 700 }; |
700 | 701 |
701 bool operator==(const ParsedFeaturePolicyDeclaration& first, | 702 bool operator==(const ParsedFeaturePolicyDeclaration& first, |
702 const ParsedFeaturePolicyDeclaration& second) { | 703 const ParsedFeaturePolicyDeclaration& second) { |
703 return std::tie(first.feature_name, first.matches_all_origins, | 704 return std::tie(first.feature, first.matches_all_origins, first.origins) == |
704 first.origins) == std::tie(second.feature_name, | 705 std::tie(second.feature, second.matches_all_origins, second.origins); |
705 second.matches_all_origins, | |
706 second.origins); | |
707 } | 706 } |
708 | 707 |
709 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { | 708 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
710 double device_scale_factor; | 709 double device_scale_factor; |
711 const char kGetFrameDeviceScaleFactor[] = | 710 const char kGetFrameDeviceScaleFactor[] = |
712 "window.domAutomationController.send(window.devicePixelRatio);"; | 711 "window.domAutomationController.send(window.devicePixelRatio);"; |
713 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, | 712 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, |
714 &device_scale_factor)); | 713 &device_scale_factor)); |
715 return device_scale_factor; | 714 return device_scale_factor; |
716 } | 715 } |
(...skipping 8146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8863 TestFeaturePolicyReplicationOnSameOriginNavigation) { | 8862 TestFeaturePolicyReplicationOnSameOriginNavigation) { |
8864 GURL start_url( | 8863 GURL start_url( |
8865 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8864 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
8866 GURL first_nav_url( | 8865 GURL first_nav_url( |
8867 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); | 8866 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); |
8868 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); | 8867 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); |
8869 | 8868 |
8870 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8869 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
8871 | 8870 |
8872 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8871 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8873 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), | 8872 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 8873 {start_url.GetOrigin()}), |
8874 root->current_replication_state().feature_policy_header); | 8874 root->current_replication_state().feature_policy_header); |
8875 | 8875 |
8876 // When the main frame navigates to a page with a new policy, it should | 8876 // When the main frame navigates to a page with a new policy, it should |
8877 // overwrite the old one. | 8877 // overwrite the old one. |
8878 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8878 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
8879 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), | 8879 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
8880 root->current_replication_state().feature_policy_header); | 8880 root->current_replication_state().feature_policy_header); |
8881 | 8881 |
8882 // When the main frame navigates to a page without a policy, the replicated | 8882 // When the main frame navigates to a page without a policy, the replicated |
8883 // policy header should be cleared. | 8883 // policy header should be cleared. |
8884 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8884 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
8885 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); | 8885 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
8886 } | 8886 } |
8887 | 8887 |
8888 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8888 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
8889 TestFeaturePolicyReplicationOnCrossOriginNavigation) { | 8889 TestFeaturePolicyReplicationOnCrossOriginNavigation) { |
8890 GURL start_url( | 8890 GURL start_url( |
8891 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8891 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
8892 GURL first_nav_url( | 8892 GURL first_nav_url( |
8893 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8893 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
8894 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8894 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
8895 | 8895 |
8896 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8896 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
8897 | 8897 |
8898 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8898 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8899 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), | 8899 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 8900 {start_url.GetOrigin()}), |
8900 root->current_replication_state().feature_policy_header); | 8901 root->current_replication_state().feature_policy_header); |
8901 | 8902 |
8902 // When the main frame navigates to a page with a new policy, it should | 8903 // When the main frame navigates to a page with a new policy, it should |
8903 // overwrite the old one. | 8904 // overwrite the old one. |
8904 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8905 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
8905 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), | 8906 EXPECT_EQ(CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
8906 root->current_replication_state().feature_policy_header); | 8907 root->current_replication_state().feature_policy_header); |
8907 | 8908 |
8908 // When the main frame navigates to a page without a policy, the replicated | 8909 // When the main frame navigates to a page without a policy, the replicated |
8909 // policy header should be cleared. | 8910 // policy header should be cleared. |
8910 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8911 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
8911 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); | 8912 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
8912 } | 8913 } |
8913 | 8914 |
8914 // Test that the replicated feature policy header is correct in subframes as | 8915 // Test that the replicated feature policy header is correct in subframes as |
8915 // they navigate. | 8916 // they navigate. |
8916 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8917 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
8917 TestFeaturePolicyReplicationFromRemoteFrames) { | 8918 TestFeaturePolicyReplicationFromRemoteFrames) { |
8918 GURL main_url( | 8919 GURL main_url( |
8919 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); | 8920 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); |
8920 GURL first_nav_url( | 8921 GURL first_nav_url( |
8921 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8922 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
8922 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8923 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
8923 | 8924 |
8924 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 8925 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
8925 | 8926 |
8926 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8927 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8927 EXPECT_EQ(CreateFPHeader("vibrate", | 8928 EXPECT_EQ(CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
8928 {main_url.GetOrigin(), GURL("http://example.com/")}), | 8929 {main_url.GetOrigin(), GURL("http://example.com/")}), |
8929 root->current_replication_state().feature_policy_header); | 8930 root->current_replication_state().feature_policy_header); |
8930 EXPECT_EQ(1UL, root->child_count()); | 8931 EXPECT_EQ(1UL, root->child_count()); |
8931 EXPECT_EQ( | 8932 EXPECT_EQ( |
8932 CreateFPHeader("vibrate", {main_url.GetOrigin()}), | 8933 CreateFPHeader(blink::WebFeaturePolicyFeature::Vibrate, |
| 8934 {main_url.GetOrigin()}), |
8933 root->child_at(0)->current_replication_state().feature_policy_header); | 8935 root->child_at(0)->current_replication_state().feature_policy_header); |
8934 | 8936 |
8935 // Navigate the iframe cross-site. | 8937 // Navigate the iframe cross-site. |
8936 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8938 NavigateFrameToURL(root->child_at(0), first_nav_url); |
8937 EXPECT_EQ( | 8939 EXPECT_EQ( |
8938 CreateFPHeaderMatchesAll("vibrate"), | 8940 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
8939 root->child_at(0)->current_replication_state().feature_policy_header); | 8941 root->child_at(0)->current_replication_state().feature_policy_header); |
8940 | 8942 |
8941 // Navigate the iframe to another location, this one with no policy header | 8943 // Navigate the iframe to another location, this one with no policy header |
8942 NavigateFrameToURL(root->child_at(0), second_nav_url); | 8944 NavigateFrameToURL(root->child_at(0), second_nav_url); |
8943 EXPECT_TRUE(root->child_at(0) | 8945 EXPECT_TRUE(root->child_at(0) |
8944 ->current_replication_state() | 8946 ->current_replication_state() |
8945 .feature_policy_header.empty()); | 8947 .feature_policy_header.empty()); |
8946 | 8948 |
8947 // Navigate the iframe back to a page with a policy | 8949 // Navigate the iframe back to a page with a policy |
8948 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8950 NavigateFrameToURL(root->child_at(0), first_nav_url); |
8949 EXPECT_EQ( | 8951 EXPECT_EQ( |
8950 CreateFPHeaderMatchesAll("vibrate"), | 8952 CreateFPHeaderMatchesAll(blink::WebFeaturePolicyFeature::Vibrate), |
8951 root->child_at(0)->current_replication_state().feature_policy_header); | 8953 root->child_at(0)->current_replication_state().feature_policy_header); |
8952 } | 8954 } |
8953 | 8955 |
8954 // Ensure that an iframe that navigates cross-site doesn't use the same process | 8956 // Ensure that an iframe that navigates cross-site doesn't use the same process |
8955 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, | 8957 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, |
8956 // it must reuse its parent's process. | 8958 // it must reuse its parent's process. |
8957 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 8959 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
8958 IframeSrcdocAfterCrossSiteNavigation) { | 8960 IframeSrcdocAfterCrossSiteNavigation) { |
8959 GURL parent_url(embedded_test_server()->GetURL( | 8961 GURL parent_url(embedded_test_server()->GetURL( |
8960 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 8962 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9576 | 9578 |
9577 // Try the same navigation, but use the browser-initiated path. | 9579 // Try the same navigation, but use the browser-initiated path. |
9578 NavigateFrameToURL(root->child_at(0), frame_url); | 9580 NavigateFrameToURL(root->child_at(0), frame_url); |
9579 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); | 9581 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); |
9580 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); | 9582 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); |
9581 EXPECT_EQ(b_site_instance, | 9583 EXPECT_EQ(b_site_instance, |
9582 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 9584 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
9583 } | 9585 } |
9584 | 9586 |
9585 } // namespace content | 9587 } // namespace content |
OLD | NEW |