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

Unified Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2148673002: Parse the hash prefix map from the V4Store on disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_merge_only
Patch Set: git fetch && git pull && gclient sync Created 4 years, 5 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 877b077d3f6fc9a444f4c9a6662ad24bdfb35f01..6f91a7f03a369ee8aff20d48aba9d5306d28ee87 100644
--- a/components/safe_browsing_db/v4_store_unittest.cc
+++ b/components/safe_browsing_db/v4_store_unittest.cc
@@ -139,6 +139,7 @@ TEST_F(V4StoreTest, TestWriteFullResponseType) {
std::unique_ptr<V4Store> read_store(new V4Store(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) {
@@ -337,4 +338,50 @@ TEST_F(V4StoreTest, TestMergeUpdatesFailsForRepeatedhashPrefix) {
store->MergeUpdate(prefix_map_old, prefix_map_additions));
}
+TEST_F(V4StoreTest, TestReadFullResponseWithValidHashPrefixMap) {
+ 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");
+ EXPECT_EQ(WRITE_SUCCESS,
+ V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
+
+ std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_));
Nathan Parker 2016/07/14 22:36:12 could put this on the stack, rather than unique_pt
vakh (use Gerrit instead) 2016/07/14 23:51:57 Done.
+ EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk());
+ EXPECT_EQ("test_client_state", read_store->state_);
+ EXPECT_EQ(2u, read_store->hash_prefix_map_.size());
Nathan Parker 2016/07/14 22:36:12 nit: ASSERT_EQ since the later checks aren't usefu
vakh (use Gerrit instead) 2016/07/14 23:51:57 Done.
+ EXPECT_EQ("00000abc", read_store->hash_prefix_map_[4]);
+ EXPECT_EQ("00000abcde", read_store->hash_prefix_map_[5]);
+}
+
+TEST_F(V4StoreTest, TestReadFullResponseInWithValidHashPrefixMap) {
Nathan Parker 2016/07/14 22:36:12 What does the "In" in the name here mean, compared
vakh (use Gerrit instead) 2016/07/14 23:51:57 Typo. Fixed.
+ 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");
+ EXPECT_EQ(WRITE_SUCCESS,
+ V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur)));
+
+ std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_));
+ EXPECT_EQ(HASH_PREFIX_MAP_GENERATION_FAILURE, read_store->ReadFromDisk());
Nathan Parker 2016/07/14 22:36:12 Add a comment above about what makes this fail. I
vakh (use Gerrit instead) 2016/07/14 23:51:57 Done.
+ EXPECT_TRUE(read_store->state_.empty());
+ EXPECT_TRUE(read_store->hash_prefix_map_.empty());
+}
+
} // namespace safe_browsing
« 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