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/ui_manager.h" | 21 #include "chrome/browser/safe_browsing/ui_manager.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "components/history/core/browser/history_backend.h" | 25 #include "components/history/core/browser/history_backend.h" |
26 #include "components/history/core/browser/history_service.h" | 26 #include "components/history/core/browser/history_service.h" |
27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/navigation_entry.h" | |
29 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/referrer.h" | 29 #include "content/public/common/referrer.h" |
31 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
32 #include "content/public/test/web_contents_tester.h" | 31 #include "content/public/test/web_contents_tester.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "ui/base/page_transition_types.h" | 34 #include "ui/base/page_transition_types.h" |
36 #include "url/gurl.h" | 35 #include "url/gurl.h" |
37 | 36 |
38 using content::BrowserThread; | 37 using content::BrowserThread; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 125 } |
127 | 126 |
128 // This is similar to NavigateAndCommit that is in WebContentsTester, but | 127 // This is similar to NavigateAndCommit that is in WebContentsTester, but |
129 // allows us to specify the referrer and page_transition_type. | 128 // allows us to specify the referrer and page_transition_type. |
130 void NavigateAndCommit(const GURL& url, | 129 void NavigateAndCommit(const GURL& url, |
131 const GURL& referrer, | 130 const GURL& referrer, |
132 ui::PageTransition type) { | 131 ui::PageTransition type) { |
133 web_contents()->GetController().LoadURL( | 132 web_contents()->GetController().LoadURL( |
134 url, content::Referrer(referrer, blink::WebReferrerPolicyDefault), | 133 url, content::Referrer(referrer, blink::WebReferrerPolicyDefault), |
135 type, std::string()); | 134 type, std::string()); |
136 int pending_id = | |
137 web_contents()->GetController().GetPendingEntry()->GetUniqueID(); | |
138 | 135 |
139 static int page_id = 0; | 136 static int page_id = 0; |
140 content::RenderFrameHost* rfh = | 137 content::RenderFrameHost* rfh = |
141 WebContentsTester::For(web_contents())->GetPendingMainFrame(); | 138 WebContentsTester::For(web_contents())->GetPendingMainFrame(); |
142 if (!rfh) { | 139 if (!rfh) { |
143 rfh = web_contents()->GetMainFrame(); | 140 rfh = web_contents()->GetMainFrame(); |
144 } | 141 } |
145 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); | 142 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); |
146 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( | 143 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( |
147 rfh, ++page_id, pending_id, true, url, | 144 rfh, ++page_id, url, |
148 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type); | 145 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type); |
149 } | 146 } |
150 | 147 |
151 bool ExtractFeatures(ClientPhishingRequest* request) { | 148 bool ExtractFeatures(ClientPhishingRequest* request) { |
152 StartExtractFeatures(request); | 149 StartExtractFeatures(request); |
153 base::MessageLoop::current()->Run(); | 150 base::MessageLoop::current()->Run(); |
154 EXPECT_EQ(1U, success_.count(request)); | 151 EXPECT_EQ(1U, success_.count(request)); |
155 return success_.count(request) ? success_[request] : false; | 152 return success_.count(request) ? success_[request] : false; |
156 } | 153 } |
157 | 154 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 // First ip is good but all the others are bad. | 650 // First ip is good but all the others are bad. |
654 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); | 651 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); |
655 } | 652 } |
656 | 653 |
657 ExtractMalwareFeatures(&request); | 654 ExtractMalwareFeatures(&request); |
658 // The number of IP matched url we store is capped at 5 IPs per request. | 655 // 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()); | 656 EXPECT_EQ(5, request.bad_ip_url_info_size()); |
660 } | 657 } |
661 | 658 |
662 } // namespace safe_browsing | 659 } // namespace safe_browsing |
OLD | NEW |