| 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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 protected: | 613 protected: |
| 614 void SetUpCommandLine(base::CommandLine* command_line) override { | 614 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 615 SitePerProcessBrowserTest::SetUpCommandLine(command_line); | 615 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| 616 // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes | 616 // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes |
| 617 // stable | 617 // stable |
| 618 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 618 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 619 "EmbedderCSPEnforcement"); | 619 "EmbedderCSPEnforcement"); |
| 620 } | 620 } |
| 621 }; | 621 }; |
| 622 | 622 |
| 623 // SitePerProcessFeaturePolicyBrowserTest |
| 624 |
| 625 class SitePerProcessFeaturePolicyBrowserTest |
| 626 : public SitePerProcessBrowserTest { |
| 627 public: |
| 628 SitePerProcessFeaturePolicyBrowserTest() {} |
| 629 |
| 630 protected: |
| 631 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 632 SitePerProcessBrowserTest::SetUpCommandLine(command_line); |
| 633 // TODO(iclelland): Remove this switch when Feature Policy ships. |
| 634 // https://crbug.com/623682 |
| 635 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 636 "FeaturePolicy"); |
| 637 } |
| 638 }; |
| 639 |
| 623 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { | 640 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { |
| 624 double device_scale_factor; | 641 double device_scale_factor; |
| 625 const char kGetFrameDeviceScaleFactor[] = | 642 const char kGetFrameDeviceScaleFactor[] = |
| 626 "window.domAutomationController.send(window.devicePixelRatio);"; | 643 "window.domAutomationController.send(window.devicePixelRatio);"; |
| 627 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, | 644 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, |
| 628 &device_scale_factor)); | 645 &device_scale_factor)); |
| 629 return device_scale_factor; | 646 return device_scale_factor; |
| 630 } | 647 } |
| 631 | 648 |
| 632 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, | 649 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, |
| (...skipping 8018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8651 // Start a URLRequest to the same URL. This should succeed. This would have | 8668 // Start a URLRequest to the same URL. This should succeed. This would have |
| 8652 // hit the 20 seconds delay before https://crbug.com/657195 was fixed. | 8669 // hit the 20 seconds delay before https://crbug.com/657195 was fixed. |
| 8653 EXPECT_TRUE(NavigateToURL(shell(), page_url)); | 8670 EXPECT_TRUE(NavigateToURL(shell(), page_url)); |
| 8654 EXPECT_EQ(page_url, shell()->web_contents()->GetLastCommittedURL()); | 8671 EXPECT_EQ(page_url, shell()->web_contents()->GetLastCommittedURL()); |
| 8655 | 8672 |
| 8656 // Note: even if the test fails and for some reason, the test has not timed | 8673 // Note: even if the test fails and for some reason, the test has not timed |
| 8657 // out by this point, the test teardown code will still hit a DCHECK when it | 8674 // out by this point, the test teardown code will still hit a DCHECK when it |
| 8658 // calls AssertNoURLRequests() in the shell's URLRequestContext destructor. | 8675 // calls AssertNoURLRequests() in the shell's URLRequestContext destructor. |
| 8659 } | 8676 } |
| 8660 | 8677 |
| 8678 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 8679 TestFeaturePolicyReplicationOnSameOriginNavigation) { |
| 8680 GURL start_url( |
| 8681 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 8682 GURL first_nav_url( |
| 8683 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); |
| 8684 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); |
| 8685 |
| 8686 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 8687 |
| 8688 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8689 EXPECT_EQ("{\"vibrate\":[\"self\"]}", |
| 8690 root->current_replication_state().feature_policy_header); |
| 8691 |
| 8692 // When the main frame navigates to a page with a new policy, it should |
| 8693 // overwrite the old one. |
| 8694 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 8695 EXPECT_EQ("{\"vibrate\":[\"*\"]}", |
| 8696 root->current_replication_state().feature_policy_header); |
| 8697 |
| 8698 // When the main frame navigates to a page without a policy, the replicated |
| 8699 // policy header should be cleared. |
| 8700 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 8701 EXPECT_EQ("", root->current_replication_state().feature_policy_header); |
| 8702 } |
| 8703 |
| 8704 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 8705 TestFeaturePolicyReplicationOnCrossOriginNavigation) { |
| 8706 GURL start_url( |
| 8707 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); |
| 8708 GURL first_nav_url( |
| 8709 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 8710 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 8711 |
| 8712 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 8713 |
| 8714 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8715 EXPECT_EQ("{\"vibrate\":[\"self\"]}", |
| 8716 root->current_replication_state().feature_policy_header); |
| 8717 |
| 8718 // When the main frame navigates to a page with a new policy, it should |
| 8719 // overwrite the old one. |
| 8720 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); |
| 8721 EXPECT_EQ("{\"vibrate\":[\"*\"]}", |
| 8722 root->current_replication_state().feature_policy_header); |
| 8723 |
| 8724 // When the main frame navigates to a page without a policy, the replicated |
| 8725 // policy header should be cleared. |
| 8726 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); |
| 8727 EXPECT_EQ("", root->current_replication_state().feature_policy_header); |
| 8728 } |
| 8729 |
| 8730 // Test that the replicated feature policy header is correct in subframes as |
| 8731 // they navigate. |
| 8732 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, |
| 8733 TestFeaturePolicyReplicationFromRemoteFrames) { |
| 8734 GURL main_url( |
| 8735 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); |
| 8736 GURL first_nav_url( |
| 8737 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); |
| 8738 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 8739 |
| 8740 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 8741 |
| 8742 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 8743 EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}", |
| 8744 root->current_replication_state().feature_policy_header); |
| 8745 EXPECT_EQ(1UL, root->child_count()); |
| 8746 EXPECT_EQ( |
| 8747 "{\"vibrate\":[\"self\"]}", |
| 8748 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8749 |
| 8750 // Navigate the iframe cross-site. |
| 8751 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 8752 EXPECT_EQ( |
| 8753 "{\"vibrate\":[\"*\"]}", |
| 8754 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8755 |
| 8756 // Navigate the iframe to another location, this one with no policy header |
| 8757 NavigateFrameToURL(root->child_at(0), second_nav_url); |
| 8758 EXPECT_EQ( |
| 8759 "", root->child_at(0)->current_replication_state().feature_policy_header); |
| 8760 |
| 8761 // Navigate the iframe back to a page with a policy |
| 8762 NavigateFrameToURL(root->child_at(0), first_nav_url); |
| 8763 EXPECT_EQ( |
| 8764 "{\"vibrate\":[\"*\"]}", |
| 8765 root->child_at(0)->current_replication_state().feature_policy_header); |
| 8766 } |
| 8661 } // namespace content | 8767 } // namespace content |
| OLD | NEW |