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 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 std::string GetOrigin(const GURL& url) { | |
| 640 std::string result = url.GetOrigin().spec(); | |
| 641 // Trim trailing / which doesn't appear in expected output. | |
| 642 base::TrimString(result, "/", &result); | |
| 643 return result; | |
| 644 } | |
| 645 | |
| 646 std::vector<FeaturePolicyParsedWhitelist> CreateExpectedFeaturePolicyHeader( | |
| 647 const std::string& feature_name, | |
| 648 bool matches_all_origins, | |
| 649 const std::vector<std::string>& origins) { | |
| 650 std::vector<FeaturePolicyParsedWhitelist> result(1); | |
| 651 result[0].feature_name = feature_name; | |
| 652 result[0].matches_all_origins = matches_all_origins; | |
| 653 result[0].origins = origins; | |
| 654 return result; | |
| 655 } | |
| 638 }; | 656 }; |
| 639 | 657 |
| 658 bool operator==(const FeaturePolicyParsedWhitelist& first, | |
| 659 const FeaturePolicyParsedWhitelist& second) { | |
| 660 if (first.feature_name != second.feature_name || | |
|
iclelland
2016/11/23 20:20:28
Can this be written as
std::tie(first.feature_nam
raymes
2016/11/29 08:20:34
Done.
| |
| 661 first.matches_all_origins != second.matches_all_origins || | |
| 662 first.origins.size() != second.origins.size() || | |
| 663 !std::equal(first.origins.begin(), first.origins.end(), | |
| 664 second.origins.begin())) { | |
| 665 return false; | |
| 666 } | |
| 667 return true; | |
| 668 } | |
| 669 | |
| 640 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { | 670 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
| 641 double device_scale_factor; | 671 double device_scale_factor; |
| 642 const char kGetFrameDeviceScaleFactor[] = | 672 const char kGetFrameDeviceScaleFactor[] = |
| 643 "window.domAutomationController.send(window.devicePixelRatio);"; | 673 "window.domAutomationController.send(window.devicePixelRatio);"; |
| 644 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, | 674 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, |
| 645 &device_scale_factor)); | 675 &device_scale_factor)); |
| 646 return device_scale_factor; | 676 return device_scale_factor; |
| 647 } | 677 } |
| 648 | 678 |
| 649 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, | 679 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
| (...skipping 8029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8679 TestFeaturePolicyReplicationOnSameOriginNavigation) { | 8709 TestFeaturePolicyReplicationOnSameOriginNavigation) { |
| 8680 GURL start_url( | 8710 GURL start_url( |
| 8681 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8711 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 8682 GURL first_nav_url( | 8712 GURL first_nav_url( |
| 8683 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); | 8713 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); |
| 8684 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); | 8714 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); |
| 8685 | 8715 |
| 8686 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8716 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 8687 | 8717 |
| 8688 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8718 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8689 EXPECT_EQ("{\"vibrate\":[\"self\"]}", | 8719 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false, |
| 8720 {GetOrigin(start_url)}), | |
| 8690 root->current_replication_state().feature_policy_header); | 8721 root->current_replication_state().feature_policy_header); |
| 8691 | 8722 |
| 8692 // When the main frame navigates to a page with a new policy, it should | 8723 // When the main frame navigates to a page with a new policy, it should |
| 8693 // overwrite the old one. | 8724 // overwrite the old one. |
| 8694 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8725 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 8695 EXPECT_EQ("{\"vibrate\":[\"*\"]}", | 8726 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true, |
| 8727 std::vector<std::string>()), | |
| 8696 root->current_replication_state().feature_policy_header); | 8728 root->current_replication_state().feature_policy_header); |
| 8697 | 8729 |
| 8698 // When the main frame navigates to a page without a policy, the replicated | 8730 // When the main frame navigates to a page without a policy, the replicated |
| 8699 // policy header should be cleared. | 8731 // policy header should be cleared. |
| 8700 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8732 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 8701 EXPECT_EQ("", root->current_replication_state().feature_policy_header); | 8733 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
| 8702 } | 8734 } |
| 8703 | 8735 |
| 8704 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8736 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 8705 TestFeaturePolicyReplicationOnCrossOriginNavigation) { | 8737 TestFeaturePolicyReplicationOnCrossOriginNavigation) { |
| 8706 GURL start_url( | 8738 GURL start_url( |
| 8707 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); | 8739 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 8708 GURL first_nav_url( | 8740 GURL first_nav_url( |
| 8709 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8741 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 8710 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8742 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 8711 | 8743 |
| 8712 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 8744 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 8713 | 8745 |
| 8714 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8746 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8715 EXPECT_EQ("{\"vibrate\":[\"self\"]}", | 8747 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false, |
| 8748 {GetOrigin(start_url)}), | |
| 8716 root->current_replication_state().feature_policy_header); | 8749 root->current_replication_state().feature_policy_header); |
| 8717 | 8750 |
| 8718 // When the main frame navigates to a page with a new policy, it should | 8751 // When the main frame navigates to a page with a new policy, it should |
| 8719 // overwrite the old one. | 8752 // overwrite the old one. |
| 8720 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); | 8753 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 8721 EXPECT_EQ("{\"vibrate\":[\"*\"]}", | 8754 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true, |
| 8755 std::vector<std::string>()), | |
| 8722 root->current_replication_state().feature_policy_header); | 8756 root->current_replication_state().feature_policy_header); |
| 8723 | 8757 |
| 8724 // When the main frame navigates to a page without a policy, the replicated | 8758 // When the main frame navigates to a page without a policy, the replicated |
| 8725 // policy header should be cleared. | 8759 // policy header should be cleared. |
| 8726 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); | 8760 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 8727 EXPECT_EQ("", root->current_replication_state().feature_policy_header); | 8761 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty()); |
| 8728 } | 8762 } |
| 8729 | 8763 |
| 8730 // Test that the replicated feature policy header is correct in subframes as | 8764 // Test that the replicated feature policy header is correct in subframes as |
| 8731 // they navigate. | 8765 // they navigate. |
| 8732 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, | 8766 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 8733 TestFeaturePolicyReplicationFromRemoteFrames) { | 8767 TestFeaturePolicyReplicationFromRemoteFrames) { |
| 8734 GURL main_url( | 8768 GURL main_url( |
| 8735 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); | 8769 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); |
| 8736 GURL first_nav_url( | 8770 GURL first_nav_url( |
| 8737 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); | 8771 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 8738 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 8772 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 8739 | 8773 |
| 8740 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 8774 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 8741 | 8775 |
| 8742 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 8776 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8743 EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}", | 8777 EXPECT_EQ(CreateExpectedFeaturePolicyHeader( |
| 8778 "vibrate", false, {GetOrigin(main_url), "http://example.com/"}), | |
| 8744 root->current_replication_state().feature_policy_header); | 8779 root->current_replication_state().feature_policy_header); |
| 8745 EXPECT_EQ(1UL, root->child_count()); | 8780 EXPECT_EQ(1UL, root->child_count()); |
| 8746 EXPECT_EQ( | 8781 EXPECT_EQ( |
| 8747 "{\"vibrate\":[\"self\"]}", | 8782 CreateExpectedFeaturePolicyHeader("vibrate", false, |
| 8783 {GetOrigin(main_url)}), | |
| 8748 root->child_at(0)->current_replication_state().feature_policy_header); | 8784 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8749 | 8785 |
| 8750 // Navigate the iframe cross-site. | 8786 // Navigate the iframe cross-site. |
| 8751 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8787 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 8752 EXPECT_EQ( | 8788 EXPECT_EQ( |
| 8753 "{\"vibrate\":[\"*\"]}", | 8789 CreateExpectedFeaturePolicyHeader("vibrate", true, |
| 8790 std::vector<std::string>()), | |
| 8754 root->child_at(0)->current_replication_state().feature_policy_header); | 8791 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8755 | 8792 |
| 8756 // Navigate the iframe to another location, this one with no policy header | 8793 // Navigate the iframe to another location, this one with no policy header |
| 8757 NavigateFrameToURL(root->child_at(0), second_nav_url); | 8794 NavigateFrameToURL(root->child_at(0), second_nav_url); |
| 8758 EXPECT_EQ( | 8795 EXPECT_TRUE(root->child_at(0) |
| 8759 "", root->child_at(0)->current_replication_state().feature_policy_header); | 8796 ->current_replication_state() |
| 8797 .feature_policy_header.empty()); | |
| 8760 | 8798 |
| 8761 // Navigate the iframe back to a page with a policy | 8799 // Navigate the iframe back to a page with a policy |
| 8762 NavigateFrameToURL(root->child_at(0), first_nav_url); | 8800 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 8763 EXPECT_EQ( | 8801 EXPECT_EQ( |
| 8764 "{\"vibrate\":[\"*\"]}", | 8802 CreateExpectedFeaturePolicyHeader("vibrate", true, |
| 8803 std::vector<std::string>()), | |
| 8765 root->child_at(0)->current_replication_state().feature_policy_header); | 8804 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8766 } | 8805 } |
| 8767 } // namespace content | 8806 } // namespace content |
| OLD | NEW |