| 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 2ce05ee3ec18ee7ee05cd2b79434eda842401b02..a6b29a54ea47668f0757e0dc5cdd2ec9cde89f6d 100644
|
| --- a/components/safe_browsing_db/v4_database_unittest.cc
|
| +++ b/components/safe_browsing_db/v4_database_unittest.cc
|
| @@ -19,15 +19,11 @@ class FakeV4Store : public V4Store {
|
| public:
|
| FakeV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
|
| const base::FilePath& store_path,
|
| - const bool reset_succeeds,
|
| const bool hash_prefix_matches)
|
| : V4Store(
|
| task_runner,
|
| base::FilePath(store_path.value() + FILE_PATH_LITERAL(".fake"))),
|
| - hash_prefix_should_match_(hash_prefix_matches),
|
| - reset_succeeds_(reset_succeeds) {}
|
| -
|
| - bool Reset() override { return reset_succeeds_; }
|
| + hash_prefix_should_match_(hash_prefix_matches) {}
|
|
|
| HashPrefix GetMatchingHashPrefix(const FullHash& full_hash) override {
|
| return hash_prefix_should_match_ ? full_hash : HashPrefix();
|
| @@ -39,30 +35,24 @@ class FakeV4Store : public V4Store {
|
|
|
| private:
|
| bool hash_prefix_should_match_;
|
| - bool reset_succeeds_;
|
| };
|
|
|
| -// This factory creates a "fake" store. It allows the caller to specify that the
|
| -// first store should fail on Reset() i.e. return false. All subsequent stores
|
| -// always return true. This is used to test the Reset() method in V4Database.
|
| +// This factory creates a "fake" store. It allows the caller to specify whether
|
| +// the store has a hash prefix matching a full hash. This is used to test the
|
| +// |GetStoresMatchingFullHash()| method in |V4Database|.
|
| class FakeV4StoreFactory : public V4StoreFactory {
|
| public:
|
| - FakeV4StoreFactory(bool next_store_reset_fails, bool hash_prefix_matches)
|
| - : hash_prefix_should_match_(hash_prefix_matches),
|
| - next_store_reset_fails_(next_store_reset_fails) {}
|
| + FakeV4StoreFactory(bool hash_prefix_matches)
|
| + : hash_prefix_should_match_(hash_prefix_matches) {}
|
|
|
| V4Store* CreateV4Store(
|
| const scoped_refptr<base::SequencedTaskRunner>& task_runner,
|
| const base::FilePath& store_path) override {
|
| - bool reset_succeeds = !next_store_reset_fails_;
|
| - next_store_reset_fails_ = false;
|
| - return new FakeV4Store(task_runner, store_path, reset_succeeds,
|
| - hash_prefix_should_match_);
|
| + return new FakeV4Store(task_runner, store_path, hash_prefix_should_match_);
|
| }
|
|
|
| private:
|
| bool hash_prefix_should_match_;
|
| - bool next_store_reset_fails_;
|
| };
|
|
|
| class V4DatabaseTest : public PlatformTest {
|
| @@ -89,6 +79,9 @@ class V4DatabaseTest : public PlatformTest {
|
| &V4DatabaseTest::NewDatabaseReadyWithExpectedStorePathsAndIds,
|
| base::Unretained(this));
|
|
|
| + callback_db_ready_for_updates_ = base::Bind(
|
| + &V4DatabaseTest::DatabaseReadyForUpdates, base::Unretained(this));
|
| +
|
| SetupInfoMapAndExpectedState();
|
| }
|
|
|
| @@ -97,10 +90,8 @@ class V4DatabaseTest : public PlatformTest {
|
| PlatformTest::TearDown();
|
| }
|
|
|
| - void RegisterFactory(bool fails_first_reset,
|
| - bool hash_prefix_matches = true) {
|
| - factory_.reset(
|
| - new FakeV4StoreFactory(fails_first_reset, hash_prefix_matches));
|
| + void RegisterFactory(bool hash_prefix_matches = true) {
|
| + factory_.reset(new FakeV4StoreFactory(hash_prefix_matches));
|
| V4Database::RegisterStoreFactoryForTest(factory_.get());
|
| }
|
|
|
| @@ -137,14 +128,14 @@ class V4DatabaseTest : public PlatformTest {
|
| EXPECT_EQ(expected_store_path, store->store_path());
|
| }
|
|
|
| - EXPECT_EQ(expected_resets_successfully_, v4_database->ResetDatabase());
|
| -
|
| EXPECT_FALSE(created_and_called_back_);
|
| created_and_called_back_ = true;
|
|
|
| v4_database_ = std::move(v4_database);
|
| }
|
|
|
| + void DatabaseReadyForUpdates() {}
|
| +
|
| std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse(
|
| StoreStateMap store_state_map,
|
| bool use_valid_response_type) {
|
| @@ -205,10 +196,10 @@ class V4DatabaseTest : public PlatformTest {
|
| ListInfos list_infos_;
|
| std::vector<ListIdentifier> expected_identifiers_;
|
| std::vector<base::FilePath> expected_store_paths_;
|
| - bool expected_resets_successfully_;
|
| std::unique_ptr<FakeV4StoreFactory> factory_;
|
| DatabaseUpdatedCallback callback_db_updated_;
|
| NewDatabaseReadyCallback callback_db_ready_;
|
| + DatabaseReadyForUpdatesCallback callback_db_ready_for_updates_;
|
| StoreStateMap expected_store_state_map_;
|
| base::hash_map<ListIdentifier, V4Store*> old_stores_map_;
|
| const ListIdentifier linux_malware_id_, win_malware_id_;
|
| @@ -216,25 +207,10 @@ class V4DatabaseTest : public PlatformTest {
|
|
|
| // Test to set up the database with fake stores.
|
| TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStores) {
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| -
|
| - V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| - created_but_not_called_back_ = true;
|
| - task_runner_->RunPendingTasks();
|
| -
|
| - base::RunLoop().RunUntilIdle();
|
| - EXPECT_EQ(true, created_and_called_back_);
|
| -}
|
| -
|
| -// Test to set up the database with fake stores that fail to reset.
|
| -TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStoresFailsReset) {
|
| - expected_resets_successfully_ = false;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| + RegisterFactory();
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
|
|
| @@ -244,11 +220,10 @@ TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStoresFailsReset) {
|
|
|
| // Test to check database updates as expected.
|
| TEST_F(V4DatabaseTest, TestApplyUpdateWithNewStates) {
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| + RegisterFactory();
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
| base::RunLoop().RunUntilIdle();
|
| @@ -275,11 +250,10 @@ TEST_F(V4DatabaseTest, TestApplyUpdateWithNewStates) {
|
|
|
| // Test to ensure no state updates leads to no store updates.
|
| TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) {
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| + RegisterFactory();
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
| base::RunLoop().RunUntilIdle();
|
| @@ -306,11 +280,10 @@ TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) {
|
|
|
| // Test to ensure no updates leads to no store updates.
|
| TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) {
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| + RegisterFactory();
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
| base::RunLoop().RunUntilIdle();
|
| @@ -338,11 +311,10 @@ TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) {
|
|
|
| // Test to ensure invalid update leads to no store changes.
|
| TEST_F(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate) {
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_);
|
| + RegisterFactory();
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
| base::RunLoop().RunUntilIdle();
|
| @@ -369,11 +341,10 @@ TEST_F(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate) {
|
| // Test to ensure the case that all stores match a given full hash.
|
| TEST_F(V4DatabaseTest, TestAllStoresMatchFullHash) {
|
| bool hash_prefix_matches = true;
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_, hash_prefix_matches);
|
| + RegisterFactory(hash_prefix_matches);
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
|
|
| @@ -395,11 +366,10 @@ TEST_F(V4DatabaseTest, TestAllStoresMatchFullHash) {
|
| // Test to ensure the case that no stores match a given full hash.
|
| TEST_F(V4DatabaseTest, TestNoStoreMatchesFullHash) {
|
| bool hash_prefix_matches = false;
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_, hash_prefix_matches);
|
| + RegisterFactory(hash_prefix_matches);
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
|
|
| @@ -417,11 +387,10 @@ TEST_F(V4DatabaseTest, TestNoStoreMatchesFullHash) {
|
| TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHash) {
|
| // Setup stores to not match the full hash.
|
| bool hash_prefix_matches = false;
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_, hash_prefix_matches);
|
| + RegisterFactory(hash_prefix_matches);
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
|
|
| @@ -447,11 +416,10 @@ TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHash) {
|
| TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHashBecauseOfStoresToMatch) {
|
| // Setup all stores to match the full hash.
|
| bool hash_prefix_matches = true;
|
| - expected_resets_successfully_ = true;
|
| - RegisterFactory(!expected_resets_successfully_, hash_prefix_matches);
|
| + RegisterFactory(hash_prefix_matches);
|
|
|
| V4Database::Create(task_runner_, database_dirname_, list_infos_,
|
| - callback_db_ready_);
|
| + callback_db_ready_, callback_db_ready_for_updates_);
|
| created_but_not_called_back_ = true;
|
| task_runner_->RunPendingTasks();
|
|
|
|
|