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

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

Issue 2483703002: Replicate feature policy headers to remote frames (Closed)
Patch Set: Add browsertest for subframe navigation Created 4 years, 1 month 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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 protected: 610 protected:
611 void SetUpCommandLine(base::CommandLine* command_line) override { 611 void SetUpCommandLine(base::CommandLine* command_line) override {
612 SitePerProcessBrowserTest::SetUpCommandLine(command_line); 612 SitePerProcessBrowserTest::SetUpCommandLine(command_line);
613 // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes 613 // TODO(amalika): Remove this switch when the EmbedderCSPEnforcement becomes
614 // stable 614 // stable
615 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, 615 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
616 "EmbedderCSPEnforcement"); 616 "EmbedderCSPEnforcement");
617 } 617 }
618 }; 618 };
619 619
620 // SitePerProcessFeaturePolicyBrowserTest
621
622 class SitePerProcessFeaturePolicyBrowserTest
623 : public SitePerProcessBrowserTest {
624 public:
625 SitePerProcessFeaturePolicyBrowserTest() {}
626
627 protected:
628 void SetUpCommandLine(base::CommandLine* command_line) override {
629 SitePerProcessBrowserTest::SetUpCommandLine(command_line);
630 // TODO(iclelland): Remove this switch when Feature Policy ships.
631 // https://crbug.com/623682
632 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
633 "FeaturePolicy");
634 }
635 };
636
620 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) { 637 double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) {
621 double device_scale_factor; 638 double device_scale_factor;
622 const char kGetFrameDeviceScaleFactor[] = 639 const char kGetFrameDeviceScaleFactor[] =
623 "window.domAutomationController.send(window.devicePixelRatio);"; 640 "window.domAutomationController.send(window.devicePixelRatio);";
624 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor, 641 EXPECT_TRUE(ExecuteScriptAndExtractDouble(adapter, kGetFrameDeviceScaleFactor,
625 &device_scale_factor)); 642 &device_scale_factor));
626 return device_scale_factor; 643 return device_scale_factor;
627 } 644 }
628 645
629 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, 646 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest,
(...skipping 7925 matching lines...) Expand 10 before | Expand all | Expand 10 after
8555 // |popup2|. This is allowed since the main tab is |popup2|'s opener. 8572 // |popup2|. This is allowed since the main tab is |popup2|'s opener.
8556 EXPECT_TRUE(NavigateToURL(shell(), b_url)); 8573 EXPECT_TRUE(NavigateToURL(shell(), b_url));
8557 8574
8558 base::string16 expected_title(base::UTF8ToUTF16("foo")); 8575 base::string16 expected_title(base::UTF8ToUTF16("foo"));
8559 TitleWatcher title_watcher(popup2->web_contents(), expected_title); 8576 TitleWatcher title_watcher(popup2->web_contents(), expected_title);
8560 EXPECT_TRUE(ExecuteScript( 8577 EXPECT_TRUE(ExecuteScript(
8561 shell(), "window.open('','popup2').postMessage('foo', '*');")); 8578 shell(), "window.open('','popup2').postMessage('foo', '*');"));
8562 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 8579 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
8563 } 8580 }
8564 8581
8582 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
8583 TestFeaturePolicyReplicationOnSameOriginNavigation) {
8584 GURL start_url(
8585 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
8586 GURL first_nav_url(
8587 embedded_test_server()->GetURL("a.com", "/feature-policy2.html"));
8588 GURL second_nav_url(embedded_test_server()->GetURL("a.com", "/title2.html"));
8589
8590 EXPECT_TRUE(NavigateToURL(shell(), start_url));
8591
8592 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8593 EXPECT_EQ("{\"vibrate\":[\"self\"]}",
8594 root->current_replication_state().feature_policy_header);
8595
8596 // When the main frame navigates to a page with a new policy, it should
8597 // overwrite the old one.
8598 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
8599 EXPECT_EQ("{\"vibrate\":[\"*\"]}",
8600 root->current_replication_state().feature_policy_header);
8601
8602 // When the main frame navigates to a page without a policy, the replicated
8603 // policy header should be cleared.
8604 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
8605 EXPECT_EQ("", root->current_replication_state().feature_policy_header);
8606 }
8607
8608 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
8609 TestFeaturePolicyReplicationOnCrossOriginNavigation) {
8610 GURL start_url(
8611 embedded_test_server()->GetURL("a.com", "/feature-policy1.html"));
8612 GURL first_nav_url(
8613 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
8614 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
8615
8616 EXPECT_TRUE(NavigateToURL(shell(), start_url));
8617
8618 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8619 EXPECT_EQ("{\"vibrate\":[\"self\"]}",
8620 root->current_replication_state().feature_policy_header);
8621
8622 // When the main frame navigates to a page with a new policy, it should
8623 // overwrite the old one.
8624 EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
8625 EXPECT_EQ("{\"vibrate\":[\"*\"]}",
8626 root->current_replication_state().feature_policy_header);
8627
8628 // When the main frame navigates to a page without a policy, the replicated
8629 // policy header should be cleared.
8630 EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
8631 EXPECT_EQ("", root->current_replication_state().feature_policy_header);
8632 }
8633
8634 // Test that the replicated feature policy header is correct in subframes as
8635 // they navigate.
8636 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
8637 TestFeaturePolicyReplicationFromRemoteFrames) {
8638 GURL main_url(
8639 embedded_test_server()->GetURL("a.com", "/feature-policy-main.html"));
8640 GURL first_nav_url(
8641 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
8642 GURL second_nav_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
8643
8644 EXPECT_TRUE(NavigateToURL(shell(), main_url));
8645
8646 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
8647 EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}",
8648 root->current_replication_state().feature_policy_header);
8649 EXPECT_EQ(1UL, root->child_count());
8650 EXPECT_EQ(
8651 "{\"vibrate\":[\"self\"]}",
8652 root->child_at(0)->current_replication_state().feature_policy_header);
8653
8654 // Navigate the iframe cross-site.
8655 NavigateFrameToURL(root->child_at(0), first_nav_url);
8656 EXPECT_EQ(
8657 "{\"vibrate\":[\"*\"]}",
8658 root->child_at(0)->current_replication_state().feature_policy_header);
8659
8660 // Navigate the iframe to another location, this one with no policy header
8661 NavigateFrameToURL(root->child_at(0), second_nav_url);
8662 EXPECT_EQ(
8663 "", root->child_at(0)->current_replication_state().feature_policy_header);
8664
8665 // Navigate the iframe back to a page with a policy
8666 NavigateFrameToURL(root->child_at(0), first_nav_url);
8667 EXPECT_EQ(
8668 "{\"vibrate\":[\"*\"]}",
8669 root->child_at(0)->current_replication_state().feature_policy_header);
8670 }
8565 } // namespace content 8671 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698