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/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
12 #include "net/url_request/url_request_job.h" | 13 #include "net/url_request/url_request_job.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 // This job type is designed to help with simple unit tests. To use, you | 17 // This job type is designed to help with simple unit tests. To use, you |
17 // probably want to inherit from it to set up the state you want. Then install | 18 // probably want to inherit from it to set up the state you want. Then install |
18 // it as the protocol handler for the "test" scheme. | 19 // it as the protocol handler for the "test" scheme. |
19 // | 20 // |
20 // It will respond to three URLs, which you can retrieve using the test_url* | 21 // It will respond to three URLs, which you can retrieve using the test_url* |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // notifications to send. This is not applicable when using auto_advance. | 84 // notifications to send. This is not applicable when using auto_advance. |
84 static bool ProcessOnePendingMessage(); | 85 static bool ProcessOnePendingMessage(); |
85 | 86 |
86 // With auto advance enabled, the job will advance thru the stages without | 87 // With auto advance enabled, the job will advance thru the stages without |
87 // the caller having to call ProcessOnePendingMessage. Auto advance depends | 88 // the caller having to call ProcessOnePendingMessage. Auto advance depends |
88 // on having a message loop running. The default is to not auto advance. | 89 // on having a message loop running. The default is to not auto advance. |
89 // Should not be altered after the job has started. | 90 // Should not be altered after the job has started. |
90 bool auto_advance() { return auto_advance_; } | 91 bool auto_advance() { return auto_advance_; } |
91 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } | 92 void set_auto_advance(bool auto_advance) { auto_advance_ = auto_advance; } |
92 | 93 |
| 94 void set_load_timing_info(const LoadTimingInfo& load_timing_info) { |
| 95 load_timing_info_ = load_timing_info; |
| 96 } |
| 97 |
93 RequestPriority priority() const { return priority_; } | 98 RequestPriority priority() const { return priority_; } |
94 | 99 |
95 // Factory method for protocol factory registration if callers don't subclass | 100 // Factory method for protocol factory registration if callers don't subclass |
96 static URLRequest::ProtocolFactory Factory; | 101 static URLRequest::ProtocolFactory Factory; |
97 | 102 |
98 // Job functions | 103 // Job functions |
99 virtual void SetPriority(RequestPriority priority) OVERRIDE; | 104 virtual void SetPriority(RequestPriority priority) OVERRIDE; |
100 virtual void Start() OVERRIDE; | 105 virtual void Start() OVERRIDE; |
101 virtual bool ReadRawData(IOBuffer* buf, | 106 virtual bool ReadRawData(IOBuffer* buf, |
102 int buf_size, | 107 int buf_size, |
103 int *bytes_read) OVERRIDE; | 108 int *bytes_read) OVERRIDE; |
104 virtual void Kill() OVERRIDE; | 109 virtual void Kill() OVERRIDE; |
105 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 110 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
106 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; | 111 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; |
| 112 virtual void GetLoadTimingInfo( |
| 113 LoadTimingInfo* load_timing_info) const OVERRIDE; |
107 virtual int GetResponseCode() const OVERRIDE; | 114 virtual int GetResponseCode() const OVERRIDE; |
108 virtual bool IsRedirectResponse(GURL* location, | 115 virtual bool IsRedirectResponse(GURL* location, |
109 int* http_status_code) OVERRIDE; | 116 int* http_status_code) OVERRIDE; |
110 | 117 |
111 protected: | 118 protected: |
112 // Override to specify whether the next read done from this job will | 119 // Override to specify whether the next read done from this job will |
113 // return IO pending. This controls whether or not the WAITING state will | 120 // return IO pending. This controls whether or not the WAITING state will |
114 // transition back to WAITING or to DATA_AVAILABLE after an asynchronous | 121 // transition back to WAITING or to DATA_AVAILABLE after an asynchronous |
115 // read is processed. | 122 // read is processed. |
116 virtual bool NextReadAsync(); | 123 virtual bool NextReadAsync(); |
(...skipping 28 matching lines...) Expand all Loading... |
145 // ctor. | 152 // ctor. |
146 std::string response_data_; | 153 std::string response_data_; |
147 | 154 |
148 // current offset within response_data_ | 155 // current offset within response_data_ |
149 int offset_; | 156 int offset_; |
150 | 157 |
151 // Holds the buffer for an asynchronous ReadRawData call | 158 // Holds the buffer for an asynchronous ReadRawData call |
152 IOBuffer* async_buf_; | 159 IOBuffer* async_buf_; |
153 int async_buf_size_; | 160 int async_buf_size_; |
154 | 161 |
| 162 LoadTimingInfo load_timing_info_; |
| 163 |
155 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; | 164 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; |
156 }; | 165 }; |
157 | 166 |
158 } // namespace net | 167 } // namespace net |
159 | 168 |
160 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 169 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
OLD | NEW |