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

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

Issue 6771043: Enabled actual transfer size in chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment added Created 9 years, 8 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/common/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) 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
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,
60 int data_length,
61 int raw_data_length) {
60 EXPECT_FALSE(complete_); 62 EXPECT_FALSE(complete_);
61 data_.append(data, len); 63 data_.append(data, data_length);
64 total_raw_data_length_ += raw_data_length;
62 } 65 }
63 66
64 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 67 virtual void OnCompletedRequest(const net::URLRequestStatus& status,
65 const std::string& security_info, 68 const std::string& security_info,
66 const base::Time& completion_time) { 69 const base::Time& completion_time) {
67 EXPECT_FALSE(complete_); 70 EXPECT_FALSE(complete_);
68 complete_ = true; 71 complete_ = true;
69 } 72 }
70 73
74 bool complete() const {
75 return complete_;
76 }
71 const std::string& data() const { 77 const std::string& data() const {
72 return data_; 78 return data_;
73 } 79 }
74 bool complete() const { 80 int total_raw_data_length() const {
75 return complete_; 81 return total_raw_data_length_;
76 } 82 }
77 83
78 private: 84 private:
79 bool complete_; 85 bool complete_;
80 std::string data_; 86 std::string data_;
87 int total_raw_data_length_;
81 }; 88 };
82 89
83 90
84 // Sets up the message sender override for the unit test 91 // Sets up the message sender override for the unit test
85 class ResourceDispatcherTest : public testing::Test, 92 class ResourceDispatcherTest : public testing::Test,
86 public IPC::Message::Sender { 93 public IPC::Message::Sender {
87 public: 94 public:
88 // Emulates IPC send operations (IPC::Message::Sender) by adding 95 // Emulates IPC send operations (IPC::Message::Sender) by adding
89 // pending messages to the queue. 96 // pending messages to the queue.
90 virtual bool Send(IPC::Message* msg) { 97 virtual bool Send(IPC::Message* msg) {
(...skipping 25 matching lines...) Expand all
116 123
117 // received data message with the test contents 124 // received data message with the test contents
118 base::SharedMemory shared_mem; 125 base::SharedMemory shared_mem;
119 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); 126 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len));
120 char* put_data_here = static_cast<char*>(shared_mem.memory()); 127 char* put_data_here = static_cast<char*>(shared_mem.memory());
121 memcpy(put_data_here, test_page_contents, test_page_contents_len); 128 memcpy(put_data_here, test_page_contents, test_page_contents_len);
122 base::SharedMemoryHandle dup_handle; 129 base::SharedMemoryHandle dup_handle;
123 EXPECT_TRUE(shared_mem.GiveToProcess( 130 EXPECT_TRUE(shared_mem.GiveToProcess(
124 base::Process::Current().handle(), &dup_handle)); 131 base::Process::Current().handle(), &dup_handle));
125 dispatcher_->OnReceivedData( 132 dispatcher_->OnReceivedData(
126 message_queue_[0], request_id, dup_handle, test_page_contents_len); 133 message_queue_[0],
134 request_id,
135 dup_handle,
136 test_page_contents_len,
137 test_page_contents_len);
127 138
128 message_queue_.erase(message_queue_.begin()); 139 message_queue_.erase(message_queue_.begin());
129 140
130 // read the ack message. 141 // read the ack message.
131 Tuple1<int> request_ack; 142 Tuple1<int> request_ack;
132 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read( 143 ASSERT_TRUE(ResourceHostMsg_DataReceived_ACK::Read(
133 &message_queue_[0], &request_ack)); 144 &message_queue_[0], &request_ack));
134 145
135 ASSERT_EQ(request_ack.a, request_id); 146 ASSERT_EQ(request_ack.a, request_id);
136 147
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ResourceLoaderBridge* bridge = CreateBridge(); 187 ResourceLoaderBridge* bridge = CreateBridge();
177 188
178 bridge->Start(&callback); 189 bridge->Start(&callback);
179 190
180 ProcessMessages(); 191 ProcessMessages();
181 192
182 // FIXME(brettw) when the request complete messages are actually handledo 193 // FIXME(brettw) when the request complete messages are actually handledo
183 // and dispatched, uncomment this. 194 // and dispatched, uncomment this.
184 //EXPECT_TRUE(callback.complete()); 195 //EXPECT_TRUE(callback.complete());
185 //EXPECT_STREQ(test_page_contents, callback.data().c_str()); 196 //EXPECT_STREQ(test_page_contents, callback.data().c_str());
197 //EXPECT_EQ(test_page_contents_len, callback.total_raw_data_length());
186 198
187 delete bridge; 199 delete bridge;
188 } 200 }
189 201
190 // Tests that the request IDs are straight when there are multiple requests. 202 // Tests that the request IDs are straight when there are multiple requests.
191 TEST_F(ResourceDispatcherTest, MultipleRequests) { 203 TEST_F(ResourceDispatcherTest, MultipleRequests) {
192 // FIXME 204 // FIXME
193 } 205 }
194 206
195 // Tests that the cancel method prevents other messages from being received 207 // Tests that the cancel method prevents other messages from being received
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 247
236 delete response_message; 248 delete response_message;
237 249
238 // Duplicate the shared memory handle so both the test and the callee can 250 // Duplicate the shared memory handle so both the test and the callee can
239 // close their copy. 251 // close their copy.
240 base::SharedMemoryHandle duplicated_handle; 252 base::SharedMemoryHandle duplicated_handle;
241 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), 253 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(),
242 &duplicated_handle)); 254 &duplicated_handle));
243 255
244 response_message = 256 response_message =
245 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100); 257 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100);
246 258
247 dispatcher_->OnMessageReceived(*response_message); 259 dispatcher_->OnMessageReceived(*response_message);
248 260
249 delete response_message; 261 delete response_message;
250 262
251 set_defer_loading(false); 263 set_defer_loading(false);
252 } 264 }
253 265
254 // ResourceLoaderBridge::Peer methods. 266 // ResourceLoaderBridge::Peer methods.
255 virtual void OnUploadProgress(uint64 position, uint64 size) { 267 virtual void OnUploadProgress(uint64 position, uint64 size) {
256 } 268 }
257 269
258 virtual bool OnReceivedRedirect( 270 virtual bool OnReceivedRedirect(
259 const GURL& new_url, 271 const GURL& new_url,
260 const ResourceResponseInfo& info, 272 const ResourceResponseInfo& info,
261 bool* has_new_first_party_for_cookies, 273 bool* has_new_first_party_for_cookies,
262 GURL* new_first_party_for_cookies) { 274 GURL* new_first_party_for_cookies) {
263 *has_new_first_party_for_cookies = false; 275 *has_new_first_party_for_cookies = false;
264 return true; 276 return true;
265 } 277 }
266 278
267 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { 279 virtual void OnReceivedResponse(const ResourceResponseInfo& info) {
268 EXPECT_EQ(defer_loading_, false); 280 EXPECT_EQ(defer_loading_, false);
269 set_defer_loading(true); 281 set_defer_loading(true);
270 } 282 }
271 283
272 virtual void OnDownloadedData(int len) { 284 virtual void OnDownloadedData(int len) {
273 } 285 }
274 286
275 virtual void OnReceivedData(const char* data, int len) { 287 virtual void OnReceivedData(const char* data,
288 int data_length,
289 int raw_data_length) {
276 EXPECT_EQ(defer_loading_, false); 290 EXPECT_EQ(defer_loading_, false);
277 set_defer_loading(false); 291 set_defer_loading(false);
278 } 292 }
279 293
280 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 294 virtual void OnCompletedRequest(const net::URLRequestStatus& status,
281 const std::string& security_info, 295 const std::string& security_info,
282 const base::Time& completion_time) { 296 const base::Time& completion_time) {
283 } 297 }
284 298
285 protected: 299 protected:
(...skipping 28 matching lines...) Expand all
314 328
315 ResourceLoaderBridge* bridge = CreateBridge(); 329 ResourceLoaderBridge* bridge = CreateBridge();
316 330
317 bridge->Start(this); 331 bridge->Start(this);
318 InitMessages(); 332 InitMessages();
319 333
320 // Dispatch deferred messages. 334 // Dispatch deferred messages.
321 message_loop.RunAllPending(); 335 message_loop.RunAllPending();
322 delete bridge; 336 delete bridge;
323 } 337 }
OLDNEW
« no previous file with comments | « content/common/resource_dispatcher.cc ('k') | content/common/resource_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698