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

Unified Diff: components/safe_browsing_db/v4_update_protocol_manager_unittest.cc

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/safe_browsing_db/v4_update_protocol_manager.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
diff --git a/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc b/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
index 856c6e4e92bbff60e03d1158d57ce9a4eaa49bfc..cdef738250148be8752905ffb7b58efadb71a405 100644
--- a/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
+++ b/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
@@ -148,8 +148,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesErrorHandlingNetwork) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
// Failed request status should result in error.
@@ -182,8 +180,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesErrorHandlingResponseCode) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -218,8 +214,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesNoError) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -253,8 +247,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesWithOneBackoff) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -270,6 +262,7 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesWithOneBackoff) {
// Retry, now no backoff.
expect_callback_to_be_called_ = true;
+ // Call RunPendingTasks to ensure that the request is sent after backoff.
runner->RunPendingTasks();
fetcher = factory.GetFetcherByID(1);
@@ -324,4 +317,45 @@ TEST_F(V4UpdateProtocolManagerTest, TestDisableAutoUpdates) {
DCHECK(!fetcher);
}
+TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesHasTimeout) {
+ scoped_refptr<base::TestSimpleTaskRunner> runner(
+ new base::TestSimpleTaskRunner());
+ base::ThreadTaskRunnerHandle runner_handler(runner);
+ net::TestURLFetcherFactory factory;
+ std::vector<ListUpdateResponse> expected_lurs;
+ SetupExpectedListUpdateResponse(&expected_lurs);
+ std::unique_ptr<V4UpdateProtocolManager> pm(
+ CreateProtocolManager(expected_lurs));
+ runner->ClearPendingTasks();
+
+ // Initial state. No errors.
+ EXPECT_EQ(0ul, pm->update_error_count_);
+ EXPECT_EQ(1ul, pm->update_back_off_mult_);
+ expect_callback_to_be_called_ = true;
+ pm->store_state_map_ = std::move(store_state_map_);
+ pm->IssueUpdateRequest();
+
+ net::TestURLFetcher* timeout_fetcher = factory.GetFetcherByID(0);
+ DCHECK(timeout_fetcher);
+ // Don't set anything on the fetcher. Let it time out.
+ runner->RunPendingTasks();
+
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(1);
+ DCHECK(!fetcher);
+ // Now wait for the next request to be scheduled.
+ runner->RunPendingTasks();
+
+ // There should be another fetcher now.
+ fetcher = factory.GetFetcherByID(1);
+ DCHECK(fetcher);
+ fetcher->set_status(net::URLRequestStatus());
+ fetcher->set_response_code(net::HTTP_OK);
+ fetcher->SetResponseString(GetExpectedV4UpdateResponse(expected_lurs));
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+
+ // No error, back off multiplier is unchanged.
+ EXPECT_EQ(0ul, pm->update_error_count_);
+ EXPECT_EQ(1ul, pm->update_back_off_mult_);
+}
+
} // namespace safe_browsing
« no previous file with comments | « components/safe_browsing_db/v4_update_protocol_manager.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698