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

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

Issue 1358513003: Use correct IntToString variants in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 // Note that although this is not a "browser" test, it runs as part of 5 // Note that although this is not a "browser" test, it runs as part of
6 // browser_tests. This is because WebKit does not work properly if it is 6 // browser_tests. This is because WebKit does not work properly if it is
7 // shutdown and re-initialized. Since browser_tests runs each test in a 7 // shutdown and re-initialized. Since browser_tests runs each test in a
8 // new process, this avoids the problem. 8 // new process, this avoids the problem.
9 9
10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" 10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 expected_features.AddBooleanFeature(features::kPageHasForms); 198 expected_features.AddBooleanFeature(features::kPageHasForms);
199 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.25); 199 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.25);
200 expected_features.AddBooleanFeature(features::kPageHasTextInputs); 200 expected_features.AddBooleanFeature(features::kPageHasTextInputs);
201 expected_features.AddBooleanFeature(features::kPageHasCheckInputs); 201 expected_features.AddBooleanFeature(features::kPageHasCheckInputs);
202 expected_features.AddBooleanFeature(features::kPageActionURL + 202 expected_features.AddBooleanFeature(features::kPageActionURL +
203 std::string("http://cgi.host.com/submit")); 203 std::string("http://cgi.host.com/submit"));
204 expected_features.AddBooleanFeature(features::kPageActionURL + 204 expected_features.AddBooleanFeature(features::kPageActionURL +
205 std::string("http://other.com/")); 205 std::string("http://other.com/"));
206 expected_features.AddBooleanFeature(features::kPageActionURL + 206 expected_features.AddBooleanFeature(features::kPageActionURL +
207 std::string("http://host.com:") + 207 std::string("http://host.com:") +
208 base::IntToString(embedded_test_server_->port()) + 208 base::UintToString(embedded_test_server_->port()) +
209 std::string("/query")); 209 std::string("/query"));
210 210
211 FeatureMap features; 211 FeatureMap features;
212 LoadHtml( 212 LoadHtml(
213 "host.com", 213 "host.com",
214 "<html><head><body>" 214 "<html><head><body>"
215 "<form action=\"query\"><input type=text><input type=checkbox></form>" 215 "<form action=\"query\"><input type=text><input type=checkbox></form>"
216 "<form action=\"http://cgi.host.com/submit\"></form>" 216 "<form action=\"http://cgi.host.com/submit\"></form>"
217 "<form action=\"http://other.com/\"></form>" 217 "<form action=\"http://other.com/\"></form>"
218 "<form action=\"query\"></form>" 218 "<form action=\"query\"></form>"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 net::SpawnedTestServer https_server( 283 net::SpawnedTestServer https_server(
284 net::SpawnedTestServer::TYPE_HTTPS, 284 net::SpawnedTestServer::TYPE_HTTPS,
285 net::SpawnedTestServer::kLocalhost, 285 net::SpawnedTestServer::kLocalhost,
286 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 286 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
287 ASSERT_TRUE(https_server.Start()); 287 ASSERT_TRUE(https_server.Start());
288 288
289 // The PhishingDOMFeatureExtractor depends on URLs being domains and not IPs, 289 // The PhishingDOMFeatureExtractor depends on URLs being domains and not IPs,
290 // so use a domain. 290 // so use a domain.
291 std::string url_str = "https://host.com:"; 291 std::string url_str = "https://host.com:";
292 url_str += base::IntToString(https_server.host_port_pair().port()); 292 url_str += base::UintToString(https_server.host_port_pair().port());
293 url_str += "/files/safe_browsing/secure_link_features.html"; 293 url_str += "/files/safe_browsing/secure_link_features.html";
294 ui_test_utils::NavigateToURL(browser(), GURL(url_str)); 294 ui_test_utils::NavigateToURL(browser(), GURL(url_str));
295 295
296 // Click through the certificate error interstitial. 296 // Click through the certificate error interstitial.
297 content::InterstitialPage* interstitial_page = 297 content::InterstitialPage* interstitial_page =
298 GetWebContents()->GetInterstitialPage(); 298 GetWebContents()->GetInterstitialPage();
299 interstitial_page->Proceed(); 299 interstitial_page->Proceed();
300 content::WaitForLoadStop(GetWebContents()); 300 content::WaitForLoadStop(GetWebContents());
301 301
302 features.Clear(); 302 features.Clear();
(...skipping 30 matching lines...) Expand all
333 features.Clear(); 333 features.Clear();
334 net::SpawnedTestServer https_server( 334 net::SpawnedTestServer https_server(
335 net::SpawnedTestServer::TYPE_HTTPS, 335 net::SpawnedTestServer::TYPE_HTTPS,
336 net::SpawnedTestServer::kLocalhost, 336 net::SpawnedTestServer::kLocalhost,
337 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 337 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
338 ASSERT_TRUE(https_server.Start()); 338 ASSERT_TRUE(https_server.Start());
339 339
340 // The PhishingDOMFeatureExtractor depends on URLs being domains and not IPs, 340 // The PhishingDOMFeatureExtractor depends on URLs being domains and not IPs,
341 // so use a domain. 341 // so use a domain.
342 std::string url_str = "https://host.com:"; 342 std::string url_str = "https://host.com:";
343 url_str += base::IntToString(https_server.host_port_pair().port()); 343 url_str += base::UintToString(https_server.host_port_pair().port());
344 url_str += "/files/safe_browsing/secure_script_and_image.html"; 344 url_str += "/files/safe_browsing/secure_script_and_image.html";
345 ui_test_utils::NavigateToURL(browser(), GURL(url_str)); 345 ui_test_utils::NavigateToURL(browser(), GURL(url_str));
346 346
347 // Click through the certificate error interstitial. 347 // Click through the certificate error interstitial.
348 content::InterstitialPage* interstitial_page = 348 content::InterstitialPage* interstitial_page =
349 GetWebContents()->GetInterstitialPage(); 349 GetWebContents()->GetInterstitialPage();
350 interstitial_page->Proceed(); 350 interstitial_page->Proceed();
351 content::WaitForLoadStop(GetWebContents()); 351 content::WaitForLoadStop(GetWebContents());
352 352
353 ASSERT_TRUE(ExtractFeatures(&features)); 353 ASSERT_TRUE(ExtractFeatures(&features));
354 ExpectFeatureMapsAreEqual(features, expected_features); 354 ExpectFeatureMapsAreEqual(features, expected_features);
355 } 355 }
356 356
357 IN_PROC_BROWSER_TEST_F(PhishingDOMFeatureExtractorTest, SubFrames) { 357 IN_PROC_BROWSER_TEST_F(PhishingDOMFeatureExtractorTest, SubFrames) {
358 // This test doesn't exercise the extraction timing. 358 // This test doesn't exercise the extraction timing.
359 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); 359 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now()));
360 360
361 // Test that features are aggregated across all frames. 361 // Test that features are aggregated across all frames.
362 362
363 std::string port = base::IntToString(embedded_test_server_->port()); 363 std::string port = base::UintToString(embedded_test_server_->port());
364 responses_[GetURL("host2.com", "").spec()] = 364 responses_[GetURL("host2.com", "").spec()] =
365 "<html><head><script></script><body>" 365 "<html><head><script></script><body>"
366 "<form action=\"http://host4.com/\"><input type=checkbox></form>" 366 "<form action=\"http://host4.com/\"><input type=checkbox></form>"
367 "<form action=\"http://host2.com/submit\"></form>" 367 "<form action=\"http://host2.com/submit\"></form>"
368 "<a href=\"http://www.host2.com/home\">link</a>" 368 "<a href=\"http://www.host2.com/home\">link</a>"
369 "<iframe src=\"nested.html\"></iframe>" 369 "<iframe src=\"nested.html\"></iframe>"
370 "<body></html>"; 370 "<body></html>";
371 371
372 responses_[GetURL("host2.com", "nested.html").spec()] = 372 responses_[GetURL("host2.com", "nested.html").spec()] =
373 "<html><body><input type=password>" 373 "<html><body><input type=password>"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Time check after the last 10 elements. 467 // Time check after the last 10 elements.
468 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(54))) 468 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(54)))
469 // A final time check for the histograms. 469 // A final time check for the histograms.
470 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(56))); 470 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(56)));
471 471
472 FeatureMap expected_features; 472 FeatureMap expected_features;
473 expected_features.AddBooleanFeature(features::kPageHasForms); 473 expected_features.AddBooleanFeature(features::kPageHasForms);
474 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.5); 474 expected_features.AddRealFeature(features::kPageActionOtherDomainFreq, 0.5);
475 expected_features.AddBooleanFeature(features::kPageActionURL + 475 expected_features.AddBooleanFeature(features::kPageActionURL +
476 std::string("http://host.com:") + 476 std::string("http://host.com:") +
477 base::IntToString(embedded_test_server_->port()) + 477 base::UintToString(embedded_test_server_->port()) +
478 std::string("/ondomain")); 478 std::string("/ondomain"));
479 expected_features.AddBooleanFeature(features::kPageActionURL + 479 expected_features.AddBooleanFeature(features::kPageActionURL +
480 std::string("http://host2.com/")); 480 std::string("http://host2.com/"));
481 481
482 FeatureMap features; 482 FeatureMap features;
483 LoadHtml("host.com", response); 483 LoadHtml("host.com", response);
484 ASSERT_TRUE(ExtractFeatures(&features)); 484 ASSERT_TRUE(ExtractFeatures(&features));
485 ExpectFeatureMapsAreEqual(features, expected_features); 485 ExpectFeatureMapsAreEqual(features, expected_features);
486 // Make sure none of the mock expectations carry over to the next test. 486 // Make sure none of the mock expectations carry over to the next test.
487 ::testing::Mock::VerifyAndClearExpectations(&clock_); 487 ::testing::Mock::VerifyAndClearExpectations(&clock_);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 LoadHtml( 546 LoadHtml(
547 "host.com", 547 "host.com",
548 "<html><head></head><body>" 548 "<html><head></head><body>"
549 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>" 549 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>"
550 "<form></form></body></html>"); 550 "<form></form></body></html>");
551 ASSERT_TRUE(ExtractFeatures(&features)); 551 ASSERT_TRUE(ExtractFeatures(&features));
552 ExpectFeatureMapsAreEqual(features, expected_features); 552 ExpectFeatureMapsAreEqual(features, expected_features);
553 } 553 }
554 554
555 } // namespace safe_browsing 555 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698