OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/safe_browsing/protocol_manager.h" | 34 #include "chrome/browser/safe_browsing/protocol_manager.h" |
35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
38 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
39 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
40 #include "content/browser/browser_thread.h" | 40 #include "content/browser/browser_thread.h" |
41 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 41 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 42 #include "content/common/net/url_fetcher.h" |
| 43 #include "content/public/common/url_fetcher_delegate.h" |
42 #include "net/base/host_resolver.h" | 44 #include "net/base/host_resolver.h" |
43 #include "net/base/load_flags.h" | 45 #include "net/base/load_flags.h" |
44 #include "net/base/net_log.h" | 46 #include "net/base/net_log.h" |
45 #include "net/test/python_utils.h" | 47 #include "net/test/python_utils.h" |
46 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
47 | 49 |
48 namespace { | 50 namespace { |
49 | 51 |
50 const FilePath::CharType kDataFile[] = FILE_PATH_LITERAL("testing_input.dat"); | 52 const FilePath::CharType kDataFile[] = FILE_PATH_LITERAL("testing_input.dat"); |
51 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls"; | 53 const char kUrlVerifyPath[] = "/safebrowsing/verify_urls"; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 bool is_checked_url_safe_; | 346 bool is_checked_url_safe_; |
345 | 347 |
346 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest); | 348 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest); |
347 }; | 349 }; |
348 | 350 |
349 // A ref counted helper class that handles callbacks between IO thread and UI | 351 // A ref counted helper class that handles callbacks between IO thread and UI |
350 // thread. | 352 // thread. |
351 class SafeBrowsingServiceTestHelper | 353 class SafeBrowsingServiceTestHelper |
352 : public base::RefCountedThreadSafe<SafeBrowsingServiceTestHelper>, | 354 : public base::RefCountedThreadSafe<SafeBrowsingServiceTestHelper>, |
353 public SafeBrowsingService::Client, | 355 public SafeBrowsingService::Client, |
354 public URLFetcher::Delegate { | 356 public content::URLFetcherDelegate { |
355 public: | 357 public: |
356 explicit SafeBrowsingServiceTestHelper( | 358 explicit SafeBrowsingServiceTestHelper( |
357 SafeBrowsingServiceTest* safe_browsing_test) | 359 SafeBrowsingServiceTest* safe_browsing_test) |
358 : safe_browsing_test_(safe_browsing_test), | 360 : safe_browsing_test_(safe_browsing_test), |
359 response_status_(net::URLRequestStatus::FAILED) { | 361 response_status_(net::URLRequestStatus::FAILED) { |
360 } | 362 } |
361 | 363 |
362 // Callbacks for SafeBrowsingService::Client. | 364 // Callbacks for SafeBrowsingService::Client. |
363 virtual void OnBrowseUrlCheckResult( | 365 virtual void OnBrowseUrlCheckResult( |
364 const GURL& url, SafeBrowsingService::UrlCheckResult result) { | 366 const GURL& url, SafeBrowsingService::UrlCheckResult result) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 // 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, |
501 // this verification will fail. | 503 // this verification will fail. |
502 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, | 504 net::URLRequestStatus::Status VerifyTestComplete(const char* host, int port, |
503 int test_step) { | 505 int test_step) { |
504 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", | 506 GURL url(StringPrintf("http://%s:%d%s?test_step=%d", |
505 host, port, kTestCompletePath, test_step)); | 507 host, port, kTestCompletePath, test_step)); |
506 return FetchUrl(url); | 508 return FetchUrl(url); |
507 } | 509 } |
508 | 510 |
509 // Callback for URLFetcher. | 511 // Callback for URLFetcher. |
510 virtual void OnURLFetchComplete(const URLFetcher* source, | 512 virtual void OnURLFetchComplete(const URLFetcher* source) { |
511 const GURL& url, | 513 source->GetResponseAsString(&response_data_); |
512 const net::URLRequestStatus& status, | 514 response_status_ = source->status().status(); |
513 int response_code, | |
514 const net::ResponseCookies& cookies, | |
515 const std::string& data) { | |
516 response_data_ = data; | |
517 response_status_ = status.status(); | |
518 StopUILoop(); | 515 StopUILoop(); |
519 } | 516 } |
520 | 517 |
521 const std::string& response_data() { | 518 const std::string& response_data() { |
522 return response_data_; | 519 return response_data_; |
523 } | 520 } |
524 | 521 |
525 private: | 522 private: |
526 // Stops UI loop after desired status is updated. | 523 // Stops UI loop after desired status is updated. |
527 void StopUILoop() { | 524 void StopUILoop() { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 648 } |
652 | 649 |
653 // 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. |
654 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 651 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
655 safe_browsing_helper->VerifyTestComplete(server_host, | 652 safe_browsing_helper->VerifyTestComplete(server_host, |
656 server_port, | 653 server_port, |
657 last_step)); | 654 last_step)); |
658 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 655 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
659 test_server.Stop(); | 656 test_server.Stop(); |
660 } | 657 } |
OLD | NEW |