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 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 rvh = web_contents()->GetRenderViewHost(); | 109 rvh = web_contents()->GetRenderViewHost(); |
110 } | 110 } |
111 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); | 111 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); |
112 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( | 112 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( |
113 rvh, ++page_id, url, | 113 rvh, ++page_id, url, |
114 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type); | 114 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type); |
115 } | 115 } |
116 | 116 |
117 bool ExtractFeatures(ClientPhishingRequest* request) { | 117 bool ExtractFeatures(ClientPhishingRequest* request) { |
118 StartExtractFeatures(request); | 118 StartExtractFeatures(request); |
119 MessageLoop::current()->Run(); | 119 base::MessageLoop::current()->Run(); |
120 EXPECT_EQ(1U, success_.count(request)); | 120 EXPECT_EQ(1U, success_.count(request)); |
121 return success_.count(request) ? success_[request] : false; | 121 return success_.count(request) ? success_[request] : false; |
122 } | 122 } |
123 | 123 |
124 void StartExtractFeatures(ClientPhishingRequest* request) { | 124 void StartExtractFeatures(ClientPhishingRequest* request) { |
125 success_.erase(request); | 125 success_.erase(request); |
126 ++num_pending_; | 126 ++num_pending_; |
127 extractor_->ExtractFeatures( | 127 extractor_->ExtractFeatures( |
128 browse_info_.get(), | 128 browse_info_.get(), |
129 request, | 129 request, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 scoped_ptr<BrowserFeatureExtractor> extractor_; | 166 scoped_ptr<BrowserFeatureExtractor> extractor_; |
167 std::map<ClientPhishingRequest*, bool> success_; | 167 std::map<ClientPhishingRequest*, bool> success_; |
168 scoped_ptr<BrowseInfo> browse_info_; | 168 scoped_ptr<BrowseInfo> browse_info_; |
169 scoped_ptr<MockClientSideDetectionService> service_; | 169 scoped_ptr<MockClientSideDetectionService> service_; |
170 | 170 |
171 private: | 171 private: |
172 void ExtractFeaturesDone(bool success, ClientPhishingRequest* request) { | 172 void ExtractFeaturesDone(bool success, ClientPhishingRequest* request) { |
173 ASSERT_EQ(0U, success_.count(request)); | 173 ASSERT_EQ(0U, success_.count(request)); |
174 success_[request] = success; | 174 success_[request] = success; |
175 if (--num_pending_ == 0) { | 175 if (--num_pending_ == 0) { |
176 MessageLoop::current()->Quit(); | 176 base::MessageLoop::current()->Quit(); |
177 } | 177 } |
178 } | 178 } |
179 }; | 179 }; |
180 | 180 |
181 TEST_F(BrowserFeatureExtractorTest, UrlNotInHistory) { | 181 TEST_F(BrowserFeatureExtractorTest, UrlNotInHistory) { |
182 ClientPhishingRequest request; | 182 ClientPhishingRequest request; |
183 SimpleNavigateAndCommit(GURL("http://www.google.com")); | 183 SimpleNavigateAndCommit(GURL("http://www.google.com")); |
184 request.set_url("http://www.google.com/"); | 184 request.set_url("http://www.google.com/"); |
185 request.set_client_score(0.5); | 185 request.set_client_score(0.5); |
186 EXPECT_FALSE(ExtractFeatures(&request)); | 186 EXPECT_FALSE(ExtractFeatures(&request)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 request.set_url("http://www.foo.com/bar.html"); | 272 request.set_url("http://www.foo.com/bar.html"); |
273 request.set_client_score(0.5); | 273 request.set_client_score(0.5); |
274 StartExtractFeatures(&request); | 274 StartExtractFeatures(&request); |
275 | 275 |
276 SimpleNavigateAndCommit(GURL("http://www.foo.com/goo.html")); | 276 SimpleNavigateAndCommit(GURL("http://www.foo.com/goo.html")); |
277 ClientPhishingRequest request2; | 277 ClientPhishingRequest request2; |
278 request2.set_url("http://www.foo.com/goo.html"); | 278 request2.set_url("http://www.foo.com/goo.html"); |
279 request2.set_client_score(1.0); | 279 request2.set_client_score(1.0); |
280 StartExtractFeatures(&request2); | 280 StartExtractFeatures(&request2); |
281 | 281 |
282 MessageLoop::current()->Run(); | 282 base::MessageLoop::current()->Run(); |
283 EXPECT_TRUE(success_[&request]); | 283 EXPECT_TRUE(success_[&request]); |
284 // Success is false because the second URL is not in the history and we are | 284 // Success is false because the second URL is not in the history and we are |
285 // not able to distinguish between a missing URL in the history and an error. | 285 // not able to distinguish between a missing URL in the history and an error. |
286 EXPECT_FALSE(success_[&request2]); | 286 EXPECT_FALSE(success_[&request2]); |
287 } | 287 } |
288 | 288 |
289 TEST_F(BrowserFeatureExtractorTest, BrowseFeatures) { | 289 TEST_F(BrowserFeatureExtractorTest, BrowseFeatures) { |
290 history_service()->AddPage(GURL("http://www.foo.com/"), | 290 history_service()->AddPage(GURL("http://www.foo.com/"), |
291 base::Time::Now(), | 291 base::Time::Now(), |
292 history::SOURCE_BROWSED); | 292 history::SOURCE_BROWSED); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); | 575 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); |
576 feature_name = base::StringPrintf("%s%s", features::kBadIpFetch, | 576 feature_name = base::StringPrintf("%s%s", features::kBadIpFetch, |
577 "92.92.92.92"); | 577 "92.92.92.92"); |
578 EXPECT_TRUE(features.count(feature_name)); | 578 EXPECT_TRUE(features.count(feature_name)); |
579 hosts = features[feature_name]; | 579 hosts = features[feature_name]; |
580 EXPECT_EQ(2U, hosts.size()); | 580 EXPECT_EQ(2U, hosts.size()); |
581 EXPECT_TRUE(hosts.find("bad.com") != hosts.end()); | 581 EXPECT_TRUE(hosts.find("bad.com") != hosts.end()); |
582 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); | 582 EXPECT_TRUE(hosts.find("evil.com") != hosts.end()); |
583 } | 583 } |
584 } // namespace safe_browsing | 584 } // namespace safe_browsing |
OLD | NEW |