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

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

Issue 23625015: Consolidate TestURLFetcherFactory::SetFakeResponse (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 2 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) 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 15 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
16 #include "chrome/common/safe_browsing/client_model.pb.h" 16 #include "chrome/common/safe_browsing/client_model.pb.h"
17 #include "chrome/common/safe_browsing/csd.pb.h" 17 #include "chrome/common/safe_browsing/csd.pb.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 #include "crypto/sha2.h" 19 #include "crypto/sha2.h"
20 #include "net/url_request/test_url_fetcher_factory.h" 20 #include "net/url_request/test_url_fetcher_factory.h"
21 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "url/gurl.h" 24 #include "url/gurl.h"
25 25
26 using ::testing::_;
27 using ::testing::Invoke; 26 using ::testing::Invoke;
28 using ::testing::Mock; 27 using ::testing::Mock;
29 using ::testing::StrictMock; 28 using ::testing::StrictMock;
29 using ::testing::_;
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 namespace safe_browsing { 32 namespace safe_browsing {
33 namespace { 33 namespace {
34 class MockClientSideDetectionService : public ClientSideDetectionService { 34 class MockClientSideDetectionService : public ClientSideDetectionService {
35 public: 35 public:
36 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} 36 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {}
37 virtual ~MockClientSideDetectionService() {} 37 virtual ~MockClientSideDetectionService() {}
38 38
39 MOCK_METHOD1(EndFetchModel, void(ClientModelStatus)); 39 MOCK_METHOD1(EndFetchModel, void(ClientModelStatus));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 csd_service_->SendClientReportMalwareRequest( 99 csd_service_->SendClientReportMalwareRequest(
100 request.release(), 100 request.release(),
101 base::Bind(&ClientSideDetectionServiceTest::SendMalwareRequestDone, 101 base::Bind(&ClientSideDetectionServiceTest::SendMalwareRequestDone,
102 base::Unretained(this))); 102 base::Unretained(this)));
103 phishing_url_ = url; 103 phishing_url_ = url;
104 msg_loop_.Run(); // Waits until callback is called. 104 msg_loop_.Run(); // Waits until callback is called.
105 return is_malware_; 105 return is_malware_;
106 } 106 }
107 107
108 void SetModelFetchResponse(std::string response_data, bool success) { 108 void SetModelFetchResponse(std::string response_data, bool success) {
109 factory_->SetFakeResponse(ClientSideDetectionService::kClientModelUrl, 109 factory_->SetFakeResponse(GURL(ClientSideDetectionService::kClientModelUrl),
110 response_data, success); 110 response_data, success);
111 } 111 }
112 112
113 void SetClientReportPhishingResponse(std::string response_data, 113 void SetClientReportPhishingResponse(std::string response_data,
114 bool success) { 114 bool success) {
115 factory_->SetFakeResponse( 115 factory_->SetFakeResponse(
116 ClientSideDetectionService::GetClientReportUrl( 116 ClientSideDetectionService::GetClientReportUrl(
117 ClientSideDetectionService::kClientReportPhishingUrl), 117 ClientSideDetectionService::kClientReportPhishingUrl),
118 response_data, success); 118 response_data, success);
119 } 119 }
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 EXPECT_CALL(*service, ScheduleFetchModel(_)) 749 EXPECT_CALL(*service, ScheduleFetchModel(_))
750 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); 750 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule));
751 EXPECT_CALL(*service, EndFetchModel( 751 EXPECT_CALL(*service, EndFetchModel(
752 ClientSideDetectionService::MODEL_NOT_CHANGED)) 752 ClientSideDetectionService::MODEL_NOT_CHANGED))
753 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); 753 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable));
754 csd_service_->SetEnabledAndRefreshState(true); 754 csd_service_->SetEnabledAndRefreshState(true);
755 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); 755 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f));
756 Mock::VerifyAndClearExpectations(service); 756 Mock::VerifyAndClearExpectations(service);
757 } 757 }
758 } // namespace safe_browsing 758 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698