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/crypto/properties_based_quic_server_info.h" | 5 #include "net/quic/crypto/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 10 matching lines...) Expand all Loading... |
21 const char kChloHashA[] = "chlo_hash_a"; | 21 const char kChloHashA[] = "chlo_hash_a"; |
22 const char kServerConfigSigA[] = "server_config_sig_a"; | 22 const char kServerConfigSigA[] = "server_config_sig_a"; |
23 const char kCertA[] = "cert_a"; | 23 const char kCertA[] = "cert_a"; |
24 const char kCertB[] = "cert_b"; | 24 const char kCertB[] = "cert_b"; |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 class PropertiesBasedQuicServerInfoTest : public ::testing::Test { | 27 class PropertiesBasedQuicServerInfoTest : public ::testing::Test { |
28 protected: | 28 protected: |
29 PropertiesBasedQuicServerInfoTest() | 29 PropertiesBasedQuicServerInfoTest() |
30 : server_id_("www.google.com", 443, PRIVACY_MODE_DISABLED), | 30 : server_id_("www.google.com", 443, PRIVACY_MODE_DISABLED), |
31 server_info_(server_id_, http_server_properties_.GetWeakPtr()) {} | 31 server_info_(server_id_, &http_server_properties_) {} |
32 | 32 |
33 // Initialize |server_info_| object and persist it. | 33 // Initialize |server_info_| object and persist it. |
34 void InitializeAndPersist() { | 34 void InitializeAndPersist() { |
35 server_info_.Start(); | 35 server_info_.Start(); |
36 EXPECT_TRUE(server_info_.IsDataReady()); | 36 EXPECT_TRUE(server_info_.IsDataReady()); |
37 QuicServerInfo::State* state = server_info_.mutable_state(); | 37 QuicServerInfo::State* state = server_info_.mutable_state(); |
38 EXPECT_TRUE(state->certs.empty()); | 38 EXPECT_TRUE(state->certs.empty()); |
39 | 39 |
40 state->server_config = kServerConfigA; | 40 state->server_config = kServerConfigA; |
41 state->source_address_token = kSourceAddressTokenA; | 41 state->source_address_token = kSourceAddressTokenA; |
(...skipping 22 matching lines...) Expand all Loading... |
64 QuicServerId server_id_; | 64 QuicServerId server_id_; |
65 PropertiesBasedQuicServerInfo server_info_; | 65 PropertiesBasedQuicServerInfo server_info_; |
66 CompletionCallback callback_; | 66 CompletionCallback callback_; |
67 }; | 67 }; |
68 | 68 |
69 // Test persisting, reading and verifying and then updating and verifing. | 69 // Test persisting, reading and verifying and then updating and verifing. |
70 TEST_F(PropertiesBasedQuicServerInfoTest, Update) { | 70 TEST_F(PropertiesBasedQuicServerInfoTest, Update) { |
71 InitializeAndPersist(); | 71 InitializeAndPersist(); |
72 | 72 |
73 // Read the persisted data and verify we have read the data correctly. | 73 // Read the persisted data and verify we have read the data correctly. |
74 PropertiesBasedQuicServerInfo server_info1( | 74 PropertiesBasedQuicServerInfo server_info1(server_id_, |
75 server_id_, http_server_properties_.GetWeakPtr()); | 75 &http_server_properties_); |
76 server_info1.Start(); | 76 server_info1.Start(); |
77 EXPECT_EQ(OK, server_info1.WaitForDataReady(callback_)); // Read the data. | 77 EXPECT_EQ(OK, server_info1.WaitForDataReady(callback_)); // Read the data. |
78 EXPECT_TRUE(server_info1.IsDataReady()); | 78 EXPECT_TRUE(server_info1.IsDataReady()); |
79 | 79 |
80 // Verify the data. | 80 // Verify the data. |
81 const QuicServerInfo::State& state1 = server_info1.state(); | 81 const QuicServerInfo::State& state1 = server_info1.state(); |
82 EXPECT_EQ(1U, state1.certs.size()); | 82 EXPECT_EQ(1U, state1.certs.size()); |
83 VerifyInitialData(state1); | 83 VerifyInitialData(state1); |
84 | 84 |
85 // Update the data, by adding another cert. | 85 // Update the data, by adding another cert. |
86 QuicServerInfo::State* state2 = server_info1.mutable_state(); | 86 QuicServerInfo::State* state2 = server_info1.mutable_state(); |
87 state2->certs.push_back(kCertB); | 87 state2->certs.push_back(kCertB); |
88 EXPECT_TRUE(server_info_.IsReadyToPersist()); | 88 EXPECT_TRUE(server_info_.IsReadyToPersist()); |
89 server_info1.Persist(); | 89 server_info1.Persist(); |
90 | 90 |
91 // Read the persisted data and verify we have read the data correctly. | 91 // Read the persisted data and verify we have read the data correctly. |
92 PropertiesBasedQuicServerInfo server_info2( | 92 PropertiesBasedQuicServerInfo server_info2(server_id_, |
93 server_id_, http_server_properties_.GetWeakPtr()); | 93 &http_server_properties_); |
94 server_info2.Start(); | 94 server_info2.Start(); |
95 EXPECT_EQ(OK, server_info2.WaitForDataReady(callback_)); // Read the data. | 95 EXPECT_EQ(OK, server_info2.WaitForDataReady(callback_)); // Read the data. |
96 EXPECT_TRUE(server_info1.IsDataReady()); | 96 EXPECT_TRUE(server_info1.IsDataReady()); |
97 | 97 |
98 // Verify updated data. | 98 // Verify updated data. |
99 const QuicServerInfo::State& state3 = server_info2.state(); | 99 const QuicServerInfo::State& state3 = server_info2.state(); |
100 VerifyInitialData(state3); | 100 VerifyInitialData(state3); |
101 EXPECT_EQ(2U, state3.certs.size()); | 101 EXPECT_EQ(2U, state3.certs.size()); |
102 EXPECT_EQ(kCertB, state3.certs[1]); | 102 EXPECT_EQ(kCertB, state3.certs[1]); |
103 } | 103 } |
104 | 104 |
105 } // namespace test | 105 } // namespace test |
106 } // namespace net | 106 } // namespace net |
OLD | NEW |