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

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

Issue 23583039: Convert a bunch of resource IPCs to be control messages. They didn't need to be routed. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove dcheck from RenderProcessHost instead Created 7 years, 3 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 | Annotate | Revision Log
« 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/process/process.h" 10 #include "base/process/process.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 dispatcher_->OnReceivedResponse(request_id, response); 127 dispatcher_->OnReceivedResponse(request_id, response);
128 128
129 // received data message with the test contents 129 // received data message with the test contents
130 base::SharedMemory shared_mem; 130 base::SharedMemory shared_mem;
131 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); 131 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len));
132 char* put_data_here = static_cast<char*>(shared_mem.memory()); 132 char* put_data_here = static_cast<char*>(shared_mem.memory());
133 memcpy(put_data_here, test_page_contents, test_page_contents_len); 133 memcpy(put_data_here, test_page_contents, test_page_contents_len);
134 base::SharedMemoryHandle dup_handle; 134 base::SharedMemoryHandle dup_handle;
135 EXPECT_TRUE(shared_mem.GiveToProcess( 135 EXPECT_TRUE(shared_mem.GiveToProcess(
136 base::Process::Current().handle(), &dup_handle)); 136 base::Process::Current().handle(), &dup_handle));
137 dispatcher_->OnSetDataBuffer(message_queue_[0], request_id, dup_handle, 137 dispatcher_->OnSetDataBuffer(request_id, dup_handle,
138 test_page_contents_len, 0); 138 test_page_contents_len, 0);
139 dispatcher_->OnReceivedData(message_queue_[0], request_id, 0, 139 dispatcher_->OnReceivedData(request_id, 0, test_page_contents_len,
140 test_page_contents_len,
141 test_page_contents_len); 140 test_page_contents_len);
142 141
143 message_queue_.erase(message_queue_.begin()); 142 message_queue_.erase(message_queue_.begin());
144 143
145 // read the ack message. 144 // read the ack message.
146 Tuple1<int> request_ack; 145 Tuple1<int> request_ack;
147 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read( 146 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read(
148 &message_queue_[0], &request_ack)); 147 &message_queue_[0], &request_ack));
149 148
150 ASSERT_EQ(request_ack.a, request_id); 149 ASSERT_EQ(request_ack.a, request_id);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return true; 243 return true;
245 } 244 }
246 245
247 void InitMessages() { 246 void InitMessages() {
248 set_defer_loading(true); 247 set_defer_loading(true);
249 248
250 ResourceResponseHead response_head; 249 ResourceResponseHead response_head;
251 response_head.error_code = net::OK; 250 response_head.error_code = net::OK;
252 251
253 dispatcher_->OnMessageReceived( 252 dispatcher_->OnMessageReceived(
254 ResourceMsg_ReceivedResponse(0, 0, response_head)); 253 ResourceMsg_ReceivedResponse(0, response_head));
255 254
256 // Duplicate the shared memory handle so both the test and the callee can 255 // Duplicate the shared memory handle so both the test and the callee can
257 // close their copy. 256 // close their copy.
258 base::SharedMemoryHandle duplicated_handle; 257 base::SharedMemoryHandle duplicated_handle;
259 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), 258 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(),
260 &duplicated_handle)); 259 &duplicated_handle));
261 260
262 dispatcher_->OnMessageReceived( 261 dispatcher_->OnMessageReceived(
263 ResourceMsg_SetDataBuffer(0, 0, duplicated_handle, 100, 0)); 262 ResourceMsg_SetDataBuffer(0, duplicated_handle, 100, 0));
264 dispatcher_->OnMessageReceived( 263 dispatcher_->OnMessageReceived(ResourceMsg_DataReceived(0, 0, 100, 100));
265 ResourceMsg_DataReceived(0, 0, 0, 100, 100));
266 264
267 set_defer_loading(false); 265 set_defer_loading(false);
268 } 266 }
269 267
270 // ResourceLoaderBridge::Peer methods. 268 // ResourceLoaderBridge::Peer methods.
271 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { 269 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE {
272 } 270 }
273 271
274 virtual bool OnReceivedRedirect( 272 virtual bool OnReceivedRedirect(
275 const GURL& new_url, 273 const GURL& new_url,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 virtual bool Send(IPC::Message* msg) OVERRIDE { 346 virtual bool Send(IPC::Message* msg) OVERRIDE {
349 delete msg; 347 delete msg;
350 return true; 348 return true;
351 } 349 }
352 350
353 void PerformTest(const ResourceResponseHead& response_head) { 351 void PerformTest(const ResourceResponseHead& response_head) {
354 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); 352 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge());
355 bridge->Start(this); 353 bridge->Start(this);
356 354
357 dispatcher_->OnMessageReceived( 355 dispatcher_->OnMessageReceived(
358 ResourceMsg_ReceivedResponse(0, 0, response_head)); 356 ResourceMsg_ReceivedResponse(0, response_head));
359 } 357 }
360 358
361 // ResourceLoaderBridge::Peer methods. 359 // ResourceLoaderBridge::Peer methods.
362 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { 360 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE {
363 } 361 }
364 362
365 virtual bool OnReceivedRedirect( 363 virtual bool OnReceivedRedirect(
366 const GURL& new_url, 364 const GURL& new_url,
367 const ResourceResponseInfo& info, 365 const ResourceResponseInfo& info,
368 bool* has_new_first_party_for_cookies, 366 bool* has_new_first_party_for_cookies,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 response_head.error_code = net::OK; 432 response_head.error_code = net::OK;
435 433
436 PerformTest(response_head); 434 PerformTest(response_head);
437 435
438 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 436 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
439 EXPECT_EQ(base::TimeTicks(), 437 EXPECT_EQ(base::TimeTicks(),
440 response_info().load_timing.connect_timing.dns_start); 438 response_info().load_timing.connect_timing.dns_start);
441 } 439 }
442 440
443 } // namespace content 441 } // 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