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

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

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 months 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) 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.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/test_tab_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/page_transition_types.h" 24 #include "content/public/common/page_transition_types.h"
25 #include "content/public/common/referrer.h" 25 #include "content/public/common/referrer.h"
26 #include "content/public/browser/navigation_controller.h"
26 #include "content/test/test_browser_thread.h" 27 #include "content/test/test_browser_thread.h"
28 #include "content/test/web_contents_tester.h"
27 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
28 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
30 32
31 using ::testing::Return; 33 using ::testing::Return;
32 using ::testing::StrictMock; 34 using ::testing::StrictMock;
33 using content::BrowserThread; 35 using content::BrowserThread;
36 using content::WebContentsTester;
34 37
35 namespace safe_browsing { 38 namespace safe_browsing {
36 namespace { 39 namespace {
37 class MockClientSideDetectionService : public ClientSideDetectionService { 40 class MockClientSideDetectionService : public ClientSideDetectionService {
38 public: 41 public:
39 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} 42 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {}
40 virtual ~MockClientSideDetectionService() {}; 43 virtual ~MockClientSideDetectionService() {};
41 44
42 MOCK_CONST_METHOD1(IsBadIpAddress, bool(const std::string&)); 45 MOCK_CONST_METHOD1(IsBadIpAddress, bool(const std::string&));
43 }; 46 };
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // This is similar to NavigateAndCommit that is in test_tab_contents, but 92 // This is similar to NavigateAndCommit that is in test_tab_contents, but
90 // allows us to specify the referrer and page_transition_type. 93 // allows us to specify the referrer and page_transition_type.
91 void NavigateAndCommit(const GURL& url, 94 void NavigateAndCommit(const GURL& url,
92 const GURL& referrer, 95 const GURL& referrer,
93 content::PageTransition type) { 96 content::PageTransition type) {
94 contents()->GetController().LoadURL( 97 contents()->GetController().LoadURL(
95 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), 98 url, content::Referrer(referrer, WebKit::WebReferrerPolicyDefault),
96 type, std::string()); 99 type, std::string());
97 100
98 static int page_id = 0; 101 static int page_id = 0;
99 content::RenderViewHost* rvh = contents()->pending_rvh(); 102 content::RenderViewHost* rvh =
103 WebContentsTester::For(contents())->pending_rvh();
100 if (!rvh) { 104 if (!rvh) {
101 rvh = contents()->GetRenderViewHost(); 105 rvh = contents()->GetRenderViewHost();
102 } 106 }
103 contents()->ProceedWithCrossSiteNavigation(); 107 WebContentsTester::For(contents())->ProceedWithCrossSiteNavigation();
104 contents()->TestDidNavigateWithReferrer( 108 WebContentsTester::For(contents())->TestDidNavigateWithReferrer(
105 rvh, ++page_id, url, 109 rvh, ++page_id, url,
106 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type); 110 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), type);
107 } 111 }
108 112
109 bool ExtractFeatures(ClientPhishingRequest* request) { 113 bool ExtractFeatures(ClientPhishingRequest* request) {
110 StartExtractFeatures(request); 114 StartExtractFeatures(request);
111 MessageLoop::current()->Run(); 115 MessageLoop::current()->Run();
112 EXPECT_EQ(1U, success_.count(request)); 116 EXPECT_EQ(1U, success_.count(request));
113 return success_.count(request) ? success_[request] : false; 117 return success_.count(request) ? success_[request] : false;
114 } 118 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 EXPECT_TRUE(features.count(StringPrintf("%s%s", 499 EXPECT_TRUE(features.count(StringPrintf("%s%s",
496 features::kSafeBrowsingMaliciousUrl, 500 features::kSafeBrowsingMaliciousUrl,
497 "http://www.malware.com/"))); 501 "http://www.malware.com/")));
498 EXPECT_TRUE(features.count(StringPrintf("%s%s", 502 EXPECT_TRUE(features.count(StringPrintf("%s%s",
499 features::kSafeBrowsingOriginalUrl, 503 features::kSafeBrowsingOriginalUrl,
500 "http://www.good.com/"))); 504 "http://www.good.com/")));
501 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); 505 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]);
502 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); 506 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]);
503 } 507 }
504 } // namespace safe_browsing 508 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/safe_browsing/client_side_detection_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698