Chromium Code Reviews| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 std::unique_ptr<ListUpdateResponse> list_update_response( | 132 std::unique_ptr<ListUpdateResponse> list_update_response( |
| 133 new ListUpdateResponse); | 133 new ListUpdateResponse); |
| 134 list_update_response->set_response_type(ListUpdateResponse::FULL_UPDATE); | 134 list_update_response->set_response_type(ListUpdateResponse::FULL_UPDATE); |
| 135 list_update_response->set_new_client_state("test_client_state"); | 135 list_update_response->set_new_client_state("test_client_state"); |
| 136 EXPECT_EQ(WRITE_SUCCESS, V4Store(task_runner_, store_path_) | 136 EXPECT_EQ(WRITE_SUCCESS, V4Store(task_runner_, store_path_) |
| 137 .WriteToDisk(std::move(list_update_response))); | 137 .WriteToDisk(std::move(list_update_response))); |
| 138 | 138 |
| 139 std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_)); | 139 std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_)); |
| 140 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk()); | 140 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk()); |
| 141 EXPECT_EQ("test_client_state", read_store->state_); | 141 EXPECT_EQ("test_client_state", read_store->state_); |
| 142 EXPECT_TRUE(read_store->hash_prefix_map_.empty()); | |
| 142 } | 143 } |
| 143 | 144 |
| 144 TEST_F(V4StoreTest, TestAddUnlumpedHashesWithInvalidAddition) { | 145 TEST_F(V4StoreTest, TestAddUnlumpedHashesWithInvalidAddition) { |
| 145 HashPrefixMap prefix_map; | 146 HashPrefixMap prefix_map; |
| 146 EXPECT_EQ(ADDITIONS_SIZE_UNEXPECTED_FAILURE, | 147 EXPECT_EQ(ADDITIONS_SIZE_UNEXPECTED_FAILURE, |
| 147 V4Store::AddUnlumpedHashes(5, "a", &prefix_map)); | 148 V4Store::AddUnlumpedHashes(5, "a", &prefix_map)); |
| 148 EXPECT_TRUE(prefix_map.empty()); | 149 EXPECT_TRUE(prefix_map.empty()); |
| 149 } | 150 } |
| 150 | 151 |
| 151 TEST_F(V4StoreTest, TestAddUnlumpedHashesWithEmptyString) { | 152 TEST_F(V4StoreTest, TestAddUnlumpedHashesWithEmptyString) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_old)); | 331 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_old)); |
| 331 HashPrefixMap prefix_map_additions; | 332 HashPrefixMap prefix_map_additions; |
| 332 EXPECT_EQ(APPLY_UPDATE_SUCCESS, | 333 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
| 333 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_additions)); | 334 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_additions)); |
| 334 | 335 |
| 335 std::unique_ptr<V4Store> store(new V4Store(task_runner_, store_path_)); | 336 std::unique_ptr<V4Store> store(new V4Store(task_runner_, store_path_)); |
| 336 EXPECT_EQ(ADDITIONS_HAS_EXISTING_PREFIX_FAILURE, | 337 EXPECT_EQ(ADDITIONS_HAS_EXISTING_PREFIX_FAILURE, |
| 337 store->MergeUpdate(prefix_map_old, prefix_map_additions)); | 338 store->MergeUpdate(prefix_map_old, prefix_map_additions)); |
| 338 } | 339 } |
| 339 | 340 |
| 341 TEST_F(V4StoreTest, TestReadFullResponseWithValidHashPrefixMap) { | |
| 342 std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse); | |
| 343 lur->set_response_type(ListUpdateResponse::FULL_UPDATE); | |
| 344 lur->set_new_client_state("test_client_state"); | |
| 345 lur->set_platform_type(WINDOWS_PLATFORM); | |
| 346 lur->set_threat_entry_type(URL); | |
| 347 lur->set_threat_type(MALWARE_THREAT); | |
| 348 ThreatEntrySet* additions = lur->add_additions(); | |
| 349 additions->set_compression_type(RAW); | |
| 350 additions->mutable_raw_hashes()->set_prefix_size(5); | |
| 351 additions->mutable_raw_hashes()->set_raw_hashes("00000abcde"); | |
| 352 additions = lur->add_additions(); | |
| 353 additions->set_compression_type(RAW); | |
| 354 additions->mutable_raw_hashes()->set_prefix_size(4); | |
| 355 additions->mutable_raw_hashes()->set_raw_hashes("00000abc"); | |
| 356 EXPECT_EQ(WRITE_SUCCESS, | |
| 357 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur))); | |
| 358 | |
| 359 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.
| |
| 360 EXPECT_EQ(READ_SUCCESS, read_store->ReadFromDisk()); | |
| 361 EXPECT_EQ("test_client_state", read_store->state_); | |
| 362 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.
| |
| 363 EXPECT_EQ("00000abc", read_store->hash_prefix_map_[4]); | |
| 364 EXPECT_EQ("00000abcde", read_store->hash_prefix_map_[5]); | |
| 365 } | |
| 366 | |
| 367 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.
| |
| 368 std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse); | |
| 369 lur->set_response_type(ListUpdateResponse::FULL_UPDATE); | |
| 370 lur->set_new_client_state("test_client_state"); | |
| 371 lur->set_platform_type(WINDOWS_PLATFORM); | |
| 372 lur->set_threat_entry_type(URL); | |
| 373 lur->set_threat_type(MALWARE_THREAT); | |
| 374 ThreatEntrySet* additions = lur->add_additions(); | |
| 375 additions->set_compression_type(RAW); | |
| 376 additions->mutable_raw_hashes()->set_prefix_size(5); | |
| 377 additions->mutable_raw_hashes()->set_raw_hashes("abcdef"); | |
| 378 EXPECT_EQ(WRITE_SUCCESS, | |
| 379 V4Store(task_runner_, store_path_).WriteToDisk(std::move(lur))); | |
| 380 | |
| 381 std::unique_ptr<V4Store> read_store(new V4Store(task_runner_, store_path_)); | |
| 382 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.
| |
| 383 EXPECT_TRUE(read_store->state_.empty()); | |
| 384 EXPECT_TRUE(read_store->hash_prefix_map_.empty()); | |
| 385 } | |
| 386 | |
| 340 } // namespace safe_browsing | 387 } // namespace safe_browsing |
| OLD | NEW |