| OLD | NEW |
| 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 "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 5 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_split.h" |
| 14 #include "content/browser/browser_thread_impl.h" | 16 #include "content/browser/browser_thread_impl.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 18 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 17 #include "content/browser/renderer_host/resource_message_filter.h" | 19 #include "content/browser/renderer_host/resource_message_filter.h" |
| 18 #include "content/common/child_process_host_impl.h" | 20 #include "content/common/child_process_host_impl.h" |
| 19 #include "content/common/resource_messages.h" | 21 #include "content/common/resource_messages.h" |
| 20 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 21 #include "content/public/browser/global_request_id.h" | 23 #include "content/public/browser/global_request_id.h" |
| 22 #include "content/public/browser/resource_context.h" | 24 #include "content/public/browser/resource_context.h" |
| 23 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 25 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 24 #include "content/public/browser/resource_throttle.h" | 26 #include "content/public/browser/resource_throttle.h" |
| 25 #include "content/public/common/resource_response.h" | 27 #include "content/public/common/resource_response.h" |
| 26 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
| 27 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 28 #include "net/base/upload_data.h" | 30 #include "net/base/upload_data.h" |
| 29 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
| 30 #include "net/url_request/url_request.h" | 32 #include "net/url_request/url_request.h" |
| 31 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 32 #include "net/url_request/url_request_job.h" | 34 #include "net/url_request/url_request_job.h" |
| 35 #include "net/url_request/url_request_simple_job.h" |
| 33 #include "net/url_request/url_request_test_job.h" | 36 #include "net/url_request/url_request_test_job.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "webkit/appcache/appcache_interfaces.h" | 38 #include "webkit/appcache/appcache_interfaces.h" |
| 36 | 39 |
| 37 // TODO(eroman): Write unit tests for SafeBrowsing that exercise | 40 // TODO(eroman): Write unit tests for SafeBrowsing that exercise |
| 38 // SafeBrowsingResourceHandler. | 41 // SafeBrowsingResourceHandler. |
| 39 | 42 |
| 40 namespace content { | 43 namespace content { |
| 41 | 44 |
| 42 namespace { | 45 namespace { |
| 43 | 46 |
| 44 // Returns the resource response header structure for this request. | 47 // Returns the resource response header structure for this request. |
| 45 void GetResponseHead(const std::vector<IPC::Message>& messages, | 48 void GetResponseHead(const std::vector<IPC::Message>& messages, |
| 46 content::ResourceResponseHead* response_head) { | 49 content::ResourceResponseHead* response_head) { |
| 47 ASSERT_GE(messages.size(), 2U); | 50 ASSERT_GE(messages.size(), 2U); |
| 48 | 51 |
| 49 // The first messages should be received response. | 52 // The first messages should be received response. |
| 50 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 53 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
| 51 | 54 |
| 52 PickleIterator iter(messages[0]); | 55 PickleIterator iter(messages[0]); |
| 53 int request_id; | 56 int request_id; |
| 54 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id)); | 57 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id)); |
| 55 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head)); | 58 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head)); |
| 56 } | 59 } |
| 57 | 60 |
| 61 void GenerateIPCMessage( |
| 62 scoped_refptr<ResourceMessageFilter> filter, |
| 63 scoped_ptr<IPC::Message> message) { |
| 64 bool msg_is_ok; |
| 65 ResourceDispatcherHostImpl::Get()->OnMessageReceived( |
| 66 *message, filter.get(), &msg_is_ok); |
| 67 } |
| 68 |
| 58 } // namespace | 69 } // namespace |
| 59 | 70 |
| 60 static int RequestIDForMessage(const IPC::Message& msg) { | 71 static int RequestIDForMessage(const IPC::Message& msg) { |
| 61 int request_id = -1; | 72 int request_id = -1; |
| 62 switch (msg.type()) { | 73 switch (msg.type()) { |
| 63 case ResourceMsg_UploadProgress::ID: | 74 case ResourceMsg_UploadProgress::ID: |
| 64 case ResourceMsg_ReceivedResponse::ID: | 75 case ResourceMsg_ReceivedResponse::ID: |
| 65 case ResourceMsg_ReceivedRedirect::ID: | 76 case ResourceMsg_ReceivedRedirect::ID: |
| 66 case ResourceMsg_DataReceived::ID: | 77 case ResourceMsg_DataReceived::ID: |
| 67 case ResourceMsg_RequestComplete::ID: | 78 case ResourceMsg_RequestComplete::ID: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 messages_.push_back(msg); | 118 messages_.push_back(msg); |
| 108 } | 119 } |
| 109 | 120 |
| 110 // This groups the messages by their request ID. The groups will be in order | 121 // This groups the messages by their request ID. The groups will be in order |
| 111 // that the first message for each request ID was received, and the messages | 122 // that the first message for each request ID was received, and the messages |
| 112 // within the groups will be in the order that they appeared. | 123 // within the groups will be in the order that they appeared. |
| 113 // Note that this clears messages_. | 124 // Note that this clears messages_. |
| 114 typedef std::vector< std::vector<IPC::Message> > ClassifiedMessages; | 125 typedef std::vector< std::vector<IPC::Message> > ClassifiedMessages; |
| 115 void GetClassifiedMessages(ClassifiedMessages* msgs); | 126 void GetClassifiedMessages(ClassifiedMessages* msgs); |
| 116 | 127 |
| 128 private: |
| 117 std::vector<IPC::Message> messages_; | 129 std::vector<IPC::Message> messages_; |
| 118 }; | 130 }; |
| 119 | 131 |
| 120 // This is very inefficient as a result of repeatedly extracting the ID, use | 132 // This is very inefficient as a result of repeatedly extracting the ID, use |
| 121 // only for tests! | 133 // only for tests! |
| 122 void ResourceIPCAccumulator::GetClassifiedMessages(ClassifiedMessages* msgs) { | 134 void ResourceIPCAccumulator::GetClassifiedMessages(ClassifiedMessages* msgs) { |
| 123 while (!messages_.empty()) { | 135 while (!messages_.empty()) { |
| 124 std::vector<IPC::Message> cur_requests; | 136 std::vector<IPC::Message> cur_requests; |
| 125 cur_requests.push_back(messages_[0]); | 137 cur_requests.push_back(messages_[0]); |
| 126 int cur_id = RequestIDForMessage(messages_[0]); | 138 int cur_id = RequestIDForMessage(messages_[0]); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 : net::URLRequestTestJob(request, response_headers, | 294 : net::URLRequestTestJob(request, response_headers, |
| 283 response_data, auto_advance) {} | 295 response_data, auto_advance) {} |
| 284 | 296 |
| 285 protected: | 297 protected: |
| 286 ~URLRequestTestDelayedCompletionJob() {} | 298 ~URLRequestTestDelayedCompletionJob() {} |
| 287 | 299 |
| 288 private: | 300 private: |
| 289 virtual bool NextReadAsync() OVERRIDE { return true; } | 301 virtual bool NextReadAsync() OVERRIDE { return true; } |
| 290 }; | 302 }; |
| 291 | 303 |
| 304 class URLRequestBigJob : public net::URLRequestSimpleJob { |
| 305 public: |
| 306 URLRequestBigJob(net::URLRequest* request) |
| 307 : net::URLRequestSimpleJob(request) { |
| 308 } |
| 292 | 309 |
| 310 virtual bool GetData(std::string* mime_type, |
| 311 std::string* charset, |
| 312 std::string* data) const { |
| 313 *mime_type = "text/plain"; |
| 314 *charset = "UTF-8"; |
| 315 |
| 316 std::string text; |
| 317 int count; |
| 318 if (!ParseURL(request_->url(), &text, &count)) |
| 319 return false; |
| 320 |
| 321 data->reserve(text.size() * count); |
| 322 for (int i = 0; i < count; ++i) |
| 323 data->append(text); |
| 324 |
| 325 return true; |
| 326 } |
| 327 |
| 328 private: |
| 329 virtual ~URLRequestBigJob() {} |
| 330 |
| 331 // big-job:substring,N |
| 332 static bool ParseURL(const GURL& url, std::string* text, int* count) { |
| 333 std::vector<std::string> parts; |
| 334 base::SplitString(url.path(), ',', &parts); |
| 335 |
| 336 if (parts.size() != 2) |
| 337 return false; |
| 338 |
| 339 *text = parts[0]; |
| 340 return base::StringToInt(parts[1], count); |
| 341 } |
| 342 }; |
| 293 | 343 |
| 294 // Associated with an URLRequest to determine if the URLRequest gets deleted. | 344 // Associated with an URLRequest to determine if the URLRequest gets deleted. |
| 295 class TestUserData : public base::SupportsUserData::Data { | 345 class TestUserData : public base::SupportsUserData::Data { |
| 296 public: | 346 public: |
| 297 explicit TestUserData(bool* was_deleted) | 347 explicit TestUserData(bool* was_deleted) |
| 298 : was_deleted_(was_deleted) { | 348 : was_deleted_(was_deleted) { |
| 299 } | 349 } |
| 300 | 350 |
| 301 ~TestUserData() { | 351 ~TestUserData() { |
| 302 *was_deleted_ = true; | 352 *was_deleted_ = true; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 422 |
| 373 class ResourceDispatcherHostTest : public testing::Test, | 423 class ResourceDispatcherHostTest : public testing::Test, |
| 374 public IPC::Message::Sender { | 424 public IPC::Message::Sender { |
| 375 public: | 425 public: |
| 376 ResourceDispatcherHostTest() | 426 ResourceDispatcherHostTest() |
| 377 : ui_thread_(BrowserThread::UI, &message_loop_), | 427 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 378 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 428 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 379 cache_thread_(BrowserThread::CACHE, &message_loop_), | 429 cache_thread_(BrowserThread::CACHE, &message_loop_), |
| 380 io_thread_(BrowserThread::IO, &message_loop_), | 430 io_thread_(BrowserThread::IO, &message_loop_), |
| 381 old_factory_(NULL), | 431 old_factory_(NULL), |
| 382 resource_type_(ResourceType::SUB_RESOURCE) { | 432 resource_type_(ResourceType::SUB_RESOURCE), |
| 433 send_data_received_acks_(false) { |
| 383 browser_context_.reset(new content::TestBrowserContext()); | 434 browser_context_.reset(new content::TestBrowserContext()); |
| 384 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); | 435 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); |
| 385 message_loop_.RunAllPending(); | 436 message_loop_.RunAllPending(); |
| 386 filter_ = new ForwardingFilter( | 437 filter_ = new ForwardingFilter( |
| 387 this, browser_context_->GetResourceContext()); | 438 this, browser_context_->GetResourceContext()); |
| 388 } | 439 } |
| 389 // IPC::Message::Sender implementation | 440 // IPC::Message::Sender implementation |
| 390 virtual bool Send(IPC::Message* msg) { | 441 virtual bool Send(IPC::Message* msg) { |
| 391 accum_.AddMessage(*msg); | 442 accum_.AddMessage(*msg); |
| 443 |
| 444 if (send_data_received_acks_ && |
| 445 msg->type() == ResourceMsg_DataReceived::ID) { |
| 446 GenerateDataReceivedACK(*msg); |
| 447 } |
| 448 |
| 392 delete msg; | 449 delete msg; |
| 393 return true; | 450 return true; |
| 394 } | 451 } |
| 395 | 452 |
| 396 protected: | 453 protected: |
| 397 // testing::Test | 454 // testing::Test |
| 398 virtual void SetUp() { | 455 virtual void SetUp() { |
| 399 DCHECK(!test_fixture_); | 456 DCHECK(!test_fixture_); |
| 400 test_fixture_ = this; | 457 test_fixture_ = this; |
| 401 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); | 458 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // ForwardingFilter. | 497 // ForwardingFilter. |
| 441 void MakeTestRequest(ResourceMessageFilter* filter, | 498 void MakeTestRequest(ResourceMessageFilter* filter, |
| 442 int render_view_id, | 499 int render_view_id, |
| 443 int request_id, | 500 int request_id, |
| 444 const GURL& url); | 501 const GURL& url); |
| 445 | 502 |
| 446 void CancelRequest(int request_id); | 503 void CancelRequest(int request_id); |
| 447 | 504 |
| 448 void CompleteStartRequest(int request_id); | 505 void CompleteStartRequest(int request_id); |
| 449 | 506 |
| 450 void EnsureTestSchemeIsAllowed() { | 507 void EnsureSchemeIsAllowed(const std::string& scheme) { |
| 451 ChildProcessSecurityPolicyImpl* policy = | 508 ChildProcessSecurityPolicyImpl* policy = |
| 452 ChildProcessSecurityPolicyImpl::GetInstance(); | 509 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 453 if (!policy->IsWebSafeScheme("test")) | 510 if (!policy->IsWebSafeScheme(scheme)) |
| 454 policy->RegisterWebSafeScheme("test"); | 511 policy->RegisterWebSafeScheme(scheme); |
| 512 } |
| 513 |
| 514 void EnsureTestSchemeIsAllowed() { |
| 515 EnsureSchemeIsAllowed("test"); |
| 455 } | 516 } |
| 456 | 517 |
| 457 // Sets a particular response for any request from now on. To switch back to | 518 // Sets a particular response for any request from now on. To switch back to |
| 458 // the default bahavior, pass an empty |headers|. |headers| should be raw- | 519 // the default bahavior, pass an empty |headers|. |headers| should be raw- |
| 459 // formatted (NULLs instead of EOLs). | 520 // formatted (NULLs instead of EOLs). |
| 460 void SetResponse(const std::string& headers, const std::string& data) { | 521 void SetResponse(const std::string& headers, const std::string& data) { |
| 461 response_headers_ = headers; | 522 response_headers_ = headers; |
| 462 response_data_ = data; | 523 response_data_ = data; |
| 463 } | 524 } |
| 464 | 525 |
| 465 // Sets a particular resource type for any request from now on. | 526 // Sets a particular resource type for any request from now on. |
| 466 void SetResourceType(ResourceType::Type type) { | 527 void SetResourceType(ResourceType::Type type) { |
| 467 resource_type_ = type; | 528 resource_type_ = type; |
| 468 } | 529 } |
| 469 | 530 |
| 531 void SendDataReceivedACKs(bool send_acks) { |
| 532 send_data_received_acks_ = send_acks; |
| 533 } |
| 534 |
| 470 // Intercepts requests for the given protocol. | 535 // Intercepts requests for the given protocol. |
| 471 void HandleScheme(const std::string& scheme) { | 536 void HandleScheme(const std::string& scheme) { |
| 472 DCHECK(scheme_.empty()); | 537 DCHECK(scheme_.empty()); |
| 473 DCHECK(!old_factory_); | 538 DCHECK(!old_factory_); |
| 474 scheme_ = scheme; | 539 scheme_ = scheme; |
| 475 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( | 540 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 476 scheme_, &ResourceDispatcherHostTest::Factory); | 541 scheme_, &ResourceDispatcherHostTest::Factory); |
| 542 EnsureSchemeIsAllowed(scheme); |
| 477 } | 543 } |
| 478 | 544 |
| 479 // Our own net::URLRequestJob factory. | 545 // Our own net::URLRequestJob factory. |
| 480 static net::URLRequestJob* Factory(net::URLRequest* request, | 546 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 481 const std::string& scheme) { | 547 const std::string& scheme) { |
| 482 if (test_fixture_->response_headers_.empty()) { | 548 if (test_fixture_->response_headers_.empty()) { |
| 483 if (delay_start_) { | 549 if (delay_start_) { |
| 484 return new URLRequestTestDelayedStartJob(request); | 550 return new URLRequestTestDelayedStartJob(request); |
| 485 } else if (delay_complete_) { | 551 } else if (delay_complete_) { |
| 486 return new URLRequestTestDelayedCompletionJob(request); | 552 return new URLRequestTestDelayedCompletionJob(request); |
| 553 } else if (scheme == "big-job") { |
| 554 return new URLRequestBigJob(request); |
| 487 } else { | 555 } else { |
| 488 return new net::URLRequestTestJob(request); | 556 return new net::URLRequestTestJob(request); |
| 489 } | 557 } |
| 490 } else { | 558 } else { |
| 491 if (delay_start_) { | 559 if (delay_start_) { |
| 492 return new URLRequestTestDelayedStartJob( | 560 return new URLRequestTestDelayedStartJob( |
| 493 request, test_fixture_->response_headers_, | 561 request, test_fixture_->response_headers_, |
| 494 test_fixture_->response_data_, false); | 562 test_fixture_->response_data_, false); |
| 495 } else if (delay_complete_) { | 563 } else if (delay_complete_) { |
| 496 return new URLRequestTestDelayedCompletionJob( | 564 return new URLRequestTestDelayedCompletionJob( |
| 497 request, test_fixture_->response_headers_, | 565 request, test_fixture_->response_headers_, |
| 498 test_fixture_->response_data_, false); | 566 test_fixture_->response_data_, false); |
| 499 } else { | 567 } else { |
| 500 return new net::URLRequestTestJob(request, | 568 return new net::URLRequestTestJob(request, |
| 501 test_fixture_->response_headers_, | 569 test_fixture_->response_headers_, |
| 502 test_fixture_->response_data_, | 570 test_fixture_->response_data_, |
| 503 false); | 571 false); |
| 504 } | 572 } |
| 505 } | 573 } |
| 506 } | 574 } |
| 507 | 575 |
| 508 void SetDelayedStartJobGeneration(bool delay_job_start) { | 576 void SetDelayedStartJobGeneration(bool delay_job_start) { |
| 509 delay_start_ = delay_job_start; | 577 delay_start_ = delay_job_start; |
| 510 } | 578 } |
| 511 | 579 |
| 512 void SetDelayedCompleteJobGeneration(bool delay_job_complete) { | 580 void SetDelayedCompleteJobGeneration(bool delay_job_complete) { |
| 513 delay_complete_ = delay_job_complete; | 581 delay_complete_ = delay_job_complete; |
| 514 } | 582 } |
| 515 | 583 |
| 584 void GenerateDataReceivedACK(const IPC::Message& msg) { |
| 585 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type()); |
| 586 |
| 587 int request_id = IPC::MessageIterator(msg).NextInt(); |
| 588 scoped_ptr<IPC::Message> ack( |
| 589 new ResourceHostMsg_DataReceived_ACK(msg.routing_id(), request_id)); |
| 590 |
| 591 MessageLoop::current()->PostTask( |
| 592 FROM_HERE, |
| 593 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); |
| 594 } |
| 595 |
| 516 MessageLoopForIO message_loop_; | 596 MessageLoopForIO message_loop_; |
| 517 BrowserThreadImpl ui_thread_; | 597 BrowserThreadImpl ui_thread_; |
| 518 BrowserThreadImpl file_thread_; | 598 BrowserThreadImpl file_thread_; |
| 519 BrowserThreadImpl cache_thread_; | 599 BrowserThreadImpl cache_thread_; |
| 520 BrowserThreadImpl io_thread_; | 600 BrowserThreadImpl io_thread_; |
| 521 scoped_ptr<content::TestBrowserContext> browser_context_; | 601 scoped_ptr<content::TestBrowserContext> browser_context_; |
| 522 scoped_refptr<ForwardingFilter> filter_; | 602 scoped_refptr<ForwardingFilter> filter_; |
| 523 ResourceDispatcherHostImpl host_; | 603 ResourceDispatcherHostImpl host_; |
| 524 ResourceIPCAccumulator accum_; | 604 ResourceIPCAccumulator accum_; |
| 525 std::string response_headers_; | 605 std::string response_headers_; |
| 526 std::string response_data_; | 606 std::string response_data_; |
| 527 std::string scheme_; | 607 std::string scheme_; |
| 528 net::URLRequest::ProtocolFactory* old_factory_; | 608 net::URLRequest::ProtocolFactory* old_factory_; |
| 529 ResourceType::Type resource_type_; | 609 ResourceType::Type resource_type_; |
| 610 bool send_data_received_acks_; |
| 530 static ResourceDispatcherHostTest* test_fixture_; | 611 static ResourceDispatcherHostTest* test_fixture_; |
| 531 static bool delay_start_; | 612 static bool delay_start_; |
| 532 static bool delay_complete_; | 613 static bool delay_complete_; |
| 533 }; | 614 }; |
| 534 // Static. | 615 // Static. |
| 535 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; | 616 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; |
| 536 bool ResourceDispatcherHostTest::delay_start_ = false; | 617 bool ResourceDispatcherHostTest::delay_start_ = false; |
| 537 bool ResourceDispatcherHostTest::delay_complete_ = false; | 618 bool ResourceDispatcherHostTest::delay_complete_ = false; |
| 538 | 619 |
| 539 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 620 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 | 1508 |
| 1428 PickleIterator iter(msgs[0][0]); | 1509 PickleIterator iter(msgs[0][0]); |
| 1429 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1510 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1430 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1511 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
| 1431 | 1512 |
| 1432 EXPECT_EQ(1, request_id); | 1513 EXPECT_EQ(1, request_id); |
| 1433 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1514 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); |
| 1434 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | 1515 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); |
| 1435 } | 1516 } |
| 1436 | 1517 |
| 1518 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { |
| 1519 EXPECT_EQ(0, host_.pending_requests()); |
| 1520 |
| 1521 SendDataReceivedACKs(true); |
| 1522 |
| 1523 HandleScheme("big-job"); |
| 1524 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 1525 |
| 1526 // Sort all the messages we saw by request. |
| 1527 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1528 accum_.GetClassifiedMessages(&msgs); |
| 1529 |
| 1530 size_t size = msgs[0].size(); |
| 1531 |
| 1532 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1533 for (size_t i = 1; i < size - 1; ++i) |
| 1534 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| 1535 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); |
| 1536 } |
| 1537 |
| 1538 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { |
| 1539 EXPECT_EQ(0, host_.pending_requests()); |
| 1540 |
| 1541 HandleScheme("big-job"); |
| 1542 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 1543 |
| 1544 // Sort all the messages we saw by request. |
| 1545 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1546 accum_.GetClassifiedMessages(&msgs); |
| 1547 |
| 1548 // We expect 1x ReceivedResponse + Nx ReceivedData messages. |
| 1549 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1550 for (size_t i = 1; i < msgs[0].size(); ++i) |
| 1551 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| 1552 |
| 1553 // NOTE: If we fail the above checks then it means that we probably didn't |
| 1554 // load a big enough response to trigger the delay mechanism we are trying to |
| 1555 // test! |
| 1556 |
| 1557 msgs[0].erase(msgs[0].begin()); |
| 1558 |
| 1559 // ACK all DataReceived messages until we find a RequestComplete message. |
| 1560 bool complete = false; |
| 1561 while (!complete) { |
| 1562 for (size_t i = 0; i < msgs[0].size(); ++i) { |
| 1563 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { |
| 1564 complete = true; |
| 1565 break; |
| 1566 } |
| 1567 |
| 1568 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
| 1569 |
| 1570 ResourceHostMsg_DataReceived_ACK msg(0, 1); |
| 1571 bool msg_was_ok; |
| 1572 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
| 1573 } |
| 1574 |
| 1575 MessageLoop::current()->RunAllPending(); |
| 1576 |
| 1577 msgs.clear(); |
| 1578 accum_.GetClassifiedMessages(&msgs); |
| 1579 } |
| 1580 } |
| 1581 |
| 1437 } // namespace content | 1582 } // namespace content |
| OLD | NEW |