Chromium Code Reviews| Index: components/safe_browsing_db/v4_local_database_manager_unittest.cc |
| diff --git a/components/safe_browsing_db/v4_local_database_manager_unittest.cc b/components/safe_browsing_db/v4_local_database_manager_unittest.cc |
| index d8f3a3c317bf983dcae56f5948a53713405651ec..a410a406914878be3b661456d76d9e462964775c 100644 |
| --- a/components/safe_browsing_db/v4_local_database_manager_unittest.cc |
| +++ b/components/safe_browsing_db/v4_local_database_manager_unittest.cc |
| @@ -7,7 +7,9 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/run_loop.h" |
| #include "base/test/test_simple_task_runner.h" |
| +#include "base/time/time.h" |
| #include "components/safe_browsing_db/v4_database.h" |
| +#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| #include "components/safe_browsing_db/v4_local_database_manager.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "testing/platform_test.h" |
| @@ -33,6 +35,30 @@ class FakeV4Database : public V4Database { |
| const MatchedHashPrefixMap& matched_hash_prefix_map_; |
| }; |
| +class FakeV4GetHashProtocolManager : public V4GetHashProtocolManager { |
| + public: |
| + FakeV4GetHashProtocolManager( |
| + net::URLRequestContextGetter* request_context_getter, |
| + const V4ProtocolConfig& config, |
| + const std::vector<SBFullHashResult>& full_hash_results, |
| + const base::Time& negative_cache_expire) |
| + : V4GetHashProtocolManager(request_context_getter, config), |
| + full_hash_results_(full_hash_results), |
| + negative_cache_expire_(negative_cache_expire) {} |
| + |
| + void GetFullHashes(const base::hash_set<HashPrefix>& prefixes, |
| + const PlatformTypeSet& platforms, |
| + const ThreatEntryTypeSet& threat_entry_types, |
| + const ThreatTypeSet& threat_types, |
| + FullHashCallback callback) override { |
| + callback.Run(full_hash_results_, negative_cache_expire_); |
| + } |
| + |
| + private: |
| + std::vector<SBFullHashResult> full_hash_results_; |
| + base::Time negative_cache_expire_; |
| +}; |
| + |
| class V4LocalDatabaseManagerTest : public PlatformTest { |
| public: |
| V4LocalDatabaseManagerTest() : task_runner_(new base::TestSimpleTaskRunner) {} |
| @@ -72,6 +98,17 @@ class V4LocalDatabaseManagerTest : public PlatformTest { |
| task_runner_, base::MakeUnique<StoreMap>(), matched_hash_prefix_map)); |
| } |
| + void ReplaceV4GetHashProtocolManager( |
| + net::URLRequestContextGetter* request_context_getter, |
| + const std::vector<SBFullHashResult>& full_hash_results, |
| + const base::Time& negative_cache_expire) { |
| + V4ProtocolConfig config; |
| + v4_local_database_manager_->v4_get_hash_protocol_manager_.reset( |
| + new FakeV4GetHashProtocolManager(request_context_getter, config, |
| + full_hash_results, |
| + negative_cache_expire)); |
| + } |
| + |
| void ForceDisableLocalDatabaseManager() { |
| v4_local_database_manager_->enabled_ = false; |
| } |
| @@ -114,6 +151,10 @@ TEST_F(V4LocalDatabaseManagerTest, TestCheckBrowseUrlWithFakeDbReturnsMatch) { |
| matched_hash_prefix_map[GetUrlMalwareId()] = HashPrefix("aaaa"); |
| ReplaceV4Database(matched_hash_prefix_map); |
| + std::vector<SBFullHashResult> full_hash_results; |
| + ReplaceV4GetHashProtocolManager(nullptr, full_hash_results, |
| + base::Time::Now()); |
|
Scott Hess - ex-Googler
2016/08/23 20:25:46
Will full_hash_results acquire contents later? Ot
|
| + |
| // The fake database returns a matched hash prefix. |
| EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl( |
| GURL("http://example.com/a/"), nullptr)); |