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

Unified Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2403913004: Small: Serialize the store's hash_prefix_map_ to file in WriteToDisk() (Closed)
Patch Set: Serialize the store's hash_prefix_map_ to file in WriteToDisk() 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_store_unittest.cc
diff --git a/components/safe_browsing_db/v4_store_unittest.cc b/components/safe_browsing_db/v4_store_unittest.cc
index 28191dad4c78179bb345c843134ec17d18fa9e55..5cb6f05224f1d752cc6e8d4b665f58e17e28ea00 100644
--- a/components/safe_browsing_db/v4_store_unittest.cc
+++ b/components/safe_browsing_db/v4_store_unittest.cc
@@ -129,35 +129,6 @@ TEST_F(V4StoreTest, TestReadFromNoHashPrefixesFile) {
EXPECT_EQ(READ_SUCCESS, V4Store(task_runner_, store_path_).ReadFromDisk());
}
-TEST_F(V4StoreTest, TestWriteNoResponseType) {
- EXPECT_EQ(INVALID_RESPONSE_TYPE_FAILURE,
- V4Store(task_runner_, store_path_)
- .WriteToDisk(base::WrapUnique(new ListUpdateResponse)));
-}
-
-TEST_F(V4StoreTest, TestWritePartialResponseType) {
- std::unique_ptr<ListUpdateResponse> list_update_response(
- new ListUpdateResponse);
- list_update_response->set_response_type(ListUpdateResponse::PARTIAL_UPDATE);
- EXPECT_EQ(INVALID_RESPONSE_TYPE_FAILURE,
- V4Store(task_runner_, store_path_)
- .WriteToDisk(std::move(list_update_response)));
-}
-
-TEST_F(V4StoreTest, TestWriteFullResponseType) {
- std::unique_ptr<ListUpdateResponse> list_update_response(
- new ListUpdateResponse);
- list_update_response->set_response_type(ListUpdateResponse::FULL_UPDATE);
- list_update_response->set_new_client_state("test_client_state");
- EXPECT_EQ(WRITE_SUCCESS, V4Store(task_runner_, store_path_)
- .WriteToDisk(std::move(list_update_response)));
-
- V4Store read_store(task_runner_, store_path_);
- EXPECT_EQ(READ_SUCCESS, read_store.ReadFromDisk());
- EXPECT_EQ("test_client_state", read_store.state_);
- EXPECT_TRUE(read_store.hash_prefix_map_.empty());
-}
-
TEST_F(V4StoreTest, TestAddUnlumpedHashesWithInvalidAddition) {
HashPrefixMap prefix_map;
EXPECT_EQ(ADDITIONS_SIZE_UNEXPECTED_FAILURE,
@@ -569,22 +540,12 @@ TEST_F(V4StoreTest, TestMergeUpdatesRemovesMultipleAcrossDifferentSizes) {
}
TEST_F(V4StoreTest, TestReadFullResponseWithValidHashPrefixMap) {
Nathan Parker 2016/10/11 20:29:42 How about a test for when a write fails (like, per
vakh (use Gerrit instead) 2016/10/11 21:50:39 Done.
- std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse);
- lur->set_response_type(ListUpdateResponse::FULL_UPDATE);
- lur->set_new_client_state("test_client_state");
- lur->set_platform_type(WINDOWS_PLATFORM);
- lur->set_threat_entry_type(URL);
- lur->set_threat_type(MALWARE_THREAT);
- ThreatEntrySet* additions = lur->add_additions();
- additions->set_compression_type(RAW);
- additions->mutable_raw_hashes()->set_prefix_size(5);
- additions->mutable_raw_hashes()->set_raw_hashes("00000abcde");
- additions = lur->add_additions();
- additions->set_compression_type(RAW);
- additions->mutable_raw_hashes()->set_prefix_size(4);
- additions->mutable_raw_hashes()->set_raw_hashes("00000abc");
+ V4Store write_store(task_runner_, store_path_);
+ write_store.hash_prefix_map_[4] = "00000abc";
+ write_store.hash_prefix_map_[5] = "00000abcde";
+ write_store.state_ = "test_client_state";
EXPECT_EQ(WRITE_SUCCESS,
- V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
+ write_store.WriteToDisk(GetUrlMalwareId(), Checksum()));
V4Store read_store (task_runner_, store_path_);
EXPECT_EQ(READ_SUCCESS, read_store.ReadFromDisk());
@@ -599,18 +560,11 @@ TEST_F(V4StoreTest, TestReadFullResponseWithValidHashPrefixMap) {
// size is 5 so the parser isn't able to split the hash prefixes list
// completely.
TEST_F(V4StoreTest, TestReadFullResponseWithInvalidHashPrefixMap) {
- std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse);
- lur->set_response_type(ListUpdateResponse::FULL_UPDATE);
- lur->set_new_client_state("test_client_state");
- lur->set_platform_type(WINDOWS_PLATFORM);
- lur->set_threat_entry_type(URL);
- lur->set_threat_type(MALWARE_THREAT);
- ThreatEntrySet* additions = lur->add_additions();
- additions->set_compression_type(RAW);
- additions->mutable_raw_hashes()->set_prefix_size(5);
- additions->mutable_raw_hashes()->set_raw_hashes("abcdef");
+ V4Store write_store(task_runner_, store_path_);
+ write_store.hash_prefix_map_[5] = "abcdef";
+ write_store.state_ = "test_client_state";
EXPECT_EQ(WRITE_SUCCESS,
- V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
+ write_store.WriteToDisk(GetUrlMalwareId(), Checksum()));
V4Store read_store(task_runner_, store_path_);
EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store.ReadFromDisk());
« components/safe_browsing_db/v4_store.cc ('K') | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698