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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/debug/leak_annotations.h" | 6 #include "base/debug/leak_annotations.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 void RegisterFactory(bool fails_first_reset, | 100 void RegisterFactory(bool fails_first_reset, |
101 bool hash_prefix_matches = true) { | 101 bool hash_prefix_matches = true) { |
102 factory_.reset( | 102 factory_.reset( |
103 new FakeV4StoreFactory(fails_first_reset, hash_prefix_matches)); | 103 new FakeV4StoreFactory(fails_first_reset, hash_prefix_matches)); |
104 V4Database::RegisterStoreFactoryForTest(factory_.get()); | 104 V4Database::RegisterStoreFactoryForTest(factory_.get()); |
105 } | 105 } |
106 | 106 |
107 void SetupInfoMapAndExpectedState() { | 107 void SetupInfoMapAndExpectedState() { |
108 store_id_file_names_.emplace_back(win_malware_id_, "win_url_malware"); | 108 list_infos_.emplace_back(win_malware_id_, "win_url_malware", |
| 109 SB_THREAT_TYPE_URL_MALWARE, true); |
109 expected_identifiers_.push_back(win_malware_id_); | 110 expected_identifiers_.push_back(win_malware_id_); |
110 expected_store_paths_.push_back( | 111 expected_store_paths_.push_back( |
111 database_dirname_.AppendASCII("win_url_malware.fake")); | 112 database_dirname_.AppendASCII("win_url_malware.fake")); |
112 | 113 |
113 store_id_file_names_.emplace_back(linux_malware_id_, "linux_url_malware"); | 114 list_infos_.emplace_back(linux_malware_id_, "linux_url_malware", |
| 115 SB_THREAT_TYPE_URL_MALWARE, true); |
114 expected_identifiers_.push_back(linux_malware_id_); | 116 expected_identifiers_.push_back(linux_malware_id_); |
115 expected_store_paths_.push_back( | 117 expected_store_paths_.push_back( |
116 database_dirname_.AppendASCII("linux_url_malware.fake")); | 118 database_dirname_.AppendASCII("linux_url_malware.fake")); |
117 } | 119 } |
118 | 120 |
119 void DatabaseUpdated() {} | 121 void DatabaseUpdated() {} |
120 void NewDatabaseReadyWithExpectedStorePathsAndIds( | 122 void NewDatabaseReadyWithExpectedStorePathsAndIds( |
121 std::unique_ptr<V4Database> v4_database) { | 123 std::unique_ptr<V4Database> v4_database) { |
122 ASSERT_TRUE(v4_database); | 124 ASSERT_TRUE(v4_database); |
123 ASSERT_TRUE(v4_database->store_map_); | 125 ASSERT_TRUE(v4_database->store_map_); |
(...skipping 20 matching lines...) Expand all Loading... |
144 } | 146 } |
145 | 147 |
146 std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse( | 148 std::unique_ptr<ParsedServerResponse> CreateFakeServerResponse( |
147 StoreStateMap store_state_map, | 149 StoreStateMap store_state_map, |
148 bool use_valid_response_type) { | 150 bool use_valid_response_type) { |
149 std::unique_ptr<ParsedServerResponse> parsed_server_response( | 151 std::unique_ptr<ParsedServerResponse> parsed_server_response( |
150 new ParsedServerResponse); | 152 new ParsedServerResponse); |
151 for (const auto& store_state_iter : store_state_map) { | 153 for (const auto& store_state_iter : store_state_map) { |
152 ListIdentifier identifier = store_state_iter.first; | 154 ListIdentifier identifier = store_state_iter.first; |
153 ListUpdateResponse* lur = new ListUpdateResponse; | 155 ListUpdateResponse* lur = new ListUpdateResponse; |
154 lur->set_platform_type(identifier.platform_type); | 156 lur->set_platform_type(identifier.platform_type()); |
155 lur->set_threat_entry_type(identifier.threat_entry_type); | 157 lur->set_threat_entry_type(identifier.threat_entry_type()); |
156 lur->set_threat_type(identifier.threat_type); | 158 lur->set_threat_type(identifier.threat_type()); |
157 lur->set_new_client_state(store_state_iter.second); | 159 lur->set_new_client_state(store_state_iter.second); |
158 if (use_valid_response_type) { | 160 if (use_valid_response_type) { |
159 lur->set_response_type(ListUpdateResponse::FULL_UPDATE); | 161 lur->set_response_type(ListUpdateResponse::FULL_UPDATE); |
160 } else { | 162 } else { |
161 lur->set_response_type(ListUpdateResponse::RESPONSE_TYPE_UNSPECIFIED); | 163 lur->set_response_type(ListUpdateResponse::RESPONSE_TYPE_UNSPECIFIED); |
162 } | 164 } |
163 parsed_server_response->push_back(base::WrapUnique(lur)); | 165 parsed_server_response->push_back(base::WrapUnique(lur)); |
164 } | 166 } |
165 return parsed_server_response; | 167 return parsed_server_response; |
166 } | 168 } |
(...skipping 26 matching lines...) Expand all Loading... |
193 } | 195 } |
194 } | 196 } |
195 | 197 |
196 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 198 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
197 std::unique_ptr<V4Database> v4_database_; | 199 std::unique_ptr<V4Database> v4_database_; |
198 base::FilePath database_dirname_; | 200 base::FilePath database_dirname_; |
199 base::ScopedTempDir temp_dir_; | 201 base::ScopedTempDir temp_dir_; |
200 content::TestBrowserThreadBundle thread_bundle_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
201 bool created_but_not_called_back_; | 203 bool created_but_not_called_back_; |
202 bool created_and_called_back_; | 204 bool created_and_called_back_; |
203 StoreIdAndFileNames store_id_file_names_; | 205 ListInfos list_infos_; |
204 std::vector<ListIdentifier> expected_identifiers_; | 206 std::vector<ListIdentifier> expected_identifiers_; |
205 std::vector<base::FilePath> expected_store_paths_; | 207 std::vector<base::FilePath> expected_store_paths_; |
206 bool expected_resets_successfully_; | 208 bool expected_resets_successfully_; |
207 std::unique_ptr<FakeV4StoreFactory> factory_; | 209 std::unique_ptr<FakeV4StoreFactory> factory_; |
208 DatabaseUpdatedCallback callback_db_updated_; | 210 DatabaseUpdatedCallback callback_db_updated_; |
209 NewDatabaseReadyCallback callback_db_ready_; | 211 NewDatabaseReadyCallback callback_db_ready_; |
210 StoreStateMap expected_store_state_map_; | 212 StoreStateMap expected_store_state_map_; |
211 base::hash_map<ListIdentifier, V4Store*> old_stores_map_; | 213 base::hash_map<ListIdentifier, V4Store*> old_stores_map_; |
212 const ListIdentifier linux_malware_id_, win_malware_id_; | 214 const ListIdentifier linux_malware_id_, win_malware_id_; |
213 }; | 215 }; |
214 | 216 |
215 // Test to set up the database with fake stores. | 217 // Test to set up the database with fake stores. |
216 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStores) { | 218 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStores) { |
217 expected_resets_successfully_ = true; | 219 expected_resets_successfully_ = true; |
218 RegisterFactory(!expected_resets_successfully_); | 220 RegisterFactory(!expected_resets_successfully_); |
219 | 221 |
220 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 222 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
221 callback_db_ready_); | 223 callback_db_ready_); |
222 created_but_not_called_back_ = true; | 224 created_but_not_called_back_ = true; |
223 task_runner_->RunPendingTasks(); | 225 task_runner_->RunPendingTasks(); |
224 | 226 |
225 base::RunLoop().RunUntilIdle(); | 227 base::RunLoop().RunUntilIdle(); |
226 EXPECT_EQ(true, created_and_called_back_); | 228 EXPECT_EQ(true, created_and_called_back_); |
227 } | 229 } |
228 | 230 |
229 // Test to set up the database with fake stores that fail to reset. | 231 // Test to set up the database with fake stores that fail to reset. |
230 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStoresFailsReset) { | 232 TEST_F(V4DatabaseTest, TestSetupDatabaseWithFakeStoresFailsReset) { |
231 expected_resets_successfully_ = false; | 233 expected_resets_successfully_ = false; |
232 RegisterFactory(!expected_resets_successfully_); | 234 RegisterFactory(!expected_resets_successfully_); |
233 | 235 |
234 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 236 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
235 callback_db_ready_); | 237 callback_db_ready_); |
236 created_but_not_called_back_ = true; | 238 created_but_not_called_back_ = true; |
237 task_runner_->RunPendingTasks(); | 239 task_runner_->RunPendingTasks(); |
238 | 240 |
239 base::RunLoop().RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
240 EXPECT_EQ(true, created_and_called_back_); | 242 EXPECT_EQ(true, created_and_called_back_); |
241 } | 243 } |
242 | 244 |
243 // Test to check database updates as expected. | 245 // Test to check database updates as expected. |
244 TEST_F(V4DatabaseTest, TestApplyUpdateWithNewStates) { | 246 TEST_F(V4DatabaseTest, TestApplyUpdateWithNewStates) { |
245 expected_resets_successfully_ = true; | 247 expected_resets_successfully_ = true; |
246 RegisterFactory(!expected_resets_successfully_); | 248 RegisterFactory(!expected_resets_successfully_); |
247 | 249 |
248 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 250 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
249 callback_db_ready_); | 251 callback_db_ready_); |
250 created_but_not_called_back_ = true; | 252 created_but_not_called_back_ = true; |
251 task_runner_->RunPendingTasks(); | 253 task_runner_->RunPendingTasks(); |
252 base::RunLoop().RunUntilIdle(); | 254 base::RunLoop().RunUntilIdle(); |
253 | 255 |
254 // The database has now been created. Time to try to update it. | 256 // The database has now been created. Time to try to update it. |
255 EXPECT_TRUE(v4_database_); | 257 EXPECT_TRUE(v4_database_); |
256 const StoreMap* db_stores = v4_database_->store_map_.get(); | 258 const StoreMap* db_stores = v4_database_->store_map_.get(); |
257 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); | 259 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); |
258 for (const auto& store_iter : *db_stores) { | 260 for (const auto& store_iter : *db_stores) { |
(...skipping 10 matching lines...) Expand all Loading... |
269 base::RunLoop().RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
270 | 272 |
271 VerifyExpectedStoresState(true); | 273 VerifyExpectedStoresState(true); |
272 } | 274 } |
273 | 275 |
274 // Test to ensure no state updates leads to no store updates. | 276 // Test to ensure no state updates leads to no store updates. |
275 TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) { | 277 TEST_F(V4DatabaseTest, TestApplyUpdateWithNoNewState) { |
276 expected_resets_successfully_ = true; | 278 expected_resets_successfully_ = true; |
277 RegisterFactory(!expected_resets_successfully_); | 279 RegisterFactory(!expected_resets_successfully_); |
278 | 280 |
279 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 281 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
280 callback_db_ready_); | 282 callback_db_ready_); |
281 created_but_not_called_back_ = true; | 283 created_but_not_called_back_ = true; |
282 task_runner_->RunPendingTasks(); | 284 task_runner_->RunPendingTasks(); |
283 base::RunLoop().RunUntilIdle(); | 285 base::RunLoop().RunUntilIdle(); |
284 | 286 |
285 // The database has now been created. Time to try to update it. | 287 // The database has now been created. Time to try to update it. |
286 EXPECT_TRUE(v4_database_); | 288 EXPECT_TRUE(v4_database_); |
287 const StoreMap* db_stores = v4_database_->store_map_.get(); | 289 const StoreMap* db_stores = v4_database_->store_map_.get(); |
288 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); | 290 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); |
289 for (const auto& store_iter : *db_stores) { | 291 for (const auto& store_iter : *db_stores) { |
(...skipping 10 matching lines...) Expand all Loading... |
300 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
301 | 303 |
302 VerifyExpectedStoresState(false); | 304 VerifyExpectedStoresState(false); |
303 } | 305 } |
304 | 306 |
305 // Test to ensure no updates leads to no store updates. | 307 // Test to ensure no updates leads to no store updates. |
306 TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) { | 308 TEST_F(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate) { |
307 expected_resets_successfully_ = true; | 309 expected_resets_successfully_ = true; |
308 RegisterFactory(!expected_resets_successfully_); | 310 RegisterFactory(!expected_resets_successfully_); |
309 | 311 |
310 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 312 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
311 callback_db_ready_); | 313 callback_db_ready_); |
312 created_but_not_called_back_ = true; | 314 created_but_not_called_back_ = true; |
313 task_runner_->RunPendingTasks(); | 315 task_runner_->RunPendingTasks(); |
314 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
315 | 317 |
316 // The database has now been created. Time to try to update it. | 318 // The database has now been created. Time to try to update it. |
317 EXPECT_TRUE(v4_database_); | 319 EXPECT_TRUE(v4_database_); |
318 const StoreMap* db_stores = v4_database_->store_map_.get(); | 320 const StoreMap* db_stores = v4_database_->store_map_.get(); |
319 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); | 321 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); |
320 for (const auto& store_iter : *db_stores) { | 322 for (const auto& store_iter : *db_stores) { |
(...skipping 11 matching lines...) Expand all Loading... |
332 base::RunLoop().RunUntilIdle(); | 334 base::RunLoop().RunUntilIdle(); |
333 | 335 |
334 VerifyExpectedStoresState(false); | 336 VerifyExpectedStoresState(false); |
335 } | 337 } |
336 | 338 |
337 // Test to ensure invalid update leads to no store changes. | 339 // Test to ensure invalid update leads to no store changes. |
338 TEST_F(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate) { | 340 TEST_F(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate) { |
339 expected_resets_successfully_ = true; | 341 expected_resets_successfully_ = true; |
340 RegisterFactory(!expected_resets_successfully_); | 342 RegisterFactory(!expected_resets_successfully_); |
341 | 343 |
342 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 344 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
343 callback_db_ready_); | 345 callback_db_ready_); |
344 created_but_not_called_back_ = true; | 346 created_but_not_called_back_ = true; |
345 task_runner_->RunPendingTasks(); | 347 task_runner_->RunPendingTasks(); |
346 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
347 | 349 |
348 // The database has now been created. Time to try to update it. | 350 // The database has now been created. Time to try to update it. |
349 EXPECT_TRUE(v4_database_); | 351 EXPECT_TRUE(v4_database_); |
350 const StoreMap* db_stores = v4_database_->store_map_.get(); | 352 const StoreMap* db_stores = v4_database_->store_map_.get(); |
351 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); | 353 EXPECT_EQ(expected_store_paths_.size(), db_stores->size()); |
352 for (const auto& store_iter : *db_stores) { | 354 for (const auto& store_iter : *db_stores) { |
(...skipping 10 matching lines...) Expand all Loading... |
363 | 365 |
364 VerifyExpectedStoresState(false); | 366 VerifyExpectedStoresState(false); |
365 } | 367 } |
366 | 368 |
367 // Test to ensure the case that all stores match a given full hash. | 369 // Test to ensure the case that all stores match a given full hash. |
368 TEST_F(V4DatabaseTest, TestAllStoresMatchFullHash) { | 370 TEST_F(V4DatabaseTest, TestAllStoresMatchFullHash) { |
369 bool hash_prefix_matches = true; | 371 bool hash_prefix_matches = true; |
370 expected_resets_successfully_ = true; | 372 expected_resets_successfully_ = true; |
371 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); | 373 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); |
372 | 374 |
373 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 375 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
374 callback_db_ready_); | 376 callback_db_ready_); |
375 created_but_not_called_back_ = true; | 377 created_but_not_called_back_ = true; |
376 task_runner_->RunPendingTasks(); | 378 task_runner_->RunPendingTasks(); |
377 | 379 |
378 base::RunLoop().RunUntilIdle(); | 380 base::RunLoop().RunUntilIdle(); |
379 EXPECT_EQ(true, created_and_called_back_); | 381 EXPECT_EQ(true, created_and_called_back_); |
380 | 382 |
381 std::unordered_set<ListIdentifier> stores_to_look( | 383 std::unordered_set<ListIdentifier> stores_to_look( |
382 {linux_malware_id_, win_malware_id_}); | 384 {linux_malware_id_, win_malware_id_}); |
383 StoreAndHashPrefixes store_and_hash_prefixes; | 385 StoreAndHashPrefixes store_and_hash_prefixes; |
384 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, | 386 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, |
385 &store_and_hash_prefixes); | 387 &store_and_hash_prefixes); |
386 EXPECT_EQ(2u, store_and_hash_prefixes.size()); | 388 EXPECT_EQ(2u, store_and_hash_prefixes.size()); |
387 std::unordered_set<ListIdentifier> stores_found; | 389 std::unordered_set<ListIdentifier> stores_found; |
388 for (const auto& it : store_and_hash_prefixes) { | 390 for (const auto& it : store_and_hash_prefixes) { |
389 stores_found.insert(it.list_id); | 391 stores_found.insert(it.list_id); |
390 } | 392 } |
391 EXPECT_EQ(stores_to_look, stores_found); | 393 EXPECT_EQ(stores_to_look, stores_found); |
392 } | 394 } |
393 | 395 |
394 // Test to ensure the case that no stores match a given full hash. | 396 // Test to ensure the case that no stores match a given full hash. |
395 TEST_F(V4DatabaseTest, TestNoStoreMatchesFullHash) { | 397 TEST_F(V4DatabaseTest, TestNoStoreMatchesFullHash) { |
396 bool hash_prefix_matches = false; | 398 bool hash_prefix_matches = false; |
397 expected_resets_successfully_ = true; | 399 expected_resets_successfully_ = true; |
398 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); | 400 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); |
399 | 401 |
400 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 402 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
401 callback_db_ready_); | 403 callback_db_ready_); |
402 created_but_not_called_back_ = true; | 404 created_but_not_called_back_ = true; |
403 task_runner_->RunPendingTasks(); | 405 task_runner_->RunPendingTasks(); |
404 | 406 |
405 base::RunLoop().RunUntilIdle(); | 407 base::RunLoop().RunUntilIdle(); |
406 EXPECT_EQ(true, created_and_called_back_); | 408 EXPECT_EQ(true, created_and_called_back_); |
407 | 409 |
408 std::unordered_set<ListIdentifier> stores_to_look( | 410 std::unordered_set<ListIdentifier> stores_to_look( |
409 {linux_malware_id_, win_malware_id_}); | 411 {linux_malware_id_, win_malware_id_}); |
410 StoreAndHashPrefixes store_and_hash_prefixes; | 412 StoreAndHashPrefixes store_and_hash_prefixes; |
411 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, | 413 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, |
412 &store_and_hash_prefixes); | 414 &store_and_hash_prefixes); |
413 EXPECT_TRUE(store_and_hash_prefixes.empty()); | 415 EXPECT_TRUE(store_and_hash_prefixes.empty()); |
414 } | 416 } |
415 | 417 |
416 // Test to ensure the case that some stores match a given full hash. | 418 // Test to ensure the case that some stores match a given full hash. |
417 TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHash) { | 419 TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHash) { |
418 // Setup stores to not match the full hash. | 420 // Setup stores to not match the full hash. |
419 bool hash_prefix_matches = false; | 421 bool hash_prefix_matches = false; |
420 expected_resets_successfully_ = true; | 422 expected_resets_successfully_ = true; |
421 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); | 423 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); |
422 | 424 |
423 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 425 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
424 callback_db_ready_); | 426 callback_db_ready_); |
425 created_but_not_called_back_ = true; | 427 created_but_not_called_back_ = true; |
426 task_runner_->RunPendingTasks(); | 428 task_runner_->RunPendingTasks(); |
427 | 429 |
428 base::RunLoop().RunUntilIdle(); | 430 base::RunLoop().RunUntilIdle(); |
429 EXPECT_EQ(true, created_and_called_back_); | 431 EXPECT_EQ(true, created_and_called_back_); |
430 | 432 |
431 // Set the store corresponding to linux_malware_id_ to match the full hash. | 433 // Set the store corresponding to linux_malware_id_ to match the full hash. |
432 FakeV4Store* store = static_cast<FakeV4Store*>( | 434 FakeV4Store* store = static_cast<FakeV4Store*>( |
433 v4_database_->store_map_->at(win_malware_id_).get()); | 435 v4_database_->store_map_->at(win_malware_id_).get()); |
(...skipping 10 matching lines...) Expand all Loading... |
444 } | 446 } |
445 | 447 |
446 // Test to ensure the case that only some stores are reported to match a given | 448 // Test to ensure the case that only some stores are reported to match a given |
447 // full hash because of stores_to_look. | 449 // full hash because of stores_to_look. |
448 TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHashBecauseOfStoresToMatch) { | 450 TEST_F(V4DatabaseTest, TestSomeStoresMatchFullHashBecauseOfStoresToMatch) { |
449 // Setup all stores to match the full hash. | 451 // Setup all stores to match the full hash. |
450 bool hash_prefix_matches = true; | 452 bool hash_prefix_matches = true; |
451 expected_resets_successfully_ = true; | 453 expected_resets_successfully_ = true; |
452 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); | 454 RegisterFactory(!expected_resets_successfully_, hash_prefix_matches); |
453 | 455 |
454 V4Database::Create(task_runner_, database_dirname_, store_id_file_names_, | 456 V4Database::Create(task_runner_, database_dirname_, list_infos_, |
455 callback_db_ready_); | 457 callback_db_ready_); |
456 created_but_not_called_back_ = true; | 458 created_but_not_called_back_ = true; |
457 task_runner_->RunPendingTasks(); | 459 task_runner_->RunPendingTasks(); |
458 | 460 |
459 base::RunLoop().RunUntilIdle(); | 461 base::RunLoop().RunUntilIdle(); |
460 EXPECT_EQ(true, created_and_called_back_); | 462 EXPECT_EQ(true, created_and_called_back_); |
461 | 463 |
462 std::unordered_set<ListIdentifier> stores_to_look({linux_malware_id_}); | 464 std::unordered_set<ListIdentifier> stores_to_look({linux_malware_id_}); |
463 // Don't add win_malware_id_ to the stores_to_look. | 465 // Don't add win_malware_id_ to the stores_to_look. |
464 StoreAndHashPrefixes store_and_hash_prefixes; | 466 StoreAndHashPrefixes store_and_hash_prefixes; |
465 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, | 467 v4_database_->GetStoresMatchingFullHash("anything", stores_to_look, |
466 &store_and_hash_prefixes); | 468 &store_and_hash_prefixes); |
467 EXPECT_EQ(1u, store_and_hash_prefixes.size()); | 469 EXPECT_EQ(1u, store_and_hash_prefixes.size()); |
468 EXPECT_EQ(store_and_hash_prefixes.begin()->list_id, linux_malware_id_); | 470 EXPECT_EQ(store_and_hash_prefixes.begin()->list_id, linux_malware_id_); |
469 EXPECT_FALSE(store_and_hash_prefixes.begin()->hash_prefix.empty()); | 471 EXPECT_FALSE(store_and_hash_prefixes.begin()->hash_prefix.empty()); |
470 } | 472 } |
471 | 473 |
472 } // namespace safe_browsing | 474 } // namespace safe_browsing |
OLD | NEW |