| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "net/base/request_priority.h" | 9 #include "net/base/request_priority.h" |
| 10 #include "net/http/http_transaction_test_util.h" | 10 #include "net/http/http_transaction_test_util.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 response_data->insert(10, 64 * 1024, 'a'); | 53 response_data->insert(10, 64 * 1024, 'a'); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BrotliHelloServer(const HttpRequestInfo* request, | 56 void BrotliHelloServer(const HttpRequestInfo* request, |
| 57 std::string* response_status, | 57 std::string* response_status, |
| 58 std::string* response_headers, | 58 std::string* response_headers, |
| 59 std::string* response_data) { | 59 std::string* response_data) { |
| 60 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1); | 60 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1); |
| 61 } | 61 } |
| 62 | 62 |
| 63 const MockTransaction kNoFilter_Transaction = { |
| 64 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
| 65 "HTTP/1.1 200 OK", |
| 66 "Cache-Control: max-age=10000\n" |
| 67 "Content-Length: 30\n", // Intentionally wrong. |
| 68 base::Time(), |
| 69 "hello", TEST_MODE_NORMAL, nullptr, nullptr, 0, 0, OK, |
| 70 }; |
| 71 |
| 63 const MockTransaction kGZip_Transaction = { | 72 const MockTransaction kGZip_Transaction = { |
| 64 "http://www.google.com/gzyp", | 73 "http://www.google.com/gzyp", |
| 65 "GET", | 74 "GET", |
| 66 base::Time(), | 75 base::Time(), |
| 67 "", | 76 "", |
| 68 LOAD_NORMAL, | 77 LOAD_NORMAL, |
| 69 "HTTP/1.1 200 OK", | 78 "HTTP/1.1 200 OK", |
| 70 "Cache-Control: max-age=10000\n" | 79 "Cache-Control: max-age=10000\n" |
| 71 "Content-Encoding: gzip\n" | 80 "Content-Encoding: gzip\n" |
| 72 "Content-Length: 30\n", // Intentionally wrong. | 81 "Content-Length: 30\n", // Intentionally wrong. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, | 148 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, |
| 140 "HTTP/1.1 200 OK", | 149 "HTTP/1.1 200 OK", |
| 141 "Cache-Control: max-age=10000\n" | 150 "Cache-Control: max-age=10000\n" |
| 142 "Content-Encoding: br\n", | 151 "Content-Encoding: br\n", |
| 143 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0, | 152 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0, |
| 144 OK, | 153 OK, |
| 145 }; | 154 }; |
| 146 | 155 |
| 147 } // namespace | 156 } // namespace |
| 148 | 157 |
| 158 TEST(URLRequestJob, TransactionNoFilter) { |
| 159 MockNetworkLayer network_layer; |
| 160 TestURLRequestContext context; |
| 161 context.set_http_transaction_factory(&network_layer); |
| 162 |
| 163 TestDelegate d; |
| 164 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 165 GURL(kNoFilter_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 166 AddMockTransaction(&kNoFilter_Transaction); |
| 167 |
| 168 req->set_method("GET"); |
| 169 req->Start(); |
| 170 |
| 171 base::MessageLoop::current()->Run(); |
| 172 |
| 173 EXPECT_TRUE(network_layer.done_reading_called()); |
| 174 |
| 175 RemoveMockTransaction(&kNoFilter_Transaction); |
| 176 } |
| 177 |
| 149 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 178 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
| 150 MockNetworkLayer network_layer; | 179 MockNetworkLayer network_layer; |
| 151 TestURLRequestContext context; | 180 TestURLRequestContext context; |
| 152 context.set_http_transaction_factory(&network_layer); | 181 context.set_http_transaction_factory(&network_layer); |
| 153 | 182 |
| 154 TestDelegate d; | 183 TestDelegate d; |
| 155 scoped_ptr<URLRequest> req( | 184 scoped_ptr<URLRequest> req( |
| 156 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); | 185 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 157 AddMockTransaction(&kGZip_Transaction); | 186 AddMockTransaction(&kGZip_Transaction); |
| 158 | 187 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 379 |
| 351 EXPECT_FALSE(d.request_failed()); | 380 EXPECT_FALSE(d.request_failed()); |
| 352 EXPECT_EQ(200, req->GetResponseCode()); | 381 EXPECT_EQ(200, req->GetResponseCode()); |
| 353 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); | 382 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); |
| 354 EXPECT_TRUE(network_layer.done_reading_called()); | 383 EXPECT_TRUE(network_layer.done_reading_called()); |
| 355 | 384 |
| 356 RemoveMockTransaction(&kBrotli_Slow_Transaction); | 385 RemoveMockTransaction(&kBrotli_Slow_Transaction); |
| 357 } | 386 } |
| 358 | 387 |
| 359 } // namespace net | 388 } // namespace net |
| OLD | NEW |