| 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 #include "net/url_request/url_request_test_job.h" | 5 #include "net/url_request/url_request_test_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // static getters for known URLs | 29 // static getters for known URLs |
| 30 GURL URLRequestTestJob::test_url_1() { | 30 GURL URLRequestTestJob::test_url_1() { |
| 31 return GURL("test:url1"); | 31 return GURL("test:url1"); |
| 32 } | 32 } |
| 33 GURL URLRequestTestJob::test_url_2() { | 33 GURL URLRequestTestJob::test_url_2() { |
| 34 return GURL("test:url2"); | 34 return GURL("test:url2"); |
| 35 } | 35 } |
| 36 GURL URLRequestTestJob::test_url_3() { | 36 GURL URLRequestTestJob::test_url_3() { |
| 37 return GURL("test:url3"); | 37 return GURL("test:url3"); |
| 38 } | 38 } |
| 39 GURL URLRequestTestJob::test_url_4() { |
| 40 return GURL("test:url4"); |
| 41 } |
| 39 GURL URLRequestTestJob::test_url_error() { | 42 GURL URLRequestTestJob::test_url_error() { |
| 40 return GURL("test:error"); | 43 return GURL("test:error"); |
| 41 } | 44 } |
| 45 GURL URLRequestTestJob::test_url_redirect_to_url_2() { |
| 46 return GURL("test:redirect_to_2"); |
| 47 } |
| 42 | 48 |
| 43 // static getters for known URL responses | 49 // static getters for known URL responses |
| 44 std::string URLRequestTestJob::test_data_1() { | 50 std::string URLRequestTestJob::test_data_1() { |
| 45 return std::string("<html><title>Test One</title></html>"); | 51 return std::string("<html><title>Test One</title></html>"); |
| 46 } | 52 } |
| 47 std::string URLRequestTestJob::test_data_2() { | 53 std::string URLRequestTestJob::test_data_2() { |
| 48 return std::string("<html><title>Test Two Two</title></html>"); | 54 return std::string("<html><title>Test Two Two</title></html>"); |
| 49 } | 55 } |
| 50 std::string URLRequestTestJob::test_data_3() { | 56 std::string URLRequestTestJob::test_data_3() { |
| 51 return std::string("<html><title>Test Three Three Three</title></html>"); | 57 return std::string("<html><title>Test Three Three Three</title></html>"); |
| 52 } | 58 } |
| 59 std::string URLRequestTestJob::test_data_4() { |
| 60 return std::string("<html><title>Test Four Four Four Four</title></html>"); |
| 61 } |
| 53 | 62 |
| 54 // static getter for simple response headers | 63 // static getter for simple response headers |
| 55 std::string URLRequestTestJob::test_headers() { | 64 std::string URLRequestTestJob::test_headers() { |
| 56 static const char kHeaders[] = | 65 static const char kHeaders[] = |
| 57 "HTTP/1.1 200 OK\0" | 66 "HTTP/1.1 200 OK\0" |
| 58 "Content-type: text/html\0" | 67 "Content-type: text/html\0" |
| 59 "\0"; | 68 "\0"; |
| 60 return std::string(kHeaders, arraysize(kHeaders)); | 69 return std::string(kHeaders, arraysize(kHeaders)); |
| 61 } | 70 } |
| 62 | 71 |
| 63 // static getter for redirect response headers | 72 // static getter for redirect response headers |
| 64 std::string URLRequestTestJob::test_redirect_headers() { | 73 std::string URLRequestTestJob::test_redirect_headers() { |
| 65 static const char kHeaders[] = | 74 static const char kHeaders[] = |
| 66 "HTTP/1.1 302 MOVED\0" | 75 "HTTP/1.1 302 MOVED\0" |
| 67 "Location: somewhere\0" | 76 "Location: somewhere\0" |
| 68 "\0"; | 77 "\0"; |
| 69 return std::string(kHeaders, arraysize(kHeaders)); | 78 return std::string(kHeaders, arraysize(kHeaders)); |
| 70 } | 79 } |
| 71 | 80 |
| 81 // static getter for redirect response headers |
| 82 std::string URLRequestTestJob::test_redirect_to_url_2_headers() { |
| 83 std::string headers = "HTTP/1.1 302 MOVED"; |
| 84 headers.push_back('\0'); |
| 85 headers += "Location: "; |
| 86 headers += test_url_2().spec(); |
| 87 headers.push_back('\0'); |
| 88 headers.push_back('\0'); |
| 89 return headers; |
| 90 } |
| 91 |
| 72 // static getter for error response headers | 92 // static getter for error response headers |
| 73 std::string URLRequestTestJob::test_error_headers() { | 93 std::string URLRequestTestJob::test_error_headers() { |
| 74 static const char kHeaders[] = | 94 static const char kHeaders[] = |
| 75 "HTTP/1.1 500 BOO HOO\0" | 95 "HTTP/1.1 500 BOO HOO\0" |
| 76 "\0"; | 96 "\0"; |
| 77 return std::string(kHeaders, arraysize(kHeaders)); | 97 return std::string(kHeaders, arraysize(kHeaders)); |
| 78 } | 98 } |
| 79 | 99 |
| 80 // static | 100 // static |
| 81 URLRequestJob* URLRequestTestJob::Factory(URLRequest* request, | 101 URLRequestJob* URLRequestTestJob::Factory(URLRequest* request, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void URLRequestTestJob::StartAsync() { | 175 void URLRequestTestJob::StartAsync() { |
| 156 if (!response_headers_.get()) { | 176 if (!response_headers_.get()) { |
| 157 response_headers_ = new HttpResponseHeaders(test_headers()); | 177 response_headers_ = new HttpResponseHeaders(test_headers()); |
| 158 if (request_->url().spec() == test_url_1().spec()) { | 178 if (request_->url().spec() == test_url_1().spec()) { |
| 159 response_data_ = test_data_1(); | 179 response_data_ = test_data_1(); |
| 160 stage_ = DATA_AVAILABLE; // Simulate a synchronous response for this one. | 180 stage_ = DATA_AVAILABLE; // Simulate a synchronous response for this one. |
| 161 } else if (request_->url().spec() == test_url_2().spec()) { | 181 } else if (request_->url().spec() == test_url_2().spec()) { |
| 162 response_data_ = test_data_2(); | 182 response_data_ = test_data_2(); |
| 163 } else if (request_->url().spec() == test_url_3().spec()) { | 183 } else if (request_->url().spec() == test_url_3().spec()) { |
| 164 response_data_ = test_data_3(); | 184 response_data_ = test_data_3(); |
| 185 } else if (request_->url().spec() == test_url_4().spec()) { |
| 186 response_data_ = test_data_4(); |
| 187 } else if (request_->url().spec() == test_url_redirect_to_url_2().spec()) { |
| 188 response_headers_ = |
| 189 new HttpResponseHeaders(test_redirect_to_url_2_headers()); |
| 165 } else { | 190 } else { |
| 166 AdvanceJob(); | 191 AdvanceJob(); |
| 167 | 192 |
| 168 // unexpected url, return error | 193 // unexpected url, return error |
| 169 // FIXME(brettw) we may want to use WININET errors or have some more types | 194 // FIXME(brettw) we may want to use WININET errors or have some more types |
| 170 // of errors | 195 // of errors |
| 171 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 196 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 172 ERR_INVALID_URL)); | 197 ERR_INVALID_URL)); |
| 173 // FIXME(brettw): this should emulate a network error, and not just fail | 198 // FIXME(brettw): this should emulate a network error, and not just fail |
| 174 // initiating a connection | 199 // initiating a connection |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 336 |
| 312 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 337 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 313 g_pending_jobs.Get().pop_front(); | 338 g_pending_jobs.Get().pop_front(); |
| 314 | 339 |
| 315 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 340 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 316 next_job->ProcessNextOperation(); | 341 next_job->ProcessNextOperation(); |
| 317 return true; | 342 return true; |
| 318 } | 343 } |
| 319 | 344 |
| 320 } // namespace net | 345 } // namespace net |
| OLD | NEW |