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

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

Issue 2105713002: Render process changes for ResourceTiming sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resource_timing_sizes_browser_process
Patch Set: Initialise encoded_body_length for sync XHR to data: URLs Created 4 years, 5 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) 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 "content/child/resource_dispatcher.h" 5 #include "content/child/resource_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 context_->total_downloaded_data_length += len; 83 context_->total_downloaded_data_length += len;
84 context_->total_encoded_data_length += encoded_data_length; 84 context_->total_encoded_data_length += encoded_data_length;
85 } 85 }
86 86
87 void OnReceivedData(std::unique_ptr<ReceivedData> data) override { 87 void OnReceivedData(std::unique_ptr<ReceivedData> data) override {
88 if (context_->cancelled) 88 if (context_->cancelled)
89 return; 89 return;
90 EXPECT_TRUE(context_->received_response); 90 EXPECT_TRUE(context_->received_response);
91 EXPECT_FALSE(context_->complete); 91 EXPECT_FALSE(context_->complete);
92 context_->data.append(data->payload(), data->length()); 92 context_->data.append(data->payload(), data->length());
93 context_->total_encoded_data_length += data->encoded_length(); 93 context_->total_encoded_data_length += data->encoded_data_length();
94 } 94 }
95 95
96 void OnCompletedRequest(int error_code, 96 void OnCompletedRequest(int error_code,
97 bool was_ignored_by_handler, 97 bool was_ignored_by_handler,
98 bool stale_copy_in_cache, 98 bool stale_copy_in_cache,
99 const std::string& security_info, 99 const std::string& security_info,
100 const base::TimeTicks& completion_time, 100 const base::TimeTicks& completion_time,
101 int64_t total_transfer_size) override { 101 int64_t total_transfer_size) override {
102 if (context_->cancelled) 102 if (context_->cancelled)
103 return; 103 return;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 void NotifyInlinedDataChunkReceived(int request_id, 284 void NotifyInlinedDataChunkReceived(int request_id,
285 const std::vector<char>& data) { 285 const std::vector<char>& data) {
286 auto size = data.size(); 286 auto size = data.size();
287 EXPECT_TRUE(dispatcher_->OnMessageReceived( 287 EXPECT_TRUE(dispatcher_->OnMessageReceived(
288 ResourceMsg_InlinedDataChunkReceived(request_id, data, size, size))); 288 ResourceMsg_InlinedDataChunkReceived(request_id, data, size, size)));
289 } 289 }
290 290
291 void NotifyDataDownloaded(int request_id, 291 void NotifyDataDownloaded(int request_id,
292 int decoded_length, 292 int decoded_length,
293 int encoded_length) { 293 int encoded_data_length) {
294 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataDownloaded( 294 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataDownloaded(
295 request_id, decoded_length, encoded_length))); 295 request_id, decoded_length, encoded_data_length)));
296 } 296 }
297 297
298 void NotifyRequestComplete(int request_id, size_t total_size) { 298 void NotifyRequestComplete(int request_id, size_t total_size) {
299 ResourceRequestCompletionStatus request_complete_data; 299 ResourceRequestCompletionStatus request_complete_data;
300 request_complete_data.error_code = net::OK; 300 request_complete_data.error_code = net::OK;
301 request_complete_data.was_ignored_by_handler = false; 301 request_complete_data.was_ignored_by_handler = false;
302 request_complete_data.exists_in_cache = false; 302 request_complete_data.exists_in_cache = false;
303 request_complete_data.encoded_data_length = total_size; 303 request_complete_data.encoded_data_length = total_size;
304 EXPECT_TRUE(dispatcher_->OnMessageReceived( 304 EXPECT_TRUE(dispatcher_->OnMessageReceived(
305 ResourceMsg_RequestComplete(request_id, request_complete_data))); 305 ResourceMsg_RequestComplete(request_id, request_complete_data)));
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 544 }
545 545
546 void OnCompletedRequest(int error_code, 546 void OnCompletedRequest(int error_code,
547 bool was_ignored_by_handler, 547 bool was_ignored_by_handler,
548 bool stale_copy_in_cache, 548 bool stale_copy_in_cache,
549 const std::string& security_info, 549 const std::string& security_info,
550 const base::TimeTicks& completion_time, 550 const base::TimeTicks& completion_time,
551 int64_t total_transfer_size) override { 551 int64_t total_transfer_size) override {
552 original_peer_->OnReceivedResponse(response_info_); 552 original_peer_->OnReceivedResponse(response_info_);
553 if (!data_.empty()) { 553 if (!data_.empty()) {
554 original_peer_->OnReceivedData(base::WrapUnique( 554 original_peer_->OnReceivedData(base::WrapUnique(new FixedReceivedData(
555 new FixedReceivedData(data_.data(), data_.size(), -1))); 555 data_.data(), data_.size(), -1, data_.size())));
556 } 556 }
557 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, 557 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler,
558 stale_copy_in_cache, security_info, 558 stale_copy_in_cache, security_info,
559 completion_time, total_transfer_size); 559 completion_time, total_transfer_size);
560 } 560 }
561 561
562 private: 562 private:
563 std::unique_ptr<RequestPeer> original_peer_; 563 std::unique_ptr<RequestPeer> original_peer_;
564 ResourceResponseInfo response_info_; 564 ResourceResponseInfo response_info_;
565 std::string data_; 565 std::string data_;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 const int kEncodedIncrement = 50; 817 const int kEncodedIncrement = 50;
818 818
819 int id = ConsumeRequestResource(); 819 int id = ConsumeRequestResource();
820 EXPECT_EQ(0u, queued_messages()); 820 EXPECT_EQ(0u, queued_messages());
821 821
822 NotifyReceivedResponse(id); 822 NotifyReceivedResponse(id);
823 EXPECT_EQ(0u, queued_messages()); 823 EXPECT_EQ(0u, queued_messages());
824 EXPECT_TRUE(peer_context.received_response); 824 EXPECT_TRUE(peer_context.received_response);
825 825
826 int expected_total_downloaded_length = 0; 826 int expected_total_downloaded_length = 0;
827 int expected_total_encoded_length = 0; 827 int expected_total_encoded_data_length = 0;
828 for (int i = 0; i < 10; ++i) { 828 for (int i = 0; i < 10; ++i) {
829 NotifyDataDownloaded(id, kDownloadedIncrement, kEncodedIncrement); 829 NotifyDataDownloaded(id, kDownloadedIncrement, kEncodedIncrement);
830 ConsumeDataDownloaded_ACK(id); 830 ConsumeDataDownloaded_ACK(id);
831 expected_total_downloaded_length += kDownloadedIncrement; 831 expected_total_downloaded_length += kDownloadedIncrement;
832 expected_total_encoded_length += kEncodedIncrement; 832 expected_total_encoded_data_length += kEncodedIncrement;
833 EXPECT_EQ(expected_total_downloaded_length, 833 EXPECT_EQ(expected_total_downloaded_length,
834 peer_context.total_downloaded_data_length); 834 peer_context.total_downloaded_data_length);
835 EXPECT_EQ(expected_total_encoded_length, 835 EXPECT_EQ(expected_total_encoded_data_length,
836 peer_context.total_encoded_data_length); 836 peer_context.total_encoded_data_length);
837 } 837 }
838 838
839 NotifyRequestComplete(id, strlen(kTestPageContents)); 839 NotifyRequestComplete(id, strlen(kTestPageContents));
840 EXPECT_EQ("", peer_context.data); 840 EXPECT_EQ("", peer_context.data);
841 EXPECT_TRUE(peer_context.complete); 841 EXPECT_TRUE(peer_context.complete);
842 EXPECT_EQ(0u, queued_messages()); 842 EXPECT_EQ(0u, queued_messages());
843 843
844 dispatcher()->RemovePendingRequest(request_id); 844 dispatcher()->RemovePendingRequest(request_id);
845 ConsumeReleaseDownloadedFile(id); 845 ConsumeReleaseDownloadedFile(id);
846 EXPECT_EQ(0u, queued_messages()); 846 EXPECT_EQ(0u, queued_messages());
847 EXPECT_EQ(expected_total_downloaded_length, 847 EXPECT_EQ(expected_total_downloaded_length,
848 peer_context.total_downloaded_data_length); 848 peer_context.total_downloaded_data_length);
849 EXPECT_EQ(expected_total_encoded_length, 849 EXPECT_EQ(expected_total_encoded_data_length,
850 peer_context.total_encoded_data_length); 850 peer_context.total_encoded_data_length);
851 } 851 }
852 852
853 // Make sure that when a download to file is cancelled, the file is destroyed. 853 // Make sure that when a download to file is cancelled, the file is destroyed.
854 TEST_F(ResourceDispatcherTest, CancelDownloadToFile) { 854 TEST_F(ResourceDispatcherTest, CancelDownloadToFile) {
855 std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true)); 855 std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true));
856 TestRequestPeer::Context peer_context; 856 TestRequestPeer::Context peer_context;
857 int request_id = StartAsync(*request_info.get(), NULL, &peer_context); 857 int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
858 858
859 int id = ConsumeRequestResource(); 859 int id = ConsumeRequestResource();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 ResourceResponseHead response_head; 935 ResourceResponseHead response_head;
936 936
937 PerformTest(response_head); 937 PerformTest(response_head);
938 938
939 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 939 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
940 EXPECT_EQ(base::TimeTicks(), 940 EXPECT_EQ(base::TimeTicks(),
941 response_info().load_timing.connect_timing.dns_start); 941 response_info().load_timing.connect_timing.dns_start);
942 } 942 }
943 943
944 } // namespace content 944 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/child/shared_memory_data_consumer_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698