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

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

Issue 2762953004: Remove inline small resource transfer experiment (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/common/resource_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 void NotifyDataReceived(int request_id, const std::string& data) { 177 void NotifyDataReceived(int request_id, const std::string& data) {
178 ASSERT_LE(data.length(), shared_memory_map_[request_id]->requested_size()); 178 ASSERT_LE(data.length(), shared_memory_map_[request_id]->requested_size());
179 memcpy(shared_memory_map_[request_id]->memory(), data.c_str(), 179 memcpy(shared_memory_map_[request_id]->memory(), data.c_str(),
180 data.length()); 180 data.length());
181 181
182 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataReceived( 182 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataReceived(
183 request_id, 0, data.length(), data.length()))); 183 request_id, 0, data.length(), data.length())));
184 } 184 }
185 185
186 void NotifyInlinedDataChunkReceived(int request_id,
187 const std::vector<char>& data) {
188 auto size = data.size();
189 EXPECT_TRUE(dispatcher_->OnMessageReceived(
190 ResourceMsg_InlinedDataChunkReceived(request_id, data, size)));
191 }
192
193 void NotifyDataDownloaded(int request_id, 186 void NotifyDataDownloaded(int request_id,
194 int decoded_length, 187 int decoded_length,
195 int encoded_data_length) { 188 int encoded_data_length) {
196 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataDownloaded( 189 EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataDownloaded(
197 request_id, decoded_length, encoded_data_length))); 190 request_id, decoded_length, encoded_data_length)));
198 } 191 }
199 192
200 void NotifyRequestComplete(int request_id, size_t total_size) { 193 void NotifyRequestComplete(int request_id, size_t total_size) {
201 ResourceRequestCompletionStatus request_complete_data; 194 ResourceRequestCompletionStatus request_complete_data;
202 request_complete_data.error_code = net::OK; 195 request_complete_data.error_code = net::OK;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 NotifyDataReceived(id, kTestPageContents + kFirstReceiveSize); 269 NotifyDataReceived(id, kTestPageContents + kFirstReceiveSize);
277 ConsumeDataReceived_ACK(id); 270 ConsumeDataReceived_ACK(id);
278 EXPECT_EQ(0u, queued_messages()); 271 EXPECT_EQ(0u, queued_messages());
279 272
280 NotifyRequestComplete(id, strlen(kTestPageContents)); 273 NotifyRequestComplete(id, strlen(kTestPageContents));
281 EXPECT_EQ(kTestPageContents, peer_context.data); 274 EXPECT_EQ(kTestPageContents, peer_context.data);
282 EXPECT_TRUE(peer_context.complete); 275 EXPECT_TRUE(peer_context.complete);
283 EXPECT_EQ(0u, queued_messages()); 276 EXPECT_EQ(0u, queued_messages());
284 } 277 }
285 278
286 // A simple request with an inline data response.
287 TEST_F(ResourceDispatcherTest, ResponseWithInlinedData) {
288 base::test::ScopedFeatureList scoped_feature_list;
289 scoped_feature_list.InitAndEnableFeature(
290 features::kOptimizeLoadingIPCForSmallResources);
291
292 std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
293 TestRequestPeer::Context peer_context;
294 StartAsync(std::move(request), NULL, &peer_context);
295
296 int id = ConsumeRequestResource();
297 EXPECT_EQ(0u, queued_messages());
298
299 NotifyReceivedResponse(id);
300 EXPECT_EQ(0u, queued_messages());
301 EXPECT_TRUE(peer_context.received_response);
302
303 std::vector<char> data(kTestPageContents,
304 kTestPageContents + strlen(kTestPageContents));
305 NotifyInlinedDataChunkReceived(id, data);
306 EXPECT_EQ(0u, queued_messages());
307
308 NotifyRequestComplete(id, strlen(kTestPageContents));
309 EXPECT_EQ(kTestPageContents, peer_context.data);
310 EXPECT_TRUE(peer_context.complete);
311 EXPECT_EQ(0u, queued_messages());
312 }
313
314 // Tests that the request IDs are straight when there are two interleaving 279 // Tests that the request IDs are straight when there are two interleaving
315 // requests. 280 // requests.
316 TEST_F(ResourceDispatcherTest, MultipleRequests) { 281 TEST_F(ResourceDispatcherTest, MultipleRequests) {
317 const char kTestPageContents2[] = "Not kTestPageContents"; 282 const char kTestPageContents2[] = "Not kTestPageContents";
318 283
319 std::unique_ptr<ResourceRequest> request1(CreateResourceRequest(false)); 284 std::unique_ptr<ResourceRequest> request1(CreateResourceRequest(false));
320 TestRequestPeer::Context peer_context1; 285 TestRequestPeer::Context peer_context1;
321 StartAsync(std::move(request1), NULL, &peer_context1); 286 StartAsync(std::move(request1), NULL, &peer_context1);
322 287
323 std::unique_ptr<ResourceRequest> request2(CreateResourceRequest(false)); 288 std::unique_ptr<ResourceRequest> request2(CreateResourceRequest(false));
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 ResourceResponseHead response_head; 910 ResourceResponseHead response_head;
946 911
947 PerformTest(response_head); 912 PerformTest(response_head);
948 913
949 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 914 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
950 EXPECT_EQ(base::TimeTicks(), 915 EXPECT_EQ(base::TimeTicks(),
951 response_info().load_timing.connect_timing.dns_start); 916 response_info().load_timing.connect_timing.dns_start);
952 } 917 }
953 918
954 } // namespace content 919 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/common/resource_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698