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

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

Issue 2668563002: Change MockHttpCache constructor to take boolean to set quic server info factory (Closed)
Patch Set: add one more constructor to MockHttpCache Created 3 years, 10 months 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
« no previous file with comments | « no previous file | net/http/mock_http_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/macros.h" 10 #include "base/macros.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 }; 87 };
88 88
89 } // namespace 89 } // namespace
90 90
91 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a 91 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a
92 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. 92 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady.
93 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { 93 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) {
94 // Use the blocking mock backend factory to force asynchronous completion 94 // Use the blocking mock backend factory to force asynchronous completion
95 // of quic_server_info->WaitForDataReady(), so that the callback will run. 95 // of quic_server_info->WaitForDataReady(), so that the callback will run.
96 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 96 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
97 MockHttpCache cache(base::WrapUnique(factory)); 97 MockHttpCache cache(base::WrapUnique(factory), true);
98 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED); 98 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED);
99 std::unique_ptr<QuicServerInfo> quic_server_info( 99 std::unique_ptr<QuicServerInfo> quic_server_info(
100 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 100 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
101 quic_server_info->Start(); 101 quic_server_info->Start();
102 TestCompletionCallback callback; 102 TestCompletionCallback callback;
103 int rv = quic_server_info->WaitForDataReady(callback.callback()); 103 int rv = quic_server_info->WaitForDataReady(callback.callback());
104 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 104 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
105 // Now complete the backend creation and let the callback run. 105 // Now complete the backend creation and let the callback run.
106 factory->FinishCreation(); 106 factory->FinishCreation();
107 EXPECT_THAT(callback.GetResult(rv), IsOk()); 107 EXPECT_THAT(callback.GetResult(rv), IsOk());
108 } 108 }
109 109
110 // Tests the basic logic of storing, retrieving and updating data. 110 // Tests the basic logic of storing, retrieving and updating data.
111 TEST(DiskCacheBasedQuicServerInfo, Update) { 111 TEST(DiskCacheBasedQuicServerInfo, Update) {
112 MockHttpCache cache; 112 MockHttpCache cache(true);
113 AddMockTransaction(&kHostInfoTransaction1); 113 AddMockTransaction(&kHostInfoTransaction1);
114 TestCompletionCallback callback; 114 TestCompletionCallback callback;
115 115
116 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 116 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
117 std::unique_ptr<QuicServerInfo> quic_server_info( 117 std::unique_ptr<QuicServerInfo> quic_server_info(
118 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 118 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
119 quic_server_info->Start(); 119 quic_server_info->Start();
120 int rv = quic_server_info->WaitForDataReady(callback.callback()); 120 int rv = quic_server_info->WaitForDataReady(callback.callback());
121 EXPECT_THAT(callback.GetResult(rv), IsOk()); 121 EXPECT_THAT(callback.GetResult(rv), IsOk());
122 122
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); 173 EXPECT_EQ(server_config_sig_a, state1.server_config_sig);
174 EXPECT_EQ(2U, state1.certs.size()); 174 EXPECT_EQ(2U, state1.certs.size());
175 EXPECT_EQ(cert_a, state1.certs[0]); 175 EXPECT_EQ(cert_a, state1.certs[0]);
176 EXPECT_EQ(cert_b, state1.certs[1]); 176 EXPECT_EQ(cert_b, state1.certs[1]);
177 177
178 RemoveMockTransaction(&kHostInfoTransaction1); 178 RemoveMockTransaction(&kHostInfoTransaction1);
179 } 179 }
180 180
181 // Test that demonstrates different info is returned when the ports differ. 181 // Test that demonstrates different info is returned when the ports differ.
182 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) { 182 TEST(DiskCacheBasedQuicServerInfo, UpdateDifferentPorts) {
183 MockHttpCache cache; 183 MockHttpCache cache(true);
184 AddMockTransaction(&kHostInfoTransaction1); 184 AddMockTransaction(&kHostInfoTransaction1);
185 AddMockTransaction(&kHostInfoTransaction2); 185 AddMockTransaction(&kHostInfoTransaction2);
186 TestCompletionCallback callback; 186 TestCompletionCallback callback;
187 187
188 // Persist data for port 443. 188 // Persist data for port 443.
189 QuicServerId server_id1("www.google.com", 443, PRIVACY_MODE_DISABLED); 189 QuicServerId server_id1("www.google.com", 443, PRIVACY_MODE_DISABLED);
190 std::unique_ptr<QuicServerInfo> quic_server_info1( 190 std::unique_ptr<QuicServerInfo> quic_server_info1(
191 new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache())); 191 new DiskCacheBasedQuicServerInfo(server_id1, cache.http_cache()));
192 quic_server_info1->Start(); 192 quic_server_info1->Start();
193 int rv = quic_server_info1->WaitForDataReady(callback.callback()); 193 int rv = quic_server_info1->WaitForDataReady(callback.callback());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_EQ(server_config_sig_b, state_b.server_config_sig); 274 EXPECT_EQ(server_config_sig_b, state_b.server_config_sig);
275 EXPECT_EQ(1U, state_b.certs.size()); 275 EXPECT_EQ(1U, state_b.certs.size());
276 EXPECT_EQ(cert_b, state_b.certs[0]); 276 EXPECT_EQ(cert_b, state_b.certs[0]);
277 277
278 RemoveMockTransaction(&kHostInfoTransaction2); 278 RemoveMockTransaction(&kHostInfoTransaction2);
279 RemoveMockTransaction(&kHostInfoTransaction1); 279 RemoveMockTransaction(&kHostInfoTransaction1);
280 } 280 }
281 281
282 // Test IsReadyToPersist when there is a pending write. 282 // Test IsReadyToPersist when there is a pending write.
283 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) { 283 TEST(DiskCacheBasedQuicServerInfo, IsReadyToPersist) {
284 MockHttpCache cache; 284 MockHttpCache cache(true);
285 AddMockTransaction(&kHostInfoTransaction1); 285 AddMockTransaction(&kHostInfoTransaction1);
286 TestCompletionCallback callback; 286 TestCompletionCallback callback;
287 287
288 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 288 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
289 std::unique_ptr<QuicServerInfo> quic_server_info( 289 std::unique_ptr<QuicServerInfo> quic_server_info(
290 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 290 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
291 EXPECT_FALSE(quic_server_info->IsDataReady()); 291 EXPECT_FALSE(quic_server_info->IsDataReady());
292 quic_server_info->Start(); 292 quic_server_info->Start();
293 int rv = quic_server_info->WaitForDataReady(callback.callback()); 293 int rv = quic_server_info->WaitForDataReady(callback.callback());
294 EXPECT_THAT(callback.GetResult(rv), IsOk()); 294 EXPECT_THAT(callback.GetResult(rv), IsOk());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 EXPECT_EQ(chlo_hash_a, state1.chlo_hash); 336 EXPECT_EQ(chlo_hash_a, state1.chlo_hash);
337 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); 337 EXPECT_EQ(server_config_sig_a, state1.server_config_sig);
338 EXPECT_EQ(1U, state1.certs.size()); 338 EXPECT_EQ(1U, state1.certs.size());
339 EXPECT_EQ(cert_a, state1.certs[0]); 339 EXPECT_EQ(cert_a, state1.certs[0]);
340 340
341 RemoveMockTransaction(&kHostInfoTransaction1); 341 RemoveMockTransaction(&kHostInfoTransaction1);
342 } 342 }
343 343
344 // Test multiple calls to Persist. 344 // Test multiple calls to Persist.
345 TEST(DiskCacheBasedQuicServerInfo, MultiplePersist) { 345 TEST(DiskCacheBasedQuicServerInfo, MultiplePersist) {
346 MockHttpCache cache; 346 MockHttpCache cache(true);
347 AddMockTransaction(&kHostInfoTransaction1); 347 AddMockTransaction(&kHostInfoTransaction1);
348 TestCompletionCallback callback; 348 TestCompletionCallback callback;
349 349
350 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 350 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
351 std::unique_ptr<QuicServerInfo> quic_server_info( 351 std::unique_ptr<QuicServerInfo> quic_server_info(
352 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 352 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
353 EXPECT_FALSE(quic_server_info->IsDataReady()); 353 EXPECT_FALSE(quic_server_info->IsDataReady());
354 quic_server_info->Start(); 354 quic_server_info->Start();
355 int rv = quic_server_info->WaitForDataReady(callback.callback()); 355 int rv = quic_server_info->WaitForDataReady(callback.callback());
356 EXPECT_THAT(callback.GetResult(rv), IsOk()); 356 EXPECT_THAT(callback.GetResult(rv), IsOk());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 EXPECT_EQ(chlo_hash_a, state1.chlo_hash); 426 EXPECT_EQ(chlo_hash_a, state1.chlo_hash);
427 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); 427 EXPECT_EQ(server_config_sig_a, state1.server_config_sig);
428 EXPECT_EQ(1U, state1.certs.size()); 428 EXPECT_EQ(1U, state1.certs.size());
429 EXPECT_EQ(cert_a, state1.certs[0]); 429 EXPECT_EQ(cert_a, state1.certs[0]);
430 430
431 RemoveMockTransaction(&kHostInfoTransaction1); 431 RemoveMockTransaction(&kHostInfoTransaction1);
432 } 432 }
433 433
434 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReady) { 434 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReady) {
435 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 435 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
436 MockHttpCache cache(base::WrapUnique(factory)); 436 MockHttpCache cache(base::WrapUnique(factory), true);
437 TestCompletionCallback callback; 437 TestCompletionCallback callback;
438 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 438 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
439 std::unique_ptr<QuicServerInfo> quic_server_info( 439 std::unique_ptr<QuicServerInfo> quic_server_info(
440 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 440 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
441 EXPECT_FALSE(quic_server_info->IsDataReady()); 441 EXPECT_FALSE(quic_server_info->IsDataReady());
442 quic_server_info->Start(); 442 quic_server_info->Start();
443 int rv = quic_server_info->WaitForDataReady(callback.callback()); 443 int rv = quic_server_info->WaitForDataReady(callback.callback());
444 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 444 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
445 // Now cancel the callback. 445 // Now cancel the callback.
446 quic_server_info->CancelWaitForDataReadyCallback(); 446 quic_server_info->CancelWaitForDataReadyCallback();
447 EXPECT_FALSE(quic_server_info->IsDataReady()); 447 EXPECT_FALSE(quic_server_info->IsDataReady());
448 // Now complete the backend creation and let the callback run. 448 // Now complete the backend creation and let the callback run.
449 factory->FinishCreation(); 449 factory->FinishCreation();
450 EXPECT_TRUE(quic_server_info->IsDataReady()); 450 EXPECT_TRUE(quic_server_info->IsDataReady());
451 } 451 }
452 452
453 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyButDataIsReady) { 453 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyButDataIsReady) {
454 MockHttpCache cache; 454 MockHttpCache cache(true);
455 AddMockTransaction(&kHostInfoTransaction1); 455 AddMockTransaction(&kHostInfoTransaction1);
456 TestCompletionCallback callback; 456 TestCompletionCallback callback;
457 457
458 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 458 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
459 std::unique_ptr<QuicServerInfo> quic_server_info( 459 std::unique_ptr<QuicServerInfo> quic_server_info(
460 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 460 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
461 EXPECT_FALSE(quic_server_info->IsDataReady()); 461 EXPECT_FALSE(quic_server_info->IsDataReady());
462 quic_server_info->Start(); 462 quic_server_info->Start();
463 int rv = quic_server_info->WaitForDataReady(callback.callback()); 463 int rv = quic_server_info->WaitForDataReady(callback.callback());
464 quic_server_info->CancelWaitForDataReadyCallback(); 464 quic_server_info->CancelWaitForDataReadyCallback();
465 EXPECT_THAT(callback.GetResult(rv), IsOk()); 465 EXPECT_THAT(callback.GetResult(rv), IsOk());
466 EXPECT_TRUE(quic_server_info->IsDataReady()); 466 EXPECT_TRUE(quic_server_info->IsDataReady());
467 RemoveMockTransaction(&kHostInfoTransaction1); 467 RemoveMockTransaction(&kHostInfoTransaction1);
468 } 468 }
469 469
470 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyAfterDeleteCache) { 470 TEST(DiskCacheBasedQuicServerInfo, CancelWaitForDataReadyAfterDeleteCache) {
471 std::unique_ptr<QuicServerInfo> quic_server_info; 471 std::unique_ptr<QuicServerInfo> quic_server_info;
472 { 472 {
473 MockHttpCache cache; 473 MockHttpCache cache(true);
474 AddMockTransaction(&kHostInfoTransaction1); 474 AddMockTransaction(&kHostInfoTransaction1);
475 TestCompletionCallback callback; 475 TestCompletionCallback callback;
476 476
477 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 477 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
478 quic_server_info.reset( 478 quic_server_info.reset(
479 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 479 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
480 EXPECT_FALSE(quic_server_info->IsDataReady()); 480 EXPECT_FALSE(quic_server_info->IsDataReady());
481 quic_server_info->Start(); 481 quic_server_info->Start();
482 int rv = quic_server_info->WaitForDataReady(callback.callback()); 482 int rv = quic_server_info->WaitForDataReady(callback.callback());
483 quic_server_info->CancelWaitForDataReadyCallback(); 483 quic_server_info->CancelWaitForDataReadyCallback();
484 EXPECT_THAT(callback.GetResult(rv), IsOk()); 484 EXPECT_THAT(callback.GetResult(rv), IsOk());
485 EXPECT_TRUE(quic_server_info->IsDataReady()); 485 EXPECT_TRUE(quic_server_info->IsDataReady());
486 RemoveMockTransaction(&kHostInfoTransaction1); 486 RemoveMockTransaction(&kHostInfoTransaction1);
487 } 487 }
488 // Cancel the callback after Cache is deleted. 488 // Cancel the callback after Cache is deleted.
489 quic_server_info->ResetWaitForDataReadyCallback(); 489 quic_server_info->ResetWaitForDataReadyCallback();
490 } 490 }
491 491
492 // Test Start() followed by Persist() without calling WaitForDataReady. 492 // Test Start() followed by Persist() without calling WaitForDataReady.
493 TEST(DiskCacheBasedQuicServerInfo, StartAndPersist) { 493 TEST(DiskCacheBasedQuicServerInfo, StartAndPersist) {
494 MockHttpCache cache; 494 MockHttpCache cache(true);
495 AddMockTransaction(&kHostInfoTransaction1); 495 AddMockTransaction(&kHostInfoTransaction1);
496 496
497 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 497 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
498 std::unique_ptr<QuicServerInfo> quic_server_info( 498 std::unique_ptr<QuicServerInfo> quic_server_info(
499 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 499 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
500 EXPECT_FALSE(quic_server_info->IsDataReady()); 500 EXPECT_FALSE(quic_server_info->IsDataReady());
501 quic_server_info->Start(); 501 quic_server_info->Start();
502 // Wait until Start() does the work. 502 // Wait until Start() does the work.
503 base::RunLoop().RunUntilIdle(); 503 base::RunLoop().RunUntilIdle();
504 504
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 EXPECT_EQ(1U, state1.certs.size()); 550 EXPECT_EQ(1U, state1.certs.size());
551 EXPECT_EQ(cert_a, state1.certs[0]); 551 EXPECT_EQ(cert_a, state1.certs[0]);
552 552
553 RemoveMockTransaction(&kHostInfoTransaction1); 553 RemoveMockTransaction(&kHostInfoTransaction1);
554 } 554 }
555 555
556 // Test Persisting data when we are not ready to persist and then verify it 556 // Test Persisting data when we are not ready to persist and then verify it
557 // persists the data when Start() finishes. 557 // persists the data when Start() finishes.
558 TEST(DiskCacheBasedQuicServerInfo, PersistWhenNotReadyToPersist) { 558 TEST(DiskCacheBasedQuicServerInfo, PersistWhenNotReadyToPersist) {
559 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 559 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
560 MockHttpCache cache(base::WrapUnique(factory)); 560 MockHttpCache cache(base::WrapUnique(factory), true);
561 AddMockTransaction(&kHostInfoTransaction1); 561 AddMockTransaction(&kHostInfoTransaction1);
562 TestCompletionCallback callback; 562 TestCompletionCallback callback;
563 563
564 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 564 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
565 std::unique_ptr<QuicServerInfo> quic_server_info( 565 std::unique_ptr<QuicServerInfo> quic_server_info(
566 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 566 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
567 EXPECT_FALSE(quic_server_info->IsDataReady()); 567 EXPECT_FALSE(quic_server_info->IsDataReady());
568 // We do a Start(), but don't call WaitForDataReady(). Because we haven't 568 // We do a Start(), but don't call WaitForDataReady(). Because we haven't
569 // created the backend, we will wait and data wouldn't be ready. 569 // created the backend, we will wait and data wouldn't be ready.
570 quic_server_info->Start(); 570 quic_server_info->Start();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 EXPECT_EQ(cert_sct_init, state1.cert_sct); 611 EXPECT_EQ(cert_sct_init, state1.cert_sct);
612 EXPECT_EQ(chlo_hash_init, state1.chlo_hash); 612 EXPECT_EQ(chlo_hash_init, state1.chlo_hash);
613 EXPECT_EQ(server_config_sig_init, state1.server_config_sig); 613 EXPECT_EQ(server_config_sig_init, state1.server_config_sig);
614 EXPECT_EQ(1U, state1.certs.size()); 614 EXPECT_EQ(1U, state1.certs.size());
615 EXPECT_EQ(cert_init, state1.certs[0]); 615 EXPECT_EQ(cert_init, state1.certs[0]);
616 RemoveMockTransaction(&kHostInfoTransaction1); 616 RemoveMockTransaction(&kHostInfoTransaction1);
617 } 617 }
618 618
619 // Test multiple calls to Persist without waiting for the data to be written. 619 // Test multiple calls to Persist without waiting for the data to be written.
620 TEST(DiskCacheBasedQuicServerInfo, MultiplePersistsWithoutWaiting) { 620 TEST(DiskCacheBasedQuicServerInfo, MultiplePersistsWithoutWaiting) {
621 MockHttpCache cache; 621 MockHttpCache cache(true);
622 AddMockTransaction(&kHostInfoTransaction1); 622 AddMockTransaction(&kHostInfoTransaction1);
623 TestCompletionCallback callback; 623 TestCompletionCallback callback;
624 624
625 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); 625 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED);
626 std::unique_ptr<QuicServerInfo> quic_server_info( 626 std::unique_ptr<QuicServerInfo> quic_server_info(
627 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache())); 627 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()));
628 EXPECT_FALSE(quic_server_info->IsDataReady()); 628 EXPECT_FALSE(quic_server_info->IsDataReady());
629 quic_server_info->Start(); 629 quic_server_info->Start();
630 int rv = quic_server_info->WaitForDataReady(callback.callback()); 630 int rv = quic_server_info->WaitForDataReady(callback.callback());
631 EXPECT_THAT(callback.GetResult(rv), IsOk()); 631 EXPECT_THAT(callback.GetResult(rv), IsOk());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 697
698 RemoveMockTransaction(&kHostInfoTransaction1); 698 RemoveMockTransaction(&kHostInfoTransaction1);
699 } 699 }
700 700
701 // crbug.com/439209: test deletion of QuicServerInfo object in the callback 701 // crbug.com/439209: test deletion of QuicServerInfo object in the callback
702 // doesn't crash. 702 // doesn't crash.
703 TEST(DiskCacheBasedQuicServerInfo, DeleteServerInfoInCallback) { 703 TEST(DiskCacheBasedQuicServerInfo, DeleteServerInfoInCallback) {
704 // Use the blocking mock backend factory to force asynchronous completion 704 // Use the blocking mock backend factory to force asynchronous completion
705 // of quic_server_info->WaitForDataReady(), so that the callback will run. 705 // of quic_server_info->WaitForDataReady(), so that the callback will run.
706 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 706 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
707 MockHttpCache cache(base::WrapUnique(factory)); 707 MockHttpCache cache(base::WrapUnique(factory), true);
708 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED); 708 QuicServerId server_id("www.verisign.com", 443, PRIVACY_MODE_DISABLED);
709 QuicServerInfo* quic_server_info = 709 QuicServerInfo* quic_server_info =
710 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()); 710 new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache());
711 // |cb| takes owndership and deletes |quic_server_info| when it is called. 711 // |cb| takes owndership and deletes |quic_server_info| when it is called.
712 DeleteCacheCompletionCallback cb(quic_server_info); 712 DeleteCacheCompletionCallback cb(quic_server_info);
713 quic_server_info->Start(); 713 quic_server_info->Start();
714 int rv = quic_server_info->WaitForDataReady(cb.callback()); 714 int rv = quic_server_info->WaitForDataReady(cb.callback());
715 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 715 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
716 // Now complete the backend creation and let the callback run. 716 // Now complete the backend creation and let the callback run.
717 factory->FinishCreation(); 717 factory->FinishCreation();
718 EXPECT_THAT(cb.GetResult(rv), IsOk()); 718 EXPECT_THAT(cb.GetResult(rv), IsOk());
719 } 719 }
720 720
721 } // namespace net 721 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/mock_http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698