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

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

Issue 657373004: Standardize usage of virtual/override/final in chrome/browser/safe_browsing/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 uses the safebrowsing test server published at 5 // This test uses the safebrowsing test server published at
6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing 6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing
7 // protocol implemetation. Details of the safebrowsing testing flow is 7 // protocol implemetation. Details of the safebrowsing testing flow is
8 // documented at 8 // documented at
9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting 9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting
10 // 10 //
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 phishing_urls->push_back(phishing_url); 105 phishing_urls->push_back(phishing_url);
106 } 106 }
107 return true; 107 return true;
108 } 108 }
109 109
110 class FakeSafeBrowsingService : public SafeBrowsingService { 110 class FakeSafeBrowsingService : public SafeBrowsingService {
111 public: 111 public:
112 explicit FakeSafeBrowsingService(const std::string& url_prefix) 112 explicit FakeSafeBrowsingService(const std::string& url_prefix)
113 : url_prefix_(url_prefix) {} 113 : url_prefix_(url_prefix) {}
114 114
115 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const override { 115 SafeBrowsingProtocolConfig GetProtocolConfig() const override {
116 SafeBrowsingProtocolConfig config; 116 SafeBrowsingProtocolConfig config;
117 config.url_prefix = url_prefix_; 117 config.url_prefix = url_prefix_;
118 // Makes sure the auto update is not triggered. The tests will force the 118 // Makes sure the auto update is not triggered. The tests will force the
119 // update when needed. 119 // update when needed.
120 config.disable_auto_update = true; 120 config.disable_auto_update = true;
121 #if defined(OS_ANDROID) 121 #if defined(OS_ANDROID)
122 config.disable_connection_check = true; 122 config.disable_connection_check = true;
123 #endif 123 #endif
124 config.client_name = "browser_tests"; 124 config.client_name = "browser_tests";
125 return config; 125 return config;
126 } 126 }
127 127
128 private: 128 private:
129 virtual ~FakeSafeBrowsingService() {} 129 ~FakeSafeBrowsingService() override {}
130 130
131 std::string url_prefix_; 131 std::string url_prefix_;
132 132
133 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); 133 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService);
134 }; 134 };
135 135
136 // Factory that creates FakeSafeBrowsingService instances. 136 // Factory that creates FakeSafeBrowsingService instances.
137 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { 137 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory {
138 public: 138 public:
139 explicit TestSafeBrowsingServiceFactory(const std::string& url_prefix) 139 explicit TestSafeBrowsingServiceFactory(const std::string& url_prefix)
140 : url_prefix_(url_prefix) {} 140 : url_prefix_(url_prefix) {}
141 141
142 virtual SafeBrowsingService* CreateSafeBrowsingService() override { 142 SafeBrowsingService* CreateSafeBrowsingService() override {
143 return new FakeSafeBrowsingService(url_prefix_); 143 return new FakeSafeBrowsingService(url_prefix_);
144 } 144 }
145 145
146 private: 146 private:
147 std::string url_prefix_; 147 std::string url_prefix_;
148 }; 148 };
149 149
150 } // namespace 150 } // namespace
151 151
152 // This starts the browser and keeps status of states related to SafeBrowsing. 152 // This starts the browser and keeps status of states related to SafeBrowsing.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 InProcessBrowserTest::SetUp(); 275 InProcessBrowserTest::SetUp();
276 } 276 }
277 277
278 virtual void TearDown() override { 278 virtual void TearDown() override {
279 InProcessBrowserTest::TearDown(); 279 InProcessBrowserTest::TearDown();
280 280
281 SafeBrowsingService::RegisterFactory(NULL); 281 SafeBrowsingService::RegisterFactory(NULL);
282 } 282 }
283 283
284 virtual void SetUpCommandLine(CommandLine* command_line) override { 284 void SetUpCommandLine(CommandLine* command_line) override {
285 // This test uses loopback. No need to use IPv6 especially it makes 285 // This test uses loopback. No need to use IPv6 especially it makes
286 // local requests slow on Windows trybot when ipv6 local address [::1] 286 // local requests slow on Windows trybot when ipv6 local address [::1]
287 // is not setup. 287 // is not setup.
288 command_line->AppendSwitch(switches::kDisableIPv6); 288 command_line->AppendSwitch(switches::kDisableIPv6);
289 289
290 // TODO(lzheng): The test server does not understand download related 290 // TODO(lzheng): The test server does not understand download related
291 // requests. We need to fix the server. 291 // requests. We need to fix the server.
292 command_line->AppendSwitch(switches::kSbDisableDownloadProtection); 292 command_line->AppendSwitch(switches::kSbDisableDownloadProtection);
293 293
294 // TODO(gcasto): Generate new testing data that includes the 294 // TODO(gcasto): Generate new testing data that includes the
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 public net::URLFetcherDelegate { 342 public net::URLFetcherDelegate {
343 public: 343 public:
344 SafeBrowsingServerTestHelper(SafeBrowsingServerTest* safe_browsing_test, 344 SafeBrowsingServerTestHelper(SafeBrowsingServerTest* safe_browsing_test,
345 net::URLRequestContextGetter* request_context) 345 net::URLRequestContextGetter* request_context)
346 : safe_browsing_test_(safe_browsing_test), 346 : safe_browsing_test_(safe_browsing_test),
347 response_status_(net::URLRequestStatus::FAILED), 347 response_status_(net::URLRequestStatus::FAILED),
348 request_context_(request_context) { 348 request_context_(request_context) {
349 } 349 }
350 350
351 // Callbacks for SafeBrowsingDatabaseManager::Client. 351 // Callbacks for SafeBrowsingDatabaseManager::Client.
352 virtual void OnCheckBrowseUrlResult(const GURL& url, 352 void OnCheckBrowseUrlResult(const GURL& url,
353 SBThreatType threat_type, 353 SBThreatType threat_type,
354 const std::string& metadata) override { 354 const std::string& metadata) override {
355 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 355 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
356 EXPECT_TRUE(safe_browsing_test_->is_checked_url_in_db()); 356 EXPECT_TRUE(safe_browsing_test_->is_checked_url_in_db());
357 safe_browsing_test_->set_is_checked_url_safe( 357 safe_browsing_test_->set_is_checked_url_safe(
358 threat_type == SB_THREAT_TYPE_SAFE); 358 threat_type == SB_THREAT_TYPE_SAFE);
359 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 359 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
360 base::Bind(&SafeBrowsingServerTestHelper::OnCheckUrlDone, this)); 360 base::Bind(&SafeBrowsingServerTestHelper::OnCheckUrlDone, this));
361 } 361 }
362 362
363 virtual void OnBlockingPageComplete(bool proceed) { 363 virtual void OnBlockingPageComplete(bool proceed) {
364 NOTREACHED() << "Not implemented."; 364 NOTREACHED() << "Not implemented.";
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // this verification will fail. 446 // this verification will fail.
447 net::URLRequestStatus::Status VerifyTestComplete( 447 net::URLRequestStatus::Status VerifyTestComplete(
448 const net::SpawnedTestServer& test_server, 448 const net::SpawnedTestServer& test_server,
449 int test_step) { 449 int test_step) {
450 std::string path = base::StringPrintf( 450 std::string path = base::StringPrintf(
451 "%s?test_step=%d", kTestCompletePath, test_step); 451 "%s?test_step=%d", kTestCompletePath, test_step);
452 return FetchUrl(test_server.GetURL(path)); 452 return FetchUrl(test_server.GetURL(path));
453 } 453 }
454 454
455 // Callback for URLFetcher. 455 // Callback for URLFetcher.
456 virtual void OnURLFetchComplete(const net::URLFetcher* source) override { 456 void OnURLFetchComplete(const net::URLFetcher* source) override {
457 source->GetResponseAsString(&response_data_); 457 source->GetResponseAsString(&response_data_);
458 response_status_ = source->GetStatus().status(); 458 response_status_ = source->GetStatus().status();
459 StopUILoop(); 459 StopUILoop();
460 } 460 }
461 461
462 const std::string& response_data() { 462 const std::string& response_data() {
463 return response_data_; 463 return response_data_;
464 } 464 }
465 465
466 private: 466 private:
467 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>; 467 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>;
468 virtual ~SafeBrowsingServerTestHelper() {} 468 ~SafeBrowsingServerTestHelper() override {}
469 469
470 // Stops UI loop after desired status is updated. 470 // Stops UI loop after desired status is updated.
471 void StopUILoop() { 471 void StopUILoop() {
472 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 472 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
473 base::MessageLoopForUI::current()->Quit(); 473 base::MessageLoopForUI::current()->Quit();
474 } 474 }
475 475
476 // Fetch a URL. If message_loop_started is true, starts the message loop 476 // Fetch a URL. If message_loop_started is true, starts the message loop
477 // so the caller could wait till OnURLFetchComplete is called. 477 // so the caller could wait till OnURLFetchComplete is called.
478 net::URLRequestStatus::Status FetchUrl(const GURL& url) { 478 net::URLRequestStatus::Status FetchUrl(const GURL& url) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 safe_browsing_helper->FetchDBToVerify(test_server(), step)); 573 safe_browsing_helper->FetchDBToVerify(test_server(), step));
574 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); 574 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U);
575 last_step = step; 575 last_step = step;
576 } 576 }
577 577
578 // Verifies with server if test is done and waits till server responses. 578 // Verifies with server if test is done and waits till server responses.
579 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 579 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
580 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); 580 safe_browsing_helper->VerifyTestComplete(test_server(), last_step));
581 EXPECT_EQ("yes", safe_browsing_helper->response_data()); 581 EXPECT_EQ("yes", safe_browsing_helper->response_data());
582 } 582 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_tab_observer.h ('k') | chrome/browser/safe_browsing/sandboxed_zip_analyzer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698