| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/quic/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/proof_verifier.h" | 7 #include "net/quic/crypto/proof_verifier.h" |
| 8 #include "net/quic/quic_server_id.h" | 8 #include "net/quic/quic_server_id.h" |
| 9 #include "net/quic/test_tools/mock_random.h" | 9 #include "net/quic/test_tools/mock_random.h" |
| 10 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // TODO(rch): Populate other fields of |state|. | 222 // TODO(rch): Populate other fields of |state|. |
| 223 state->set_source_address_token("TOKEN"); | 223 state->set_source_address_token("TOKEN"); |
| 224 | 224 |
| 225 // Do not set the proof as valid, and check that it is not used | 225 // Do not set the proof as valid, and check that it is not used |
| 226 // as a canonical entry. | 226 // as a canonical entry. |
| 227 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); | 227 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { | 230 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { |
| 231 QuicCryptoClientConfig config; | 231 QuicCryptoClientConfig config; |
| 232 QuicServerId canonical_server_id("www.google.com", 80, false, | 232 QuicServerId server_id("www.google.com", 80, false, PRIVACY_MODE_DISABLED); |
| 233 PRIVACY_MODE_DISABLED); | 233 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); |
| 234 QuicCryptoClientConfig::CachedState* state = | |
| 235 config.LookupOrCreate(canonical_server_id); | |
| 236 // TODO(rch): Populate other fields of |state|. | 234 // TODO(rch): Populate other fields of |state|. |
| 237 vector<string> certs(1); | 235 vector<string> certs(1); |
| 238 certs[0] = "Hello Cert"; | 236 certs[0] = "Hello Cert"; |
| 239 state->SetProof(certs, "signature"); | 237 state->SetProof(certs, "signature"); |
| 240 state->set_source_address_token("TOKEN"); | 238 state->set_source_address_token("TOKEN"); |
| 241 state->SetProofValid(); | 239 state->SetProofValid(); |
| 240 EXPECT_EQ(1u, state->generation_counter()); |
| 242 | 241 |
| 243 // Verify LookupOrCreate returns the same data. | 242 // Verify LookupOrCreate returns the same data. |
| 244 QuicServerId other_server_id("www.google.com", 80, false, | 243 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(server_id); |
| 245 PRIVACY_MODE_DISABLED); | |
| 246 | 244 |
| 247 QuicCryptoClientConfig::CachedState* other = | 245 EXPECT_EQ(state, other); |
| 248 config.LookupOrCreate(other_server_id); | |
| 249 | |
| 250 EXPECT_TRUE(other->proof_valid()); | |
| 251 EXPECT_EQ(state->server_config(), other->server_config()); | |
| 252 EXPECT_EQ(state->signature(), other->signature()); | |
| 253 EXPECT_EQ(state->certs(), other->certs()); | |
| 254 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | |
| 255 EXPECT_EQ(1u, other->generation_counter()); | 246 EXPECT_EQ(1u, other->generation_counter()); |
| 256 | 247 |
| 257 // Clear the cached state. | 248 // Clear the cached states. |
| 258 config.ClearCachedStates(); | 249 config.ClearCachedStates(); |
| 259 | 250 |
| 260 // Verify LookupOrCreate doesn't have any data. | 251 // Verify LookupOrCreate doesn't have any data. |
| 261 QuicCryptoClientConfig::CachedState* cleared_cache = | 252 QuicCryptoClientConfig::CachedState* cleared_cache = |
| 262 config.LookupOrCreate(other_server_id); | 253 config.LookupOrCreate(server_id); |
| 263 | 254 |
| 255 EXPECT_EQ(state, cleared_cache); |
| 264 EXPECT_FALSE(cleared_cache->proof_valid()); | 256 EXPECT_FALSE(cleared_cache->proof_valid()); |
| 265 EXPECT_TRUE(cleared_cache->server_config().empty()); | 257 EXPECT_TRUE(cleared_cache->server_config().empty()); |
| 266 EXPECT_TRUE(cleared_cache->certs().empty()); | 258 EXPECT_TRUE(cleared_cache->certs().empty()); |
| 267 EXPECT_TRUE(cleared_cache->signature().empty()); | 259 EXPECT_TRUE(cleared_cache->signature().empty()); |
| 268 EXPECT_LT(1u, cleared_cache->generation_counter()); | 260 EXPECT_EQ(2u, cleared_cache->generation_counter()); |
| 269 } | 261 } |
| 270 | 262 |
| 271 } // namespace test | 263 } // namespace test |
| 272 } // namespace net | 264 } // namespace net |
| OLD | NEW |