OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // This is a sample public key for testing the API. The corresponding private | 22 // This is a sample public key for testing the API. The corresponding private |
22 // key (use this to generate new samples for this test file) is: | 23 // key (use this to generate new samples for this test file) is: |
23 // | 24 // |
24 // 0x83, 0x67, 0xf4, 0xcd, 0x2a, 0x1f, 0x0e, 0x04, 0x0d, 0x43, 0x13, | 25 // 0x83, 0x67, 0xf4, 0xcd, 0x2a, 0x1f, 0x0e, 0x04, 0x0d, 0x43, 0x13, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 114 |
114 const url::Origin appropriate_origin_; | 115 const url::Origin appropriate_origin_; |
115 const url::Origin inappropriate_origin_; | 116 const url::Origin inappropriate_origin_; |
116 const url::Origin insecure_origin_; | 117 const url::Origin insecure_origin_; |
117 | 118 |
118 private: | 119 private: |
119 TestContentClient test_content_client_; | 120 TestContentClient test_content_client_; |
120 }; | 121 }; |
121 | 122 |
122 TEST_F(TrialTokenValidatorTest, ValidateValidToken) { | 123 TEST_F(TrialTokenValidatorTest, ValidateValidToken) { |
123 EXPECT_TRUE(TrialTokenValidator::ValidateToken( | 124 EXPECT_EQ(blink::WebOriginTrialTokenStatus::Success, |
124 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); | 125 TrialTokenValidator::ValidateToken( |
| 126 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); |
125 } | 127 } |
126 | 128 |
127 TEST_F(TrialTokenValidatorTest, ValidateInappropriateOrigin) { | 129 TEST_F(TrialTokenValidatorTest, ValidateInappropriateOrigin) { |
128 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 130 EXPECT_EQ(blink::WebOriginTrialTokenStatus::WrongOrigin, |
129 kSampleToken, inappropriate_origin_, kAppropriateFeatureName)); | 131 TrialTokenValidator::ValidateToken( |
130 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 132 kSampleToken, inappropriate_origin_, kAppropriateFeatureName)); |
131 kSampleToken, insecure_origin_, kAppropriateFeatureName)); | 133 EXPECT_EQ(blink::WebOriginTrialTokenStatus::WrongOrigin, |
| 134 TrialTokenValidator::ValidateToken(kSampleToken, insecure_origin_, |
| 135 kAppropriateFeatureName)); |
132 } | 136 } |
133 | 137 |
134 TEST_F(TrialTokenValidatorTest, ValidateInappropriateFeature) { | 138 TEST_F(TrialTokenValidatorTest, ValidateInappropriateFeature) { |
135 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 139 EXPECT_EQ(blink::WebOriginTrialTokenStatus::WrongFeature, |
136 kSampleToken, appropriate_origin_, kInappropriateFeatureName)); | 140 TrialTokenValidator::ValidateToken( |
| 141 kSampleToken, appropriate_origin_, kInappropriateFeatureName)); |
137 } | 142 } |
138 | 143 |
139 TEST_F(TrialTokenValidatorTest, ValidateInvalidSignature) { | 144 TEST_F(TrialTokenValidatorTest, ValidateInvalidSignature) { |
140 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 145 EXPECT_EQ(blink::WebOriginTrialTokenStatus::InvalidSignature, |
141 kInvalidSignatureToken, appropriate_origin_, kAppropriateFeatureName)); | 146 TrialTokenValidator::ValidateToken(kInvalidSignatureToken, |
| 147 appropriate_origin_, |
| 148 kAppropriateFeatureName)); |
142 } | 149 } |
143 | 150 |
144 TEST_F(TrialTokenValidatorTest, ValidateUnparsableToken) { | 151 TEST_F(TrialTokenValidatorTest, ValidateUnparsableToken) { |
145 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 152 EXPECT_EQ(blink::WebOriginTrialTokenStatus::Malformed, |
146 kUnparsableToken, appropriate_origin_, kAppropriateFeatureName)); | 153 TrialTokenValidator::ValidateToken(kUnparsableToken, |
| 154 appropriate_origin_, |
| 155 kAppropriateFeatureName)); |
147 } | 156 } |
148 | 157 |
149 TEST_F(TrialTokenValidatorTest, ValidateExpiredToken) { | 158 TEST_F(TrialTokenValidatorTest, ValidateExpiredToken) { |
150 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 159 EXPECT_EQ(blink::WebOriginTrialTokenStatus::Expired, |
151 kExpiredToken, appropriate_origin_, kAppropriateFeatureName)); | 160 TrialTokenValidator::ValidateToken( |
| 161 kExpiredToken, appropriate_origin_, kAppropriateFeatureName)); |
152 } | 162 } |
153 | 163 |
154 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { | 164 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { |
155 SetPublicKey(kTestPublicKey2); | 165 SetPublicKey(kTestPublicKey2); |
156 EXPECT_FALSE(TrialTokenValidator::ValidateToken( | 166 EXPECT_EQ(blink::WebOriginTrialTokenStatus::InvalidSignature, |
157 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); | 167 TrialTokenValidator::ValidateToken( |
| 168 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); |
158 } | 169 } |
159 | 170 |
160 } // namespace content | 171 } // namespace content |
OLD | NEW |