| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "net/base/request_priority.h" | 8 #include "net/base/request_priority.h" |
| 9 #include "net/http/http_transaction_unittest.h" | 9 #include "net/http/http_transaction_unittest.h" |
| 10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 void BigGZipServer(const HttpRequestInfo* request, | 29 void BigGZipServer(const HttpRequestInfo* request, |
| 30 std::string* response_status, | 30 std::string* response_status, |
| 31 std::string* response_headers, | 31 std::string* response_headers, |
| 32 std::string* response_data) { | 32 std::string* response_data) { |
| 33 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); | 33 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); |
| 34 response_data->insert(10, 64 * 1024, 'a'); | 34 response_data->insert(10, 64 * 1024, 'a'); |
| 35 } | 35 } |
| 36 | 36 |
| 37 const MockTransaction kGZip_Transaction = { | 37 const MockTransaction kGZip_Transaction = { |
| 38 "http://www.google.com/gzyp", | 38 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
| 39 "GET", | |
| 40 base::Time(), | |
| 41 "", | |
| 42 LOAD_NORMAL, | |
| 43 "HTTP/1.1 200 OK", | 39 "HTTP/1.1 200 OK", |
| 44 "Cache-Control: max-age=10000\n" | 40 "Cache-Control: max-age=10000\n" |
| 45 "Content-Encoding: gzip\n" | 41 "Content-Encoding: gzip\n" |
| 46 "Content-Length: 30\n", // Intentionally wrong. | 42 "Content-Length: 30\n", // Intentionally wrong. |
| 47 base::Time(), | 43 base::Time(), |
| 48 "", | 44 "", TEST_MODE_NORMAL, &GZipServer, 0, OK}; |
| 49 TEST_MODE_NORMAL, | |
| 50 &GZipServer, | |
| 51 0, | |
| 52 OK | |
| 53 }; | |
| 54 | 45 |
| 55 const MockTransaction kRedirect_Transaction = { | 46 const MockTransaction kRedirect_Transaction = { |
| 56 "http://www.google.com/redirect", | 47 "http://www.google.com/redirect", "GET", base::Time(), "", LOAD_NORMAL, |
| 57 "GET", | |
| 58 base::Time(), | |
| 59 "", | |
| 60 LOAD_NORMAL, | |
| 61 "HTTP/1.1 302 Found", | 48 "HTTP/1.1 302 Found", |
| 62 "Cache-Control: max-age=10000\n" | 49 "Cache-Control: max-age=10000\n" |
| 63 "Location: http://www.google.com/destination\n" | 50 "Location: http://www.google.com/destination\n" |
| 64 "Content-Length: 5\n", | 51 "Content-Length: 5\n", |
| 65 base::Time(), | 52 base::Time(), "hello", TEST_MODE_NORMAL, NULL, 0, OK}; |
| 66 "hello", | |
| 67 TEST_MODE_NORMAL, | |
| 68 NULL, | |
| 69 0, | |
| 70 OK | |
| 71 }; | |
| 72 | 53 |
| 73 } // namespace | 54 } // namespace |
| 74 | 55 |
| 75 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 56 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
| 76 MockNetworkLayer network_layer; | 57 MockNetworkLayer network_layer; |
| 77 TestURLRequestContext context; | 58 TestURLRequestContext context; |
| 78 context.set_http_transaction_factory(&network_layer); | 59 context.set_http_transaction_factory(&network_layer); |
| 79 | 60 |
| 80 TestDelegate d; | 61 TestDelegate d; |
| 81 TestURLRequest req( | 62 TestURLRequest req( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 141 |
| 161 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { | 142 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { |
| 162 MockNetworkLayer network_layer; | 143 MockNetworkLayer network_layer; |
| 163 TestNetworkDelegate network_delegate; | 144 TestNetworkDelegate network_delegate; |
| 164 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); | 145 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); |
| 165 TestURLRequestContext context; | 146 TestURLRequestContext context; |
| 166 context.set_http_transaction_factory(&network_layer); | 147 context.set_http_transaction_factory(&network_layer); |
| 167 context.set_network_delegate(&network_delegate); | 148 context.set_network_delegate(&network_delegate); |
| 168 | 149 |
| 169 TestDelegate d; | 150 TestDelegate d; |
| 170 TestURLRequest req(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, | 151 TestURLRequest req( |
| 171 &context); | 152 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); |
| 172 AddMockTransaction(&kGZip_Transaction); | 153 AddMockTransaction(&kGZip_Transaction); |
| 173 | 154 |
| 174 req.set_method("GET"); | 155 req.set_method("GET"); |
| 175 req.Start(); | 156 req.Start(); |
| 176 | 157 |
| 177 base::RunLoop().Run(); | 158 base::RunLoop().Run(); |
| 178 | 159 |
| 179 EXPECT_TRUE(network_layer.stop_caching_called()); | 160 EXPECT_TRUE(network_layer.stop_caching_called()); |
| 180 | 161 |
| 181 RemoveMockTransaction(&kGZip_Transaction); | 162 RemoveMockTransaction(&kGZip_Transaction); |
| 182 } | 163 } |
| 183 | 164 |
| 184 } // namespace net | 165 } // namespace net |
| OLD | NEW |