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

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: Fixes from ksakamoto review 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 13 matching lines...) Expand all
24 #include "content/child/request_extra_data.h" 24 #include "content/child/request_extra_data.h"
25 #include "content/child/request_info.h" 25 #include "content/child/request_info.h"
26 #include "content/common/appcache_interfaces.h" 26 #include "content/common/appcache_interfaces.h"
27 #include "content/common/resource_messages.h" 27 #include "content/common/resource_messages.h"
28 #include "content/common/resource_request.h" 28 #include "content/common/resource_request.h"
29 #include "content/common/resource_request_completion_status.h" 29 #include "content/common/resource_request_completion_status.h"
30 #include "content/common/service_worker/service_worker_types.h" 30 #include "content/common/service_worker/service_worker_types.h"
31 #include "content/public/child/fixed_received_data.h" 31 #include "content/public/child/fixed_received_data.h"
32 #include "content/public/child/request_peer.h" 32 #include "content/public/child/request_peer.h"
33 #include "content/public/child/resource_dispatcher_delegate.h" 33 #include "content/public/child/resource_dispatcher_delegate.h"
34 #include "content/public/common/content_features.cc" 34 #include "content/public/common/content_features.h"
35 #include "content/public/common/resource_response.h" 35 #include "content/public/common/resource_response.h"
36 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
37 #include "net/http/http_response_headers.h" 37 #include "net/http/http_response_headers.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 39
40 namespace content { 40 namespace content {
41 41
42 static const char kTestPageUrl[] = "http://www.google.com/"; 42 static const char kTestPageUrl[] = "http://www.google.com/";
43 static const char kTestPageHeaders[] = 43 static const char kTestPageHeaders[] =
44 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; 44 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n";
(...skipping 38 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 543 }
544 544
545 void OnCompletedRequest(int error_code, 545 void OnCompletedRequest(int error_code,
546 bool was_ignored_by_handler, 546 bool was_ignored_by_handler,
547 bool stale_copy_in_cache, 547 bool stale_copy_in_cache,
548 const std::string& security_info, 548 const std::string& security_info,
549 const base::TimeTicks& completion_time, 549 const base::TimeTicks& completion_time,
550 int64_t total_transfer_size) override { 550 int64_t total_transfer_size) override {
551 original_peer_->OnReceivedResponse(response_info_); 551 original_peer_->OnReceivedResponse(response_info_);
552 if (!data_.empty()) { 552 if (!data_.empty()) {
553 original_peer_->OnReceivedData(base::WrapUnique( 553 original_peer_->OnReceivedData(base::WrapUnique(new FixedReceivedData(
554 new FixedReceivedData(data_.data(), data_.size(), -1))); 554 data_.data(), data_.size(), -1, data_.size())));
555 } 555 }
556 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler, 556 original_peer_->OnCompletedRequest(error_code, was_ignored_by_handler,
557 stale_copy_in_cache, security_info, 557 stale_copy_in_cache, security_info,
558 completion_time, total_transfer_size); 558 completion_time, total_transfer_size);
559 } 559 }
560 560
561 private: 561 private:
562 std::unique_ptr<RequestPeer> original_peer_; 562 std::unique_ptr<RequestPeer> original_peer_;
563 ResourceResponseInfo response_info_; 563 ResourceResponseInfo response_info_;
564 std::string data_; 564 std::string data_;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 const int kEncodedIncrement = 50; 816 const int kEncodedIncrement = 50;
817 817
818 int id = ConsumeRequestResource(); 818 int id = ConsumeRequestResource();
819 EXPECT_EQ(0u, queued_messages()); 819 EXPECT_EQ(0u, queued_messages());
820 820
821 NotifyReceivedResponse(id); 821 NotifyReceivedResponse(id);
822 EXPECT_EQ(0u, queued_messages()); 822 EXPECT_EQ(0u, queued_messages());
823 EXPECT_TRUE(peer_context.received_response); 823 EXPECT_TRUE(peer_context.received_response);
824 824
825 int expected_total_downloaded_length = 0; 825 int expected_total_downloaded_length = 0;
826 int expected_total_encoded_length = 0; 826 int expected_total_encoded_data_length = 0;
827 for (int i = 0; i < 10; ++i) { 827 for (int i = 0; i < 10; ++i) {
828 NotifyDataDownloaded(id, kDownloadedIncrement, kEncodedIncrement); 828 NotifyDataDownloaded(id, kDownloadedIncrement, kEncodedIncrement);
829 ConsumeDataDownloaded_ACK(id); 829 ConsumeDataDownloaded_ACK(id);
830 expected_total_downloaded_length += kDownloadedIncrement; 830 expected_total_downloaded_length += kDownloadedIncrement;
831 expected_total_encoded_length += kEncodedIncrement; 831 expected_total_encoded_data_length += kEncodedIncrement;
832 EXPECT_EQ(expected_total_downloaded_length, 832 EXPECT_EQ(expected_total_downloaded_length,
833 peer_context.total_downloaded_data_length); 833 peer_context.total_downloaded_data_length);
834 EXPECT_EQ(expected_total_encoded_length, 834 EXPECT_EQ(expected_total_encoded_data_length,
835 peer_context.total_encoded_data_length); 835 peer_context.total_encoded_data_length);
836 } 836 }
837 837
838 NotifyRequestComplete(id, strlen(kTestPageContents)); 838 NotifyRequestComplete(id, strlen(kTestPageContents));
839 EXPECT_EQ("", peer_context.data); 839 EXPECT_EQ("", peer_context.data);
840 EXPECT_TRUE(peer_context.complete); 840 EXPECT_TRUE(peer_context.complete);
841 EXPECT_EQ(0u, queued_messages()); 841 EXPECT_EQ(0u, queued_messages());
842 842
843 dispatcher()->RemovePendingRequest(request_id); 843 dispatcher()->RemovePendingRequest(request_id);
844 ConsumeReleaseDownloadedFile(id); 844 ConsumeReleaseDownloadedFile(id);
845 EXPECT_EQ(0u, queued_messages()); 845 EXPECT_EQ(0u, queued_messages());
846 EXPECT_EQ(expected_total_downloaded_length, 846 EXPECT_EQ(expected_total_downloaded_length,
847 peer_context.total_downloaded_data_length); 847 peer_context.total_downloaded_data_length);
848 EXPECT_EQ(expected_total_encoded_length, 848 EXPECT_EQ(expected_total_encoded_data_length,
849 peer_context.total_encoded_data_length); 849 peer_context.total_encoded_data_length);
850 } 850 }
851 851
852 // Make sure that when a download to file is cancelled, the file is destroyed. 852 // Make sure that when a download to file is cancelled, the file is destroyed.
853 TEST_F(ResourceDispatcherTest, CancelDownloadToFile) { 853 TEST_F(ResourceDispatcherTest, CancelDownloadToFile) {
854 std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true)); 854 std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true));
855 TestRequestPeer::Context peer_context; 855 TestRequestPeer::Context peer_context;
856 int request_id = StartAsync(*request_info.get(), NULL, &peer_context); 856 int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
857 857
858 int id = ConsumeRequestResource(); 858 int id = ConsumeRequestResource();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 ResourceResponseHead response_head; 934 ResourceResponseHead response_head;
935 935
936 PerformTest(response_head); 936 PerformTest(response_head);
937 937
938 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 938 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
939 EXPECT_EQ(base::TimeTicks(), 939 EXPECT_EQ(base::TimeTicks(),
940 response_info().load_timing.connect_timing.dns_start); 940 response_info().load_timing.connect_timing.dns_start);
941 } 941 }
942 942
943 } // namespace content 943 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698