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

Side by Side Diff: chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc

Issue 653773004: Standardize usage of virtual/override/final in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop/message_loop_proxy.h" 7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 20 matching lines...) Expand all
31 : public net::TestURLRequestContextGetter { 31 : public net::TestURLRequestContextGetter {
32 public: 32 public:
33 explicit TrackingTestURLRequestContextGetter( 33 explicit TrackingTestURLRequestContextGetter(
34 base::MessageLoopProxy* io_message_loop_proxy, 34 base::MessageLoopProxy* io_message_loop_proxy,
35 net::URLRequestThrottlerManager* throttler_manager) 35 net::URLRequestThrottlerManager* throttler_manager)
36 : TestURLRequestContextGetter(io_message_loop_proxy), 36 : TestURLRequestContextGetter(io_message_loop_proxy),
37 throttler_manager_(throttler_manager) { 37 throttler_manager_(throttler_manager) {
38 g_request_context_getter_instances++; 38 g_request_context_getter_instances++;
39 } 39 }
40 40
41 virtual net::TestURLRequestContext* GetURLRequestContext() override { 41 net::TestURLRequestContext* GetURLRequestContext() override {
42 if (!context_.get()) { 42 if (!context_.get()) {
43 context_.reset(new net::TestURLRequestContext(true)); 43 context_.reset(new net::TestURLRequestContext(true));
44 context_->set_throttler_manager(throttler_manager_); 44 context_->set_throttler_manager(throttler_manager_);
45 context_->Init(); 45 context_->Init();
46 } 46 }
47 return context_.get(); 47 return context_.get();
48 } 48 }
49 49
50 protected: 50 protected:
51 virtual ~TrackingTestURLRequestContextGetter() { 51 ~TrackingTestURLRequestContextGetter() override {
52 g_request_context_getter_instances--; 52 g_request_context_getter_instances--;
53 } 53 }
54 54
55 private: 55 private:
56 // Not owned here. 56 // Not owned here.
57 net::URLRequestThrottlerManager* throttler_manager_; 57 net::URLRequestThrottlerManager* throttler_manager_;
58 scoped_ptr<net::TestURLRequestContext> context_; 58 scoped_ptr<net::TestURLRequestContext> context_;
59 }; 59 };
60 60
61 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { 61 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher {
62 public: 62 public:
63 explicit TestCloudPrintURLFetcher( 63 explicit TestCloudPrintURLFetcher(
64 base::MessageLoopProxy* io_message_loop_proxy) 64 base::MessageLoopProxy* io_message_loop_proxy)
65 : io_message_loop_proxy_(io_message_loop_proxy) { 65 : io_message_loop_proxy_(io_message_loop_proxy) {
66 } 66 }
67 67
68 virtual net::URLRequestContextGetter* GetRequestContextGetter() override { 68 net::URLRequestContextGetter* GetRequestContextGetter() override {
69 return new TrackingTestURLRequestContextGetter( 69 return new TrackingTestURLRequestContextGetter(
70 io_message_loop_proxy_.get(), throttler_manager()); 70 io_message_loop_proxy_.get(), throttler_manager());
71 } 71 }
72 72
73 net::URLRequestThrottlerManager* throttler_manager() { 73 net::URLRequestThrottlerManager* throttler_manager() {
74 return &throttler_manager_; 74 return &throttler_manager_;
75 } 75 }
76 76
77 private: 77 private:
78 virtual ~TestCloudPrintURLFetcher() {} 78 ~TestCloudPrintURLFetcher() override {}
79 79
80 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 80 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
81 81
82 // We set this as the throttler manager for the 82 // We set this as the throttler manager for the
83 // TestURLRequestContext we create. 83 // TestURLRequestContext we create.
84 net::URLRequestThrottlerManager throttler_manager_; 84 net::URLRequestThrottlerManager throttler_manager_;
85 }; 85 };
86 86
87 class CloudPrintURLFetcherTest : public testing::Test, 87 class CloudPrintURLFetcherTest : public testing::Test,
88 public CloudPrintURLFetcherDelegate { 88 public CloudPrintURLFetcherDelegate {
89 public: 89 public:
90 CloudPrintURLFetcherTest() : max_retries_(0), fetcher_(NULL) { } 90 CloudPrintURLFetcherTest() : max_retries_(0), fetcher_(NULL) { }
91 91
92 // Creates a URLFetcher, using the program's main thread to do IO. 92 // Creates a URLFetcher, using the program's main thread to do IO.
93 virtual void CreateFetcher(const GURL& url, int max_retries); 93 virtual void CreateFetcher(const GURL& url, int max_retries);
94 94
95 // CloudPrintURLFetcher::Delegate 95 // CloudPrintURLFetcher::Delegate
96 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( 96 CloudPrintURLFetcher::ResponseAction HandleRawResponse(
97 const net::URLFetcher* source, 97 const net::URLFetcher* source,
98 const GURL& url, 98 const GURL& url,
99 const net::URLRequestStatus& status, 99 const net::URLRequestStatus& status,
100 int response_code, 100 int response_code,
101 const net::ResponseCookies& cookies, 101 const net::ResponseCookies& cookies,
102 const std::string& data) override; 102 const std::string& data) override;
103 103
104 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() override { 104 CloudPrintURLFetcher::ResponseAction OnRequestAuthError() override {
105 ADD_FAILURE(); 105 ADD_FAILURE();
106 return CloudPrintURLFetcher::STOP_PROCESSING; 106 return CloudPrintURLFetcher::STOP_PROCESSING;
107 } 107 }
108 108
109 virtual std::string GetAuthHeader() override { 109 std::string GetAuthHeader() override { return std::string(); }
110 return std::string();
111 }
112 110
113 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { 111 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() {
114 return io_message_loop_proxy_; 112 return io_message_loop_proxy_;
115 } 113 }
116 114
117 protected: 115 protected:
118 virtual void SetUp() { 116 virtual void SetUp() {
119 testing::Test::SetUp(); 117 testing::Test::SetUp();
120 118
121 io_message_loop_proxy_ = base::MessageLoopProxy::current(); 119 io_message_loop_proxy_ = base::MessageLoopProxy::current();
(...skipping 17 matching lines...) Expand all
139 int max_retries_; 137 int max_retries_;
140 Time start_time_; 138 Time start_time_;
141 scoped_refptr<TestCloudPrintURLFetcher> fetcher_; 139 scoped_refptr<TestCloudPrintURLFetcher> fetcher_;
142 }; 140 };
143 141
144 class CloudPrintURLFetcherBasicTest : public CloudPrintURLFetcherTest { 142 class CloudPrintURLFetcherBasicTest : public CloudPrintURLFetcherTest {
145 public: 143 public:
146 CloudPrintURLFetcherBasicTest() 144 CloudPrintURLFetcherBasicTest()
147 : handle_raw_response_(false), handle_raw_data_(false) { } 145 : handle_raw_response_(false), handle_raw_data_(false) { }
148 // CloudPrintURLFetcher::Delegate 146 // CloudPrintURLFetcher::Delegate
149 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( 147 CloudPrintURLFetcher::ResponseAction HandleRawResponse(
150 const net::URLFetcher* source, 148 const net::URLFetcher* source,
151 const GURL& url, 149 const GURL& url,
152 const net::URLRequestStatus& status, 150 const net::URLRequestStatus& status,
153 int response_code, 151 int response_code,
154 const net::ResponseCookies& cookies, 152 const net::ResponseCookies& cookies,
155 const std::string& data) override; 153 const std::string& data) override;
156 154
157 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( 155 CloudPrintURLFetcher::ResponseAction HandleRawData(
158 const net::URLFetcher* source, 156 const net::URLFetcher* source,
159 const GURL& url, 157 const GURL& url,
160 const std::string& data) override; 158 const std::string& data) override;
161 159
162 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( 160 CloudPrintURLFetcher::ResponseAction HandleJSONData(
163 const net::URLFetcher* source, 161 const net::URLFetcher* source,
164 const GURL& url, 162 const GURL& url,
165 base::DictionaryValue* json_data, 163 base::DictionaryValue* json_data,
166 bool succeeded) override; 164 bool succeeded) override;
167 165
168 void SetHandleRawResponse(bool handle_raw_response) { 166 void SetHandleRawResponse(bool handle_raw_response) {
169 handle_raw_response_ = handle_raw_response; 167 handle_raw_response_ = handle_raw_response;
170 } 168 }
171 void SetHandleRawData(bool handle_raw_data) { 169 void SetHandleRawData(bool handle_raw_data) {
172 handle_raw_data_ = handle_raw_data; 170 handle_raw_data_ = handle_raw_data;
173 } 171 }
174 private: 172 private:
175 bool handle_raw_response_; 173 bool handle_raw_response_;
176 bool handle_raw_data_; 174 bool handle_raw_data_;
177 }; 175 };
178 176
179 // Version of CloudPrintURLFetcherTest that tests overload protection. 177 // Version of CloudPrintURLFetcherTest that tests overload protection.
180 class CloudPrintURLFetcherOverloadTest : public CloudPrintURLFetcherTest { 178 class CloudPrintURLFetcherOverloadTest : public CloudPrintURLFetcherTest {
181 public: 179 public:
182 CloudPrintURLFetcherOverloadTest() : response_count_(0) { 180 CloudPrintURLFetcherOverloadTest() : response_count_(0) {
183 } 181 }
184 182
185 // CloudPrintURLFetcher::Delegate 183 // CloudPrintURLFetcher::Delegate
186 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( 184 CloudPrintURLFetcher::ResponseAction HandleRawData(
187 const net::URLFetcher* source, 185 const net::URLFetcher* source,
188 const GURL& url, 186 const GURL& url,
189 const std::string& data) override; 187 const std::string& data) override;
190 188
191 private: 189 private:
192 int response_count_; 190 int response_count_;
193 }; 191 };
194 192
195 // Version of CloudPrintURLFetcherTest that tests backoff protection. 193 // Version of CloudPrintURLFetcherTest that tests backoff protection.
196 class CloudPrintURLFetcherRetryBackoffTest : public CloudPrintURLFetcherTest { 194 class CloudPrintURLFetcherRetryBackoffTest : public CloudPrintURLFetcherTest {
197 public: 195 public:
198 CloudPrintURLFetcherRetryBackoffTest() : response_count_(0) { 196 CloudPrintURLFetcherRetryBackoffTest() : response_count_(0) {
199 } 197 }
200 198
201 // CloudPrintURLFetcher::Delegate 199 // CloudPrintURLFetcher::Delegate
202 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( 200 CloudPrintURLFetcher::ResponseAction HandleRawData(
203 const net::URLFetcher* source, 201 const net::URLFetcher* source,
204 const GURL& url, 202 const GURL& url,
205 const std::string& data) override; 203 const std::string& data) override;
206 204
207 virtual void OnRequestGiveUp() override; 205 void OnRequestGiveUp() override;
208 206
209 private: 207 private:
210 int response_count_; 208 int response_count_;
211 }; 209 };
212 210
213 211
214 void CloudPrintURLFetcherTest::CreateFetcher(const GURL& url, int max_retries) { 212 void CloudPrintURLFetcherTest::CreateFetcher(const GURL& url, int max_retries) {
215 fetcher_ = new TestCloudPrintURLFetcher(io_message_loop_proxy().get()); 213 fetcher_ = new TestCloudPrintURLFetcher(io_message_loop_proxy().get());
216 214
217 // Registers an entry for test url. It only allows 3 requests to be sent 215 // Registers an entry for test url. It only allows 3 requests to be sent
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 base::FilePath(kDocRoot)); 368 base::FilePath(kDocRoot));
371 ASSERT_TRUE(test_server.Start()); 369 ASSERT_TRUE(test_server.Start());
372 370
373 GURL url(test_server.GetURL("defaultresponse")); 371 GURL url(test_server.GetURL("defaultresponse"));
374 CreateFetcher(url, 11); 372 CreateFetcher(url, 11);
375 373
376 base::MessageLoop::current()->Run(); 374 base::MessageLoop::current()->Run();
377 } 375 }
378 376
379 } // namespace cloud_print 377 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_url_fetcher.h ('k') | chrome/service/cloud_print/cloud_print_wipeout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698