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

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager_unittest.cc

Issue 2487343005: Fix Thread::SetMessageLoop(nullptr). (Closed)
Patch Set: Merge up to r434093 Created 4 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
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/protocol_manager.h" 5 #include "chrome/browser/safe_browsing/protocol_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/safe_browsing/chunk.pb.h" 15 #include "chrome/browser/safe_browsing/chunk.pb.h"
16 #include "components/safe_browsing_db/safe_browsing_prefs.h" 16 #include "components/safe_browsing_db/safe_browsing_prefs.h"
17 #include "components/safe_browsing_db/safebrowsing.pb.h" 17 #include "components/safe_browsing_db/safebrowsing.pb.h"
18 #include "components/safe_browsing_db/util.h" 18 #include "components/safe_browsing_db/util.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "google_apis/google_api_keys.h" 20 #include "google_apis/google_api_keys.h"
21 #include "net/base/escape.h" 21 #include "net/base/escape.h"
22 #include "net/base/load_flags.h" 22 #include "net/base/load_flags.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/url_request/test_url_fetcher_factory.h" 24 #include "net/url_request/test_url_fetcher_factory.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gmock_mutant.h" 26 #include "testing/gmock_mutant.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 using base::Time; 29 using base::Time;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 }; 67 };
68 const std::string kChunkPayload2(kRawChunkPayload2, sizeof(kRawChunkPayload2)); 68 const std::string kChunkPayload2(kRawChunkPayload2, sizeof(kRawChunkPayload2));
69 69
70 } // namespace 70 } // namespace
71 71
72 namespace safe_browsing { 72 namespace safe_browsing {
73 73
74 class SafeBrowsingProtocolManagerTest : public testing::Test { 74 class SafeBrowsingProtocolManagerTest : public testing::Test {
75 protected: 75 protected:
76 SafeBrowsingProtocolManagerTest() 76 SafeBrowsingProtocolManagerTest()
77 : runner_(new base::TestSimpleTaskRunner), 77 : thread_bundle_(content::TestBrowserThreadBundle::Options::IO_MAINLOOP) {
78 runner_handler_(runner_), 78 }
79 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()) {}
80 79
81 ~SafeBrowsingProtocolManagerTest() override {} 80 ~SafeBrowsingProtocolManagerTest() override {}
82 81
83 void SetUp() override { 82 void SetUp() override {
84 std::string key = google_apis::GetAPIKey(); 83 std::string key = google_apis::GetAPIKey();
85 if (!key.empty()) { 84 if (!key.empty()) {
86 key_param_ = base::StringPrintf( 85 key_param_ = base::StringPrintf(
87 "&key=%s", 86 "&key=%s",
88 net::EscapeQueryParamValue(key, true).c_str()); 87 net::EscapeQueryParamValue(key, true).c_str());
89 } 88 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 122 }
124 123
125 void ValidateRedirectFetcherRequest(const net::TestURLFetcher* url_fetcher, 124 void ValidateRedirectFetcherRequest(const net::TestURLFetcher* url_fetcher,
126 const std::string& expected_url) { 125 const std::string& expected_url) {
127 ASSERT_TRUE(url_fetcher); 126 ASSERT_TRUE(url_fetcher);
128 EXPECT_EQ(net::LOAD_DISABLE_CACHE, url_fetcher->GetLoadFlags()); 127 EXPECT_EQ(net::LOAD_DISABLE_CACHE, url_fetcher->GetLoadFlags());
129 EXPECT_EQ("", url_fetcher->upload_data()); 128 EXPECT_EQ("", url_fetcher->upload_data());
130 EXPECT_EQ(GURL(expected_url), url_fetcher->GetOriginalURL()); 129 EXPECT_EQ(GURL(expected_url), url_fetcher->GetOriginalURL());
131 } 130 }
132 131
133 scoped_refptr<base::TestSimpleTaskRunner> runner_; 132 // Fakes BrowserThreads and the main MessageLoop.
134 base::ThreadTaskRunnerHandle runner_handler_; 133 content::TestBrowserThreadBundle thread_bundle_;
135 content::TestBrowserThread io_thread_; 134
135 // Replaces the main MessageLoop's TaskRunner with a TaskRunner on which time
136 // is mocked to allow testing of things bound to timers below.
137 base::ScopedMockTimeMessageLoopTaskRunner mock_time_task_runner_;
138
136 std::string key_param_; 139 std::string key_param_;
137 }; 140 };
138 141
139 // Ensure that we respect section 5 of the SafeBrowsing protocol specification. 142 // Ensure that we respect section 5 of the SafeBrowsing protocol specification.
140 TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { 143 TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) {
141 std::unique_ptr<SafeBrowsingProtocolManager> pm( 144 std::unique_ptr<SafeBrowsingProtocolManager> pm(
142 CreateProtocolManager(nullptr)); 145 CreateProtocolManager(nullptr));
143 146
144 pm->next_update_interval_ = TimeDelta::FromSeconds(1800); 147 pm->next_update_interval_ = TimeDelta::FromSeconds(1800);
145 ASSERT_TRUE(pm->back_off_fuzz_ >= 0.0 && pm->back_off_fuzz_ <= 1.0); 148 ASSERT_TRUE(pm->back_off_fuzz_ >= 0.0 && pm->back_off_fuzz_ <= 1.0);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce( 420 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce(
418 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 421 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
419 std::vector<SBListChunkRanges>(), 422 std::vector<SBListChunkRanges>(),
420 true))); 423 true)));
421 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 424 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
422 425
423 std::unique_ptr<SafeBrowsingProtocolManager> pm( 426 std::unique_ptr<SafeBrowsingProtocolManager> pm(
424 CreateProtocolManager(&test_delegate)); 427 CreateProtocolManager(&test_delegate));
425 428
426 pm->ForceScheduleNextUpdate(TimeDelta()); 429 pm->ForceScheduleNextUpdate(TimeDelta());
427 runner_->RunPendingTasks(); 430 mock_time_task_runner_->RunUntilIdle();
428 431
429 EXPECT_TRUE(pm->IsUpdateScheduled()); 432 EXPECT_TRUE(pm->IsUpdateScheduled());
430 } 433 }
431 434
432 // Tests the contents of the POST body when there are contents in the 435 // Tests the contents of the POST body when there are contents in the
433 // local database. This is not exhaustive, as the actual list formatting 436 // local database. This is not exhaustive, as the actual list formatting
434 // is covered by SafeBrowsingProtocolManagerTest.TestChunkStrings. 437 // is covered by SafeBrowsingProtocolManagerTest.TestChunkStrings.
435 TEST_F(SafeBrowsingProtocolManagerTest, ExistingDatabase) { 438 TEST_F(SafeBrowsingProtocolManagerTest, ExistingDatabase) {
436 net::TestURLFetcherFactory url_fetcher_factory; 439 net::TestURLFetcherFactory url_fetcher_factory;
437 440
(...skipping 14 matching lines...) Expand all
452 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 455 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
453 ranges, 456 ranges,
454 false))); 457 false)));
455 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 458 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
456 459
457 std::unique_ptr<SafeBrowsingProtocolManager> pm( 460 std::unique_ptr<SafeBrowsingProtocolManager> pm(
458 CreateProtocolManager(&test_delegate)); 461 CreateProtocolManager(&test_delegate));
459 462
460 // Kick off initialization. This returns chunks from the DB synchronously. 463 // Kick off initialization. This returns chunks from the DB synchronously.
461 pm->ForceScheduleNextUpdate(TimeDelta()); 464 pm->ForceScheduleNextUpdate(TimeDelta());
462 runner_->RunPendingTasks(); 465 mock_time_task_runner_->RunUntilIdle();
463 466
464 // We should have an URLFetcher at this point in time. 467 // We should have an URLFetcher at this point in time.
465 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 468 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
466 ASSERT_TRUE(url_fetcher); 469 ASSERT_TRUE(url_fetcher);
467 EXPECT_EQ(net::LOAD_DISABLE_CACHE, url_fetcher->GetLoadFlags()); 470 EXPECT_EQ(net::LOAD_DISABLE_CACHE, url_fetcher->GetLoadFlags());
468 EXPECT_EQ(base::StringPrintf("%s;a:adds_phish:s:subs_phish\n" 471 EXPECT_EQ(base::StringPrintf("%s;a:adds_phish:s:subs_phish\n"
469 "unknown_list;a:adds_unknown:s:subs_unknown\n" 472 "unknown_list;a:adds_unknown:s:subs_unknown\n"
470 "%s;\n", 473 "%s;\n",
471 kDefaultPhishList, kDefaultMalwareList), 474 kDefaultPhishList, kDefaultMalwareList),
472 url_fetcher->upload_data()); 475 url_fetcher->upload_data());
(...skipping 19 matching lines...) Expand all
492 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 495 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
493 std::vector<SBListChunkRanges>(), 496 std::vector<SBListChunkRanges>(),
494 false))); 497 false)));
495 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 498 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
496 499
497 std::unique_ptr<SafeBrowsingProtocolManager> pm( 500 std::unique_ptr<SafeBrowsingProtocolManager> pm(
498 CreateProtocolManager(&test_delegate)); 501 CreateProtocolManager(&test_delegate));
499 502
500 // Kick off initialization. This returns chunks from the DB synchronously. 503 // Kick off initialization. This returns chunks from the DB synchronously.
501 pm->ForceScheduleNextUpdate(TimeDelta()); 504 pm->ForceScheduleNextUpdate(TimeDelta());
502 runner_->RunPendingTasks(); 505 mock_time_task_runner_->RunUntilIdle();
503 506
504 // We should have an URLFetcher at this point in time. 507 // We should have an URLFetcher at this point in time.
505 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 508 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
506 ValidateUpdateFetcherRequest(url_fetcher); 509 ValidateUpdateFetcherRequest(url_fetcher);
507 510
508 // The update response is successful, but an invalid body. 511 // The update response is successful, but an invalid body.
509 url_fetcher->set_status(net::URLRequestStatus()); 512 url_fetcher->set_status(net::URLRequestStatus());
510 url_fetcher->set_response_code(200); 513 url_fetcher->set_response_code(200);
511 url_fetcher->SetResponseString("THIS_IS_A_BAD_RESPONSE"); 514 url_fetcher->SetResponseString("THIS_IS_A_BAD_RESPONSE");
512 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 515 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
(...skipping 23 matching lines...) Expand all
536 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 539 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
537 std::vector<SBListChunkRanges>(), 540 std::vector<SBListChunkRanges>(),
538 false))); 541 false)));
539 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 542 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
540 543
541 std::unique_ptr<SafeBrowsingProtocolManager> pm( 544 std::unique_ptr<SafeBrowsingProtocolManager> pm(
542 CreateProtocolManager(&test_delegate)); 545 CreateProtocolManager(&test_delegate));
543 546
544 // Kick off initialization. This returns chunks from the DB synchronously. 547 // Kick off initialization. This returns chunks from the DB synchronously.
545 pm->ForceScheduleNextUpdate(TimeDelta()); 548 pm->ForceScheduleNextUpdate(TimeDelta());
546 runner_->RunPendingTasks(); 549 mock_time_task_runner_->RunUntilIdle();
547 550
548 // We should have an URLFetcher at this point in time. 551 // We should have an URLFetcher at this point in time.
549 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 552 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
550 ValidateUpdateFetcherRequest(url_fetcher); 553 ValidateUpdateFetcherRequest(url_fetcher);
551 554
552 // Go ahead and respond to it. 555 // Go ahead and respond to it.
553 url_fetcher->set_status(net::URLRequestStatus()); 556 url_fetcher->set_status(net::URLRequestStatus());
554 url_fetcher->set_response_code(404); 557 url_fetcher->set_response_code(404);
555 url_fetcher->SetResponseString(std::string()); 558 url_fetcher->SetResponseString(std::string());
556 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 559 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
(...skipping 23 matching lines...) Expand all
580 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 583 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
581 std::vector<SBListChunkRanges>(), 584 std::vector<SBListChunkRanges>(),
582 false))); 585 false)));
583 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 586 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
584 587
585 std::unique_ptr<SafeBrowsingProtocolManager> pm( 588 std::unique_ptr<SafeBrowsingProtocolManager> pm(
586 CreateProtocolManager(&test_delegate)); 589 CreateProtocolManager(&test_delegate));
587 590
588 // Kick off initialization. This returns chunks from the DB synchronously. 591 // Kick off initialization. This returns chunks from the DB synchronously.
589 pm->ForceScheduleNextUpdate(TimeDelta()); 592 pm->ForceScheduleNextUpdate(TimeDelta());
590 runner_->RunPendingTasks(); 593 mock_time_task_runner_->RunUntilIdle();
591 594
592 // We should have an URLFetcher at this point in time. 595 // We should have an URLFetcher at this point in time.
593 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 596 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
594 ValidateUpdateFetcherRequest(url_fetcher); 597 ValidateUpdateFetcherRequest(url_fetcher);
595 598
596 // Go ahead and respond to it. 599 // Go ahead and respond to it.
597 url_fetcher->set_status(net::URLRequestStatus()); 600 url_fetcher->set_status(net::URLRequestStatus());
598 url_fetcher->set_response_code(404); 601 url_fetcher->set_response_code(404);
599 url_fetcher->SetResponseString(std::string()); 602 url_fetcher->SetResponseString(std::string());
600 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 603 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
(...skipping 23 matching lines...) Expand all
624 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 627 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
625 std::vector<SBListChunkRanges>(), 628 std::vector<SBListChunkRanges>(),
626 false))); 629 false)));
627 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 630 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
628 631
629 std::unique_ptr<SafeBrowsingProtocolManager> pm( 632 std::unique_ptr<SafeBrowsingProtocolManager> pm(
630 CreateProtocolManager(&test_delegate)); 633 CreateProtocolManager(&test_delegate));
631 634
632 // Kick off initialization. This returns chunks from the DB synchronously. 635 // Kick off initialization. This returns chunks from the DB synchronously.
633 pm->ForceScheduleNextUpdate(TimeDelta()); 636 pm->ForceScheduleNextUpdate(TimeDelta());
634 runner_->RunPendingTasks(); 637 mock_time_task_runner_->RunUntilIdle();
635 638
636 // We should have an URLFetcher at this point in time. 639 // We should have an URLFetcher at this point in time.
637 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 640 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
638 ValidateUpdateFetcherRequest(url_fetcher); 641 ValidateUpdateFetcherRequest(url_fetcher);
639 642
640 // Go ahead and respond to it. 643 // Go ahead and respond to it.
641 url_fetcher->set_status(net::URLRequestStatus()); 644 url_fetcher->set_status(net::URLRequestStatus());
642 url_fetcher->set_response_code(404); 645 url_fetcher->set_response_code(404);
643 url_fetcher->SetResponseString(std::string()); 646 url_fetcher->SetResponseString(std::string());
644 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 647 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
645 648
646 // There should now be a backup request. 649 // There should now be a backup request.
647 net::TestURLFetcher* backup_url_fetcher = 650 net::TestURLFetcher* backup_url_fetcher =
648 url_fetcher_factory.GetFetcherByID(1); 651 url_fetcher_factory.GetFetcherByID(1);
649 ValidateUpdateFetcherRequest(backup_url_fetcher, kBackupHttpUrlPrefix, ""); 652 ValidateUpdateFetcherRequest(backup_url_fetcher, kBackupHttpUrlPrefix, "");
650 653
651 // Either one or two calls to RunPendingTasks are needed here. The first run 654 // Confirm that no update is scheduled (still waiting on a response to the
652 // of RunPendingTasks will run the canceled timeout task associated with 655 // backup request).
653 // the first Update request. Depending on timing, this will either directly 656 EXPECT_FALSE(pm->IsUpdateScheduled());
654 // call the timeout task from the backup request, or schedule another task 657
655 // to run that in the future. 658 // Force the timeout to fire. Need to fast forward by twice the timeout amount
656 // TODO(cbentzel): Less fragile approach. 659 // as issuing the backup request above restarted the timeout timer but that
657 runner_->RunPendingTasks(); 660 // Timer's clock isn't mocked and its impl is such that it will re-use its
658 if (!pm->IsUpdateScheduled()) 661 // initial delayed task and re-post by the remainder of the timeout when it
659 runner_->RunPendingTasks(); 662 // fires (which is pretty much the full timeout in real time since we mock the
663 // wait). A cleaner solution would be to pass
664 // |mock_time_task_runner_->GetMockTickClock()| to the
665 // SafeBrowsingProtocolManager's Timers but such hooks were deemed overkill
666 // per this being the only use case at this point.
667 mock_time_task_runner_->FastForwardBy(
668 SafeBrowsingProtocolManager::GetUpdateTimeoutForTesting() * 2);
660 EXPECT_TRUE(pm->IsUpdateScheduled()); 669 EXPECT_TRUE(pm->IsUpdateScheduled());
661 } 670 }
662 671
663 // Tests what happens when there is a connection error when issuing the update 672 // Tests what happens when there is a connection error when issuing the update
664 // request, and an error with the backup update request. 673 // request, and an error with the backup update request.
665 TEST_F(SafeBrowsingProtocolManagerTest, 674 TEST_F(SafeBrowsingProtocolManagerTest,
666 UpdateResponseConnectionErrorBackupError) { 675 UpdateResponseConnectionErrorBackupError) {
667 net::TestURLFetcherFactory url_fetcher_factory; 676 net::TestURLFetcherFactory url_fetcher_factory;
668 677
669 testing::StrictMock<MockProtocolDelegate> test_delegate; 678 testing::StrictMock<MockProtocolDelegate> test_delegate;
670 EXPECT_CALL(test_delegate, UpdateStarted()).Times(1); 679 EXPECT_CALL(test_delegate, UpdateStarted()).Times(1);
671 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce( 680 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce(
672 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 681 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
673 std::vector<SBListChunkRanges>(), 682 std::vector<SBListChunkRanges>(),
674 false))); 683 false)));
675 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 684 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
676 685
677 std::unique_ptr<SafeBrowsingProtocolManager> pm( 686 std::unique_ptr<SafeBrowsingProtocolManager> pm(
678 CreateProtocolManager(&test_delegate)); 687 CreateProtocolManager(&test_delegate));
679 688
680 // Kick off initialization. This returns chunks from the DB synchronously. 689 // Kick off initialization. This returns chunks from the DB synchronously.
681 pm->ForceScheduleNextUpdate(TimeDelta()); 690 pm->ForceScheduleNextUpdate(TimeDelta());
682 runner_->RunPendingTasks(); 691 mock_time_task_runner_->RunUntilIdle();
683 692
684 // We should have an URLFetcher at this point in time. 693 // We should have an URLFetcher at this point in time.
685 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 694 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
686 ValidateUpdateFetcherRequest(url_fetcher); 695 ValidateUpdateFetcherRequest(url_fetcher);
687 696
688 // Go ahead and respond to it. 697 // Go ahead and respond to it.
689 url_fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, 698 url_fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED,
690 net::ERR_CONNECTION_RESET)); 699 net::ERR_CONNECTION_RESET));
691 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 700 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
692 701
(...skipping 23 matching lines...) Expand all
716 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 725 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
717 std::vector<SBListChunkRanges>(), 726 std::vector<SBListChunkRanges>(),
718 false))); 727 false)));
719 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 728 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
720 729
721 std::unique_ptr<SafeBrowsingProtocolManager> pm( 730 std::unique_ptr<SafeBrowsingProtocolManager> pm(
722 CreateProtocolManager(&test_delegate)); 731 CreateProtocolManager(&test_delegate));
723 732
724 // Kick off initialization. This returns chunks from the DB synchronously. 733 // Kick off initialization. This returns chunks from the DB synchronously.
725 pm->ForceScheduleNextUpdate(TimeDelta()); 734 pm->ForceScheduleNextUpdate(TimeDelta());
726 runner_->RunPendingTasks(); 735 mock_time_task_runner_->RunUntilIdle();
727 736
728 // We should have an URLFetcher at this point in time. 737 // We should have an URLFetcher at this point in time.
729 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 738 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
730 ValidateUpdateFetcherRequest(url_fetcher); 739 ValidateUpdateFetcherRequest(url_fetcher);
731 740
732 // Go ahead and respond to it. 741 // Go ahead and respond to it.
733 url_fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, 742 url_fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED,
734 net::ERR_CONNECTION_RESET)); 743 net::ERR_CONNECTION_RESET));
735 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 744 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
736 745
(...skipping 22 matching lines...) Expand all
759 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 768 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
760 std::vector<SBListChunkRanges>(), 769 std::vector<SBListChunkRanges>(),
761 false))); 770 false)));
762 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 771 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
763 772
764 std::unique_ptr<SafeBrowsingProtocolManager> pm( 773 std::unique_ptr<SafeBrowsingProtocolManager> pm(
765 CreateProtocolManager(&test_delegate)); 774 CreateProtocolManager(&test_delegate));
766 775
767 // Kick off initialization. This returns chunks from the DB synchronously. 776 // Kick off initialization. This returns chunks from the DB synchronously.
768 pm->ForceScheduleNextUpdate(TimeDelta()); 777 pm->ForceScheduleNextUpdate(TimeDelta());
769 runner_->RunPendingTasks(); 778 mock_time_task_runner_->RunUntilIdle();
770 779
771 // We should have an URLFetcher at this point in time. 780 // We should have an URLFetcher at this point in time.
772 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 781 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
773 ValidateUpdateFetcherRequest(url_fetcher); 782 ValidateUpdateFetcherRequest(url_fetcher);
774 783
775 // Go ahead and respond to it. 784 // Go ahead and respond to it.
776 url_fetcher->set_status( 785 url_fetcher->set_status(
777 net::URLRequestStatus(net::URLRequestStatus::FAILED, 786 net::URLRequestStatus(net::URLRequestStatus::FAILED,
778 net::ERR_INTERNET_DISCONNECTED)); 787 net::ERR_INTERNET_DISCONNECTED));
779 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 788 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
(...skipping 24 matching lines...) Expand all
804 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 813 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
805 std::vector<SBListChunkRanges>(), 814 std::vector<SBListChunkRanges>(),
806 false))); 815 false)));
807 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 816 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
808 817
809 std::unique_ptr<SafeBrowsingProtocolManager> pm( 818 std::unique_ptr<SafeBrowsingProtocolManager> pm(
810 CreateProtocolManager(&test_delegate)); 819 CreateProtocolManager(&test_delegate));
811 820
812 // Kick off initialization. This returns chunks from the DB synchronously. 821 // Kick off initialization. This returns chunks from the DB synchronously.
813 pm->ForceScheduleNextUpdate(TimeDelta()); 822 pm->ForceScheduleNextUpdate(TimeDelta());
814 runner_->RunPendingTasks(); 823 mock_time_task_runner_->RunUntilIdle();
815 824
816 // We should have an URLFetcher at this point in time. 825 // We should have an URLFetcher at this point in time.
817 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 826 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
818 ValidateUpdateFetcherRequest(url_fetcher); 827 ValidateUpdateFetcherRequest(url_fetcher);
819 828
820 // Go ahead and respond to it. 829 // Go ahead and respond to it.
821 url_fetcher->set_status( 830 url_fetcher->set_status(
822 net::URLRequestStatus(net::URLRequestStatus::FAILED, 831 net::URLRequestStatus(net::URLRequestStatus::FAILED,
823 net::ERR_INTERNET_DISCONNECTED)); 832 net::ERR_INTERNET_DISCONNECTED));
824 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 833 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
(...skipping 22 matching lines...) Expand all
847 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 856 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
848 std::vector<SBListChunkRanges>(), 857 std::vector<SBListChunkRanges>(),
849 false))); 858 false)));
850 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 859 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
851 860
852 std::unique_ptr<SafeBrowsingProtocolManager> pm( 861 std::unique_ptr<SafeBrowsingProtocolManager> pm(
853 CreateProtocolManager(&test_delegate)); 862 CreateProtocolManager(&test_delegate));
854 863
855 // Kick off initialization. This returns chunks from the DB synchronously. 864 // Kick off initialization. This returns chunks from the DB synchronously.
856 pm->ForceScheduleNextUpdate(TimeDelta()); 865 pm->ForceScheduleNextUpdate(TimeDelta());
857 runner_->RunPendingTasks(); 866 mock_time_task_runner_->RunUntilIdle();
858 867
859 // We should have an URLFetcher at this point in time. 868 // We should have an URLFetcher at this point in time.
860 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 869 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
861 ValidateUpdateFetcherRequest(url_fetcher); 870 ValidateUpdateFetcherRequest(url_fetcher);
862 871
863 // The first time RunPendingTasks is called above, the update timeout timer is 872 // Force the timeout to fire.
864 // not handled. This call of RunPendingTasks will handle the update. 873 mock_time_task_runner_->FastForwardBy(
865 runner_->RunPendingTasks(); 874 SafeBrowsingProtocolManager::GetUpdateTimeoutForTesting());
866 875
867 // There should be a backup URLFetcher now. 876 // There should be a backup URLFetcher now.
868 net::TestURLFetcher* backup_url_fetcher = 877 net::TestURLFetcher* backup_url_fetcher =
869 url_fetcher_factory.GetFetcherByID(1); 878 url_fetcher_factory.GetFetcherByID(1);
870 ValidateUpdateFetcherRequest(backup_url_fetcher, kBackupConnectUrlPrefix, ""); 879 ValidateUpdateFetcherRequest(backup_url_fetcher, kBackupConnectUrlPrefix, "");
871 880
872 // Respond to the backup unsuccessfully. 881 // Respond to the backup unsuccessfully.
873 backup_url_fetcher->set_status(net::URLRequestStatus()); 882 backup_url_fetcher->set_status(net::URLRequestStatus());
874 backup_url_fetcher->set_response_code(200); 883 backup_url_fetcher->set_response_code(200);
875 backup_url_fetcher->SetResponseString(std::string()); 884 backup_url_fetcher->SetResponseString(std::string());
(...skipping 13 matching lines...) Expand all
889 std::vector<SBListChunkRanges>(), 898 std::vector<SBListChunkRanges>(),
890 false))); 899 false)));
891 EXPECT_CALL(test_delegate, ResetDatabase()).Times(1); 900 EXPECT_CALL(test_delegate, ResetDatabase()).Times(1);
892 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 901 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
893 902
894 std::unique_ptr<SafeBrowsingProtocolManager> pm( 903 std::unique_ptr<SafeBrowsingProtocolManager> pm(
895 CreateProtocolManager(&test_delegate)); 904 CreateProtocolManager(&test_delegate));
896 905
897 // Kick off initialization. This returns chunks from the DB synchronously. 906 // Kick off initialization. This returns chunks from the DB synchronously.
898 pm->ForceScheduleNextUpdate(TimeDelta()); 907 pm->ForceScheduleNextUpdate(TimeDelta());
899 runner_->RunPendingTasks(); 908 mock_time_task_runner_->RunUntilIdle();
900 909
901 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 910 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
902 ValidateUpdateFetcherRequest(url_fetcher); 911 ValidateUpdateFetcherRequest(url_fetcher);
903 912
904 // The update response is successful, and has a reset command. 913 // The update response is successful, and has a reset command.
905 url_fetcher->set_status(net::URLRequestStatus()); 914 url_fetcher->set_status(net::URLRequestStatus());
906 url_fetcher->set_response_code(200); 915 url_fetcher->set_response_code(200);
907 url_fetcher->SetResponseString("r:pleasereset\n"); 916 url_fetcher->SetResponseString("r:pleasereset\n");
908 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 917 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
909 918
(...skipping 11 matching lines...) Expand all
921 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 930 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
922 std::vector<SBListChunkRanges>(), 931 std::vector<SBListChunkRanges>(),
923 false))); 932 false)));
924 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 933 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
925 934
926 std::unique_ptr<SafeBrowsingProtocolManager> pm( 935 std::unique_ptr<SafeBrowsingProtocolManager> pm(
927 CreateProtocolManager(&test_delegate)); 936 CreateProtocolManager(&test_delegate));
928 937
929 // Kick off initialization. This returns chunks from the DB synchronously. 938 // Kick off initialization. This returns chunks from the DB synchronously.
930 pm->ForceScheduleNextUpdate(TimeDelta()); 939 pm->ForceScheduleNextUpdate(TimeDelta());
931 runner_->RunPendingTasks(); 940 mock_time_task_runner_->RunUntilIdle();
932 941
933 // The update response contains a single redirect command. 942 // The update response contains a single redirect command.
934 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 943 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
935 ValidateUpdateFetcherRequest(url_fetcher); 944 ValidateUpdateFetcherRequest(url_fetcher);
936 url_fetcher->set_status(net::URLRequestStatus()); 945 url_fetcher->set_status(net::URLRequestStatus());
937 url_fetcher->set_response_code(200); 946 url_fetcher->set_response_code(200);
938 url_fetcher->SetResponseString( 947 url_fetcher->SetResponseString(
939 base::StringPrintf("i:%s\n" 948 base::StringPrintf("i:%s\n"
940 "u:redirect-server.example.com/path\n", 949 "u:redirect-server.example.com/path\n",
941 kDefaultPhishList)); 950 kDefaultPhishList));
(...skipping 23 matching lines...) Expand all
965 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 974 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
966 std::vector<SBListChunkRanges>(), 975 std::vector<SBListChunkRanges>(),
967 false))); 976 false)));
968 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1); 977 EXPECT_CALL(test_delegate, UpdateFinished(false)).Times(1);
969 978
970 std::unique_ptr<SafeBrowsingProtocolManager> pm( 979 std::unique_ptr<SafeBrowsingProtocolManager> pm(
971 CreateProtocolManager(&test_delegate)); 980 CreateProtocolManager(&test_delegate));
972 981
973 // Kick off initialization. This returns chunks from the DB synchronously. 982 // Kick off initialization. This returns chunks from the DB synchronously.
974 pm->ForceScheduleNextUpdate(TimeDelta()); 983 pm->ForceScheduleNextUpdate(TimeDelta());
975 runner_->RunPendingTasks(); 984 mock_time_task_runner_->RunUntilIdle();
976 985
977 // The update response contains a single redirect command. 986 // The update response contains a single redirect command.
978 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 987 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
979 ValidateUpdateFetcherRequest(url_fetcher); 988 ValidateUpdateFetcherRequest(url_fetcher);
980 url_fetcher->set_status(net::URLRequestStatus()); 989 url_fetcher->set_status(net::URLRequestStatus());
981 url_fetcher->set_response_code(200); 990 url_fetcher->set_response_code(200);
982 url_fetcher->SetResponseString( 991 url_fetcher->SetResponseString(
983 base::StringPrintf("i:%s\n" 992 base::StringPrintf("i:%s\n"
984 "u:redirect-server.example.com/path\n", 993 "u:redirect-server.example.com/path\n",
985 kDefaultPhishList)); 994 kDefaultPhishList));
(...skipping 25 matching lines...) Expand all
1011 false))); 1020 false)));
1012 EXPECT_CALL(test_delegate, AddChunksRaw(kDefaultPhishList, _, _)).WillOnce( 1021 EXPECT_CALL(test_delegate, AddChunksRaw(kDefaultPhishList, _, _)).WillOnce(
1013 Invoke(HandleAddChunks)); 1022 Invoke(HandleAddChunks));
1014 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 1023 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
1015 1024
1016 std::unique_ptr<SafeBrowsingProtocolManager> pm( 1025 std::unique_ptr<SafeBrowsingProtocolManager> pm(
1017 CreateProtocolManager(&test_delegate)); 1026 CreateProtocolManager(&test_delegate));
1018 1027
1019 // Kick off initialization. This returns chunks from the DB synchronously. 1028 // Kick off initialization. This returns chunks from the DB synchronously.
1020 pm->ForceScheduleNextUpdate(TimeDelta()); 1029 pm->ForceScheduleNextUpdate(TimeDelta());
1021 runner_->RunPendingTasks(); 1030 mock_time_task_runner_->RunUntilIdle();
1022 1031
1023 // The update response contains a single redirect command. 1032 // The update response contains a single redirect command.
1024 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 1033 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
1025 ValidateUpdateFetcherRequest(url_fetcher); 1034 ValidateUpdateFetcherRequest(url_fetcher);
1026 url_fetcher->set_status(net::URLRequestStatus()); 1035 url_fetcher->set_status(net::URLRequestStatus());
1027 url_fetcher->set_response_code(200); 1036 url_fetcher->set_response_code(200);
1028 url_fetcher->SetResponseString( 1037 url_fetcher->SetResponseString(
1029 base::StringPrintf("i:%s\n" 1038 base::StringPrintf("i:%s\n"
1030 "u:redirect-server.example.com/path\n", 1039 "u:redirect-server.example.com/path\n",
1031 kDefaultPhishList)); 1040 kDefaultPhishList));
1032 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 1041 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
1033 1042
1034 // The redirect response contains a single chunk. 1043 // The redirect response contains a single chunk.
1035 net::TestURLFetcher* chunk_url_fetcher = 1044 net::TestURLFetcher* chunk_url_fetcher =
1036 url_fetcher_factory.GetFetcherByID(1); 1045 url_fetcher_factory.GetFetcherByID(1);
1037 ValidateRedirectFetcherRequest( 1046 ValidateRedirectFetcherRequest(
1038 chunk_url_fetcher, "https://redirect-server.example.com/path"); 1047 chunk_url_fetcher, "https://redirect-server.example.com/path");
1039 chunk_url_fetcher->set_status(net::URLRequestStatus()); 1048 chunk_url_fetcher->set_status(net::URLRequestStatus());
1040 chunk_url_fetcher->set_response_code(200); 1049 chunk_url_fetcher->set_response_code(200);
1041 chunk_url_fetcher->SetResponseString(kChunkPayload1); 1050 chunk_url_fetcher->SetResponseString(kChunkPayload1);
1042 chunk_url_fetcher->delegate()->OnURLFetchComplete(chunk_url_fetcher); 1051 chunk_url_fetcher->delegate()->OnURLFetchComplete(chunk_url_fetcher);
1043 1052
1044 EXPECT_FALSE(pm->IsUpdateScheduled()); 1053 EXPECT_FALSE(pm->IsUpdateScheduled());
1045 1054
1046 // The AddChunksCallback needs to be invoked. 1055 // The AddChunksCallback needs to be invoked.
1047 runner_->RunPendingTasks(); 1056 mock_time_task_runner_->RunUntilIdle();
1048 1057
1049 EXPECT_TRUE(pm->IsUpdateScheduled()); 1058 EXPECT_TRUE(pm->IsUpdateScheduled());
1050 } 1059 }
1051 1060
1052 // Tests a single valid update response, followed by multiple redirect responses 1061 // Tests a single valid update response, followed by multiple redirect responses
1053 // containing chunks. 1062 // containing chunks.
1054 TEST_F(SafeBrowsingProtocolManagerTest, MultipleRedirectResponsesWithChunks) { 1063 TEST_F(SafeBrowsingProtocolManagerTest, MultipleRedirectResponsesWithChunks) {
1055 net::TestURLFetcherFactory url_fetcher_factory; 1064 net::TestURLFetcherFactory url_fetcher_factory;
1056 1065
1057 testing::StrictMock<MockProtocolDelegate> test_delegate; 1066 testing::StrictMock<MockProtocolDelegate> test_delegate;
1058 EXPECT_CALL(test_delegate, UpdateStarted()).Times(1); 1067 EXPECT_CALL(test_delegate, UpdateStarted()).Times(1);
1059 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce( 1068 EXPECT_CALL(test_delegate, GetChunks(_)).WillOnce(
1060 Invoke(testing::CreateFunctor(InvokeGetChunksCallback, 1069 Invoke(testing::CreateFunctor(InvokeGetChunksCallback,
1061 std::vector<SBListChunkRanges>(), 1070 std::vector<SBListChunkRanges>(),
1062 false))); 1071 false)));
1063 EXPECT_CALL(test_delegate, AddChunksRaw(kDefaultPhishList, _, _)). 1072 EXPECT_CALL(test_delegate, AddChunksRaw(kDefaultPhishList, _, _)).
1064 WillRepeatedly(Invoke(HandleAddChunks)); 1073 WillRepeatedly(Invoke(HandleAddChunks));
1065 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1); 1074 EXPECT_CALL(test_delegate, UpdateFinished(true)).Times(1);
1066 1075
1067 std::unique_ptr<SafeBrowsingProtocolManager> pm( 1076 std::unique_ptr<SafeBrowsingProtocolManager> pm(
1068 CreateProtocolManager(&test_delegate)); 1077 CreateProtocolManager(&test_delegate));
1069 1078
1070 // Kick off initialization. This returns chunks from the DB synchronously. 1079 // Kick off initialization. This returns chunks from the DB synchronously.
1071 pm->ForceScheduleNextUpdate(TimeDelta()); 1080 pm->ForceScheduleNextUpdate(TimeDelta());
1072 runner_->RunPendingTasks(); 1081 mock_time_task_runner_->RunUntilIdle();
1073 1082
1074 // The update response contains multiple redirect commands. 1083 // The update response contains multiple redirect commands.
1075 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0); 1084 net::TestURLFetcher* url_fetcher = url_fetcher_factory.GetFetcherByID(0);
1076 ValidateUpdateFetcherRequest(url_fetcher); 1085 ValidateUpdateFetcherRequest(url_fetcher);
1077 url_fetcher->set_status(net::URLRequestStatus()); 1086 url_fetcher->set_status(net::URLRequestStatus());
1078 url_fetcher->set_response_code(200); 1087 url_fetcher->set_response_code(200);
1079 url_fetcher->SetResponseString( 1088 url_fetcher->SetResponseString(
1080 base::StringPrintf("i:%s\n" 1089 base::StringPrintf("i:%s\n"
1081 "u:redirect-server.example.com/one\n" 1090 "u:redirect-server.example.com/one\n"
1082 "u:redirect-server.example.com/two\n", 1091 "u:redirect-server.example.com/two\n",
1083 kDefaultPhishList)); 1092 kDefaultPhishList));
1084 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 1093 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
1085 1094
1086 // The first redirect response contains a single chunk. 1095 // The first redirect response contains a single chunk.
1087 net::TestURLFetcher* first_chunk_url_fetcher = 1096 net::TestURLFetcher* first_chunk_url_fetcher =
1088 url_fetcher_factory.GetFetcherByID(1); 1097 url_fetcher_factory.GetFetcherByID(1);
1089 ValidateRedirectFetcherRequest( 1098 ValidateRedirectFetcherRequest(
1090 first_chunk_url_fetcher, "https://redirect-server.example.com/one"); 1099 first_chunk_url_fetcher, "https://redirect-server.example.com/one");
1091 first_chunk_url_fetcher->set_status(net::URLRequestStatus()); 1100 first_chunk_url_fetcher->set_status(net::URLRequestStatus());
1092 first_chunk_url_fetcher->set_response_code(200); 1101 first_chunk_url_fetcher->set_response_code(200);
1093 first_chunk_url_fetcher->SetResponseString(kChunkPayload1); 1102 first_chunk_url_fetcher->SetResponseString(kChunkPayload1);
1094 first_chunk_url_fetcher->delegate()->OnURLFetchComplete( 1103 first_chunk_url_fetcher->delegate()->OnURLFetchComplete(
1095 first_chunk_url_fetcher); 1104 first_chunk_url_fetcher);
1096 1105
1097 // Invoke the AddChunksCallback to trigger the second request. 1106 // Invoke the AddChunksCallback to trigger the second request.
1098 runner_->RunPendingTasks(); 1107 mock_time_task_runner_->RunUntilIdle();
1099 1108
1100 EXPECT_FALSE(pm->IsUpdateScheduled()); 1109 EXPECT_FALSE(pm->IsUpdateScheduled());
1101 1110
1102 // The second redirect response contains a single chunk. 1111 // The second redirect response contains a single chunk.
1103 net::TestURLFetcher* second_chunk_url_fetcher = 1112 net::TestURLFetcher* second_chunk_url_fetcher =
1104 url_fetcher_factory.GetFetcherByID(2); 1113 url_fetcher_factory.GetFetcherByID(2);
1105 ValidateRedirectFetcherRequest( 1114 ValidateRedirectFetcherRequest(
1106 second_chunk_url_fetcher, "https://redirect-server.example.com/two"); 1115 second_chunk_url_fetcher, "https://redirect-server.example.com/two");
1107 second_chunk_url_fetcher->set_status(net::URLRequestStatus()); 1116 second_chunk_url_fetcher->set_status(net::URLRequestStatus());
1108 second_chunk_url_fetcher->set_response_code(200); 1117 second_chunk_url_fetcher->set_response_code(200);
1109 second_chunk_url_fetcher->SetResponseString(kChunkPayload2); 1118 second_chunk_url_fetcher->SetResponseString(kChunkPayload2);
1110 second_chunk_url_fetcher->delegate()->OnURLFetchComplete( 1119 second_chunk_url_fetcher->delegate()->OnURLFetchComplete(
1111 second_chunk_url_fetcher); 1120 second_chunk_url_fetcher);
1112 1121
1113 EXPECT_FALSE(pm->IsUpdateScheduled()); 1122 EXPECT_FALSE(pm->IsUpdateScheduled());
1114 1123
1115 // Invoke the AddChunksCallback to finish the update. 1124 // Invoke the AddChunksCallback to finish the update.
1116 runner_->RunPendingTasks(); 1125 mock_time_task_runner_->RunUntilIdle();
1117 1126
1118 EXPECT_TRUE(pm->IsUpdateScheduled()); 1127 EXPECT_TRUE(pm->IsUpdateScheduled());
1119 } 1128 }
1120 1129
1121 } // namespace safe_browsing 1130 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698