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

Side by Side Diff: third_party/WebKit/Source/core/experiments/ExperimentsTest.cpp

Issue 1541983003: Force all experiment enabled checks to use ExperimentalFeatures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/experiments/Experiments.h" 5 #include "core/experiments/Experiments.h"
6 6
7 #include "core/HTMLNames.h" 7 #include "core/HTMLNames.h"
8 #include "core/dom/DOMException.h" 8 #include "core/dom/DOMException.h"
9 #include "core/dom/ExceptionCode.h" 9 #include "core/dom/ExceptionCode.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 head->appendChild(meta.release()); 83 head->appendChild(meta.release());
84 } 84 }
85 85
86 bool isApiEnabled(const String& origin, const String& apiName, const char* a piKeyValue, String& errorMessage) 86 bool isApiEnabled(const String& origin, const String& apiName, const char* a piKeyValue, String& errorMessage)
87 { 87 {
88 setPageOrigin(origin); 88 setPageOrigin(origin);
89 addApiKey(apiKeyValue); 89 addApiKey(apiKeyValue);
90 return Experiments::isApiEnabled(executionContext(), apiName, errorMessa ge); 90 return Experiments::isApiEnabled(executionContext(), apiName, errorMessa ge);
91 } 91 }
92 92
93 bool isApiEnabledWithoutErrorMessage(const String& origin, const String& api Name, const char* apiKeyValue)
94 {
95 setPageOrigin(origin);
96 addApiKey(apiKeyValue);
97 return Experiments::isApiEnabled(executionContext(), apiName);
98 }
99
93 private: 100 private:
94 OwnPtr<DummyPageHolder> m_page; 101 OwnPtr<DummyPageHolder> m_page;
95 RefPtrWillBePersistent<HTMLDocument> m_document; 102 RefPtrWillBePersistent<HTMLDocument> m_document;
96 const bool m_frameworkWasEnabled; 103 const bool m_frameworkWasEnabled;
97 }; 104 };
98 105
99 TEST_F(ExperimentsTest, EnabledNonExistingAPI) 106 TEST_F(ExperimentsTest, EnabledNonExistingAPI)
100 { 107 {
101 String errorMessage; 108 String errorMessage;
102 bool isNonExistingApiEnabled = isApiEnabled(kFrobulateEnabledOrigin, 109 bool isNonExistingApiEnabled = isApiEnabled(kFrobulateEnabledOrigin,
103 kNonExistingAPIName, 110 kNonExistingAPIName,
104 kFrobulateAPIName /* Use existing api name as the key value */, 111 kFrobulateAPIName /* Use existing api name as the key value */,
105 errorMessage); 112 errorMessage);
106 EXPECT_FALSE(isNonExistingApiEnabled); 113 EXPECT_FALSE(isNonExistingApiEnabled);
107 EXPECT_EQ(("The provided key(s) are not valid for the 'This API does not exi st' API."), errorMessage); 114 EXPECT_EQ(("The provided key(s) are not valid for the 'This API does not exi st' API."), errorMessage);
108 } 115 }
109 116
117 TEST_F(ExperimentsTest, EnabledNonExistingAPIWithoutErrorMessage)
118 {
119 bool isNonExistingApiEnabled = isApiEnabledWithoutErrorMessage(
120 kFrobulateEnabledOrigin,
121 kNonExistingAPIName,
122 kFrobulateAPIName /* Use existing api name as the key value */);
123 EXPECT_FALSE(isNonExistingApiEnabled);
124 }
125
110 // The API should be enabled if a valid key for the origin is provided 126 // The API should be enabled if a valid key for the origin is provided
111 TEST_F(ExperimentsTest, EnabledSecureRegisteredOrigin) 127 TEST_F(ExperimentsTest, EnabledSecureRegisteredOrigin)
112 { 128 {
113 String errorMessage; 129 String errorMessage;
114 bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOrigin, 130 bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOrigin,
115 kFrobulateAPIName, 131 kFrobulateAPIName,
116 kFrobulateAPIName /* Use just the api name as the key value */, 132 kFrobulateAPIName /* Use just the api name as the key value */,
117 errorMessage); 133 errorMessage);
118 EXPECT_TRUE(isOriginEnabled); 134 EXPECT_TRUE(isOriginEnabled);
119 EXPECT_TRUE(errorMessage.isEmpty()); 135 EXPECT_TRUE(errorMessage.isEmpty());
120 } 136 }
121 137
138 TEST_F(ExperimentsTest, EnabledSecureRegisteredOriginWithoutErrorMessage)
139 {
140 bool isOriginEnabled = isApiEnabledWithoutErrorMessage(
141 kFrobulateEnabledOrigin,
142 kFrobulateAPIName,
143 kFrobulateAPIName /* Use just the api name as the key value */);
144 EXPECT_TRUE(isOriginEnabled);
145 }
146
122 // The API should not be enabled if the origin is unsecure, even if a valid 147 // The API should not be enabled if the origin is unsecure, even if a valid
123 // key for the origin is provided 148 // key for the origin is provided
124 TEST_F(ExperimentsTest, EnabledNonSecureRegisteredOrigin) 149 TEST_F(ExperimentsTest, EnabledNonSecureRegisteredOrigin)
125 { 150 {
126 String errorMessage; 151 String errorMessage;
127 bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOriginUnsecure, 152 bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOriginUnsecure,
128 kFrobulateAPIName, 153 kFrobulateAPIName,
129 kFrobulateAPIName /* Use just the api name as the key value */, 154 kFrobulateAPIName /* Use just the api name as the key value */,
130 errorMessage); 155 errorMessage);
131 EXPECT_FALSE(isOriginEnabled); 156 EXPECT_FALSE(isOriginEnabled);
132 EXPECT_TRUE(errorMessage.contains("secure origin")) << "Message should indic ate only secure origins are allowed, was: " << errorMessage; 157 EXPECT_TRUE(errorMessage.contains("secure origin")) << "Message should indic ate only secure origins are allowed, was: " << errorMessage;
133 } 158 }
134 159
135 TEST_F(ExperimentsTest, DisabledException) 160 TEST_F(ExperimentsTest, DisabledException)
136 { 161 {
137 DOMException* disabledException = Experiments::createApiDisabledException(kN onExistingAPIName); 162 DOMException* disabledException = Experiments::createApiDisabledException(kN onExistingAPIName);
138 ASSERT_TRUE(disabledException) << "An exception should have been created"; 163 ASSERT_TRUE(disabledException) << "An exception should have been created";
139 EXPECT_EQ(DOMException::getErrorName(NotSupportedError), disabledException-> name()); 164 EXPECT_EQ(DOMException::getErrorName(NotSupportedError), disabledException-> name());
140 EXPECT_TRUE(disabledException->message().contains(kNonExistingAPIName)) << " Message should contain the API name, was: " << disabledException->message(); 165 EXPECT_TRUE(disabledException->message().contains(kNonExistingAPIName)) << " Message should contain the API name, was: " << disabledException->message();
141 } 166 }
142 167
143 } // namespace 168 } // namespace
144 } // namespace blink 169 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698