Chromium Code Reviews| Index: third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp |
| diff --git a/third_party/WebKit/Source/core/experiments/ExperimentsTest.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp |
| similarity index 52% |
| rename from third_party/WebKit/Source/core/experiments/ExperimentsTest.cpp |
| rename to third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp |
| index 1be05eee22568f0e2bed203284a26bdb4743673e..90b229cd69799c8529b4f9f1b2c72729293cc02a 100644 |
| --- a/third_party/WebKit/Source/core/experiments/ExperimentsTest.cpp |
| +++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "core/experiments/Experiments.h" |
| +#include "core/origin_trials/OriginTrialContext.h" |
| #include "core/HTMLNames.h" |
| #include "core/dom/DOMException.h" |
| @@ -14,31 +14,31 @@ |
| #include "core/testing/DummyPageHolder.h" |
| #include "platform/weborigin/KURL.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| -#include "public/platform/WebApiKeyValidator.h" |
| +#include "public/platform/WebTrialTokenValidator.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace blink { |
| namespace { |
| -const char* kNonExistingAPIName = "This API does not exist"; |
| -const char* kFrobulateAPIName = "Frobulate"; |
| +const char* kNonExistingFeatureName = "This feature does not exist"; |
| +const char* kFrobulateFeatureName = "Frobulate"; |
| const char* kFrobulateEnabledOrigin = "https://www.example.com"; |
| const char* kFrobulateEnabledOriginUnsecure = "http://www.example.com"; |
| -// API Key which will appear valid |
| -const char* kGoodAPIKey = "AnySignatureWillDo|https://www.example.com|Frobulate|2000000000"; |
| +// Trial token which will appear valid |
| +const char* kGoodToken = "AnySignatureWillDo|https://www.example.com|Frobulate|2000000000"; |
| -class MockApiKeyValidator : public WebApiKeyValidator { |
| +class MockTokenValidator : public WebTrialTokenValidator { |
| public: |
| - MockApiKeyValidator() |
| + MockTokenValidator() |
| : m_response(false) |
| , m_callCount(0) |
| { |
| } |
| - ~MockApiKeyValidator() override {} |
| + ~MockTokenValidator() override {} |
| - // blink::WebApiKeyValidator implementation |
| - bool validateApiKey(const blink::WebString& apiKey, const blink::WebString& origin, const blink::WebString& apiName) override |
| + // blink::WebTrialTokenValidator implementation |
| + bool validateToken(const blink::WebString& token, const blink::WebString& origin, const blink::WebString& featureName) override |
| { |
| m_callCount++; |
| return m_response; |
| @@ -63,24 +63,24 @@ private: |
| bool m_response; |
| int m_callCount; |
| - DISALLOW_COPY_AND_ASSIGN(MockApiKeyValidator); |
| + DISALLOW_COPY_AND_ASSIGN(MockTokenValidator); |
| }; |
| } // namespace |
| -class ExperimentsTest : public ::testing::Test { |
| +class OriginTrialContextTest : public ::testing::Test { |
| protected: |
| - ExperimentsTest() |
| + OriginTrialContextTest() |
| : m_page(DummyPageHolder::create()) |
| , m_frameworkWasEnabled(RuntimeEnabledFeatures::experimentalFrameworkEnabled()) |
| - , m_apiKeyValidator(adoptPtr(new MockApiKeyValidator())) |
| + , m_tokenValidator(adoptPtr(new MockTokenValidator())) |
| { |
| if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) { |
| RuntimeEnabledFeatures::setExperimentalFrameworkEnabled(true); |
| } |
| } |
| - ~ExperimentsTest() |
| + ~OriginTrialContextTest() |
| { |
| if (!m_frameworkWasEnabled) { |
| RuntimeEnabledFeatures::setExperimentalFrameworkEnabled(false); |
| @@ -102,7 +102,7 @@ protected: |
| } |
| ExecutionContext* executionContext() { return &(m_page->document()); } |
| - MockApiKeyValidator* apiKeyValidator() { return m_apiKeyValidator.get(); } |
| + MockTokenValidator* tokenValidator() { return m_tokenValidator.get(); } |
| HTMLDocument& document() const { return *m_document; } |
| void setPageOrigin(const String& origin) |
| @@ -118,7 +118,7 @@ protected: |
| document().view()->updateAllLifecyclePhases(); |
| } |
| - void addApiKey(const String& keyValue) |
| + void addTrialToken(const String& keyValue) |
|
chasej
2016/01/26 16:56:53
Should be tokenValue.
iclelland
2016/01/26 19:05:49
Renamed to 'token' for consistency with the method
|
| { |
| HTMLElement* head = document().head(); |
| ASSERT_TRUE(head); |
| @@ -130,105 +130,105 @@ protected: |
| head->appendChild(meta.release()); |
| } |
| - bool isApiEnabled(const String& origin, const String& apiName, const String& apiKeyValue, String* errorMessage) |
| + bool isFeatureEnabled(const String& origin, const String& featureName, const String& token, String* errorMessage) |
| { |
| setPageOrigin(origin); |
| - addApiKey(apiKeyValue); |
| - return Experiments::isApiEnabled(executionContext(), apiName, errorMessage, apiKeyValidator()); |
| + addTrialToken(token); |
| + return OriginTrialContext::isFeatureEnabled(executionContext(), featureName, errorMessage, tokenValidator()); |
| } |
| - bool isApiEnabledWithoutErrorMessage(const String& origin, const String& apiName, const char* apiKeyValue) |
| + bool isFeatureEnabledWithoutErrorMessage(const String& origin, const String& featureName, const char* token) |
| { |
| - return isApiEnabled(origin, apiName, apiKeyValue, nullptr); |
| + return isFeatureEnabled(origin, featureName, token, nullptr); |
| } |
| private: |
| OwnPtr<DummyPageHolder> m_page; |
| RefPtrWillBePersistent<HTMLDocument> m_document; |
| const bool m_frameworkWasEnabled; |
| - OwnPtr<MockApiKeyValidator> m_apiKeyValidator; |
| + OwnPtr<MockTokenValidator> m_tokenValidator; |
| }; |
| -TEST_F(ExperimentsTest, EnabledNonExistingAPI) |
| +TEST_F(OriginTrialContextTest, EnabledNonExistingFeature) |
| { |
| String errorMessage; |
| - bool isNonExistingApiEnabled = isApiEnabled(kFrobulateEnabledOrigin, |
| - kNonExistingAPIName, |
| - kGoodAPIKey, |
| + bool isNonExistingFeatureEnabled = isFeatureEnabled(kFrobulateEnabledOrigin, |
| + kNonExistingFeatureName, |
| + kGoodToken, |
| &errorMessage); |
| - EXPECT_FALSE(isNonExistingApiEnabled); |
| - EXPECT_EQ(("The provided key(s) are not valid for the 'This API does not exist' API."), errorMessage); |
| + EXPECT_FALSE(isNonExistingFeatureEnabled); |
| + EXPECT_EQ(("The provided token(s) are not valid for the 'This feature does not exist' API."), errorMessage); |
|
chasej
2016/01/26 16:56:53
Error message should have "feature", not "API".
iclelland
2016/01/26 19:05:49
Done.
|
| } |
| -TEST_F(ExperimentsTest, EnabledNonExistingAPIWithoutErrorMessage) |
| +TEST_F(OriginTrialContextTest, EnabledNonExistingFeatureWithoutErrorMessage) |
| { |
| - bool isNonExistingApiEnabled = isApiEnabledWithoutErrorMessage( |
| + bool isNonExistingFeatureEnabled = isFeatureEnabledWithoutErrorMessage( |
| kFrobulateEnabledOrigin, |
| - kNonExistingAPIName, |
| - kGoodAPIKey); |
| - EXPECT_FALSE(isNonExistingApiEnabled); |
| + kNonExistingFeatureName, |
| + kGoodToken); |
| + EXPECT_FALSE(isNonExistingFeatureEnabled); |
| } |
| -// The API should be enabled if a valid key for the origin is provided |
| -TEST_F(ExperimentsTest, EnabledSecureRegisteredOrigin) |
| +// The feature should be enabled if a valid token for the origin is provided |
| +TEST_F(OriginTrialContextTest, EnabledSecureRegisteredOrigin) |
| { |
| String errorMessage; |
| - apiKeyValidator()->setResponse(true); |
| - bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOrigin, |
| - kFrobulateAPIName, |
| - kGoodAPIKey, |
| + tokenValidator()->setResponse(true); |
| + bool isOriginEnabled = isFeatureEnabled(kFrobulateEnabledOrigin, |
| + kFrobulateFeatureName, |
| + kGoodToken, |
| &errorMessage); |
| EXPECT_TRUE(isOriginEnabled); |
| EXPECT_TRUE(errorMessage.isEmpty()) << "Message should be empty, was: " << errorMessage; |
| - EXPECT_EQ(1, apiKeyValidator()->callCount()); |
| + EXPECT_EQ(1, tokenValidator()->callCount()); |
| } |
| // ... but if the browser says it's invalid for any reason, that's enough to |
| // reject. |
| -TEST_F(ExperimentsTest, InvalidKeyResponseFromPlatform) |
| +TEST_F(OriginTrialContextTest, InvalidKeyResponseFromPlatform) |
|
chasej
2016/01/26 16:56:53
Should be InvalidTokenResponseFromPlatform.
iclelland
2016/01/26 19:05:49
Done.
|
| { |
| String errorMessage; |
| - apiKeyValidator()->setResponse(false); |
| - bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOrigin, |
| - kFrobulateAPIName, |
| - kGoodAPIKey, |
| + tokenValidator()->setResponse(false); |
| + bool isOriginEnabled = isFeatureEnabled(kFrobulateEnabledOrigin, |
| + kFrobulateFeatureName, |
| + kGoodToken, |
| &errorMessage); |
| EXPECT_FALSE(isOriginEnabled); |
| - EXPECT_EQ(("The provided key(s) are not valid for the 'Frobulate' API."), errorMessage); |
| - EXPECT_EQ(1, apiKeyValidator()->callCount()); |
| + EXPECT_EQ(("The provided token(s) are not valid for the 'Frobulate' API."), errorMessage); |
|
chasej
2016/01/26 16:56:53
Error message should have "feature", not "API".
iclelland
2016/01/26 19:05:48
Done.
|
| + EXPECT_EQ(1, tokenValidator()->callCount()); |
| } |
| -TEST_F(ExperimentsTest, EnabledSecureRegisteredOriginWithoutErrorMessage) |
| +TEST_F(OriginTrialContextTest, EnabledSecureRegisteredOriginWithoutErrorMessage) |
| { |
| - apiKeyValidator()->setResponse(true); |
| - bool isOriginEnabled = isApiEnabledWithoutErrorMessage( |
| + tokenValidator()->setResponse(true); |
| + bool isOriginEnabled = isFeatureEnabledWithoutErrorMessage( |
| kFrobulateEnabledOrigin, |
| - kFrobulateAPIName, |
| - kGoodAPIKey); |
| + kFrobulateFeatureName, |
| + kGoodToken); |
| EXPECT_TRUE(isOriginEnabled); |
| - EXPECT_EQ(1, apiKeyValidator()->callCount()); |
| + EXPECT_EQ(1, tokenValidator()->callCount()); |
| } |
| -// The API should not be enabled if the origin is unsecure, even if a valid |
| -// key for the origin is provided |
| -TEST_F(ExperimentsTest, EnabledNonSecureRegisteredOrigin) |
| +// The feature should not be enabled if the origin is unsecure, even if a valid |
| +// token for the origin is provided |
| +TEST_F(OriginTrialContextTest, EnabledNonSecureRegisteredOrigin) |
| { |
| String errorMessage; |
| - bool isOriginEnabled = isApiEnabled(kFrobulateEnabledOriginUnsecure, |
| - kFrobulateAPIName, |
| - kGoodAPIKey, |
| + bool isOriginEnabled = isFeatureEnabled(kFrobulateEnabledOriginUnsecure, |
| + kFrobulateFeatureName, |
| + kGoodToken, |
| &errorMessage); |
| EXPECT_FALSE(isOriginEnabled); |
| EXPECT_TRUE(errorMessage.contains("secure origin")) << "Message should indicate only secure origins are allowed, was: " << errorMessage; |
| - EXPECT_EQ(0, apiKeyValidator()->callCount()); |
| + EXPECT_EQ(0, tokenValidator()->callCount()); |
| } |
| -TEST_F(ExperimentsTest, DisabledException) |
| +TEST_F(OriginTrialContextTest, DisabledException) |
| { |
| - DOMException* disabledException = Experiments::createApiDisabledException(kNonExistingAPIName); |
| + DOMException* disabledException = OriginTrialContext::createApiDisabledException(kNonExistingFeatureName); |
| ASSERT_TRUE(disabledException) << "An exception should have been created"; |
| EXPECT_EQ(DOMException::getErrorName(NotSupportedError), disabledException->name()); |
| - EXPECT_TRUE(disabledException->message().contains(kNonExistingAPIName)) << "Message should contain the API name, was: " << disabledException->message(); |
| + EXPECT_TRUE(disabledException->message().contains(kNonExistingFeatureName)) << "Message should contain the feature name, was: " << disabledException->message(); |
| } |
| } // namespace blink |