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

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

Issue 7793012: Change the client-side phishing detection hashing function to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 ClientSideDetectionService::MODEL_NOT_CHANGED)) 659 ClientSideDetectionService::MODEL_NOT_CHANGED))
660 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); 660 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable));
661 csd_service_->SetEnabled(true); 661 csd_service_->SetEnabled(true);
662 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); 662 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f));
663 Mock::VerifyAndClearExpectations(service); 663 Mock::VerifyAndClearExpectations(service);
664 } 664 }
665 665
666 TEST_F(ClientSideDetectionServiceTest, SanitizeRequestForPingback) { 666 TEST_F(ClientSideDetectionServiceTest, SanitizeRequestForPingback) {
667 ClientPhishingRequest request; 667 ClientPhishingRequest request;
668 request.set_url("http://www.us.host.com/blah"); 668 request.set_url("http://www.us.host.com/blah");
669 request.set_suffix_prefix_hash("hash"); 669 request.set_hash_prefix("hash");
670 request.set_client_score(0.8f); 670 request.set_client_score(0.8f);
671 request.set_is_phishing(true); 671 request.set_is_phishing(true);
672 AddFeature(std::string(features::kUrlTldToken) + "com", 1.0, &request); 672 AddFeature(std::string(features::kUrlTldToken) + "com", 1.0, &request);
673 AddFeature(std::string(features::kUrlDomainToken) + "host", 1.0, &request); 673 AddFeature(std::string(features::kUrlDomainToken) + "host", 1.0, &request);
674 AddFeature(std::string(features::kUrlOtherHostToken) + "us", 1.0, &request); 674 AddFeature(std::string(features::kUrlOtherHostToken) + "us", 1.0, &request);
675 AddFeature(std::string(features::kUrlOtherHostToken) + "www", 1.0, &request); 675 AddFeature(std::string(features::kUrlOtherHostToken) + "www", 1.0, &request);
676 AddFeature(features::kUrlNumOtherHostTokensGTOne, 1.0, &request); 676 AddFeature(features::kUrlNumOtherHostTokensGTOne, 1.0, &request);
677 AddFeature(std::string(features::kUrlPathToken) + "blah", 1.0, &request); 677 AddFeature(std::string(features::kUrlPathToken) + "blah", 1.0, &request);
678 AddFeature(features::kPageHasForms, 1.0, &request); 678 AddFeature(features::kPageHasForms, 1.0, &request);
679 AddFeature(std::string(features::kPageTerm) + "term", 1.0, &request); 679 AddFeature(std::string(features::kPageTerm) + "term", 1.0, &request);
(...skipping 22 matching lines...) Expand all
702 AddNonModelFeature(std::string(features::kSafeBrowsingOriginalUrl) + 702 AddNonModelFeature(std::string(features::kSafeBrowsingOriginalUrl) +
703 "http://original.com/", 1.0, &request); 703 "http://original.com/", 1.0, &request);
704 704
705 csd_service_.reset(ClientSideDetectionService::Create(NULL)); 705 csd_service_.reset(ClientSideDetectionService::Create(NULL));
706 706
707 ClientPhishingRequest sanitized_request; 707 ClientPhishingRequest sanitized_request;
708 csd_service_->SanitizeRequestForPingback(request, &sanitized_request); 708 csd_service_->SanitizeRequestForPingback(request, &sanitized_request);
709 709
710 // For easier debugging, we'll check the output protobuf fields individually. 710 // For easier debugging, we'll check the output protobuf fields individually.
711 ClientPhishingRequest expected; 711 ClientPhishingRequest expected;
712 expected.set_suffix_prefix_hash(request.suffix_prefix_hash()); 712 expected.set_hash_prefix(request.hash_prefix());
713 expected.set_client_score(request.client_score()); 713 expected.set_client_score(request.client_score());
714 expected.set_is_phishing(request.is_phishing()); 714 expected.set_is_phishing(request.is_phishing());
715 AddFeature(features::kUrlNumOtherHostTokensGTOne, 1.0, &expected); 715 AddFeature(features::kUrlNumOtherHostTokensGTOne, 1.0, &expected);
716 AddFeature(features::kPageHasForms, 1.0, &expected); 716 AddFeature(features::kPageHasForms, 1.0, &expected);
717 AddFeature(features::kPageImgOtherDomainFreq, 0.5, &expected); 717 AddFeature(features::kPageImgOtherDomainFreq, 0.5, &expected);
718 expected.set_model_version(3); 718 expected.set_model_version(3);
719 AddNonModelFeature(features::kUrlHistoryVisitCount, 5.0, &expected); 719 AddNonModelFeature(features::kUrlHistoryVisitCount, 5.0, &expected);
720 720
721 EXPECT_FALSE(sanitized_request.has_url()); 721 EXPECT_FALSE(sanitized_request.has_url());
722 EXPECT_EQ(expected.suffix_prefix_hash(), 722 EXPECT_EQ(expected.hash_prefix(), sanitized_request.hash_prefix());
723 sanitized_request.suffix_prefix_hash());
724 EXPECT_FLOAT_EQ(expected.client_score(), sanitized_request.client_score()); 723 EXPECT_FLOAT_EQ(expected.client_score(), sanitized_request.client_score());
725 EXPECT_EQ(expected.is_phishing(), sanitized_request.is_phishing()); 724 EXPECT_EQ(expected.is_phishing(), sanitized_request.is_phishing());
726 725
727 ASSERT_EQ(expected.feature_map_size(), sanitized_request.feature_map_size()); 726 ASSERT_EQ(expected.feature_map_size(), sanitized_request.feature_map_size());
728 for (int i = 0; i < expected.feature_map_size(); ++i) { 727 for (int i = 0; i < expected.feature_map_size(); ++i) {
729 EXPECT_EQ(expected.feature_map(i).name(), 728 EXPECT_EQ(expected.feature_map(i).name(),
730 sanitized_request.feature_map(i).name()) << "Feature " << i; 729 sanitized_request.feature_map(i).name()) << "Feature " << i;
731 EXPECT_DOUBLE_EQ(expected.feature_map(i).value(), 730 EXPECT_DOUBLE_EQ(expected.feature_map(i).value(),
732 sanitized_request.feature_map(i).value()) 731 sanitized_request.feature_map(i).value())
733 << "Feature " << i; 732 << "Feature " << i;
(...skipping 10 matching lines...) Expand all
744 << "Non-model feature " << i; 743 << "Non-model feature " << i;
745 } 744 }
746 745
747 // Also check the serialized forms in case there's a field that we forget 746 // Also check the serialized forms in case there's a field that we forget
748 // to add above. 747 // to add above.
749 EXPECT_EQ(expected.SerializeAsString(), 748 EXPECT_EQ(expected.SerializeAsString(),
750 sanitized_request.SerializeAsString()); 749 sanitized_request.SerializeAsString());
751 } 750 }
752 751
753 } // namespace safe_browsing 752 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698