Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc

Issue 629603002: replace OVERRIDE and FINAL with override and final in chrome/browser/[r-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 SafeBrowsingProtocolManager::FullHashCallback callback, 64 SafeBrowsingProtocolManager::FullHashCallback callback,
65 const std::vector<SBFullHashResult>& result) { 65 const std::vector<SBFullHashResult>& result) {
66 callback.Run(result, base::TimeDelta::FromMinutes(45)); 66 callback.Run(result, base::TimeDelta::FromMinutes(45));
67 } 67 }
68 68
69 class FakeSafeBrowsingService : public SafeBrowsingService { 69 class FakeSafeBrowsingService : public SafeBrowsingService {
70 public: 70 public:
71 explicit FakeSafeBrowsingService(const std::string& url_prefix) 71 explicit FakeSafeBrowsingService(const std::string& url_prefix)
72 : url_prefix_(url_prefix) {} 72 : url_prefix_(url_prefix) {}
73 73
74 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const OVERRIDE { 74 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const override {
75 SafeBrowsingProtocolConfig config; 75 SafeBrowsingProtocolConfig config;
76 config.url_prefix = url_prefix_; 76 config.url_prefix = url_prefix_;
77 // Makes sure the auto update is not triggered. The tests will force the 77 // Makes sure the auto update is not triggered. The tests will force the
78 // update when needed. 78 // update when needed.
79 config.disable_auto_update = true; 79 config.disable_auto_update = true;
80 #if defined(OS_ANDROID) 80 #if defined(OS_ANDROID)
81 config.disable_connection_check = true; 81 config.disable_connection_check = true;
82 #endif 82 #endif
83 config.client_name = "browser_tests"; 83 config.client_name = "browser_tests";
84 return config; 84 return config;
85 } 85 }
86 86
87 private: 87 private:
88 virtual ~FakeSafeBrowsingService() {} 88 virtual ~FakeSafeBrowsingService() {}
89 89
90 std::string url_prefix_; 90 std::string url_prefix_;
91 91
92 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); 92 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService);
93 }; 93 };
94 94
95 // Factory that creates FakeSafeBrowsingService instances. 95 // Factory that creates FakeSafeBrowsingService instances.
96 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { 96 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory {
97 public: 97 public:
98 explicit TestSafeBrowsingServiceFactory(const std::string& url_prefix) 98 explicit TestSafeBrowsingServiceFactory(const std::string& url_prefix)
99 : url_prefix_(url_prefix) {} 99 : url_prefix_(url_prefix) {}
100 100
101 virtual SafeBrowsingService* CreateSafeBrowsingService() OVERRIDE { 101 virtual SafeBrowsingService* CreateSafeBrowsingService() override {
102 return new FakeSafeBrowsingService(url_prefix_); 102 return new FakeSafeBrowsingService(url_prefix_);
103 } 103 }
104 104
105 private: 105 private:
106 std::string url_prefix_; 106 std::string url_prefix_;
107 }; 107 };
108 108
109 // A SafeBrowingDatabase class that allows us to inject the malicious URLs. 109 // A SafeBrowingDatabase class that allows us to inject the malicious URLs.
110 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase { 110 class TestSafeBrowsingDatabase : public SafeBrowsingDatabase {
111 public: 111 public:
112 TestSafeBrowsingDatabase() {} 112 TestSafeBrowsingDatabase() {}
113 113
114 virtual ~TestSafeBrowsingDatabase() {} 114 virtual ~TestSafeBrowsingDatabase() {}
115 115
116 // Initializes the database with the given filename. 116 // Initializes the database with the given filename.
117 virtual void Init(const base::FilePath& filename) OVERRIDE {} 117 virtual void Init(const base::FilePath& filename) override {}
118 118
119 // Deletes the current database and creates a new one. 119 // Deletes the current database and creates a new one.
120 virtual bool ResetDatabase() OVERRIDE { 120 virtual bool ResetDatabase() override {
121 badurls_.clear(); 121 badurls_.clear();
122 return true; 122 return true;
123 } 123 }
124 124
125 // Called on the IO thread to check if the given URL is safe or not. If we 125 // Called on the IO thread to check if the given URL is safe or not. If we
126 // can synchronously determine that the URL is safe, CheckUrl returns true, 126 // can synchronously determine that the URL is safe, CheckUrl returns true,
127 // otherwise it returns false. 127 // otherwise it returns false.
128 virtual bool ContainsBrowseUrl( 128 virtual bool ContainsBrowseUrl(
129 const GURL& url, 129 const GURL& url,
130 std::vector<SBPrefix>* prefix_hits, 130 std::vector<SBPrefix>* prefix_hits,
131 std::vector<SBFullHashResult>* cache_hits) OVERRIDE { 131 std::vector<SBFullHashResult>* cache_hits) override {
132 cache_hits->clear(); 132 cache_hits->clear();
133 return ContainsUrl(safe_browsing_util::MALWARE, 133 return ContainsUrl(safe_browsing_util::MALWARE,
134 safe_browsing_util::PHISH, 134 safe_browsing_util::PHISH,
135 std::vector<GURL>(1, url), 135 std::vector<GURL>(1, url),
136 prefix_hits); 136 prefix_hits);
137 } 137 }
138 virtual bool ContainsDownloadUrl( 138 virtual bool ContainsDownloadUrl(
139 const std::vector<GURL>& urls, 139 const std::vector<GURL>& urls,
140 std::vector<SBPrefix>* prefix_hits) OVERRIDE { 140 std::vector<SBPrefix>* prefix_hits) override {
141 bool found = ContainsUrl(safe_browsing_util::BINURL, 141 bool found = ContainsUrl(safe_browsing_util::BINURL,
142 safe_browsing_util::BINURL, 142 safe_browsing_util::BINURL,
143 urls, 143 urls,
144 prefix_hits); 144 prefix_hits);
145 if (!found) 145 if (!found)
146 return false; 146 return false;
147 DCHECK_LE(1U, prefix_hits->size()); 147 DCHECK_LE(1U, prefix_hits->size());
148 return true; 148 return true;
149 } 149 }
150 virtual bool ContainsCsdWhitelistedUrl(const GURL& url) OVERRIDE { 150 virtual bool ContainsCsdWhitelistedUrl(const GURL& url) override {
151 return true; 151 return true;
152 } 152 }
153 virtual bool ContainsDownloadWhitelistedString( 153 virtual bool ContainsDownloadWhitelistedString(
154 const std::string& str) OVERRIDE { 154 const std::string& str) override {
155 return true; 155 return true;
156 } 156 }
157 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) OVERRIDE { 157 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) override {
158 return true; 158 return true;
159 } 159 }
160 virtual bool ContainsExtensionPrefixes( 160 virtual bool ContainsExtensionPrefixes(
161 const std::vector<SBPrefix>& prefixes, 161 const std::vector<SBPrefix>& prefixes,
162 std::vector<SBPrefix>* prefix_hits) OVERRIDE { 162 std::vector<SBPrefix>* prefix_hits) override {
163 return true; 163 return true;
164 } 164 }
165 virtual bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) OVERRIDE { 165 virtual bool ContainsSideEffectFreeWhitelistUrl(const GURL& url) override {
166 return true; 166 return true;
167 } 167 }
168 virtual bool ContainsMalwareIP(const std::string& ip_address) OVERRIDE { 168 virtual bool ContainsMalwareIP(const std::string& ip_address) override {
169 return true; 169 return true;
170 } 170 }
171 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) OVERRIDE { 171 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override {
172 ADD_FAILURE() << "Not implemented."; 172 ADD_FAILURE() << "Not implemented.";
173 return false; 173 return false;
174 } 174 }
175 virtual void InsertChunks( 175 virtual void InsertChunks(
176 const std::string& list_name, 176 const std::string& list_name,
177 const std::vector<SBChunkData*>& chunks) OVERRIDE { 177 const std::vector<SBChunkData*>& chunks) override {
178 ADD_FAILURE() << "Not implemented."; 178 ADD_FAILURE() << "Not implemented.";
179 } 179 }
180 virtual void DeleteChunks( 180 virtual void DeleteChunks(
181 const std::vector<SBChunkDelete>& chunk_deletes) OVERRIDE { 181 const std::vector<SBChunkDelete>& chunk_deletes) override {
182 ADD_FAILURE() << "Not implemented."; 182 ADD_FAILURE() << "Not implemented.";
183 } 183 }
184 virtual void UpdateFinished(bool update_succeeded) OVERRIDE { 184 virtual void UpdateFinished(bool update_succeeded) override {
185 ADD_FAILURE() << "Not implemented."; 185 ADD_FAILURE() << "Not implemented.";
186 } 186 }
187 virtual void CacheHashResults( 187 virtual void CacheHashResults(
188 const std::vector<SBPrefix>& prefixes, 188 const std::vector<SBPrefix>& prefixes,
189 const std::vector<SBFullHashResult>& cache_hits, 189 const std::vector<SBFullHashResult>& cache_hits,
190 const base::TimeDelta& cache_lifetime) OVERRIDE { 190 const base::TimeDelta& cache_lifetime) override {
191 // Do nothing for the cache. 191 // Do nothing for the cache.
192 } 192 }
193 virtual bool IsMalwareIPMatchKillSwitchOn() OVERRIDE { 193 virtual bool IsMalwareIPMatchKillSwitchOn() override {
194 return false; 194 return false;
195 } 195 }
196 virtual bool IsCsdWhitelistKillSwitchOn() OVERRIDE { 196 virtual bool IsCsdWhitelistKillSwitchOn() override {
197 return false; 197 return false;
198 } 198 }
199 199
200 // Fill up the database with test URL. 200 // Fill up the database with test URL.
201 void AddUrl(const GURL& url, 201 void AddUrl(const GURL& url,
202 int list_id, 202 int list_id,
203 const std::vector<SBPrefix>& prefix_hits) { 203 const std::vector<SBPrefix>& prefix_hits) {
204 badurls_[url.spec()].list_id = list_id; 204 badurls_[url.spec()].list_id = list_id;
205 badurls_[url.spec()].prefix_hits = prefix_hits; 205 badurls_[url.spec()].prefix_hits = prefix_hits;
206 } 206 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 public: 249 public:
250 TestSafeBrowsingDatabaseFactory() : db_(NULL) {} 250 TestSafeBrowsingDatabaseFactory() : db_(NULL) {}
251 virtual ~TestSafeBrowsingDatabaseFactory() {} 251 virtual ~TestSafeBrowsingDatabaseFactory() {}
252 252
253 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( 253 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase(
254 bool enable_download_protection, 254 bool enable_download_protection,
255 bool enable_client_side_whitelist, 255 bool enable_client_side_whitelist,
256 bool enable_download_whitelist, 256 bool enable_download_whitelist,
257 bool enable_extension_blacklist, 257 bool enable_extension_blacklist,
258 bool enable_side_effect_free_whitelist, 258 bool enable_side_effect_free_whitelist,
259 bool enable_ip_blacklist) OVERRIDE { 259 bool enable_ip_blacklist) override {
260 db_ = new TestSafeBrowsingDatabase(); 260 db_ = new TestSafeBrowsingDatabase();
261 return db_; 261 return db_;
262 } 262 }
263 TestSafeBrowsingDatabase* GetDb() { 263 TestSafeBrowsingDatabase* GetDb() {
264 return db_; 264 return db_;
265 } 265 }
266 private: 266 private:
267 // Owned by the SafebrowsingService. 267 // Owned by the SafebrowsingService.
268 TestSafeBrowsingDatabase* db_; 268 TestSafeBrowsingDatabase* db_;
269 }; 269 };
(...skipping 14 matching lines...) Expand all
284 } 284 }
285 285
286 // This function is called when there is a prefix hit in local safebrowsing 286 // This function is called when there is a prefix hit in local safebrowsing
287 // database and safebrowsing service issues a get hash request to backends. 287 // database and safebrowsing service issues a get hash request to backends.
288 // We return a result from the prefilled full_hashes_ hash_map to simulate 288 // We return a result from the prefilled full_hashes_ hash_map to simulate
289 // server's response. At the same time, latency is added to simulate real 289 // server's response. At the same time, latency is added to simulate real
290 // life network issues. 290 // life network issues.
291 virtual void GetFullHash( 291 virtual void GetFullHash(
292 const std::vector<SBPrefix>& prefixes, 292 const std::vector<SBPrefix>& prefixes,
293 SafeBrowsingProtocolManager::FullHashCallback callback, 293 SafeBrowsingProtocolManager::FullHashCallback callback,
294 bool is_download) OVERRIDE { 294 bool is_download) override {
295 BrowserThread::PostDelayedTask( 295 BrowserThread::PostDelayedTask(
296 BrowserThread::IO, FROM_HERE, 296 BrowserThread::IO, FROM_HERE,
297 base::Bind(InvokeFullHashCallback, callback, full_hashes_), 297 base::Bind(InvokeFullHashCallback, callback, full_hashes_),
298 delay_); 298 delay_);
299 } 299 }
300 300
301 // Prepare the GetFullHash results for the next request. 301 // Prepare the GetFullHash results for the next request.
302 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) { 302 void SetGetFullHashResponse(const SBFullHashResult& full_hash_result) {
303 full_hashes_.clear(); 303 full_hashes_.clear();
304 full_hashes_.push_back(full_hash_result); 304 full_hashes_.push_back(full_hash_result);
(...skipping 25 matching lines...) Expand all
330 330
331 // Factory that creates TestProtocolManager instances. 331 // Factory that creates TestProtocolManager instances.
332 class TestSBProtocolManagerFactory : public SBProtocolManagerFactory { 332 class TestSBProtocolManagerFactory : public SBProtocolManagerFactory {
333 public: 333 public:
334 TestSBProtocolManagerFactory() : pm_(NULL) {} 334 TestSBProtocolManagerFactory() : pm_(NULL) {}
335 virtual ~TestSBProtocolManagerFactory() {} 335 virtual ~TestSBProtocolManagerFactory() {}
336 336
337 virtual SafeBrowsingProtocolManager* CreateProtocolManager( 337 virtual SafeBrowsingProtocolManager* CreateProtocolManager(
338 SafeBrowsingProtocolManagerDelegate* delegate, 338 SafeBrowsingProtocolManagerDelegate* delegate,
339 net::URLRequestContextGetter* request_context_getter, 339 net::URLRequestContextGetter* request_context_getter,
340 const SafeBrowsingProtocolConfig& config) OVERRIDE { 340 const SafeBrowsingProtocolConfig& config) override {
341 pm_ = new TestProtocolManager(delegate, request_context_getter, config); 341 pm_ = new TestProtocolManager(delegate, request_context_getter, config);
342 return pm_; 342 return pm_;
343 } 343 }
344 344
345 TestProtocolManager* GetProtocolManager() { 345 TestProtocolManager* GetProtocolManager() {
346 return pm_; 346 return pm_;
347 } 347 }
348 348
349 private: 349 private:
350 // Owned by the SafebrowsingService. 350 // Owned by the SafebrowsingService.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 virtual void TearDown() { 398 virtual void TearDown() {
399 InProcessBrowserTest::TearDown(); 399 InProcessBrowserTest::TearDown();
400 400
401 // Unregister test factories after InProcessBrowserTest::TearDown 401 // Unregister test factories after InProcessBrowserTest::TearDown
402 // (which destructs SafeBrowsingService). 402 // (which destructs SafeBrowsingService).
403 SafeBrowsingDatabase::RegisterFactory(NULL); 403 SafeBrowsingDatabase::RegisterFactory(NULL);
404 SafeBrowsingProtocolManager::RegisterFactory(NULL); 404 SafeBrowsingProtocolManager::RegisterFactory(NULL);
405 SafeBrowsingService::RegisterFactory(NULL); 405 SafeBrowsingService::RegisterFactory(NULL);
406 } 406 }
407 407
408 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 408 virtual void SetUpCommandLine(CommandLine* command_line) override {
409 // Makes sure the auto update is not triggered during the test. 409 // Makes sure the auto update is not triggered during the test.
410 // This test will fill up the database using testing prefixes 410 // This test will fill up the database using testing prefixes
411 // and urls. 411 // and urls.
412 command_line->AppendSwitch(switches::kSbDisableAutoUpdate); 412 command_line->AppendSwitch(switches::kSbDisableAutoUpdate);
413 #if defined(OS_CHROMEOS) 413 #if defined(OS_CHROMEOS)
414 command_line->AppendSwitch( 414 command_line->AppendSwitch(
415 chromeos::switches::kIgnoreUserProfileMappingForTests); 415 chromeos::switches::kIgnoreUserProfileMappingForTests);
416 #endif 416 #endif
417 } 417 }
418 418
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 METADATA_LANDING, 507 METADATA_LANDING,
508 METADATA_DISTRIBUTION, 508 METADATA_DISTRIBUTION,
509 }; 509 };
510 510
511 class SafeBrowsingServiceMetadataTest 511 class SafeBrowsingServiceMetadataTest
512 : public SafeBrowsingServiceTest, 512 : public SafeBrowsingServiceTest,
513 public ::testing::WithParamInterface<MalwareMetadataTestType> { 513 public ::testing::WithParamInterface<MalwareMetadataTestType> {
514 public: 514 public:
515 SafeBrowsingServiceMetadataTest() {} 515 SafeBrowsingServiceMetadataTest() {}
516 516
517 virtual void SetUpOnMainThread() OVERRIDE { 517 virtual void SetUpOnMainThread() override {
518 SafeBrowsingServiceTest::SetUpOnMainThread(); 518 SafeBrowsingServiceTest::SetUpOnMainThread();
519 g_browser_process->safe_browsing_service()->ui_manager()->AddObserver( 519 g_browser_process->safe_browsing_service()->ui_manager()->AddObserver(
520 &observer_); 520 &observer_);
521 } 521 }
522 522
523 virtual void TearDownOnMainThread() OVERRIDE { 523 virtual void TearDownOnMainThread() override {
524 g_browser_process->safe_browsing_service()->ui_manager()->RemoveObserver( 524 g_browser_process->safe_browsing_service()->ui_manager()->RemoveObserver(
525 &observer_); 525 &observer_);
526 SafeBrowsingServiceTest::TearDownOnMainThread(); 526 SafeBrowsingServiceTest::TearDownOnMainThread();
527 } 527 }
528 528
529 void GenUrlFullhashResultWithMetadata(const GURL& url, 529 void GenUrlFullhashResultWithMetadata(const GURL& url,
530 SBFullHashResult* full_hash) { 530 SBFullHashResult* full_hash) {
531 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, full_hash); 531 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, full_hash);
532 532
533 safe_browsing::MalwarePatternType proto; 533 safe_browsing::MalwarePatternType proto;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 friend class base::RefCountedThreadSafe<TestSBClient>; 746 friend class base::RefCountedThreadSafe<TestSBClient>;
747 virtual ~TestSBClient() {} 747 virtual ~TestSBClient() {}
748 748
749 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) { 749 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) {
750 safe_browsing_service_->database_manager()-> 750 safe_browsing_service_->database_manager()->
751 CheckDownloadUrl(url_chain, this); 751 CheckDownloadUrl(url_chain, this);
752 } 752 }
753 753
754 // Called when the result of checking a download URL is known. 754 // Called when the result of checking a download URL is known.
755 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, 755 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain,
756 SBThreatType threat_type) OVERRIDE { 756 SBThreatType threat_type) override {
757 threat_type_ = threat_type; 757 threat_type_ = threat_type;
758 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 758 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
759 base::Bind(&TestSBClient::DownloadCheckDone, this)); 759 base::Bind(&TestSBClient::DownloadCheckDone, this));
760 } 760 }
761 761
762 void DownloadCheckDone() { 762 void DownloadCheckDone() {
763 base::MessageLoopForUI::current()->Quit(); 763 base::MessageLoopForUI::current()->Quit();
764 } 764 }
765 765
766 SBThreatType threat_type_; 766 SBThreatType threat_type_;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 profile2.reset(); 912 profile2.reset();
913 WaitForIOThread(); 913 WaitForIOThread();
914 EXPECT_FALSE(sb_service->enabled()); 914 EXPECT_FALSE(sb_service->enabled());
915 EXPECT_FALSE(csd_service->enabled()); 915 EXPECT_FALSE(csd_service->enabled());
916 } 916 }
917 917
918 } // namespace 918 } // namespace
919 919
920 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest { 920 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest {
921 public: 921 public:
922 virtual void TearDown() OVERRIDE { 922 virtual void TearDown() override {
923 // Browser should be fully torn down by now, so we can safely check these 923 // Browser should be fully torn down by now, so we can safely check these
924 // counters. 924 // counters.
925 EXPECT_EQ(1, TestProtocolManager::create_count()); 925 EXPECT_EQ(1, TestProtocolManager::create_count());
926 EXPECT_EQ(1, TestProtocolManager::delete_count()); 926 EXPECT_EQ(1, TestProtocolManager::delete_count());
927 927
928 SafeBrowsingServiceTest::TearDown(); 928 SafeBrowsingServiceTest::TearDown();
929 } 929 }
930 930
931 // An observer that returns back to test code after a new profile is 931 // An observer that returns back to test code after a new profile is
932 // initialized. 932 // initialized.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 985
986 // End the test, shutting down the browser. 986 // End the test, shutting down the browser.
987 // SafeBrowsingServiceShutdownTest::TearDown will check the create_count and 987 // SafeBrowsingServiceShutdownTest::TearDown will check the create_count and
988 // delete_count again. 988 // delete_count again.
989 } 989 }
990 990
991 class SafeBrowsingDatabaseManagerCookieTest : public InProcessBrowserTest { 991 class SafeBrowsingDatabaseManagerCookieTest : public InProcessBrowserTest {
992 public: 992 public:
993 SafeBrowsingDatabaseManagerCookieTest() {} 993 SafeBrowsingDatabaseManagerCookieTest() {}
994 994
995 virtual void SetUp() OVERRIDE { 995 virtual void SetUp() override {
996 // We need to start the test server to get the host&port in the url. 996 // We need to start the test server to get the host&port in the url.
997 ASSERT_TRUE(test_server()->Start()); 997 ASSERT_TRUE(test_server()->Start());
998 998
999 // Point to the testing server for all SafeBrowsing requests. 999 // Point to the testing server for all SafeBrowsing requests.
1000 GURL url_prefix = test_server()->GetURL( 1000 GURL url_prefix = test_server()->GetURL(
1001 "expect-and-set-cookie?expect=a%3db" 1001 "expect-and-set-cookie?expect=a%3db"
1002 "&set=c%3dd%3b%20Expires=Fri,%2001%20Jan%202038%2001:01:01%20GMT" 1002 "&set=c%3dd%3b%20Expires=Fri,%2001%20Jan%202038%2001:01:01%20GMT"
1003 "&data=foo#"); 1003 "&data=foo#");
1004 sb_factory_.reset(new TestSafeBrowsingServiceFactory(url_prefix.spec())); 1004 sb_factory_.reset(new TestSafeBrowsingServiceFactory(url_prefix.spec()));
1005 SafeBrowsingService::RegisterFactory(sb_factory_.get()); 1005 SafeBrowsingService::RegisterFactory(sb_factory_.get());
1006 1006
1007 InProcessBrowserTest::SetUp(); 1007 InProcessBrowserTest::SetUp();
1008 } 1008 }
1009 1009
1010 virtual void TearDown() OVERRIDE { 1010 virtual void TearDown() override {
1011 InProcessBrowserTest::TearDown(); 1011 InProcessBrowserTest::TearDown();
1012 1012
1013 SafeBrowsingService::RegisterFactory(NULL); 1013 SafeBrowsingService::RegisterFactory(NULL);
1014 } 1014 }
1015 1015
1016 virtual bool SetUpUserDataDirectory() OVERRIDE { 1016 virtual bool SetUpUserDataDirectory() override {
1017 base::FilePath cookie_path( 1017 base::FilePath cookie_path(
1018 SafeBrowsingService::GetCookieFilePathForTesting()); 1018 SafeBrowsingService::GetCookieFilePathForTesting());
1019 EXPECT_FALSE(base::PathExists(cookie_path)); 1019 EXPECT_FALSE(base::PathExists(cookie_path));
1020 1020
1021 base::FilePath test_dir; 1021 base::FilePath test_dir;
1022 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_dir)) { 1022 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_dir)) {
1023 EXPECT_TRUE(false); 1023 EXPECT_TRUE(false);
1024 return false; 1024 return false;
1025 } 1025 }
1026 1026
(...skipping 25 matching lines...) Expand all
1052 return false; 1052 return false;
1053 } 1053 }
1054 if (!smt.Run()) { 1054 if (!smt.Run()) {
1055 EXPECT_TRUE(false); 1055 EXPECT_TRUE(false);
1056 return false; 1056 return false;
1057 } 1057 }
1058 1058
1059 return InProcessBrowserTest::SetUpUserDataDirectory(); 1059 return InProcessBrowserTest::SetUpUserDataDirectory();
1060 } 1060 }
1061 1061
1062 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 1062 virtual void TearDownInProcessBrowserTestFixture() override {
1063 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 1063 InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
1064 1064
1065 sql::Connection db; 1065 sql::Connection db;
1066 base::FilePath cookie_path( 1066 base::FilePath cookie_path(
1067 SafeBrowsingService::GetCookieFilePathForTesting()); 1067 SafeBrowsingService::GetCookieFilePathForTesting());
1068 ASSERT_TRUE(db.Open(cookie_path)); 1068 ASSERT_TRUE(db.Open(cookie_path));
1069 1069
1070 sql::Statement smt(db.GetUniqueStatement( 1070 sql::Statement smt(db.GetUniqueStatement(
1071 "SELECT name, value FROM cookies ORDER BY name")); 1071 "SELECT name, value FROM cookies ORDER BY name"));
1072 ASSERT_TRUE(smt.is_valid()); 1072 ASSERT_TRUE(smt.is_valid());
1073 1073
1074 ASSERT_TRUE(smt.Step()); 1074 ASSERT_TRUE(smt.Step());
1075 ASSERT_EQ("a", smt.ColumnString(0)); 1075 ASSERT_EQ("a", smt.ColumnString(0));
1076 ASSERT_EQ("b", smt.ColumnString(1)); 1076 ASSERT_EQ("b", smt.ColumnString(1));
1077 ASSERT_TRUE(smt.Step()); 1077 ASSERT_TRUE(smt.Step());
1078 ASSERT_EQ("c", smt.ColumnString(0)); 1078 ASSERT_EQ("c", smt.ColumnString(0));
1079 ASSERT_EQ("d", smt.ColumnString(1)); 1079 ASSERT_EQ("d", smt.ColumnString(1));
1080 EXPECT_FALSE(smt.Step()); 1080 EXPECT_FALSE(smt.Step());
1081 } 1081 }
1082 1082
1083 virtual void SetUpOnMainThread() OVERRIDE { 1083 virtual void SetUpOnMainThread() override {
1084 sb_service_ = g_browser_process->safe_browsing_service(); 1084 sb_service_ = g_browser_process->safe_browsing_service();
1085 ASSERT_TRUE(sb_service_.get() != NULL); 1085 ASSERT_TRUE(sb_service_.get() != NULL);
1086 } 1086 }
1087 1087
1088 virtual void TearDownOnMainThread() OVERRIDE { 1088 virtual void TearDownOnMainThread() override {
1089 sb_service_ = NULL; 1089 sb_service_ = NULL;
1090 } 1090 }
1091 1091
1092 void ForceUpdate() { 1092 void ForceUpdate() {
1093 sb_service_->protocol_manager()->ForceScheduleNextUpdate( 1093 sb_service_->protocol_manager()->ForceScheduleNextUpdate(
1094 base::TimeDelta::FromSeconds(0)); 1094 base::TimeDelta::FromSeconds(0));
1095 } 1095 }
1096 1096
1097 scoped_refptr<SafeBrowsingService> sb_service_; 1097 scoped_refptr<SafeBrowsingService> sb_service_;
1098 1098
(...skipping 10 matching lines...) Expand all
1109 content::WindowedNotificationObserver observer( 1109 content::WindowedNotificationObserver observer(
1110 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 1110 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
1111 content::Source<SafeBrowsingDatabaseManager>( 1111 content::Source<SafeBrowsingDatabaseManager>(
1112 sb_service_->database_manager().get())); 1112 sb_service_->database_manager().get()));
1113 BrowserThread::PostTask( 1113 BrowserThread::PostTask(
1114 BrowserThread::IO, 1114 BrowserThread::IO,
1115 FROM_HERE, 1115 FROM_HERE,
1116 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); 1116 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this));
1117 observer.Wait(); 1117 observer.Wait();
1118 } 1118 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.cc ('k') | chrome/browser/safe_browsing/safe_browsing_store_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698