| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromium/properties_based_quic_server_info.h" | 5 #include "net/quic/chromium/properties_based_quic_server_info.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_server_properties_impl.h" | 10 #include "net/http/http_server_properties_impl.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 class PropertiesBasedQuicServerInfoTest : public ::testing::Test { | 29 class PropertiesBasedQuicServerInfoTest : public ::testing::Test { |
| 30 protected: | 30 protected: |
| 31 PropertiesBasedQuicServerInfoTest() | 31 PropertiesBasedQuicServerInfoTest() |
| 32 : server_id_("www.google.com", 443, PRIVACY_MODE_DISABLED), | 32 : server_id_("www.google.com", 443, PRIVACY_MODE_DISABLED), |
| 33 server_info_(server_id_, &http_server_properties_) {} | 33 server_info_(server_id_, &http_server_properties_) {} |
| 34 | 34 |
| 35 // Initialize |server_info_| object and persist it. | 35 // Initialize |server_info_| object and persist it. |
| 36 void InitializeAndPersist() { | 36 void InitializeAndPersist() { |
| 37 server_info_.Start(); | |
| 38 EXPECT_TRUE(server_info_.IsDataReady()); | |
| 39 QuicServerInfo::State* state = server_info_.mutable_state(); | 37 QuicServerInfo::State* state = server_info_.mutable_state(); |
| 40 EXPECT_TRUE(state->certs.empty()); | 38 EXPECT_TRUE(state->certs.empty()); |
| 41 | 39 |
| 42 state->server_config = kServerConfigA; | 40 state->server_config = kServerConfigA; |
| 43 state->source_address_token = kSourceAddressTokenA; | 41 state->source_address_token = kSourceAddressTokenA; |
| 44 state->server_config_sig = kServerConfigSigA; | 42 state->server_config_sig = kServerConfigSigA; |
| 45 state->cert_sct = kCertSCTA; | 43 state->cert_sct = kCertSCTA; |
| 46 state->chlo_hash = kChloHashA; | 44 state->chlo_hash = kChloHashA; |
| 47 state->certs.push_back(kCertA); | 45 state->certs.push_back(kCertA); |
| 48 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 49 server_info_.Persist(); | 46 server_info_.Persist(); |
| 50 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 51 EXPECT_TRUE(server_info_.IsDataReady()); | |
| 52 server_info_.OnExternalCacheHit(); | |
| 53 } | 47 } |
| 54 | 48 |
| 55 // Verify the data that is persisted in InitializeAndPersist(). | 49 // Verify the data that is persisted in InitializeAndPersist(). |
| 56 void VerifyInitialData(const QuicServerInfo::State& state) { | 50 void VerifyInitialData(const QuicServerInfo::State& state) { |
| 57 EXPECT_EQ(kServerConfigA, state.server_config); | 51 EXPECT_EQ(kServerConfigA, state.server_config); |
| 58 EXPECT_EQ(kSourceAddressTokenA, state.source_address_token); | 52 EXPECT_EQ(kSourceAddressTokenA, state.source_address_token); |
| 59 EXPECT_EQ(kCertSCTA, state.cert_sct); | 53 EXPECT_EQ(kCertSCTA, state.cert_sct); |
| 60 EXPECT_EQ(kChloHashA, state.chlo_hash); | 54 EXPECT_EQ(kChloHashA, state.chlo_hash); |
| 61 EXPECT_EQ(kServerConfigSigA, state.server_config_sig); | 55 EXPECT_EQ(kServerConfigSigA, state.server_config_sig); |
| 62 EXPECT_EQ(kCertA, state.certs[0]); | 56 EXPECT_EQ(kCertA, state.certs[0]); |
| 63 } | 57 } |
| 64 | 58 |
| 65 HttpServerPropertiesImpl http_server_properties_; | 59 HttpServerPropertiesImpl http_server_properties_; |
| 66 QuicServerId server_id_; | 60 QuicServerId server_id_; |
| 67 PropertiesBasedQuicServerInfo server_info_; | 61 PropertiesBasedQuicServerInfo server_info_; |
| 68 CompletionCallback callback_; | 62 CompletionCallback callback_; |
| 69 }; | 63 }; |
| 70 | 64 |
| 71 // Test persisting, reading and verifying and then updating and verifing. | 65 // Test persisting, reading and verifying and then updating and verifing. |
| 72 TEST_F(PropertiesBasedQuicServerInfoTest, Update) { | 66 TEST_F(PropertiesBasedQuicServerInfoTest, Update) { |
| 73 InitializeAndPersist(); | 67 InitializeAndPersist(); |
| 74 | 68 |
| 75 // Read the persisted data and verify we have read the data correctly. | 69 // Read the persisted data and verify we have read the data correctly. |
| 76 PropertiesBasedQuicServerInfo server_info1(server_id_, | 70 PropertiesBasedQuicServerInfo server_info1(server_id_, |
| 77 &http_server_properties_); | 71 &http_server_properties_); |
| 78 server_info1.Start(); | 72 EXPECT_TRUE(server_info1.Load()); |
| 79 EXPECT_THAT(server_info1.WaitForDataReady(callback_), | |
| 80 IsOk()); // Read the data. | |
| 81 EXPECT_TRUE(server_info1.IsDataReady()); | |
| 82 | 73 |
| 83 // Verify the data. | 74 // Verify the data. |
| 84 const QuicServerInfo::State& state1 = server_info1.state(); | 75 const QuicServerInfo::State& state1 = server_info1.state(); |
| 85 EXPECT_EQ(1U, state1.certs.size()); | 76 EXPECT_EQ(1U, state1.certs.size()); |
| 86 VerifyInitialData(state1); | 77 VerifyInitialData(state1); |
| 87 | 78 |
| 88 // Update the data, by adding another cert. | 79 // Update the data, by adding another cert. |
| 89 QuicServerInfo::State* state2 = server_info1.mutable_state(); | 80 QuicServerInfo::State* state2 = server_info1.mutable_state(); |
| 90 state2->certs.push_back(kCertB); | 81 state2->certs.push_back(kCertB); |
| 91 EXPECT_TRUE(server_info_.IsReadyToPersist()); | |
| 92 server_info1.Persist(); | 82 server_info1.Persist(); |
| 93 | 83 |
| 94 // Read the persisted data and verify we have read the data correctly. | 84 // Read the persisted data and verify we have read the data correctly. |
| 95 PropertiesBasedQuicServerInfo server_info2(server_id_, | 85 PropertiesBasedQuicServerInfo server_info2(server_id_, |
| 96 &http_server_properties_); | 86 &http_server_properties_); |
| 97 server_info2.Start(); | 87 EXPECT_TRUE(server_info2.Load()); |
| 98 EXPECT_THAT(server_info2.WaitForDataReady(callback_), | |
| 99 IsOk()); // Read the data. | |
| 100 EXPECT_TRUE(server_info1.IsDataReady()); | |
| 101 | 88 |
| 102 // Verify updated data. | 89 // Verify updated data. |
| 103 const QuicServerInfo::State& state3 = server_info2.state(); | 90 const QuicServerInfo::State& state3 = server_info2.state(); |
| 104 VerifyInitialData(state3); | 91 VerifyInitialData(state3); |
| 105 EXPECT_EQ(2U, state3.certs.size()); | 92 EXPECT_EQ(2U, state3.certs.size()); |
| 106 EXPECT_EQ(kCertB, state3.certs[1]); | 93 EXPECT_EQ(kCertB, state3.certs[1]); |
| 107 } | 94 } |
| 108 | 95 |
| 109 } // namespace test | 96 } // namespace test |
| 110 } // namespace net | 97 } // namespace net |
| OLD | NEW |