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

Unified Diff: components/safe_browsing_db/v4_update_protocol_manager_unittest.cc

Issue 1853833002: Added a test for success after one backoff (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v4_02_init_update
Patch Set: git fetch && pull && bring back checks for update_error_count_ Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/safe_browsing_db/v4_update_protocol_manager.h ('k') | no next file » | 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 5ea6182c5a7d72afda3fbc25168e5ba84816d370..c7665cd8fa06a5d4a851d159f10a623989d002a6 100644
--- a/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
+++ b/components/safe_browsing_db/v4_update_protocol_manager_unittest.cc
@@ -34,9 +34,12 @@ namespace safe_browsing {
class V4UpdateProtocolManagerTest : public testing::Test {
protected:
- static void ValidateGetUpdatesResults(
+ void ValidateGetUpdatesResults(
const std::vector<ListUpdateResponse>& expected_lurs,
const std::vector<ListUpdateResponse>& list_update_responses) {
+ // The callback should never be called if expect_callback_to_be_called_ is
+ // false.
+ EXPECT_TRUE(expect_callback_to_be_called_);
ASSERT_EQ(expected_lurs.size(), list_update_responses.size());
for (unsigned int i = 0; i < list_update_responses.size(); ++i) {
@@ -64,7 +67,8 @@ class V4UpdateProtocolManagerTest : public testing::Test {
config.disable_auto_update = false;
return V4UpdateProtocolManager::Create(
NULL, config, current_list_states,
- base::Bind(ValidateGetUpdatesResults, expected_lurs));
+ base::Bind(&V4UpdateProtocolManagerTest::ValidateGetUpdatesResults,
+ base::Unretained(this), expected_lurs));
}
void SetupCurrentListStates(
@@ -130,6 +134,8 @@ class V4UpdateProtocolManagerTest : public testing::Test {
return res_data;
}
+
+ bool expect_callback_to_be_called_;
};
// TODO(vakh): Add many more tests.
@@ -147,8 +153,9 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesErrorHandlingNetwork) {
// Initial state. No errors.
EXPECT_EQ(0ul, pm->update_error_count_);
EXPECT_EQ(1ul, pm->update_back_off_mult_);
-
+ expect_callback_to_be_called_ = false;
pm->IssueUpdateRequest();
+
EXPECT_FALSE(pm->IsUpdateScheduled());
runner->RunPendingTasks();
@@ -177,7 +184,12 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesErrorHandlingResponseCode) {
CreateProtocolManager(current_list_states, 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_ = false;
pm->IssueUpdateRequest();
+
EXPECT_FALSE(pm->IsUpdateScheduled());
runner->RunPendingTasks();
@@ -209,7 +221,12 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesNoError) {
CreateProtocolManager(current_list_states, 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->IssueUpdateRequest();
+
EXPECT_FALSE(pm->IsUpdateScheduled());
runner->RunPendingTasks();
@@ -227,4 +244,57 @@ TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesNoError) {
EXPECT_TRUE(pm->IsUpdateScheduled());
}
+TEST_F(V4UpdateProtocolManagerTest, TestGetUpdatesWithOneBackoff) {
+ scoped_refptr<base::TestSimpleTaskRunner> runner(
+ new base::TestSimpleTaskRunner());
+ base::ThreadTaskRunnerHandle runner_handler(runner);
+ net::TestURLFetcherFactory factory;
+ std::vector<ListUpdateResponse> expected_lurs;
+ SetupExpectedListUpdateResponse(&expected_lurs);
+ base::hash_map<UpdateListIdentifier, std::string> current_list_states;
+ SetupCurrentListStates(&current_list_states);
+ scoped_ptr<V4UpdateProtocolManager> pm(
+ CreateProtocolManager(current_list_states, 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_ = false;
+ pm->IssueUpdateRequest();
+
+ EXPECT_FALSE(pm->IsUpdateScheduled());
+
+ runner->RunPendingTasks();
+
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
+ DCHECK(fetcher);
+ fetcher->set_status(net::URLRequestStatus());
+ // Response code of anything other than 200 should result in error.
+ fetcher->set_response_code(net::HTTP_NO_CONTENT);
+ fetcher->SetResponseString("");
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+
+ // Should have recorded one error, but back off multiplier is unchanged.
+ EXPECT_EQ(1ul, pm->update_error_count_);
+ EXPECT_EQ(1ul, pm->update_back_off_mult_);
+ EXPECT_TRUE(pm->IsUpdateScheduled());
+
+ // Retry, now no backoff.
+ expect_callback_to_be_called_ = true;
+ runner->RunPendingTasks();
+
+ 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_);
+ EXPECT_TRUE(pm->IsUpdateScheduled());
+}
+
} // namespace safe_browsing
« no previous file with comments | « components/safe_browsing_db/v4_update_protocol_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698