| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
| 6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
| 7 // service. | 7 // service. |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 using content::WebContents; | 49 using content::WebContents; |
| 50 using ::testing::_; | 50 using ::testing::_; |
| 51 using ::testing::Mock; | 51 using ::testing::Mock; |
| 52 using ::testing::StrictMock; | 52 using ::testing::StrictMock; |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 void InvokeFullHashCallback( | 56 void InvokeFullHashCallback( |
| 57 SafeBrowsingProtocolManager::FullHashCallback callback, | 57 SafeBrowsingProtocolManager::FullHashCallback callback, |
| 58 const std::vector<SBFullHashResult>& result) { | 58 const std::vector<SBFullHashResult>& result) { |
| 59 callback.Run(result, true); | 59 callback.Run(result, base::TimeDelta::FromMinutes(45)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 class FakeSafeBrowsingService : public SafeBrowsingService { | 62 class FakeSafeBrowsingService : public SafeBrowsingService { |
| 63 public: | 63 public: |
| 64 explicit FakeSafeBrowsingService(const std::string& url_prefix) | 64 explicit FakeSafeBrowsingService(const std::string& url_prefix) |
| 65 : url_prefix_(url_prefix) {} | 65 : url_prefix_(url_prefix) {} |
| 66 | 66 |
| 67 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const OVERRIDE { | 67 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const OVERRIDE { |
| 68 SafeBrowsingProtocolConfig config; | 68 SafeBrowsingProtocolConfig config; |
| 69 config.url_prefix = url_prefix_; | 69 config.url_prefix = url_prefix_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // Deletes the current database and creates a new one. | 109 // Deletes the current database and creates a new one. |
| 110 virtual bool ResetDatabase() OVERRIDE { | 110 virtual bool ResetDatabase() OVERRIDE { |
| 111 badurls_.clear(); | 111 badurls_.clear(); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Called on the IO thread to check if the given URL is safe or not. If we | 115 // Called on the IO thread to check if the given URL is safe or not. If we |
| 116 // can synchronously determine that the URL is safe, CheckUrl returns true, | 116 // can synchronously determine that the URL is safe, CheckUrl returns true, |
| 117 // otherwise it returns false. | 117 // otherwise it returns false. |
| 118 virtual bool ContainsBrowseUrl(const GURL& url, | 118 virtual bool ContainsBrowseUrl( |
| 119 std::vector<SBPrefix>* prefix_hits, | 119 const GURL& url, |
| 120 std::vector<SBFullHashResult>* cached_hits, | 120 std::vector<SBPrefix>* prefix_hits, |
| 121 base::Time last_update) OVERRIDE { | 121 std::vector<SBFullHashResult>* cached_hits) OVERRIDE { |
| 122 std::vector<GURL> urls(1, url); | 122 std::vector<GURL> urls(1, url); |
| 123 return ContainsUrl(safe_browsing_util::MALWARE, | 123 return ContainsUrl(safe_browsing_util::MALWARE, |
| 124 safe_browsing_util::PHISH, | 124 safe_browsing_util::PHISH, |
| 125 urls, prefix_hits, cached_hits); | 125 urls, prefix_hits, cached_hits); |
| 126 } | 126 } |
| 127 virtual bool ContainsDownloadUrl( | 127 virtual bool ContainsDownloadUrl( |
| 128 const std::vector<GURL>& urls, | 128 const std::vector<GURL>& urls, |
| 129 std::vector<SBPrefix>* prefix_hits) OVERRIDE { | 129 std::vector<SBPrefix>* prefix_hits) OVERRIDE { |
| 130 std::vector<SBFullHashResult> full_hits; | 130 std::vector<SBFullHashResult> full_hits; |
| 131 bool found = ContainsUrl(safe_browsing_util::BINURL, | 131 bool found = ContainsUrl(safe_browsing_util::BINURL, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const SBChunkList& chunks) OVERRIDE { | 165 const SBChunkList& chunks) OVERRIDE { |
| 166 ADD_FAILURE() << "Not implemented."; | 166 ADD_FAILURE() << "Not implemented."; |
| 167 } | 167 } |
| 168 virtual void DeleteChunks( | 168 virtual void DeleteChunks( |
| 169 const std::vector<SBChunkDelete>& chunk_deletes) OVERRIDE { | 169 const std::vector<SBChunkDelete>& chunk_deletes) OVERRIDE { |
| 170 ADD_FAILURE() << "Not implemented."; | 170 ADD_FAILURE() << "Not implemented."; |
| 171 } | 171 } |
| 172 virtual void UpdateFinished(bool update_succeeded) OVERRIDE { | 172 virtual void UpdateFinished(bool update_succeeded) OVERRIDE { |
| 173 ADD_FAILURE() << "Not implemented."; | 173 ADD_FAILURE() << "Not implemented."; |
| 174 } | 174 } |
| 175 virtual void CacheHashResults(const std::vector<SBPrefix>& prefixes, | 175 virtual void CacheHashResults( |
| 176 const std::vector<SBFullHashResult>& full_hits) OVERRIDE { | 176 const std::vector<SBPrefix>& prefixes, |
| 177 const std::vector<SBFullHashResult>& full_hits, |
| 178 const base::TimeDelta& cache_lifetime) OVERRIDE { |
| 177 // Do nothing for the cache. | 179 // Do nothing for the cache. |
| 178 } | 180 } |
| 179 virtual bool IsMalwareIPMatchKillSwitchOn() OVERRIDE { | 181 virtual bool IsMalwareIPMatchKillSwitchOn() OVERRIDE { |
| 180 return false; | 182 return false; |
| 181 } | 183 } |
| 182 | 184 |
| 183 // Fill up the database with test URL. | 185 // Fill up the database with test URL. |
| 184 void AddUrl(const GURL& url, | 186 void AddUrl(const GURL& url, |
| 185 int list_id, | 187 int list_id, |
| 186 const std::vector<SBPrefix>& prefix_hits, | 188 const std::vector<SBPrefix>& prefix_hits, |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 content::WindowedNotificationObserver observer( | 994 content::WindowedNotificationObserver observer( |
| 993 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 995 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 994 content::Source<SafeBrowsingDatabaseManager>( | 996 content::Source<SafeBrowsingDatabaseManager>( |
| 995 sb_service_->database_manager().get())); | 997 sb_service_->database_manager().get())); |
| 996 BrowserThread::PostTask( | 998 BrowserThread::PostTask( |
| 997 BrowserThread::IO, | 999 BrowserThread::IO, |
| 998 FROM_HERE, | 1000 FROM_HERE, |
| 999 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1001 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
| 1000 observer.Wait(); | 1002 observer.Wait(); |
| 1001 } | 1003 } |
| OLD | NEW |