| OLD | NEW |
| 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 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "net/base/load_timing_info.h" | 11 #include "net/base/load_timing_info.h" |
| 12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_job.h" | 13 #include "net/url_request/url_request_job.h" |
| 14 #include "net/url_request/url_request_job_factory.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 // This job type is designed to help with simple unit tests. To use, you | 18 // This job type is designed to help with simple unit tests. To use, you |
| 18 // probably want to inherit from it to set up the state you want. Then install | 19 // probably want to inherit from it to set up the state you want. Then install |
| 19 // it as the protocol handler for the "test" scheme. | 20 // it as the protocol handler for the "test" scheme. |
| 20 // | 21 // |
| 21 // It will respond to several URLs, which you can retrieve using the test_url* | 22 // It will respond to several URLs, which you can retrieve using the test_url* |
| 22 // getters, which will in turn respond with the corresponding responses returned | 23 // getters, which will in turn respond with the corresponding responses returned |
| 23 // by test_data*. Any other URLs that begin with "test:" will return an error, | 24 // by test_data*. Any other URLs that begin with "test:" will return an error, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Should not be altered after the job has started. | 97 // Should not be altered after the job has started. |
| 97 bool auto_advance() { return auto_advance_; } | 98 bool auto_advance() { return auto_advance_; } |
| 98 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } | 99 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } |
| 99 | 100 |
| 100 void set_load_timing_info(const LoadTimingInfo& load_timing_info) { | 101 void set_load_timing_info(const LoadTimingInfo& load_timing_info) { |
| 101 load_timing_info_ = load_timing_info; | 102 load_timing_info_ = load_timing_info; |
| 102 } | 103 } |
| 103 | 104 |
| 104 RequestPriority priority() const { return priority_; } | 105 RequestPriority priority() const { return priority_; } |
| 105 | 106 |
| 106 // Factory method for protocol factory registration if callers don't subclass | 107 // Create a protocol handler for callers that don't subclass. |
| 107 static URLRequest::ProtocolFactory Factory; | 108 static URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler(); |
| 108 | 109 |
| 109 // Job functions | 110 // Job functions |
| 110 virtual void SetPriority(RequestPriority priority) OVERRIDE; | 111 virtual void SetPriority(RequestPriority priority) OVERRIDE; |
| 111 virtual void Start() OVERRIDE; | 112 virtual void Start() OVERRIDE; |
| 112 virtual bool ReadRawData(IOBuffer* buf, | 113 virtual bool ReadRawData(IOBuffer* buf, |
| 113 int buf_size, | 114 int buf_size, |
| 114 int *bytes_read) OVERRIDE; | 115 int *bytes_read) OVERRIDE; |
| 115 virtual void Kill() OVERRIDE; | 116 virtual void Kill() OVERRIDE; |
| 116 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 117 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 117 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; | 118 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 int async_buf_size_; | 167 int async_buf_size_; |
| 167 | 168 |
| 168 LoadTimingInfo load_timing_info_; | 169 LoadTimingInfo load_timing_info_; |
| 169 | 170 |
| 170 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; | 171 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 } // namespace net | 174 } // namespace net |
| 174 | 175 |
| 175 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 176 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
| OLD | NEW |