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

Unified Diff: third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp

Issue 1635593004: Rename Experimental Framework classes and concepts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
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 50%
rename from third_party/WebKit/Source/core/experiments/ExperimentsTest.cpp
rename to third_party/WebKit/Source/core/origin_trials/OriginTrialContextTest.cpp
index aa90cf64940656f484d1b103cbeda0ac9d934187..ef186159bdd18b9b5776b85881a028b27d88ed36 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 that 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,117 +118,109 @@ protected:
document().view()->updateAllLifecyclePhases();
}
- void addApiKey(const String& keyValue)
+ void addTrialToken(const String& token)
{
HTMLElement* head = document().head();
ASSERT_TRUE(head);
RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(document());
meta->setAttribute(HTMLNames::nameAttr, "api-experiments");
- AtomicString value(keyValue);
+ AtomicString value(token);
meta->setAttribute(HTMLNames::contentAttr, value);
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' feature."), errorMessage);
}
-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, InvalidTokenResponseFromPlatform)
{
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' feature."), errorMessage);
+ 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());
-}
-
-TEST_F(ExperimentsTest, DisabledException)
-{
- DOMException* disabledException = Experiments::createApiDisabledException(kNonExistingAPIName);
- 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_EQ(0, tokenValidator()->callCount());
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698