| 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_job.h" | 5 #include "net/url_request/url_request_job.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 void BrotliHelloServer(const HttpRequestInfo* request, | 57 void BrotliHelloServer(const HttpRequestInfo* request, |
| 58 std::string* response_status, | 58 std::string* response_status, |
| 59 std::string* response_headers, | 59 std::string* response_headers, |
| 60 std::string* response_data) { | 60 std::string* response_data) { |
| 61 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1); | 61 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1); |
| 62 } | 62 } |
| 63 | 63 |
| 64 const MockTransaction kGZip_Transaction = { | 64 const MockTransaction kGZip_Transaction = { |
| 65 "http://www.google.com/gzyp", | 65 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
| 66 "GET", | |
| 67 base::Time(), | |
| 68 "", | |
| 69 LOAD_NORMAL, | |
| 70 "HTTP/1.1 200 OK", | 66 "HTTP/1.1 200 OK", |
| 71 "Cache-Control: max-age=10000\n" | 67 "Cache-Control: max-age=10000\n" |
| 72 "Content-Encoding: gzip\n" | 68 "Content-Encoding: gzip\n" |
| 73 "Content-Length: 30\n", // Intentionally wrong. | 69 "Content-Length: 30\n", // Intentionally wrong. |
| 74 base::Time(), | 70 base::Time(), |
| 75 "", | 71 "", TEST_MODE_NORMAL, &GZipServer, nullptr, nullptr, 0, 0, OK, |
| 76 TEST_MODE_NORMAL, | |
| 77 &GZipServer, | |
| 78 nullptr, | |
| 79 0, | |
| 80 0, | |
| 81 OK, | |
| 82 }; | 72 }; |
| 83 | 73 |
| 84 const MockTransaction kGzip_Slow_Transaction = { | 74 const MockTransaction kGzip_Slow_Transaction = { |
| 85 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 75 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
| 86 "HTTP/1.1 200 OK", | 76 "HTTP/1.1 200 OK", |
| 87 "Cache-Control: max-age=10000\n" | 77 "Cache-Control: max-age=10000\n" |
| 88 "Content-Encoding: gzip\n", | 78 "Content-Encoding: gzip\n", |
| 89 base::Time(), "", TEST_MODE_SLOW_READ, &GZipHelloServer, nullptr, 0, 0, OK, | 79 base::Time(), "", TEST_MODE_SLOW_READ, &GZipHelloServer, nullptr, nullptr, |
| 80 0, 0, OK, |
| 90 }; | 81 }; |
| 91 | 82 |
| 92 const MockTransaction kRedirect_Transaction = { | 83 const MockTransaction kRedirect_Transaction = { |
| 93 "http://www.google.com/redirect", | 84 "http://www.google.com/redirect", "GET", base::Time(), "", LOAD_NORMAL, |
| 94 "GET", | |
| 95 base::Time(), | |
| 96 "", | |
| 97 LOAD_NORMAL, | |
| 98 "HTTP/1.1 302 Found", | 85 "HTTP/1.1 302 Found", |
| 99 "Cache-Control: max-age=10000\n" | 86 "Cache-Control: max-age=10000\n" |
| 100 "Location: http://www.google.com/destination\n" | 87 "Location: http://www.google.com/destination\n" |
| 101 "Content-Length: 5\n", | 88 "Content-Length: 5\n", |
| 102 base::Time(), | 89 base::Time(), "hello", TEST_MODE_NORMAL, nullptr, nullptr, nullptr, 0, 0, |
| 103 "hello", | |
| 104 TEST_MODE_NORMAL, | |
| 105 nullptr, | |
| 106 nullptr, | |
| 107 0, | |
| 108 0, | |
| 109 OK, | 90 OK, |
| 110 }; | 91 }; |
| 111 | 92 |
| 112 const MockTransaction kEmptyBodyGzip_Transaction = { | 93 const MockTransaction kEmptyBodyGzip_Transaction = { |
| 113 "http://www.google.com/empty_body", | 94 "http://www.google.com/empty_body", |
| 114 "GET", | 95 "GET", |
| 115 base::Time(), | 96 base::Time(), |
| 116 "", | 97 "", |
| 117 LOAD_NORMAL, | 98 LOAD_NORMAL, |
| 118 "HTTP/1.1 200 OK", | 99 "HTTP/1.1 200 OK", |
| 119 "Content-Encoding: gzip\n", | 100 "Content-Encoding: gzip\n", |
| 120 base::Time(), | 101 base::Time(), |
| 121 "", | 102 "", |
| 122 TEST_MODE_NORMAL, | 103 TEST_MODE_NORMAL, |
| 123 nullptr, | 104 nullptr, |
| 124 nullptr, | 105 nullptr, |
| 106 nullptr, |
| 125 0, | 107 0, |
| 126 0, | 108 0, |
| 127 OK, | 109 OK, |
| 128 }; | 110 }; |
| 129 | 111 |
| 130 const MockTransaction kInvalidContentGZip_Transaction = { | 112 const MockTransaction kInvalidContentGZip_Transaction = { |
| 131 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, | 113 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
| 132 "HTTP/1.1 200 OK", | 114 "HTTP/1.1 200 OK", |
| 133 "Content-Encoding: gzip\n" | 115 "Content-Encoding: gzip\n" |
| 134 "Content-Length: 21\n", | 116 "Content-Length: 21\n", |
| 135 base::Time(), "not a valid gzip body", TEST_MODE_NORMAL, nullptr, nullptr, | 117 base::Time(), "not a valid gzip body", TEST_MODE_NORMAL, nullptr, nullptr, |
| 136 0, 0, OK, | 118 nullptr, 0, 0, OK, |
| 137 }; | 119 }; |
| 138 | 120 |
| 139 const MockTransaction kBrotli_Slow_Transaction = { | 121 const MockTransaction kBrotli_Slow_Transaction = { |
| 140 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, | 122 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, |
| 141 "HTTP/1.1 200 OK", | 123 "HTTP/1.1 200 OK", |
| 142 "Cache-Control: max-age=10000\n" | 124 "Cache-Control: max-age=10000\n" |
| 143 "Content-Encoding: br\n", | 125 "Content-Encoding: br\n", |
| 144 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0, | 126 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, nullptr, |
| 145 OK, | 127 0, 0, OK, |
| 146 }; | 128 }; |
| 147 | 129 |
| 148 } // namespace | 130 } // namespace |
| 149 | 131 |
| 150 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 132 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
| 151 MockNetworkLayer network_layer; | 133 MockNetworkLayer network_layer; |
| 152 TestURLRequestContext context; | 134 TestURLRequestContext context; |
| 153 context.set_http_transaction_factory(&network_layer); | 135 context.set_http_transaction_factory(&network_layer); |
| 154 | 136 |
| 155 TestDelegate d; | 137 TestDelegate d; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 333 |
| 352 EXPECT_FALSE(d.request_failed()); | 334 EXPECT_FALSE(d.request_failed()); |
| 353 EXPECT_EQ(200, req->GetResponseCode()); | 335 EXPECT_EQ(200, req->GetResponseCode()); |
| 354 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); | 336 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); |
| 355 EXPECT_TRUE(network_layer.done_reading_called()); | 337 EXPECT_TRUE(network_layer.done_reading_called()); |
| 356 | 338 |
| 357 RemoveMockTransaction(&kBrotli_Slow_Transaction); | 339 RemoveMockTransaction(&kBrotli_Slow_Transaction); |
| 358 } | 340 } |
| 359 | 341 |
| 360 } // namespace net | 342 } // namespace net |
| OLD | NEW |