| 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 <map> | 5 #include <map> |
| 6 #include <queue> | 6 #include <queue> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 true /* success */); | 347 true /* success */); |
| 348 EXPECT_TRUE(SendClientReportPhishingRequest(url, score)); | 348 EXPECT_TRUE(SendClientReportPhishingRequest(url, score)); |
| 349 | 349 |
| 350 // This request will fail | 350 // This request will fail |
| 351 GURL second_url("http://b.com/"); | 351 GURL second_url("http://b.com/"); |
| 352 response.set_phishy(false); | 352 response.set_phishy(false); |
| 353 SetClientReportPhishingResponse(response.SerializeAsString(), | 353 SetClientReportPhishingResponse(response.SerializeAsString(), |
| 354 false /* success */); | 354 false /* success */); |
| 355 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score)); | 355 EXPECT_FALSE(SendClientReportPhishingRequest(second_url, score)); |
| 356 | 356 |
| 357 // This is a false positive. | |
| 358 response.set_phishy(true); | |
| 359 response.add_whitelist_expression("c.com/a.html"); | |
| 360 SetClientReportPhishingResponse(response.SerializeAsString(), | |
| 361 true /* success */); | |
| 362 GURL third_url("http://c.com/"); | |
| 363 EXPECT_FALSE(SendClientReportPhishingRequest(third_url, score)); | |
| 364 | |
| 365 base::Time after = base::Time::Now(); | 357 base::Time after = base::Time::Now(); |
| 366 | 358 |
| 367 // Check that we have recorded all 4 requests within the correct time range. | 359 // Check that we have recorded all 3 requests within the correct time range. |
| 368 std::queue<base::Time>& report_times = GetPhishingReportTimes(); | 360 std::queue<base::Time>& report_times = GetPhishingReportTimes(); |
| 369 EXPECT_EQ(4U, report_times.size()); | 361 EXPECT_EQ(3U, report_times.size()); |
| 370 while (!report_times.empty()) { | 362 while (!report_times.empty()) { |
| 371 base::Time time = report_times.back(); | 363 base::Time time = report_times.back(); |
| 372 report_times.pop(); | 364 report_times.pop(); |
| 373 EXPECT_LE(before, time); | 365 EXPECT_LE(before, time); |
| 374 EXPECT_GE(after, time); | 366 EXPECT_GE(after, time); |
| 375 } | 367 } |
| 376 | 368 |
| 377 // Only the first url should be in the cache. | 369 // Only the first url should be in the cache. |
| 378 bool is_phishing; | 370 bool is_phishing; |
| 379 EXPECT_TRUE(csd_service_->IsInCache(url)); | 371 EXPECT_TRUE(csd_service_->IsInCache(url)); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // report back. | 648 // report back. |
| 657 EXPECT_CALL(*service, ScheduleFetchModel(_)) | 649 EXPECT_CALL(*service, ScheduleFetchModel(_)) |
| 658 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); | 650 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); |
| 659 EXPECT_CALL(*service, EndFetchModel( | 651 EXPECT_CALL(*service, EndFetchModel( |
| 660 ClientSideDetectionService::MODEL_NOT_CHANGED)) | 652 ClientSideDetectionService::MODEL_NOT_CHANGED)) |
| 661 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); | 653 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); |
| 662 csd_service_->SetEnabledAndRefreshState(true); | 654 csd_service_->SetEnabledAndRefreshState(true); |
| 663 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); | 655 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); |
| 664 Mock::VerifyAndClearExpectations(service); | 656 Mock::VerifyAndClearExpectations(service); |
| 665 } | 657 } |
| 666 | |
| 667 TEST_F(ClientSideDetectionServiceTest, IsFalsePositiveResponse) { | |
| 668 GURL url("http://www.google.com/"); | |
| 669 ClientPhishingResponse response; | |
| 670 | |
| 671 // If the response is not phishing is should never be a false positive. | |
| 672 response.set_phishy(false); | |
| 673 response.add_whitelist_expression("www.google.com/"); | |
| 674 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 675 url, response)); | |
| 676 | |
| 677 // If there are no entries in the whitelist it should always return false. | |
| 678 response.clear_whitelist_expression(); | |
| 679 response.set_phishy(true); | |
| 680 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 681 url, response)); | |
| 682 | |
| 683 // If the URL doesn't match any whitelist entries it whould return false. | |
| 684 response.add_whitelist_expression("www.yahoo.com/"); | |
| 685 EXPECT_FALSE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 686 url, response)); | |
| 687 | |
| 688 // If the URL matches the whitelist it should return true. | |
| 689 response.add_whitelist_expression("google.com/"); | |
| 690 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 691 url, response)); | |
| 692 | |
| 693 // If an entry in the whitelist matches the URL it should return true. | |
| 694 response.clear_whitelist_expression(); | |
| 695 response.add_whitelist_expression("www.google.com/a/b.html"); | |
| 696 EXPECT_TRUE(ClientSideDetectionService::IsFalsePositiveResponse( | |
| 697 url, response)); | |
| 698 } | |
| 699 } // namespace safe_browsing | 658 } // namespace safe_browsing |
| OLD | NEW |