| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/safe_browsing/browser_features.h" | 19 #include "chrome/browser/safe_browsing/browser_features.h" |
| 19 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 20 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.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" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 rfh = web_contents()->GetMainFrame(); | 143 rfh = web_contents()->GetMainFrame(); |
| 143 } | 144 } |
| 144 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); | 145 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); |
| 145 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( | 146 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( |
| 146 rfh, ++page_id, pending_id, true, url, | 147 rfh, ++page_id, pending_id, true, url, |
| 147 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type); | 148 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type); |
| 148 } | 149 } |
| 149 | 150 |
| 150 bool ExtractFeatures(ClientPhishingRequest* request) { | 151 bool ExtractFeatures(ClientPhishingRequest* request) { |
| 151 StartExtractFeatures(request); | 152 StartExtractFeatures(request); |
| 152 base::MessageLoop::current()->Run(); | 153 base::RunLoop().Run(); |
| 153 EXPECT_EQ(1U, success_.count(request)); | 154 EXPECT_EQ(1U, success_.count(request)); |
| 154 return success_.count(request) ? success_[request] : false; | 155 return success_.count(request) ? success_[request] : false; |
| 155 } | 156 } |
| 156 | 157 |
| 157 void StartExtractFeatures(ClientPhishingRequest* request) { | 158 void StartExtractFeatures(ClientPhishingRequest* request) { |
| 158 success_.erase(request); | 159 success_.erase(request); |
| 159 ++num_pending_; | 160 ++num_pending_; |
| 160 extractor_->ExtractFeatures( | 161 extractor_->ExtractFeatures( |
| 161 browse_info_.get(), | 162 browse_info_.get(), |
| 162 request, | 163 request, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 request.set_url("http://www.foo.com/bar.html"); | 334 request.set_url("http://www.foo.com/bar.html"); |
| 334 request.set_client_score(0.5); | 335 request.set_client_score(0.5); |
| 335 StartExtractFeatures(&request); | 336 StartExtractFeatures(&request); |
| 336 | 337 |
| 337 SimpleNavigateAndCommit(GURL("http://www.foo.com/goo.html")); | 338 SimpleNavigateAndCommit(GURL("http://www.foo.com/goo.html")); |
| 338 ClientPhishingRequest request2; | 339 ClientPhishingRequest request2; |
| 339 request2.set_url("http://www.foo.com/goo.html"); | 340 request2.set_url("http://www.foo.com/goo.html"); |
| 340 request2.set_client_score(1.0); | 341 request2.set_client_score(1.0); |
| 341 StartExtractFeatures(&request2); | 342 StartExtractFeatures(&request2); |
| 342 | 343 |
| 343 base::MessageLoop::current()->Run(); | 344 base::RunLoop().Run(); |
| 344 EXPECT_TRUE(success_[&request]); | 345 EXPECT_TRUE(success_[&request]); |
| 345 // Success is false because the second URL is not in the history and we are | 346 // Success is false because the second URL is not in the history and we are |
| 346 // not able to distinguish between a missing URL in the history and an error. | 347 // not able to distinguish between a missing URL in the history and an error. |
| 347 EXPECT_FALSE(success_[&request2]); | 348 EXPECT_FALSE(success_[&request2]); |
| 348 } | 349 } |
| 349 | 350 |
| 350 TEST_F(BrowserFeatureExtractorTest, BrowseFeatures) { | 351 TEST_F(BrowserFeatureExtractorTest, BrowseFeatures) { |
| 351 history_service()->AddPage(GURL("http://www.foo.com/"), | 352 history_service()->AddPage(GURL("http://www.foo.com/"), |
| 352 base::Time::Now(), | 353 base::Time::Now(), |
| 353 history::SOURCE_BROWSED); | 354 history::SOURCE_BROWSED); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 // First ip is good but all the others are bad. | 653 // First ip is good but all the others are bad. |
| 653 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); | 654 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); |
| 654 } | 655 } |
| 655 | 656 |
| 656 ExtractMalwareFeatures(&request); | 657 ExtractMalwareFeatures(&request); |
| 657 // The number of IP matched url we store is capped at 5 IPs per request. | 658 // The number of IP matched url we store is capped at 5 IPs per request. |
| 658 EXPECT_EQ(5, request.bad_ip_url_info_size()); | 659 EXPECT_EQ(5, request.bad_ip_url_info_size()); |
| 659 } | 660 } |
| 660 | 661 |
| 661 } // namespace safe_browsing | 662 } // namespace safe_browsing |
| OLD | NEW |