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 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 virtual void OnBlockingPageComplete(bool proceed) { | 377 virtual void OnBlockingPageComplete(bool proceed) { |
378 NOTREACHED() << "Not implemented."; | 378 NOTREACHED() << "Not implemented."; |
379 } | 379 } |
380 | 380 |
381 // Functions and callbacks to start the safebrowsing database update. | 381 // Functions and callbacks to start the safebrowsing database update. |
382 void ForceUpdate() { | 382 void ForceUpdate() { |
383 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 383 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
384 base::Bind(&SafeBrowsingServiceTestHelper::ForceUpdateInIOThread, | 384 base::Bind(&SafeBrowsingServiceTestHelper::ForceUpdateInIOThread, |
385 this)); | 385 this)); |
386 // Will continue after OnForceUpdateDone(). | 386 // Will continue after OnForceUpdateDone(). |
387 ui_test_utils::RunMessageLoop(); | 387 content::RunMessageLoop(); |
388 } | 388 } |
389 void ForceUpdateInIOThread() { | 389 void ForceUpdateInIOThread() { |
390 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 390 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
391 safe_browsing_test_->ForceUpdate(); | 391 safe_browsing_test_->ForceUpdate(); |
392 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 392 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
393 base::Bind(&SafeBrowsingServiceTestHelper::OnForceUpdateDone, | 393 base::Bind(&SafeBrowsingServiceTestHelper::OnForceUpdateDone, |
394 this)); | 394 this)); |
395 } | 395 } |
396 void OnForceUpdateDone() { | 396 void OnForceUpdateDone() { |
397 StopUILoop(); | 397 StopUILoop(); |
398 } | 398 } |
399 | 399 |
400 // Functions and callbacks related to CheckUrl. These are used to verify | 400 // Functions and callbacks related to CheckUrl. These are used to verify |
401 // phishing URLs. | 401 // phishing URLs. |
402 void CheckUrl(const GURL& url) { | 402 void CheckUrl(const GURL& url) { |
403 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 403 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
404 base::Bind(&SafeBrowsingServiceTestHelper::CheckUrlOnIOThread, | 404 base::Bind(&SafeBrowsingServiceTestHelper::CheckUrlOnIOThread, |
405 this, url)); | 405 this, url)); |
406 ui_test_utils::RunMessageLoop(); | 406 content::RunMessageLoop(); |
407 } | 407 } |
408 void CheckUrlOnIOThread(const GURL& url) { | 408 void CheckUrlOnIOThread(const GURL& url) { |
409 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 409 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
410 safe_browsing_test_->CheckUrl(this, url); | 410 safe_browsing_test_->CheckUrl(this, url); |
411 if (!safe_browsing_test_->is_checked_url_in_db()) { | 411 if (!safe_browsing_test_->is_checked_url_in_db()) { |
412 // Ends the checking since this URL's prefix is not in database. | 412 // Ends the checking since this URL's prefix is not in database. |
413 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 413 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
414 base::Bind(&SafeBrowsingServiceTestHelper::OnCheckUrlDone, | 414 base::Bind(&SafeBrowsingServiceTestHelper::OnCheckUrlDone, |
415 this)); | 415 this)); |
416 } | 416 } |
(...skipping 29 matching lines...) Expand all Loading... |
446 | 446 |
447 // Wait for a given period to get safebrowsing status updated. | 447 // Wait for a given period to get safebrowsing status updated. |
448 void WaitForStatusUpdate(base::TimeDelta wait_time) { | 448 void WaitForStatusUpdate(base::TimeDelta wait_time) { |
449 BrowserThread::PostDelayedTask( | 449 BrowserThread::PostDelayedTask( |
450 BrowserThread::IO, | 450 BrowserThread::IO, |
451 FROM_HERE, | 451 FROM_HERE, |
452 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, | 452 base::Bind(&SafeBrowsingServiceTestHelper::CheckStatusOnIOThread, |
453 this), | 453 this), |
454 wait_time); | 454 wait_time); |
455 // Will continue after OnWaitForStatusUpdateDone(). | 455 // Will continue after OnWaitForStatusUpdateDone(). |
456 ui_test_utils::RunMessageLoop(); | 456 content::RunMessageLoop(); |
457 } | 457 } |
458 | 458 |
459 void WaitTillServerReady(const char* host, int port) { | 459 void WaitTillServerReady(const char* host, int port) { |
460 response_status_ = net::URLRequestStatus::FAILED; | 460 response_status_ = net::URLRequestStatus::FAILED; |
461 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0", | 461 GURL url(base::StringPrintf("http://%s:%d%s?test_step=0", |
462 host, port, kDBResetPath)); | 462 host, port, kDBResetPath)); |
463 // TODO(lzheng): We should have a way to reliably tell when a server is | 463 // TODO(lzheng): We should have a way to reliably tell when a server is |
464 // ready so we could get rid of the Sleep and retry loop. | 464 // ready so we could get rid of the Sleep and retry loop. |
465 while (true) { | 465 while (true) { |
466 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS) | 466 if (FetchUrl(url) == net::URLRequestStatus::SUCCESS) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 } | 526 } |
527 | 527 |
528 // Fetch a URL. If message_loop_started is true, starts the message loop | 528 // Fetch a URL. If message_loop_started is true, starts the message loop |
529 // so the caller could wait till OnURLFetchComplete is called. | 529 // so the caller could wait till OnURLFetchComplete is called. |
530 net::URLRequestStatus::Status FetchUrl(const GURL& url) { | 530 net::URLRequestStatus::Status FetchUrl(const GURL& url) { |
531 url_fetcher_.reset(net::URLFetcher::Create( | 531 url_fetcher_.reset(net::URLFetcher::Create( |
532 url, net::URLFetcher::GET, this)); | 532 url, net::URLFetcher::GET, this)); |
533 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 533 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
534 url_fetcher_->SetRequestContext(request_context_); | 534 url_fetcher_->SetRequestContext(request_context_); |
535 url_fetcher_->Start(); | 535 url_fetcher_->Start(); |
536 ui_test_utils::RunMessageLoop(); | 536 content::RunMessageLoop(); |
537 return response_status_; | 537 return response_status_; |
538 } | 538 } |
539 | 539 |
540 base::OneShotTimer<SafeBrowsingServiceTestHelper> check_update_timer_; | 540 base::OneShotTimer<SafeBrowsingServiceTestHelper> check_update_timer_; |
541 SafeBrowsingServiceTest* safe_browsing_test_; | 541 SafeBrowsingServiceTest* safe_browsing_test_; |
542 scoped_ptr<net::URLFetcher> url_fetcher_; | 542 scoped_ptr<net::URLFetcher> url_fetcher_; |
543 std::string response_data_; | 543 std::string response_data_; |
544 net::URLRequestStatus::Status response_status_; | 544 net::URLRequestStatus::Status response_status_; |
545 net::URLRequestContextGetter* request_context_; | 545 net::URLRequestContextGetter* request_context_; |
546 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); | 546 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTestHelper); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 645 } |
646 | 646 |
647 // Verifies with server if test is done and waits till server responses. | 647 // Verifies with server if test is done and waits till server responses. |
648 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 648 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
649 safe_browsing_helper->VerifyTestComplete(server_host, | 649 safe_browsing_helper->VerifyTestComplete(server_host, |
650 server_port, | 650 server_port, |
651 last_step)); | 651 last_step)); |
652 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 652 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
653 test_server.Stop(); | 653 test_server.Stop(); |
654 } | 654 } |
OLD | NEW |