| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 return true; | 242 return true; |
| 238 } | 243 } |
| 239 | 244 |
| 240 void InitMessages() { | 245 void InitMessages() { |
| 241 set_defer_loading(true); | 246 set_defer_loading(true); |
| 242 | 247 |
| 243 ResourceResponseHead response_head; | 248 ResourceResponseHead response_head; |
| 244 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 249 response_head.status.set_status(net::URLRequestStatus::SUCCESS); |
| 245 | 250 |
| 246 IPC::Message* response_message = | 251 IPC::Message* response_message = |
| 247 new ResourceMsg_ReceivedResponse(0, 0, response_head); | 252 new ResourceMsg_ReceivedResponse(0, 0, response_head, |
| 253 base::TimeTicks(), base::TimeTicks()); |
| 248 | 254 |
| 249 dispatcher_->OnMessageReceived(*response_message); | 255 dispatcher_->OnMessageReceived(*response_message); |
| 250 | 256 |
| 251 delete response_message; | 257 delete response_message; |
| 252 | 258 |
| 253 // Duplicate the shared memory handle so both the test and the callee can | 259 // Duplicate the shared memory handle so both the test and the callee can |
| 254 // close their copy. | 260 // close their copy. |
| 255 base::SharedMemoryHandle duplicated_handle; | 261 base::SharedMemoryHandle duplicated_handle; |
| 256 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 262 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
| 257 &duplicated_handle)); | 263 &duplicated_handle)); |
| 258 | 264 |
| 259 response_message = | 265 response_message = |
| 260 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); | 266 new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); |
| 261 | 267 |
| 262 dispatcher_->OnMessageReceived(*response_message); | 268 dispatcher_->OnMessageReceived(*response_message); |
| 263 | 269 |
| 264 delete response_message; | 270 delete response_message; |
| 265 | 271 |
| 266 set_defer_loading(false); | 272 set_defer_loading(false); |
| 267 } | 273 } |
| 268 | 274 |
| 269 // ResourceLoaderBridge::Peer methods. | 275 // ResourceLoaderBridge::Peer methods. |
| 270 virtual void OnUploadProgress(uint64 position, uint64 size) { | 276 virtual void OnUploadProgress(uint64 position, uint64 size) { |
| 271 } | 277 } |
| 272 | 278 |
| 273 virtual bool OnReceivedRedirect( | 279 virtual bool OnReceivedRedirect( |
| 274 const GURL& new_url, | 280 const GURL& new_url, |
| 275 const ResourceResponseInfo& info, | 281 const ResourceResponseInfo& info, |
| 282 const base::TimeTicks& start_time, |
| 283 const base::TimeTicks& end_time, |
| 276 bool* has_new_first_party_for_cookies, | 284 bool* has_new_first_party_for_cookies, |
| 277 GURL* new_first_party_for_cookies) { | 285 GURL* new_first_party_for_cookies) { |
| 278 *has_new_first_party_for_cookies = false; | 286 *has_new_first_party_for_cookies = false; |
| 279 return true; | 287 return true; |
| 280 } | 288 } |
| 281 | 289 |
| 282 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { | 290 virtual void OnReceivedResponse(const ResourceResponseInfo& info, |
| 291 const base::TimeTicks& start_time, |
| 292 const base::TimeTicks& end_time) { |
| 283 EXPECT_EQ(defer_loading_, false); | 293 EXPECT_EQ(defer_loading_, false); |
| 284 set_defer_loading(true); | 294 set_defer_loading(true); |
| 285 } | 295 } |
| 286 | 296 |
| 287 virtual void OnDownloadedData(int len) { | 297 virtual void OnDownloadedData(int len) { |
| 288 } | 298 } |
| 289 | 299 |
| 290 virtual void OnReceivedData(const char* data, | 300 virtual void OnReceivedData(const char* data, |
| 291 int data_length, | 301 int data_length, |
| 292 int encoded_data_length) { | 302 int encoded_data_length) { |
| 293 EXPECT_EQ(defer_loading_, false); | 303 EXPECT_EQ(defer_loading_, false); |
| 294 set_defer_loading(false); | 304 set_defer_loading(false); |
| 295 } | 305 } |
| 296 | 306 |
| 297 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 307 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 298 const std::string& security_info, | 308 const std::string& security_info, |
| 299 const base::Time& completion_time) { | 309 const base::TimeTicks& completion_time) { |
| 300 } | 310 } |
| 301 | 311 |
| 302 protected: | 312 protected: |
| 303 virtual void SetUp() { | 313 virtual void SetUp() { |
| 304 ResourceDispatcherTest::SetUp(); | 314 ResourceDispatcherTest::SetUp(); |
| 305 shared_handle_.Delete(kShmemSegmentName); | 315 shared_handle_.Delete(kShmemSegmentName); |
| 306 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); | 316 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); |
| 307 } | 317 } |
| 308 | 318 |
| 309 virtual void TearDown() { | 319 virtual void TearDown() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 331 | 341 |
| 332 ResourceLoaderBridge* bridge = CreateBridge(); | 342 ResourceLoaderBridge* bridge = CreateBridge(); |
| 333 | 343 |
| 334 bridge->Start(this); | 344 bridge->Start(this); |
| 335 InitMessages(); | 345 InitMessages(); |
| 336 | 346 |
| 337 // Dispatch deferred messages. | 347 // Dispatch deferred messages. |
| 338 message_loop.RunAllPending(); | 348 message_loop.RunAllPending(); |
| 339 delete bridge; | 349 delete bridge; |
| 340 } | 350 } |
| OLD | NEW |