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

Unified Diff: components/safe_browsing_db/v4_database_unittest.cc

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: shess@ feedback Created 4 years, 2 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
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..5e76dabad1c6bcc9646348c906b3e4f2dc298347 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 {
@@ -97,10 +87,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 +125,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() {}
Nathan Parker 2016/10/07 23:24:28 This isn't used. Should it be?
vakh (use Gerrit instead) 2016/10/10 17:42:33 Nope, not needed now. Removed.
+
std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse(
StoreStateMap store_state_map,
bool use_valid_response_type) {
@@ -205,7 +193,6 @@ 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_;
@@ -216,22 +203,7 @@ 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_);
@@ -244,8 +216,7 @@ 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_);
@@ -275,8 +246,7 @@ 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_);
@@ -306,8 +276,7 @@ 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_);
@@ -338,8 +307,7 @@ 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_);
@@ -369,8 +337,7 @@ 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_);
@@ -395,8 +362,7 @@ 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_);
@@ -417,8 +383,7 @@ 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_);
@@ -447,8 +412,7 @@ 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_);

Powered by Google App Engine
This is Rietveld 408576698