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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 bool is_update_scheduled() { | 246 bool is_update_scheduled() { |
247 base::AutoLock l(update_status_mutex_); | 247 base::AutoLock l(update_status_mutex_); |
248 return is_update_scheduled_; | 248 return is_update_scheduled_; |
249 } | 249 } |
250 | 250 |
251 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() { | 251 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() { |
252 return local_database_manager()->safe_browsing_task_runner_; | 252 return local_database_manager()->safe_browsing_task_runner_; |
253 } | 253 } |
254 | 254 |
255 const net::SpawnedTestServer& test_server() const { | 255 const net::SpawnedTestServer& spawned_test_server() const { |
256 return *test_server_; | 256 return *test_server_; |
257 } | 257 } |
258 | 258 |
259 protected: | 259 protected: |
260 bool InitSafeBrowsingService() { | 260 bool InitSafeBrowsingService() { |
261 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 261 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
262 return safe_browsing_service_ != NULL; | 262 return safe_browsing_service_ != NULL; |
263 } | 263 } |
264 | 264 |
265 void SetUp() override { | 265 void SetUp() override { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 safe_browsing_helper->UpdateStatus(); | 531 safe_browsing_helper->UpdateStatus(); |
532 EXPECT_TRUE(is_database_ready()); | 532 EXPECT_TRUE(is_database_ready()); |
533 EXPECT_FALSE(is_update_scheduled()); | 533 EXPECT_FALSE(is_update_scheduled()); |
534 EXPECT_FALSE(last_update().is_null()); | 534 EXPECT_FALSE(last_update().is_null()); |
535 if (last_update() < now) { | 535 if (last_update() < now) { |
536 // This means no data available anymore. | 536 // This means no data available anymore. |
537 break; | 537 break; |
538 } | 538 } |
539 | 539 |
540 // Fetches URLs to verify and waits till server responses with data. | 540 // Fetches URLs to verify and waits till server responses with data. |
541 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 541 EXPECT_EQ( |
542 safe_browsing_helper->FetchUrlsToVerify(test_server(), step)); | 542 net::URLRequestStatus::SUCCESS, |
| 543 safe_browsing_helper->FetchUrlsToVerify(spawned_test_server(), step)); |
543 | 544 |
544 std::vector<PhishingUrl> phishing_urls; | 545 std::vector<PhishingUrl> phishing_urls; |
545 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 546 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
546 &phishing_urls)); | 547 &phishing_urls)); |
547 EXPECT_GT(phishing_urls.size(), 0U); | 548 EXPECT_GT(phishing_urls.size(), 0U); |
548 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 549 for (size_t j = 0; j < phishing_urls.size(); ++j) { |
549 // Verifes with server if a URL is a phishing URL and waits till server | 550 // Verifes with server if a URL is a phishing URL and waits till server |
550 // responses. | 551 // responses. |
551 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 552 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
552 if (phishing_urls[j].is_phishing) { | 553 if (phishing_urls[j].is_phishing) { |
553 EXPECT_TRUE(is_checked_url_in_db()) | 554 EXPECT_TRUE(is_checked_url_in_db()) |
554 << phishing_urls[j].url | 555 << phishing_urls[j].url |
555 << " is_phishing: " << phishing_urls[j].is_phishing | 556 << " is_phishing: " << phishing_urls[j].is_phishing |
556 << " test step: " << step; | 557 << " test step: " << step; |
557 EXPECT_FALSE(is_checked_url_safe()) | 558 EXPECT_FALSE(is_checked_url_safe()) |
558 << phishing_urls[j].url | 559 << phishing_urls[j].url |
559 << " is_phishing: " << phishing_urls[j].is_phishing | 560 << " is_phishing: " << phishing_urls[j].is_phishing |
560 << " test step: " << step; | 561 << " test step: " << step; |
561 } else { | 562 } else { |
562 EXPECT_TRUE(is_checked_url_safe()) | 563 EXPECT_TRUE(is_checked_url_safe()) |
563 << phishing_urls[j].url | 564 << phishing_urls[j].url |
564 << " is_phishing: " << phishing_urls[j].is_phishing | 565 << " is_phishing: " << phishing_urls[j].is_phishing |
565 << " test step: " << step; | 566 << " test step: " << step; |
566 } | 567 } |
567 } | 568 } |
568 // TODO(lzheng): We should verify the fetched database with local | 569 // TODO(lzheng): We should verify the fetched database with local |
569 // database to make sure they match. | 570 // database to make sure they match. |
570 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 571 EXPECT_EQ( |
571 safe_browsing_helper->FetchDBToVerify(test_server(), step)); | 572 net::URLRequestStatus::SUCCESS, |
| 573 safe_browsing_helper->FetchDBToVerify(spawned_test_server(), step)); |
572 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 574 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
573 last_step = step; | 575 last_step = step; |
574 } | 576 } |
575 | 577 |
576 // 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. |
577 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 579 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
578 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); | 580 safe_browsing_helper->VerifyTestComplete(spawned_test_server(), |
| 581 last_step)); |
579 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 582 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
580 } | 583 } |
OLD | NEW |