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

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager_unittest.cc

Issue 2616653002: Have a list of pending checks instead of pending clients (Closed)
Patch Set: git rebase manually! ugh. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « components/safe_browsing_db/v4_local_database_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_local_database_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698