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 30 matching lines...) Expand all Loading... |
41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
42 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
43 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
44 #include "content/public/browser/browser_context.h" | 44 #include "content/public/browser/browser_context.h" |
45 #include "content/public/test/test_browser_thread.h" | 45 #include "content/public/test/test_browser_thread.h" |
46 #include "content/public/test/test_utils.h" | 46 #include "content/public/test/test_utils.h" |
47 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
48 #include "net/dns/host_resolver.h" | 48 #include "net/dns/host_resolver.h" |
49 #include "net/log/net_log.h" | 49 #include "net/log/net_log.h" |
50 #include "net/test/python_utils.h" | 50 #include "net/test/python_utils.h" |
| 51 #include "net/test/spawned_test_server/spawned_test_server.h" |
51 #include "net/url_request/url_fetcher.h" | 52 #include "net/url_request/url_fetcher.h" |
52 #include "net/url_request/url_fetcher_delegate.h" | 53 #include "net/url_request/url_fetcher_delegate.h" |
53 #include "net/url_request/url_request_status.h" | 54 #include "net/url_request/url_request_status.h" |
54 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
55 | 56 |
56 using content::BrowserThread; | 57 using content::BrowserThread; |
57 | 58 |
58 #ifndef SAFE_BROWSING_DB_LOCAL | 59 #ifndef SAFE_BROWSING_DB_LOCAL |
59 #error This test requires the SAFE_BROWSING_DB_LOCAL implementation. | 60 #error This test requires the SAFE_BROWSING_DB_LOCAL implementation. |
60 #endif | 61 #endif |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 248 |
248 bool is_update_scheduled() { | 249 bool is_update_scheduled() { |
249 base::AutoLock l(update_status_mutex_); | 250 base::AutoLock l(update_status_mutex_); |
250 return is_update_scheduled_; | 251 return is_update_scheduled_; |
251 } | 252 } |
252 | 253 |
253 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() { | 254 scoped_refptr<base::SequencedTaskRunner> SafeBrowsingTaskRunner() { |
254 return local_database_manager()->safe_browsing_task_runner_; | 255 return local_database_manager()->safe_browsing_task_runner_; |
255 } | 256 } |
256 | 257 |
257 const net::SpawnedTestServer& test_server() const { | 258 const net::SpawnedTestServer& spawned_test_server() const { |
258 return *test_server_; | 259 return *test_server_; |
259 } | 260 } |
260 | 261 |
261 protected: | 262 protected: |
262 bool InitSafeBrowsingService() { | 263 bool InitSafeBrowsingService() { |
263 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 264 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
264 return safe_browsing_service_ != NULL; | 265 return safe_browsing_service_ != NULL; |
265 } | 266 } |
266 | 267 |
267 void SetUp() override { | 268 void SetUp() override { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 safe_browsing_helper->UpdateStatus(); | 534 safe_browsing_helper->UpdateStatus(); |
534 EXPECT_TRUE(is_database_ready()); | 535 EXPECT_TRUE(is_database_ready()); |
535 EXPECT_FALSE(is_update_scheduled()); | 536 EXPECT_FALSE(is_update_scheduled()); |
536 EXPECT_FALSE(last_update().is_null()); | 537 EXPECT_FALSE(last_update().is_null()); |
537 if (last_update() < now) { | 538 if (last_update() < now) { |
538 // This means no data available anymore. | 539 // This means no data available anymore. |
539 break; | 540 break; |
540 } | 541 } |
541 | 542 |
542 // Fetches URLs to verify and waits till server responses with data. | 543 // Fetches URLs to verify and waits till server responses with data. |
543 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 544 EXPECT_EQ( |
544 safe_browsing_helper->FetchUrlsToVerify(test_server(), step)); | 545 net::URLRequestStatus::SUCCESS, |
| 546 safe_browsing_helper->FetchUrlsToVerify(spawned_test_server(), step)); |
545 | 547 |
546 std::vector<PhishingUrl> phishing_urls; | 548 std::vector<PhishingUrl> phishing_urls; |
547 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), | 549 EXPECT_TRUE(ParsePhishingUrls(safe_browsing_helper->response_data(), |
548 &phishing_urls)); | 550 &phishing_urls)); |
549 EXPECT_GT(phishing_urls.size(), 0U); | 551 EXPECT_GT(phishing_urls.size(), 0U); |
550 for (size_t j = 0; j < phishing_urls.size(); ++j) { | 552 for (size_t j = 0; j < phishing_urls.size(); ++j) { |
551 // Verifes with server if a URL is a phishing URL and waits till server | 553 // Verifes with server if a URL is a phishing URL and waits till server |
552 // responses. | 554 // responses. |
553 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); | 555 safe_browsing_helper->CheckUrl(GURL(phishing_urls[j].url)); |
554 if (phishing_urls[j].is_phishing) { | 556 if (phishing_urls[j].is_phishing) { |
555 EXPECT_TRUE(is_checked_url_in_db()) | 557 EXPECT_TRUE(is_checked_url_in_db()) |
556 << phishing_urls[j].url | 558 << phishing_urls[j].url |
557 << " is_phishing: " << phishing_urls[j].is_phishing | 559 << " is_phishing: " << phishing_urls[j].is_phishing |
558 << " test step: " << step; | 560 << " test step: " << step; |
559 EXPECT_FALSE(is_checked_url_safe()) | 561 EXPECT_FALSE(is_checked_url_safe()) |
560 << phishing_urls[j].url | 562 << phishing_urls[j].url |
561 << " is_phishing: " << phishing_urls[j].is_phishing | 563 << " is_phishing: " << phishing_urls[j].is_phishing |
562 << " test step: " << step; | 564 << " test step: " << step; |
563 } else { | 565 } else { |
564 EXPECT_TRUE(is_checked_url_safe()) | 566 EXPECT_TRUE(is_checked_url_safe()) |
565 << phishing_urls[j].url | 567 << phishing_urls[j].url |
566 << " is_phishing: " << phishing_urls[j].is_phishing | 568 << " is_phishing: " << phishing_urls[j].is_phishing |
567 << " test step: " << step; | 569 << " test step: " << step; |
568 } | 570 } |
569 } | 571 } |
570 // TODO(lzheng): We should verify the fetched database with local | 572 // TODO(lzheng): We should verify the fetched database with local |
571 // database to make sure they match. | 573 // database to make sure they match. |
572 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 574 EXPECT_EQ( |
573 safe_browsing_helper->FetchDBToVerify(test_server(), step)); | 575 net::URLRequestStatus::SUCCESS, |
| 576 safe_browsing_helper->FetchDBToVerify(spawned_test_server(), step)); |
574 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 577 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
575 last_step = step; | 578 last_step = step; |
576 } | 579 } |
577 | 580 |
578 // Verifies with server if test is done and waits till server responses. | 581 // Verifies with server if test is done and waits till server responses. |
579 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 582 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
580 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); | 583 safe_browsing_helper->VerifyTestComplete(spawned_test_server(), |
| 584 last_step)); |
581 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 585 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
582 } | 586 } |
583 | 587 |
584 } // namespace safe_browsing | 588 } // namespace safe_browsing |
OLD | NEW |