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

Side by Side Diff: content/common/origin_trials/trial_token_validator_unittest.cc

Issue 2049783002: Refactor OriginTrialPolicy to be an abstract interface in content/public/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-add-revoked-feature-list
Patch Set: Switch to lazy initialization in ChromeContentClient 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 unified diff | Download patch
« no previous file with comments | « content/common/origin_trials/trial_token_validator.cc ('k') | content/content_shell.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/common/origin_trials/trial_token_validator.h" 5 #include "content/common/origin_trials/trial_token_validator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/test/simple_test_clock.h" 11 #include "base/test/simple_test_clock.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/public/common/content_client.h" 13 #include "content/public/common/content_client.h"
14 #include "content/public/common/origin_trial_policy.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h" 16 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 namespace { 21 namespace {
21 22
22 // This is a sample public key for testing the API. The corresponding private 23 // This is a sample public key for testing the API. The corresponding private
23 // key (use this to generate new samples for this test file) is: 24 // key (use this to generate new samples for this test file) is:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Generate this token with the command (in tools/origin_trials): 78 // Generate this token with the command (in tools/origin_trials):
78 // generate_token.py valid.example.com Frobulate --expire-timestamp=1000000000 79 // generate_token.py valid.example.com Frobulate --expire-timestamp=1000000000
79 const char kExpiredToken[] = 80 const char kExpiredToken[] =
80 "AmHPUIXMaXe9jWW8kJeDFXolVjT93p4XMnK4+jMYd2pjqtFcYB1bUmdD8PunQKM+" 81 "AmHPUIXMaXe9jWW8kJeDFXolVjT93p4XMnK4+jMYd2pjqtFcYB1bUmdD8PunQKM+"
81 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" 82 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
82 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" 83 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
83 "IjogMTAwMDAwMDAwMH0="; 84 "IjogMTAwMDAwMDAwMH0=";
84 85
85 const char kUnparsableToken[] = "abcde"; 86 const char kUnparsableToken[] = "abcde";
86 87
87 class TestContentClient : public ContentClient { 88 class TestOriginTrialPolicy : public OriginTrialPolicy {
88 public: 89 public:
89 base::StringPiece GetOriginTrialPublicKey() override { 90 base::StringPiece GetPublicKey() const override {
90 return base::StringPiece(reinterpret_cast<const char*>(key_), 91 return base::StringPiece(reinterpret_cast<const char*>(key_),
91 arraysize(kTestPublicKey)); 92 arraysize(kTestPublicKey));
92 } 93 }
93 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; } 94
95 // Test setup methods
96 void SetPublicKey(const uint8_t* key) { key_ = key; }
97
98 private:
94 const uint8_t* key_ = nullptr; 99 const uint8_t* key_ = nullptr;
95 }; 100 };
96 101
102 class TestContentClient : public ContentClient {
103 public:
104 // ContentRendererClient methods
105 OriginTrialPolicy* GetOriginTrialPolicy() override {
106 return &origin_trial_policy_;
107 }
108 // Test setup methods
109 void SetOriginTrialPublicKey(const uint8_t* key) {
110 origin_trial_policy_.SetPublicKey(key);
111 }
112
113 private:
114 TestOriginTrialPolicy origin_trial_policy_;
115 };
116
97 } // namespace 117 } // namespace
98 118
99 class TrialTokenValidatorTest : public testing::Test { 119 class TrialTokenValidatorTest : public testing::Test {
100 public: 120 public:
101 TrialTokenValidatorTest() 121 TrialTokenValidatorTest()
102 : appropriate_origin_(GURL(kAppropriateOrigin)), 122 : appropriate_origin_(GURL(kAppropriateOrigin)),
103 inappropriate_origin_(GURL(kInappropriateOrigin)), 123 inappropriate_origin_(GURL(kInappropriateOrigin)),
104 insecure_origin_(GURL(kInsecureOrigin)) { 124 insecure_origin_(GURL(kInsecureOrigin)) {
105 SetPublicKey(kTestPublicKey); 125 SetPublicKey(kTestPublicKey);
106 SetContentClient(&test_content_client_); 126 SetContentClient(&test_content_client_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 182 }
163 183
164 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { 184 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) {
165 SetPublicKey(kTestPublicKey2); 185 SetPublicKey(kTestPublicKey2);
166 EXPECT_EQ(blink::WebOriginTrialTokenStatus::InvalidSignature, 186 EXPECT_EQ(blink::WebOriginTrialTokenStatus::InvalidSignature,
167 TrialTokenValidator::ValidateToken( 187 TrialTokenValidator::ValidateToken(
168 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); 188 kSampleToken, appropriate_origin_, kAppropriateFeatureName));
169 } 189 }
170 190
171 } // namespace content 191 } // namespace content
OLDNEW
« no previous file with comments | « content/common/origin_trials/trial_token_validator.cc ('k') | content/content_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698