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

Side by Side Diff: chrome/renderer/safe_browsing/phishing_classifier_browsertest.cc

Issue 105493002: Use base namespace for string16 in chrome/renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 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/renderer/safe_browsing/phishing_classifier.h" 5 #include "chrome/renderer/safe_browsing/phishing_classifier.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 clock_)); 96 clock_));
97 } 97 }
98 98
99 virtual void TearDownOnMainThread() OVERRIDE { 99 virtual void TearDownOnMainThread() OVERRIDE {
100 content::RunAllPendingInMessageLoop(); 100 content::RunAllPendingInMessageLoop();
101 } 101 }
102 102
103 // Helper method to start phishing classification and wait for it to 103 // Helper method to start phishing classification and wait for it to
104 // complete. Returns the true if the page is classified as phishy and 104 // complete. Returns the true if the page is classified as phishy and
105 // false otherwise. 105 // false otherwise.
106 bool RunPhishingClassifier(const string16* page_text, 106 bool RunPhishingClassifier(const base::string16* page_text,
107 float* phishy_score, 107 float* phishy_score,
108 FeatureMap* features) { 108 FeatureMap* features) {
109 ClientPhishingRequest verdict; 109 ClientPhishingRequest verdict;
110 // The classifier accesses the RenderView and must run in the RenderThread. 110 // The classifier accesses the RenderView and must run in the RenderThread.
111 PostTaskToInProcessRendererAndWait( 111 PostTaskToInProcessRendererAndWait(
112 base::Bind(&PhishingClassifierTest::DoRunPhishingClassifier, 112 base::Bind(&PhishingClassifierTest::DoRunPhishingClassifier,
113 base::Unretained(this), 113 base::Unretained(this),
114 page_text, phishy_score, features, &verdict)); 114 page_text, phishy_score, features, &verdict));
115 return verdict.is_phishing(); 115 return verdict.is_phishing();
116 } 116 }
117 117
118 void DoRunPhishingClassifier(const string16* page_text, 118 void DoRunPhishingClassifier(const base::string16* page_text,
119 float* phishy_score, 119 float* phishy_score,
120 FeatureMap* features, 120 FeatureMap* features,
121 ClientPhishingRequest* verdict) { 121 ClientPhishingRequest* verdict) {
122 *phishy_score = PhishingClassifier::kInvalidScore; 122 *phishy_score = PhishingClassifier::kInvalidScore;
123 features->Clear(); 123 features->Clear();
124 124
125 // Force synchronous behavior for ease of unittesting. 125 // Force synchronous behavior for ease of unittesting.
126 base::RunLoop run_loop; 126 base::RunLoop run_loop;
127 classifier_->BeginClassification( 127 classifier_->BeginClassification(
128 page_text, 128 page_text,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ASSERT_FALSE(classifier_->is_ready()); 211 ASSERT_FALSE(classifier_->is_ready());
212 212
213 // Now set the scorer. 213 // Now set the scorer.
214 classifier_->set_phishing_scorer(scorer_.get()); 214 classifier_->set_phishing_scorer(scorer_.get());
215 ASSERT_TRUE(classifier_->is_ready()); 215 ASSERT_TRUE(classifier_->is_ready());
216 216
217 // This test doesn't exercise the extraction timing. 217 // This test doesn't exercise the extraction timing.
218 EXPECT_CALL(*clock_, Now()) 218 EXPECT_CALL(*clock_, Now())
219 .WillRepeatedly(::testing::Return(base::TimeTicks::Now())); 219 .WillRepeatedly(::testing::Return(base::TimeTicks::Now()));
220 220
221 string16 page_text = ASCIIToUTF16("login"); 221 base::string16 page_text = ASCIIToUTF16("login");
222 float phishy_score; 222 float phishy_score;
223 FeatureMap features; 223 FeatureMap features;
224 224
225 LoadHtml("host.net", 225 LoadHtml("host.net",
226 "<html><body><a href=\"http://phishing.com/\">login</a></body></html>"); 226 "<html><body><a href=\"http://phishing.com/\">login</a></body></html>");
227 EXPECT_TRUE(RunPhishingClassifier(&page_text, &phishy_score, &features)); 227 EXPECT_TRUE(RunPhishingClassifier(&page_text, &phishy_score, &features));
228 // Note: features.features() might contain other features that simply aren't 228 // Note: features.features() might contain other features that simply aren't
229 // in the model. 229 // in the model.
230 EXPECT_THAT(features.features(), 230 EXPECT_THAT(features.features(),
231 AllOf(Contains(Pair(url_tld_token_net_, 1.0)), 231 AllOf(Contains(Pair(url_tld_token_net_, 1.0)),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Now set the scorer. 281 // Now set the scorer.
282 classifier_->set_phishing_scorer(scorer_.get()); 282 classifier_->set_phishing_scorer(scorer_.get());
283 EXPECT_TRUE(classifier_->is_ready()); 283 EXPECT_TRUE(classifier_->is_ready());
284 284
285 // Set a NULL scorer, which turns detection back off. 285 // Set a NULL scorer, which turns detection back off.
286 classifier_->set_phishing_scorer(NULL); 286 classifier_->set_phishing_scorer(NULL);
287 EXPECT_FALSE(classifier_->is_ready()); 287 EXPECT_FALSE(classifier_->is_ready());
288 } 288 }
289 289
290 } // namespace safe_browsing 290 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/renderer/safe_browsing/phishing_classifier.cc ('k') | chrome/renderer/safe_browsing/phishing_classifier_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698