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

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

Issue 1431653003: Migrating tests to use EmbeddedTestServer (misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More test movement. Created 5 years, 1 month 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/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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 148
149 // Completion callback for classification. 149 // Completion callback for classification.
150 void ClassificationFinished(base::RunLoop* run_loop, 150 void ClassificationFinished(base::RunLoop* run_loop,
151 ClientPhishingRequest* verdict_out, 151 ClientPhishingRequest* verdict_out,
152 const ClientPhishingRequest& verdict) { 152 const ClientPhishingRequest& verdict) {
153 *verdict_out = verdict; // Copy the verdict. 153 *verdict_out = verdict; // Copy the verdict.
154 run_loop->Quit(); 154 run_loop->Quit();
155 } 155 }
156 156
157 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; 157 scoped_ptr<net::EmbeddedTestServer> embedded_test_server_;
158 net::test_server::EmbeddedTestServer* embedded_test_server() { 158 net::EmbeddedTestServer* embedded_test_server() {
159 // TODO(ajwong): Merge this into BrowserTestBase. 159 // TODO(ajwong): Merge this into BrowserTestBase.
mmenke 2015/11/05 17:38:13 Can we just address this in this CL? Same goes fo
svaldez 2015/11/05 18:15:55 Done.
160 if (!embedded_test_server_) { 160 if (!embedded_test_server_) {
161 embedded_test_server_.reset(new net::test_server::EmbeddedTestServer()); 161 embedded_test_server_.reset(new net::EmbeddedTestServer());
162 embedded_test_server_->RegisterRequestHandler( 162 embedded_test_server_->RegisterRequestHandler(
163 base::Bind(&PhishingClassifierTest::HandleRequest, 163 base::Bind(&PhishingClassifierTest::HandleRequest,
164 base::Unretained(this))); 164 base::Unretained(this)));
165 CHECK(embedded_test_server_->InitializeAndWaitUntilReady()); 165 CHECK(embedded_test_server_->Start());
166 } 166 }
167 return embedded_test_server_.get(); 167 return embedded_test_server_.get();
168 } 168 }
169 169
170 void LoadHtml(const std::string& host, const std::string& content) { 170 void LoadHtml(const std::string& host, const std::string& content) {
171 GURL::Replacements replace_host; 171 GURL::Replacements replace_host;
172 replace_host.SetHostStr(host); 172 replace_host.SetHostStr(host);
173 response_content_ = content; 173 response_content_ = content;
174 ui_test_utils::NavigateToURL( 174 ui_test_utils::NavigateToURL(
175 browser(), 175 browser(),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 EXPECT_GE(phishy_score, 0.0); 256 EXPECT_GE(phishy_score, 0.0);
257 EXPECT_LT(phishy_score, 0.5); 257 EXPECT_LT(phishy_score, 0.5);
258 258
259 // Extraction should fail for this case since there is no TLD. 259 // Extraction should fail for this case since there is no TLD.
260 LoadHtml("localhost", "<html><body>content</body></html>"); 260 LoadHtml("localhost", "<html><body>content</body></html>");
261 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); 261 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features));
262 EXPECT_EQ(0U, features.features().size()); 262 EXPECT_EQ(0U, features.features().size());
263 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); 263 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score);
264 264
265 // Extraction should also fail for this case because the URL is not http. 265 // Extraction should also fail for this case because the URL is not http.
266 net::SpawnedTestServer https_server( 266 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
267 net::SpawnedTestServer::TYPE_HTTPS, 267 https_server.ServeFilesFromSourceDirectory("chrome/test/data");
268 net::SpawnedTestServer::kLocalhost,
269 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
270 ASSERT_TRUE(https_server.Start()); 268 ASSERT_TRUE(https_server.Start());
271 GURL::Replacements replace_host; 269 GURL::Replacements replace_host;
272 replace_host.SetHostStr("host.net"); 270 replace_host.SetHostStr("host.net");
273 GURL test_url = https_server.GetURL("/files/title1.html"); 271 GURL test_url = https_server.GetURL("/title1.html");
274 ui_test_utils::NavigateToURL(browser(), 272 ui_test_utils::NavigateToURL(browser(),
275 test_url.ReplaceComponents(replace_host)); 273 test_url.ReplaceComponents(replace_host));
276 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); 274 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features));
277 EXPECT_EQ(0U, features.features().size()); 275 EXPECT_EQ(0U, features.features().size());
278 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); 276 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score);
279 277
280 // Extraction should fail for this case because the URL is a POST request. 278 // Extraction should fail for this case because the URL is a POST request.
281 LoadHtmlPost("host.net", "<html><body>content</body></html>"); 279 LoadHtmlPost("host.net", "<html><body>content</body></html>");
282 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); 280 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features));
283 EXPECT_EQ(0U, features.features().size()); 281 EXPECT_EQ(0U, features.features().size());
(...skipping 13 matching lines...) Expand all
297 // Now set the scorer. 295 // Now set the scorer.
298 classifier_->set_phishing_scorer(scorer_.get()); 296 classifier_->set_phishing_scorer(scorer_.get());
299 EXPECT_TRUE(classifier_->is_ready()); 297 EXPECT_TRUE(classifier_->is_ready());
300 298
301 // Set a NULL scorer, which turns detection back off. 299 // Set a NULL scorer, which turns detection back off.
302 classifier_->set_phishing_scorer(NULL); 300 classifier_->set_phishing_scorer(NULL);
303 EXPECT_FALSE(classifier_->is_ready()); 301 EXPECT_FALSE(classifier_->is_ready());
304 } 302 }
305 303
306 } // namespace safe_browsing 304 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698