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

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

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: relax the dcheck Created 5 years, 7 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
OLDNEW
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"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/referrer.h" 30 #include "content/public/common/referrer.h"
30 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
31 #include "content/public/test/web_contents_tester.h" 32 #include "content/public/test/web_contents_tester.h"
32 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/page_transition_types.h" 35 #include "ui/base/page_transition_types.h"
35 #include "url/gurl.h" 36 #include "url/gurl.h"
36 37
37 using content::BrowserThread; 38 using content::BrowserThread;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 126 }
126 127
127 // This is similar to NavigateAndCommit that is in WebContentsTester, but 128 // This is similar to NavigateAndCommit that is in WebContentsTester, but
128 // allows us to specify the referrer and page_transition_type. 129 // allows us to specify the referrer and page_transition_type.
129 void NavigateAndCommit(const GURL& url, 130 void NavigateAndCommit(const GURL& url,
130 const GURL& referrer, 131 const GURL& referrer,
131 ui::PageTransition type) { 132 ui::PageTransition type) {
132 web_contents()->GetController().LoadURL( 133 web_contents()->GetController().LoadURL(
133 url, content::Referrer(referrer, blink::WebReferrerPolicyDefault), 134 url, content::Referrer(referrer, blink::WebReferrerPolicyDefault),
134 type, std::string()); 135 type, std::string());
136 int pending_id =
137 web_contents()->GetController().GetPendingEntry()->GetUniqueID();
135 138
136 static int page_id = 0; 139 static int page_id = 0;
137 content::RenderFrameHost* rfh = 140 content::RenderFrameHost* rfh =
138 WebContentsTester::For(web_contents())->GetPendingMainFrame(); 141 WebContentsTester::For(web_contents())->GetPendingMainFrame();
139 if (!rfh) { 142 if (!rfh) {
140 rfh = web_contents()->GetMainFrame(); 143 rfh = web_contents()->GetMainFrame();
141 } 144 }
142 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation(); 145 WebContentsTester::For(web_contents())->ProceedWithCrossSiteNavigation();
143 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer( 146 WebContentsTester::For(web_contents())->TestDidNavigateWithReferrer(
144 rfh, ++page_id, url, 147 rfh, ++page_id, pending_id, true, url,
145 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type); 148 content::Referrer(referrer, blink::WebReferrerPolicyDefault), type);
146 } 149 }
147 150
148 bool ExtractFeatures(ClientPhishingRequest* request) { 151 bool ExtractFeatures(ClientPhishingRequest* request) {
149 StartExtractFeatures(request); 152 StartExtractFeatures(request);
150 base::MessageLoop::current()->Run(); 153 base::MessageLoop::current()->Run();
151 EXPECT_EQ(1U, success_.count(request)); 154 EXPECT_EQ(1U, success_.count(request));
152 return success_.count(request) ? success_[request] : false; 155 return success_.count(request) ? success_[request] : false;
153 } 156 }
154 157
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // First ip is good but all the others are bad. 653 // First ip is good but all the others are bad.
651 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); 654 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0));
652 } 655 }
653 656
654 ExtractMalwareFeatures(&request); 657 ExtractMalwareFeatures(&request);
655 // 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.
656 EXPECT_EQ(5, request.bad_ip_url_info_size()); 659 EXPECT_EQ(5, request.bad_ip_url_info_size());
657 } 660 }
658 661
659 } // namespace safe_browsing 662 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/rlz/rlz_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698