| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/debug/leak_annotations.h" | 6 #include "base/debug/leak_annotations.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 SetupInfoMapAndExpectedState(); | 85 SetupInfoMapAndExpectedState(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TearDown() override { | 88 void TearDown() override { |
| 89 V4Database::RegisterStoreFactoryForTest(nullptr); | 89 V4Database::RegisterStoreFactoryForTest(nullptr); |
| 90 PlatformTest::TearDown(); | 90 PlatformTest::TearDown(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void RegisterFactory(bool hash_prefix_matches = true) { | 93 void RegisterFactory(bool hash_prefix_matches = true) { |
| 94 V4Database::RegisterStoreFactoryForTest( | 94 factory_.reset(new FakeV4StoreFactory(hash_prefix_matches)); |
| 95 base::MakeUnique<FakeV4StoreFactory>(hash_prefix_matches)); | 95 V4Database::RegisterStoreFactoryForTest(factory_.get()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void SetupInfoMapAndExpectedState() { | 98 void SetupInfoMapAndExpectedState() { |
| 99 list_infos_.emplace_back(true, "win_url_malware", win_malware_id_, | 99 list_infos_.emplace_back(true, "win_url_malware", win_malware_id_, |
| 100 SB_THREAT_TYPE_URL_MALWARE); | 100 SB_THREAT_TYPE_URL_MALWARE); |
| 101 expected_identifiers_.push_back(win_malware_id_); | 101 expected_identifiers_.push_back(win_malware_id_); |
| 102 expected_store_paths_.push_back( | 102 expected_store_paths_.push_back( |
| 103 database_dirname_.AppendASCII("win_url_malware.fake")); | 103 database_dirname_.AppendASCII("win_url_malware.fake")); |
| 104 | 104 |
| 105 list_infos_.emplace_back(true, "linux_url_malware", linux_malware_id_, | 105 list_infos_.emplace_back(true, "linux_url_malware", linux_malware_id_, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 std::unique_ptr<V4Database> v4_database_; | 199 std::unique_ptr<V4Database> v4_database_; |
| 200 base::FilePath database_dirname_; | 200 base::FilePath database_dirname_; |
| 201 base::ScopedTempDir temp_dir_; | 201 base::ScopedTempDir temp_dir_; |
| 202 content::TestBrowserThreadBundle thread_bundle_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
| 203 bool created_but_not_called_back_; | 203 bool created_but_not_called_back_; |
| 204 bool created_and_called_back_; | 204 bool created_and_called_back_; |
| 205 bool verify_checksum_called_back_; | 205 bool verify_checksum_called_back_; |
| 206 ListInfos list_infos_; | 206 ListInfos list_infos_; |
| 207 std::vector<ListIdentifier> expected_identifiers_; | 207 std::vector<ListIdentifier> expected_identifiers_; |
| 208 std::vector<base::FilePath> expected_store_paths_; | 208 std::vector<base::FilePath> expected_store_paths_; |
| 209 std::unique_ptr<FakeV4StoreFactory> factory_; |
| 209 DatabaseUpdatedCallback callback_db_updated_; | 210 DatabaseUpdatedCallback callback_db_updated_; |
| 210 NewDatabaseReadyCallback callback_db_ready_; | 211 NewDatabaseReadyCallback callback_db_ready_; |
| 211 StoreStateMap expected_store_state_map_; | 212 StoreStateMap expected_store_state_map_; |
| 212 base::hash_map<ListIdentifier, V4Store*> old_stores_map_; | 213 base::hash_map<ListIdentifier, V4Store*> old_stores_map_; |
| 213 const ListIdentifier linux_malware_id_, win_malware_id_; | 214 const ListIdentifier linux_malware_id_, win_malware_id_; |
| 214 }; | 215 }; |
| 215 | 216 |
| 216 // Test to set up the database with fake stores. | 217 // Test to set up the database with fake stores. |
| 217 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStores) { | 218 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStores) { |
| 218 RegisterFactory(); | 219 RegisterFactory(); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 // Step 3: Before V4Store::ApplyUpdate gets executed on the task runner, | 509 // Step 3: Before V4Store::ApplyUpdate gets executed on the task runner, |
| 509 // destroy the database. This posts ~V4Database() on the task runner. | 510 // destroy the database. This posts ~V4Database() on the task runner. |
| 510 V4Database::Destroy(std::move(v4_database_)); | 511 V4Database::Destroy(std::move(v4_database_)); |
| 511 | 512 |
| 512 // Step 4: Wait for the task runner to go to completion. The test should | 513 // Step 4: Wait for the task runner to go to completion. The test should |
| 513 // finish to completion and the |null_callback| should not get called. | 514 // finish to completion and the |null_callback| should not get called. |
| 514 WaitForTasksOnTaskRunner(); | 515 WaitForTasksOnTaskRunner(); |
| 515 } | 516 } |
| 516 | 517 |
| 517 } // namespace safe_browsing | 518 } // namespace safe_browsing |
| OLD | NEW |