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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 req.set_method("GET"); | 85 req.set_method("GET"); |
76 req.Start(); | 86 req.Start(); |
77 | 87 |
78 base::MessageLoop::current()->Run(); | 88 base::MessageLoop::current()->Run(); |
79 | 89 |
80 EXPECT_TRUE(network_layer.done_reading_called()); | 90 EXPECT_TRUE(network_layer.done_reading_called()); |
81 | 91 |
82 RemoveMockTransaction(&kGZip_Transaction); | 92 RemoveMockTransaction(&kGZip_Transaction); |
83 } | 93 } |
84 | 94 |
85 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 95 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
wtc
2014/05/02 22:59:13
The new SyncSlowTransaction test seems most simila
rvargas (doing something else)
2014/05/03 00:19:33
Done.
| |
86 MockNetworkLayer network_layer; | 96 MockNetworkLayer network_layer; |
87 TestURLRequestContext context; | 97 TestURLRequestContext context; |
88 context.set_http_transaction_factory(&network_layer); | 98 context.set_http_transaction_factory(&network_layer); |
89 | 99 |
90 TestDelegate d; | 100 TestDelegate d; |
91 TestURLRequest req( | 101 TestURLRequest req( |
92 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 102 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); |
93 MockTransaction transaction(kGZip_Transaction); | 103 MockTransaction transaction(kGZip_Transaction); |
94 transaction.test_mode = TEST_MODE_SYNC_ALL; | 104 transaction.test_mode = TEST_MODE_SYNC_ALL; |
95 AddMockTransaction(&transaction); | 105 AddMockTransaction(&transaction); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 req.set_method("GET"); | 150 req.set_method("GET"); |
141 req.Start(); | 151 req.Start(); |
142 | 152 |
143 base::RunLoop().Run(); | 153 base::RunLoop().Run(); |
144 | 154 |
145 EXPECT_TRUE(network_layer.stop_caching_called()); | 155 EXPECT_TRUE(network_layer.stop_caching_called()); |
146 | 156 |
147 RemoveMockTransaction(&kGZip_Transaction); | 157 RemoveMockTransaction(&kGZip_Transaction); |
148 } | 158 } |
149 | 159 |
160 // Tests processing a large gzip header one byte at a time. | |
161 TEST(URLRequestJob, SyncSlowTransaction) { | |
162 MockNetworkLayer network_layer; | |
163 TestURLRequestContext context; | |
164 context.set_http_transaction_factory(&network_layer); | |
165 | |
166 TestDelegate d; | |
167 TestURLRequest req( | |
168 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | |
169 MockTransaction transaction(kGZip_Transaction); | |
170 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; | |
171 transaction.handler = &BigGZipServer; | |
172 AddMockTransaction(&transaction); | |
173 | |
174 req.set_method("GET"); | |
175 req.Start(); | |
176 | |
177 base::RunLoop().Run(); | |
178 | |
179 EXPECT_TRUE(network_layer.done_reading_called()); | |
180 | |
181 RemoveMockTransaction(&transaction); | |
182 } | |
183 | |
150 } // namespace net | 184 } // namespace net |
OLD | NEW |