| 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 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/safe_browsing/browser_features.h" | 17 #include "chrome/browser/safe_browsing/browser_features.h" |
| 18 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 19 #include "chrome/browser/safe_browsing/database_manager.h" | 19 #include "chrome/browser/safe_browsing/database_manager.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 21 #include "chrome/browser/safe_browsing/test_database_manager.h" |
| 21 #include "chrome/browser/safe_browsing/ui_manager.h" | 22 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 22 #include "chrome/common/safe_browsing/csd.pb.h" | 23 #include "chrome/common/safe_browsing/csd.pb.h" |
| 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 25 #include "components/history/core/browser/history_backend.h" | 26 #include "components/history/core/browser/history_backend.h" |
| 26 #include "components/history/core/browser/history_service.h" | 27 #include "components/history/core/browser/history_service.h" |
| 27 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/referrer.h" | 30 #include "content/public/common/referrer.h" |
| 30 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
| 31 #include "content/public/test/web_contents_tester.h" | 32 #include "content/public/test/web_contents_tester.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "ui/base/page_transition_types.h" | 35 #include "ui/base/page_transition_types.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 36 | 37 |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| 38 using content::ResourceType; | 39 using content::ResourceType; |
| 39 using content::WebContentsTester; | 40 using content::WebContentsTester; |
| 40 | 41 |
| 41 using testing::DoAll; | 42 using testing::DoAll; |
| 42 using testing::Return; | 43 using testing::Return; |
| 43 using testing::StrictMock; | 44 using testing::StrictMock; |
| 44 | 45 |
| 45 namespace safe_browsing { | 46 namespace safe_browsing { |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { | 50 class MockSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager { |
| 50 public: | 51 public: |
| 51 explicit MockSafeBrowsingDatabaseManager( | 52 MockSafeBrowsingDatabaseManager() {} |
| 52 const scoped_refptr<SafeBrowsingService>& service) | |
| 53 : SafeBrowsingDatabaseManager(service) { } | |
| 54 | 53 |
| 55 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); | 54 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); |
| 56 | 55 |
| 57 protected: | 56 protected: |
| 58 virtual ~MockSafeBrowsingDatabaseManager() {} | 57 virtual ~MockSafeBrowsingDatabaseManager() {} |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); | 60 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); |
| 62 }; | 61 }; |
| 63 | 62 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 }; | 75 }; |
| 77 } // namespace | 76 } // namespace |
| 78 | 77 |
| 79 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { | 78 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { |
| 80 protected: | 79 protected: |
| 81 void SetUp() override { | 80 void SetUp() override { |
| 82 ChromeRenderViewHostTestHarness::SetUp(); | 81 ChromeRenderViewHostTestHarness::SetUp(); |
| 83 ASSERT_TRUE(profile()->CreateHistoryService( | 82 ASSERT_TRUE(profile()->CreateHistoryService( |
| 84 true /* delete_file */, false /* no_db */)); | 83 true /* delete_file */, false /* no_db */)); |
| 85 | 84 |
| 86 db_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>( | 85 db_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>(); |
| 87 SafeBrowsingService::CreateSafeBrowsingService()); | |
| 88 host_.reset(new StrictMock<MockClientSideDetectionHost>( | 86 host_.reset(new StrictMock<MockClientSideDetectionHost>( |
| 89 web_contents(), db_manager_.get())); | 87 web_contents(), db_manager_.get())); |
| 90 extractor_.reset( | 88 extractor_.reset( |
| 91 new BrowserFeatureExtractor(web_contents(), host_.get())); | 89 new BrowserFeatureExtractor(web_contents(), host_.get())); |
| 92 num_pending_ = 0; | 90 num_pending_ = 0; |
| 93 browse_info_.reset(new BrowseInfo); | 91 browse_info_.reset(new BrowseInfo); |
| 94 } | 92 } |
| 95 | 93 |
| 96 void TearDown() override { | 94 void TearDown() override { |
| 97 extractor_.reset(); | 95 extractor_.reset(); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 // First ip is good but all the others are bad. | 648 // First ip is good but all the others are bad. |
| 651 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); | 649 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); |
| 652 } | 650 } |
| 653 | 651 |
| 654 ExtractMalwareFeatures(&request); | 652 ExtractMalwareFeatures(&request); |
| 655 // The number of IP matched url we store is capped at 5 IPs per request. | 653 // The number of IP matched url we store is capped at 5 IPs per request. |
| 656 EXPECT_EQ(5, request.bad_ip_url_info_size()); | 654 EXPECT_EQ(5, request.bad_ip_url_info_size()); |
| 657 } | 655 } |
| 658 | 656 |
| 659 } // namespace safe_browsing | 657 } // namespace safe_browsing |
| OLD | NEW |