Index: content/common/feature_policy/feature_policy_unittest.cc |
diff --git a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicyTest.cpp b/content/common/feature_policy/feature_policy_unittest.cc |
similarity index 51% |
copy from third_party/WebKit/Source/platform/feature_policy/FeaturePolicyTest.cpp |
copy to content/common/feature_policy/feature_policy_unittest.cc |
index b5ec7f27f8ddf8509d098935c6270b73e3e66e49..525aeed602631f5379b26915ae1274f7591aa21a 100644 |
--- a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicyTest.cpp |
+++ b/content/common/feature_policy/feature_policy_unittest.cc |
@@ -2,155 +2,74 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "platform/feature_policy/FeaturePolicy.h" |
+#include "content/common/feature_policy/feature_policy.h" |
-#include "platform/RuntimeEnabledFeatures.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
// Origin strings used for tests |
#define ORIGIN_A "https://example.com/" |
#define ORIGIN_B "https://example.net/" |
#define ORIGIN_C "https://example.org/" |
-namespace blink { |
+namespace content { |
namespace { |
-const char* kValidPolicies[] = { |
- "{\"feature\": []}", |
- "{\"feature\": [\"self\"]}", |
- "{\"feature\": [\"*\"]}", |
- "{\"feature\": [\"" ORIGIN_A "\"]}", |
- "{\"feature\": [\"" ORIGIN_B "\"]}", |
- "{\"feature\": [\"" ORIGIN_A "\", \"" ORIGIN_B "\"]}", |
- "{\"feature1\": [\"" ORIGIN_A "\"], \"feature2\": [\"self\"]}", |
- "{\"feature1\": [\"" ORIGIN_A "\"]}, {\"feature2\": [\"self\"]}"}; |
- |
-const char* kInvalidPolicies[] = { |
- "Not A JSON literal", |
- "\"Not a JSON object\"", |
- "[\"Also\", \"Not a JSON object\"]", |
- "1.0", |
- "{\"Whitelist\": \"Not a JSON array\"}", |
- "{\"feature1\": [\"*\"], \"feature2\": \"Not an array\"}"}; |
- |
// This is an example of a feature which should be enabled by default in all |
// frames. |
-const FeaturePolicy::Feature kDefaultOnFeature{ |
+const FeaturePolicy::Feature kDefaultOnFeatureDfn{ |
"default-on", FeaturePolicy::FeatureDefault::EnableForAll}; |
// This is an example of a feature which should be enabled in top-level frames, |
// and same-origin child-frames, but must be delegated to all cross-origin |
// frames explicitly. |
-const FeaturePolicy::Feature kDefaultSelfFeature{ |
+const FeaturePolicy::Feature kDefaultSelfFeatureDfn{ |
"default-self", FeaturePolicy::FeatureDefault::EnableForSelf}; |
// This is an example of a feature which should be disabled by default, both in |
// top-level and nested frames. |
-const FeaturePolicy::Feature kDefaultOffFeature{ |
+const FeaturePolicy::Feature kDefaultOffFeatureDfn{ |
"default-off", FeaturePolicy::FeatureDefault::DisableForAll}; |
+// Define the three new features for testing |
+blink::WebFeaturePolicyFeature kDefaultOnFeature = |
+ static_cast<blink::WebFeaturePolicyFeature>( |
+ static_cast<int>(blink::WebFeaturePolicyFeature::LAST_FEATURE) + 1); |
+blink::WebFeaturePolicyFeature kDefaultSelfFeature = |
+ static_cast<blink::WebFeaturePolicyFeature>( |
+ static_cast<int>(blink::WebFeaturePolicyFeature::LAST_FEATURE) + 2); |
+blink::WebFeaturePolicyFeature kDefaultOffFeature = |
+ static_cast<blink::WebFeaturePolicyFeature>( |
+ static_cast<int>(blink::WebFeaturePolicyFeature::LAST_FEATURE) + 3); |
+ |
} // namespace |
class FeaturePolicyTest : public ::testing::Test { |
protected: |
FeaturePolicyTest() |
- : m_frameworkWasEnabled(RuntimeEnabledFeatures::featurePolicyEnabled()), |
- m_featureList( |
- {&kDefaultOnFeature, &kDefaultSelfFeature, &kDefaultOffFeature}) { |
- RuntimeEnabledFeatures::setFeaturePolicyEnabled(true); |
- } |
+ : featureList_({{kDefaultOnFeature, &kDefaultOnFeatureDfn}, |
+ {kDefaultSelfFeature, &kDefaultSelfFeatureDfn}, |
+ {kDefaultOffFeature, &kDefaultOffFeatureDfn}}) {} |
- ~FeaturePolicyTest() { |
- RuntimeEnabledFeatures::setFeaturePolicyEnabled(m_frameworkWasEnabled); |
- } |
+ ~FeaturePolicyTest() override {} |
- std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
+ std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
const FeaturePolicy* parent, |
- RefPtr<SecurityOrigin> origin) { |
- return FeaturePolicy::createFromParentPolicy(parent, origin, m_featureList); |
+ url::Origin origin) { |
+ return FeaturePolicy::CreateFromParentPolicy(parent, origin, featureList_); |
} |
- RefPtr<SecurityOrigin> m_originA = SecurityOrigin::createFromString(ORIGIN_A); |
- RefPtr<SecurityOrigin> m_originB = SecurityOrigin::createFromString(ORIGIN_B); |
- RefPtr<SecurityOrigin> m_originC = SecurityOrigin::createFromString(ORIGIN_C); |
+ url::Origin originA_ = url::Origin(GURL(ORIGIN_A)); |
+ url::Origin originB_ = url::Origin(GURL(ORIGIN_B)); |
+ url::Origin originC_ = url::Origin(GURL(ORIGIN_C)); |
private: |
- const bool m_frameworkWasEnabled; |
- |
// Contains the list of controlled features, so that we are guaranteed to |
// have at least one of each kind of default behaviour represented. |
- FeaturePolicy::FeatureList m_featureList; |
+ FeaturePolicy::FeatureList featureList_; |
}; |
-TEST_F(FeaturePolicyTest, ParseValidPolicy) { |
- Vector<String> messages; |
- for (const char* policyString : kValidPolicies) { |
- messages.clear(); |
- FeaturePolicy::parseFeaturePolicy(policyString, m_originA.get(), &messages); |
- EXPECT_EQ(0UL, messages.size()); |
- } |
-} |
- |
-TEST_F(FeaturePolicyTest, ParseInvalidPolicy) { |
- Vector<String> messages; |
- for (const char* policyString : kInvalidPolicies) { |
- messages.clear(); |
- FeaturePolicy::parseFeaturePolicy(policyString, m_originA.get(), &messages); |
- EXPECT_NE(0UL, messages.size()); |
- } |
-} |
- |
-TEST_F(FeaturePolicyTest, PolicyParsedCorrectly) { |
- Vector<String> messages; |
- |
- // Empty policy. |
- WebParsedFeaturePolicy parsedPolicy = |
- FeaturePolicy::parseFeaturePolicy("{}", m_originA.get(), &messages); |
- EXPECT_EQ(0UL, parsedPolicy.size()); |
- |
- // Simple policy with "self". |
- parsedPolicy = FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\"]}", m_originA.get(), &messages); |
- EXPECT_EQ(1UL, parsedPolicy.size()); |
- EXPECT_EQ("default-self", parsedPolicy[0].featureName); |
- EXPECT_FALSE(parsedPolicy[0].matchesAllOrigins); |
- EXPECT_EQ(1UL, parsedPolicy[0].origins.size()); |
- EXPECT_TRUE(m_originA->isSameSchemeHostPortAndSuborigin( |
- parsedPolicy[0].origins[0].get())); |
- |
- // Simple policy with *. |
- parsedPolicy = FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"]}", m_originA.get(), &messages); |
- EXPECT_EQ(1UL, parsedPolicy.size()); |
- EXPECT_EQ("default-self", parsedPolicy[0].featureName); |
- EXPECT_TRUE(parsedPolicy[0].matchesAllOrigins); |
- EXPECT_EQ(0UL, parsedPolicy[0].origins.size()); |
- |
- // Complicated policy. |
- parsedPolicy = FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"], " |
- "\"default-on\": [\"https://example.net\", \"https://example.org\"], " |
- "\"default-off\": [\"self\"]}", |
- m_originA.get(), &messages); |
- EXPECT_EQ(3UL, parsedPolicy.size()); |
- EXPECT_EQ("default-self", parsedPolicy[0].featureName); |
- EXPECT_TRUE(parsedPolicy[0].matchesAllOrigins); |
- EXPECT_EQ(0UL, parsedPolicy[0].origins.size()); |
- EXPECT_EQ("default-on", parsedPolicy[1].featureName); |
- EXPECT_FALSE(parsedPolicy[1].matchesAllOrigins); |
- EXPECT_EQ(2UL, parsedPolicy[1].origins.size()); |
- EXPECT_TRUE(m_originB->isSameSchemeHostPortAndSuborigin( |
- parsedPolicy[1].origins[0].get())); |
- EXPECT_TRUE(m_originC->isSameSchemeHostPortAndSuborigin( |
- parsedPolicy[1].origins[1].get())); |
- EXPECT_EQ("default-off", parsedPolicy[2].featureName); |
- EXPECT_FALSE(parsedPolicy[2].matchesAllOrigins); |
- EXPECT_EQ(1UL, parsedPolicy[2].origins.size()); |
- EXPECT_TRUE(m_originA->isSameSchemeHostPortAndSuborigin( |
- parsedPolicy[2].origins[0].get())); |
-} |
- |
TEST_F(FeaturePolicyTest, TestInitialPolicy) { |
// +-------------+ |
// |(1)Origin A | |
@@ -159,10 +78,10 @@ TEST_F(FeaturePolicyTest, TestInitialPolicy) { |
// Default-on and top-level-only features should be enabled in top-level |
// frame. Default-off features should be disabled. |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOffFeature)); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy1->IsFeatureEnabled(kDefaultOffFeature)); |
} |
TEST_F(FeaturePolicyTest, TestInitialSameOriginChildPolicy) { |
@@ -177,12 +96,12 @@ TEST_F(FeaturePolicyTest, TestInitialSameOriginChildPolicy) { |
// Default-on and Default-self features should be enabled in a same-origin |
// child frame. Default-off features should be disabled. |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
+ CreateFromParentPolicy(nullptr, originA_); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originA); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOffFeature)); |
+ CreateFromParentPolicy(policy1.get(), originA_); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOffFeature)); |
} |
TEST_F(FeaturePolicyTest, TestInitialCrossOriginChildPolicy) { |
@@ -197,12 +116,12 @@ TEST_F(FeaturePolicyTest, TestInitialCrossOriginChildPolicy) { |
// Default-on features should be enabled in child frame. Default-self and |
// Default-off features should be disabled. |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
+ CreateFromParentPolicy(nullptr, originA_); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOffFeature)); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOffFeature)); |
} |
TEST_F(FeaturePolicyTest, TestCrossOriginChildCannotEnableFeature) { |
@@ -216,15 +135,12 @@ TEST_F(FeaturePolicyTest, TestCrossOriginChildCannotEnableFeature) { |
// +---------------------------------------+ |
// Default-self feature should be disabled in cross origin frame, even if no |
// policy was specified in the parent frame. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
+ CreateFromParentPolicy(nullptr, originA_); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\"]}", m_originB.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy({{{"default-self", false, {originB_}}}}); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestFrameSelfInheritance) { |
@@ -243,24 +159,21 @@ TEST_F(FeaturePolicyTest, TestFrameSelfInheritance) { |
// Feature should be enabled at the top-level, and through the chain of |
// same-origin frames 2 and 3. It should be disabled in frames 4 and 5, as |
// they are at a different origin. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originA); |
+ CreateFromParentPolicy(policy1.get(), originA_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originA); |
+ CreateFromParentPolicy(policy2.get(), originA_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy5 = |
- createFromParentPolicy(policy4.get(), m_originB); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy5->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy4.get(), originB_); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy5->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestReflexiveFrameSelfInheritance) { |
@@ -278,18 +191,15 @@ TEST_F(FeaturePolicyTest, TestReflexiveFrameSelfInheritance) { |
// +-----------------------------------+ |
// Feature which is enabled at top-level should be disabled in frame 3, as |
// it is embedded by frame 2, for which the feature is not enabled. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originA); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originA_); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestSelectiveFrameInheritance) { |
@@ -308,21 +218,18 @@ TEST_F(FeaturePolicyTest, TestSelectiveFrameInheritance) { |
// Feature should be enabled in second level Origin B frame, but disabled in |
// Frame 4, because it is embedded by frame 3, where the feature is not |
// enabled. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy1.get(), m_originC); |
+ CreateFromParentPolicy(policy1.get(), originC_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy3.get(), m_originB); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy3.get(), originB_); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestPolicyCanBlockSelf) { |
@@ -331,13 +238,11 @@ TEST_F(FeaturePolicyTest, TestPolicyCanBlockSelf) { |
// |Policy: {"default-on": []} | |
// +----------------------------+ |
// Default-on feature should be disabled in top-level frame. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": []}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
- EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy( |
+ {{{"default-on", false, std::vector<url::Origin>()}}}); |
+ EXPECT_FALSE(policy1->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestParentPolicyBlocksSameOriginChildPolicy) { |
@@ -350,15 +255,13 @@ TEST_F(FeaturePolicyTest, TestParentPolicyBlocksSameOriginChildPolicy) { |
// | +-------------+ | |
// +----------------------------+ |
// Feature should be disabled in child frame. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": []}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy( |
+ {{{"default-on", false, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originA); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy1.get(), originA_); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockSelf) { |
@@ -371,15 +274,13 @@ TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockSelf) { |
// | +----------------------------+ | |
// +--------------------------------+ |
// Default-on feature should be disabled by cross-origin child frame. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
+ CreateFromParentPolicy(nullptr, originA_); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": []}", m_originB.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy( |
+ {{{"default-on", false, std::vector<url::Origin>()}}}); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockChildren) { |
@@ -397,18 +298,15 @@ TEST_F(FeaturePolicyTest, TestChildPolicyCanBlockChildren) { |
// +--------------------------------------+ |
// Default-on feature should be enabled in frames 1 and 2; disabled in frame |
// 3 by child frame policy. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
+ CreateFromParentPolicy(nullptr, originA_); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": [\"self\"]}", m_originB.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy({{{"default-on", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestParentPolicyBlocksCrossOriginChildPolicy) { |
@@ -421,15 +319,13 @@ TEST_F(FeaturePolicyTest, TestParentPolicyBlocksCrossOriginChildPolicy) { |
// | +-------------+ | |
// +----------------------------+ |
// Default-on feature should be disabled in cross-origin child frame. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": []}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy( |
+ {{{"default-on", false, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestEnableForAllOrigins) { |
@@ -446,19 +342,17 @@ TEST_F(FeaturePolicyTest, TestEnableForAllOrigins) { |
// | +-----------------+ | |
// +--------------------------------+ |
// Feature should be enabled in top and second level; disabled in frame 3. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy( |
+ {{{"default-self", true, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originA); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originA_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestDefaultOnEnablesForAllAncestors) { |
@@ -475,22 +369,19 @@ TEST_F(FeaturePolicyTest, TestDefaultOnEnablesForAllAncestors) { |
// | +-----------------------------------+ | |
// +---------------------------------------+ |
// Feature should be disabled in frame 1; enabled in frames 2, 3 and 4. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-on", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originB); |
+ CreateFromParentPolicy(policy2.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy4->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_FALSE(policy1->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy4->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestDefaultSelfRespectsSameOriginEmbedding) { |
@@ -507,22 +398,19 @@ TEST_F(FeaturePolicyTest, TestDefaultSelfRespectsSameOriginEmbedding) { |
// | +-----------------------------------+ | |
// +---------------------------------------+ |
// Feature should be disabled in frames 1 and 4; enabled in frames 2 and 3. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originB); |
+ CreateFromParentPolicy(policy2.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_FALSE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestDefaultOffMustBeDelegatedToAllCrossOriginFrames) { |
@@ -539,26 +427,21 @@ TEST_F(FeaturePolicyTest, TestDefaultOffMustBeDelegatedToAllCrossOriginFrames) { |
// | +--------------------------------------------------------+ | |
// +------------------------------------------------------------+ |
// Feature should be disabled in frames 1, 3 and 4; enabled in frame 2 only. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-off\": [\"" ORIGIN_B "\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-off", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-off\": [\"self\"]}", m_originB.get(), &messages)); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy({{{"default-off", false, {originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originB); |
+ CreateFromParentPolicy(policy2.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- policy4->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-off\": [\"self\"]}", m_originC.get(), &messages)); |
- EXPECT_FALSE(policy1->isFeatureEnabled(kDefaultOffFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOffFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOffFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultOffFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ policy4->SetHeaderPolicy({{{"default-off", false, {originC_}}}}); |
+ EXPECT_FALSE(policy1->IsFeatureEnabled(kDefaultOffFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOffFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultOffFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultOffFeature)); |
} |
TEST_F(FeaturePolicyTest, TestReenableForAllOrigins) { |
@@ -575,22 +458,19 @@ TEST_F(FeaturePolicyTest, TestReenableForAllOrigins) { |
// | +--------------------------------+ | |
// +------------------------------------+ |
// Feature should be enabled in all frames. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy( |
+ {{{"default-self", true, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"]}", m_originB.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy( |
+ {{{"default-self", true, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originA); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originA_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestBlockedFrameCannotReenable) { |
@@ -607,25 +487,21 @@ TEST_F(FeaturePolicyTest, TestBlockedFrameCannotReenable) { |
// | +----------------------------------+ | |
// +--------------------------------------+ |
// Feature should be enabled at the top level; disabled in all other frames. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\"]}", m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"]}", m_originB.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy( |
+ {{{"default-self", true, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originA); |
+ CreateFromParentPolicy(policy2.get(), originA_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegate) { |
@@ -642,24 +518,17 @@ TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegate) { |
// | +-----------------------------------------------+ | |
// +---------------------------------------------------+ |
// Feature should be enabled in all frames. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_, originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\", \"" ORIGIN_C "\"]}", m_originB.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy({{{"default-self", false, {originB_, originC_}}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegateByDefault) { |
@@ -676,23 +545,19 @@ TEST_F(FeaturePolicyTest, TestEnabledFrameCanDelegateByDefault) { |
// | +--------------------+ +--------------------+ | |
// +-----------------------------------------------+ |
// Feature should be enabled in frames 1, 2, and 3, and disabled in frame 4. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-on\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-on", false, {originA_, originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originC); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy1.get(), m_originC); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy1.get(), originC_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestNonNestedFeaturesDontDelegateByDefault) { |
@@ -710,23 +575,19 @@ TEST_F(FeaturePolicyTest, TestNonNestedFeaturesDontDelegateByDefault) { |
// +-----------------------------------------------+ |
// Feature should be enabled in frames 1 and 2, and disabled in frames 3 and |
// 4. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_, originB_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originC); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
std::unique_ptr<FeaturePolicy> policy4 = |
- createFromParentPolicy(policy1.get(), m_originC); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy4->isFeatureEnabled(kDefaultSelfFeature)); |
+ CreateFromParentPolicy(policy1.get(), originC_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy4->IsFeatureEnabled(kDefaultSelfFeature)); |
} |
TEST_F(FeaturePolicyTest, TestFeaturesAreIndependent) { |
@@ -746,28 +607,23 @@ TEST_F(FeaturePolicyTest, TestFeaturesAreIndependent) { |
// +-----------------------------------------------+ |
// Default-self feature should be enabled in all frames; Default-on feature |
// should be enabled in frame 1, and disabled in frames 2 and 3. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"self\", \"" ORIGIN_B |
- "\"], \"default-on\": [\"self\"]}", |
- m_originA.get(), &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-self", false, {originA_, originB_}}, |
+ {"default-on", false, {originA_}}}}); |
std::unique_ptr<FeaturePolicy> policy2 = |
- createFromParentPolicy(policy1.get(), m_originB); |
- policy2->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-self\": [\"*\"], \"default-on\": [\"*\"]}", m_originB.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
+ CreateFromParentPolicy(policy1.get(), originB_); |
+ policy2->SetHeaderPolicy( |
+ {{{"default-self", true, std::vector<url::Origin>()}, |
+ {"default-on", true, std::vector<url::Origin>()}}}); |
std::unique_ptr<FeaturePolicy> policy3 = |
- createFromParentPolicy(policy2.get(), m_originC); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); |
- EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); |
- EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature)); |
+ CreateFromParentPolicy(policy2.get(), originC_); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_TRUE(policy1->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy2->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy2->IsFeatureEnabled(kDefaultOnFeature)); |
+ EXPECT_TRUE(policy3->IsFeatureEnabled(kDefaultSelfFeature)); |
+ EXPECT_FALSE(policy3->IsFeatureEnabled(kDefaultOnFeature)); |
} |
TEST_F(FeaturePolicyTest, TestFeatureEnabledForOrigin) { |
@@ -777,19 +633,13 @@ TEST_F(FeaturePolicyTest, TestFeatureEnabledForOrigin) { |
// +-----------------------------------------------+ |
// Features should be enabled by the policy in frame 1 for origins A and B, |
// and disabled for origin C. |
- Vector<String> messages; |
std::unique_ptr<FeaturePolicy> policy1 = |
- createFromParentPolicy(nullptr, m_originA); |
- policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy( |
- "{\"default-off\": [\"self\", \"" ORIGIN_B "\"]}", m_originA.get(), |
- &messages)); |
- EXPECT_EQ(0UL, messages.size()); |
- EXPECT_TRUE( |
- policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originA)); |
- EXPECT_TRUE( |
- policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originB)); |
+ CreateFromParentPolicy(nullptr, originA_); |
+ policy1->SetHeaderPolicy({{{"default-off", false, {originA_, originB_}}}}); |
+ EXPECT_TRUE(policy1->IsFeatureEnabledForOrigin(kDefaultOffFeature, originA_)); |
+ EXPECT_TRUE(policy1->IsFeatureEnabledForOrigin(kDefaultOffFeature, originB_)); |
EXPECT_FALSE( |
- policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originC)); |
+ policy1->IsFeatureEnabledForOrigin(kDefaultOffFeature, originC_)); |
} |
-} // namespace blink |
+} // namespace content |