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

Unified 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: Fp2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index 006b70b8bf29cd0438ae69643e851a0c608d46f7..09f53d443e18a51cbc2288ee72b898dae5af4602 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -635,8 +635,38 @@ class SitePerProcessFeaturePolicyBrowserTest
command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
"FeaturePolicy");
}
+
+ std::string GetOrigin(const GURL& url) {
+ std::string result = url.GetOrigin().spec();
+ // Trim trailing / which doesn't appear in expected output.
+ base::TrimString(result, "/", &result);
+ return result;
+ }
+
+ std::vector<FeaturePolicyParsedWhitelist> CreateExpectedFeaturePolicyHeader(
+ const std::string& feature_name,
+ bool matches_all_origins,
+ const std::vector<std::string>& origins) {
+ std::vector<FeaturePolicyParsedWhitelist> result(1);
+ result[0].feature_name = feature_name;
+ result[0].matches_all_origins = matches_all_origins;
+ result[0].origins = origins;
+ return result;
+ }
};
+bool operator==(const FeaturePolicyParsedWhitelist& first,
+ const FeaturePolicyParsedWhitelist& second) {
+ 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.
+ first.matches_all_origins != second.matches_all_origins ||
+ first.origins.size() != second.origins.size() ||
+ !std::equal(first.origins.begin(), first.origins.end(),
+ second.origins.begin())) {
+ return false;
+ }
+ return true;
+}
+
double GetFrameDeviceScaleFactor(const ToRenderFrameHost& adapter) {
double device_scale_factor;
const char kGetFrameDeviceScaleFactor[] =
@@ -8686,19 +8716,21 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), start_url));
FrameTreeNode* root = web_contents()->GetFrameTree()->root();
- EXPECT_EQ("{\"vibrate\":[\"self\"]}",
+ EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false,
+ {GetOrigin(start_url)}),
root->current_replication_state().feature_policy_header);
// When the main frame navigates to a page with a new policy, it should
// overwrite the old one.
EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
- EXPECT_EQ("{\"vibrate\":[\"*\"]}",
+ EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true,
+ std::vector<std::string>()),
root->current_replication_state().feature_policy_header);
// When the main frame navigates to a page without a policy, the replicated
// policy header should be cleared.
EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
- EXPECT_EQ("", root->current_replication_state().feature_policy_header);
+ EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
}
IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
@@ -8712,19 +8744,21 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), start_url));
FrameTreeNode* root = web_contents()->GetFrameTree()->root();
- EXPECT_EQ("{\"vibrate\":[\"self\"]}",
+ EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", false,
+ {GetOrigin(start_url)}),
root->current_replication_state().feature_policy_header);
// When the main frame navigates to a page with a new policy, it should
// overwrite the old one.
EXPECT_TRUE(NavigateToURL(shell(), first_nav_url));
- EXPECT_EQ("{\"vibrate\":[\"*\"]}",
+ EXPECT_EQ(CreateExpectedFeaturePolicyHeader("vibrate", true,
+ std::vector<std::string>()),
root->current_replication_state().feature_policy_header);
// When the main frame navigates to a page without a policy, the replicated
// policy header should be cleared.
EXPECT_TRUE(NavigateToURL(shell(), second_nav_url));
- EXPECT_EQ("", root->current_replication_state().feature_policy_header);
+ EXPECT_TRUE(root->current_replication_state().feature_policy_header.empty());
}
// Test that the replicated feature policy header is correct in subframes as
@@ -8740,28 +8774,33 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessFeaturePolicyBrowserTest,
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = web_contents()->GetFrameTree()->root();
- EXPECT_EQ("{\"vibrate\":[\"self\", \"http://example.com/\"]}",
+ EXPECT_EQ(CreateExpectedFeaturePolicyHeader(
+ "vibrate", false, {GetOrigin(main_url), "http://example.com/"}),
root->current_replication_state().feature_policy_header);
EXPECT_EQ(1UL, root->child_count());
EXPECT_EQ(
- "{\"vibrate\":[\"self\"]}",
+ CreateExpectedFeaturePolicyHeader("vibrate", false,
+ {GetOrigin(main_url)}),
root->child_at(0)->current_replication_state().feature_policy_header);
// Navigate the iframe cross-site.
NavigateFrameToURL(root->child_at(0), first_nav_url);
EXPECT_EQ(
- "{\"vibrate\":[\"*\"]}",
+ CreateExpectedFeaturePolicyHeader("vibrate", true,
+ std::vector<std::string>()),
root->child_at(0)->current_replication_state().feature_policy_header);
// Navigate the iframe to another location, this one with no policy header
NavigateFrameToURL(root->child_at(0), second_nav_url);
- EXPECT_EQ(
- "", root->child_at(0)->current_replication_state().feature_policy_header);
+ EXPECT_TRUE(root->child_at(0)
+ ->current_replication_state()
+ .feature_policy_header.empty());
// Navigate the iframe back to a page with a policy
NavigateFrameToURL(root->child_at(0), first_nav_url);
EXPECT_EQ(
- "{\"vibrate\":[\"*\"]}",
+ CreateExpectedFeaturePolicyHeader("vibrate", true,
+ std::vector<std::string>()),
root->child_at(0)->current_replication_state().feature_policy_header);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698