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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 SitePerProcessFeaturePolicyBrowserTest() {} | 628 SitePerProcessFeaturePolicyBrowserTest() {} |
629 | 629 |
630 protected: | 630 protected: |
631 void SetUpCommandLine(base::CommandLine* command_line) override { | 631 void SetUpCommandLine(base::CommandLine* command_line) override { |
632 SitePerProcessBrowserTest::SetUpCommandLine(command_line); | 632 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
633 // TODO(iclelland): Remove this switch when Feature Policy ships. | 633 // TODO(iclelland): Remove this switch when Feature Policy ships. |
634 // https://crbug.com/623682 | 634 // https://crbug.com/623682 |
635 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 635 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
636 "FeaturePolicy"); | 636 "FeaturePolicy"); |
637 } | 637 } |
| 638 |
| 639 ParsedFeaturePolicy CreateFPHeader(const std::string& feature_name, |
| 640 const std::vector<GURL>& origins) { |
| 641 ParsedFeaturePolicy result(1); |
| 642 result[0].feature_name = feature_name; |
| 643 result[0].matches_all_origins = false; |
| 644 DCHECK(!origins.empty()); |
| 645 for (const GURL& origin : origins) |
| 646 result[0].origins.push_back(url::Origin(origin)); |
| 647 return result; |
| 648 } |
| 649 |
| 650 ParsedFeaturePolicy CreateFPHeaderMatchesAll( |
| 651 const std::string& feature_name) { |
| 652 ParsedFeaturePolicy result(1); |
| 653 result[0].feature_name = feature_name; |
| 654 result[0].matches_all_origins = true; |
| 655 return result; |
| 656 } |
638 }; | 657 }; |
639 | 658 |
| 659 bool operator==(const FeaturePolicyParsedWhitelist& first, |
| 660 const FeaturePolicyParsedWhitelist& second) { |
| 661 return std::tie(first.feature_name, first.matches_all_origins, |
| 662 first.origins) == std::tie(second.feature_name, |
| 663 second.matches_all_origins, |
| 664 second.origins); |
| 665 } |
| 666 |
640 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { | 667 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
641 double device_scale_factor; | 668 double device_scale_factor; |
642 const char kGetFrameDeviceScaleFactor[] = | 669 const char kGetFrameDeviceScaleFactor[] = |
643 "window.domAutomationController.send(window.devicePixelRatio);"; | 670 "window.domAutomationController.send(window.devicePixelRatio);"; |
644 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, | 671 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, |
645 &device_scale_factor)); | 672 &device_scale_factor)); |
646 return device_scale_factor; | 673 return device_scale_factor; |
647 } | 674 } |
648 | 675 |
649 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, | 676 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
(...skipping 8029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8679 TestFeaturePolicyReplicationOnSameOriginNavigation) { | 8706 TestFeaturePolicyReplicationOnSameOriginNavigation) { |
8680 GURL start_url( | 8707 GURL start_url( |
8681 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8708 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
8682 GURL first_nav_url( | 8709 GURL first_nav_url( |
8683 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); | 8710 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); |
8684 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); | 8711 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); |
8685 | 8712 |
8686 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8713 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
8687 | 8714 |
8688 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8715 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8689 EXPECT_EQ("{\"vibrate\":[\"self\"]}", | 8716 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), |
8690 root->current_replication_state().feature_policy_header); | 8717 root->current_replication_state().feature_policy_header); |
8691 | 8718 |
8692 // When the main frame navigates to a page with a new policy, it should | 8719 // When the main frame navigates to a page with a new policy, it should |
8693 // overwrite the old one. | 8720 // overwrite the old one. |
8694 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8721 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
8695 EXPECT_EQ("{\"vibrate\":[\"*\"]}", | 8722 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), |
8696 root->current_replication_state().feature_policy_header); | 8723 root->current_replication_state().feature_policy_header); |
8697 | 8724 |
8698 // When the main frame navigates to a page without a policy, the replicated | 8725 // When the main frame navigates to a page without a policy, the replicated |
8699 // policy header should be cleared. | 8726 // policy header should be cleared. |
8700 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8727 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
8701 EXPECT_EQ("", root->current_replication_state().feature_policy_header); | 8728 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
8702 } | 8729 } |
8703 | 8730 |
8704 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8731 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
8705 TestFeaturePolicyReplicationOnCrossOriginNavigation) { | 8732 TestFeaturePolicyReplicationOnCrossOriginNavigation) { |
8706 GURL start_url( | 8733 GURL start_url( |
8707 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8734 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
8708 GURL first_nav_url( | 8735 GURL first_nav_url( |
8709 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8736 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
8710 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8737 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
8711 | 8738 |
8712 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8739 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
8713 | 8740 |
8714 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8741 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8715 EXPECT_EQ("{\"vibrate\":[\"self\"]}", | 8742 EXPECT_EQ(CreateFPHeader("vibrate", {start_url.GetOrigin()}), |
8716 root->current_replication_state().feature_policy_header); | 8743 root->current_replication_state().feature_policy_header); |
8717 | 8744 |
8718 // When the main frame navigates to a page with a new policy, it should | 8745 // When the main frame navigates to a page with a new policy, it should |
8719 // overwrite the old one. | 8746 // overwrite the old one. |
8720 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8747 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
8721 EXPECT_EQ("{\"vibrate\":[\"*\"]}", | 8748 EXPECT_EQ(CreateFPHeaderMatchesAll("vibrate"), |
8722 root->current_replication_state().feature_policy_header); | 8749 root->current_replication_state().feature_policy_header); |
8723 | 8750 |
8724 // When the main frame navigates to a page without a policy, the replicated | 8751 // When the main frame navigates to a page without a policy, the replicated |
8725 // policy header should be cleared. | 8752 // policy header should be cleared. |
8726 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8753 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
8727 EXPECT_EQ("", root->current_replication_state().feature_policy_header); | 8754 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
8728 } | 8755 } |
8729 | 8756 |
8730 // Test that the replicated feature policy header is correct in subframes as | 8757 // Test that the replicated feature policy header is correct in subframes as |
8731 // they navigate. | 8758 // they navigate. |
8732 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8759 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
8733 TestFeaturePolicyReplicationFromRemoteFrames) { | 8760 TestFeaturePolicyReplicationFromRemoteFrames) { |
8734 GURL main_url( | 8761 GURL main_url( |
8735 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); | 8762 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); |
8736 GURL first_nav_url( | 8763 GURL first_nav_url( |
8737 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8764 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
8738 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8765 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
8739 | 8766 |
8740 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 8767 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
8741 | 8768 |
8742 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8769 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
8743 EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}", | 8770 EXPECT_EQ(CreateFPHeader("vibrate", |
| 8771 {main_url.GetOrigin(), GURL("http://example.com/")}), |
8744 root->current_replication_state().feature_policy_header); | 8772 root->current_replication_state().feature_policy_header); |
8745 EXPECT_EQ(1UL, root->child_count()); | 8773 EXPECT_EQ(1UL, root->child_count()); |
8746 EXPECT_EQ( | 8774 EXPECT_EQ( |
8747 "{\"vibrate\":[\"self\"]}", | 8775 CreateFPHeader("vibrate", {main_url.GetOrigin()}), |
8748 root->child_at(0)->current_replication_state().feature_policy_header); | 8776 root->child_at(0)->current_replication_state().feature_policy_header); |
8749 | 8777 |
8750 // Navigate the iframe cross-site. | 8778 // Navigate the iframe cross-site. |
8751 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8779 NavigateFrameToURL(root->child_at(0), first_nav_url); |
8752 EXPECT_EQ( | 8780 EXPECT_EQ( |
8753 "{\"vibrate\":[\"*\"]}", | 8781 CreateFPHeaderMatchesAll("vibrate"), |
8754 root->child_at(0)->current_replication_state().feature_policy_header); | 8782 root->child_at(0)->current_replication_state().feature_policy_header); |
8755 | 8783 |
8756 // Navigate the iframe to another location, this one with no policy header | 8784 // Navigate the iframe to another location, this one with no policy header |
8757 NavigateFrameToURL(root->child_at(0), second_nav_url); | 8785 NavigateFrameToURL(root->child_at(0), second_nav_url); |
8758 EXPECT_EQ( | 8786 EXPECT_TRUE(root->child_at(0) |
8759 "", root->child_at(0)->current_replication_state().feature_policy_header); | 8787 ->current_replication_state() |
| 8788 .feature_policy_header.empty()); |
8760 | 8789 |
8761 // Navigate the iframe back to a page with a policy | 8790 // Navigate the iframe back to a page with a policy |
8762 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8791 NavigateFrameToURL(root->child_at(0), first_nav_url); |
8763 EXPECT_EQ( | 8792 EXPECT_EQ( |
8764 "{\"vibrate\":[\"*\"]}", | 8793 CreateFPHeaderMatchesAll("vibrate"), |
8765 root->child_at(0)->current_replication_state().feature_policy_header); | 8794 root->child_at(0)->current_replication_state().feature_policy_header); |
8766 } | 8795 } |
8767 | 8796 |
8768 // Ensure that an iframe that navigates cross-site doesn't use the same process | 8797 // Ensure that an iframe that navigates cross-site doesn't use the same process |
8769 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, | 8798 // as its parent. Then when its parent navigates it via the "srcdoc" attribute, |
8770 // it must reuse its parent's process. | 8799 // it must reuse its parent's process. |
8771 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 8800 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
8772 IframeSrcdocAfterCrossSiteNavigation) { | 8801 IframeSrcdocAfterCrossSiteNavigation) { |
8773 GURL parent_url(embedded_test_server()->GetURL( | 8802 GURL parent_url(embedded_test_server()->GetURL( |
8774 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 8803 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
(...skipping 23 matching lines...) Expand all Loading... |
8798 | 8827 |
8799 // Ensure that the iframe reuses its parent's process. | 8828 // Ensure that the iframe reuses its parent's process. |
8800 EXPECT_EQ(blank_url, child->current_url()); | 8829 EXPECT_EQ(blank_url, child->current_url()); |
8801 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(), | 8830 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(), |
8802 child->current_frame_host()->GetSiteInstance()); | 8831 child->current_frame_host()->GetSiteInstance()); |
8803 EXPECT_EQ(root->current_frame_host()->GetProcess(), | 8832 EXPECT_EQ(root->current_frame_host()->GetProcess(), |
8804 child->current_frame_host()->GetProcess()); | 8833 child->current_frame_host()->GetProcess()); |
8805 } | 8834 } |
8806 | 8835 |
8807 } // namespace content | 8836 } // namespace content |
OLD | NEW |