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