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

Side by Side Diff: content/child/web_url_loader_impl_unittest.cc

Issue 2540023003: Dispatch encoded_data_length separately in content/child (Closed)
Patch Set: fix Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 did_receive_response_ = true; 171 did_receive_response_ = true;
172 response_ = response; 172 response_ = response;
173 if (delete_on_receive_response_) 173 if (delete_on_receive_response_)
174 loader_.reset(); 174 loader_.reset();
175 } 175 }
176 176
177 void didDownloadData(int dataLength, int encodedDataLength) override { 177 void didDownloadData(int dataLength, int encodedDataLength) override {
178 EXPECT_TRUE(loader_); 178 EXPECT_TRUE(loader_);
179 } 179 }
180 180
181 void didReceiveData(const char* data, 181 void didReceiveData(const char* data, int dataLength) override {
182 int dataLength,
183 int encodedDataLength) override {
184 EXPECT_TRUE(loader_); 182 EXPECT_TRUE(loader_);
185 // The response should have started, but must not have finished, or failed. 183 // The response should have started, but must not have finished, or failed.
186 EXPECT_TRUE(did_receive_response_); 184 EXPECT_TRUE(did_receive_response_);
187 EXPECT_FALSE(did_finish_); 185 EXPECT_FALSE(did_finish_);
188 EXPECT_EQ(net::OK, error_.reason); 186 EXPECT_EQ(net::OK, error_.reason);
189 EXPECT_EQ("", error_.domain.utf8()); 187 EXPECT_EQ("", error_.domain.utf8());
190 188
191 received_data_.append(data, dataLength); 189 received_data_.append(data, dataLength);
192 190
193 if (delete_on_receive_data_) 191 if (delete_on_receive_data_)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 EXPECT_FALSE(client()->did_receive_response()); 308 EXPECT_FALSE(client()->did_receive_response());
311 peer()->OnReceivedResponse(content::ResourceResponseInfo()); 309 peer()->OnReceivedResponse(content::ResourceResponseInfo());
312 EXPECT_TRUE(client()->did_receive_response()); 310 EXPECT_TRUE(client()->did_receive_response());
313 } 311 }
314 312
315 // Assumes it is called only once for a request. 313 // Assumes it is called only once for a request.
316 void DoReceiveData() { 314 void DoReceiveData() {
317 EXPECT_EQ("", client()->received_data()); 315 EXPECT_EQ("", client()->received_data());
318 auto size = strlen(kTestData); 316 auto size = strlen(kTestData);
319 peer()->OnReceivedData( 317 peer()->OnReceivedData(
320 base::MakeUnique<FixedReceivedData>(kTestData, size, size)); 318 base::MakeUnique<FixedReceivedData>(kTestData, size));
321 EXPECT_EQ(kTestData, client()->received_data()); 319 EXPECT_EQ(kTestData, client()->received_data());
322 } 320 }
323 321
324 void DoCompleteRequest() { 322 void DoCompleteRequest() {
325 EXPECT_FALSE(client()->did_finish()); 323 EXPECT_FALSE(client()->did_finish());
326 peer()->OnCompletedRequest(net::OK, false, false, base::TimeTicks(), 324 peer()->OnCompletedRequest(net::OK, false, false, base::TimeTicks(),
327 strlen(kTestData), strlen(kTestData)); 325 strlen(kTestData), strlen(kTestData));
328 EXPECT_TRUE(client()->did_finish()); 326 EXPECT_TRUE(client()->did_finish());
329 // There should be no error. 327 // There should be no error.
330 EXPECT_EQ(net::OK, client()->error().reason); 328 EXPECT_EQ(net::OK, client()->error().reason);
(...skipping 13 matching lines...) Expand all
344 EXPECT_FALSE(client()->did_receive_response()); 342 EXPECT_FALSE(client()->did_receive_response());
345 content::ResourceResponseInfo response_info; 343 content::ResourceResponseInfo response_info;
346 response_info.mime_type = kFtpDirMimeType; 344 response_info.mime_type = kFtpDirMimeType;
347 peer()->OnReceivedResponse(response_info); 345 peer()->OnReceivedResponse(response_info);
348 EXPECT_TRUE(client()->did_receive_response()); 346 EXPECT_TRUE(client()->did_receive_response());
349 } 347 }
350 348
351 void DoReceiveDataFtp() { 349 void DoReceiveDataFtp() {
352 auto size = strlen(kFtpDirListing); 350 auto size = strlen(kFtpDirListing);
353 peer()->OnReceivedData( 351 peer()->OnReceivedData(
354 base::MakeUnique<FixedReceivedData>(kFtpDirListing, size, size)); 352 base::MakeUnique<FixedReceivedData>(kFtpDirListing, size));
355 // The FTP delegate should modify the data the client sees. 353 // The FTP delegate should modify the data the client sees.
356 EXPECT_NE(kFtpDirListing, client()->received_data()); 354 EXPECT_NE(kFtpDirListing, client()->received_data());
357 } 355 }
358 356
359 TestWebURLLoaderClient* client() { return client_.get(); } 357 TestWebURLLoaderClient* client() { return client_.get(); }
360 TestResourceDispatcher* dispatcher() { return &dispatcher_; } 358 TestResourceDispatcher* dispatcher() { return &dispatcher_; }
361 RequestPeer* peer() { return dispatcher()->peer(); } 359 RequestPeer* peer() { return dispatcher()->peer(); }
362 base::MessageLoop* message_loop() { return &message_loop_; } 360 base::MessageLoop* message_loop() { return &message_loop_; }
363 361
364 private: 362 private:
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 int64_t encoded_body_length = 0; 685 int64_t encoded_body_length = 0;
688 client()->loader()->loadSynchronously( 686 client()->loader()->loadSynchronously(
689 request, response, error, data, encoded_data_length, encoded_body_length); 687 request, response, error, data, encoded_data_length, encoded_body_length);
690 688
691 EXPECT_EQ(kEncodedBodyLength, encoded_body_length); 689 EXPECT_EQ(kEncodedBodyLength, encoded_body_length);
692 EXPECT_EQ(kEncodedDataLength, encoded_data_length); 690 EXPECT_EQ(kEncodedDataLength, encoded_data_length);
693 } 691 }
694 692
695 } // namespace 693 } // namespace
696 } // namespace content 694 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698