OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 9 #include "base/message_loop.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 *has_new_first_party_for_cookies = false; | 49 *has_new_first_party_for_cookies = false; |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { | 53 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { |
54 } | 54 } |
55 | 55 |
56 virtual void OnDownloadedData(int len) { | 56 virtual void OnDownloadedData(int len) { |
57 } | 57 } |
58 | 58 |
59 virtual void OnReceivedData(const char* data, int len) { | 59 virtual void OnReceivedData(const char* data, int data_length, |
pfeldman
2011/04/01 08:48:06
nit: one parameter per line.
vsevik
2011/04/01 09:50:59
Done.
| |
60 int length_received) { | |
60 EXPECT_FALSE(complete_); | 61 EXPECT_FALSE(complete_); |
61 data_.append(data, len); | 62 data_.append(data, data_length); |
63 length_received_ += length_received; | |
62 } | 64 } |
63 | 65 |
64 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 66 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
65 const std::string& security_info, | 67 const std::string& security_info, |
66 const base::Time& completion_time) { | 68 const base::Time& completion_time) { |
67 EXPECT_FALSE(complete_); | 69 EXPECT_FALSE(complete_); |
68 complete_ = true; | 70 complete_ = true; |
69 } | 71 } |
70 | 72 |
73 bool complete() const { | |
pfeldman
2011/04/01 08:48:06
define in the header.
vsevik
2011/04/01 09:50:59
It's a unit test without a header.
| |
74 return complete_; | |
75 } | |
71 const std::string& data() const { | 76 const std::string& data() const { |
72 return data_; | 77 return data_; |
73 } | 78 } |
74 bool complete() const { | 79 int lengthReceived() const { |
pfeldman
2011/04/01 08:48:06
either GetLengthReceived or length_received define
vsevik
2011/04/01 09:50:59
Renamed to length_received
| |
75 return complete_; | 80 return length_received_; |
76 } | 81 } |
77 | 82 |
78 private: | 83 private: |
79 bool complete_; | 84 bool complete_; |
80 std::string data_; | 85 std::string data_; |
86 int length_received_; | |
81 }; | 87 }; |
82 | 88 |
83 | 89 |
84 // Sets up the message sender override for the unit test | 90 // Sets up the message sender override for the unit test |
85 class ResourceDispatcherTest : public testing::Test, | 91 class ResourceDispatcherTest : public testing::Test, |
86 public IPC::Message::Sender { | 92 public IPC::Message::Sender { |
87 public: | 93 public: |
88 // Emulates IPC send operations (IPC::Message::Sender) by adding | 94 // Emulates IPC send operations (IPC::Message::Sender) by adding |
89 // pending messages to the queue. | 95 // pending messages to the queue. |
90 virtual bool Send(IPC::Message* msg) { | 96 virtual bool Send(IPC::Message* msg) { |
(...skipping 25 matching lines...) Expand all Loading... | |
116 | 122 |
117 // received data message with the test contents | 123 // received data message with the test contents |
118 base::SharedMemory shared_mem; | 124 base::SharedMemory shared_mem; |
119 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); | 125 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); |
120 char* put_data_here = static_cast<char*>(shared_mem.memory()); | 126 char* put_data_here = static_cast<char*>(shared_mem.memory()); |
121 memcpy(put_data_here, test_page_contents, test_page_contents_len); | 127 memcpy(put_data_here, test_page_contents, test_page_contents_len); |
122 base::SharedMemoryHandle dup_handle; | 128 base::SharedMemoryHandle dup_handle; |
123 EXPECT_TRUE(shared_mem.GiveToProcess( | 129 EXPECT_TRUE(shared_mem.GiveToProcess( |
124 base::Process::Current().handle(), &dup_handle)); | 130 base::Process::Current().handle(), &dup_handle)); |
125 dispatcher_->OnReceivedData( | 131 dispatcher_->OnReceivedData( |
126 message_queue_[0], request_id, dup_handle, test_page_contents_len); | 132 message_queue_[0], request_id, dup_handle, test_page_contents_len, |
133 test_page_contents_len); | |
127 | 134 |
128 message_queue_.erase(message_queue_.begin()); | 135 message_queue_.erase(message_queue_.begin()); |
129 | 136 |
130 // read the ack message. | 137 // read the ack message. |
131 Tuple1<int> request_ack; | 138 Tuple1<int> request_ack; |
132 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read( | 139 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read( |
133 &message_queue_[0], &request_ack)); | 140 &message_queue_[0], &request_ack)); |
134 | 141 |
135 ASSERT_EQ(request_ack.a, request_id); | 142 ASSERT_EQ(request_ack.a, request_id); |
136 | 143 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 242 |
236 delete response_message; | 243 delete response_message; |
237 | 244 |
238 // Duplicate the shared memory handle so both the test and the callee can | 245 // Duplicate the shared memory handle so both the test and the callee can |
239 // close their copy. | 246 // close their copy. |
240 base::SharedMemoryHandle duplicated_handle; | 247 base::SharedMemoryHandle duplicated_handle; |
241 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 248 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
242 &duplicated_handle)); | 249 &duplicated_handle)); |
243 | 250 |
244 response_message = | 251 response_message = |
245 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100); | 252 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); |
246 | 253 |
247 dispatcher_->OnMessageReceived(*response_message); | 254 dispatcher_->OnMessageReceived(*response_message); |
248 | 255 |
249 delete response_message; | 256 delete response_message; |
250 | 257 |
251 set_defer_loading(false); | 258 set_defer_loading(false); |
252 } | 259 } |
253 | 260 |
254 // ResourceLoaderBridge::Peer methods. | 261 // ResourceLoaderBridge::Peer methods. |
255 virtual void OnUploadProgress(uint64 position, uint64 size) { | 262 virtual void OnUploadProgress(uint64 position, uint64 size) { |
256 } | 263 } |
257 | 264 |
258 virtual bool OnReceivedRedirect( | 265 virtual bool OnReceivedRedirect( |
259 const GURL& new_url, | 266 const GURL& new_url, |
260 const ResourceResponseInfo& info, | 267 const ResourceResponseInfo& info, |
261 bool* has_new_first_party_for_cookies, | 268 bool* has_new_first_party_for_cookies, |
262 GURL* new_first_party_for_cookies) { | 269 GURL* new_first_party_for_cookies) { |
263 *has_new_first_party_for_cookies = false; | 270 *has_new_first_party_for_cookies = false; |
264 return true; | 271 return true; |
265 } | 272 } |
266 | 273 |
267 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { | 274 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { |
268 EXPECT_EQ(defer_loading_, false); | 275 EXPECT_EQ(defer_loading_, false); |
269 set_defer_loading(true); | 276 set_defer_loading(true); |
270 } | 277 } |
271 | 278 |
272 virtual void OnDownloadedData(int len) { | 279 virtual void OnDownloadedData(int len) { |
273 } | 280 } |
274 | 281 |
275 virtual void OnReceivedData(const char* data, int len) { | 282 virtual void OnReceivedData(const char* data, int data_length, |
pfeldman
2011/04/01 08:48:06
ditto, ditto, ditto...
vsevik
2011/04/01 09:50:59
Done.
| |
283 int length_received) { | |
276 EXPECT_EQ(defer_loading_, false); | 284 EXPECT_EQ(defer_loading_, false); |
277 set_defer_loading(false); | 285 set_defer_loading(false); |
278 } | 286 } |
279 | 287 |
280 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 288 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
281 const std::string& security_info, | 289 const std::string& security_info, |
282 const base::Time& completion_time) { | 290 const base::Time& completion_time) { |
283 } | 291 } |
284 | 292 |
285 protected: | 293 protected: |
(...skipping 28 matching lines...) Expand all Loading... | |
314 | 322 |
315 ResourceLoaderBridge* bridge = CreateBridge(); | 323 ResourceLoaderBridge* bridge = CreateBridge(); |
316 | 324 |
317 bridge->Start(this); | 325 bridge->Start(this); |
318 InitMessages(); | 326 InitMessages(); |
319 | 327 |
320 // Dispatch deferred messages. | 328 // Dispatch deferred messages. |
321 message_loop.RunAllPending(); | 329 message_loop.RunAllPending(); |
322 delete bridge; | 330 delete bridge; |
323 } | 331 } |
OLD | NEW |