| OLD | NEW |
| 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 #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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 EXPECT_TRUE(SendClientReportMalwareRequest(url)); | 465 EXPECT_TRUE(SendClientReportMalwareRequest(url)); |
| 466 CheckConfirmedMalwareUrl(GURL("http://response-bad.com/")); | 466 CheckConfirmedMalwareUrl(GURL("http://response-bad.com/")); |
| 467 | 467 |
| 468 // This request will fail | 468 // This request will fail |
| 469 response.set_blacklist(false); | 469 response.set_blacklist(false); |
| 470 SetClientReportMalwareResponse(response.SerializeAsString(), | 470 SetClientReportMalwareResponse(response.SerializeAsString(), |
| 471 net::HTTP_INTERNAL_SERVER_ERROR, | 471 net::HTTP_INTERNAL_SERVER_ERROR, |
| 472 net::URLRequestStatus::FAILED); | 472 net::URLRequestStatus::FAILED); |
| 473 EXPECT_FALSE(SendClientReportMalwareRequest(url)); | 473 EXPECT_FALSE(SendClientReportMalwareRequest(url)); |
| 474 | 474 |
| 475 // server blacklist decision is false, and response is succesful | 475 // Server blacklist decision is false, and response is successful |
| 476 response.set_blacklist(false); | 476 response.set_blacklist(false); |
| 477 SetClientReportMalwareResponse(response.SerializeAsString(), net::HTTP_OK, | 477 SetClientReportMalwareResponse(response.SerializeAsString(), net::HTTP_OK, |
| 478 net::URLRequestStatus::SUCCESS); | 478 net::URLRequestStatus::SUCCESS); |
| 479 EXPECT_FALSE(SendClientReportMalwareRequest(url)); | 479 EXPECT_FALSE(SendClientReportMalwareRequest(url)); |
| 480 | 480 |
| 481 // Check that we have recorded all 4 requests within the correct time range. | 481 // Check that we have recorded all 5 requests within the correct time range. |
| 482 base::Time after = base::Time::Now(); | 482 base::Time after = base::Time::Now(); |
| 483 std::queue<base::Time>& report_times = GetMalwareReportTimes(); | 483 std::queue<base::Time>& report_times = GetMalwareReportTimes(); |
| 484 EXPECT_EQ(4U, report_times.size()); | 484 EXPECT_EQ(5U, report_times.size()); |
| 485 | 485 |
| 486 // Another normal behavior will fail because of the limit is hit | 486 // Check that the malware report limit was reached. |
| 487 response.set_blacklist(true); | 487 EXPECT_TRUE(csd_service_->OverMalwareReportLimit()); |
| 488 SetClientReportMalwareResponse(response.SerializeAsString(), net::HTTP_OK, | |
| 489 net::URLRequestStatus::SUCCESS); | |
| 490 EXPECT_FALSE(SendClientReportMalwareRequest(url)); | |
| 491 | 488 |
| 492 report_times = GetMalwareReportTimes(); | 489 report_times = GetMalwareReportTimes(); |
| 493 EXPECT_EQ(4U, report_times.size()); | 490 EXPECT_EQ(5U, report_times.size()); |
| 494 while (!report_times.empty()) { | 491 while (!report_times.empty()) { |
| 495 base::Time time = report_times.back(); | 492 base::Time time = report_times.back(); |
| 496 report_times.pop(); | 493 report_times.pop(); |
| 497 EXPECT_LE(before, time); | 494 EXPECT_LE(before, time); |
| 498 EXPECT_GE(after, time); | 495 EXPECT_GE(after, time); |
| 499 } | 496 } |
| 500 } | 497 } |
| 501 | 498 |
| 502 TEST_F(ClientSideDetectionServiceTest, GetNumReportTest) { | 499 TEST_F(ClientSideDetectionServiceTest, GetNumReportTest) { |
| 503 SetModelFetchResponse("bogus model", net::HTTP_OK, | 500 SetModelFetchResponse("bogus model", net::HTTP_OK, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 EXPECT_CALL(*service, ScheduleFetchModel(_)) | 695 EXPECT_CALL(*service, ScheduleFetchModel(_)) |
| 699 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); | 696 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); |
| 700 EXPECT_CALL(*service, EndFetchModel( | 697 EXPECT_CALL(*service, EndFetchModel( |
| 701 ClientSideDetectionService::MODEL_NOT_CHANGED)) | 698 ClientSideDetectionService::MODEL_NOT_CHANGED)) |
| 702 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); | 699 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); |
| 703 csd_service_->SetEnabledAndRefreshState(true); | 700 csd_service_->SetEnabledAndRefreshState(true); |
| 704 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); | 701 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); |
| 705 Mock::VerifyAndClearExpectations(service); | 702 Mock::VerifyAndClearExpectations(service); |
| 706 } | 703 } |
| 707 } // namespace safe_browsing | 704 } // namespace safe_browsing |
| OLD | NEW |