| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 8 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 9 | 9 |
| 10 #include "chrome/browser/safe_browsing/protocol_manager.h" | 10 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // (3) Register TestSafeBrowsingServiceFactory | 33 // (3) Register TestSafeBrowsingServiceFactory |
| 34 // SafeBrowsingService::RegisterFactory(test_sb_factory_); | 34 // SafeBrowsingService::RegisterFactory(test_sb_factory_); |
| 35 // (4) InProcessBrowserTest::SetUp() or other base class SetUp() function must | 35 // (4) InProcessBrowserTest::SetUp() or other base class SetUp() function must |
| 36 // be called at last. | 36 // be called at last. |
| 37 // * When overriding TearDown(): | 37 // * When overriding TearDown(): |
| 38 // Call base class TearDown() first then call | 38 // Call base class TearDown() first then call |
| 39 // SafeBrowsingService::RegisterFactory(nullptr) to unregister | 39 // SafeBrowsingService::RegisterFactory(nullptr) to unregister |
| 40 // test_sb_factory_. | 40 // test_sb_factory_. |
| 41 class TestSafeBrowsingService : public SafeBrowsingService { | 41 class TestSafeBrowsingService : public SafeBrowsingService { |
| 42 public: | 42 public: |
| 43 explicit TestSafeBrowsingService( | 43 TestSafeBrowsingService(); |
| 44 V4FeatureList::V4UsageStatus v4_usage_status); | |
| 45 // SafeBrowsingService overrides | 44 // SafeBrowsingService overrides |
| 46 SafeBrowsingProtocolConfig GetProtocolConfig() const override; | 45 SafeBrowsingProtocolConfig GetProtocolConfig() const override; |
| 47 V4ProtocolConfig GetV4ProtocolConfig() const override; | 46 V4ProtocolConfig GetV4ProtocolConfig() const override; |
| 48 | 47 |
| 49 std::string serilized_download_report(); | 48 std::string serilized_download_report(); |
| 50 void ClearDownloadReport(); | 49 void ClearDownloadReport(); |
| 51 | 50 |
| 52 // In browser tests, the following setters must be called before | 51 // In browser tests, the following setters must be called before |
| 53 // SafeBrowsingService::Initialize(). | 52 // SafeBrowsingService::Initialize(). |
| 54 // The preferable way to use these setters is by calling corresponding | 53 // The preferable way to use these setters is by calling corresponding |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 bool protocol_manager_delegate_disabled_; | 73 bool protocol_manager_delegate_disabled_; |
| 75 std::unique_ptr<SafeBrowsingProtocolConfig> protocol_config_; | 74 std::unique_ptr<SafeBrowsingProtocolConfig> protocol_config_; |
| 76 std::unique_ptr<V4ProtocolConfig> v4_protocol_config_; | 75 std::unique_ptr<V4ProtocolConfig> v4_protocol_config_; |
| 77 std::string serialized_download_report_; | 76 std::string serialized_download_report_; |
| 78 | 77 |
| 79 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingService); | 78 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingService); |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { | 81 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { |
| 83 public: | 82 public: |
| 84 explicit TestSafeBrowsingServiceFactory( | 83 TestSafeBrowsingServiceFactory(); |
| 85 V4FeatureList::V4UsageStatus v4_usage_status = | |
| 86 V4FeatureList::V4UsageStatus::V4_DISABLED); | |
| 87 ~TestSafeBrowsingServiceFactory() override; | 84 ~TestSafeBrowsingServiceFactory() override; |
| 88 | 85 |
| 89 // Creates test safe browsing service, and configures test UI manager, | 86 // Creates test safe browsing service, and configures test UI manager, |
| 90 // database manager and so on. | 87 // database manager and so on. |
| 91 SafeBrowsingService* CreateSafeBrowsingService() override; | 88 SafeBrowsingService* CreateSafeBrowsingService() override; |
| 92 | 89 |
| 93 TestSafeBrowsingService* test_safe_browsing_service(); | 90 TestSafeBrowsingService* test_safe_browsing_service(); |
| 94 | 91 |
| 95 // Test UI manager, database manager and protocol config need to be set before | 92 // Test UI manager, database manager and protocol config need to be set before |
| 96 // SafeBrowsingService::Initialize() is called. | 93 // SafeBrowsingService::Initialize() is called. |
| 97 void SetTestUIManager(TestSafeBrowsingUIManager* ui_manager); | 94 void SetTestUIManager(TestSafeBrowsingUIManager* ui_manager); |
| 98 void SetTestDatabaseManager( | 95 void SetTestDatabaseManager( |
| 99 TestSafeBrowsingDatabaseManager* database_manager); | 96 TestSafeBrowsingDatabaseManager* database_manager); |
| 100 void SetTestProtocolConfig(const SafeBrowsingProtocolConfig& protocol_config); | 97 void SetTestProtocolConfig(const SafeBrowsingProtocolConfig& protocol_config); |
| 101 | 98 |
| 102 private: | 99 private: |
| 103 TestSafeBrowsingService* test_safe_browsing_service_; | 100 TestSafeBrowsingService* test_safe_browsing_service_; |
| 104 scoped_refptr<TestSafeBrowsingDatabaseManager> test_database_manager_; | 101 scoped_refptr<TestSafeBrowsingDatabaseManager> test_database_manager_; |
| 105 scoped_refptr<TestSafeBrowsingUIManager> test_ui_manager_; | 102 scoped_refptr<TestSafeBrowsingUIManager> test_ui_manager_; |
| 106 SafeBrowsingProtocolConfig* test_protocol_config_; | 103 SafeBrowsingProtocolConfig* test_protocol_config_; |
| 107 V4FeatureList::V4UsageStatus v4_usage_status_; | |
| 108 | 104 |
| 109 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingServiceFactory); | 105 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingServiceFactory); |
| 110 }; | 106 }; |
| 111 | 107 |
| 112 // This is an implemenation of SafeBrowsingUIManager without actually | 108 // This is an implemenation of SafeBrowsingUIManager without actually |
| 113 // sending report to safe browsing backend. Safe browsing reports are | 109 // sending report to safe browsing backend. Safe browsing reports are |
| 114 // stored in strings for easy verification. | 110 // stored in strings for easy verification. |
| 115 class TestSafeBrowsingUIManager : public SafeBrowsingUIManager { | 111 class TestSafeBrowsingUIManager : public SafeBrowsingUIManager { |
| 116 public: | 112 public: |
| 117 TestSafeBrowsingUIManager(); | 113 TestSafeBrowsingUIManager(); |
| 118 explicit TestSafeBrowsingUIManager( | 114 explicit TestSafeBrowsingUIManager( |
| 119 const scoped_refptr<SafeBrowsingService>& service); | 115 const scoped_refptr<SafeBrowsingService>& service); |
| 120 void SendSerializedThreatDetails(const std::string& serialized) override; | 116 void SendSerializedThreatDetails(const std::string& serialized) override; |
| 121 void SetSafeBrowsingService(SafeBrowsingService* sb_service); | 117 void SetSafeBrowsingService(SafeBrowsingService* sb_service); |
| 122 std::list<std::string>* GetThreatDetails(); | 118 std::list<std::string>* GetThreatDetails(); |
| 123 | 119 |
| 124 protected: | 120 protected: |
| 125 ~TestSafeBrowsingUIManager() override; | 121 ~TestSafeBrowsingUIManager() override; |
| 126 std::list<std::string> details_; | 122 std::list<std::string> details_; |
| 127 | 123 |
| 128 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingUIManager); | 124 DISALLOW_COPY_AND_ASSIGN(TestSafeBrowsingUIManager); |
| 129 }; | 125 }; |
| 130 | 126 |
| 131 } // namespace safe_browsing | 127 } // namespace safe_browsing |
| 132 | 128 |
| 133 #endif // CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ | 129 #endif // CHROME_BROWSER_SAFE_BROWSING_TEST_SAFE_BROWSING_SERVICE_H_ |
| OLD | NEW |