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

Unified Diff: components/safe_browsing_db/v4_database_unittest.cc

Issue 2649643002: [S] Use a weak_factory for V4Database callbacks + test (Closed)
Patch Set: Nit: s/weak_factory_/weak_factory_on_io_ Created 3 years, 11 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_database.cc ('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_database_unittest.cc
diff --git a/components/safe_browsing_db/v4_database_unittest.cc b/components/safe_browsing_db/v4_database_unittest.cc
index a9133d74f2bf0d2bd226f7924b3d8f999119a0a2..b8e0786aedca30413f7d55130aa2ed9137313179 100644
--- a/components/safe_browsing_db/v4_database_unittest.cc
+++ b/components/safe_browsing_db/v4_database_unittest.cc
@@ -110,6 +110,7 @@ class V4DatabaseTest : public PlatformTest {
}
void DatabaseUpdated() {}
+
void NewDatabaseReadyWithExpectedStorePathsAndIds(
std::unique_ptr<V4Database> v4_database) {
ASSERT_TRUE(v4_database);
@@ -476,4 +477,42 @@ TEST_F(V4DatabaseTest, TestStoresAvailable) {
EXPECT_FALSE(v4_database_->AreStoresAvailable(StoresToCheck({bogus_id})));
}
+// Test to ensure that the callback to the database is dropped when the database
+// gets destroyed. See http://crbug.com/683147#c5 for more details.
+TEST_F(V4DatabaseTest, UsingWeakPtrDropsCallback) {
+ RegisterFactory();
+
+ // Step 1: Create the database.
+ V4Database::Create(task_runner_, database_dirname_, list_infos_,
+ callback_db_ready_);
+ created_but_not_called_back_ = true;
+ WaitForTasksOnTaskRunner();
+
+ // Step 2: Try to update the database. This posts V4Store::ApplyUpdate on the
+ // task runner.
+ std::unique_ptr<ParsedServerResponse> parsed_server_response(
+ new ParsedServerResponse);
+ auto lur = base::MakeUnique<ListUpdateResponse>();
+ lur->set_platform_type(linux_malware_id_.platform_type());
+ lur->set_threat_entry_type(linux_malware_id_.threat_entry_type());
+ lur->set_threat_type(linux_malware_id_.threat_type());
+ lur->set_new_client_state("new_state");
+ lur->set_response_type(ListUpdateResponse::FULL_UPDATE);
+ parsed_server_response->push_back(std::move(lur));
+
+ // We pass |null_callback| as the second argument to |ApplyUpdate| since we
+ // expect it to not get called. This callback method is called from
+ // V4Database::UpdatedStoreReady but we expect that call to get dropped.
+ base::Callback<void()> null_callback;
+ v4_database_->ApplyUpdate(std::move(parsed_server_response), null_callback);
+
+ // Step 3: Before V4Store::ApplyUpdate gets executed on the task runner,
+ // destroy the database. This posts ~V4Database() on the task runner.
+ V4Database::Destroy(std::move(v4_database_));
+
+ // Step 4: Wait for the task runner to go to completion. The test should
+ // finish to completion and the |null_callback| should not get called.
+ WaitForTasksOnTaskRunner();
+}
+
} // namespace safe_browsing
« no previous file with comments | « components/safe_browsing_db/v4_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698