| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // This is a header that signals the end of the data. | 17 // This is a header that signals the end of the data. |
| 18 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; | 18 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; |
| 19 const char kGzipDataWithName[] = |
| 20 "\x1f\x08b\x08\x08\0\0\0\0\0\0name\0\3\0\0\0\0\0\0\0\0"; |
| 19 | 21 |
| 20 void GZipServer(const HttpRequestInfo* request, | 22 void GZipServer(const HttpRequestInfo* request, |
| 21 std::string* response_status, | 23 std::string* response_status, |
| 22 std::string* response_headers, | 24 std::string* response_headers, |
| 23 std::string* response_data) { | 25 std::string* response_data) { |
| 24 response_data->assign(kGzipGata, sizeof(kGzipGata)); | 26 response_data->assign(kGzipData, sizeof(kGzipData)); |
| 27 } |
| 28 |
| 29 void BigGZipServer(const HttpRequestInfo* request, |
| 30 std::string* response_status, |
| 31 std::string* response_headers, |
| 32 std::string* response_data) { |
| 33 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); |
| 34 response_data->insert(10, 64 * 1024, 'a'); |
| 25 } | 35 } |
| 26 | 36 |
| 27 const MockTransaction kGZip_Transaction = { | 37 const MockTransaction kGZip_Transaction = { |
| 28 "http://www.google.com/gzyp", | 38 "http://www.google.com/gzyp", |
| 29 "GET", | 39 "GET", |
| 30 base::Time(), | 40 base::Time(), |
| 31 "", | 41 "", |
| 32 LOAD_NORMAL, | 42 LOAD_NORMAL, |
| 33 "HTTP/1.1 200 OK", | 43 "HTTP/1.1 200 OK", |
| 34 "Cache-Control: max-age=10000\n" | 44 "Cache-Control: max-age=10000\n" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 req.set_method("GET"); | 107 req.set_method("GET"); |
| 98 req.Start(); | 108 req.Start(); |
| 99 | 109 |
| 100 base::RunLoop().Run(); | 110 base::RunLoop().Run(); |
| 101 | 111 |
| 102 EXPECT_TRUE(network_layer.done_reading_called()); | 112 EXPECT_TRUE(network_layer.done_reading_called()); |
| 103 | 113 |
| 104 RemoveMockTransaction(&transaction); | 114 RemoveMockTransaction(&transaction); |
| 105 } | 115 } |
| 106 | 116 |
| 117 // Tests processing a large gzip header one byte at a time. |
| 118 TEST(URLRequestJob, SyncSlowTransaction) { |
| 119 MockNetworkLayer network_layer; |
| 120 TestURLRequestContext context; |
| 121 context.set_http_transaction_factory(&network_layer); |
| 122 |
| 123 TestDelegate d; |
| 124 TestURLRequest req( |
| 125 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); |
| 126 MockTransaction transaction(kGZip_Transaction); |
| 127 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; |
| 128 transaction.handler = &BigGZipServer; |
| 129 AddMockTransaction(&transaction); |
| 130 |
| 131 req.set_method("GET"); |
| 132 req.Start(); |
| 133 |
| 134 base::RunLoop().Run(); |
| 135 |
| 136 EXPECT_TRUE(network_layer.done_reading_called()); |
| 137 |
| 138 RemoveMockTransaction(&transaction); |
| 139 } |
| 140 |
| 107 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { | 141 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { |
| 108 MockNetworkLayer network_layer; | 142 MockNetworkLayer network_layer; |
| 109 TestURLRequestContext context; | 143 TestURLRequestContext context; |
| 110 context.set_http_transaction_factory(&network_layer); | 144 context.set_http_transaction_factory(&network_layer); |
| 111 | 145 |
| 112 TestDelegate d; | 146 TestDelegate d; |
| 113 TestURLRequest req( | 147 TestURLRequest req( |
| 114 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 148 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context); |
| 115 AddMockTransaction(&kRedirect_Transaction); | 149 AddMockTransaction(&kRedirect_Transaction); |
| 116 | 150 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 141 req.Start(); | 175 req.Start(); |
| 142 | 176 |
| 143 base::RunLoop().Run(); | 177 base::RunLoop().Run(); |
| 144 | 178 |
| 145 EXPECT_TRUE(network_layer.stop_caching_called()); | 179 EXPECT_TRUE(network_layer.stop_caching_called()); |
| 146 | 180 |
| 147 RemoveMockTransaction(&kGZip_Transaction); | 181 RemoveMockTransaction(&kGZip_Transaction); |
| 148 } | 182 } |
| 149 | 183 |
| 150 } // namespace net | 184 } // namespace net |
| OLD | NEW |