| 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 27 matching lines...) Expand all Loading... |
| 38 public: | 38 public: |
| 39 TestRequestCallback() : complete_(false) { | 39 TestRequestCallback() : complete_(false) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual void OnUploadProgress(uint64 position, uint64 size) { | 42 virtual void OnUploadProgress(uint64 position, uint64 size) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual bool OnReceivedRedirect( | 45 virtual bool OnReceivedRedirect( |
| 46 const GURL& new_url, | 46 const GURL& new_url, |
| 47 const ResourceResponseInfo& info, | 47 const ResourceResponseInfo& info, |
| 48 const base::TimeTicks& start_time, |
| 49 const base::TimeTicks& end_time, |
| 48 bool* has_new_first_party_for_cookies, | 50 bool* has_new_first_party_for_cookies, |
| 49 GURL* new_first_party_for_cookies) { | 51 GURL* new_first_party_for_cookies) { |
| 50 *has_new_first_party_for_cookies = false; | 52 *has_new_first_party_for_cookies = false; |
| 51 return true; | 53 return true; |
| 52 } | 54 } |
| 53 | 55 |
| 54 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { | 56 virtual void OnReceivedResponse(const ResourceResponseInfo& info, |
| 57 const base::TimeTicks& start_time, |
| 58 const base::TimeTicks& end_time) { |
| 55 } | 59 } |
| 56 | 60 |
| 57 virtual void OnDownloadedData(int len) { | 61 virtual void OnDownloadedData(int len) { |
| 58 } | 62 } |
| 59 | 63 |
| 60 virtual void OnReceivedData(const char* data, | 64 virtual void OnReceivedData(const char* data, |
| 61 int data_length, | 65 int data_length, |
| 62 int encoded_data_length) { | 66 int encoded_data_length) { |
| 63 EXPECT_FALSE(complete_); | 67 EXPECT_FALSE(complete_); |
| 64 data_.append(data, data_length); | 68 data_.append(data, data_length); |
| 65 total_encoded_data_length_ += encoded_data_length; | 69 total_encoded_data_length_ += encoded_data_length; |
| 66 } | 70 } |
| 67 | 71 |
| 68 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 72 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 69 const std::string& security_info, | 73 const std::string& security_info, |
| 70 const base::Time& completion_time) { | 74 const base::TimeTicks& completion_time) { |
| 71 EXPECT_FALSE(complete_); | 75 EXPECT_FALSE(complete_); |
| 72 complete_ = true; | 76 complete_ = true; |
| 73 } | 77 } |
| 74 | 78 |
| 75 bool complete() const { | 79 bool complete() const { |
| 76 return complete_; | 80 return complete_; |
| 77 } | 81 } |
| 78 const std::string& data() const { | 82 const std::string& data() const { |
| 79 return data_; | 83 return data_; |
| 80 } | 84 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // check values | 117 // check values |
| 114 EXPECT_EQ(test_page_url, request.url.spec()); | 118 EXPECT_EQ(test_page_url, request.url.spec()); |
| 115 | 119 |
| 116 // received response message | 120 // received response message |
| 117 ResourceResponseHead response; | 121 ResourceResponseHead response; |
| 118 std::string raw_headers(test_page_headers); | 122 std::string raw_headers(test_page_headers); |
| 119 std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0'); | 123 std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0'); |
| 120 response.headers = new net::HttpResponseHeaders(raw_headers); | 124 response.headers = new net::HttpResponseHeaders(raw_headers); |
| 121 response.mime_type = test_page_mime_type; | 125 response.mime_type = test_page_mime_type; |
| 122 response.charset = test_page_charset; | 126 response.charset = test_page_charset; |
| 123 dispatcher_->OnReceivedResponse(request_id, response); | 127 dispatcher_->OnReceivedResponse(request_id, response, base::TimeTicks(), |
| 128 base::TimeTicks()); |
| 124 | 129 |
| 125 // received data message with the test contents | 130 // received data message with the test contents |
| 126 base::SharedMemory shared_mem; | 131 base::SharedMemory shared_mem; |
| 127 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); | 132 EXPECT_TRUE(shared_mem.CreateAndMapAnonymous(test_page_contents_len)); |
| 128 char* put_data_here = static_cast<char*>(shared_mem.memory()); | 133 char* put_data_here = static_cast<char*>(shared_mem.memory()); |
| 129 memcpy(put_data_here, test_page_contents, test_page_contents_len); | 134 memcpy(put_data_here, test_page_contents, test_page_contents_len); |
| 130 base::SharedMemoryHandle dup_handle; | 135 base::SharedMemoryHandle dup_handle; |
| 131 EXPECT_TRUE(shared_mem.GiveToProcess( | 136 EXPECT_TRUE(shared_mem.GiveToProcess( |
| 132 base::Process::Current().handle(), &dup_handle)); | 137 base::Process::Current().handle(), &dup_handle)); |
| 133 dispatcher_->OnReceivedData( | 138 dispatcher_->OnReceivedData( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return true; | 243 return true; |
| 239 } | 244 } |
| 240 | 245 |
| 241 void InitMessages() { | 246 void InitMessages() { |
| 242 set_defer_loading(true); | 247 set_defer_loading(true); |
| 243 | 248 |
| 244 ResourceResponseHead response_head; | 249 ResourceResponseHead response_head; |
| 245 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 250 response_head.status.set_status(net::URLRequestStatus::SUCCESS); |
| 246 | 251 |
| 247 IPC::Message* response_message = | 252 IPC::Message* response_message = |
| 248 new ResourceMsg_ReceivedResponse(0, 0, response_head); | 253 new ResourceMsg_ReceivedResponse(0, 0, response_head, |
| 254 base::TimeTicks(), base::TimeTicks()); |
| 249 | 255 |
| 250 dispatcher_->OnMessageReceived(*response_message); | 256 dispatcher_->OnMessageReceived(*response_message); |
| 251 | 257 |
| 252 delete response_message; | 258 delete response_message; |
| 253 | 259 |
| 254 // Duplicate the shared memory handle so both the test and the callee can | 260 // Duplicate the shared memory handle so both the test and the callee can |
| 255 // close their copy. | 261 // close their copy. |
| 256 base::SharedMemoryHandle duplicated_handle; | 262 base::SharedMemoryHandle duplicated_handle; |
| 257 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 263 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
| 258 &duplicated_handle)); | 264 &duplicated_handle)); |
| 259 | 265 |
| 260 response_message = | 266 response_message = |
| 261 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); | 267 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); |
| 262 | 268 |
| 263 dispatcher_->OnMessageReceived(*response_message); | 269 dispatcher_->OnMessageReceived(*response_message); |
| 264 | 270 |
| 265 delete response_message; | 271 delete response_message; |
| 266 | 272 |
| 267 set_defer_loading(false); | 273 set_defer_loading(false); |
| 268 } | 274 } |
| 269 | 275 |
| 270 // ResourceLoaderBridge::Peer methods. | 276 // ResourceLoaderBridge::Peer methods. |
| 271 virtual void OnUploadProgress(uint64 position, uint64 size) { | 277 virtual void OnUploadProgress(uint64 position, uint64 size) { |
| 272 } | 278 } |
| 273 | 279 |
| 274 virtual bool OnReceivedRedirect( | 280 virtual bool OnReceivedRedirect( |
| 275 const GURL& new_url, | 281 const GURL& new_url, |
| 276 const ResourceResponseInfo& info, | 282 const ResourceResponseInfo& info, |
| 283 const base::TimeTicks& start_time, |
| 284 const base::TimeTicks& end_time, |
| 277 bool* has_new_first_party_for_cookies, | 285 bool* has_new_first_party_for_cookies, |
| 278 GURL* new_first_party_for_cookies) { | 286 GURL* new_first_party_for_cookies) { |
| 279 *has_new_first_party_for_cookies = false; | 287 *has_new_first_party_for_cookies = false; |
| 280 return true; | 288 return true; |
| 281 } | 289 } |
| 282 | 290 |
| 283 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { | 291 virtual void OnReceivedResponse(const ResourceResponseInfo& info, |
| 292 const base::TimeTicks& start_time, |
| 293 const base::TimeTicks& end_time) { |
| 284 EXPECT_EQ(defer_loading_, false); | 294 EXPECT_EQ(defer_loading_, false); |
| 285 set_defer_loading(true); | 295 set_defer_loading(true); |
| 286 } | 296 } |
| 287 | 297 |
| 288 virtual void OnDownloadedData(int len) { | 298 virtual void OnDownloadedData(int len) { |
| 289 } | 299 } |
| 290 | 300 |
| 291 virtual void OnReceivedData(const char* data, | 301 virtual void OnReceivedData(const char* data, |
| 292 int data_length, | 302 int data_length, |
| 293 int encoded_data_length) { | 303 int encoded_data_length) { |
| 294 EXPECT_EQ(defer_loading_, false); | 304 EXPECT_EQ(defer_loading_, false); |
| 295 set_defer_loading(false); | 305 set_defer_loading(false); |
| 296 } | 306 } |
| 297 | 307 |
| 298 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 308 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 299 const std::string& security_info, | 309 const std::string& security_info, |
| 300 const base::Time& completion_time) { | 310 const base::TimeTicks& completion_time) { |
| 301 } | 311 } |
| 302 | 312 |
| 303 protected: | 313 protected: |
| 304 virtual void SetUp() { | 314 virtual void SetUp() { |
| 305 ResourceDispatcherTest::SetUp(); | 315 ResourceDispatcherTest::SetUp(); |
| 306 shared_handle_.Delete(kShmemSegmentName); | 316 shared_handle_.Delete(kShmemSegmentName); |
| 307 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); | 317 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); |
| 308 } | 318 } |
| 309 | 319 |
| 310 virtual void TearDown() { | 320 virtual void TearDown() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 332 | 342 |
| 333 ResourceLoaderBridge* bridge = CreateBridge(); | 343 ResourceLoaderBridge* bridge = CreateBridge(); |
| 334 | 344 |
| 335 bridge->Start(this); | 345 bridge->Start(this); |
| 336 InitMessages(); | 346 InitMessages(); |
| 337 | 347 |
| 338 // Dispatch deferred messages. | 348 // Dispatch deferred messages. |
| 339 message_loop.RunAllPending(); | 349 message_loop.RunAllPending(); |
| 340 delete bridge; | 350 delete bridge; |
| 341 } | 351 } |
| OLD | NEW |