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

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

Issue 8801003: Make TestTabContents::TestDidNavigate not take a ViewHostMsg_FrameNavigate_Params, since that's a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Also get rid of content usage and remove the method Created 9 years 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) 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 89 }
89 90
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(url, referrer, type, std::string()); 96 contents()->controller().LoadURL(url, referrer, type, std::string());
96 97
97 static int page_id = 0; 98 static int page_id = 0;
98 ViewHostMsg_FrameNavigate_Params params;
99 InitNavigateParams(&params, ++page_id, url, type);
100 params.referrer =
101 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault);
102
103 RenderViewHost* rvh = contents()->pending_rvh(); 99 RenderViewHost* rvh = contents()->pending_rvh();
104 if (!rvh) { 100 if (!rvh) {
105 rvh = contents()->render_view_host(); 101 rvh = contents()->render_view_host();
106 } 102 }
107 contents()->ProceedWithCrossSiteNavigation(); 103 contents()->ProceedWithCrossSiteNavigation();
108 contents()->TestDidNavigate(rvh, params); 104 contents()->TestDidNavigateWithReferrer(
105 rvh, ++page_id, url,
106 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type);
109 } 107 }
110 108
111 bool ExtractFeatures(ClientPhishingRequest* request) { 109 bool ExtractFeatures(ClientPhishingRequest* request) {
112 StartExtractFeatures(request); 110 StartExtractFeatures(request);
113 MessageLoop::current()->Run(); 111 MessageLoop::current()->Run();
114 EXPECT_EQ(1U, success_.count(request)); 112 EXPECT_EQ(1U, success_.count(request));
115 return success_.count(request) ? success_[request] : false; 113 return success_.count(request) ? success_[request] : false;
116 } 114 }
117 115
118 void StartExtractFeatures(ClientPhishingRequest* request) { 116 void StartExtractFeatures(ClientPhishingRequest* request) {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 EXPECT_TRUE(features.count(StringPrintf("%s%s", 495 EXPECT_TRUE(features.count(StringPrintf("%s%s",
498 features::kSafeBrowsingMaliciousUrl, 496 features::kSafeBrowsingMaliciousUrl,
499 "http://www.malware.com/"))); 497 "http://www.malware.com/")));
500 EXPECT_TRUE(features.count(StringPrintf("%s%s", 498 EXPECT_TRUE(features.count(StringPrintf("%s%s",
501 features::kSafeBrowsingOriginalUrl, 499 features::kSafeBrowsingOriginalUrl,
502 "http://www.good.com/"))); 500 "http://www.good.com/")));
503 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); 501 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]);
504 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); 502 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]);
505 } 503 }
506 } // namespace safe_browsing 504 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698