| 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 #include <map> | 5 #include <map> |
| 6 #include <queue> | 6 #include <queue> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 15 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 16 #include "chrome/common/safe_browsing/client_model.pb.h" | 16 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 17 #include "chrome/common/safe_browsing/csd.pb.h" | 17 #include "chrome/common/safe_browsing/csd.pb.h" |
| 18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 #include "content/common/test_url_fetcher_factory.h" | |
| 20 #include "content/common/url_fetcher.h" | 19 #include "content/common/url_fetcher.h" |
| 20 #include "content/test/test_url_fetcher_factory.h" |
| 21 #include "crypto/sha2.h" | 21 #include "crypto/sha2.h" |
| 22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 23 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using ::testing::Mock; | 27 using ::testing::Mock; |
| 28 | 28 |
| 29 namespace safe_browsing { | 29 namespace safe_browsing { |
| 30 namespace { | 30 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 MessageLoop::current()->Quit(); | 43 MessageLoop::current()->Quit(); |
| 44 } | 44 } |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 class ClientSideDetectionServiceTest : public testing::Test { | 47 class ClientSideDetectionServiceTest : public testing::Test { |
| 48 protected: | 48 protected: |
| 49 virtual void SetUp() { | 49 virtual void SetUp() { |
| 50 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &msg_loop_)); | 50 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &msg_loop_)); |
| 51 | 51 |
| 52 factory_.reset(new FakeURLFetcherFactory()); | 52 factory_.reset(new FakeURLFetcherFactory()); |
| 53 URLFetcher::set_factory(factory_.get()); | |
| 54 | 53 |
| 55 browser_thread_.reset(new BrowserThread(BrowserThread::UI, &msg_loop_)); | 54 browser_thread_.reset(new BrowserThread(BrowserThread::UI, &msg_loop_)); |
| 56 } | 55 } |
| 57 | 56 |
| 58 virtual void TearDown() { | 57 virtual void TearDown() { |
| 59 msg_loop_.RunAllPending(); | 58 msg_loop_.RunAllPending(); |
| 60 csd_service_.reset(); | 59 csd_service_.reset(); |
| 61 URLFetcher::set_factory(NULL); | |
| 62 file_thread_.reset(); | 60 file_thread_.reset(); |
| 63 browser_thread_.reset(); | 61 browser_thread_.reset(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 bool SendClientReportPhishingRequest(const GURL& phishing_url, | 64 bool SendClientReportPhishingRequest(const GURL& phishing_url, |
| 67 float score) { | 65 float score) { |
| 68 ClientPhishingRequest* request = new ClientPhishingRequest(); | 66 ClientPhishingRequest* request = new ClientPhishingRequest(); |
| 69 request->set_url(phishing_url.spec()); | 67 request->set_url(phishing_url.spec()); |
| 70 request->set_client_score(score); | 68 request->set_client_score(score); |
| 71 request->set_is_phishing(true); // client thinks the URL is phishing. | 69 request->set_is_phishing(true); // client thinks the URL is phishing. |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 494 |
| 497 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.127.255")); | 495 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.127.255")); |
| 498 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.0")); | 496 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.0")); |
| 499 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.128.1")); | 497 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.128.1")); |
| 500 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.255")); | 498 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.255")); |
| 501 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.0")); | 499 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.0")); |
| 502 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.255")); | 500 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.255")); |
| 503 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.2.0.0")); | 501 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.2.0.0")); |
| 504 } | 502 } |
| 505 } // namespace safe_browsing | 503 } // namespace safe_browsing |
| OLD | NEW |