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