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

Unified Diff: content/common/origin_trials/trial_token_validator_unittest.cc

Issue 1741783002: Add disabled origin trial feature list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-finch
Patch Set: Rebase Created 4 years, 6 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
« no previous file with comments | « content/common/origin_trials/trial_token_validator.cc ('k') | content/public/common/origin_trial_policy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/origin_trials/trial_token_validator_unittest.cc
diff --git a/content/common/origin_trials/trial_token_validator_unittest.cc b/content/common/origin_trials/trial_token_validator_unittest.cc
index 6cd219af8cff04dbb1483047f86807ce18aab968..af18d2276003ea550abfa79e4380b476c664d395 100644
--- a/content/common/origin_trials/trial_token_validator_unittest.cc
+++ b/content/common/origin_trials/trial_token_validator_unittest.cc
@@ -5,6 +5,8 @@
#include "content/common/origin_trials/trial_token_validator.h"
#include <memory>
+#include <set>
+#include <string>
#include "base/macros.h"
#include "base/strings/string_util.h"
@@ -91,12 +93,19 @@ class TestOriginTrialPolicy : public OriginTrialPolicy {
return base::StringPiece(reinterpret_cast<const char*>(key_),
arraysize(kTestPublicKey));
}
+ bool IsFeatureDisabled(base::StringPiece feature) const override {
+ return disabled_features_.count(feature.as_string()) > 0;
+ }
// Test setup methods
void SetPublicKey(const uint8_t* key) { key_ = key; }
+ void DisableFeature(const std::string& feature) {
+ disabled_features_.insert(feature);
+ }
private:
const uint8_t* key_ = nullptr;
+ std::set<std::string> disabled_features_;
};
class TestContentClient : public ContentClient {
@@ -109,6 +118,9 @@ class TestContentClient : public ContentClient {
void SetOriginTrialPublicKey(const uint8_t* key) {
origin_trial_policy_.SetPublicKey(key);
}
+ void DisableFeature(const std::string& feature) {
+ origin_trial_policy_.DisableFeature(feature);
+ }
private:
TestOriginTrialPolicy origin_trial_policy_;
@@ -132,6 +144,10 @@ class TrialTokenValidatorTest : public testing::Test {
test_content_client_.SetOriginTrialPublicKey(key);
}
+ void DisableFeature(const std::string& feature) {
+ test_content_client_.DisableFeature(feature);
+ }
+
const url::Origin appropriate_origin_;
const url::Origin inappropriate_origin_;
const url::Origin insecure_origin_;
@@ -188,4 +204,17 @@ TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) {
kSampleToken, appropriate_origin_, kAppropriateFeatureName));
}
+TEST_F(TrialTokenValidatorTest, ValidatorRespectsDisabledFeatures) {
+ // Disable an irrelevant feature; token should still validate
+ DisableFeature(kInappropriateFeatureName);
+ EXPECT_EQ(blink::WebOriginTrialTokenStatus::Success,
+ TrialTokenValidator::ValidateToken(
+ kSampleToken, appropriate_origin_, kAppropriateFeatureName));
+ // Disable the token's feature; it should no longer be valid
+ DisableFeature(kAppropriateFeatureName);
+ EXPECT_EQ(blink::WebOriginTrialTokenStatus::FeatureDisabled,
+ TrialTokenValidator::ValidateToken(
+ kSampleToken, appropriate_origin_, kAppropriateFeatureName));
+}
+
} // namespace content
« no previous file with comments | « content/common/origin_trials/trial_token_validator.cc ('k') | content/public/common/origin_trial_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698