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 "chrome/test/testing_browser_process_test.h" |
18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
19 #include "content/common/url_fetcher.h" | 20 #include "content/common/url_fetcher.h" |
20 #include "content/test/test_url_fetcher_factory.h" | 21 #include "content/test/test_url_fetcher_factory.h" |
21 #include "crypto/sha2.h" | 22 #include "crypto/sha2.h" |
22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 using ::testing::Mock; | 28 using ::testing::Mock; |
28 | 29 |
29 namespace safe_browsing { | 30 namespace safe_browsing { |
30 namespace { | 31 namespace { |
31 class MockClientSideDetectionService : public ClientSideDetectionService { | 32 class MockClientSideDetectionService : public ClientSideDetectionService { |
32 public: | 33 public: |
33 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} | 34 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} |
34 virtual ~MockClientSideDetectionService() {} | 35 virtual ~MockClientSideDetectionService() {} |
35 | 36 |
36 MOCK_METHOD1(EndFetchModel, void(ClientModelStatus)); | 37 MOCK_METHOD1(EndFetchModel, void(ClientModelStatus)); |
37 | 38 |
38 private: | 39 private: |
39 DISALLOW_COPY_AND_ASSIGN(MockClientSideDetectionService); | 40 DISALLOW_COPY_AND_ASSIGN(MockClientSideDetectionService); |
40 }; | 41 }; |
41 | 42 |
42 ACTION(QuitCurrentMessageLoop) { | 43 ACTION(QuitCurrentMessageLoop) { |
43 MessageLoop::current()->Quit(); | 44 MessageLoop::current()->Quit(); |
44 } | 45 } |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 class ClientSideDetectionServiceTest : public testing::Test { | 48 class ClientSideDetectionServiceTest : public TestingBrowserProcessTest { |
48 protected: | 49 protected: |
49 virtual void SetUp() { | 50 virtual void SetUp() { |
50 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &msg_loop_)); | 51 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &msg_loop_)); |
51 | 52 |
52 factory_.reset(new FakeURLFetcherFactory()); | 53 factory_.reset(new FakeURLFetcherFactory()); |
53 | 54 |
54 browser_thread_.reset(new BrowserThread(BrowserThread::UI, &msg_loop_)); | 55 browser_thread_.reset(new BrowserThread(BrowserThread::UI, &msg_loop_)); |
55 } | 56 } |
56 | 57 |
57 virtual void TearDown() { | 58 virtual void TearDown() { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 495 |
495 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.127.255")); | 496 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.1.127.255")); |
496 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.0")); | 497 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.0")); |
497 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.128.1")); | 498 EXPECT_TRUE(csd_service_->IsBadIpAddress("::ffff:192.1.128.1")); |
498 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.255")); | 499 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.128.255")); |
499 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.0")); | 500 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.0")); |
500 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.255")); | 501 EXPECT_TRUE(csd_service_->IsBadIpAddress("192.1.255.255")); |
501 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.2.0.0")); | 502 EXPECT_FALSE(csd_service_->IsBadIpAddress("192.2.0.0")); |
502 } | 503 } |
503 } // namespace safe_browsing | 504 } // namespace safe_browsing |
OLD | NEW |