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

Side by Side Diff: net/url_request/url_request_test_job.h

Issue 2552463002: Add more ResourceLoaderTests (Closed)
Patch Set: Fix Created 4 years 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
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 #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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 URLRequestTestJob(URLRequest* request, 56 URLRequestTestJob(URLRequest* request,
57 NetworkDelegate* network_delegate, 57 NetworkDelegate* network_delegate,
58 const std::string& response_headers, 58 const std::string& response_headers,
59 const std::string& response_data, 59 const std::string& response_data,
60 bool auto_advance); 60 bool auto_advance);
61 61
62 ~URLRequestTestJob() override; 62 ~URLRequestTestJob() override;
63 63
64 // The canned URLs this handler will respond to without having been 64 // The canned URLs this handler will respond to without having been
65 // explicitly initialized with response headers and data. 65 // explicitly initialized with response headers and data.
66 // FIXME(brettw): we should probably also have a redirect one 66
67 // URL that, by default, automatically advances through each state. Reads
68 // complete synchronously.
67 static GURL test_url_1(); 69 static GURL test_url_1();
70
71 // URLs that, by default, must be manually advanced through each state.
68 static GURL test_url_2(); 72 static GURL test_url_2();
69 static GURL test_url_3(); 73 static GURL test_url_3();
70 static GURL test_url_4(); 74 static GURL test_url_4();
75
76 // URL that, by default, automatically advances through each state. Reads
77 // complete asynchronously. Has same response body as test_url_1(), which is
78 // (test_data_1()).
79 static GURL test_url_auto_advance_async_reads_1();
80
81 // URL that fails with ERR_INVALID_URL.
71 static GURL test_url_error(); 82 static GURL test_url_error();
83
84 // Redirects to test_url_1().
72 static GURL test_url_redirect_to_url_1(); 85 static GURL test_url_redirect_to_url_1();
86
87 // Redirects to test_url_2().
73 static GURL test_url_redirect_to_url_2(); 88 static GURL test_url_redirect_to_url_2();
74 89
75 // The data that corresponds to each of the URLs above 90 // The data that corresponds to each of the URLs above
76 static std::string test_data_1(); 91 static std::string test_data_1();
77 static std::string test_data_2(); 92 static std::string test_data_2();
78 static std::string test_data_3(); 93 static std::string test_data_3();
79 static std::string test_data_4(); 94 static std::string test_data_4();
80 95
81 // The headers that correspond to each of the URLs above 96 // The headers that correspond to each of the URLs above
82 static std::string test_headers(); 97 static std::string test_headers();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 159
145 // Call to move the job along to the next operation. 160 // Call to move the job along to the next operation.
146 void AdvanceJob(); 161 void AdvanceJob();
147 162
148 // Called via InvokeLater to cause callbacks to occur after Start() returns. 163 // Called via InvokeLater to cause callbacks to occur after Start() returns.
149 virtual void StartAsync(); 164 virtual void StartAsync();
150 165
151 // Assigns |response_headers_| and |response_headers_length_|. 166 // Assigns |response_headers_| and |response_headers_length_|.
152 void SetResponseHeaders(const std::string& response_headers); 167 void SetResponseHeaders(const std::string& response_headers);
153 168
169 // Copies as much of the response body as will into |buf|, and returns number
170 // of bytes written.
171 int CopyDataForRead(IOBuffer* buf, int buf_size);
172
154 bool auto_advance_; 173 bool auto_advance_;
155 174
156 Stage stage_; 175 Stage stage_;
157 176
158 RequestPriority priority_; 177 RequestPriority priority_;
159 178
160 // The data to send, will be set in Start() if not provided in the explicit 179 // The data to send, will be set in Start() if not provided in the explicit
161 // ctor. 180 // ctor.
162 std::string response_data_; 181 std::string response_data_;
163 182
164 // current offset within response_data_ 183 // current offset within response_data_
165 int offset_; 184 int offset_;
166 185
167 // Holds the buffer for an asynchronous ReadRawData call 186 // Holds the buffer for an asynchronous ReadRawData call
168 IOBuffer* async_buf_; 187 IOBuffer* async_buf_;
169 int async_buf_size_; 188 int async_buf_size_;
170 189
171 LoadTimingInfo load_timing_info_; 190 LoadTimingInfo load_timing_info_;
172 191
173 private: 192 private:
174 // The headers the job should return, will be set in Start() if not provided 193 // The headers the job should return, will be set in Start() if not provided
175 // in the explicit ctor. 194 // in the explicit ctor.
176 scoped_refptr<HttpResponseHeaders> response_headers_; 195 scoped_refptr<HttpResponseHeaders> response_headers_;
177 196
178 // Original size in bytes of the response headers before decoding. 197 // Original size in bytes of the response headers before decoding.
179 int response_headers_length_; 198 int response_headers_length_;
180 199
200 bool async_reads_;
201
181 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; 202 base::WeakPtrFactory<URLRequestTestJob> weak_factory_;
182 }; 203 };
183 204
184 } // namespace net 205 } // namespace net
185 206
186 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ 207 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_
OLDNEW
« no previous file with comments | « content/browser/loader/test_resource_handler.cc ('k') | net/url_request/url_request_test_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698