OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 12 #include "base/message_loop.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
16 #include "chrome/browser/history/history_backend.h" | 16 #include "chrome/browser/history/history_backend.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/browser_features.h" | 18 #include "chrome/browser/safe_browsing/browser_features.h" |
19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
20 #include "chrome/common/safe_browsing/csd.pb.h" | 20 #include "chrome/common/safe_browsing/csd.pb.h" |
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
22 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/browser/tab_contents/test_tab_contents.h" | 24 #include "content/browser/tab_contents/test_tab_contents.h" |
25 #include "content/common/view_messages.h" | |
26 #include "content/public/common/page_transition_types.h" | 25 #include "content/public/common/page_transition_types.h" |
| 26 #include "content/public/common/referrer.h" |
27 #include "content/test/test_browser_thread.h" | 27 #include "content/test/test_browser_thread.h" |
28 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebReferrerPolicy.h" |
31 | 32 |
32 using ::testing::Return; | 33 using ::testing::Return; |
33 using ::testing::StrictMock; | 34 using ::testing::StrictMock; |
34 using content::BrowserThread; | 35 using content::BrowserThread; |
35 | 36 |
36 namespace safe_browsing { | 37 namespace safe_browsing { |
37 namespace { | 38 namespace { |
38 class MockClientSideDetectionService : public ClientSideDetectionService { | 39 class MockClientSideDetectionService : public ClientSideDetectionService { |
39 public: | 40 public: |
40 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} | 41 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // This is similar to NavigateAndCommit that is in test_tab_contents, but | 91 // This is similar to NavigateAndCommit that is in test_tab_contents, but |
91 // allows us to specify the referrer and page_transition_type. | 92 // allows us to specify the referrer and page_transition_type. |
92 void NavigateAndCommit(const GURL& url, | 93 void NavigateAndCommit(const GURL& url, |
93 const GURL& referrer, | 94 const GURL& referrer, |
94 content::PageTransition type) { | 95 content::PageTransition type) { |
95 contents()->controller().LoadURL( | 96 contents()->controller().LoadURL( |
96 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), | 97 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), |
97 type, std::string()); | 98 type, std::string()); |
98 | 99 |
99 static int page_id = 0; | 100 static int page_id = 0; |
100 ViewHostMsg_FrameNavigate_Params params; | |
101 InitNavigateParams(¶ms, ++page_id, url, type); | |
102 params.referrer = | |
103 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault); | |
104 | |
105 RenderViewHost* rvh = contents()->pending_rvh(); | 101 RenderViewHost* rvh = contents()->pending_rvh(); |
106 if (!rvh) { | 102 if (!rvh) { |
107 rvh = contents()->render_view_host(); | 103 rvh = contents()->render_view_host(); |
108 } | 104 } |
109 contents()->ProceedWithCrossSiteNavigation(); | 105 contents()->ProceedWithCrossSiteNavigation(); |
110 contents()->TestDidNavigate(rvh, params); | 106 contents()->TestDidNavigateWithReferrer( |
| 107 rvh, ++page_id, url, |
| 108 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type); |
111 } | 109 } |
112 | 110 |
113 bool ExtractFeatures(ClientPhishingRequest* request) { | 111 bool ExtractFeatures(ClientPhishingRequest* request) { |
114 StartExtractFeatures(request); | 112 StartExtractFeatures(request); |
115 MessageLoop::current()->Run(); | 113 MessageLoop::current()->Run(); |
116 EXPECT_EQ(1U, success_.count(request)); | 114 EXPECT_EQ(1U, success_.count(request)); |
117 return success_.count(request) ? success_[request] : false; | 115 return success_.count(request) ? success_[request] : false; |
118 } | 116 } |
119 | 117 |
120 void StartExtractFeatures(ClientPhishingRequest* request) { | 118 void StartExtractFeatures(ClientPhishingRequest* request) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 497 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
500 features::kSafeBrowsingMaliciousUrl, | 498 features::kSafeBrowsingMaliciousUrl, |
501 "http://www.malware.com/"))); | 499 "http://www.malware.com/"))); |
502 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 500 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
503 features::kSafeBrowsingOriginalUrl, | 501 features::kSafeBrowsingOriginalUrl, |
504 "http://www.good.com/"))); | 502 "http://www.good.com/"))); |
505 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); | 503 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); |
506 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); | 504 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); |
507 } | 505 } |
508 } // namespace safe_browsing | 506 } // namespace safe_browsing |
OLD | NEW |