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

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

Issue 11308035: Fix URLFetcherDownloadProgressTest to work with remote test server (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Hardcode the file size in the test Created 8 years, 1 month 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
« no previous file with comments | « build/android/gtest_filter/net_unittests_disabled ('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 "net/url_request/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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 class ThrottlingTestURLRequestContextGetter 54 class ThrottlingTestURLRequestContextGetter
55 : public TestURLRequestContextGetter { 55 : public TestURLRequestContextGetter {
56 public: 56 public:
57 ThrottlingTestURLRequestContextGetter( 57 ThrottlingTestURLRequestContextGetter(
58 base::MessageLoopProxy* io_message_loop_proxy, 58 base::MessageLoopProxy* io_message_loop_proxy,
59 TestURLRequestContext* request_context) 59 TestURLRequestContext* request_context)
60 : TestURLRequestContextGetter(io_message_loop_proxy), 60 : TestURLRequestContextGetter(io_message_loop_proxy),
61 context_(request_context) { 61 context_(request_context) {
62 } 62 }
63 63
64 // TestURLRequestContextGetter:
64 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { 65 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
65 return context_; 66 return context_;
66 } 67 }
67 68
68 protected: 69 protected:
69 virtual ~ThrottlingTestURLRequestContextGetter() {} 70 virtual ~ThrottlingTestURLRequestContextGetter() {}
70 71
71 TestURLRequestContext* const context_; 72 TestURLRequestContext* const context_;
72 }; 73 };
73 74
74 } // namespace 75 } // namespace
75 76
76 class URLFetcherTest : public testing::Test, 77 class URLFetcherTest : public testing::Test,
77 public URLFetcherDelegate { 78 public URLFetcherDelegate {
78 public: 79 public:
79 URLFetcherTest() 80 URLFetcherTest()
80 : fetcher_(NULL), 81 : fetcher_(NULL),
81 context_(new ThrottlingTestURLRequestContext()) { 82 context_(new ThrottlingTestURLRequestContext()) {
82 } 83 }
83 84
84 static int GetNumFetcherCores() { 85 static int GetNumFetcherCores() {
85 return URLFetcherImpl::GetNumFetcherCores(); 86 return URLFetcherImpl::GetNumFetcherCores();
86 } 87 }
87 88
88 // Creates a URLFetcher, using the program's main thread to do IO. 89 // Creates a URLFetcher, using the program's main thread to do IO.
89 virtual void CreateFetcher(const GURL& url); 90 virtual void CreateFetcher(const GURL& url);
90 91
91 // URLFetcherDelegate 92 // URLFetcherDelegate:
92 // Subclasses that override this should either call this function or 93 // Subclasses that override this should either call this function or
93 // CleanupAfterFetchComplete() at the end of their processing, depending on 94 // CleanupAfterFetchComplete() at the end of their processing, depending on
94 // whether they want to check for a non-empty HTTP 200 response or not. 95 // whether they want to check for a non-empty HTTP 200 response or not.
95 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 96 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
96 97
97 // Deletes |fetcher| and terminates the message loop. 98 // Deletes |fetcher| and terminates the message loop.
98 void CleanupAfterFetchComplete(); 99 void CleanupAfterFetchComplete();
99 100
100 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { 101 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() {
101 return io_message_loop_proxy_; 102 return io_message_loop_proxy_;
102 } 103 }
103 104
104 TestURLRequestContext* request_context() { 105 TestURLRequestContext* request_context() {
105 return context_.get(); 106 return context_.get();
106 } 107 }
107 108
108 protected: 109 protected:
110 // testing::Test:
109 virtual void SetUp() OVERRIDE { 111 virtual void SetUp() OVERRIDE {
110 testing::Test::SetUp(); 112 testing::Test::SetUp();
111 113
112 io_message_loop_proxy_ = base::MessageLoopProxy::current(); 114 io_message_loop_proxy_ = base::MessageLoopProxy::current();
113 115
114 #if defined(USE_NSS) 116 #if defined(USE_NSS)
115 crypto::EnsureNSSInit(); 117 crypto::EnsureNSSInit();
116 EnsureNSSHttpIOInit(); 118 EnsureNSSHttpIOInit();
117 #endif 119 #endif
118 } 120 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 161 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
160 // If the current message loop is not the IO loop, it will be shut down when 162 // If the current message loop is not the IO loop, it will be shut down when
161 // the main loop returns and this thread subsequently goes out of scope. 163 // the main loop returns and this thread subsequently goes out of scope.
162 } 164 }
163 165
164 namespace { 166 namespace {
165 167
166 // Version of URLFetcherTest that does a POST instead 168 // Version of URLFetcherTest that does a POST instead
167 class URLFetcherPostTest : public URLFetcherTest { 169 class URLFetcherPostTest : public URLFetcherTest {
168 public: 170 public:
169 // URLFetcherTest override. 171 // URLFetcherTest:
170 virtual void CreateFetcher(const GURL& url) OVERRIDE; 172 virtual void CreateFetcher(const GURL& url) OVERRIDE;
171
172 // URLFetcherDelegate
wtc 2012/11/26 23:19:06 Strictly speaking, these "URLFetcherDelegate" comm
ppi 2012/11/29 13:07:59 I agree - I think that precise "URLFetcherDelegate
173 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 173 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
174 }; 174 };
175 175
176 // Version of URLFetcherTest that does a POST instead with empty upload body 176 // Version of URLFetcherTest that does a POST instead with empty upload body
177 class URLFetcherEmptyPostTest : public URLFetcherTest { 177 class URLFetcherEmptyPostTest : public URLFetcherTest {
178 public: 178 public:
179 // URLFetcherTest override. 179 // URLFetcherTest:
180 virtual void CreateFetcher(const GURL& url) OVERRIDE; 180 virtual void CreateFetcher(const GURL& url) OVERRIDE;
181
182 // URLFetcherDelegate
183 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 181 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
184 }; 182 };
185 183
186 // Version of URLFetcherTest that tests download progress reports. 184 // Version of URLFetcherTest that tests download progress reports.
187 class URLFetcherDownloadProgressTest : public URLFetcherTest { 185 class URLFetcherDownloadProgressTest : public URLFetcherTest {
188 public: 186 public:
189 // URLFetcherTest override. 187 URLFetcherDownloadProgressTest()
188 : previous_progress_(0),
189 first_call_(true),
190 expected_total_size_(0) {
191 }
192
193 // URLFetcherTest:
190 virtual void CreateFetcher(const GURL& url) OVERRIDE; 194 virtual void CreateFetcher(const GURL& url) OVERRIDE;
195 virtual void OnURLFetchDownloadProgress(const URLFetcher* source,
196 int64 current,
197 int64 total) OVERRIDE;
191 198
192 // URLFetcherDelegate
193 virtual void OnURLFetchDownloadProgress(const URLFetcher* source,
194 int64 current, int64 total) OVERRIDE;
195 protected: 199 protected:
200 // Data returned by the previous callback.
wtc 2012/11/26 23:19:06 "Data" => "Download progress" or "Number of bytes"
ppi 2012/11/29 13:07:59 Absolutely, fixed. On 2012/11/26 23:19:06, wtc wr
196 int64 previous_progress_; 201 int64 previous_progress_;
197 int64 expected_total_; 202 // Indicates that |previous_progress| is not yet set.
203 bool first_call_;
204 // Size of the file being downloaded, known in advance (provided by each test
205 // case).
206 int64 expected_total_size_;
wtc 2012/11/26 23:19:06 1. We don't need first_call_ any more. Since previ
ppi 2012/11/29 13:07:59 I find "expected_total_size_" more descriptive and
198 }; 207 };
199 208
200 /// Version of URLFetcherTest that tests progress reports at cancellation. 209 // Version of URLFetcherTest that tests progress reports at cancellation.
201 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { 210 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest {
202 public: 211 public:
203 // URLFetcherTest override. 212 // URLFetcherTest:
204 virtual void CreateFetcher(const GURL& url) OVERRIDE; 213 virtual void CreateFetcher(const GURL& url) OVERRIDE;
205
206 // URLFetcherDelegate
207 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 214 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
208 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, 215 virtual void OnURLFetchDownloadProgress(const URLFetcher* source,
209 int64 current, int64 total) OVERRIDE; 216 int64 current,
217 int64 total) OVERRIDE;
210 protected: 218 protected:
211 bool cancelled_; 219 bool cancelled_;
212 }; 220 };
213 221
214 // Version of URLFetcherTest that tests upload progress reports. 222 // Version of URLFetcherTest that tests upload progress reports.
215 class URLFetcherUploadProgressTest : public URLFetcherTest { 223 class URLFetcherUploadProgressTest : public URLFetcherTest {
216 public: 224 public:
217 virtual void CreateFetcher(const GURL& url); 225 // URLFetcherTest:
218 226 virtual void CreateFetcher(const GURL& url) OVERRIDE;
219 // URLFetcherDelegate
220 virtual void OnURLFetchUploadProgress(const URLFetcher* source, 227 virtual void OnURLFetchUploadProgress(const URLFetcher* source,
221 int64 current, int64 total); 228 int64 current,
229 int64 total) OVERRIDE;
222 protected: 230 protected:
223 int64 previous_progress_; 231 int64 previous_progress_;
224 std::string chunk_; 232 std::string chunk_;
225 int64 number_of_chunks_added_; 233 int64 number_of_chunks_added_;
226 }; 234 };
227 235
228 // Version of URLFetcherTest that tests headers. 236 // Version of URLFetcherTest that tests headers.
229 class URLFetcherHeadersTest : public URLFetcherTest { 237 class URLFetcherHeadersTest : public URLFetcherTest {
230 public: 238 public:
231 // URLFetcherDelegate 239 // URLFetcherTest:
232 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 240 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
233 }; 241 };
234 242
235 // Version of URLFetcherTest that tests SocketAddress. 243 // Version of URLFetcherTest that tests SocketAddress.
236 class URLFetcherSocketAddressTest : public URLFetcherTest { 244 class URLFetcherSocketAddressTest : public URLFetcherTest {
237 public: 245 public:
238 // URLFetcherDelegate 246 // URLFetcherTest:
239 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 247 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
240 protected: 248 protected:
241 std::string expected_host_; 249 std::string expected_host_;
242 uint16 expected_port_; 250 uint16 expected_port_;
243 }; 251 };
244 252
245 // Version of URLFetcherTest that tests stopping on a redirect. 253 // Version of URLFetcherTest that tests stopping on a redirect.
246 class URLFetcherStopOnRedirectTest : public URLFetcherTest { 254 class URLFetcherStopOnRedirectTest : public URLFetcherTest {
247 public: 255 public:
248 URLFetcherStopOnRedirectTest(); 256 URLFetcherStopOnRedirectTest();
249 virtual ~URLFetcherStopOnRedirectTest(); 257 virtual ~URLFetcherStopOnRedirectTest();
250 258
251 // URLFetcherTest override. 259 // URLFetcherTest:
252 virtual void CreateFetcher(const GURL& url) OVERRIDE; 260 virtual void CreateFetcher(const GURL& url) OVERRIDE;
253 // URLFetcherDelegate
254 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 261 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
255 262
256 protected: 263 protected:
257 // The URL we should be redirected to. 264 // The URL we should be redirected to.
258 static const char* kRedirectTarget; 265 static const char* kRedirectTarget;
259 266
260 bool callback_called_; // Set to true in OnURLFetchComplete(). 267 bool callback_called_; // Set to true in OnURLFetchComplete().
261 }; 268 };
262 269
263 // Version of URLFetcherTest that tests overload protection. 270 // Version of URLFetcherTest that tests overload protection.
264 class URLFetcherProtectTest : public URLFetcherTest { 271 class URLFetcherProtectTest : public URLFetcherTest {
265 public: 272 public:
266 // URLFetcherTest override. 273 // URLFetcherTest:
267 virtual void CreateFetcher(const GURL& url) OVERRIDE; 274 virtual void CreateFetcher(const GURL& url) OVERRIDE;
268 // URLFetcherDelegate
269 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 275 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
270 private: 276 private:
271 Time start_time_; 277 Time start_time_;
272 }; 278 };
273 279
274 // Version of URLFetcherTest that tests overload protection, when responses 280 // Version of URLFetcherTest that tests overload protection, when responses
275 // passed through. 281 // passed through.
276 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { 282 class URLFetcherProtectTestPassedThrough : public URLFetcherTest {
277 public: 283 public:
278 // URLFetcherTest override. 284 // URLFetcherTest:
279 virtual void CreateFetcher(const GURL& url) OVERRIDE; 285 virtual void CreateFetcher(const GURL& url) OVERRIDE;
280 // URLFetcherDelegate
281 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 286 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
282 private: 287 private:
283 Time start_time_; 288 Time start_time_;
284 }; 289 };
285 290
286 // Version of URLFetcherTest that tests bad HTTPS requests. 291 // Version of URLFetcherTest that tests bad HTTPS requests.
287 class URLFetcherBadHTTPSTest : public URLFetcherTest { 292 class URLFetcherBadHTTPSTest : public URLFetcherTest {
288 public: 293 public:
289 URLFetcherBadHTTPSTest(); 294 URLFetcherBadHTTPSTest();
290 295
291 // URLFetcherDelegate 296 // URLFetcherTest:
292 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 297 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
293 298
294 private: 299 private:
295 FilePath cert_dir_; 300 FilePath cert_dir_;
296 }; 301 };
297 302
298 // Version of URLFetcherTest that tests request cancellation on shutdown. 303 // Version of URLFetcherTest that tests request cancellation on shutdown.
299 class URLFetcherCancelTest : public URLFetcherTest { 304 class URLFetcherCancelTest : public URLFetcherTest {
300 public: 305 public:
301 // URLFetcherTest override. 306 // URLFetcherTest:
302 virtual void CreateFetcher(const GURL& url) OVERRIDE; 307 virtual void CreateFetcher(const GURL& url) OVERRIDE;
303 // URLFetcherDelegate
304 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 308 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
305 309
306 void CancelRequest(); 310 void CancelRequest();
307 }; 311 };
308 312
309 // Version of TestURLRequestContext that posts a Quit task to the IO 313 // Version of TestURLRequestContext that posts a Quit task to the IO
310 // thread once it is deleted. 314 // thread once it is deleted.
311 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { 315 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext {
312 public: 316 public:
313 explicit CancelTestURLRequestContext() { 317 explicit CancelTestURLRequestContext() {
(...skipping 11 matching lines...) Expand all
325 : public TestURLRequestContextGetter { 329 : public TestURLRequestContextGetter {
326 public: 330 public:
327 CancelTestURLRequestContextGetter( 331 CancelTestURLRequestContextGetter(
328 base::MessageLoopProxy* io_message_loop_proxy, 332 base::MessageLoopProxy* io_message_loop_proxy,
329 const GURL& throttle_for_url) 333 const GURL& throttle_for_url)
330 : TestURLRequestContextGetter(io_message_loop_proxy), 334 : TestURLRequestContextGetter(io_message_loop_proxy),
331 io_message_loop_proxy_(io_message_loop_proxy), 335 io_message_loop_proxy_(io_message_loop_proxy),
332 context_created_(false, false), 336 context_created_(false, false),
333 throttle_for_url_(throttle_for_url) { 337 throttle_for_url_(throttle_for_url) {
334 } 338 }
339
340 // TestURLRequestContextGetter:
335 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { 341 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
336 if (!context_.get()) { 342 if (!context_.get()) {
337 context_.reset(new CancelTestURLRequestContext()); 343 context_.reset(new CancelTestURLRequestContext());
338 DCHECK(context_->throttler_manager()); 344 DCHECK(context_->throttler_manager());
339 345
340 // Registers an entry for test url. The backoff time is calculated by: 346 // Registers an entry for test url. The backoff time is calculated by:
341 // new_backoff = 2.0 * old_backoff + 0 347 // new_backoff = 2.0 * old_backoff + 0
342 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. 348 // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
343 // Maximum retries allowed is set to 2. 349 // Maximum retries allowed is set to 2.
344 scoped_refptr<URLRequestThrottlerEntry> entry( 350 scoped_refptr<URLRequestThrottlerEntry> entry(
345 new URLRequestThrottlerEntry( 351 new URLRequestThrottlerEntry(
346 context_->throttler_manager(), 352 context_->throttler_manager(),
347 "", 200, 3, 2000, 2.0, 0.0, 4000)); 353 "", 200, 3, 2000, 2.0, 0.0, 4000));
348 context_->throttler_manager()->OverrideEntryForTests( 354 context_->throttler_manager()->OverrideEntryForTests(
349 throttle_for_url_, entry); 355 throttle_for_url_, entry);
350 356
351 context_created_.Signal(); 357 context_created_.Signal();
352 } 358 }
353 return context_.get(); 359 return context_.get();
354 } 360 }
361
355 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { 362 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
356 return io_message_loop_proxy_; 363 return io_message_loop_proxy_;
357 } 364 }
365
358 void WaitForContextCreation() { 366 void WaitForContextCreation() {
359 context_created_.Wait(); 367 context_created_.Wait();
360 } 368 }
361 369
362 protected: 370 protected:
363 virtual ~CancelTestURLRequestContextGetter() {} 371 virtual ~CancelTestURLRequestContextGetter() {}
364 372
365 private: 373 private:
366 scoped_ptr<TestURLRequestContext> context_; 374 scoped_ptr<TestURLRequestContext> context_;
367 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 375 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
368 base::WaitableEvent context_created_; 376 base::WaitableEvent context_created_;
369 GURL throttle_for_url_; 377 GURL throttle_for_url_;
370 }; 378 };
371 379
372 // Version of URLFetcherTest that tests retying the same request twice. 380 // Version of URLFetcherTest that tests retying the same request twice.
373 class URLFetcherMultipleAttemptTest : public URLFetcherTest { 381 class URLFetcherMultipleAttemptTest : public URLFetcherTest {
374 public: 382 public:
375 // URLFetcherDelegate 383 // URLFetcherTest:
376 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 384 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
377 private: 385 private:
378 std::string data_; 386 std::string data_;
379 }; 387 };
380 388
381 class URLFetcherFileTest : public URLFetcherTest { 389 class URLFetcherFileTest : public URLFetcherTest {
382 public: 390 public:
383 URLFetcherFileTest() : take_ownership_of_file_(false), 391 URLFetcherFileTest() : take_ownership_of_file_(false),
384 expected_file_error_(base::PLATFORM_FILE_OK) {} 392 expected_file_error_(base::PLATFORM_FILE_OK) {}
385 393
386 void CreateFetcherForFile(const GURL& url, const FilePath& file_path); 394 void CreateFetcherForFile(const GURL& url, const FilePath& file_path);
387 void CreateFetcherForTempFile(const GURL& url); 395 void CreateFetcherForTempFile(const GURL& url);
388 396
389 // URLFetcherDelegate 397 // URLFetcherTest:
390 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 398 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
391 399
392 protected: 400 protected:
393 FilePath expected_file_; 401 FilePath expected_file_;
394 FilePath file_path_; 402 FilePath file_path_;
395 403
396 // Set by the test. Used in OnURLFetchComplete() to decide if 404 // Set by the test. Used in OnURLFetchComplete() to decide if
397 // the URLFetcher should own the temp file, so that we can test 405 // the URLFetcher should own the temp file, so that we can test
398 // disowning prevents the file from being deleted. 406 // disowning prevents the file from being deleted.
399 bool take_ownership_of_file_; 407 bool take_ownership_of_file_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 445
438 CleanupAfterFetchComplete(); 446 CleanupAfterFetchComplete();
439 // Do not call the super class method URLFetcherTest::OnURLFetchComplete, 447 // Do not call the super class method URLFetcherTest::OnURLFetchComplete,
440 // since it expects a non-empty response. 448 // since it expects a non-empty response.
441 } 449 }
442 450
443 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { 451 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) {
444 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); 452 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
445 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 453 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
446 io_message_loop_proxy(), request_context())); 454 io_message_loop_proxy(), request_context()));
447 previous_progress_ = 0;
448 fetcher_->Start(); 455 fetcher_->Start();
449 } 456 }
450 457
451 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( 458 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress(
452 const URLFetcher* source, int64 current, int64 total) { 459 const URLFetcher* source, int64 current, int64 total) {
453 // Increasing between 0 and total. 460 // Progress has to be between 0 and total size.
454 EXPECT_LE(0, current); 461 EXPECT_LE(0, current);
455 EXPECT_GE(total, current); 462 EXPECT_GE(total, current);
456 EXPECT_LE(previous_progress_, current); 463
464 EXPECT_EQ(expected_total_size_, total);
465
466 // Progress has to be non-decreasing.
467 if (!first_call_)
468 EXPECT_LE(previous_progress_, current);
469
457 previous_progress_ = current; 470 previous_progress_ = current;
458 EXPECT_EQ(expected_total_, total); 471 first_call_ = false;
wtc 2012/11/26 23:19:06 If we remove first_call_ and use the original expe
ppi 2012/11/29 13:07:59 Removed "first_call_". I did rename "current" to "
459 } 472 }
460 473
461 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { 474 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) {
462 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); 475 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this);
463 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 476 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
464 io_message_loop_proxy(), request_context())); 477 io_message_loop_proxy(), request_context()));
465 cancelled_ = false; 478 cancelled_ = false;
466 fetcher_->Start(); 479 fetcher_->Start();
467 } 480 }
468 481
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 861
849 TEST_F(URLFetcherDownloadProgressTest, Basic) { 862 TEST_F(URLFetcherDownloadProgressTest, Basic) {
850 TestServer test_server(TestServer::TYPE_HTTP, 863 TestServer test_server(TestServer::TYPE_HTTP,
851 TestServer::kLocalhost, 864 TestServer::kLocalhost,
852 FilePath(kDocRoot)); 865 FilePath(kDocRoot));
853 ASSERT_TRUE(test_server.Start()); 866 ASSERT_TRUE(test_server.Start());
854 867
855 // Get a file large enough to require more than one read into 868 // Get a file large enough to require more than one read into
856 // URLFetcher::Core's IOBuffer. 869 // URLFetcher::Core's IOBuffer.
857 static const char kFileToFetch[] = "animate1.gif"; 870 static const char kFileToFetch[] = "animate1.gif";
858 file_util::GetFileSize(test_server.document_root().AppendASCII(kFileToFetch), 871 // Hardcoded file size - it cannot be easily fetched when a remote http server
859 &expected_total_); 872 // is used for testing.
873 static const int64 kFileSize = 19021;
874
875 expected_total_size_ = kFileSize;
876
860 CreateFetcher(test_server.GetURL( 877 CreateFetcher(test_server.GetURL(
861 std::string(kTestServerFilePrefix) + kFileToFetch)); 878 std::string(kTestServerFilePrefix) + kFileToFetch));
862 879
863 MessageLoop::current()->Run(); 880 MessageLoop::current()->Run();
864 } 881 }
865 882
866 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { 883 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) {
867 TestServer test_server(TestServer::TYPE_HTTP, 884 TestServer test_server(TestServer::TYPE_HTTP,
868 TestServer::kLocalhost, 885 TestServer::kLocalhost,
869 FilePath(kDocRoot)); 886 FilePath(kDocRoot));
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1262 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1246 1263
1247 MessageLoop::current()->RunUntilIdle(); 1264 MessageLoop::current()->RunUntilIdle();
1248 ASSERT_FALSE(file_util::PathExists(file_path_)) 1265 ASSERT_FALSE(file_util::PathExists(file_path_))
1249 << file_path_.value() << " not removed."; 1266 << file_path_.value() << " not removed.";
1250 } 1267 }
1251 1268
1252 } // namespace 1269 } // namespace
1253 1270
1254 } // namespace net 1271 } // namespace net
OLDNEW
« no previous file with comments | « build/android/gtest_filter/net_unittests_disabled ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698