Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: net/http/disk_cache_based_quic_server_info_unittest.cc

Issue 1411063004: Remove insecure QUIC support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enough! Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 "", 32 "",
33 TEST_MODE_NORMAL, 33 TEST_MODE_NORMAL,
34 nullptr, 34 nullptr,
35 nullptr, 35 nullptr,
36 0, 36 0,
37 0, 37 0,
38 OK, 38 OK,
39 }; 39 };
40 40
41 const MockTransaction kHostInfoTransaction2 = { 41 const MockTransaction kHostInfoTransaction2 = {
42 "quicserverinfo:http://www.google.com:80", 42 "quicserverinfo:https://www.google.com:80",
43 "", 43 "",
44 base::Time(), 44 base::Time(),
45 "", 45 "",
46 LOAD_NORMAL, 46 LOAD_NORMAL,
47 "", 47 "",
48 "", 48 "",
49 base::Time(), 49 base::Time(),
50 "", 50 "",
51 TEST_MODE_NORMAL, 51 TEST_MODE_NORMAL,
52 nullptr, 52 nullptr,
(...skipping 26 matching lines...) Expand all
79 79
80 } // namespace 80 } // namespace
81 81
82 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a 82 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a
83 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. 83 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady.
84 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { 84 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) {
85 // Use the blocking mock backend factory to force asynchronous completion 85 // Use the blocking mock backend factory to force asynchronous completion
86 // of quic_server_info->WaitForDataReady(), so that the callback will run. 86 // of quic_server_info->WaitForDataReady(), so that the callback will run.
87 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 87 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
88 MockHttpCache cache(factory); 88 MockHttpCache cache(factory);
89 QuicServerId server_id("www.verisign.com", 443, true, PRIVACY_MODE_DISABLED); 89 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED);
90 scoped_ptr<QuicServerInfo> quic_server_info( 90 scoped_ptr<QuicServerInfo> quic_server_info(
91 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 91 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
92 quic_server_info->Start(); 92 quic_server_info->Start();
93 TestCompletionCallback callback; 93 TestCompletionCallback callback;
94 int rv = quic_server_info->WaitForDataReady(callback.callback()); 94 int rv = quic_server_info->WaitForDataReady(callback.callback());
95 EXPECT_EQ(ERR_IO_PENDING, rv); 95 EXPECT_EQ(ERR_IO_PENDING, rv);
96 // Now complete the backend creation and let the callback run. 96 // Now complete the backend creation and let the callback run.
97 factory->FinishCreation(); 97 factory->FinishCreation();
98 EXPECT_EQ(OK, callback.GetResult(rv)); 98 EXPECT_EQ(OK, callback.GetResult(rv));
99 } 99 }
100 100
101 // Tests the basic logic of storing, retrieving and updating data. 101 // Tests the basic logic of storing, retrieving and updating data.
102 TEST(DiskCacheBasedQuicServerInfo, Update) { 102 TEST(DiskCacheBasedQuicServerInfo, Update) {
103 MockHttpCache cache; 103 MockHttpCache cache;
104 AddMockTransaction(&kHostInfoTransaction1); 104 AddMockTransaction(&kHostInfoTransaction1);
105 TestCompletionCallback callback; 105 TestCompletionCallback callback;
106 106
107 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 107 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
108 scoped_ptr<QuicServerInfo> quic_server_info( 108 scoped_ptr<QuicServerInfo> quic_server_info(
109 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 109 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
110 quic_server_info->Start(); 110 quic_server_info->Start();
111 int rv = quic_server_info->WaitForDataReady(callback.callback()); 111 int rv = quic_server_info->WaitForDataReady(callback.callback());
112 EXPECT_EQ(OK, callback.GetResult(rv)); 112 EXPECT_EQ(OK, callback.GetResult(rv));
113 113
114 QuicServerInfo::State* state = quic_server_info->mutable_state(); 114 QuicServerInfo::State* state = quic_server_info->mutable_state();
115 EXPECT_TRUE(state->certs.empty()); 115 EXPECT_TRUE(state->certs.empty());
116 const string server_config_a = "server_config_a"; 116 const string server_config_a = "server_config_a";
117 const string source_address_token_a = "source_address_token_a"; 117 const string source_address_token_a = "source_address_token_a";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 // Test that demonstrates different info is returned when the ports differ. 166 // Test that demonstrates different info is returned when the ports differ.
167 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { 167 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) {
168 MockHttpCache cache; 168 MockHttpCache cache;
169 AddMockTransaction(&kHostInfoTransaction1); 169 AddMockTransaction(&kHostInfoTransaction1);
170 AddMockTransaction(&kHostInfoTransaction2); 170 AddMockTransaction(&kHostInfoTransaction2);
171 TestCompletionCallback callback; 171 TestCompletionCallback callback;
172 172
173 // Persist data for port 443. 173 // Persist data for port 443.
174 QuicServerId server_id1("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 174 QuicServerId server_id1("www.google.com", 443, PRIVACY_MODE_DISABLED);
175 scoped_ptr<QuicServerInfo> quic_server_info1( 175 scoped_ptr<QuicServerInfo> quic_server_info1(
176 new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache())); 176 new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache()));
177 quic_server_info1->Start(); 177 quic_server_info1->Start();
178 int rv = quic_server_info1->WaitForDataReady(callback.callback()); 178 int rv = quic_server_info1->WaitForDataReady(callback.callback());
179 EXPECT_EQ(OK, callback.GetResult(rv)); 179 EXPECT_EQ(OK, callback.GetResult(rv));
180 180
181 QuicServerInfo::State* state1 = quic_server_info1->mutable_state(); 181 QuicServerInfo::State* state1 = quic_server_info1->mutable_state();
182 EXPECT_TRUE(state1->certs.empty()); 182 EXPECT_TRUE(state1->certs.empty());
183 const string server_config_a = "server_config_a"; 183 const string server_config_a = "server_config_a";
184 const string source_address_token_a = "source_address_token_a"; 184 const string source_address_token_a = "source_address_token_a";
185 const string server_config_sig_a = "server_config_sig_a"; 185 const string server_config_sig_a = "server_config_sig_a";
186 const string cert_a = "cert_a"; 186 const string cert_a = "cert_a";
187 187
188 state1->server_config = server_config_a; 188 state1->server_config = server_config_a;
189 state1->source_address_token = source_address_token_a; 189 state1->source_address_token = source_address_token_a;
190 state1->server_config_sig = server_config_sig_a; 190 state1->server_config_sig = server_config_sig_a;
191 state1->certs.push_back(cert_a); 191 state1->certs.push_back(cert_a);
192 quic_server_info1->Persist(); 192 quic_server_info1->Persist();
193 193
194 // Wait until Persist() does the work. 194 // Wait until Persist() does the work.
195 base::MessageLoop::current()->RunUntilIdle(); 195 base::MessageLoop::current()->RunUntilIdle();
196 196
197 // Persist data for port 80. 197 // Persist data for port 80.
198 QuicServerId server_id2("www.google.com", 80, false, PRIVACY_MODE_DISABLED); 198 QuicServerId server_id2("www.google.com", 80, PRIVACY_MODE_DISABLED);
199 scoped_ptr<QuicServerInfo> quic_server_info2( 199 scoped_ptr<QuicServerInfo> quic_server_info2(
200 new DiskCacheBasedQuicServerInfo(server_id2, cache.http_cache())); 200 new DiskCacheBasedQuicServerInfo(server_id2, cache.http_cache()));
201 quic_server_info2->Start(); 201 quic_server_info2->Start();
202 rv = quic_server_info2->WaitForDataReady(callback.callback()); 202 rv = quic_server_info2->WaitForDataReady(callback.callback());
203 EXPECT_EQ(OK, callback.GetResult(rv)); 203 EXPECT_EQ(OK, callback.GetResult(rv));
204 204
205 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); 205 QuicServerInfo::State* state2 = quic_server_info2->mutable_state();
206 EXPECT_TRUE(state2->certs.empty()); 206 EXPECT_TRUE(state2->certs.empty());
207 const string server_config_b = "server_config_b"; 207 const string server_config_b = "server_config_b";
208 const string source_address_token_b = "source_address_token_b"; 208 const string source_address_token_b = "source_address_token_b";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 RemoveMockTransaction(&kHostInfoTransaction2); 251 RemoveMockTransaction(&kHostInfoTransaction2);
252 RemoveMockTransaction(&kHostInfoTransaction1); 252 RemoveMockTransaction(&kHostInfoTransaction1);
253 } 253 }
254 254
255 // Test IsReadyToPersist when there is a pending write. 255 // Test IsReadyToPersist when there is a pending write.
256 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { 256 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) {
257 MockHttpCache cache; 257 MockHttpCache cache;
258 AddMockTransaction(&kHostInfoTransaction1); 258 AddMockTransaction(&kHostInfoTransaction1);
259 TestCompletionCallback callback; 259 TestCompletionCallback callback;
260 260
261 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 261 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
262 scoped_ptr<QuicServerInfo> quic_server_info( 262 scoped_ptr<QuicServerInfo> quic_server_info(
263 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 263 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
264 EXPECT_FALSE(quic_server_info->IsDataReady()); 264 EXPECT_FALSE(quic_server_info->IsDataReady());
265 quic_server_info->Start(); 265 quic_server_info->Start();
266 int rv = quic_server_info->WaitForDataReady(callback.callback()); 266 int rv = quic_server_info->WaitForDataReady(callback.callback());
267 EXPECT_EQ(OK, callback.GetResult(rv)); 267 EXPECT_EQ(OK, callback.GetResult(rv));
268 EXPECT_TRUE(quic_server_info->IsDataReady()); 268 EXPECT_TRUE(quic_server_info->IsDataReady());
269 269
270 QuicServerInfo::State* state = quic_server_info->mutable_state(); 270 QuicServerInfo::State* state = quic_server_info->mutable_state();
271 EXPECT_TRUE(state->certs.empty()); 271 EXPECT_TRUE(state->certs.empty());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 RemoveMockTransaction(&kHostInfoTransaction1); 308 RemoveMockTransaction(&kHostInfoTransaction1);
309 } 309 }
310 310
311 // Test multiple calls to Persist. 311 // Test multiple calls to Persist.
312 TEST(DiskCacheBasedQuicServerInfo, MultiplePersist) { 312 TEST(DiskCacheBasedQuicServerInfo, MultiplePersist) {
313 MockHttpCache cache; 313 MockHttpCache cache;
314 AddMockTransaction(&kHostInfoTransaction1); 314 AddMockTransaction(&kHostInfoTransaction1);
315 TestCompletionCallback callback; 315 TestCompletionCallback callback;
316 316
317 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 317 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
318 scoped_ptr<QuicServerInfo> quic_server_info( 318 scoped_ptr<QuicServerInfo> quic_server_info(
319 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 319 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
320 EXPECT_FALSE(quic_server_info->IsDataReady()); 320 EXPECT_FALSE(quic_server_info->IsDataReady());
321 quic_server_info->Start(); 321 quic_server_info->Start();
322 int rv = quic_server_info->WaitForDataReady(callback.callback()); 322 int rv = quic_server_info->WaitForDataReady(callback.callback());
323 EXPECT_EQ(OK, callback.GetResult(rv)); 323 EXPECT_EQ(OK, callback.GetResult(rv));
324 EXPECT_TRUE(quic_server_info->IsDataReady()); 324 EXPECT_TRUE(quic_server_info->IsDataReady());
325 325
326 // Persist data once. 326 // Persist data once.
327 QuicServerInfo::State* state = quic_server_info->mutable_state(); 327 QuicServerInfo::State* state = quic_server_info->mutable_state();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 EXPECT_EQ(1U, state1.certs.size()); 385 EXPECT_EQ(1U, state1.certs.size());
386 EXPECT_EQ(cert_a, state1.certs[0]); 386 EXPECT_EQ(cert_a, state1.certs[0]);
387 387
388 RemoveMockTransaction(&kHostInfoTransaction1); 388 RemoveMockTransaction(&kHostInfoTransaction1);
389 } 389 }
390 390
391 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReady) { 391 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReady) {
392 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 392 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
393 MockHttpCache cache(factory); 393 MockHttpCache cache(factory);
394 TestCompletionCallback callback; 394 TestCompletionCallback callback;
395 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 395 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
396 scoped_ptr<QuicServerInfo> quic_server_info( 396 scoped_ptr<QuicServerInfo> quic_server_info(
397 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 397 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
398 EXPECT_FALSE(quic_server_info->IsDataReady()); 398 EXPECT_FALSE(quic_server_info->IsDataReady());
399 quic_server_info->Start(); 399 quic_server_info->Start();
400 int rv = quic_server_info->WaitForDataReady(callback.callback()); 400 int rv = quic_server_info->WaitForDataReady(callback.callback());
401 EXPECT_EQ(ERR_IO_PENDING, rv); 401 EXPECT_EQ(ERR_IO_PENDING, rv);
402 // Now cancel the callback. 402 // Now cancel the callback.
403 quic_server_info->CancelWaitForDataReadyCallback(); 403 quic_server_info->CancelWaitForDataReadyCallback();
404 EXPECT_FALSE(quic_server_info->IsDataReady()); 404 EXPECT_FALSE(quic_server_info->IsDataReady());
405 // Now complete the backend creation and let the callback run. 405 // Now complete the backend creation and let the callback run.
406 factory->FinishCreation(); 406 factory->FinishCreation();
407 EXPECT_TRUE(quic_server_info->IsDataReady()); 407 EXPECT_TRUE(quic_server_info->IsDataReady());
408 } 408 }
409 409
410 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyButDataIsReady) { 410 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyButDataIsReady) {
411 MockHttpCache cache; 411 MockHttpCache cache;
412 AddMockTransaction(&kHostInfoTransaction1); 412 AddMockTransaction(&kHostInfoTransaction1);
413 TestCompletionCallback callback; 413 TestCompletionCallback callback;
414 414
415 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 415 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
416 scoped_ptr<QuicServerInfo> quic_server_info( 416 scoped_ptr<QuicServerInfo> quic_server_info(
417 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 417 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
418 EXPECT_FALSE(quic_server_info->IsDataReady()); 418 EXPECT_FALSE(quic_server_info->IsDataReady());
419 quic_server_info->Start(); 419 quic_server_info->Start();
420 int rv = quic_server_info->WaitForDataReady(callback.callback()); 420 int rv = quic_server_info->WaitForDataReady(callback.callback());
421 quic_server_info->CancelWaitForDataReadyCallback(); 421 quic_server_info->CancelWaitForDataReadyCallback();
422 EXPECT_EQ(OK, callback.GetResult(rv)); 422 EXPECT_EQ(OK, callback.GetResult(rv));
423 EXPECT_TRUE(quic_server_info->IsDataReady()); 423 EXPECT_TRUE(quic_server_info->IsDataReady());
424 RemoveMockTransaction(&kHostInfoTransaction1); 424 RemoveMockTransaction(&kHostInfoTransaction1);
425 } 425 }
426 426
427 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyAfterDeleteCache) { 427 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyAfterDeleteCache) {
428 scoped_ptr<QuicServerInfo> quic_server_info; 428 scoped_ptr<QuicServerInfo> quic_server_info;
429 { 429 {
430 MockHttpCache cache; 430 MockHttpCache cache;
431 AddMockTransaction(&kHostInfoTransaction1); 431 AddMockTransaction(&kHostInfoTransaction1);
432 TestCompletionCallback callback; 432 TestCompletionCallback callback;
433 433
434 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 434 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
435 quic_server_info.reset( 435 quic_server_info.reset(
436 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 436 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
437 EXPECT_FALSE(quic_server_info->IsDataReady()); 437 EXPECT_FALSE(quic_server_info->IsDataReady());
438 quic_server_info->Start(); 438 quic_server_info->Start();
439 int rv = quic_server_info->WaitForDataReady(callback.callback()); 439 int rv = quic_server_info->WaitForDataReady(callback.callback());
440 quic_server_info->CancelWaitForDataReadyCallback(); 440 quic_server_info->CancelWaitForDataReadyCallback();
441 EXPECT_EQ(OK, callback.GetResult(rv)); 441 EXPECT_EQ(OK, callback.GetResult(rv));
442 EXPECT_TRUE(quic_server_info->IsDataReady()); 442 EXPECT_TRUE(quic_server_info->IsDataReady());
443 RemoveMockTransaction(&kHostInfoTransaction1); 443 RemoveMockTransaction(&kHostInfoTransaction1);
444 } 444 }
445 // Cancel the callback after Cache is deleted. 445 // Cancel the callback after Cache is deleted.
446 quic_server_info->ResetWaitForDataReadyCallback(); 446 quic_server_info->ResetWaitForDataReadyCallback();
447 } 447 }
448 448
449 // Test Start() followed by Persist() without calling WaitForDataReady. 449 // Test Start() followed by Persist() without calling WaitForDataReady.
450 TEST(DiskCacheBasedQuicServerInfo, StartAndPersist) { 450 TEST(DiskCacheBasedQuicServerInfo, StartAndPersist) {
451 MockHttpCache cache; 451 MockHttpCache cache;
452 AddMockTransaction(&kHostInfoTransaction1); 452 AddMockTransaction(&kHostInfoTransaction1);
453 453
454 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 454 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
455 scoped_ptr<QuicServerInfo> quic_server_info( 455 scoped_ptr<QuicServerInfo> quic_server_info(
456 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 456 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
457 EXPECT_FALSE(quic_server_info->IsDataReady()); 457 EXPECT_FALSE(quic_server_info->IsDataReady());
458 quic_server_info->Start(); 458 quic_server_info->Start();
459 // Wait until Start() does the work. 459 // Wait until Start() does the work.
460 base::MessageLoop::current()->RunUntilIdle(); 460 base::MessageLoop::current()->RunUntilIdle();
461 461
462 EXPECT_TRUE(quic_server_info->IsDataReady()); 462 EXPECT_TRUE(quic_server_info->IsDataReady());
463 463
464 QuicServerInfo::State* state = quic_server_info->mutable_state(); 464 QuicServerInfo::State* state = quic_server_info->mutable_state();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 505 }
506 506
507 // Test Persisting data when we are not ready to persist and then verify it 507 // Test Persisting data when we are not ready to persist and then verify it
508 // persists the data when Start() finishes. 508 // persists the data when Start() finishes.
509 TEST(DiskCacheBasedQuicServerInfo, PersistWhenNotReadyToPersist) { 509 TEST(DiskCacheBasedQuicServerInfo, PersistWhenNotReadyToPersist) {
510 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 510 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
511 MockHttpCache cache(factory); 511 MockHttpCache cache(factory);
512 AddMockTransaction(&kHostInfoTransaction1); 512 AddMockTransaction(&kHostInfoTransaction1);
513 TestCompletionCallback callback; 513 TestCompletionCallback callback;
514 514
515 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 515 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
516 scoped_ptr<QuicServerInfo> quic_server_info( 516 scoped_ptr<QuicServerInfo> quic_server_info(
517 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 517 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
518 EXPECT_FALSE(quic_server_info->IsDataReady()); 518 EXPECT_FALSE(quic_server_info->IsDataReady());
519 // We do a Start(), but don't call WaitForDataReady(). Because we haven't 519 // We do a Start(), but don't call WaitForDataReady(). Because we haven't
520 // created the backend, we will wait and data wouldn't be ready. 520 // created the backend, we will wait and data wouldn't be ready.
521 quic_server_info->Start(); 521 quic_server_info->Start();
522 EXPECT_FALSE(quic_server_info->IsDataReady()); 522 EXPECT_FALSE(quic_server_info->IsDataReady());
523 523
524 // Persist data once, even though the backend is not ready. 524 // Persist data once, even though the backend is not ready.
525 QuicServerInfo::State* state = quic_server_info->mutable_state(); 525 QuicServerInfo::State* state = quic_server_info->mutable_state();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 EXPECT_EQ(cert_init, state1.certs[0]); 560 EXPECT_EQ(cert_init, state1.certs[0]);
561 RemoveMockTransaction(&kHostInfoTransaction1); 561 RemoveMockTransaction(&kHostInfoTransaction1);
562 } 562 }
563 563
564 // Test multiple calls to Persist without waiting for the data to be written. 564 // Test multiple calls to Persist without waiting for the data to be written.
565 TEST(DiskCacheBasedQuicServerInfo, MultiplePersistsWithoutWaiting) { 565 TEST(DiskCacheBasedQuicServerInfo, MultiplePersistsWithoutWaiting) {
566 MockHttpCache cache; 566 MockHttpCache cache;
567 AddMockTransaction(&kHostInfoTransaction1); 567 AddMockTransaction(&kHostInfoTransaction1);
568 TestCompletionCallback callback; 568 TestCompletionCallback callback;
569 569
570 QuicServerId server_id("www.google.com", 443, true, PRIVACY_MODE_DISABLED); 570 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
571 scoped_ptr<QuicServerInfo> quic_server_info( 571 scoped_ptr<QuicServerInfo> quic_server_info(
572 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 572 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
573 EXPECT_FALSE(quic_server_info->IsDataReady()); 573 EXPECT_FALSE(quic_server_info->IsDataReady());
574 quic_server_info->Start(); 574 quic_server_info->Start();
575 int rv = quic_server_info->WaitForDataReady(callback.callback()); 575 int rv = quic_server_info->WaitForDataReady(callback.callback());
576 EXPECT_EQ(OK, callback.GetResult(rv)); 576 EXPECT_EQ(OK, callback.GetResult(rv));
577 EXPECT_TRUE(quic_server_info->IsDataReady()); 577 EXPECT_TRUE(quic_server_info->IsDataReady());
578 578
579 // Persist data once. 579 // Persist data once.
580 QuicServerInfo::State* state = quic_server_info->mutable_state(); 580 QuicServerInfo::State* state = quic_server_info->mutable_state();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 RemoveMockTransaction(&kHostInfoTransaction1); 633 RemoveMockTransaction(&kHostInfoTransaction1);
634 } 634 }
635 635
636 // crbug.com/439209: test deletion of QuicServerInfo object in the callback 636 // crbug.com/439209: test deletion of QuicServerInfo object in the callback
637 // doesn't crash. 637 // doesn't crash.
638 TEST(DiskCacheBasedQuicServerInfo, DeleteServerInfoInCallback) { 638 TEST(DiskCacheBasedQuicServerInfo, DeleteServerInfoInCallback) {
639 // Use the blocking mock backend factory to force asynchronous completion 639 // Use the blocking mock backend factory to force asynchronous completion
640 // of quic_server_info->WaitForDataReady(), so that the callback will run. 640 // of quic_server_info->WaitForDataReady(), so that the callback will run.
641 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 641 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
642 MockHttpCache cache(factory); 642 MockHttpCache cache(factory);
643 QuicServerId server_id("www.verisign.com", 443, true, PRIVACY_MODE_DISABLED); 643 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED);
644 QuicServerInfo* quic_server_info = 644 QuicServerInfo* quic_server_info =
645 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()); 645 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache());
646 // |cb| takes owndership and deletes |quic_server_info| when it is called. 646 // |cb| takes owndership and deletes |quic_server_info| when it is called.
647 DeleteCacheCompletionCallback cb(quic_server_info); 647 DeleteCacheCompletionCallback cb(quic_server_info);
648 quic_server_info->Start(); 648 quic_server_info->Start();
649 int rv = quic_server_info->WaitForDataReady(cb.callback()); 649 int rv = quic_server_info->WaitForDataReady(cb.callback());
650 EXPECT_EQ(ERR_IO_PENDING, rv); 650 EXPECT_EQ(ERR_IO_PENDING, rv);
651 // Now complete the backend creation and let the callback run. 651 // Now complete the backend creation and let the callback run.
652 factory->FinishCreation(); 652 factory->FinishCreation();
653 EXPECT_EQ(OK, cb.GetResult(rv)); 653 EXPECT_EQ(OK, cb.GetResult(rv));
654 } 654 }
655 655
656 } // namespace net 656 } // namespace net
OLDNEW
« no previous file with comments | « components/cronet/android/test/quic_test_server.cc ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698