| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 GURL URLRequestTestJob::test_url_3() { | 50 GURL URLRequestTestJob::test_url_3() { |
| 51 return GURL("test:url3"); | 51 return GURL("test:url3"); |
| 52 } | 52 } |
| 53 GURL URLRequestTestJob::test_url_4() { | 53 GURL URLRequestTestJob::test_url_4() { |
| 54 return GURL("test:url4"); | 54 return GURL("test:url4"); |
| 55 } | 55 } |
| 56 GURL URLRequestTestJob::test_url_error() { | 56 GURL URLRequestTestJob::test_url_error() { |
| 57 return GURL("test:error"); | 57 return GURL("test:error"); |
| 58 } | 58 } |
| 59 GURL URLRequestTestJob::test_url_redirect_to_url_1() { |
| 60 return GURL("test:redirect_to_1"); |
| 61 } |
| 59 GURL URLRequestTestJob::test_url_redirect_to_url_2() { | 62 GURL URLRequestTestJob::test_url_redirect_to_url_2() { |
| 60 return GURL("test:redirect_to_2"); | 63 return GURL("test:redirect_to_2"); |
| 61 } | 64 } |
| 62 | 65 |
| 63 // static getters for known URL responses | 66 // static getters for known URL responses |
| 64 std::string URLRequestTestJob::test_data_1() { | 67 std::string URLRequestTestJob::test_data_1() { |
| 65 return std::string("<html><title>Test One</title></html>"); | 68 return std::string("<html><title>Test One</title></html>"); |
| 66 } | 69 } |
| 67 std::string URLRequestTestJob::test_data_2() { | 70 std::string URLRequestTestJob::test_data_2() { |
| 68 return std::string("<html><title>Test Two Two</title></html>"); | 71 return std::string("<html><title>Test Two Two</title></html>"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 // static getter for redirect response headers | 89 // static getter for redirect response headers |
| 87 std::string URLRequestTestJob::test_redirect_headers() { | 90 std::string URLRequestTestJob::test_redirect_headers() { |
| 88 static const char kHeaders[] = | 91 static const char kHeaders[] = |
| 89 "HTTP/1.1 302 MOVED\n" | 92 "HTTP/1.1 302 MOVED\n" |
| 90 "Location: somewhere\n" | 93 "Location: somewhere\n" |
| 91 "\n"; | 94 "\n"; |
| 92 return std::string(kHeaders, arraysize(kHeaders)); | 95 return std::string(kHeaders, arraysize(kHeaders)); |
| 93 } | 96 } |
| 94 | 97 |
| 95 // static getter for redirect response headers | 98 // static getter for redirect response headers |
| 99 std::string URLRequestTestJob::test_redirect_to_url_1_headers() { |
| 100 std::string headers = "HTTP/1.1 302 MOVED"; |
| 101 headers.push_back('\n'); |
| 102 headers += "Location: "; |
| 103 headers += test_url_1().spec(); |
| 104 headers.push_back('\n'); |
| 105 headers.push_back('\n'); |
| 106 return headers; |
| 107 } |
| 108 |
| 109 // static getter for redirect response headers |
| 96 std::string URLRequestTestJob::test_redirect_to_url_2_headers() { | 110 std::string URLRequestTestJob::test_redirect_to_url_2_headers() { |
| 97 std::string headers = "HTTP/1.1 302 MOVED"; | 111 std::string headers = "HTTP/1.1 302 MOVED"; |
| 98 headers.push_back('\n'); | 112 headers.push_back('\n'); |
| 99 headers += "Location: "; | 113 headers += "Location: "; |
| 100 headers += test_url_2().spec(); | 114 headers += test_url_2().spec(); |
| 101 headers.push_back('\n'); | 115 headers.push_back('\n'); |
| 102 headers.push_back('\n'); | 116 headers.push_back('\n'); |
| 103 return headers; | 117 return headers; |
| 104 } | 118 } |
| 105 | 119 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 SetResponseHeaders(test_headers()); | 206 SetResponseHeaders(test_headers()); |
| 193 if (request_->url().spec() == test_url_1().spec()) { | 207 if (request_->url().spec() == test_url_1().spec()) { |
| 194 response_data_ = test_data_1(); | 208 response_data_ = test_data_1(); |
| 195 stage_ = DATA_AVAILABLE; // Simulate a synchronous response for this one. | 209 stage_ = DATA_AVAILABLE; // Simulate a synchronous response for this one. |
| 196 } else if (request_->url().spec() == test_url_2().spec()) { | 210 } else if (request_->url().spec() == test_url_2().spec()) { |
| 197 response_data_ = test_data_2(); | 211 response_data_ = test_data_2(); |
| 198 } else if (request_->url().spec() == test_url_3().spec()) { | 212 } else if (request_->url().spec() == test_url_3().spec()) { |
| 199 response_data_ = test_data_3(); | 213 response_data_ = test_data_3(); |
| 200 } else if (request_->url().spec() == test_url_4().spec()) { | 214 } else if (request_->url().spec() == test_url_4().spec()) { |
| 201 response_data_ = test_data_4(); | 215 response_data_ = test_data_4(); |
| 216 } else if (request_->url().spec() == test_url_redirect_to_url_1().spec()) { |
| 217 SetResponseHeaders(test_redirect_to_url_1_headers()); |
| 202 } else if (request_->url().spec() == test_url_redirect_to_url_2().spec()) { | 218 } else if (request_->url().spec() == test_url_redirect_to_url_2().spec()) { |
| 203 SetResponseHeaders(test_redirect_to_url_2_headers()); | 219 SetResponseHeaders(test_redirect_to_url_2_headers()); |
| 204 } else { | 220 } else { |
| 205 AdvanceJob(); | 221 AdvanceJob(); |
| 206 | 222 |
| 207 // unexpected url, return error | 223 // unexpected url, return error |
| 208 // FIXME(brettw) we may want to use WININET errors or have some more types | 224 // FIXME(brettw) we may want to use WININET errors or have some more types |
| 209 // of errors | 225 // of errors |
| 210 NotifyStartError( | 226 NotifyStartError( |
| 211 URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL)); | 227 URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 369 |
| 354 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 370 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 355 g_pending_jobs.Get().pop_front(); | 371 g_pending_jobs.Get().pop_front(); |
| 356 | 372 |
| 357 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 373 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 358 next_job->ProcessNextOperation(); | 374 next_job->ProcessNextOperation(); |
| 359 return true; | 375 return true; |
| 360 } | 376 } |
| 361 | 377 |
| 362 } // namespace net | 378 } // namespace net |
| OLD | NEW |