| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This class simulates a slow download. This is used in browser tests | 4 // This class simulates a slow download. This used in a UI test to test the |
| 5 // to test the download manager. Requests to |kUnknownSizeUrl| and | 5 // download manager. Requests to |kUnknownSizeUrl| and |kKnownSizeUrl| start |
| 6 // |kKnownSizeUrl| start downloads that pause after the first chunk of | 6 // downloads that pause after the first |
| 7 // data is delivered. A later request to |kFinishDownloadUrl| will finish | |
| 8 // these downloads. A later request to |kErrorFinishDownloadUrl| will | |
| 9 // cause these downloads to error with |net::ERR_FAILED|. | |
| 10 // TODO(rdsmith): Update to allow control of returned error. | |
| 11 | 7 |
| 12 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 8 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| 13 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 9 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| 14 #pragma once | 10 #pragma once |
| 15 | 11 |
| 16 #include <string> | 12 #include <string> |
| 17 #include <vector> | 13 #include <vector> |
| 18 | 14 |
| 19 #include "base/task.h" | 15 #include "base/task.h" |
| 20 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 virtual void GetResponseInfo(net::HttpResponseInfo* info); | 30 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
| 35 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 31 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
| 36 | 32 |
| 37 static net::URLRequestJob* Factory(net::URLRequest* request, | 33 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 38 const std::string& scheme); | 34 const std::string& scheme); |
| 39 | 35 |
| 40 // Test URLs. | 36 // Test URLs. |
| 41 static const char kUnknownSizeUrl[]; | 37 static const char kUnknownSizeUrl[]; |
| 42 static const char kKnownSizeUrl[]; | 38 static const char kKnownSizeUrl[]; |
| 43 static const char kFinishDownloadUrl[]; | 39 static const char kFinishDownloadUrl[]; |
| 44 static const char kErrorFinishDownloadUrl[]; | |
| 45 | 40 |
| 46 // Adds the testing URLs to the net::URLRequestFilter. | 41 // Adds the testing URLs to the net::URLRequestFilter. |
| 47 CONTENT_EXPORT static void AddUrlHandler(); | 42 CONTENT_EXPORT static void AddUrlHandler(); |
| 48 | 43 |
| 49 private: | 44 private: |
| 50 virtual ~URLRequestSlowDownloadJob(); | 45 virtual ~URLRequestSlowDownloadJob(); |
| 51 | 46 |
| 52 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 47 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
| 53 | 48 |
| 54 // Mark all pending requests to be finished. We keep track of pending | 49 // Mark all pending requests to be finished. We keep track of pending |
| 55 // requests in |pending_requests_|. | 50 // requests in |kPendingRequests|. |
| 56 static void FinishPendingRequests(bool error); | 51 static void FinishPendingRequests(); |
| 57 static std::vector<URLRequestSlowDownloadJob*> pending_requests_; | 52 static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; |
| 58 | 53 |
| 59 void StartAsync(); | 54 void StartAsync(); |
| 60 | 55 |
| 61 void set_should_finish_download() { should_finish_download_ = true; } | 56 void set_should_finish_download() { should_finish_download_ = true; } |
| 62 void set_should_error_download() { should_error_download_ = true; } | |
| 63 | 57 |
| 64 int first_download_size_remaining_; | 58 int first_download_size_remaining_; |
| 65 bool should_finish_download_; | 59 bool should_finish_download_; |
| 66 bool should_send_second_chunk_; | 60 bool should_send_second_chunk_; |
| 67 bool should_error_download_; | |
| 68 | 61 |
| 69 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; | 62 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; |
| 70 }; | 63 }; |
| 71 | 64 |
| 72 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 65 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| OLD | NEW |