OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 ClientPhishingRequest request; | 481 ClientPhishingRequest request; |
482 request.set_url("http://host.com/"); | 482 request.set_url("http://host.com/"); |
483 request.set_client_score(0.8f); | 483 request.set_client_score(0.8f); |
484 | 484 |
485 history_service()->AddPage(GURL("http://host.com/"), | 485 history_service()->AddPage(GURL("http://host.com/"), |
486 history::SOURCE_BROWSED); | 486 history::SOURCE_BROWSED); |
487 contents()->NavigateAndCommit(GURL("http://host.com/")); | 487 contents()->NavigateAndCommit(GURL("http://host.com/")); |
488 | 488 |
489 EXPECT_TRUE(ExtractFeatures(&request)); | 489 EXPECT_TRUE(ExtractFeatures(&request)); |
490 EXPECT_EQ(crypto::SHA256HashString("host.com/").substr( | 490 EXPECT_EQ(crypto::SHA256HashString("host.com/").substr( |
491 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | 491 0, BrowserFeatureExtractor::kHashPrefixLength), |
492 request.suffix_prefix_hash()); | 492 request.hash_prefix()); |
493 | 493 |
494 request.set_url("http://www.host.com/path/"); | 494 request.set_url("http://www.host.com/path/"); |
495 history_service()->AddPage(GURL("http://www.host.com/path/"), | 495 history_service()->AddPage(GURL("http://www.host.com/path/"), |
496 history::SOURCE_BROWSED); | 496 history::SOURCE_BROWSED); |
497 contents()->NavigateAndCommit(GURL("http://www.host.com/path/")); | 497 contents()->NavigateAndCommit(GURL("http://www.host.com/path/")); |
498 | 498 |
499 EXPECT_TRUE(ExtractFeatures(&request)); | 499 EXPECT_TRUE(ExtractFeatures(&request)); |
500 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/").substr( | 500 EXPECT_EQ(crypto::SHA256HashString("host.com/path/").substr( |
501 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | 501 0, BrowserFeatureExtractor::kHashPrefixLength), |
502 request.suffix_prefix_hash()); | 502 request.hash_prefix()); |
503 | 503 |
504 request.set_url("http://user@www.host.com:1111/path/123?args"); | 504 request.set_url("http://user@www.host.com:1111/path/123?args"); |
505 history_service()->AddPage( | 505 history_service()->AddPage( |
506 GURL("http://user@www.host.com:1111/path/123?args"), | 506 GURL("http://user@www.host.com:1111/path/123?args"), |
507 history::SOURCE_BROWSED); | 507 history::SOURCE_BROWSED); |
508 contents()->NavigateAndCommit( | 508 contents()->NavigateAndCommit( |
509 GURL("http://user@www.host.com:1111/path/123?args")); | 509 GURL("http://user@www.host.com:1111/path/123?args")); |
510 | 510 |
511 EXPECT_TRUE(ExtractFeatures(&request)); | 511 EXPECT_TRUE(ExtractFeatures(&request)); |
512 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/123").substr( | 512 EXPECT_EQ(crypto::SHA256HashString("host.com/path/").substr( |
513 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | 513 0, BrowserFeatureExtractor::kHashPrefixLength), |
514 request.suffix_prefix_hash()); | 514 request.hash_prefix()); |
515 | 515 |
516 // Check that escaping matches the SafeBrowsing specification. | 516 // Check that escaping matches the SafeBrowsing specification. |
517 request.set_url("http://www.host.com/A%21//B"); | 517 request.set_url("http://www.host.com/A%21//B"); |
518 history_service()->AddPage(GURL("http://www.host.com/A%21//B"), | 518 history_service()->AddPage(GURL("http://www.host.com/A%21//B"), |
519 history::SOURCE_BROWSED); | 519 history::SOURCE_BROWSED); |
520 contents()->NavigateAndCommit(GURL("http://www.host.com/A%21//B")); | 520 contents()->NavigateAndCommit(GURL("http://www.host.com/A%21//B")); |
521 | 521 |
522 EXPECT_TRUE(ExtractFeatures(&request)); | 522 EXPECT_TRUE(ExtractFeatures(&request)); |
523 EXPECT_EQ(crypto::SHA256HashString("www.host.com/A!/B").substr( | 523 EXPECT_EQ(crypto::SHA256HashString("host.com/a!/").substr( |
524 0, BrowserFeatureExtractor::kSuffixPrefixHashLength), | 524 0, BrowserFeatureExtractor::kHashPrefixLength), |
525 request.suffix_prefix_hash()); | 525 request.hash_prefix()); |
526 } | 526 } |
527 } // namespace safe_browsing | 527 } // namespace safe_browsing |
OLD | NEW |