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

Side by Side Diff: third_party/WebKit/Source/core/frame/FeaturePolicyInFrameTest.cpp

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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/feature_policy/FeaturePolicy.h" 5 #include "platform/feature_policy/FeaturePolicy.h"
6 6
7 #include "bindings/core/v8/ConditionalFeatures.h" 7 #include "bindings/core/v8/ConditionalFeatures.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
10 #include "platform/RuntimeEnabledFeatures.h" 10 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 document().setFeaturePolicyForTesting(std::move(policy2)); 91 document().setFeaturePolicyForTesting(std::move(policy2));
92 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame())); 92 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame()));
93 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultSelfFeature, frame())); 93 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultSelfFeature, frame()));
94 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOffFeature, frame())); 94 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOffFeature, frame()));
95 } 95 }
96 96
97 TEST_F(FeaturePolicyInFrameTest, TestFeatureOverriddenInFrame) { 97 TEST_F(FeaturePolicyInFrameTest, TestFeatureOverriddenInFrame) {
98 Vector<String> messages; 98 Vector<String> messages;
99 std::unique_ptr<FeaturePolicy> policy1 = 99 std::unique_ptr<FeaturePolicy> policy1 =
100 createFromParentPolicy(nullptr, m_originA); 100 createFromParentPolicy(nullptr, m_originA);
101 policy1->setHeaderPolicy("{\"default-off\": [\"self\"], \"default-on\": []}", 101 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
102 &messages); 102 "{\"default-off\": [\"self\"], \"default-on\": []}", m_originA.get(),
103 &messages));
103 EXPECT_EQ(0UL, messages.size()); 104 EXPECT_EQ(0UL, messages.size());
104 document().setFeaturePolicyForTesting(std::move(policy1)); 105 document().setFeaturePolicyForTesting(std::move(policy1));
105 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOffFeature, frame())); 106 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOffFeature, frame()));
106 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOnFeature, frame())); 107 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOnFeature, frame()));
107 } 108 }
108 109
109 // Ensure that features are enabled / disabled correctly when the FP runtime 110 // Ensure that features are enabled / disabled correctly when the FP runtime
110 // flag is turned off. 111 // flag is turned off.
111 TEST_F(FeaturePolicyInFrameTest, TestFeatureDefaultsWhenFPDisabled) { 112 TEST_F(FeaturePolicyInFrameTest, TestFeatureDefaultsWhenFPDisabled) {
112 RuntimeEnabledFeatures::setFeaturePolicyEnabled(false); 113 RuntimeEnabledFeatures::setFeaturePolicyEnabled(false);
113 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame())); 114 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame()));
114 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultSelfFeature, frame())); 115 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultSelfFeature, frame()));
115 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOffFeature, frame())); 116 EXPECT_FALSE(isFeatureEnabledInFrame(kDefaultOffFeature, frame()));
116 } 117 }
117 118
118 // Ensure that feature policy has no effect when the FP runtime flag is turned 119 // Ensure that feature policy has no effect when the FP runtime flag is turned
119 // off. 120 // off.
120 TEST_F(FeaturePolicyInFrameTest, TestPolicyInactiveWhenFPDisabled) { 121 TEST_F(FeaturePolicyInFrameTest, TestPolicyInactiveWhenFPDisabled) {
121 RuntimeEnabledFeatures::setFeaturePolicyEnabled(false); 122 RuntimeEnabledFeatures::setFeaturePolicyEnabled(false);
122 Vector<String> messages; 123 Vector<String> messages;
123 std::unique_ptr<FeaturePolicy> policy1 = 124 std::unique_ptr<FeaturePolicy> policy1 =
124 createFromParentPolicy(nullptr, m_originA); 125 createFromParentPolicy(nullptr, m_originA);
125 policy1->setHeaderPolicy("{\"default-on\": []}", &messages); 126 policy1->setHeaderPolicy(FeaturePolicy::parseFeaturePolicy(
127 "{\"default-on\": []}", m_originA.get(), &messages));
126 EXPECT_EQ(0UL, messages.size()); 128 EXPECT_EQ(0UL, messages.size());
127 document().setFeaturePolicyForTesting(std::move(policy1)); 129 document().setFeaturePolicyForTesting(std::move(policy1));
128 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame())); 130 EXPECT_TRUE(isFeatureEnabledInFrame(kDefaultOnFeature, frame()));
129 } 131 }
130 132
131 } // namespace blink 133 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/SecurityContext.cpp ('k') | third_party/WebKit/Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698