Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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_TEST_SAFE_BROWSING_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ | |
| 7 | |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 9 | |
| 10 #include "chrome/browser/safe_browsing/protocol_manager.h" | |
| 11 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" | |
| 12 #include "chrome/browser/safe_browsing/ui_manager.h" | |
| 13 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | |
| 14 | |
| 15 namespace safe_browsing { | |
| 16 struct SafeBrowsingProtocolConfig; | |
| 17 class SafeBrowsingDatabaseManager; | |
| 18 class SafeBrowsingPingManager; | |
| 19 class SafeBrowsingProtocolManager; | |
| 20 struct V4ProtocolConfig; | |
| 21 class TestSafeBrowsingDatabaseManager; | |
| 22 class TestSafeBrowsingUIManager; | |
| 23 | |
| 24 // TestSafeBrowsingService and its factory provides a flexible way to configure | |
| 25 // customized safe browsing UI manager, database manager, protocol manager, | |
| 26 // and etc without the need of override SafeBrowsingService in tests over and | |
| 27 // over again. | |
| 28 // | |
| 29 // How to configure TestSafeBrowsingService in browser tests set up? | |
| 30 // * When overriding SetUp(): | |
| 31 // (1) create an instance of TestSafeBrowsingServiceFactory ( | |
| 32 // e.g. test_sb_factory_), | |
| 33 // (2) Set up necessary test components by calling | |
| 34 // test_sb_factory_->SetTest[DatabaseManager/UIManager/...](...), | |
| 35 // (3) Register TestSafeBrowsingServiceFactory | |
| 36 // SafeBrowsingService::RegisterFactory(test_sb_factory_); | |
| 37 // (4) InProcessBrowserTest::SetUp() or other base class SetUp() function must | |
| 38 // be called at last. | |
| 39 // * When overriding TearDown(): | |
| 40 // Call base class TearDown() first then call | |
| 41 // SafeBrowsingService::RegisterFactory(nullptr) to unregister | |
| 42 // test_sb_factory_. | |
| 43 class TestSafeBrowsingService : public SafeBrowsingService { | |
| 44 public: | |
| 45 TestSafeBrowsingService(); | |
| 46 // SafeBrowsingService overrides | |
| 47 SafeBrowsingProtocolConfig GetProtocolConfig() const override; | |
| 48 V4ProtocolConfig GetV4ProtocolConfig() const override; | |
| 49 | |
| 50 std::string serilized_download_report(); | |
| 51 void ClearDownloadReport(); | |
| 52 | |
| 53 // In browser tests, the following setters must be called before | |
| 54 // SafeBrowsingService::Initialize(). | |
| 55 // The preferable way to use these setters is by calling corresponding | |
| 56 // TestSafeBrowsingServiceFactory::SetTest[DatabaseManager/UIManager/ | |
| 57 // ProtocolConfig]() before InProcessBrowserTest::SetUp() is called. Then | |
| 58 // inside TestSafeBrowsingServiceFactory::CreateSafeBrowsingService(), | |
| 59 // TestSafeBrowsingService instance is created, customised(by using the | |
| 60 // following setters), and then initialized. | |
| 61 void SetUIManager(TestSafeBrowsingUIManager* ui_manager); | |
| 62 void SetDatabaseManager(TestSafeBrowsingDatabaseManager* database_manager); | |
| 63 void SetProtocolConfig(SafeBrowsingProtocolConfig* protocol_config); | |
| 64 void SetV4ProtocolConfig(V4ProtocolConfig* v4_protocol_config); | |
|
asanka
2016/05/18 17:08:47
At the moment we have two sets of SB satellite ser
Jialiu Lin
2016/05/18 19:06:55
I tried to consolidate these two cases, but found
| |
| 65 | |
| 66 protected: | |
| 67 // SafeBrowsingService overrides | |
| 68 ~TestSafeBrowsingService() override; | |
| 69 SafeBrowsingDatabaseManager* CreateDatabaseManager() override; | |
| 70 SafeBrowsingUIManager* CreateUIManager() override; | |
| 71 SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate() override; | |
| 72 void SendSerializedDownloadReport(const std::string& report) override; | |
| 73 | |
| 74 private: | |
| 75 bool protocol_manager_delegate_disabled_; | |
| 76 std::unique_ptr<SafeBrowsingProtocolConfig> protocol_config_; | |
| 77 std::unique_ptr<V4ProtocolConfig> v4_protocol_config_; | |
| 78 std::string serialized_download_report_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingService); | |
| 81 }; | |
| 82 | |
| 83 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { | |
| 84 public: | |
| 85 TestSafeBrowsingServiceFactory(); | |
| 86 ~TestSafeBrowsingServiceFactory() override; | |
| 87 | |
| 88 // Creates test safe browsing service, and configures test UI manager, | |
| 89 // database manager and so on. | |
| 90 SafeBrowsingService* CreateSafeBrowsingService() override; | |
| 91 | |
| 92 TestSafeBrowsingService* test_safe_browsing_service(); | |
| 93 | |
| 94 // Test UI manager, database manager and protocol config need to be set before | |
| 95 // SafeBrowsingService::Initialize() is called. | |
| 96 void SetTestUIManager(TestSafeBrowsingUIManager* ui_manager); | |
| 97 void SetTestDatabaseManager( | |
| 98 TestSafeBrowsingDatabaseManager* database_manager); | |
| 99 void SetTestProtocolConfig(const SafeBrowsingProtocolConfig& protocol_config); | |
| 100 | |
| 101 private: | |
| 102 TestSafeBrowsingService* test_safe_browsing_service_; | |
| 103 scoped_refptr<TestSafeBrowsingDatabaseManager> test_database_manager_; | |
| 104 scoped_refptr<TestSafeBrowsingUIManager> test_ui_manager_; | |
| 105 SafeBrowsingProtocolConfig* test_protocol_config_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingServiceFactory); | |
| 108 }; | |
| 109 | |
| 110 // This is an implemenation of SafeBrowsingUIManager without actually | |
| 111 // sending report to safe browsing backend. Safe browsing reports are | |
| 112 // stored in strings for easy verification. | |
| 113 class TestSafeBrowsingUIManager : public SafeBrowsingUIManager { | |
| 114 public: | |
| 115 TestSafeBrowsingUIManager(); | |
| 116 explicit TestSafeBrowsingUIManager( | |
| 117 const scoped_refptr<SafeBrowsingService>& service); | |
| 118 void SendSerializedThreatDetails(const std::string& serialized) override; | |
| 119 void SetSafeBrowsingService(SafeBrowsingService* sb_service); | |
| 120 std::list<std::string>* GetThreatDetails(); | |
| 121 | |
| 122 protected: | |
| 123 ~TestSafeBrowsingUIManager() override; | |
| 124 std::list<std::string> details_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingUIManager); | |
| 127 }; | |
| 128 | |
| 129 } // namespace safe_browsing | |
| 130 | |
| 131 #endif // CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ | |
| OLD | NEW |