OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/http/disk_cache_based_quic_server_info.h" | 5 #include "net/http/disk_cache_based_quic_server_info.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a | 53 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a |
54 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. | 54 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. |
55 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { | 55 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { |
56 // Use the blocking mock backend factory to force asynchronous completion | 56 // Use the blocking mock backend factory to force asynchronous completion |
57 // of quic_server_info->WaitForDataReady(), so that the callback will run. | 57 // of quic_server_info->WaitForDataReady(), so that the callback will run. |
58 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 58 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
59 MockHttpCache cache(factory); | 59 MockHttpCache cache(factory); |
60 QuicSessionKey server_key("www.verisign.com", 443, true, | 60 QuicSessionKey server_key("www.verisign.com", 443, true, |
61 PRIVACY_MODE_DISABLED); | 61 kPrivacyModeDisabled); |
62 scoped_ptr<QuicServerInfo> quic_server_info( | 62 scoped_ptr<QuicServerInfo> quic_server_info( |
63 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 63 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
64 quic_server_info->Start(); | 64 quic_server_info->Start(); |
65 TestCompletionCallback callback; | 65 TestCompletionCallback callback; |
66 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 66 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
67 EXPECT_EQ(ERR_IO_PENDING, rv); | 67 EXPECT_EQ(ERR_IO_PENDING, rv); |
68 // Now complete the backend creation and let the callback run. | 68 // Now complete the backend creation and let the callback run. |
69 factory->FinishCreation(); | 69 factory->FinishCreation(); |
70 EXPECT_EQ(OK, callback.GetResult(rv)); | 70 EXPECT_EQ(OK, callback.GetResult(rv)); |
71 } | 71 } |
72 | 72 |
73 // Tests the basic logic of storing, retrieving and updating data. | 73 // Tests the basic logic of storing, retrieving and updating data. |
74 TEST(DiskCacheBasedQuicServerInfo, Update) { | 74 TEST(DiskCacheBasedQuicServerInfo, Update) { |
75 MockHttpCache cache; | 75 MockHttpCache cache; |
76 AddMockTransaction(&kHostInfoTransaction1); | 76 AddMockTransaction(&kHostInfoTransaction1); |
77 TestCompletionCallback callback; | 77 TestCompletionCallback callback; |
78 | 78 |
79 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); | 79 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); |
80 scoped_ptr<QuicServerInfo> quic_server_info( | 80 scoped_ptr<QuicServerInfo> quic_server_info( |
81 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 81 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
82 quic_server_info->Start(); | 82 quic_server_info->Start(); |
83 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 83 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
84 EXPECT_EQ(OK, callback.GetResult(rv)); | 84 EXPECT_EQ(OK, callback.GetResult(rv)); |
85 | 85 |
86 QuicServerInfo::State* state = quic_server_info->mutable_state(); | 86 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
87 EXPECT_TRUE(state->certs.empty()); | 87 EXPECT_TRUE(state->certs.empty()); |
88 const string server_config_a = "server_config_a"; | 88 const string server_config_a = "server_config_a"; |
89 const string source_address_token_a = "source_address_token_a"; | 89 const string source_address_token_a = "source_address_token_a"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 // Test that demonstrates different info is returned when the ports differ. | 138 // Test that demonstrates different info is returned when the ports differ. |
139 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { | 139 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { |
140 MockHttpCache cache; | 140 MockHttpCache cache; |
141 AddMockTransaction(&kHostInfoTransaction1); | 141 AddMockTransaction(&kHostInfoTransaction1); |
142 AddMockTransaction(&kHostInfoTransaction2); | 142 AddMockTransaction(&kHostInfoTransaction2); |
143 TestCompletionCallback callback; | 143 TestCompletionCallback callback; |
144 | 144 |
145 // Persist data for port 443. | 145 // Persist data for port 443. |
146 QuicSessionKey server_key1("www.google.com", 443, true, | 146 QuicSessionKey server_key1("www.google.com", 443, true, kPrivacyModeDisabled); |
147 PRIVACY_MODE_DISABLED); | |
148 scoped_ptr<QuicServerInfo> quic_server_info1( | 147 scoped_ptr<QuicServerInfo> quic_server_info1( |
149 new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); | 148 new DiskCacheBasedQuicServerInfo(server_key1, cache.http_cache())); |
150 quic_server_info1->Start(); | 149 quic_server_info1->Start(); |
151 int rv = quic_server_info1->WaitForDataReady(callback.callback()); | 150 int rv = quic_server_info1->WaitForDataReady(callback.callback()); |
152 EXPECT_EQ(OK, callback.GetResult(rv)); | 151 EXPECT_EQ(OK, callback.GetResult(rv)); |
153 | 152 |
154 QuicServerInfo::State* state1 = quic_server_info1->mutable_state(); | 153 QuicServerInfo::State* state1 = quic_server_info1->mutable_state(); |
155 EXPECT_TRUE(state1->certs.empty()); | 154 EXPECT_TRUE(state1->certs.empty()); |
156 const string server_config_a = "server_config_a"; | 155 const string server_config_a = "server_config_a"; |
157 const string source_address_token_a = "source_address_token_a"; | 156 const string source_address_token_a = "source_address_token_a"; |
158 const string server_config_sig_a = "server_config_sig_a"; | 157 const string server_config_sig_a = "server_config_sig_a"; |
159 const string cert_a = "cert_a"; | 158 const string cert_a = "cert_a"; |
160 | 159 |
161 state1->server_config = server_config_a; | 160 state1->server_config = server_config_a; |
162 state1->source_address_token = source_address_token_a; | 161 state1->source_address_token = source_address_token_a; |
163 state1->server_config_sig = server_config_sig_a; | 162 state1->server_config_sig = server_config_sig_a; |
164 state1->certs.push_back(cert_a); | 163 state1->certs.push_back(cert_a); |
165 quic_server_info1->Persist(); | 164 quic_server_info1->Persist(); |
166 | 165 |
167 // Wait until Persist() does the work. | 166 // Wait until Persist() does the work. |
168 base::MessageLoop::current()->RunUntilIdle(); | 167 base::MessageLoop::current()->RunUntilIdle(); |
169 | 168 |
170 // Persist data for port 80. | 169 // Persist data for port 80. |
171 QuicSessionKey server_key2("www.google.com", 80, false, | 170 QuicSessionKey server_key2("www.google.com", 80, false, kPrivacyModeDisabled); |
172 PRIVACY_MODE_DISABLED); | |
173 scoped_ptr<QuicServerInfo> quic_server_info2( | 171 scoped_ptr<QuicServerInfo> quic_server_info2( |
174 new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); | 172 new DiskCacheBasedQuicServerInfo(server_key2, cache.http_cache())); |
175 quic_server_info2->Start(); | 173 quic_server_info2->Start(); |
176 rv = quic_server_info2->WaitForDataReady(callback.callback()); | 174 rv = quic_server_info2->WaitForDataReady(callback.callback()); |
177 EXPECT_EQ(OK, callback.GetResult(rv)); | 175 EXPECT_EQ(OK, callback.GetResult(rv)); |
178 | 176 |
179 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); | 177 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
180 EXPECT_TRUE(state2->certs.empty()); | 178 EXPECT_TRUE(state2->certs.empty()); |
181 const string server_config_b = "server_config_b"; | 179 const string server_config_b = "server_config_b"; |
182 const string source_address_token_b = "source_address_token_b"; | 180 const string source_address_token_b = "source_address_token_b"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 RemoveMockTransaction(&kHostInfoTransaction2); | 223 RemoveMockTransaction(&kHostInfoTransaction2); |
226 RemoveMockTransaction(&kHostInfoTransaction1); | 224 RemoveMockTransaction(&kHostInfoTransaction1); |
227 } | 225 } |
228 | 226 |
229 // Test IsReadyToPersist when there is a pending write. | 227 // Test IsReadyToPersist when there is a pending write. |
230 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { | 228 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { |
231 MockHttpCache cache; | 229 MockHttpCache cache; |
232 AddMockTransaction(&kHostInfoTransaction1); | 230 AddMockTransaction(&kHostInfoTransaction1); |
233 TestCompletionCallback callback; | 231 TestCompletionCallback callback; |
234 | 232 |
235 QuicSessionKey server_key("www.google.com", 443, true, PRIVACY_MODE_DISABLED); | 233 QuicSessionKey server_key("www.google.com", 443, true, kPrivacyModeDisabled); |
236 scoped_ptr<QuicServerInfo> quic_server_info( | 234 scoped_ptr<QuicServerInfo> quic_server_info( |
237 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); | 235 new DiskCacheBasedQuicServerInfo(server_key, cache.http_cache())); |
238 EXPECT_FALSE(quic_server_info->IsDataReady()); | 236 EXPECT_FALSE(quic_server_info->IsDataReady()); |
239 quic_server_info->Start(); | 237 quic_server_info->Start(); |
240 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 238 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
241 EXPECT_EQ(OK, callback.GetResult(rv)); | 239 EXPECT_EQ(OK, callback.GetResult(rv)); |
242 EXPECT_TRUE(quic_server_info->IsDataReady()); | 240 EXPECT_TRUE(quic_server_info->IsDataReady()); |
243 | 241 |
244 QuicServerInfo::State* state = quic_server_info->mutable_state(); | 242 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
245 EXPECT_TRUE(state->certs.empty()); | 243 EXPECT_TRUE(state->certs.empty()); |
(...skipping 30 matching lines...) Expand all Loading... |
276 EXPECT_EQ(server_config_a, state1.server_config); | 274 EXPECT_EQ(server_config_a, state1.server_config); |
277 EXPECT_EQ(source_address_token_a, state1.source_address_token); | 275 EXPECT_EQ(source_address_token_a, state1.source_address_token); |
278 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); | 276 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); |
279 EXPECT_EQ(1U, state1.certs.size()); | 277 EXPECT_EQ(1U, state1.certs.size()); |
280 EXPECT_EQ(cert_a, state1.certs[0]); | 278 EXPECT_EQ(cert_a, state1.certs[0]); |
281 | 279 |
282 RemoveMockTransaction(&kHostInfoTransaction1); | 280 RemoveMockTransaction(&kHostInfoTransaction1); |
283 } | 281 } |
284 | 282 |
285 } // namespace net | 283 } // namespace net |
OLD | NEW |