Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 2520223002: Replicate a parsed feature policy representation so it doesn't need to be parsed in the browser pro… (Closed)
Patch Set: Replicate a parsed feature policy representation so it doesn't need to be parsed in the browser pro… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::vector<FeaturePolicyParsedWhitelist> CreateExpectedFeaturePolicyHeader(
640 const std::string& feature_name,
641 bool matches_all_origins,
642 const std::vector<std::string>& origins) {
643 std::vector<FeaturePolicyParsedWhitelist> result(1);
644 result[0].feature_name = feature_name;
645 result[0].matches_all_origins = matches_all_origins;
646 for (const std::string& origin_string : origins)
647 result[0].origins.push_back(url::Origin(GURL(origin_string)));
648 return result;
649 }
638 }; 650 };
639 651
652 bool operator==(const FeaturePolicyParsedWhitelist& first,
alexmos 2016/12/01 02:04:19 Any value in putting this next to the struct defin
raymes 2016/12/01 03:03:09 Right now it's only used from the test and I can't
alexmos 2016/12/01 22:27:54 Acknowledged.
653 const FeaturePolicyParsedWhitelist& second) {
654 return std::tie(first.feature_name, first.matches_all_origins,
655 first.origins) == std::tie(second.feature_name,
656 second.matches_all_origins,
657 second.origins);
658 }
659
640 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { 660 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) {
641 double device_scale_factor; 661 double device_scale_factor;
642 const char kGetFrameDeviceScaleFactor[] = 662 const char kGetFrameDeviceScaleFactor[] =
643 "window.domAutomationController.send(window.devicePixelRatio);"; 663 "window.domAutomationController.send(window.devicePixelRatio);";
644 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, 664 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor,
645 &device_scale_factor)); 665 &device_scale_factor));
646 return device_scale_factor; 666 return device_scale_factor;
647 } 667 }
648 668
649 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, 669 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest,
(...skipping 8029 matching lines...) Expand 10 before | Expand all | Expand 10 after
8679 TestFeaturePolicyReplicationOnSameOriginNavigation) { 8699 TestFeaturePolicyReplicationOnSameOriginNavigation) {
8680 GURL start_url( 8700 GURL start_url(
8681 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 8701 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
8682 GURL first_nav_url( 8702 GURL first_nav_url(
8683 embedded_test_server()->GetURL("a.com", "/feature-policy2.html")); 8703 embedded_test_server()->GetURL("a.com", "/feature-policy2.html"));
8684 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html")); 8704 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html"));
8685 8705
8686 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 8706 EXPECT_TRUE(NavigateToURL(shell(), start_url));
8687 8707
8688 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 8708 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8689 EXPECT_EQ("{\"vibrate\":[\"self\"]}", 8709 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false,
alexmos 2016/12/01 02:04:19 nit: the tests might be a bit more readable if ins
raymes 2016/12/01 03:03:09 Done.
8710 {start_url.GetOrigin().spec()}),
8690 root->current_replication_state().feature_policy_header); 8711 root->current_replication_state().feature_policy_header);
8691 8712
8692 // When the main frame navigates to a page with a new policy, it should 8713 // When the main frame navigates to a page with a new policy, it should
8693 // overwrite the old one. 8714 // overwrite the old one.
8694 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 8715 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
8695 EXPECT_EQ("{\"vibrate\":[\"*\"]}", 8716 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true,
8717 std::vector<std::string>()),
8696 root->current_replication_state().feature_policy_header); 8718 root->current_replication_state().feature_policy_header);
8697 8719
8698 // When the main frame navigates to a page without a policy, the replicated 8720 // When the main frame navigates to a page without a policy, the replicated
8699 // policy header should be cleared. 8721 // policy header should be cleared.
8700 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 8722 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
8701 EXPECT_EQ("", root->current_replication_state().feature_policy_header); 8723 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
8702 } 8724 }
8703 8725
8704 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 8726 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
8705 TestFeaturePolicyReplicationOnCrossOriginNavigation) { 8727 TestFeaturePolicyReplicationOnCrossOriginNavigation) {
8706 GURL start_url( 8728 GURL start_url(
8707 embedded_test_server()->GetURL("a.com", "/feature-policy1.html")); 8729 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
8708 GURL first_nav_url( 8730 GURL first_nav_url(
8709 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 8731 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
8710 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 8732 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
8711 8733
8712 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 8734 EXPECT_TRUE(NavigateToURL(shell(), start_url));
8713 8735
8714 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 8736 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8715 EXPECT_EQ("{\"vibrate\":[\"self\"]}", 8737 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false,
8738 {start_url.GetOrigin().spec()}),
8716 root->current_replication_state().feature_policy_header); 8739 root->current_replication_state().feature_policy_header);
8717 8740
8718 // When the main frame navigates to a page with a new policy, it should 8741 // When the main frame navigates to a page with a new policy, it should
8719 // overwrite the old one. 8742 // overwrite the old one.
8720 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url)); 8743 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
8721 EXPECT_EQ("{\"vibrate\":[\"*\"]}", 8744 EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true,
8745 std::vector<std::string>()),
8722 root->current_replication_state().feature_policy_header); 8746 root->current_replication_state().feature_policy_header);
8723 8747
8724 // When the main frame navigates to a page without a policy, the replicated 8748 // When the main frame navigates to a page without a policy, the replicated
8725 // policy header should be cleared. 8749 // policy header should be cleared.
8726 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url)); 8750 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
8727 EXPECT_EQ("", root->current_replication_state().feature_policy_header); 8751 EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
8728 } 8752 }
8729 8753
8730 // Test that the replicated feature policy header is correct in subframes as 8754 // Test that the replicated feature policy header is correct in subframes as
8731 // they navigate. 8755 // they navigate.
8732 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest, 8756 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
8733 TestFeaturePolicyReplicationFromRemoteFrames) { 8757 TestFeaturePolicyReplicationFromRemoteFrames) {
8734 GURL main_url( 8758 GURL main_url(
8735 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html")); 8759 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html"));
8736 GURL first_nav_url( 8760 GURL first_nav_url(
8737 embedded_test_server()->GetURL("b.com", "/feature-policy2.html")); 8761 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
8738 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html")); 8762 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
8739 8763
8740 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 8764 EXPECT_TRUE(NavigateToURL(shell(), main_url));
8741 8765
8742 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 8766 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8743 EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}", 8767 EXPECT_EQ(CreateExpectedFeaturePolicyHeader(
8768 "vibrate", false,
8769 {main_url.GetOrigin().spec(), "http://example.com/"}),
8744 root->current_replication_state().feature_policy_header); 8770 root->current_replication_state().feature_policy_header);
8745 EXPECT_EQ(1UL, root->child_count()); 8771 EXPECT_EQ(1UL, root->child_count());
8746 EXPECT_EQ( 8772 EXPECT_EQ(
8747 "{\"vibrate\":[\"self\"]}", 8773 CreateExpectedFeaturePolicyHeader("vibrate", false,
8774 {main_url.GetOrigin().spec()}),
8748 root->child_at(0)->current_replication_state().feature_policy_header); 8775 root->child_at(0)->current_replication_state().feature_policy_header);
8749 8776
8750 // Navigate the iframe cross-site. 8777 // Navigate the iframe cross-site.
8751 NavigateFrameToURL(root->child_at(0), first_nav_url); 8778 NavigateFrameToURL(root->child_at(0), first_nav_url);
8752 EXPECT_EQ( 8779 EXPECT_EQ(
8753 "{\"vibrate\":[\"*\"]}", 8780 CreateExpectedFeaturePolicyHeader("vibrate", true,
8781 std::vector<std::string>()),
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 CreateExpectedFeaturePolicyHeader("vibrate", true,
8794 std::vector<std::string>()),
8765 root->child_at(0)->current_replication_state().feature_policy_header); 8795 root->child_at(0)->current_replication_state().feature_policy_header);
8766 } 8796 }
8767 8797
8768 // Ensure that an iframe that navigates cross-site doesn't use the same process 8798 // 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, 8799 // as its parent. Then when its parent navigates it via the "srcdoc" attribute,
8770 // it must reuse its parent's process. 8800 // it must reuse its parent's process.
8771 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 8801 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
8772 IframeSrcdocAfterCrossSiteNavigation) { 8802 IframeSrcdocAfterCrossSiteNavigation) {
8773 GURL parent_url(embedded_test_server()->GetURL( 8803 GURL parent_url(embedded_test_server()->GetURL(
8774 "a.com", "/cross_site_iframe_factory.html?a(b)")); 8804 "a.com", "/cross_site_iframe_factory.html?a(b)"));
(...skipping 23 matching lines...) Expand all
8798 8828
8799 // Ensure that the iframe reuses its parent's process. 8829 // Ensure that the iframe reuses its parent's process.
8800 EXPECT_EQ(blank_url, child->current_url()); 8830 EXPECT_EQ(blank_url, child->current_url());
8801 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(), 8831 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(),
8802 child->current_frame_host()->GetSiteInstance()); 8832 child->current_frame_host()->GetSiteInstance());
8803 EXPECT_EQ(root->current_frame_host()->GetProcess(), 8833 EXPECT_EQ(root->current_frame_host()->GetProcess(),
8804 child->current_frame_host()->GetProcess()); 8834 child->current_frame_host()->GetProcess());
8805 } 8835 }
8806 8836
8807 } // namespace content 8837 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698