| 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/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // v4_local_database_manager_ is enabled. | 360 // v4_local_database_manager_ is enabled. |
| 361 ForceDisableLocalDatabaseManager(); | 361 ForceDisableLocalDatabaseManager(); |
| 362 | 362 |
| 363 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( | 363 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( |
| 364 GURL("http://example.com/a/"), nullptr)); | 364 GURL("http://example.com/a/"), nullptr)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(V4LocalDatabaseManagerTest, TestGetSeverestThreatTypeAndMetadata) { | 367 TEST_F(V4LocalDatabaseManagerTest, TestGetSeverestThreatTypeAndMetadata) { |
| 368 WaitForTasksOnTaskRunner(); | 368 WaitForTasksOnTaskRunner(); |
| 369 | 369 |
| 370 FullHashInfo fhi_malware(FullHash("Malware"), GetUrlMalwareId(), | 370 FullHash full_hash("Malware"); |
| 371 base::Time::Now()); | 371 FullHashInfo fhi_malware(full_hash, GetUrlMalwareId(), base::Time::Now()); |
| 372 fhi_malware.metadata.population_id = "malware_popid"; | 372 fhi_malware.metadata.population_id = "malware_popid"; |
| 373 | 373 |
| 374 FullHashInfo fhi_api(FullHash("api"), GetChromeUrlApiId(), base::Time::Now()); | 374 FullHashInfo fhi_api(FullHash("api"), GetChromeUrlApiId(), base::Time::Now()); |
| 375 fhi_api.metadata.population_id = "api_popid"; | 375 fhi_api.metadata.population_id = "api_popid"; |
| 376 | 376 |
| 377 std::vector<FullHashInfo> fhis({fhi_malware, fhi_api}); | 377 std::vector<FullHashInfo> fhis({fhi_malware, fhi_api}); |
| 378 | 378 |
| 379 SBThreatType result_threat_type; | 379 SBThreatType result_threat_type; |
| 380 ThreatMetadata metadata; | 380 ThreatMetadata metadata; |
| 381 FullHash matching_full_hash; |
| 381 | 382 |
| 382 v4_local_database_manager_->GetSeverestThreatTypeAndMetadata( | 383 v4_local_database_manager_->GetSeverestThreatTypeAndMetadata( |
| 383 &result_threat_type, &metadata, fhis); | 384 &result_threat_type, &metadata, &matching_full_hash, fhis); |
| 384 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, result_threat_type); | 385 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, result_threat_type); |
| 385 EXPECT_EQ("malware_popid", metadata.population_id); | 386 EXPECT_EQ("malware_popid", metadata.population_id); |
| 387 EXPECT_EQ(full_hash, matching_full_hash); |
| 386 | 388 |
| 387 // Reversing the list has no effect. | 389 // Reversing the list has no effect. |
| 388 std::reverse(std::begin(fhis), std::end(fhis)); | 390 std::reverse(std::begin(fhis), std::end(fhis)); |
| 389 v4_local_database_manager_->GetSeverestThreatTypeAndMetadata( | 391 v4_local_database_manager_->GetSeverestThreatTypeAndMetadata( |
| 390 &result_threat_type, &metadata, fhis); | 392 &result_threat_type, &metadata, &matching_full_hash, fhis); |
| 391 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, result_threat_type); | 393 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, result_threat_type); |
| 392 EXPECT_EQ("malware_popid", metadata.population_id); | 394 EXPECT_EQ("malware_popid", metadata.population_id); |
| 395 EXPECT_EQ(full_hash, matching_full_hash); |
| 393 } | 396 } |
| 394 | 397 |
| 395 TEST_F(V4LocalDatabaseManagerTest, TestChecksAreQueued) { | 398 TEST_F(V4LocalDatabaseManagerTest, TestChecksAreQueued) { |
| 396 const GURL url("https://www.example.com/"); | 399 const GURL url("https://www.example.com/"); |
| 397 TestClient client(SB_THREAT_TYPE_SAFE, url); | 400 TestClient client(SB_THREAT_TYPE_SAFE, url); |
| 398 EXPECT_TRUE(GetQueuedChecks().empty()); | 401 EXPECT_TRUE(GetQueuedChecks().empty()); |
| 399 v4_local_database_manager_->CheckBrowseUrl(url, &client); | 402 v4_local_database_manager_->CheckBrowseUrl(url, &client); |
| 400 // The database is unavailable so the check should get queued. | 403 // The database is unavailable so the check should get queued. |
| 401 EXPECT_EQ(1ul, GetQueuedChecks().size()); | 404 EXPECT_EQ(1ul, GetQueuedChecks().size()); |
| 402 | 405 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 // the |url| equal to |expected_url|, which is |second_url| in this test. | 676 // the |url| equal to |expected_url|, which is |second_url| in this test. |
| 674 EXPECT_TRUE(client.result_received_); | 677 EXPECT_TRUE(client.result_received_); |
| 675 } | 678 } |
| 676 | 679 |
| 677 // TODO(nparker): Add tests for | 680 // TODO(nparker): Add tests for |
| 678 // CheckDownloadUrl() | 681 // CheckDownloadUrl() |
| 679 // CheckExtensionIDs() | 682 // CheckExtensionIDs() |
| 680 // CheckResourceUrl() | 683 // CheckResourceUrl() |
| 681 | 684 |
| 682 } // namespace safe_browsing | 685 } // namespace safe_browsing |
| OLD | NEW |