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

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

Issue 2797813002: Replicate feature policy container policies. (Closed)
Patch Set: Addressing review comments Created 3 years, 8 months 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 733
734 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll( 734 ParsedFeaturePolicyHeader CreateFPHeaderMatchesAll(
735 blink::WebFeaturePolicyFeature feature) { 735 blink::WebFeaturePolicyFeature feature) {
736 ParsedFeaturePolicyHeader result(1); 736 ParsedFeaturePolicyHeader result(1);
737 result[0].feature = feature; 737 result[0].feature = feature;
738 result[0].matches_all_origins = true; 738 result[0].matches_all_origins = true;
739 return result; 739 return result;
740 } 740 }
741 }; 741 };
742 742
743 bool operator==(const ParsedFeaturePolicyDeclaration& first,
744 const ParsedFeaturePolicyDeclaration& second) {
745 return std::tie(first.feature, first.matches_all_origins, first.origins) ==
746 std::tie(second.feature, second.matches_all_origins, second.origins);
747 }
748
749 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest, 743 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest,
750 SubframeLoadsWithCorrectDeviceScaleFactor) { 744 SubframeLoadsWithCorrectDeviceScaleFactor) {
751 GURL main_url(embedded_test_server()->GetURL( 745 GURL main_url(embedded_test_server()->GetURL(
752 "a.com", "/cross_site_iframe_factory.html?a(b)")); 746 "a.com", "/cross_site_iframe_factory.html?a(b)"));
753 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 747 EXPECT_TRUE(NavigateToURL(shell(), main_url));
754 748
755 // On Android forcing device scale factor does not work for tests, therefore 749 // On Android forcing device scale factor does not work for tests, therefore
756 // we ensure that make frame and iframe have the same DIP scale there, but 750 // we ensure that make frame and iframe have the same DIP scale there, but
757 // not necessarily kDeviceScaleFactor. 751 // not necessarily kDeviceScaleFactor.
758 const double expected_dip_scale = 752 const double expected_dip_scale =
(...skipping 8745 matching lines...) Expand 10 before | Expand all | Expand 10 after
9504 EXPECT_TRUE(ExecuteScript( 9498 EXPECT_TRUE(ExecuteScript(
9505 root, "document.getElementById('child-3').allow='fullscreen vibrate'")); 9499 root, "document.getElementById('child-3').allow='fullscreen vibrate'"));
9506 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features.size(), 9500 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features.size(),
9507 2u); 9501 2u);
9508 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features[0], 9502 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features[0],
9509 blink::WebFeaturePolicyFeature::kFullscreen); 9503 blink::WebFeaturePolicyFeature::kFullscreen);
9510 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features[1], 9504 EXPECT_EQ(root->child_at(3)->frame_owner_properties().allowed_features[1],
9511 blink::WebFeaturePolicyFeature::kVibrate); 9505 blink::WebFeaturePolicyFeature::kVibrate);
9512 } 9506 }
9513 9507
9508 // Test iframe container policy is replicated properly to the browser.
9509 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9510 ContainerPolicy) {
9511 GURL url(embedded_test_server()->GetURL("/allowed_frames.html"));
9512 EXPECT_TRUE(NavigateToURL(shell(), url));
9513
9514 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9515
9516 EXPECT_EQ(0UL, root->effective_container_policy().size());
9517 EXPECT_EQ(0UL, root->child_at(0)->effective_container_policy().size());
9518 EXPECT_EQ(0UL, root->child_at(1)->effective_container_policy().size());
9519 EXPECT_EQ(2UL, root->child_at(2)->effective_container_policy().size());
9520 EXPECT_EQ(2UL, root->child_at(3)->effective_container_policy().size());
9521 }
9522
9523 // Test dynamic updates to iframe "allow" attribute are propagated correctly.
9524 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9525 ContainerPolicyDynamic) {
9526 GURL main_url(embedded_test_server()->GetURL("/allowed_frames.html"));
9527 GURL nav_url(
9528 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9529 EXPECT_TRUE(NavigateToURL(shell(), main_url));
9530
9531 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9532
9533 EXPECT_EQ(2UL, root->child_at(2)->effective_container_policy().size());
9534
9535 // Removing the "allow" attribute; pending policy should update, but effective
9536 // policy remains unchanged.
9537 EXPECT_TRUE(ExecuteScript(
9538 root, "document.getElementById('child-2').setAttribute('allow','')"));
9539 EXPECT_EQ(2UL, root->child_at(2)->effective_container_policy().size());
9540 EXPECT_EQ(0UL, root->child_at(2)->pending_container_policy_.size());
9541
9542 // Navigate the frame; pending policy should be committed.
9543 NavigateFrameToURL(root->child_at(2), nav_url);
9544 EXPECT_EQ(0UL, root->child_at(2)->effective_container_policy().size());
9545 }
9546
9547 // Test that dynamic updates to iframe sandbox attribute correctly set the
9548 // replicated container policy.
9549 IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
9550 ContainerPolicySandboxDynamic) {
9551 GURL main_url(embedded_test_server()->GetURL("/allowed_frames.html"));
9552 GURL nav_url(
9553 embedded_test_server()->GetURL("b.com", "/feature-policy2.html"));
9554 EXPECT_TRUE(NavigateToURL(shell(), main_url));
9555
9556 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
9557
9558 // Validate that the effective container policy contains a single non-unique
9559 // origin.
9560 const ParsedFeaturePolicyHeader initial_effective_policy =
9561 root->child_at(2)->effective_container_policy();
9562 EXPECT_EQ(1UL, initial_effective_policy[0].origins.size());
9563 EXPECT_FALSE(initial_effective_policy[0].origins[0].unique());
9564
9565 // Set the "sandbox" attribute; pending policy should update, and should now
9566 // contain a unique origin, but effective policy should remain unchanged.
9567 EXPECT_TRUE(ExecuteScript(
9568 root, "document.getElementById('child-2').setAttribute('sandbox','')"));
9569 const ParsedFeaturePolicyHeader updated_effective_policy =
9570 root->child_at(2)->effective_container_policy();
9571 const ParsedFeaturePolicyHeader updated_pending_policy =
9572 root->child_at(2)->pending_container_policy_;
9573 EXPECT_EQ(1UL, updated_effective_policy[0].origins.size());
9574 EXPECT_FALSE(updated_effective_policy[0].origins[0].unique());
9575 EXPECT_EQ(1UL, updated_pending_policy[0].origins.size());
9576 EXPECT_TRUE(updated_pending_policy[0].origins[0].unique());
9577
9578 // Navigate the frame; pending policy should now be committed.
9579 NavigateFrameToURL(root->child_at(2), nav_url);
9580 const ParsedFeaturePolicyHeader final_effective_policy =
9581 root->child_at(2)->effective_container_policy();
9582 EXPECT_EQ(1UL, final_effective_policy[0].origins.size());
9583 EXPECT_TRUE(final_effective_policy[0].origins[0].unique());
9584 }
9585
9514 // Test harness that allows for "barrier" style delaying of requests matching 9586 // Test harness that allows for "barrier" style delaying of requests matching
9515 // certain paths. Call SetDelayedRequestsForPath to delay requests, then 9587 // certain paths. Call SetDelayedRequestsForPath to delay requests, then
9516 // SetUpEmbeddedTestServer to register handlers and start the server. 9588 // SetUpEmbeddedTestServer to register handlers and start the server.
9517 class RequestDelayingSitePerProcessBrowserTest 9589 class RequestDelayingSitePerProcessBrowserTest
9518 : public SitePerProcessBrowserTest { 9590 : public SitePerProcessBrowserTest {
9519 public: 9591 public:
9520 RequestDelayingSitePerProcessBrowserTest() 9592 RequestDelayingSitePerProcessBrowserTest()
9521 : test_server_(base::MakeUnique<net::EmbeddedTestServer>()) {} 9593 : test_server_(base::MakeUnique<net::EmbeddedTestServer>()) {}
9522 9594
9523 // Must be called after any calls to SetDelayedRequestsForPath. 9595 // Must be called after any calls to SetDelayedRequestsForPath.
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
9861 names.insert(root->children[0]->frame_entry->frame_unique_name()); 9933 names.insert(root->children[0]->frame_entry->frame_unique_name());
9862 } 9934 }
9863 9935
9864 // More than one entry in the set means that the subframe frame navigation 9936 // More than one entry in the set means that the subframe frame navigation
9865 // entries didn't have a consistent unique name. This will break history 9937 // entries didn't have a consistent unique name. This will break history
9866 // navigations =( 9938 // navigations =(
9867 EXPECT_THAT(names, SizeIs(1)) << "Mismatched names for subframe!"; 9939 EXPECT_THAT(names, SizeIs(1)) << "Mismatched names for subframe!";
9868 } 9940 }
9869 9941
9870 } // namespace content 9942 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_message_filter.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698