Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review. Tweak comments and list initializer. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/referrer.h" 31 #include "content/public/common/referrer.h"
31 #include "content/public/test/test_browser_thread.h" 32 #include "content/public/test/test_browser_thread.h"
32 #include "content/public/test/web_contents_tester.h" 33 #include "content/public/test/web_contents_tester.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 #include "ui/base/page_transition_types.h" 36 #include "ui/base/page_transition_types.h"
36 #include "url/gurl.h" 37 #include "url/gurl.h"
37 38
38 using content::BrowserThread; 39 using content::BrowserThread;
39 using content::ResourceType; 40 using content::ResourceType;
40 using content::WebContentsTester; 41 using content::WebContentsTester;
41 42
42 using testing::DoAll; 43 using testing::DoAll;
43 using testing::Return; 44 using testing::Return;
44 using testing::StrictMock; 45 using testing::StrictMock;
45 46
46 namespace safe_browsing { 47 namespace safe_browsing {
47 48
48 namespace { 49 namespace {
49 50
50 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { 51 class MockSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager {
51 public: 52 public:
52 explicit MockSafeBrowsingDatabaseManager( 53 MockSafeBrowsingDatabaseManager() {}
53 const scoped_refptr<SafeBrowsingService>& service)
54 : SafeBrowsingDatabaseManager(service) { }
55 54
56 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); 55 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address));
57 56
58 protected: 57 protected:
59 virtual ~MockSafeBrowsingDatabaseManager() {} 58 virtual ~MockSafeBrowsingDatabaseManager() {}
60 59
61 private: 60 private:
62 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); 61 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager);
63 }; 62 };
64 63
(...skipping 12 matching lines...) Expand all
77 }; 76 };
78 } // namespace 77 } // namespace
79 78
80 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { 79 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness {
81 protected: 80 protected:
82 void SetUp() override { 81 void SetUp() override {
83 ChromeRenderViewHostTestHarness::SetUp(); 82 ChromeRenderViewHostTestHarness::SetUp();
84 ASSERT_TRUE(profile()->CreateHistoryService( 83 ASSERT_TRUE(profile()->CreateHistoryService(
85 true /* delete_file */, false /* no_db */)); 84 true /* delete_file */, false /* no_db */));
86 85
87 db_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>( 86 db_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>();
88 SafeBrowsingService::CreateSafeBrowsingService());
89 host_.reset(new StrictMock<MockClientSideDetectionHost>( 87 host_.reset(new StrictMock<MockClientSideDetectionHost>(
90 web_contents(), db_manager_.get())); 88 web_contents(), db_manager_.get()));
91 extractor_.reset( 89 extractor_.reset(
92 new BrowserFeatureExtractor(web_contents(), host_.get())); 90 new BrowserFeatureExtractor(web_contents(), host_.get()));
93 num_pending_ = 0; 91 num_pending_ = 0;
94 browse_info_.reset(new BrowseInfo); 92 browse_info_.reset(new BrowseInfo);
95 } 93 }
96 94
97 void TearDown() override { 95 void TearDown() override {
98 extractor_.reset(); 96 extractor_.reset();
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // First ip is good but all the others are bad. 651 // First ip is good but all the others are bad.
654 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); 652 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0));
655 } 653 }
656 654
657 ExtractMalwareFeatures(&request); 655 ExtractMalwareFeatures(&request);
658 // The number of IP matched url we store is capped at 5 IPs per request. 656 // The number of IP matched url we store is capped at 5 IPs per request.
659 EXPECT_EQ(5, request.bad_ip_url_info_size()); 657 EXPECT_EQ(5, request.bad_ip_url_info_size());
660 } 658 }
661 659
662 } // namespace safe_browsing 660 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698