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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 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 | Annotate | Revision Log
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
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/navigation_controller.h" 25 #include "content/public/browser/navigation_controller.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/page_transition_types.h" 27 #include "content/public/common/page_transition_types.h"
28 #include "content/public/common/referrer.h" 28 #include "content/public/common/referrer.h"
29 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
30 #include "content/public/test/web_contents_tester.h" 30 #include "content/public/test/web_contents_tester.h"
31 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 using ::testing::Return;
36 using ::testing::StrictMock;
37 using content::BrowserThread;
38 using content::WebContentsTester; 35 using content::WebContentsTester;
36 using testing::Return;
37 using testing::StrictMock;
39 38
40 namespace safe_browsing { 39 namespace safe_browsing {
41 namespace { 40 namespace {
42 class MockClientSideDetectionService : public ClientSideDetectionService { 41 class MockClientSideDetectionService : public ClientSideDetectionService {
43 public: 42 public:
44 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} 43 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {}
45 virtual ~MockClientSideDetectionService() {}; 44 virtual ~MockClientSideDetectionService() {};
46 45
47 MOCK_CONST_METHOD1(IsBadIpAddress, bool(const std::string&)); 46 MOCK_CONST_METHOD1(IsBadIpAddress, bool(const std::string&));
48 }; 47 };
49 } // namespace 48 } // namespace
50 49
51 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { 50 class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness {
52 protected: 51 protected:
53 BrowserFeatureExtractorTest()
54 : ui_thread_(BrowserThread::UI, &message_loop_) {
55 }
56
57 virtual void SetUp() { 52 virtual void SetUp() {
58 ChromeRenderViewHostTestHarness::SetUp(); 53 ChromeRenderViewHostTestHarness::SetUp();
59 profile()->CreateHistoryService(true /* delete_file */, false /* no_db */); 54 profile()->CreateHistoryService(true /* delete_file */, false /* no_db */);
60 service_.reset(new StrictMock<MockClientSideDetectionService>()); 55 service_.reset(new StrictMock<MockClientSideDetectionService>());
61 extractor_.reset( 56 extractor_.reset(
62 new BrowserFeatureExtractor(web_contents(), service_.get())); 57 new BrowserFeatureExtractor(web_contents(), service_.get()));
63 num_pending_ = 0; 58 num_pending_ = 0;
64 browse_info_.reset(new BrowseInfo); 59 browse_info_.reset(new BrowseInfo);
65 } 60 }
66 61
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 request.feature_map(i); 149 request.feature_map(i);
155 EXPECT_EQ(0U, features->count(feature.name())); 150 EXPECT_EQ(0U, features->count(feature.name()));
156 std::set<std::string> meta_infos; 151 std::set<std::string> meta_infos;
157 for (int j = 0; j < feature.metainfo_size(); ++j) { 152 for (int j = 0; j < feature.metainfo_size(); ++j) {
158 meta_infos.insert(feature.metainfo(j)); 153 meta_infos.insert(feature.metainfo(j));
159 } 154 }
160 (*features)[feature.name()] = meta_infos; 155 (*features)[feature.name()] = meta_infos;
161 } 156 }
162 } 157 }
163 158
164 content::TestBrowserThread ui_thread_;
165 int num_pending_; 159 int num_pending_;
166 scoped_ptr<BrowserFeatureExtractor> extractor_; 160 scoped_ptr<BrowserFeatureExtractor> extractor_;
167 std::map<ClientPhishingRequest*, bool> success_; 161 std::map<ClientPhishingRequest*, bool> success_;
168 scoped_ptr<BrowseInfo> browse_info_; 162 scoped_ptr<BrowseInfo> browse_info_;
169 scoped_ptr<MockClientSideDetectionService> service_; 163 scoped_ptr<MockClientSideDetectionService> service_;
170 164
171 private: 165 private:
172 void ExtractFeaturesDone(bool success, ClientPhishingRequest* request) { 166 void ExtractFeaturesDone(bool success, ClientPhishingRequest* request) {
173 ASSERT_EQ(0U, success_.count(request)); 167 ASSERT_EQ(0U, success_.count(request));
174 success_[request] = success; 168 success_[request] = success;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); 569 EXPECT_TRUE(hosts.find("evil.com") != hosts.end());
576 feature_name = base::StringPrintf("%s%s", features::kBadIpFetch, 570 feature_name = base::StringPrintf("%s%s", features::kBadIpFetch,
577 "92.92.92.92"); 571 "92.92.92.92");
578 EXPECT_TRUE(features.count(feature_name)); 572 EXPECT_TRUE(features.count(feature_name));
579 hosts = features[feature_name]; 573 hosts = features[feature_name];
580 EXPECT_EQ(2U, hosts.size()); 574 EXPECT_EQ(2U, hosts.size());
581 EXPECT_TRUE(hosts.find("bad.com") != hosts.end()); 575 EXPECT_TRUE(hosts.find("bad.com") != hosts.end());
582 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); 576 EXPECT_TRUE(hosts.find("evil.com") != hosts.end());
583 } 577 }
584 } // namespace safe_browsing 578 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698