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 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // 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 |
18 // 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 |
19 // it as the protocol handler for the "test" scheme. | 19 // it as the protocol handler for the "test" scheme. |
20 // | 20 // |
21 // It will respond to three URLs, which you can retrieve using the test_url* | 21 // 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 | 22 // 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, | 23 // by test_data*. Any other URLs that begin with "test:" will return an error, |
24 // which might also be useful, you can use test_url_error() to retreive a | 24 // which might also be useful, you can use test_url_error() to retreive a |
25 // standard one. | 25 // standard one. |
26 // | 26 // |
27 // You can override the known URLs or the response data by overriding Start(). | 27 // You can override the known URLs or the response data by overriding Start(). |
28 // | 28 // |
29 // Optionally, you can also construct test jobs to return a headers and data | 29 // Optionally, you can also construct test jobs to return a headers and data |
30 // provided to the contstructor in response to any request url. | 30 // provided to the contstructor in response to any request url. |
31 // | 31 // |
(...skipping 18 matching lines...) Expand all Loading... |
50 | 50 |
51 // Constructs a job to return the given response regardless of the request | 51 // Constructs a job to return the given response regardless of the request |
52 // url. The headers should include the HTTP status line and be formatted as | 52 // url. The headers should include the HTTP status line and be formatted as |
53 // expected by HttpResponseHeaders. | 53 // expected by HttpResponseHeaders. |
54 URLRequestTestJob(URLRequest* request, | 54 URLRequestTestJob(URLRequest* request, |
55 net::NetworkDelegate* network_delegate, | 55 net::NetworkDelegate* network_delegate, |
56 const std::string& response_headers, | 56 const std::string& response_headers, |
57 const std::string& response_data, | 57 const std::string& response_data, |
58 bool auto_advance); | 58 bool auto_advance); |
59 | 59 |
60 // The three canned URLs this handler will respond to without having been | 60 // The canned URLs this handler will respond to without having been |
61 // explicitly initialized with response headers and data. | 61 // explicitly initialized with response headers and data. |
62 // FIXME(brettw): we should probably also have a redirect one | 62 // FIXME(brettw): we should probably also have a redirect one |
63 static GURL test_url_1(); | 63 static GURL test_url_1(); |
64 static GURL test_url_2(); | 64 static GURL test_url_2(); |
65 static GURL test_url_3(); | 65 static GURL test_url_3(); |
| 66 static GURL test_url_4(); |
66 static GURL test_url_error(); | 67 static GURL test_url_error(); |
| 68 static GURL test_url_redirect_to_url_2(); |
67 | 69 |
68 // The data that corresponds to each of the URLs above | 70 // The data that corresponds to each of the URLs above |
69 static std::string test_data_1(); | 71 static std::string test_data_1(); |
70 static std::string test_data_2(); | 72 static std::string test_data_2(); |
71 static std::string test_data_3(); | 73 static std::string test_data_3(); |
| 74 static std::string test_data_4(); |
72 | 75 |
73 // The headers that correspond to each of the URLs above | 76 // The headers that correspond to each of the URLs above |
74 static std::string test_headers(); | 77 static std::string test_headers(); |
75 | 78 |
76 // The headers for a redirect response | 79 // The headers for a redirect response |
77 static std::string test_redirect_headers(); | 80 static std::string test_redirect_headers(); |
78 | 81 |
| 82 // The headers for a redirect response to the second test url. |
| 83 static std::string test_redirect_to_url_2_headers(); |
| 84 |
79 // The headers for a server error response | 85 // The headers for a server error response |
80 static std::string test_error_headers(); | 86 static std::string test_error_headers(); |
81 | 87 |
82 // Processes one pending message from the stack, returning true if any | 88 // Processes one pending message from the stack, returning true if any |
83 // message was processed, or false if there are no more pending request | 89 // message was processed, or false if there are no more pending request |
84 // notifications to send. This is not applicable when using auto_advance. | 90 // notifications to send. This is not applicable when using auto_advance. |
85 static bool ProcessOnePendingMessage(); | 91 static bool ProcessOnePendingMessage(); |
86 | 92 |
87 // With auto advance enabled, the job will advance thru the stages without | 93 // With auto advance enabled, the job will advance thru the stages without |
88 // the caller having to call ProcessOnePendingMessage. Auto advance depends | 94 // the caller having to call ProcessOnePendingMessage. Auto advance depends |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 int async_buf_size_; | 166 int async_buf_size_; |
161 | 167 |
162 LoadTimingInfo load_timing_info_; | 168 LoadTimingInfo load_timing_info_; |
163 | 169 |
164 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; | 170 base::WeakPtrFactory<URLRequestTestJob> weak_factory_; |
165 }; | 171 }; |
166 | 172 |
167 } // namespace net | 173 } // namespace net |
168 | 174 |
169 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ | 175 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_JOB_H_ |
OLD | NEW |