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

Side by Side Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 10534154: Move URLFetcherImpl to net/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows link error Created 8 years, 6 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
« no previous file with comments | « net/url_request/url_fetcher_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/common/net/url_fetcher_impl.h" 5 #include "net/url_request/url_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "crypto/nss_util.h" 16 #include "crypto/nss_util.h"
17 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
18 #include "net/test/test_server.h" 18 #include "net/test/test_server.h"
19 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
20 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
21 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
22 #include "net/url_request/url_request_throttler_manager.h" 22 #include "net/url_request/url_request_throttler_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 #if defined(USE_NSS) 25 #if defined(USE_NSS)
26 #include "net/ocsp/nss_ocsp.h" 26 #include "net/ocsp/nss_ocsp.h"
27 #endif 27 #endif
28 28
29 namespace net {
30
29 using base::Time; 31 using base::Time;
30 using base::TimeDelta; 32 using base::TimeDelta;
31 33
32 // TODO(eroman): Add a regression test for http://crbug.com/40505. 34 // TODO(eroman): Add a regression test for http://crbug.com/40505.
33 35
34 namespace { 36 namespace {
35 37
38 // TODO(akalin): Move all the test data to somewhere under net/.
36 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 39 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
37 const char kTestServerFilePrefix[] = "files/"; 40 const char kTestServerFilePrefix[] = "files/";
38 41
39 class ThrottlingTestURLRequestContext : public TestURLRequestContext { 42 class ThrottlingTestURLRequestContext : public TestURLRequestContext {
40 public: 43 public:
41 ThrottlingTestURLRequestContext() : TestURLRequestContext(true) { 44 ThrottlingTestURLRequestContext() : TestURLRequestContext(true) {
42 set_throttler_manager(&throttler_manager_); 45 set_throttler_manager(&throttler_manager_);
43 Init(); 46 Init();
44 DCHECK(throttler_manager() != NULL); 47 DCHECK(throttler_manager() != NULL);
45 } 48 }
46 49
47 private: 50 private:
48 net::URLRequestThrottlerManager throttler_manager_; 51 URLRequestThrottlerManager throttler_manager_;
49 }; 52 };
50 53
51 class ThrottlingTestURLRequestContextGetter 54 class ThrottlingTestURLRequestContextGetter
52 : public TestURLRequestContextGetter { 55 : public TestURLRequestContextGetter {
53 public: 56 public:
54 ThrottlingTestURLRequestContextGetter( 57 ThrottlingTestURLRequestContextGetter(
55 base::MessageLoopProxy* io_message_loop_proxy, 58 base::MessageLoopProxy* io_message_loop_proxy,
56 TestURLRequestContext* request_context) 59 TestURLRequestContext* request_context)
57 : TestURLRequestContextGetter(io_message_loop_proxy), 60 : TestURLRequestContextGetter(io_message_loop_proxy),
58 context_(request_context) { 61 context_(request_context) {
59 } 62 }
60 63
61 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { 64 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
62 return context_; 65 return context_;
63 } 66 }
64 67
65 protected: 68 protected:
66 virtual ~ThrottlingTestURLRequestContextGetter() {} 69 virtual ~ThrottlingTestURLRequestContextGetter() {}
67 70
68 TestURLRequestContext* const context_; 71 TestURLRequestContext* const context_;
69 }; 72 };
70 73
71 } // namespace 74 } // namespace
72 75
73 class URLFetcherTest : public testing::Test, 76 class URLFetcherTest : public testing::Test,
74 public net::URLFetcherDelegate { 77 public URLFetcherDelegate {
75 public: 78 public:
76 URLFetcherTest() 79 URLFetcherTest()
77 : fetcher_(NULL), 80 : fetcher_(NULL),
78 context_(new ThrottlingTestURLRequestContext()) { 81 context_(new ThrottlingTestURLRequestContext()) {
79 } 82 }
80 83
81 static int GetNumFetcherCores() { 84 static int GetNumFetcherCores() {
82 return URLFetcherImpl::GetNumFetcherCores(); 85 return URLFetcherImpl::GetNumFetcherCores();
83 } 86 }
84 87
85 // Creates a URLFetcher, using the program's main thread to do IO. 88 // Creates a URLFetcher, using the program's main thread to do IO.
86 virtual void CreateFetcher(const GURL& url); 89 virtual void CreateFetcher(const GURL& url);
87 90
88 // net::URLFetcherDelegate 91 // URLFetcherDelegate
89 // Subclasses that override this should either call this function or 92 // Subclasses that override this should either call this function or
90 // CleanupAfterFetchComplete() at the end of their processing, depending on 93 // CleanupAfterFetchComplete() at the end of their processing, depending on
91 // whether they want to check for a non-empty HTTP 200 response or not. 94 // whether they want to check for a non-empty HTTP 200 response or not.
92 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 95 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
93 96
94 // Deletes |fetcher| and terminates the message loop. 97 // Deletes |fetcher| and terminates the message loop.
95 void CleanupAfterFetchComplete(); 98 void CleanupAfterFetchComplete();
96 99
97 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { 100 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() {
98 return io_message_loop_proxy_; 101 return io_message_loop_proxy_;
99 } 102 }
100 103
101 TestURLRequestContext* request_context() { 104 TestURLRequestContext* request_context() {
102 return context_.get(); 105 return context_.get();
103 } 106 }
104 107
105 protected: 108 protected:
106 virtual void SetUp() OVERRIDE { 109 virtual void SetUp() OVERRIDE {
107 testing::Test::SetUp(); 110 testing::Test::SetUp();
108 111
109 io_message_loop_proxy_ = base::MessageLoopProxy::current(); 112 io_message_loop_proxy_ = base::MessageLoopProxy::current();
110 113
111 #if defined(USE_NSS) 114 #if defined(USE_NSS)
112 crypto::EnsureNSSInit(); 115 crypto::EnsureNSSInit();
113 net::EnsureNSSHttpIOInit(); 116 EnsureNSSHttpIOInit();
114 #endif 117 #endif
115 } 118 }
116 119
117 virtual void TearDown() OVERRIDE { 120 virtual void TearDown() OVERRIDE {
118 #if defined(USE_NSS) 121 #if defined(USE_NSS)
119 net::ShutdownNSSHttpIO(); 122 ShutdownNSSHttpIO();
120 #endif 123 #endif
121 } 124 }
122 125
123 // URLFetcher is designed to run on the main UI thread, but in our tests 126 // URLFetcher is designed to run on the main UI thread, but in our tests
124 // we assume that the current thread is the IO thread where the URLFetcher 127 // we assume that the current thread is the IO thread where the URLFetcher
125 // dispatches its requests to. When we wish to simulate being used from 128 // dispatches its requests to. When we wish to simulate being used from
126 // a UI thread, we dispatch a worker thread to do so. 129 // a UI thread, we dispatch a worker thread to do so.
127 MessageLoopForIO io_loop_; 130 MessageLoopForIO io_loop_;
128 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 131 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
129 132
130 URLFetcherImpl* fetcher_; 133 URLFetcherImpl* fetcher_;
131 const scoped_ptr<TestURLRequestContext> context_; 134 const scoped_ptr<TestURLRequestContext> context_;
132 }; 135 };
133 136
134 void URLFetcherTest::CreateFetcher(const GURL& url) { 137 void URLFetcherTest::CreateFetcher(const GURL& url) {
135 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 138 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
136 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 139 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
137 io_message_loop_proxy(), request_context())); 140 io_message_loop_proxy(), request_context()));
138 fetcher_->Start(); 141 fetcher_->Start();
139 } 142 }
140 143
141 void URLFetcherTest::OnURLFetchComplete(const net::URLFetcher* source) { 144 void URLFetcherTest::OnURLFetchComplete(const URLFetcher* source) {
142 EXPECT_TRUE(source->GetStatus().is_success()); 145 EXPECT_TRUE(source->GetStatus().is_success());
143 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 146 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
144 147
145 std::string data; 148 std::string data;
146 EXPECT_TRUE(source->GetResponseAsString(&data)); 149 EXPECT_TRUE(source->GetResponseAsString(&data));
147 EXPECT_FALSE(data.empty()); 150 EXPECT_FALSE(data.empty());
148 151
149 CleanupAfterFetchComplete(); 152 CleanupAfterFetchComplete();
150 } 153 }
151 154
152 void URLFetcherTest::CleanupAfterFetchComplete() { 155 void URLFetcherTest::CleanupAfterFetchComplete() {
153 delete fetcher_; // Have to delete this here and not in the destructor, 156 delete fetcher_; // Have to delete this here and not in the destructor,
154 // because the destructor won't necessarily run on the 157 // because the destructor won't necessarily run on the
155 // same thread that CreateFetcher() did. 158 // same thread that CreateFetcher() did.
156 159
157 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 160 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
158 // If the current message loop is not the IO loop, it will be shut down when 161 // If the current message loop is not the IO loop, it will be shut down when
159 // the main loop returns and this thread subsequently goes out of scope. 162 // the main loop returns and this thread subsequently goes out of scope.
160 } 163 }
161 164
162 namespace { 165 namespace {
163 166
164 // Version of URLFetcherTest that does a POST instead 167 // Version of URLFetcherTest that does a POST instead
165 class URLFetcherPostTest : public URLFetcherTest { 168 class URLFetcherPostTest : public URLFetcherTest {
166 public: 169 public:
167 // URLFetcherTest override. 170 // URLFetcherTest override.
168 virtual void CreateFetcher(const GURL& url) OVERRIDE; 171 virtual void CreateFetcher(const GURL& url) OVERRIDE;
169 172
170 // net::URLFetcherDelegate 173 // URLFetcherDelegate
171 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 174 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
172 }; 175 };
173 176
174 // Version of URLFetcherTest that tests download progress reports. 177 // Version of URLFetcherTest that tests download progress reports.
175 class URLFetcherDownloadProgressTest : public URLFetcherTest { 178 class URLFetcherDownloadProgressTest : public URLFetcherTest {
176 public: 179 public:
177 // URLFetcherTest override. 180 // URLFetcherTest override.
178 virtual void CreateFetcher(const GURL& url) OVERRIDE; 181 virtual void CreateFetcher(const GURL& url) OVERRIDE;
179 182
180 // net::URLFetcherDelegate 183 // URLFetcherDelegate
181 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, 184 virtual void OnURLFetchDownloadProgress(const URLFetcher* source,
182 int64 current, int64 total) OVERRIDE; 185 int64 current, int64 total) OVERRIDE;
183 protected: 186 protected:
184 int64 previous_progress_; 187 int64 previous_progress_;
185 int64 expected_total_; 188 int64 expected_total_;
186 }; 189 };
187 190
188 /// Version of URLFetcherTest that tests progress reports at cancellation. 191 /// Version of URLFetcherTest that tests progress reports at cancellation.
189 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { 192 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest {
190 public: 193 public:
191 // URLFetcherTest override. 194 // URLFetcherTest override.
192 virtual void CreateFetcher(const GURL& url) OVERRIDE; 195 virtual void CreateFetcher(const GURL& url) OVERRIDE;
193 196
194 // net::URLFetcherDelegate 197 // URLFetcherDelegate
195 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 198 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
196 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, 199 virtual void OnURLFetchDownloadProgress(const URLFetcher* source,
197 int64 current, int64 total) OVERRIDE; 200 int64 current, int64 total) OVERRIDE;
198 protected: 201 protected:
199 bool cancelled_; 202 bool cancelled_;
200 }; 203 };
201 204
202 // Version of URLFetcherTest that tests upload progress reports. 205 // Version of URLFetcherTest that tests upload progress reports.
203 class URLFetcherUploadProgressTest : public URLFetcherTest { 206 class URLFetcherUploadProgressTest : public URLFetcherTest {
204 public: 207 public:
205 virtual void CreateFetcher(const GURL& url); 208 virtual void CreateFetcher(const GURL& url);
206 209
207 // net::URLFetcherDelegate 210 // URLFetcherDelegate
208 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, 211 virtual void OnURLFetchUploadProgress(const URLFetcher* source,
209 int64 current, int64 total); 212 int64 current, int64 total);
210 protected: 213 protected:
211 int64 previous_progress_; 214 int64 previous_progress_;
212 std::string chunk_; 215 std::string chunk_;
213 int64 number_of_chunks_added_; 216 int64 number_of_chunks_added_;
214 }; 217 };
215 218
216 // Version of URLFetcherTest that tests headers. 219 // Version of URLFetcherTest that tests headers.
217 class URLFetcherHeadersTest : public URLFetcherTest { 220 class URLFetcherHeadersTest : public URLFetcherTest {
218 public: 221 public:
219 // net::URLFetcherDelegate 222 // URLFetcherDelegate
220 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 223 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
221 }; 224 };
222 225
223 // Version of URLFetcherTest that tests SocketAddress. 226 // Version of URLFetcherTest that tests SocketAddress.
224 class URLFetcherSocketAddressTest : public URLFetcherTest { 227 class URLFetcherSocketAddressTest : public URLFetcherTest {
225 public: 228 public:
226 // net::URLFetcherDelegate 229 // URLFetcherDelegate
227 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 230 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
228 protected: 231 protected:
229 std::string expected_host_; 232 std::string expected_host_;
230 uint16 expected_port_; 233 uint16 expected_port_;
231 }; 234 };
232 235
233 // Version of URLFetcherTest that tests stopping on a redirect. 236 // Version of URLFetcherTest that tests stopping on a redirect.
234 class URLFetcherStopOnRedirectTest : public URLFetcherTest { 237 class URLFetcherStopOnRedirectTest : public URLFetcherTest {
235 public: 238 public:
236 URLFetcherStopOnRedirectTest(); 239 URLFetcherStopOnRedirectTest();
237 virtual ~URLFetcherStopOnRedirectTest(); 240 virtual ~URLFetcherStopOnRedirectTest();
238 241
239 // URLFetcherTest override. 242 // URLFetcherTest override.
240 virtual void CreateFetcher(const GURL& url) OVERRIDE; 243 virtual void CreateFetcher(const GURL& url) OVERRIDE;
241 // net::URLFetcherDelegate 244 // URLFetcherDelegate
242 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 245 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
243 246
244 protected: 247 protected:
245 // The URL we should be redirected to. 248 // The URL we should be redirected to.
246 static const char* kRedirectTarget; 249 static const char* kRedirectTarget;
247 250
248 bool callback_called_; // Set to true in OnURLFetchComplete(). 251 bool callback_called_; // Set to true in OnURLFetchComplete().
249 }; 252 };
250 253
251 // Version of URLFetcherTest that tests overload protection. 254 // Version of URLFetcherTest that tests overload protection.
252 class URLFetcherProtectTest : public URLFetcherTest { 255 class URLFetcherProtectTest : public URLFetcherTest {
253 public: 256 public:
254 // URLFetcherTest override. 257 // URLFetcherTest override.
255 virtual void CreateFetcher(const GURL& url) OVERRIDE; 258 virtual void CreateFetcher(const GURL& url) OVERRIDE;
256 // net::URLFetcherDelegate 259 // URLFetcherDelegate
257 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 260 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
258 private: 261 private:
259 Time start_time_; 262 Time start_time_;
260 }; 263 };
261 264
262 // Version of URLFetcherTest that tests overload protection, when responses 265 // Version of URLFetcherTest that tests overload protection, when responses
263 // passed through. 266 // passed through.
264 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { 267 class URLFetcherProtectTestPassedThrough : public URLFetcherTest {
265 public: 268 public:
266 // URLFetcherTest override. 269 // URLFetcherTest override.
267 virtual void CreateFetcher(const GURL& url) OVERRIDE; 270 virtual void CreateFetcher(const GURL& url) OVERRIDE;
268 // net::URLFetcherDelegate 271 // URLFetcherDelegate
269 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 272 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
270 private: 273 private:
271 Time start_time_; 274 Time start_time_;
272 }; 275 };
273 276
274 // Version of URLFetcherTest that tests bad HTTPS requests. 277 // Version of URLFetcherTest that tests bad HTTPS requests.
275 class URLFetcherBadHTTPSTest : public URLFetcherTest { 278 class URLFetcherBadHTTPSTest : public URLFetcherTest {
276 public: 279 public:
277 URLFetcherBadHTTPSTest(); 280 URLFetcherBadHTTPSTest();
278 281
279 // net::URLFetcherDelegate 282 // URLFetcherDelegate
280 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 283 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
281 284
282 private: 285 private:
283 FilePath cert_dir_; 286 FilePath cert_dir_;
284 }; 287 };
285 288
286 // Version of URLFetcherTest that tests request cancellation on shutdown. 289 // Version of URLFetcherTest that tests request cancellation on shutdown.
287 class URLFetcherCancelTest : public URLFetcherTest { 290 class URLFetcherCancelTest : public URLFetcherTest {
288 public: 291 public:
289 // URLFetcherTest override. 292 // URLFetcherTest override.
290 virtual void CreateFetcher(const GURL& url) OVERRIDE; 293 virtual void CreateFetcher(const GURL& url) OVERRIDE;
291 // net::URLFetcherDelegate 294 // URLFetcherDelegate
292 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 295 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
293 296
294 void CancelRequest(); 297 void CancelRequest();
295 }; 298 };
296 299
297 // Version of TestURLRequestContext that posts a Quit task to the IO 300 // Version of TestURLRequestContext that posts a Quit task to the IO
298 // thread once it is deleted. 301 // thread once it is deleted.
299 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { 302 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext {
300 public: 303 public:
301 explicit CancelTestURLRequestContext() { 304 explicit CancelTestURLRequestContext() {
302 } 305 }
(...skipping 19 matching lines...) Expand all
322 } 325 }
323 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { 326 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
324 if (!context_.get()) { 327 if (!context_.get()) {
325 context_.reset(new CancelTestURLRequestContext()); 328 context_.reset(new CancelTestURLRequestContext());
326 DCHECK(context_->throttler_manager()); 329 DCHECK(context_->throttler_manager());
327 330
328 // Registers an entry for test url. The backoff time is calculated by: 331 // Registers an entry for test url. The backoff time is calculated by:
329 // new_backoff = 2.0 * old_backoff + 0 332 // new_backoff = 2.0 * old_backoff + 0
330 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. 333 // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
331 // Maximum retries allowed is set to 2. 334 // Maximum retries allowed is set to 2.
332 scoped_refptr<net::URLRequestThrottlerEntry> entry( 335 scoped_refptr<URLRequestThrottlerEntry> entry(
333 new net::URLRequestThrottlerEntry( 336 new URLRequestThrottlerEntry(
334 context_->throttler_manager(), 337 context_->throttler_manager(),
335 "", 200, 3, 2000, 2.0, 0.0, 4000)); 338 "", 200, 3, 2000, 2.0, 0.0, 4000));
336 context_->throttler_manager()->OverrideEntryForTests( 339 context_->throttler_manager()->OverrideEntryForTests(
337 throttle_for_url_, entry); 340 throttle_for_url_, entry);
338 341
339 context_created_.Signal(); 342 context_created_.Signal();
340 } 343 }
341 return context_.get(); 344 return context_.get();
342 } 345 }
343 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { 346 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
344 return io_message_loop_proxy_; 347 return io_message_loop_proxy_;
345 } 348 }
346 void WaitForContextCreation() { 349 void WaitForContextCreation() {
347 context_created_.Wait(); 350 context_created_.Wait();
348 } 351 }
349 352
350 protected: 353 protected:
351 virtual ~CancelTestURLRequestContextGetter() {} 354 virtual ~CancelTestURLRequestContextGetter() {}
352 355
353 private: 356 private:
354 scoped_ptr<TestURLRequestContext> context_; 357 scoped_ptr<TestURLRequestContext> context_;
355 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 358 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
356 base::WaitableEvent context_created_; 359 base::WaitableEvent context_created_;
357 GURL throttle_for_url_; 360 GURL throttle_for_url_;
358 }; 361 };
359 362
360 // Version of URLFetcherTest that tests retying the same request twice. 363 // Version of URLFetcherTest that tests retying the same request twice.
361 class URLFetcherMultipleAttemptTest : public URLFetcherTest { 364 class URLFetcherMultipleAttemptTest : public URLFetcherTest {
362 public: 365 public:
363 // net::URLFetcherDelegate 366 // URLFetcherDelegate
364 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 367 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
365 private: 368 private:
366 std::string data_; 369 std::string data_;
367 }; 370 };
368 371
369 class URLFetcherFileTest : public URLFetcherTest { 372 class URLFetcherFileTest : public URLFetcherTest {
370 public: 373 public:
371 URLFetcherFileTest() : take_ownership_of_file_(false), 374 URLFetcherFileTest() : take_ownership_of_file_(false),
372 expected_file_error_(base::PLATFORM_FILE_OK) {} 375 expected_file_error_(base::PLATFORM_FILE_OK) {}
373 376
374 void CreateFetcherForFile(const GURL& url, const FilePath& file_path); 377 void CreateFetcherForFile(const GURL& url, const FilePath& file_path);
375 void CreateFetcherForTempFile(const GURL& url); 378 void CreateFetcherForTempFile(const GURL& url);
376 379
377 // net::URLFetcherDelegate 380 // URLFetcherDelegate
378 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 381 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
379 382
380 protected: 383 protected:
381 FilePath expected_file_; 384 FilePath expected_file_;
382 FilePath file_path_; 385 FilePath file_path_;
383 386
384 // Set by the test. Used in OnURLFetchComplete() to decide if 387 // Set by the test. Used in OnURLFetchComplete() to decide if
385 // the URLFetcher should own the temp file, so that we can test 388 // the URLFetcher should own the temp file, so that we can test
386 // disowning prevents the file from being deleted. 389 // disowning prevents the file from being deleted.
387 bool take_ownership_of_file_; 390 bool take_ownership_of_file_;
388 391
389 // Expected file error code for the test. 392 // Expected file error code for the test.
390 // PLATFORM_FILE_OK when expecting success. 393 // PLATFORM_FILE_OK when expecting success.
391 base::PlatformFileError expected_file_error_; 394 base::PlatformFileError expected_file_error_;
392 }; 395 };
393 396
394 void URLFetcherPostTest::CreateFetcher(const GURL& url) { 397 void URLFetcherPostTest::CreateFetcher(const GURL& url) {
395 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::POST, this); 398 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
396 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 399 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
397 io_message_loop_proxy(), request_context())); 400 io_message_loop_proxy(), request_context()));
398 fetcher_->SetUploadData("application/x-www-form-urlencoded", 401 fetcher_->SetUploadData("application/x-www-form-urlencoded",
399 "bobsyeruncle"); 402 "bobsyeruncle");
400 fetcher_->Start(); 403 fetcher_->Start();
401 } 404 }
402 405
403 void URLFetcherPostTest::OnURLFetchComplete(const net::URLFetcher* source) { 406 void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) {
404 std::string data; 407 std::string data;
405 EXPECT_TRUE(source->GetResponseAsString(&data)); 408 EXPECT_TRUE(source->GetResponseAsString(&data));
406 EXPECT_EQ(std::string("bobsyeruncle"), data); 409 EXPECT_EQ(std::string("bobsyeruncle"), data);
407 URLFetcherTest::OnURLFetchComplete(source); 410 URLFetcherTest::OnURLFetchComplete(source);
408 } 411 }
409 412
410 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { 413 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) {
411 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 414 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
412 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 415 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
413 io_message_loop_proxy(), request_context())); 416 io_message_loop_proxy(), request_context()));
414 previous_progress_ = 0; 417 previous_progress_ = 0;
415 fetcher_->Start(); 418 fetcher_->Start();
416 } 419 }
417 420
418 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( 421 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress(
419 const net::URLFetcher* source, int64 current, int64 total) { 422 const URLFetcher* source, int64 current, int64 total) {
420 // Increasing between 0 and total. 423 // Increasing between 0 and total.
421 EXPECT_LE(0, current); 424 EXPECT_LE(0, current);
422 EXPECT_GE(total, current); 425 EXPECT_GE(total, current);
423 EXPECT_LE(previous_progress_, current); 426 EXPECT_LE(previous_progress_, current);
424 previous_progress_ = current; 427 previous_progress_ = current;
425 EXPECT_EQ(expected_total_, total); 428 EXPECT_EQ(expected_total_, total);
426 } 429 }
427 430
428 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { 431 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) {
429 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 432 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
430 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 433 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
431 io_message_loop_proxy(), request_context())); 434 io_message_loop_proxy(), request_context()));
432 cancelled_ = false; 435 cancelled_ = false;
433 fetcher_->Start(); 436 fetcher_->Start();
434 } 437 }
435 438
436 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( 439 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress(
437 const net::URLFetcher* source, int64 current, int64 total) { 440 const URLFetcher* source, int64 current, int64 total) {
438 EXPECT_FALSE(cancelled_); 441 EXPECT_FALSE(cancelled_);
439 if (!cancelled_) { 442 if (!cancelled_) {
440 cancelled_ = true; 443 cancelled_ = true;
441 CleanupAfterFetchComplete(); 444 CleanupAfterFetchComplete();
442 } 445 }
443 } 446 }
444 447
445 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( 448 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete(
446 const net::URLFetcher* source) { 449 const URLFetcher* source) {
447 // Should have been cancelled. 450 // Should have been cancelled.
448 ADD_FAILURE(); 451 ADD_FAILURE();
449 CleanupAfterFetchComplete(); 452 CleanupAfterFetchComplete();
450 } 453 }
451 454
452 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { 455 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) {
453 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::POST, this); 456 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
454 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 457 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
455 io_message_loop_proxy(), request_context())); 458 io_message_loop_proxy(), request_context()));
456 previous_progress_ = 0; 459 previous_progress_ = 0;
457 // Large enough data to require more than one read from UploadDataStream. 460 // Large enough data to require more than one read from UploadDataStream.
458 chunk_.assign(1<<16, 'a'); 461 chunk_.assign(1<<16, 'a');
459 // Use chunked upload to wait for a timer event of progress notification. 462 // Use chunked upload to wait for a timer event of progress notification.
460 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); 463 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded");
461 fetcher_->Start(); 464 fetcher_->Start();
462 number_of_chunks_added_ = 1; 465 number_of_chunks_added_ = 1;
463 fetcher_->AppendChunkToUpload(chunk_, false); 466 fetcher_->AppendChunkToUpload(chunk_, false);
464 } 467 }
465 468
466 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( 469 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress(
467 const net::URLFetcher* source, int64 current, int64 total) { 470 const URLFetcher* source, int64 current, int64 total) {
468 // Increasing between 0 and total. 471 // Increasing between 0 and total.
469 EXPECT_LE(0, current); 472 EXPECT_LE(0, current);
470 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, 473 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_,
471 current); 474 current);
472 EXPECT_LE(previous_progress_, current); 475 EXPECT_LE(previous_progress_, current);
473 previous_progress_ = current; 476 previous_progress_ = current;
474 EXPECT_EQ(-1, total); 477 EXPECT_EQ(-1, total);
475 478
476 if (number_of_chunks_added_ < 2) { 479 if (number_of_chunks_added_ < 2) {
477 number_of_chunks_added_ += 1; 480 number_of_chunks_added_ += 1;
478 fetcher_->AppendChunkToUpload(chunk_, true); 481 fetcher_->AppendChunkToUpload(chunk_, true);
479 } 482 }
480 } 483 }
481 484
482 void URLFetcherHeadersTest::OnURLFetchComplete( 485 void URLFetcherHeadersTest::OnURLFetchComplete(
483 const net::URLFetcher* source) { 486 const URLFetcher* source) {
484 std::string header; 487 std::string header;
485 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control", 488 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control",
486 &header)); 489 &header));
487 EXPECT_EQ("private", header); 490 EXPECT_EQ("private", header);
488 URLFetcherTest::OnURLFetchComplete(source); 491 URLFetcherTest::OnURLFetchComplete(source);
489 } 492 }
490 493
491 void URLFetcherSocketAddressTest::OnURLFetchComplete( 494 void URLFetcherSocketAddressTest::OnURLFetchComplete(
492 const net::URLFetcher* source) { 495 const URLFetcher* source) {
493 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host()); 496 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host());
494 EXPECT_EQ(expected_port_, source->GetSocketAddress().port()); 497 EXPECT_EQ(expected_port_, source->GetSocketAddress().port());
495 URLFetcherTest::OnURLFetchComplete(source); 498 URLFetcherTest::OnURLFetchComplete(source);
496 } 499 }
497 500
498 // static 501 // static
499 const char* URLFetcherStopOnRedirectTest::kRedirectTarget = 502 const char* URLFetcherStopOnRedirectTest::kRedirectTarget =
500 "http://redirect.target.com"; 503 "http://redirect.target.com";
501 504
502 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest() 505 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest()
503 : callback_called_(false) { 506 : callback_called_(false) {
504 } 507 }
505 508
506 URLFetcherStopOnRedirectTest::~URLFetcherStopOnRedirectTest() { 509 URLFetcherStopOnRedirectTest::~URLFetcherStopOnRedirectTest() {
507 } 510 }
508 511
509 void URLFetcherStopOnRedirectTest::CreateFetcher(const GURL& url) { 512 void URLFetcherStopOnRedirectTest::CreateFetcher(const GURL& url) {
510 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 513 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
511 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 514 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
512 io_message_loop_proxy(), request_context())); 515 io_message_loop_proxy(), request_context()));
513 fetcher_->SetStopOnRedirect(true); 516 fetcher_->SetStopOnRedirect(true);
514 fetcher_->Start(); 517 fetcher_->Start();
515 } 518 }
516 519
517 void URLFetcherStopOnRedirectTest::OnURLFetchComplete( 520 void URLFetcherStopOnRedirectTest::OnURLFetchComplete(
518 const net::URLFetcher* source) { 521 const URLFetcher* source) {
519 callback_called_ = true; 522 callback_called_ = true;
520 EXPECT_EQ(GURL(kRedirectTarget), source->GetURL()); 523 EXPECT_EQ(GURL(kRedirectTarget), source->GetURL());
521 EXPECT_EQ(net::URLRequestStatus::CANCELED, source->GetStatus().status()); 524 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status());
522 EXPECT_EQ(301, source->GetResponseCode()); 525 EXPECT_EQ(301, source->GetResponseCode());
523 CleanupAfterFetchComplete(); 526 CleanupAfterFetchComplete();
524 } 527 }
525 528
526 void URLFetcherProtectTest::CreateFetcher(const GURL& url) { 529 void URLFetcherProtectTest::CreateFetcher(const GURL& url) {
527 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 530 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
528 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 531 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
529 io_message_loop_proxy(), request_context())); 532 io_message_loop_proxy(), request_context()));
530 start_time_ = Time::Now(); 533 start_time_ = Time::Now();
531 fetcher_->SetMaxRetries(11); 534 fetcher_->SetMaxRetries(11);
532 fetcher_->Start(); 535 fetcher_->Start();
533 } 536 }
534 537
535 void URLFetcherProtectTest::OnURLFetchComplete(const net::URLFetcher* source) { 538 void URLFetcherProtectTest::OnURLFetchComplete(const URLFetcher* source) {
536 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); 539 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000);
537 if (source->GetResponseCode() >= 500) { 540 if (source->GetResponseCode() >= 500) {
538 // Now running ServerUnavailable test. 541 // Now running ServerUnavailable test.
539 // It takes more than 1 second to finish all 11 requests. 542 // It takes more than 1 second to finish all 11 requests.
540 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); 543 EXPECT_TRUE(Time::Now() - start_time_ >= one_second);
541 EXPECT_TRUE(source->GetStatus().is_success()); 544 EXPECT_TRUE(source->GetStatus().is_success());
542 std::string data; 545 std::string data;
543 EXPECT_TRUE(source->GetResponseAsString(&data)); 546 EXPECT_TRUE(source->GetResponseAsString(&data));
544 EXPECT_FALSE(data.empty()); 547 EXPECT_FALSE(data.empty());
545 CleanupAfterFetchComplete(); 548 CleanupAfterFetchComplete();
546 } else { 549 } else {
547 // Now running Overload test. 550 // Now running Overload test.
548 static int count = 0; 551 static int count = 0;
549 count++; 552 count++;
550 if (count < 20) { 553 if (count < 20) {
551 fetcher_->SetRequestContext( 554 fetcher_->SetRequestContext(
552 new ThrottlingTestURLRequestContextGetter( 555 new ThrottlingTestURLRequestContextGetter(
553 io_message_loop_proxy(), request_context())); 556 io_message_loop_proxy(), request_context()));
554 fetcher_->Start(); 557 fetcher_->Start();
555 } else { 558 } else {
556 // We have already sent 20 requests continuously. And we expect that 559 // We have already sent 20 requests continuously. And we expect that
557 // it takes more than 1 second due to the overload protection settings. 560 // it takes more than 1 second due to the overload protection settings.
558 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); 561 EXPECT_TRUE(Time::Now() - start_time_ >= one_second);
559 URLFetcherTest::OnURLFetchComplete(source); 562 URLFetcherTest::OnURLFetchComplete(source);
560 } 563 }
561 } 564 }
562 } 565 }
563 566
564 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { 567 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) {
565 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 568 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
566 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 569 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
567 io_message_loop_proxy(), request_context())); 570 io_message_loop_proxy(), request_context()));
568 fetcher_->SetAutomaticallyRetryOn5xx(false); 571 fetcher_->SetAutomaticallyRetryOn5xx(false);
569 start_time_ = Time::Now(); 572 start_time_ = Time::Now();
570 fetcher_->SetMaxRetries(11); 573 fetcher_->SetMaxRetries(11);
571 fetcher_->Start(); 574 fetcher_->Start();
572 } 575 }
573 576
574 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete( 577 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete(
575 const net::URLFetcher* source) { 578 const URLFetcher* source) {
576 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000); 579 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000);
577 if (source->GetResponseCode() >= 500) { 580 if (source->GetResponseCode() >= 500) {
578 // Now running ServerUnavailable test. 581 // Now running ServerUnavailable test.
579 // It should get here on the first attempt, so almost immediately and 582 // It should get here on the first attempt, so almost immediately and
580 // *not* to attempt to execute all 11 requests (2.5 minutes). 583 // *not* to attempt to execute all 11 requests (2.5 minutes).
581 EXPECT_TRUE(Time::Now() - start_time_ < one_minute); 584 EXPECT_TRUE(Time::Now() - start_time_ < one_minute);
582 EXPECT_TRUE(source->GetStatus().is_success()); 585 EXPECT_TRUE(source->GetStatus().is_success());
583 // Check that suggested back off time is bigger than 0. 586 // Check that suggested back off time is bigger than 0.
584 EXPECT_GT(fetcher_->GetBackoffDelay().InMicroseconds(), 0); 587 EXPECT_GT(fetcher_->GetBackoffDelay().InMicroseconds(), 0);
585 std::string data; 588 std::string data;
(...skipping 12 matching lines...) Expand all
598 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); 601 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_);
599 cert_dir_ = cert_dir_.AppendASCII("chrome"); 602 cert_dir_ = cert_dir_.AppendASCII("chrome");
600 cert_dir_ = cert_dir_.AppendASCII("test"); 603 cert_dir_ = cert_dir_.AppendASCII("test");
601 cert_dir_ = cert_dir_.AppendASCII("data"); 604 cert_dir_ = cert_dir_.AppendASCII("data");
602 cert_dir_ = cert_dir_.AppendASCII("ssl"); 605 cert_dir_ = cert_dir_.AppendASCII("ssl");
603 cert_dir_ = cert_dir_.AppendASCII("certificates"); 606 cert_dir_ = cert_dir_.AppendASCII("certificates");
604 } 607 }
605 608
606 // The "server certificate expired" error should result in automatic 609 // The "server certificate expired" error should result in automatic
607 // cancellation of the request by 610 // cancellation of the request by
608 // net::URLRequest::Delegate::OnSSLCertificateError. 611 // URLRequest::Delegate::OnSSLCertificateError.
609 void URLFetcherBadHTTPSTest::OnURLFetchComplete( 612 void URLFetcherBadHTTPSTest::OnURLFetchComplete(
610 const net::URLFetcher* source) { 613 const URLFetcher* source) {
611 // This part is different from URLFetcherTest::OnURLFetchComplete 614 // This part is different from URLFetcherTest::OnURLFetchComplete
612 // because this test expects the request to be cancelled. 615 // because this test expects the request to be cancelled.
613 EXPECT_EQ(net::URLRequestStatus::CANCELED, source->GetStatus().status()); 616 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status());
614 EXPECT_EQ(net::ERR_ABORTED, source->GetStatus().error()); 617 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error());
615 EXPECT_EQ(-1, source->GetResponseCode()); 618 EXPECT_EQ(-1, source->GetResponseCode());
616 EXPECT_TRUE(source->GetCookies().empty()); 619 EXPECT_TRUE(source->GetCookies().empty());
617 std::string data; 620 std::string data;
618 EXPECT_TRUE(source->GetResponseAsString(&data)); 621 EXPECT_TRUE(source->GetResponseAsString(&data));
619 EXPECT_TRUE(data.empty()); 622 EXPECT_TRUE(data.empty());
620 CleanupAfterFetchComplete(); 623 CleanupAfterFetchComplete();
621 } 624 }
622 625
623 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { 626 void URLFetcherCancelTest::CreateFetcher(const GURL& url) {
624 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 627 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
625 CancelTestURLRequestContextGetter* context_getter = 628 CancelTestURLRequestContextGetter* context_getter =
626 new CancelTestURLRequestContextGetter(io_message_loop_proxy(), 629 new CancelTestURLRequestContextGetter(io_message_loop_proxy(),
627 url); 630 url);
628 fetcher_->SetRequestContext(context_getter); 631 fetcher_->SetRequestContext(context_getter);
629 fetcher_->SetMaxRetries(2); 632 fetcher_->SetMaxRetries(2);
630 fetcher_->Start(); 633 fetcher_->Start();
631 // We need to wait for the creation of the net::URLRequestContext, since we 634 // We need to wait for the creation of the URLRequestContext, since we
632 // rely on it being destroyed as a signal to end the test. 635 // rely on it being destroyed as a signal to end the test.
633 context_getter->WaitForContextCreation(); 636 context_getter->WaitForContextCreation();
634 CancelRequest(); 637 CancelRequest();
635 } 638 }
636 639
637 void URLFetcherCancelTest::OnURLFetchComplete( 640 void URLFetcherCancelTest::OnURLFetchComplete(
638 const net::URLFetcher* source) { 641 const URLFetcher* source) {
639 // We should have cancelled the request before completion. 642 // We should have cancelled the request before completion.
640 ADD_FAILURE(); 643 ADD_FAILURE();
641 CleanupAfterFetchComplete(); 644 CleanupAfterFetchComplete();
642 } 645 }
643 646
644 void URLFetcherCancelTest::CancelRequest() { 647 void URLFetcherCancelTest::CancelRequest() {
645 delete fetcher_; 648 delete fetcher_;
646 // The URLFetcher's test context will post a Quit task once it is 649 // The URLFetcher's test context will post a Quit task once it is
647 // deleted. So if this test simply hangs, it means cancellation 650 // deleted. So if this test simply hangs, it means cancellation
648 // did not work. 651 // did not work.
649 } 652 }
650 653
651 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( 654 void URLFetcherMultipleAttemptTest::OnURLFetchComplete(
652 const net::URLFetcher* source) { 655 const URLFetcher* source) {
653 EXPECT_TRUE(source->GetStatus().is_success()); 656 EXPECT_TRUE(source->GetStatus().is_success());
654 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 657 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
655 std::string data; 658 std::string data;
656 EXPECT_TRUE(source->GetResponseAsString(&data)); 659 EXPECT_TRUE(source->GetResponseAsString(&data));
657 EXPECT_FALSE(data.empty()); 660 EXPECT_FALSE(data.empty());
658 if (!data.empty() && data_.empty()) { 661 if (!data.empty() && data_.empty()) {
659 data_ = data; 662 data_ = data;
660 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 663 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
661 io_message_loop_proxy(), request_context())); 664 io_message_loop_proxy(), request_context()));
662 fetcher_->Start(); 665 fetcher_->Start();
663 } else { 666 } else {
664 EXPECT_EQ(data, data_); 667 EXPECT_EQ(data, data_);
665 CleanupAfterFetchComplete(); 668 CleanupAfterFetchComplete();
666 } 669 }
667 } 670 }
668 671
669 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url, 672 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url,
670 const FilePath& file_path) { 673 const FilePath& file_path) {
671 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 674 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
672 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 675 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
673 io_message_loop_proxy(), request_context())); 676 io_message_loop_proxy(), request_context()));
674 677
675 // Use the IO message loop to do the file operations in this test. 678 // Use the IO message loop to do the file operations in this test.
676 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy()); 679 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy());
677 fetcher_->Start(); 680 fetcher_->Start();
678 } 681 }
679 682
680 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { 683 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) {
681 fetcher_ = new URLFetcherImpl(url, net::URLFetcher::GET, this); 684 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
682 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 685 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
683 io_message_loop_proxy(), request_context())); 686 io_message_loop_proxy(), request_context()));
684 687
685 // Use the IO message loop to do the file operations in this test. 688 // Use the IO message loop to do the file operations in this test.
686 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); 689 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy());
687 fetcher_->Start(); 690 fetcher_->Start();
688 } 691 }
689 692
690 void URLFetcherFileTest::OnURLFetchComplete(const net::URLFetcher* source) { 693 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) {
691 if (expected_file_error_ == base::PLATFORM_FILE_OK) { 694 if (expected_file_error_ == base::PLATFORM_FILE_OK) {
692 EXPECT_TRUE(source->GetStatus().is_success()); 695 EXPECT_TRUE(source->GetStatus().is_success());
693 EXPECT_EQ(source->GetResponseCode(), 200); 696 EXPECT_EQ(source->GetResponseCode(), 200);
694 697
695 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 698 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
696 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code)); 699 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code));
697 700
698 EXPECT_TRUE(source->GetResponseAsFilePath( 701 EXPECT_TRUE(source->GetResponseAsFilePath(
699 take_ownership_of_file_, &file_path_)); 702 take_ownership_of_file_, &file_path_));
700 703
701 EXPECT_TRUE(file_util::ContentsEqual(expected_file_, file_path_)); 704 EXPECT_TRUE(file_util::ContentsEqual(expected_file_, file_path_));
702 } else { 705 } else {
703 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 706 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
704 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code)); 707 EXPECT_TRUE(fetcher_->FileErrorOccurred(&error_code));
705 EXPECT_EQ(expected_file_error_, error_code); 708 EXPECT_EQ(expected_file_error_, error_code);
706 } 709 }
707 CleanupAfterFetchComplete(); 710 CleanupAfterFetchComplete();
708 } 711 }
709 712
710 TEST_F(URLFetcherTest, SameThreadsTest) { 713 TEST_F(URLFetcherTest, SameThreadsTest) {
711 net::TestServer test_server(net::TestServer::TYPE_HTTP, 714 TestServer test_server(TestServer::TYPE_HTTP,
712 net::TestServer::kLocalhost, 715 TestServer::kLocalhost,
713 FilePath(kDocRoot)); 716 FilePath(kDocRoot));
714 ASSERT_TRUE(test_server.Start()); 717 ASSERT_TRUE(test_server.Start());
715 718
716 // Create the fetcher on the main thread. Since IO will happen on the main 719 // Create the fetcher on the main thread. Since IO will happen on the main
717 // thread, this will test URLFetcher's ability to do everything on one 720 // thread, this will test URLFetcher's ability to do everything on one
718 // thread. 721 // thread.
719 CreateFetcher(test_server.GetURL("defaultresponse")); 722 CreateFetcher(test_server.GetURL("defaultresponse"));
720 723
721 MessageLoop::current()->Run(); 724 MessageLoop::current()->Run();
722 } 725 }
723 726
724 #if defined(OS_MACOSX) 727 #if defined(OS_MACOSX)
725 // SIGSEGV on Mac: http://crbug.com/60426 728 // SIGSEGV on Mac: http://crbug.com/60426
726 TEST_F(URLFetcherTest, DISABLED_DifferentThreadsTest) { 729 TEST_F(URLFetcherTest, DISABLED_DifferentThreadsTest) {
727 #else 730 #else
728 TEST_F(URLFetcherTest, DifferentThreadsTest) { 731 TEST_F(URLFetcherTest, DifferentThreadsTest) {
729 #endif 732 #endif
730 net::TestServer test_server(net::TestServer::TYPE_HTTP, 733 TestServer test_server(TestServer::TYPE_HTTP,
731 net::TestServer::kLocalhost, 734 TestServer::kLocalhost,
732 FilePath(kDocRoot)); 735 FilePath(kDocRoot));
733 ASSERT_TRUE(test_server.Start()); 736 ASSERT_TRUE(test_server.Start());
734 737
735 // Create a separate thread that will create the URLFetcher. The current 738 // Create a separate thread that will create the URLFetcher. The current
736 // (main) thread will do the IO, and when the fetch is complete it will 739 // (main) thread will do the IO, and when the fetch is complete it will
737 // terminate the main thread's message loop; then the other thread's 740 // terminate the main thread's message loop; then the other thread's
738 // message loop will be shut down automatically as the thread goes out of 741 // message loop will be shut down automatically as the thread goes out of
739 // scope. 742 // scope.
740 base::Thread t("URLFetcher test thread"); 743 base::Thread t("URLFetcher test thread");
741 ASSERT_TRUE(t.Start()); 744 ASSERT_TRUE(t.Start());
742 t.message_loop()->PostTask( 745 t.message_loop()->PostTask(
743 FROM_HERE, 746 FROM_HERE,
744 base::Bind(&URLFetcherTest::CreateFetcher, 747 base::Bind(&URLFetcherTest::CreateFetcher,
745 base::Unretained(this), 748 base::Unretained(this),
746 test_server.GetURL("defaultresponse"))); 749 test_server.GetURL("defaultresponse")));
747 750
748 MessageLoop::current()->Run(); 751 MessageLoop::current()->Run();
749 } 752 }
750 753
751 void CancelAllOnIO() { 754 void CancelAllOnIO() {
752 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); 755 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores());
753 URLFetcherImpl::CancelAll(); 756 URLFetcherImpl::CancelAll();
754 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); 757 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores());
755 } 758 }
756 759
757 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers. 760 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers.
758 TEST_F(URLFetcherTest, CancelAll) { 761 TEST_F(URLFetcherTest, CancelAll) {
759 net::TestServer test_server(net::TestServer::TYPE_HTTP, 762 TestServer test_server(TestServer::TYPE_HTTP,
760 net::TestServer::kLocalhost, 763 TestServer::kLocalhost,
761 FilePath(kDocRoot)); 764 FilePath(kDocRoot));
762 ASSERT_TRUE(test_server.Start()); 765 ASSERT_TRUE(test_server.Start());
763 EXPECT_EQ(0, GetNumFetcherCores()); 766 EXPECT_EQ(0, GetNumFetcherCores());
764 767
765 CreateFetcher(test_server.GetURL("defaultresponse")); 768 CreateFetcher(test_server.GetURL("defaultresponse"));
766 io_message_loop_proxy()->PostTaskAndReply( 769 io_message_loop_proxy()->PostTaskAndReply(
767 FROM_HERE, 770 FROM_HERE,
768 base::Bind(&CancelAllOnIO), 771 base::Bind(&CancelAllOnIO),
769 MessageLoop::QuitClosure()); 772 MessageLoop::QuitClosure());
770 MessageLoop::current()->Run(); 773 MessageLoop::current()->Run();
771 EXPECT_EQ(0, GetNumFetcherCores()); 774 EXPECT_EQ(0, GetNumFetcherCores());
772 delete fetcher_; 775 delete fetcher_;
773 } 776 }
774 777
775 #if defined(OS_MACOSX) 778 #if defined(OS_MACOSX)
776 // SIGSEGV on Mac: http://crbug.com/60426 779 // SIGSEGV on Mac: http://crbug.com/60426
777 TEST_F(URLFetcherPostTest, DISABLED_Basic) { 780 TEST_F(URLFetcherPostTest, DISABLED_Basic) {
778 #else 781 #else
779 TEST_F(URLFetcherPostTest, Basic) { 782 TEST_F(URLFetcherPostTest, Basic) {
780 #endif 783 #endif
781 net::TestServer test_server(net::TestServer::TYPE_HTTP, 784 TestServer test_server(TestServer::TYPE_HTTP,
782 net::TestServer::kLocalhost, 785 TestServer::kLocalhost,
783 FilePath(kDocRoot)); 786 FilePath(kDocRoot));
784 ASSERT_TRUE(test_server.Start()); 787 ASSERT_TRUE(test_server.Start());
785 788
786 CreateFetcher(test_server.GetURL("echo")); 789 CreateFetcher(test_server.GetURL("echo"));
787 MessageLoop::current()->Run(); 790 MessageLoop::current()->Run();
788 } 791 }
789 792
790 #if defined(OS_MACOSX) 793 #if defined(OS_MACOSX)
791 // SIGSEGV on Mac: http://crbug.com/60426 794 // SIGSEGV on Mac: http://crbug.com/60426
792 TEST_F(URLFetcherUploadProgressTest, DISABLED_Basic) { 795 TEST_F(URLFetcherUploadProgressTest, DISABLED_Basic) {
793 #else 796 #else
794 TEST_F(URLFetcherUploadProgressTest, Basic) { 797 TEST_F(URLFetcherUploadProgressTest, Basic) {
795 #endif 798 #endif
796 net::TestServer test_server(net::TestServer::TYPE_HTTP, 799 TestServer test_server(TestServer::TYPE_HTTP,
797 net::TestServer::kLocalhost, 800 TestServer::kLocalhost,
798 FilePath(kDocRoot)); 801 FilePath(kDocRoot));
799 ASSERT_TRUE(test_server.Start()); 802 ASSERT_TRUE(test_server.Start());
800 803
801 CreateFetcher(test_server.GetURL("echo")); 804 CreateFetcher(test_server.GetURL("echo"));
802 MessageLoop::current()->Run(); 805 MessageLoop::current()->Run();
803 } 806 }
804 807
805 TEST_F(URLFetcherDownloadProgressTest, Basic) { 808 TEST_F(URLFetcherDownloadProgressTest, Basic) {
806 net::TestServer test_server(net::TestServer::TYPE_HTTP, 809 TestServer test_server(TestServer::TYPE_HTTP,
807 net::TestServer::kLocalhost, 810 TestServer::kLocalhost,
808 FilePath(kDocRoot)); 811 FilePath(kDocRoot));
809 ASSERT_TRUE(test_server.Start()); 812 ASSERT_TRUE(test_server.Start());
810 813
811 // Get a file large enough to require more than one read into 814 // Get a file large enough to require more than one read into
812 // URLFetcher::Core's IOBuffer. 815 // URLFetcher::Core's IOBuffer.
813 static const char kFileToFetch[] = "animate1.gif"; 816 static const char kFileToFetch[] = "animate1.gif";
814 file_util::GetFileSize(test_server.document_root().AppendASCII(kFileToFetch), 817 file_util::GetFileSize(test_server.document_root().AppendASCII(kFileToFetch),
815 &expected_total_); 818 &expected_total_);
816 CreateFetcher(test_server.GetURL( 819 CreateFetcher(test_server.GetURL(
817 std::string(kTestServerFilePrefix) + kFileToFetch)); 820 std::string(kTestServerFilePrefix) + kFileToFetch));
818 821
819 MessageLoop::current()->Run(); 822 MessageLoop::current()->Run();
820 } 823 }
821 824
822 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { 825 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) {
823 net::TestServer test_server(net::TestServer::TYPE_HTTP, 826 TestServer test_server(TestServer::TYPE_HTTP,
824 net::TestServer::kLocalhost, 827 TestServer::kLocalhost,
825 FilePath(kDocRoot)); 828 FilePath(kDocRoot));
826 ASSERT_TRUE(test_server.Start()); 829 ASSERT_TRUE(test_server.Start());
827 830
828 // Get a file large enough to require more than one read into 831 // Get a file large enough to require more than one read into
829 // URLFetcher::Core's IOBuffer. 832 // URLFetcher::Core's IOBuffer.
830 static const char kFileToFetch[] = "animate1.gif"; 833 static const char kFileToFetch[] = "animate1.gif";
831 CreateFetcher(test_server.GetURL( 834 CreateFetcher(test_server.GetURL(
832 std::string(kTestServerFilePrefix) + kFileToFetch)); 835 std::string(kTestServerFilePrefix) + kFileToFetch));
833 836
834 MessageLoop::current()->Run(); 837 MessageLoop::current()->Run();
835 } 838 }
836 839
837 TEST_F(URLFetcherHeadersTest, Headers) { 840 TEST_F(URLFetcherHeadersTest, Headers) {
838 net::TestServer test_server( 841 TestServer test_server(
839 net::TestServer::TYPE_HTTP, 842 TestServer::TYPE_HTTP,
840 net::TestServer::kLocalhost, 843 TestServer::kLocalhost,
841 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 844 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
842 ASSERT_TRUE(test_server.Start()); 845 ASSERT_TRUE(test_server.Start());
843 846
844 CreateFetcher(test_server.GetURL("files/with-headers.html")); 847 CreateFetcher(test_server.GetURL("files/with-headers.html"));
845 MessageLoop::current()->Run(); 848 MessageLoop::current()->Run();
846 // The actual tests are in the URLFetcherHeadersTest fixture. 849 // The actual tests are in the URLFetcherHeadersTest fixture.
847 } 850 }
848 851
849 TEST_F(URLFetcherSocketAddressTest, SocketAddress) { 852 TEST_F(URLFetcherSocketAddressTest, SocketAddress) {
850 net::TestServer test_server( 853 TestServer test_server(
851 net::TestServer::TYPE_HTTP, 854 TestServer::TYPE_HTTP,
852 net::TestServer::kLocalhost, 855 TestServer::kLocalhost,
853 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 856 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
854 ASSERT_TRUE(test_server.Start()); 857 ASSERT_TRUE(test_server.Start());
855 expected_port_ = test_server.host_port_pair().port(); 858 expected_port_ = test_server.host_port_pair().port();
856 859
857 // Reusing "with-headers.html" but doesn't really matter. 860 // Reusing "with-headers.html" but doesn't really matter.
858 CreateFetcher(test_server.GetURL("files/with-headers.html")); 861 CreateFetcher(test_server.GetURL("files/with-headers.html"));
859 MessageLoop::current()->Run(); 862 MessageLoop::current()->Run();
860 // The actual tests are in the URLFetcherSocketAddressTest fixture. 863 // The actual tests are in the URLFetcherSocketAddressTest fixture.
861 } 864 }
862 865
863 TEST_F(URLFetcherStopOnRedirectTest, StopOnRedirect) { 866 TEST_F(URLFetcherStopOnRedirectTest, StopOnRedirect) {
864 net::TestServer test_server(net::TestServer::TYPE_HTTP, 867 TestServer test_server(TestServer::TYPE_HTTP,
865 net::TestServer::kLocalhost, 868 TestServer::kLocalhost,
866 FilePath(kDocRoot)); 869 FilePath(kDocRoot));
867 ASSERT_TRUE(test_server.Start()); 870 ASSERT_TRUE(test_server.Start());
868 871
869 CreateFetcher( 872 CreateFetcher(
870 test_server.GetURL(std::string("server-redirect?") + kRedirectTarget)); 873 test_server.GetURL(std::string("server-redirect?") + kRedirectTarget));
871 MessageLoop::current()->Run(); 874 MessageLoop::current()->Run();
872 EXPECT_TRUE(callback_called_); 875 EXPECT_TRUE(callback_called_);
873 } 876 }
874 877
875 TEST_F(URLFetcherProtectTest, Overload) { 878 TEST_F(URLFetcherProtectTest, Overload) {
876 net::TestServer test_server(net::TestServer::TYPE_HTTP, 879 TestServer test_server(TestServer::TYPE_HTTP,
877 net::TestServer::kLocalhost, 880 TestServer::kLocalhost,
878 FilePath(kDocRoot)); 881 FilePath(kDocRoot));
879 ASSERT_TRUE(test_server.Start()); 882 ASSERT_TRUE(test_server.Start());
880 883
881 GURL url(test_server.GetURL("defaultresponse")); 884 GURL url(test_server.GetURL("defaultresponse"));
882 885
883 // Registers an entry for test url. It only allows 3 requests to be sent 886 // Registers an entry for test url. It only allows 3 requests to be sent
884 // in 200 milliseconds. 887 // in 200 milliseconds.
885 scoped_refptr<net::URLRequestThrottlerEntry> entry( 888 scoped_refptr<URLRequestThrottlerEntry> entry(
886 new net::URLRequestThrottlerEntry( 889 new URLRequestThrottlerEntry(
887 request_context()->throttler_manager(), 890 request_context()->throttler_manager(),
888 "", 200, 3, 1, 2.0, 0.0, 256)); 891 "", 200, 3, 1, 2.0, 0.0, 256));
889 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 892 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
890 893
891 CreateFetcher(url); 894 CreateFetcher(url);
892 895
893 MessageLoop::current()->Run(); 896 MessageLoop::current()->Run();
894 } 897 }
895 898
896 TEST_F(URLFetcherProtectTest, ServerUnavailable) { 899 TEST_F(URLFetcherProtectTest, ServerUnavailable) {
897 net::TestServer test_server(net::TestServer::TYPE_HTTP, 900 TestServer test_server(TestServer::TYPE_HTTP,
898 net::TestServer::kLocalhost, 901 TestServer::kLocalhost,
899 FilePath(kDocRoot)); 902 FilePath(kDocRoot));
900 ASSERT_TRUE(test_server.Start()); 903 ASSERT_TRUE(test_server.Start());
901 904
902 GURL url(test_server.GetURL("files/server-unavailable.html")); 905 GURL url(test_server.GetURL("files/server-unavailable.html"));
903 906
904 // Registers an entry for test url. The backoff time is calculated by: 907 // Registers an entry for test url. The backoff time is calculated by:
905 // new_backoff = 2.0 * old_backoff + 0 908 // new_backoff = 2.0 * old_backoff + 0
906 // and maximum backoff time is 256 milliseconds. 909 // and maximum backoff time is 256 milliseconds.
907 // Maximum retries allowed is set to 11. 910 // Maximum retries allowed is set to 11.
908 scoped_refptr<net::URLRequestThrottlerEntry> entry( 911 scoped_refptr<URLRequestThrottlerEntry> entry(
909 new net::URLRequestThrottlerEntry( 912 new URLRequestThrottlerEntry(
910 request_context()->throttler_manager(), 913 request_context()->throttler_manager(),
911 "", 200, 3, 1, 2.0, 0.0, 256)); 914 "", 200, 3, 1, 2.0, 0.0, 256));
912 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 915 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
913 916
914 CreateFetcher(url); 917 CreateFetcher(url);
915 918
916 MessageLoop::current()->Run(); 919 MessageLoop::current()->Run();
917 } 920 }
918 921
919 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { 922 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) {
920 net::TestServer test_server(net::TestServer::TYPE_HTTP, 923 TestServer test_server(TestServer::TYPE_HTTP,
921 net::TestServer::kLocalhost, 924 TestServer::kLocalhost,
922 FilePath(kDocRoot)); 925 FilePath(kDocRoot));
923 ASSERT_TRUE(test_server.Start()); 926 ASSERT_TRUE(test_server.Start());
924 927
925 GURL url(test_server.GetURL("files/server-unavailable.html")); 928 GURL url(test_server.GetURL("files/server-unavailable.html"));
926 929
927 // Registers an entry for test url. The backoff time is calculated by: 930 // Registers an entry for test url. The backoff time is calculated by:
928 // new_backoff = 2.0 * old_backoff + 0 931 // new_backoff = 2.0 * old_backoff + 0
929 // and maximum backoff time is 150000 milliseconds. 932 // and maximum backoff time is 150000 milliseconds.
930 // Maximum retries allowed is set to 11. 933 // Maximum retries allowed is set to 11.
931 scoped_refptr<net::URLRequestThrottlerEntry> entry( 934 scoped_refptr<URLRequestThrottlerEntry> entry(
932 new net::URLRequestThrottlerEntry( 935 new URLRequestThrottlerEntry(
933 request_context()->throttler_manager(), 936 request_context()->throttler_manager(),
934 "", 200, 3, 100, 2.0, 0.0, 150000)); 937 "", 200, 3, 100, 2.0, 0.0, 150000));
935 // Total time if *not* for not doing automatic backoff would be 150s. 938 // Total time if *not* for not doing automatic backoff would be 150s.
936 // In reality it should be "as soon as server responds". 939 // In reality it should be "as soon as server responds".
937 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 940 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
938 941
939 CreateFetcher(url); 942 CreateFetcher(url);
940 943
941 MessageLoop::current()->Run(); 944 MessageLoop::current()->Run();
942 } 945 }
943 946
944 #if defined(OS_MACOSX) 947 #if defined(OS_MACOSX)
945 // SIGSEGV on Mac: http://crbug.com/60426 948 // SIGSEGV on Mac: http://crbug.com/60426
946 TEST_F(URLFetcherBadHTTPSTest, DISABLED_BadHTTPSTest) { 949 TEST_F(URLFetcherBadHTTPSTest, DISABLED_BadHTTPSTest) {
947 #else 950 #else
948 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { 951 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) {
949 #endif 952 #endif
950 net::TestServer::HTTPSOptions https_options( 953 TestServer::HTTPSOptions https_options(
951 net::TestServer::HTTPSOptions::CERT_EXPIRED); 954 TestServer::HTTPSOptions::CERT_EXPIRED);
952 net::TestServer test_server(https_options, FilePath(kDocRoot)); 955 TestServer test_server(https_options, FilePath(kDocRoot));
953 ASSERT_TRUE(test_server.Start()); 956 ASSERT_TRUE(test_server.Start());
954 957
955 CreateFetcher(test_server.GetURL("defaultresponse")); 958 CreateFetcher(test_server.GetURL("defaultresponse"));
956 MessageLoop::current()->Run(); 959 MessageLoop::current()->Run();
957 } 960 }
958 961
959 #if defined(OS_MACOSX) 962 #if defined(OS_MACOSX)
960 // SIGSEGV on Mac: http://crbug.com/60426 963 // SIGSEGV on Mac: http://crbug.com/60426
961 TEST_F(URLFetcherCancelTest, DISABLED_ReleasesContext) { 964 TEST_F(URLFetcherCancelTest, DISABLED_ReleasesContext) {
962 #else 965 #else
963 TEST_F(URLFetcherCancelTest, ReleasesContext) { 966 TEST_F(URLFetcherCancelTest, ReleasesContext) {
964 #endif 967 #endif
965 net::TestServer test_server(net::TestServer::TYPE_HTTP, 968 TestServer test_server(TestServer::TYPE_HTTP,
966 net::TestServer::kLocalhost, 969 TestServer::kLocalhost,
967 FilePath(kDocRoot)); 970 FilePath(kDocRoot));
968 ASSERT_TRUE(test_server.Start()); 971 ASSERT_TRUE(test_server.Start());
969 972
970 GURL url(test_server.GetURL("files/server-unavailable.html")); 973 GURL url(test_server.GetURL("files/server-unavailable.html"));
971 974
972 // Create a separate thread that will create the URLFetcher. The current 975 // Create a separate thread that will create the URLFetcher. The current
973 // (main) thread will do the IO, and when the fetch is complete it will 976 // (main) thread will do the IO, and when the fetch is complete it will
974 // terminate the main thread's message loop; then the other thread's 977 // terminate the main thread's message loop; then the other thread's
975 // message loop will be shut down automatically as the thread goes out of 978 // message loop will be shut down automatically as the thread goes out of
976 // scope. 979 // scope.
977 base::Thread t("URLFetcher test thread"); 980 base::Thread t("URLFetcher test thread");
978 ASSERT_TRUE(t.Start()); 981 ASSERT_TRUE(t.Start());
979 t.message_loop()->PostTask( 982 t.message_loop()->PostTask(
980 FROM_HERE, 983 FROM_HERE,
981 base::Bind(&URLFetcherCancelTest::CreateFetcher, 984 base::Bind(&URLFetcherCancelTest::CreateFetcher,
982 base::Unretained(this), url)); 985 base::Unretained(this), url));
983 986
984 MessageLoop::current()->Run(); 987 MessageLoop::current()->Run();
985 } 988 }
986 989
987 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { 990 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) {
988 net::TestServer test_server(net::TestServer::TYPE_HTTP, 991 TestServer test_server(TestServer::TYPE_HTTP,
989 net::TestServer::kLocalhost, 992 TestServer::kLocalhost,
990 FilePath(kDocRoot)); 993 FilePath(kDocRoot));
991 ASSERT_TRUE(test_server.Start()); 994 ASSERT_TRUE(test_server.Start());
992 995
993 GURL url(test_server.GetURL("files/server-unavailable.html")); 996 GURL url(test_server.GetURL("files/server-unavailable.html"));
994 997
995 // Register an entry for test url. 998 // Register an entry for test url.
996 // Using a sliding window of 4 seconds, and max of 1 request, under a fast 999 // Using a sliding window of 4 seconds, and max of 1 request, under a fast
997 // run we expect to have a 4 second delay when posting the Start task. 1000 // run we expect to have a 4 second delay when posting the Start task.
998 scoped_refptr<net::URLRequestThrottlerEntry> entry( 1001 scoped_refptr<URLRequestThrottlerEntry> entry(
999 new net::URLRequestThrottlerEntry( 1002 new URLRequestThrottlerEntry(
1000 request_context()->throttler_manager(), 1003 request_context()->throttler_manager(),
1001 "", 4000, 1, 2000, 2.0, 0.0, 4000)); 1004 "", 4000, 1, 2000, 2.0, 0.0, 4000));
1002 request_context()->throttler_manager()->OverrideEntryForTests(url, entry); 1005 request_context()->throttler_manager()->OverrideEntryForTests(url, entry);
1003 // Fake that a request has just started. 1006 // Fake that a request has just started.
1004 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); 1007 entry->ReserveSendingTimeForNextRequest(base::TimeTicks());
1005 1008
1006 // The next request we try to send will be delayed by ~4 seconds. 1009 // The next request we try to send will be delayed by ~4 seconds.
1007 // The slower the test runs, the less the delay will be (since it takes the 1010 // The slower the test runs, the less the delay will be (since it takes the
1008 // time difference from now). 1011 // time difference from now).
1009 1012
1010 base::Thread t("URLFetcher test thread"); 1013 base::Thread t("URLFetcher test thread");
1011 ASSERT_TRUE(t.Start()); 1014 ASSERT_TRUE(t.Start());
1012 t.message_loop()->PostTask( 1015 t.message_loop()->PostTask(
1013 FROM_HERE, 1016 FROM_HERE,
1014 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); 1017 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url));
1015 1018
1016 MessageLoop::current()->Run(); 1019 MessageLoop::current()->Run();
1017 } 1020 }
1018 1021
1019 TEST_F(URLFetcherMultipleAttemptTest, SameData) { 1022 TEST_F(URLFetcherMultipleAttemptTest, SameData) {
1020 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1023 TestServer test_server(TestServer::TYPE_HTTP,
1021 net::TestServer::kLocalhost, 1024 TestServer::kLocalhost,
1022 FilePath(kDocRoot)); 1025 FilePath(kDocRoot));
1023 ASSERT_TRUE(test_server.Start()); 1026 ASSERT_TRUE(test_server.Start());
1024 1027
1025 // Create the fetcher on the main thread. Since IO will happen on the main 1028 // Create the fetcher on the main thread. Since IO will happen on the main
1026 // thread, this will test URLFetcher's ability to do everything on one 1029 // thread, this will test URLFetcher's ability to do everything on one
1027 // thread. 1030 // thread.
1028 CreateFetcher(test_server.GetURL("defaultresponse")); 1031 CreateFetcher(test_server.GetURL("defaultresponse"));
1029 1032
1030 MessageLoop::current()->Run(); 1033 MessageLoop::current()->Run();
1031 } 1034 }
1032 1035
1033 TEST_F(URLFetcherFileTest, SmallGet) { 1036 TEST_F(URLFetcherFileTest, SmallGet) {
1034 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1037 TestServer test_server(TestServer::TYPE_HTTP,
1035 net::TestServer::kLocalhost, 1038 TestServer::kLocalhost,
1036 FilePath(kDocRoot)); 1039 FilePath(kDocRoot));
1037 ASSERT_TRUE(test_server.Start()); 1040 ASSERT_TRUE(test_server.Start());
1038 1041
1039 ScopedTempDir temp_dir; 1042 ScopedTempDir temp_dir;
1040 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1043 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1041 1044
1042 // Get a small file. 1045 // Get a small file.
1043 static const char kFileToFetch[] = "simple.html"; 1046 static const char kFileToFetch[] = "simple.html";
1044 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1047 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1045 CreateFetcherForFile( 1048 CreateFetcherForFile(
1046 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1049 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1047 temp_dir.path().AppendASCII(kFileToFetch)); 1050 temp_dir.path().AppendASCII(kFileToFetch));
1048 1051
1049 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1052 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1050 1053
1051 ASSERT_FALSE(file_util::PathExists(file_path_)) 1054 ASSERT_FALSE(file_util::PathExists(file_path_))
1052 << file_path_.value() << " not removed."; 1055 << file_path_.value() << " not removed.";
1053 } 1056 }
1054 1057
1055 TEST_F(URLFetcherFileTest, LargeGet) { 1058 TEST_F(URLFetcherFileTest, LargeGet) {
1056 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1059 TestServer test_server(TestServer::TYPE_HTTP,
1057 net::TestServer::kLocalhost, 1060 TestServer::kLocalhost,
1058 FilePath(kDocRoot)); 1061 FilePath(kDocRoot));
1059 ASSERT_TRUE(test_server.Start()); 1062 ASSERT_TRUE(test_server.Start());
1060 1063
1061 ScopedTempDir temp_dir; 1064 ScopedTempDir temp_dir;
1062 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1065 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1063 1066
1064 // Get a file large enough to require more than one read into 1067 // Get a file large enough to require more than one read into
1065 // URLFetcher::Core's IOBuffer. 1068 // URLFetcher::Core's IOBuffer.
1066 static const char kFileToFetch[] = "animate1.gif"; 1069 static const char kFileToFetch[] = "animate1.gif";
1067 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1070 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1068 CreateFetcherForFile( 1071 CreateFetcherForFile(
1069 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1072 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1070 temp_dir.path().AppendASCII(kFileToFetch)); 1073 temp_dir.path().AppendASCII(kFileToFetch));
1071 1074
1072 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1075 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1073 } 1076 }
1074 1077
1075 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfFile) { 1078 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfFile) {
1076 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1079 TestServer test_server(TestServer::TYPE_HTTP,
1077 net::TestServer::kLocalhost, 1080 TestServer::kLocalhost,
1078 FilePath(kDocRoot)); 1081 FilePath(kDocRoot));
1079 ASSERT_TRUE(test_server.Start()); 1082 ASSERT_TRUE(test_server.Start());
1080 1083
1081 ScopedTempDir temp_dir; 1084 ScopedTempDir temp_dir;
1082 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1085 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1083 1086
1084 // Get a small file. 1087 // Get a small file.
1085 static const char kFileToFetch[] = "simple.html"; 1088 static const char kFileToFetch[] = "simple.html";
1086 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1089 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1087 CreateFetcherForFile( 1090 CreateFetcherForFile(
1088 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1091 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1089 temp_dir.path().AppendASCII(kFileToFetch)); 1092 temp_dir.path().AppendASCII(kFileToFetch));
1090 1093
1091 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1094 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1092 1095
1093 MessageLoop::current()->RunAllPending(); 1096 MessageLoop::current()->RunAllPending();
1094 ASSERT_FALSE(file_util::PathExists(file_path_)) 1097 ASSERT_FALSE(file_util::PathExists(file_path_))
1095 << file_path_.value() << " not removed."; 1098 << file_path_.value() << " not removed.";
1096 } 1099 }
1097 1100
1098 1101
1099 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { 1102 TEST_F(URLFetcherFileTest, OverwriteExistingFile) {
1100 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1103 TestServer test_server(TestServer::TYPE_HTTP,
1101 net::TestServer::kLocalhost, 1104 TestServer::kLocalhost,
1102 FilePath(kDocRoot)); 1105 FilePath(kDocRoot));
1103 ASSERT_TRUE(test_server.Start()); 1106 ASSERT_TRUE(test_server.Start());
1104 1107
1105 ScopedTempDir temp_dir; 1108 ScopedTempDir temp_dir;
1106 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1109 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1107 1110
1108 // Create a file before trying to fetch. 1111 // Create a file before trying to fetch.
1109 static const char kFileToFetch[] = "simple.html"; 1112 static const char kFileToFetch[] = "simple.html";
1110 static const char kData[] = "abcdefghijklmnopqrstuvwxyz"; 1113 static const char kData[] = "abcdefghijklmnopqrstuvwxyz";
1111 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); 1114 file_path_ = temp_dir.path().AppendASCII(kFileToFetch);
1112 const int data_size = arraysize(kData); 1115 const int data_size = arraysize(kData);
1113 ASSERT_EQ(file_util::WriteFile(file_path_, kData, data_size), data_size); 1116 ASSERT_EQ(file_util::WriteFile(file_path_, kData, data_size), data_size);
1114 ASSERT_TRUE(file_util::PathExists(file_path_)); 1117 ASSERT_TRUE(file_util::PathExists(file_path_));
1115 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1118 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1116 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_)); 1119 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_));
1117 1120
1118 // Get a small file. 1121 // Get a small file.
1119 CreateFetcherForFile( 1122 CreateFetcherForFile(
1120 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1123 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1121 file_path_); 1124 file_path_);
1122 1125
1123 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1126 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1124 } 1127 }
1125 1128
1126 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { 1129 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) {
1127 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1130 TestServer test_server(TestServer::TYPE_HTTP,
1128 net::TestServer::kLocalhost, 1131 TestServer::kLocalhost,
1129 FilePath(kDocRoot)); 1132 FilePath(kDocRoot));
1130 ASSERT_TRUE(test_server.Start()); 1133 ASSERT_TRUE(test_server.Start());
1131 1134
1132 ScopedTempDir temp_dir; 1135 ScopedTempDir temp_dir;
1133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1136 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1134 1137
1135 // Create a directory before trying to fetch. 1138 // Create a directory before trying to fetch.
1136 static const char kFileToFetch[] = "simple.html"; 1139 static const char kFileToFetch[] = "simple.html";
1137 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); 1140 file_path_ = temp_dir.path().AppendASCII(kFileToFetch);
1138 ASSERT_TRUE(file_util::CreateDirectory(file_path_)); 1141 ASSERT_TRUE(file_util::CreateDirectory(file_path_));
1139 ASSERT_TRUE(file_util::PathExists(file_path_)); 1142 ASSERT_TRUE(file_util::PathExists(file_path_));
1140 1143
1141 // Get a small file. 1144 // Get a small file.
1142 expected_file_error_ = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; 1145 expected_file_error_ = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
1143 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1146 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1144 CreateFetcherForFile( 1147 CreateFetcherForFile(
1145 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1148 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1146 file_path_); 1149 file_path_);
1147 1150
1148 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1151 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1149 1152
1150 MessageLoop::current()->RunAllPending(); 1153 MessageLoop::current()->RunAllPending();
1151 } 1154 }
1152 1155
1153 TEST_F(URLFetcherFileTest, SmallGetToTempFile) { 1156 TEST_F(URLFetcherFileTest, SmallGetToTempFile) {
1154 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1157 TestServer test_server(TestServer::TYPE_HTTP,
1155 net::TestServer::kLocalhost, 1158 TestServer::kLocalhost,
1156 FilePath(kDocRoot)); 1159 FilePath(kDocRoot));
1157 ASSERT_TRUE(test_server.Start()); 1160 ASSERT_TRUE(test_server.Start());
1158 1161
1159 // Get a small file. 1162 // Get a small file.
1160 static const char kFileToFetch[] = "simple.html"; 1163 static const char kFileToFetch[] = "simple.html";
1161 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1164 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1162 CreateFetcherForTempFile( 1165 CreateFetcherForTempFile(
1163 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); 1166 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch));
1164 1167
1165 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1168 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1166 1169
1167 ASSERT_FALSE(file_util::PathExists(file_path_)) 1170 ASSERT_FALSE(file_util::PathExists(file_path_))
1168 << file_path_.value() << " not removed."; 1171 << file_path_.value() << " not removed.";
1169 } 1172 }
1170 1173
1171 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { 1174 TEST_F(URLFetcherFileTest, LargeGetToTempFile) {
1172 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1175 TestServer test_server(TestServer::TYPE_HTTP,
1173 net::TestServer::kLocalhost, 1176 TestServer::kLocalhost,
1174 FilePath(kDocRoot)); 1177 FilePath(kDocRoot));
1175 ASSERT_TRUE(test_server.Start()); 1178 ASSERT_TRUE(test_server.Start());
1176 1179
1177 // Get a file large enough to require more than one read into 1180 // Get a file large enough to require more than one read into
1178 // URLFetcher::Core's IOBuffer. 1181 // URLFetcher::Core's IOBuffer.
1179 static const char kFileToFetch[] = "animate1.gif"; 1182 static const char kFileToFetch[] = "animate1.gif";
1180 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1183 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1181 CreateFetcherForTempFile(test_server.GetURL( 1184 CreateFetcherForTempFile(test_server.GetURL(
1182 std::string(kTestServerFilePrefix) + kFileToFetch)); 1185 std::string(kTestServerFilePrefix) + kFileToFetch));
1183 1186
1184 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1187 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1185 } 1188 }
1186 1189
1187 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfTempFile) { 1190 TEST_F(URLFetcherFileTest, CanTakeOwnershipOfTempFile) {
1188 net::TestServer test_server(net::TestServer::TYPE_HTTP, 1191 TestServer test_server(TestServer::TYPE_HTTP,
1189 net::TestServer::kLocalhost, 1192 TestServer::kLocalhost,
1190 FilePath(kDocRoot)); 1193 FilePath(kDocRoot));
1191 ASSERT_TRUE(test_server.Start()); 1194 ASSERT_TRUE(test_server.Start());
1192 1195
1193 // Get a small file. 1196 // Get a small file.
1194 static const char kFileToFetch[] = "simple.html"; 1197 static const char kFileToFetch[] = "simple.html";
1195 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); 1198 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
1196 CreateFetcherForTempFile(test_server.GetURL( 1199 CreateFetcherForTempFile(test_server.GetURL(
1197 std::string(kTestServerFilePrefix) + kFileToFetch)); 1200 std::string(kTestServerFilePrefix) + kFileToFetch));
1198 1201
1199 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1202 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1200 1203
1201 MessageLoop::current()->RunAllPending(); 1204 MessageLoop::current()->RunAllPending();
1202 ASSERT_FALSE(file_util::PathExists(file_path_)) 1205 ASSERT_FALSE(file_util::PathExists(file_path_))
1203 << file_path_.value() << " not removed."; 1206 << file_path_.value() << " not removed.";
1204 } 1207 }
1205 1208
1206 } // namespace. 1209 } // namespace
1210
1211 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698