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

Unified Diff: components/safe_browsing_db/v4_update_protocol_manager_unittest.cc

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: 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
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 e8596e68e89a7a73dd7045b9084d580214dd311d..055bdcfb784fa2c5db86aae84bbe5ef7e30c90ff 100644
--- a/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
+++ b/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
@@ -163,8 +163,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.
@@ -197,8 +195,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesErrorHandlingResponseCode) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -233,8 +229,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesNoError) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -268,8 +262,6 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesWithOneBackoff) {
EXPECT_FALSE(pm->IsUpdateScheduled());
- runner->RunPendingTasks();
-
net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
DCHECK(fetcher);
fetcher->set_status(net::URLRequestStatus());
@@ -285,6 +277,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);
@@ -320,4 +313,40 @@ TEST_F(V4UpdateProtocolManagerTest, TestBase64EncodingUsesUrlEncoding) {
// the '-' case is sufficient to prove that we are using URL encoding.
}
+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();
+
+ // There should be another fetcher now.
+ net::TestURLFetcher* 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

Powered by Google App Engine
This is Rietveld 408576698