OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ |
| 7 |
| 8 #include "components/safe_browsing_db/v4_database.h" |
| 9 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 10 |
| 11 namespace safe_browsing { |
| 12 |
| 13 class TestV4Store : public V4Store { |
| 14 public: |
| 15 TestV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 16 const base::FilePath& store_path); |
| 17 |
| 18 bool HasValidData() const override; |
| 19 |
| 20 void MarkPrefixAsBad(HashPrefix prefix); |
| 21 }; |
| 22 |
| 23 class TestV4StoreFactory : public V4StoreFactory { |
| 24 public: |
| 25 V4Store* CreateV4Store( |
| 26 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 27 const base::FilePath& store_path) override; |
| 28 }; |
| 29 |
| 30 class TestV4Database : public V4Database { |
| 31 public: |
| 32 TestV4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 33 std::unique_ptr<StoreMap> store_map); |
| 34 |
| 35 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix); |
| 36 }; |
| 37 |
| 38 class TestV4DatabaseFactory : public V4DatabaseFactory { |
| 39 public: |
| 40 TestV4DatabaseFactory(); |
| 41 |
| 42 std::unique_ptr<V4Database> Create( |
| 43 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 44 std::unique_ptr<StoreMap> store_map) override; |
| 45 |
| 46 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix); |
| 47 |
| 48 private: |
| 49 // Owned by V4LocalDatabaseManager. The following usage is expected: each |
| 50 // test in the test fixture instantiates a new SafebrowsingService instance, |
| 51 // which instantiates a new V4LocalDatabaseManager, which instantiates a new |
| 52 // V4Database using this method so use-after-free isn't possible. |
| 53 TestV4Database* v4_db_; |
| 54 }; |
| 55 |
| 56 class TestV4GetHashProtocolManager : public V4GetHashProtocolManager { |
| 57 public: |
| 58 TestV4GetHashProtocolManager( |
| 59 net::URLRequestContextGetter* request_context_getter, |
| 60 const StoresToCheck& stores_to_check, |
| 61 const V4ProtocolConfig& config); |
| 62 |
| 63 void AddToFullHashCache(FullHashInfo fhi); |
| 64 }; |
| 65 |
| 66 class TestV4GetHashProtocolManagerFactory |
| 67 : public V4GetHashProtocolManagerFactory { |
| 68 public: |
| 69 std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( |
| 70 net::URLRequestContextGetter* request_context_getter, |
| 71 const StoresToCheck& stores_to_check, |
| 72 const V4ProtocolConfig& config) override; |
| 73 |
| 74 void AddToFullHashCache(FullHashInfo fhi) { pm_->AddToFullHashCache(fhi); } |
| 75 |
| 76 private: |
| 77 // Owned by the SafeBrowsingService. |
| 78 TestV4GetHashProtocolManager* pm_; |
| 79 }; |
| 80 |
| 81 // Returns a FullHash for the basic host+path pattern for a given URL after |
| 82 // canonicalization. |
| 83 FullHash GetFullHash(const GURL& url); |
| 84 |
| 85 // Returns FullHashInfo object for the basic host+path pattern for a given URL |
| 86 // after canonicalization. |
| 87 FullHashInfo GetFullHashInfo(const GURL& url, const ListIdentifier& list_id); |
| 88 |
| 89 // Returns a FullHashInfo info for the basic host+path pattern for a given URL |
| 90 // after canonicalization. Also adds metadata information to the FullHashInfo |
| 91 // object. |
| 92 FullHashInfo GetFullHashInfoWithMetadata(const GURL& url, |
| 93 const ListIdentifier& list_id, |
| 94 ThreatPatternType threat_pattern_type); |
| 95 |
| 96 } // namespace safe_browsing |
| 97 |
| 98 #endif // CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ |
OLD | NEW |