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

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

Issue 7792004: Parse the whitelist expressions from the phishing verdict response if (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Brian's comments 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ClientPhishingResponse response; 343 ClientPhishingResponse response;
344 response.set_phishy(true); 344 response.set_phishy(true);
345 SetClientReportPhishingResponse(response.SerializeAsString(), 345 SetClientReportPhishingResponse(response.SerializeAsString(),
346 true /* success */); 346 true /* success */);
347 EXPECT_TRUE(SendClientReportPhishingRequest(url, score)); 347 EXPECT_TRUE(SendClientReportPhishingRequest(url, score));
348 348
349 // This request will fail 349 // This request will fail
350 GURL second_url("http://b.com/"); 350 GURL second_url("http://b.com/");
351 response.set_phishy(false); 351 response.set_phishy(false);
352 SetClientReportPhishingResponse(response.SerializeAsString(), 352 SetClientReportPhishingResponse(response.SerializeAsString(),
353 false /* success*/); 353 false /* success */);
354 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score)); 354 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score));
355 355
356 // This is a false positive.
357 response.set_phishy(true);
358 response.add_whitelist_expression("c.com/a.html");
359 SetClientReportPhishingResponse(response.SerializeAsString(),
360 true /* success */);
361 GURL third_url("http://c.com/");
362 EXPECT_FALSE(SendClientReportPhishingRequest(third_url, score));
363
356 base::Time after = base::Time::Now(); 364 base::Time after = base::Time::Now();
357 365
358 // Check that we have recorded all 3 requests within the correct time range. 366 // Check that we have recorded all 4 requests within the correct time range.
359 std::queue<base::Time>& report_times = GetPhishingReportTimes(); 367 std::queue<base::Time>& report_times = GetPhishingReportTimes();
360 EXPECT_EQ(3U, report_times.size()); 368 EXPECT_EQ(4U, report_times.size());
361 while (!report_times.empty()) { 369 while (!report_times.empty()) {
362 base::Time time = report_times.back(); 370 base::Time time = report_times.back();
363 report_times.pop(); 371 report_times.pop();
364 EXPECT_LE(before, time); 372 EXPECT_LE(before, time);
365 EXPECT_GE(after, time); 373 EXPECT_GE(after, time);
366 } 374 }
367 375
368 // Only the first url should be in the cache. 376 // Only the first url should be in the cache.
369 bool is_phishing; 377 bool is_phishing;
370 EXPECT_TRUE(csd_service_->IsInCache(url)); 378 EXPECT_TRUE(csd_service_->IsInCache(url));
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 sanitized_request.non_model_feature_map(i).value()) 750 sanitized_request.non_model_feature_map(i).value())
743 << "Non-model feature " << i; 751 << "Non-model feature " << i;
744 } 752 }
745 753
746 // Also check the serialized forms in case there's a field that we forget 754 // Also check the serialized forms in case there's a field that we forget
747 // to add above. 755 // to add above.
748 EXPECT_EQ(expected.SerializeAsString(), 756 EXPECT_EQ(expected.SerializeAsString(),
749 sanitized_request.SerializeAsString()); 757 sanitized_request.SerializeAsString());
750 } 758 }
751 759
760 TEST_F(ClientSideDetectionServiceTest, IsFalsePositiveResponse) {
761 GURL url("http://www.google.com/");
762 ClientPhishingResponse response;
763
764 // If the response is not phishing is should never be a false positive.
765 response.set_phishy(false);
766 response.add_whitelist_expression("www.google.com/");
767 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse(
768 url, response));
769
770 // If there are no entries in the whitelist it should always return false.
771 response.clear_whitelist_expression();
772 response.set_phishy(true);
773 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse(
774 url, response));
775
776 // If the URL doesn't match any whitelist entries it whould return false.
777 response.add_whitelist_expression("www.yahoo.com/");
778 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse(
779 url, response));
780
781 // If the URL matches the whitelist it should return true.
782 response.add_whitelist_expression("google.com/");
783 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse(
784 url, response));
785
786 // If an entry in the whitelist matches the URL it should return true.
787 response.clear_whitelist_expression();
788 response.add_whitelist_expression("www.google.com/a/b.html");
789 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse(
790 url, response));
791 }
752 } // namespace safe_browsing 792 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_service.cc ('k') | chrome/browser/safe_browsing/safe_browsing_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698