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

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: Const correctness; clear disabled features 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
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 8cce482bb260918b8bb934b78b77877725724b02..363e3d8dd5c8c10150f9562282e2fe7181fe9da0 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"
@@ -86,12 +88,24 @@ const char kUnparsableToken[] = "abcde";
class TestContentClient : public ContentClient {
public:
- base::StringPiece GetOriginTrialPublicKey() override {
+ // ContentRendererClient methods
+ base::StringPiece GetOriginTrialPublicKey() const override {
return base::StringPiece(reinterpret_cast<const char*>(key_),
arraysize(kTestPublicKey));
}
+ bool IsOriginTrialFeatureDisabled(base::StringPiece feature) const override {
+ return disabled_features_.count(feature.as_string()) > 0;
+ }
+
+ // Test setup methods
void SetOriginTrialPublicKey(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_;
};
} // namespace
@@ -112,6 +126,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_;
@@ -168,4 +186,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

Powered by Google App Engine
This is Rietveld 408576698