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

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

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // bad URL that server expects test to fetch full hash but the test didn't, 502 // bad URL that server expects test to fetch full hash but the test didn't,
503 // this verification will fail. 503 // this verification will fail.
504 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, 504 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port,
505 int test_step) { 505 int test_step) {
506 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", 506 GURL url(StringPrintf("http://%s:%d%s?test_step=%d",
507 host, port, kTestCompletePath, test_step)); 507 host, port, kTestCompletePath, test_step));
508 return FetchUrl(url); 508 return FetchUrl(url);
509 } 509 }
510 510
511 // Callback for URLFetcher. 511 // Callback for URLFetcher.
512 virtual void OnURLFetchComplete(const URLFetcher* source) { 512 virtual void OnURLFetchComplete(const content::URLFetcher* source) {
513 source->GetResponseAsString(&response_data_); 513 source->GetResponseAsString(&response_data_);
514 response_status_ = source->status().status(); 514 response_status_ = source->GetStatus().status();
515 StopUILoop(); 515 StopUILoop();
516 } 516 }
517 517
518 const std::string& response_data() { 518 const std::string& response_data() {
519 return response_data_; 519 return response_data_;
520 } 520 }
521 521
522 private: 522 private:
523 // Stops UI loop after desired status is updated. 523 // Stops UI loop after desired status is updated.
524 void StopUILoop() { 524 void StopUILoop() {
525 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 525 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
526 MessageLoopForUI::current()->Quit(); 526 MessageLoopForUI::current()->Quit();
527 } 527 }
528 528
529 // Fetch a URL. If message_loop_started is true, starts the message loop 529 // Fetch a URL. If message_loop_started is true, starts the message loop
530 // so the caller could wait till OnURLFetchComplete is called. 530 // so the caller could wait till OnURLFetchComplete is called.
531 net::URLRequestStatus::Status FetchUrl(const GURL& url) { 531 net::URLRequestStatus::Status FetchUrl(const GURL& url) {
532 url_fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); 532 url_fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
533 url_fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE); 533 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
534 url_fetcher_->set_request_context( 534 url_fetcher_->SetRequestContext(
535 Profile::Deprecated::GetDefaultRequestContext()); 535 Profile::Deprecated::GetDefaultRequestContext());
536 url_fetcher_->Start(); 536 url_fetcher_->Start();
537 ui_test_utils::RunMessageLoop(); 537 ui_test_utils::RunMessageLoop();
538 return response_status_; 538 return response_status_;
539 } 539 }
540 540
541 base::OneShotTimer<SafeBrowsingServiceTestHelper> check_update_timer_; 541 base::OneShotTimer<SafeBrowsingServiceTestHelper> check_update_timer_;
542 SafeBrowsingServiceTest* safe_browsing_test_; 542 SafeBrowsingServiceTest* safe_browsing_test_;
543 scoped_ptr<URLFetcher> url_fetcher_; 543 scoped_ptr<content::URLFetcher> url_fetcher_;
544 std::string response_data_; 544 std::string response_data_;
545 net::URLRequestStatus::Status response_status_; 545 net::URLRequestStatus::Status response_status_;
546 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); 546 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper);
547 }; 547 };
548 548
549 #if defined(OS_WIN) && defined(NDEBUG) 549 #if defined(OS_WIN) && defined(NDEBUG)
550 #define MAYBE_SafeBrowsingSystemTest FLAKY_SafeBrowsingSystemTest 550 #define MAYBE_SafeBrowsingSystemTest FLAKY_SafeBrowsingSystemTest
551 #else 551 #else
552 #define MAYBE_SafeBrowsingSystemTest SafeBrowsingServiceTest 552 #define MAYBE_SafeBrowsingSystemTest SafeBrowsingServiceTest
553 #endif 553 #endif
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 } 648 }
649 649
650 // Verifies with server if test is done and waits till server responses. 650 // Verifies with server if test is done and waits till server responses.
651 EXPECT_EQ(net::URLRequestStatus::SUCCESS, 651 EXPECT_EQ(net::URLRequestStatus::SUCCESS,
652 safe_browsing_helper->VerifyTestComplete(server_host, 652 safe_browsing_helper->VerifyTestComplete(server_host,
653 server_port, 653 server_port,
654 last_step)); 654 last_step));
655 EXPECT_EQ("yes", safe_browsing_helper->response_data()); 655 EXPECT_EQ("yes", safe_browsing_helper->response_data());
656 test_server.Stop(); 656 test_server.Stop();
657 } 657 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.cc ('k') | chrome/browser/search_engines/template_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698