Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: net/url_request/url_request_http_job_unittest.cc

Issue 1284993005: Notify NetworkDelegate when bytes have been received over the network. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed NetworkDelegate::OnRawBytesRead Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, 126 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
127 &delegate) 127 &delegate)
128 .Pass(); 128 .Pass();
129 129
130 request->Start(); 130 request->Start();
131 ASSERT_TRUE(request->is_pending()); 131 ASSERT_TRUE(request->is_pending());
132 base::RunLoop().Run(); 132 base::RunLoop().Run();
133 133
134 EXPECT_TRUE(request->status().is_success()); 134 EXPECT_TRUE(request->status().is_success());
135 EXPECT_EQ(12, request->received_response_content_length()); 135 EXPECT_EQ(12, request->received_response_content_length());
136 EXPECT_GE(network_delegate_.total_network_bytes_received(),
137 reads[0].data_len + reads[1].data_len);
mmenke 2015/08/19 15:48:41 We should be able to do EXPECT_EQ in these.
sclittle 2015/08/20 01:10:49 Done.
136 } 138 }
137 139
138 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthAbortedRequest) { 140 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthAbortedRequest) {
139 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 141 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
140 "Content-Length: 20\r\n\r\n"), 142 "Content-Length: 20\r\n\r\n"),
141 MockRead("Test Content"), 143 MockRead("Test Content"),
142 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; 144 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)};
143 145
144 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); 146 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0);
145 socket_factory_.AddSocketDataProvider(&socket_data); 147 socket_factory_.AddSocketDataProvider(&socket_data);
146 148
147 TestDelegate delegate; 149 TestDelegate delegate;
148 scoped_ptr<URLRequest> request = 150 scoped_ptr<URLRequest> request =
149 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, 151 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
150 &delegate) 152 &delegate)
151 .Pass(); 153 .Pass();
152 154
153 request->Start(); 155 request->Start();
154 ASSERT_TRUE(request->is_pending()); 156 ASSERT_TRUE(request->is_pending());
155 base::RunLoop().Run(); 157 base::RunLoop().Run();
156 158
157 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); 159 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status());
158 EXPECT_EQ(12, request->received_response_content_length()); 160 EXPECT_EQ(12, request->received_response_content_length());
161 EXPECT_GE(network_delegate_.total_network_bytes_received(),
162 reads[0].data_len + reads[1].data_len);
159 } 163 }
160 164
161 TEST_F(URLRequestHttpJobWithMockSocketsTest, 165 TEST_F(URLRequestHttpJobWithMockSocketsTest,
162 TestContentLengthCancelledRequest) { 166 TestContentLengthCancelledRequest) {
163 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 167 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
164 "Content-Length: 20\r\n\r\n"), 168 "Content-Length: 20\r\n\r\n"),
165 MockRead("Test Content"), 169 MockRead("Test Content"),
166 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; 170 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)};
167 171
168 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); 172 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0);
169 socket_factory_.AddSocketDataProvider(&socket_data); 173 socket_factory_.AddSocketDataProvider(&socket_data);
170 174
171 TestDelegate delegate; 175 TestDelegate delegate;
172 scoped_ptr<URLRequest> request = 176 scoped_ptr<URLRequest> request =
173 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, 177 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
174 &delegate) 178 &delegate)
175 .Pass(); 179 .Pass();
176 180
181 delegate.set_cancel_in_received_data(true);
182 request->Start();
183 base::RunLoop().RunUntilIdle();
184
185 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status());
186 EXPECT_EQ(12, request->received_response_content_length());
187 EXPECT_GE(network_delegate_.total_network_bytes_received(),
188 reads[0].data_len + reads[1].data_len);
189 }
190
191 TEST_F(URLRequestHttpJobWithMockSocketsTest,
192 TestNetworkBytesRedirectedRequest) {
193 MockRead redirect_read(
194 "HTTP/1.1 302 Found\r\n"
195 "Location: http://www.example.com\r\n\r\n");
196 StaticSocketDataProvider redirect_socket_data(&redirect_read, 1, nullptr, 0);
197 socket_factory_.AddSocketDataProvider(&redirect_socket_data);
198
199 MockRead response_reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
200 "Content-Length: 12\r\n\r\n"),
201 MockRead("Test Content")};
202 StaticSocketDataProvider response_socket_data(
203 response_reads, arraysize(response_reads), nullptr, 0);
204 socket_factory_.AddSocketDataProvider(&response_socket_data);
205
206 TestDelegate delegate;
207 scoped_ptr<URLRequest> request =
208 context_->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY,
209 &delegate)
210 .Pass();
211
177 request->Start(); 212 request->Start();
213 ASSERT_TRUE(request->is_pending());
178 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
179 request->Cancel(); 215
180 base::RunLoop().Run(); 216 EXPECT_TRUE(request->status().is_success());
217 EXPECT_EQ(12, request->received_response_content_length());
218 EXPECT_GE(network_delegate_.total_network_bytes_received(),
219 redirect_read.data_len + response_reads[0].data_len +
220 response_reads[1].data_len);
221 }
222
223 TEST_F(URLRequestHttpJobWithMockSocketsTest,
224 TestNetworkBytesCancelledAfterHeaders) {
mmenke 2015/08/19 15:48:41 Maybe an HTTP/0.9 one, too?
mmenke 2015/08/19 15:48:41 Maybe just a simple sanity test - start a request,
sclittle 2015/08/20 01:10:49 Done.
sclittle 2015/08/20 01:10:49 Done.
225 MockRead read("HTTP/1.1 200 OK\r\n\r\n");
226 StaticSocketDataProvider socket_data(&read, 1, nullptr, 0);
227 socket_factory_.AddSocketDataProvider(&socket_data);
228
229 TestDelegate delegate;
230 scoped_ptr<URLRequest> request =
231 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
232 &delegate)
233 .Pass();
234
235 delegate.set_cancel_in_response_started(true);
236 request->Start();
237 base::RunLoop().RunUntilIdle();
181 238
182 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 239 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status());
183 EXPECT_EQ(12, request->received_response_content_length()); 240 EXPECT_GE(network_delegate_.total_network_bytes_received(), read.data_len);
184 } 241 }
185 242
186 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) { 243 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeader) {
187 MockWrite writes[] = {MockWrite( 244 MockWrite writes[] = {MockWrite(
188 "GET / HTTP/1.1\r\n" 245 "GET / HTTP/1.1\r\n"
189 "Host: www.example.com\r\n" 246 "Host: www.example.com\r\n"
190 "Connection: keep-alive\r\n" 247 "Connection: keep-alive\r\n"
191 "User-Agent:\r\n" 248 "User-Agent:\r\n"
192 "Accept-Encoding: gzip, deflate\r\n" 249 "Accept-Encoding: gzip, deflate\r\n"
193 "Accept-Language: en-us,fr\r\n\r\n")}; 250 "Accept-Language: en-us,fr\r\n\r\n")};
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 629 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
573 job->Start(); 630 job->Start();
574 base::RunLoop().RunUntilIdle(); 631 base::RunLoop().RunUntilIdle();
575 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); 632 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
576 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 633 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
577 } 634 }
578 635
579 } // namespace 636 } // namespace
580 637
581 } // namespace net 638 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698