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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 EXPECT_FALSE( | 634 EXPECT_FALSE( |
635 v4_local_database_manager_->MatchModuleWhitelistString("badstuff.dll")); | 635 v4_local_database_manager_->MatchModuleWhitelistString("badstuff.dll")); |
636 // Whitelisted. | 636 // Whitelisted. |
637 EXPECT_TRUE( | 637 EXPECT_TRUE( |
638 v4_local_database_manager_->MatchModuleWhitelistString("chrome.dll")); | 638 v4_local_database_manager_->MatchModuleWhitelistString("chrome.dll")); |
639 | 639 |
640 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( | 640 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( |
641 v4_local_database_manager_)); | 641 v4_local_database_manager_)); |
642 } | 642 } |
643 | 643 |
| 644 // This verifies the fix for race in http://crbug.com/660293 |
| 645 TEST_F(V4LocalDatabaseManagerTest, TestCheckBrowseUrlWithSameClientAndCancel) { |
| 646 ScopedFakeGetHashProtocolManagerFactory pin; |
| 647 // Reset the database manager so it picks up the replacement protocol manager. |
| 648 ResetLocalDatabaseManager(); |
| 649 WaitForTasksOnTaskRunner(); |
| 650 |
| 651 StoreAndHashPrefixes store_and_hash_prefixes; |
| 652 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), |
| 653 HashPrefix("sن\340\t\006_")); |
| 654 ReplaceV4Database(store_and_hash_prefixes); |
| 655 |
| 656 GURL first_url("http://example.com/a"); |
| 657 GURL second_url("http://example.com/"); |
| 658 TestClient client(SB_THREAT_TYPE_SAFE, first_url); |
| 659 // The fake database returns a matched hash prefix. |
| 660 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(first_url, &client)); |
| 661 |
| 662 // That check gets queued. Now, let's cancel the check. After this, we should |
| 663 // not receive a call for |OnCheckBrowseUrlResult| with |first_url|. |
| 664 v4_local_database_manager_->CancelCheck(&client); |
| 665 |
| 666 // Now, re-use that client but for |second_url|. |
| 667 client.expected_url = second_url; |
| 668 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(second_url, &client)); |
| 669 |
| 670 // Wait for PerformFullHashCheck to complete. |
| 671 WaitForTasksOnTaskRunner(); |
| 672 // |result_received_| is true only if OnCheckBrowseUrlResult gets called with |
| 673 // the |url| equal to |expected_url|, which is |second_url| in this test. |
| 674 EXPECT_TRUE(client.result_received_); |
| 675 } |
| 676 |
644 // TODO(nparker): Add tests for | 677 // TODO(nparker): Add tests for |
645 // CheckDownloadUrl() | 678 // CheckDownloadUrl() |
646 // CheckExtensionIDs() | 679 // CheckExtensionIDs() |
647 // CheckResourceUrl() | 680 // CheckResourceUrl() |
648 | 681 |
649 } // namespace safe_browsing | 682 } // namespace safe_browsing |
OLD | NEW |