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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler_unittest.cc

Issue 2574143003: Implement upload progress handling in Mojo loading (Closed)
Patch Set: +content_browsertests Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/loader/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 #include "mojo/public/c/system/types.h" 37 #include "mojo/public/c/system/types.h"
38 #include "mojo/public/cpp/bindings/strong_binding.h" 38 #include "mojo/public/cpp/bindings/strong_binding.h"
39 #include "mojo/public/cpp/system/data_pipe.h" 39 #include "mojo/public/cpp/system/data_pipe.h"
40 #include "net/base/auth.h" 40 #include "net/base/auth.h"
41 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
42 #include "net/http/http_response_headers.h" 42 #include "net/http/http_response_headers.h"
43 #include "net/http/http_response_info.h" 43 #include "net/http/http_response_info.h"
44 #include "net/http/http_status_code.h" 44 #include "net/http/http_status_code.h"
45 #include "net/http/http_util.h" 45 #include "net/http/http_util.h"
46 #include "net/ssl/client_cert_store.h" 46 #include "net/ssl/client_cert_store.h"
47 #include "net/test/url_request/url_request_mock_data_job.h"
47 #include "net/url_request/url_request.h" 48 #include "net/url_request/url_request.h"
48 #include "net/url_request/url_request_context.h" 49 #include "net/url_request/url_request_context.h"
49 #include "net/url_request/url_request_status.h" 50 #include "net/url_request/url_request_status.h"
50 #include "net/url_request/url_request_test_util.h" 51 #include "net/url_request/url_request_test_util.h"
51 #include "testing/gtest/include/gtest/gtest.h" 52 #include "testing/gtest/include/gtest/gtest.h"
52 #include "ui/base/page_transition_types.h" 53 #include "ui/base/page_transition_types.h"
53 54
54 namespace content { 55 namespace content {
55 namespace { 56 namespace {
56 57
57 constexpr int kSizeMimeSnifferRequiresForFirstOnWillRead = 2048; 58 constexpr int kSizeMimeSnifferRequiresForFirstOnWillRead = 2048;
58 59
60 class FakeUploadDataStream : public net::UploadDataStream {
61 public:
62 FakeUploadDataStream(int64_t position, int64_t size)
63 : UploadDataStream(false, 0), position_(position), size_(size) {}
64
65 void set_position(int64_t position) { position_ = position; }
66 int InitInternal(const net::NetLogWithSource& net_log) override {
67 NOTREACHED();
68 return 0;
69 }
70 int ReadInternal(net::IOBuffer* buf, int buf_len) override {
71 NOTREACHED();
72 return 0;
73 }
74 void ResetInternal() override { NOTREACHED(); }
75
76 net::UploadProgress GetUploadProgress() const override {
77 return net::UploadProgress(position_, size_);
78 }
79
80 private:
81 int64_t position_;
82 int64_t size_;
83
84 DISALLOW_COPY_AND_ASSIGN(FakeUploadDataStream);
85 };
86
59 class TestResourceDispatcherHostDelegate final 87 class TestResourceDispatcherHostDelegate final
60 : public ResourceDispatcherHostDelegate { 88 : public ResourceDispatcherHostDelegate {
61 public: 89 public:
62 TestResourceDispatcherHostDelegate() = default; 90 TestResourceDispatcherHostDelegate() = default;
63 ~TestResourceDispatcherHostDelegate() override { 91 ~TestResourceDispatcherHostDelegate() override {
64 EXPECT_EQ(num_on_response_started_calls_expectation_, 92 EXPECT_EQ(num_on_response_started_calls_expectation_,
65 num_on_response_started_calls_); 93 num_on_response_started_calls_);
66 } 94 }
67 95
68 bool ShouldBeginRequest(const std::string& method, 96 bool ShouldBeginRequest(const std::string& method,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); 299 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory);
272 }; 300 };
273 301
274 class MojoAsyncResourceHandlerTestBase { 302 class MojoAsyncResourceHandlerTestBase {
275 public: 303 public:
276 MojoAsyncResourceHandlerTestBase() 304 MojoAsyncResourceHandlerTestBase()
277 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 305 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
278 browser_context_(new TestBrowserContext()) { 306 browser_context_(new TestBrowserContext()) {
279 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024); 307 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024);
280 rdh_.SetDelegate(&rdh_delegate_); 308 rdh_.SetDelegate(&rdh_delegate_);
309 }
281 310
311 void SetUpRequest() { SetUpRequestWithUpload(nullptr); }
312
313 void SetUpRequestWithUpload(
314 std::unique_ptr<net::UploadDataStream> upload_stream) {
282 // Create and initialize |request_|. None of this matters, for these tests, 315 // Create and initialize |request_|. None of this matters, for these tests,
283 // just need something non-NULL. 316 // just need something non-NULL.
284 net::URLRequestContext* request_context = 317 net::URLRequestContext* request_context =
285 browser_context_->GetResourceContext()->GetRequestContext(); 318 browser_context_->GetResourceContext()->GetRequestContext();
286 request_ = request_context->CreateRequest( 319 request_ = request_context->CreateRequest(
287 GURL("http://foo/"), net::DEFAULT_PRIORITY, &url_request_delegate_); 320 GURL("http://foo/"), net::DEFAULT_PRIORITY, &url_request_delegate_);
321 request_->set_upload(std::move(upload_stream));
288 ResourceRequestInfo::AllocateForTesting( 322 ResourceRequestInfo::AllocateForTesting(
289 request_.get(), // request 323 request_.get(), // request
290 RESOURCE_TYPE_XHR, // resource_type 324 RESOURCE_TYPE_XHR, // resource_type
291 browser_context_->GetResourceContext(), // context 325 browser_context_->GetResourceContext(), // context
292 2, // render_process_id 326 2, // render_process_id
293 0, // render_view_id 327 0, // render_view_id
294 0, // render_frame_id 328 0, // render_frame_id
295 true, // is_main_frame 329 true, // is_main_frame
296 false, // parent_is_main_frame 330 false, // parent_is_main_frame
297 false, // allow_download 331 false, // allow_download
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 class MojoAsyncResourceHandlerWithAllocationSizeTest 409 class MojoAsyncResourceHandlerWithAllocationSizeTest
376 : public MojoAsyncResourceHandlerTestBase, 410 : public MojoAsyncResourceHandlerTestBase,
377 public ::testing::TestWithParam<size_t> { 411 public ::testing::TestWithParam<size_t> {
378 protected: 412 protected:
379 MojoAsyncResourceHandlerWithAllocationSizeTest() { 413 MojoAsyncResourceHandlerWithAllocationSizeTest() {
380 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); 414 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam());
381 } 415 }
382 }; 416 };
383 417
384 TEST_F(MojoAsyncResourceHandlerTest, InFlightRequests) { 418 TEST_F(MojoAsyncResourceHandlerTest, InFlightRequests) {
419 SetUpRequest();
mmenke 2017/01/18 17:00:46 Can we do this in the constructor instead, and mak
tzik 2017/01/19 11:53:09 Done.
385 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 420 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
386 handler_ = nullptr; 421 handler_ = nullptr;
387 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 422 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
388 } 423 }
389 424
390 TEST_F(MojoAsyncResourceHandlerTest, OnWillStart) { 425 TEST_F(MojoAsyncResourceHandlerTest, OnWillStart) {
426 SetUpRequest();
391 EXPECT_EQ(MockResourceLoader::Status::IDLE, 427 EXPECT_EQ(MockResourceLoader::Status::IDLE,
392 mock_loader_->OnWillStart(request_->url())); 428 mock_loader_->OnWillStart(request_->url()));
393 } 429 }
394 430
395 TEST_F(MojoAsyncResourceHandlerTest, OnResponseStarted) { 431 TEST_F(MojoAsyncResourceHandlerTest, OnResponseStarted) {
432 SetUpRequest();
396 rdh_delegate_.set_num_on_response_started_calls_expectation(1); 433 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
397 scoped_refptr<net::IOBufferWithSize> metadata = new net::IOBufferWithSize(5); 434 scoped_refptr<net::IOBufferWithSize> metadata = new net::IOBufferWithSize(5);
398 memcpy(metadata->data(), "hello", 5); 435 memcpy(metadata->data(), "hello", 5);
399 handler_->SetMetadata(metadata); 436 handler_->SetMetadata(metadata);
400 437
401 ASSERT_EQ(MockResourceLoader::Status::IDLE, 438 ASSERT_EQ(MockResourceLoader::Status::IDLE,
402 mock_loader_->OnWillStart(request_->url())); 439 mock_loader_->OnWillStart(request_->url()));
403 440
404 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 441 scoped_refptr<ResourceResponse> response = new ResourceResponse();
405 response->head.content_length = 99; 442 response->head.content_length = 99;
(...skipping 18 matching lines...) Expand all
424 url_loader_client_.response_head().request_start); 461 url_loader_client_.response_head().request_start);
425 EXPECT_EQ(response->head.response_start, 462 EXPECT_EQ(response->head.response_start,
426 url_loader_client_.response_head().response_start); 463 url_loader_client_.response_head().response_start);
427 EXPECT_EQ(99, url_loader_client_.response_head().content_length); 464 EXPECT_EQ(99, url_loader_client_.response_head().content_length);
428 465
429 url_loader_client_.RunUntilCachedMetadataReceived(); 466 url_loader_client_.RunUntilCachedMetadataReceived();
430 EXPECT_EQ("hello", url_loader_client_.cached_metadata()); 467 EXPECT_EQ("hello", url_loader_client_.cached_metadata());
431 } 468 }
432 469
433 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) { 470 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) {
471 SetUpRequest();
434 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 472 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
435 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 473 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
436 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 474 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
437 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); 475 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing());
438 handler_ = nullptr; 476 handler_ = nullptr;
439 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 477 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
440 } 478 }
441 479
442 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadWithInsufficientResource) { 480 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadWithInsufficientResource) {
481 SetUpRequest();
443 rdh_.set_max_num_in_flight_requests_per_process(0); 482 rdh_.set_max_num_in_flight_requests_per_process(0);
444 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 483 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
445 484
446 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1)); 485 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1));
447 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code()); 486 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code());
448 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); 487 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing());
449 handler_ = nullptr; 488 handler_ = nullptr;
450 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 489 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
451 } 490 }
452 491
453 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndOnReadCompleted) { 492 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndOnReadCompleted) {
493 SetUpRequest();
454 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 494 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
455 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 495 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
456 // The buffer size that the mime sniffer requires implicitly. 496 // The buffer size that the mime sniffer requires implicitly.
457 ASSERT_GE(mock_loader_->io_buffer_size(), 497 ASSERT_GE(mock_loader_->io_buffer_size(),
458 kSizeMimeSnifferRequiresForFirstOnWillRead); 498 kSizeMimeSnifferRequiresForFirstOnWillRead);
459 499
460 url_loader_client_.RunUntilResponseBodyArrived(); 500 url_loader_client_.RunUntilResponseBodyArrived();
461 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 501 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
462 502
463 ASSERT_EQ(MockResourceLoader::Status::IDLE, 503 ASSERT_EQ(MockResourceLoader::Status::IDLE,
(...skipping 10 matching lines...) Expand all
474 base::RunLoop().RunUntilIdle(); 514 base::RunLoop().RunUntilIdle();
475 continue; 515 continue;
476 } 516 }
477 contents.append(buffer, read_size); 517 contents.append(buffer, read_size);
478 } 518 }
479 EXPECT_EQ("AB", contents); 519 EXPECT_EQ("AB", contents);
480 } 520 }
481 521
482 TEST_F(MojoAsyncResourceHandlerTest, 522 TEST_F(MojoAsyncResourceHandlerTest,
483 OnWillReadAndOnReadCompletedWithInsufficientInitialCapacity) { 523 OnWillReadAndOnReadCompletedWithInsufficientInitialCapacity) {
524 SetUpRequest();
484 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); 525 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2);
485 526
486 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 527 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
487 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 528 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
488 // The buffer size that the mime sniffer requires implicitly. 529 // The buffer size that the mime sniffer requires implicitly.
489 ASSERT_GE(mock_loader_->io_buffer_size(), 530 ASSERT_GE(mock_loader_->io_buffer_size(),
490 kSizeMimeSnifferRequiresForFirstOnWillRead); 531 kSizeMimeSnifferRequiresForFirstOnWillRead);
491 532
492 url_loader_client_.RunUntilResponseBodyArrived(); 533 url_loader_client_.RunUntilResponseBodyArrived();
493 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 534 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
(...skipping 16 matching lines...) Expand all
510 ASSERT_EQ(MOJO_RESULT_OK, result); 551 ASSERT_EQ(MOJO_RESULT_OK, result);
511 contents.append(buffer, read_size); 552 contents.append(buffer, read_size);
512 } 553 }
513 EXPECT_EQ(data, contents); 554 EXPECT_EQ(data, contents);
514 EXPECT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, 555 EXPECT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
515 mock_loader_->status()); 556 mock_loader_->status());
516 } 557 }
517 558
518 TEST_F(MojoAsyncResourceHandlerTest, 559 TEST_F(MojoAsyncResourceHandlerTest,
519 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) { 560 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) {
561 SetUpRequest();
520 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 562 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
521 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 563 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
522 // The io_buffer size that the mime sniffer requires implicitly. 564 // The io_buffer size that the mime sniffer requires implicitly.
523 ASSERT_GE(mock_loader_->io_buffer_size(), 565 ASSERT_GE(mock_loader_->io_buffer_size(),
524 kSizeMimeSnifferRequiresForFirstOnWillRead); 566 kSizeMimeSnifferRequiresForFirstOnWillRead);
525 567
526 handler_ = nullptr; 568 handler_ = nullptr;
527 url_loader_client_.Unbind(); 569 url_loader_client_.Unbind();
528 base::RunLoop().RunUntilIdle(); 570 base::RunLoop().RunUntilIdle();
529 571
530 // Hopefully ASAN checks this operation's validity. 572 // Hopefully ASAN checks this operation's validity.
531 mock_loader_->io_buffer()->data()[0] = 'A'; 573 mock_loader_->io_buffer()->data()[0] = 'A';
532 } 574 }
533 575
534 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompleted) { 576 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompleted) {
577 SetUpRequest();
535 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 578 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
536 579
537 ResourceRequestInfoImpl::ForRequest(request_.get()) 580 ResourceRequestInfoImpl::ForRequest(request_.get())
538 ->set_was_ignored_by_handler(false); 581 ->set_was_ignored_by_handler(false);
539 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, net::OK); 582 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, net::OK);
540 583
541 base::TimeTicks now1 = base::TimeTicks::Now(); 584 base::TimeTicks now1 = base::TimeTicks::Now();
542 ASSERT_EQ(MockResourceLoader::Status::IDLE, 585 ASSERT_EQ(MockResourceLoader::Status::IDLE,
543 mock_loader_->OnResponseCompleted(status)); 586 mock_loader_->OnResponseCompleted(status));
544 base::TimeTicks now2 = base::TimeTicks::Now(); 587 base::TimeTicks now2 = base::TimeTicks::Now();
545 588
546 url_loader_client_.RunUntilComplete(); 589 url_loader_client_.RunUntilComplete();
547 EXPECT_TRUE(url_loader_client_.has_received_completion()); 590 EXPECT_TRUE(url_loader_client_.has_received_completion());
548 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code); 591 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code);
549 EXPECT_FALSE(url_loader_client_.completion_status().was_ignored_by_handler); 592 EXPECT_FALSE(url_loader_client_.completion_status().was_ignored_by_handler);
550 EXPECT_LE(now1, url_loader_client_.completion_status().completion_time); 593 EXPECT_LE(now1, url_loader_client_.completion_status().completion_time);
551 EXPECT_LE(url_loader_client_.completion_status().completion_time, now2); 594 EXPECT_LE(url_loader_client_.completion_status().completion_time, now2);
552 EXPECT_EQ(request_->GetTotalReceivedBytes(), 595 EXPECT_EQ(request_->GetTotalReceivedBytes(),
553 url_loader_client_.completion_status().encoded_data_length); 596 url_loader_client_.completion_status().encoded_data_length);
mmenke 2017/01/18 17:00:46 Should we test somewhere for the non-upload cases
tzik 2017/01/19 11:53:09 Done.
554 } 597 }
555 598
556 // This test case sets different status values from OnResponseCompleted. 599 // This test case sets different status values from OnResponseCompleted.
557 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompleted2) { 600 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompleted2) {
601 SetUpRequest();
558 rdh_.SetDelegate(nullptr); 602 rdh_.SetDelegate(nullptr);
559 // Don't use CallOnWillStartAndOnResponseStarted as this test case manually 603 // Don't use CallOnWillStartAndOnResponseStarted as this test case manually
560 // sets the null delegate. 604 // sets the null delegate.
561 ASSERT_EQ(MockResourceLoader::Status::IDLE, 605 ASSERT_EQ(MockResourceLoader::Status::IDLE,
562 mock_loader_->OnWillStart(request_->url())); 606 mock_loader_->OnWillStart(request_->url()));
563 ASSERT_EQ(MockResourceLoader::Status::IDLE, 607 ASSERT_EQ(MockResourceLoader::Status::IDLE,
564 mock_loader_->OnResponseStarted( 608 mock_loader_->OnResponseStarted(
565 make_scoped_refptr(new ResourceResponse()))); 609 make_scoped_refptr(new ResourceResponse())));
566 ASSERT_FALSE(url_loader_client_.has_received_response()); 610 ASSERT_FALSE(url_loader_client_.has_received_response());
567 url_loader_client_.RunUntilResponseReceived(); 611 url_loader_client_.RunUntilResponseReceived();
(...skipping 13 matching lines...) Expand all
581 EXPECT_EQ(net::ERR_ABORTED, 625 EXPECT_EQ(net::ERR_ABORTED,
582 url_loader_client_.completion_status().error_code); 626 url_loader_client_.completion_status().error_code);
583 EXPECT_TRUE(url_loader_client_.completion_status().was_ignored_by_handler); 627 EXPECT_TRUE(url_loader_client_.completion_status().was_ignored_by_handler);
584 EXPECT_LE(now1, url_loader_client_.completion_status().completion_time); 628 EXPECT_LE(now1, url_loader_client_.completion_status().completion_time);
585 EXPECT_LE(url_loader_client_.completion_status().completion_time, now2); 629 EXPECT_LE(url_loader_client_.completion_status().completion_time, now2);
586 EXPECT_EQ(request_->GetTotalReceivedBytes(), 630 EXPECT_EQ(request_->GetTotalReceivedBytes(),
587 url_loader_client_.completion_status().encoded_data_length); 631 url_loader_client_.completion_status().encoded_data_length);
588 } 632 }
589 633
590 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompletedWithCanceledTimedOut) { 634 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompletedWithCanceledTimedOut) {
635 SetUpRequest();
591 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, 636 net::URLRequestStatus status(net::URLRequestStatus::CANCELED,
592 net::ERR_TIMED_OUT); 637 net::ERR_TIMED_OUT);
593 638
594 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 639 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
595 ASSERT_EQ(MockResourceLoader::Status::IDLE, 640 ASSERT_EQ(MockResourceLoader::Status::IDLE,
596 mock_loader_->OnResponseCompleted(status)); 641 mock_loader_->OnResponseCompleted(status));
597 642
598 url_loader_client_.RunUntilComplete(); 643 url_loader_client_.RunUntilComplete();
599 EXPECT_TRUE(url_loader_client_.has_received_completion()); 644 EXPECT_TRUE(url_loader_client_.has_received_completion());
600 EXPECT_EQ(net::ERR_TIMED_OUT, 645 EXPECT_EQ(net::ERR_TIMED_OUT,
601 url_loader_client_.completion_status().error_code); 646 url_loader_client_.completion_status().error_code);
602 } 647 }
603 648
604 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompletedWithFailedTimedOut) { 649 TEST_F(MojoAsyncResourceHandlerTest, OnResponseCompletedWithFailedTimedOut) {
650 SetUpRequest();
605 net::URLRequestStatus status(net::URLRequestStatus::FAILED, 651 net::URLRequestStatus status(net::URLRequestStatus::FAILED,
606 net::ERR_TIMED_OUT); 652 net::ERR_TIMED_OUT);
607 653
608 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 654 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
609 ASSERT_EQ(MockResourceLoader::Status::IDLE, 655 ASSERT_EQ(MockResourceLoader::Status::IDLE,
610 mock_loader_->OnResponseCompleted(status)); 656 mock_loader_->OnResponseCompleted(status));
611 657
612 url_loader_client_.RunUntilComplete(); 658 url_loader_client_.RunUntilComplete();
613 EXPECT_TRUE(url_loader_client_.has_received_completion()); 659 EXPECT_TRUE(url_loader_client_.has_received_completion());
614 EXPECT_EQ(net::ERR_TIMED_OUT, 660 EXPECT_EQ(net::ERR_TIMED_OUT,
615 url_loader_client_.completion_status().error_code); 661 url_loader_client_.completion_status().error_code);
616 } 662 }
617 663
618 TEST_F(MojoAsyncResourceHandlerTest, ResponseCompletionShouldCloseDataPipe) { 664 TEST_F(MojoAsyncResourceHandlerTest, ResponseCompletionShouldCloseDataPipe) {
665 SetUpRequest();
619 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 666 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
620 667
621 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 668 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
622 url_loader_client_.RunUntilResponseBodyArrived(); 669 url_loader_client_.RunUntilResponseBodyArrived();
623 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 670 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
624 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); 671 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0));
625 672
626 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, net::OK); 673 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, net::OK);
627 ASSERT_EQ(MockResourceLoader::Status::IDLE, 674 ASSERT_EQ(MockResourceLoader::Status::IDLE,
628 mock_loader_->OnResponseCompleted(status)); 675 mock_loader_->OnResponseCompleted(status));
629 676
630 url_loader_client_.RunUntilComplete(); 677 url_loader_client_.RunUntilComplete();
631 EXPECT_TRUE(url_loader_client_.has_received_completion()); 678 EXPECT_TRUE(url_loader_client_.has_received_completion());
632 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code); 679 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code);
633 680
634 while (true) { 681 while (true) {
635 char buffer[16]; 682 char buffer[16];
636 uint32_t read_size = sizeof(buffer); 683 uint32_t read_size = sizeof(buffer);
637 MojoResult result = 684 MojoResult result =
638 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer, 685 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer,
639 &read_size, MOJO_READ_DATA_FLAG_NONE); 686 &read_size, MOJO_READ_DATA_FLAG_NONE);
640 if (result == MOJO_RESULT_FAILED_PRECONDITION) 687 if (result == MOJO_RESULT_FAILED_PRECONDITION)
641 break; 688 break;
642 ASSERT_EQ(result, MOJO_RESULT_SHOULD_WAIT); 689 ASSERT_EQ(result, MOJO_RESULT_SHOULD_WAIT);
643 } 690 }
644 } 691 }
645 692
646 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) { 693 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) {
694 SetUpRequest();
647 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 695 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
648 696
649 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 697 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
650 url_loader_client_.RunUntilResponseBodyArrived(); 698 url_loader_client_.RunUntilResponseBodyArrived();
651 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 699 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
652 std::string data(mock_loader_->io_buffer_size(), 'a'); 700 std::string data(mock_loader_->io_buffer_size(), 'a');
653 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, 701 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
654 mock_loader_->OnReadCompleted(data)); 702 mock_loader_->OnReadCompleted(data));
655 703
656 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); 704 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED);
(...skipping 19 matching lines...) Expand all
676 continue; 724 continue;
677 } 725 }
678 EXPECT_EQ(MOJO_RESULT_OK, result); 726 EXPECT_EQ(MOJO_RESULT_OK, result);
679 actual.append(buf, read_size); 727 actual.append(buf, read_size);
680 } 728 }
681 EXPECT_EQ(data, actual); 729 EXPECT_EQ(data, actual);
682 } 730 }
683 731
684 // In this case, an error is notified after OnWillRead, before OnReadCompleted. 732 // In this case, an error is notified after OnWillRead, before OnReadCompleted.
685 TEST_F(MojoAsyncResourceHandlerTest, ResponseErrorDuringBodyTransmission2) { 733 TEST_F(MojoAsyncResourceHandlerTest, ResponseErrorDuringBodyTransmission2) {
734 SetUpRequest();
686 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 735 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
687 736
688 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 737 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
689 url_loader_client_.RunUntilResponseBodyArrived(); 738 url_loader_client_.RunUntilResponseBodyArrived();
690 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 739 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
691 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); 740 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED);
692 ASSERT_EQ(MockResourceLoader::Status::IDLE, 741 ASSERT_EQ(MockResourceLoader::Status::IDLE,
693 mock_loader_->OnResponseCompleted(status)); 742 mock_loader_->OnResponseCompleted(status));
694 743
695 url_loader_client_.RunUntilComplete(); 744 url_loader_client_.RunUntilComplete();
696 EXPECT_TRUE(url_loader_client_.has_received_completion()); 745 EXPECT_TRUE(url_loader_client_.has_received_completion());
697 EXPECT_EQ(net::ERR_FAILED, url_loader_client_.completion_status().error_code); 746 EXPECT_EQ(net::ERR_FAILED, url_loader_client_.completion_status().error_code);
698 747
699 while (true) { 748 while (true) {
700 char buf[16]; 749 char buf[16];
701 uint32_t read_size = sizeof(buf); 750 uint32_t read_size = sizeof(buf);
702 MojoResult result = 751 MojoResult result =
703 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, 752 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size,
704 MOJO_READ_DATA_FLAG_NONE); 753 MOJO_READ_DATA_FLAG_NONE);
705 if (result == MOJO_RESULT_FAILED_PRECONDITION) 754 if (result == MOJO_RESULT_FAILED_PRECONDITION)
706 break; 755 break;
707 ASSERT_EQ(MOJO_RESULT_SHOULD_WAIT, result); 756 ASSERT_EQ(MOJO_RESULT_SHOULD_WAIT, result);
708 base::RunLoop().RunUntilIdle(); 757 base::RunLoop().RunUntilIdle();
709 } 758 }
710 } 759 }
711 760
712 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) { 761 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) {
762 SetUpRequest();
713 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); 763 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN);
714 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 764 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
715 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1)); 765 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1));
716 } 766 }
717 767
718 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) { 768 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) {
769 SetUpRequest();
719 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); 770 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT);
720 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 771 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
721 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 772 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
722 } 773 }
723 774
724 TEST_F(MojoAsyncResourceHandlerTest, 775 TEST_F(MojoAsyncResourceHandlerTest,
725 BeginWriteReturnsShouldWaitOnWillReadAndThenReturnsOK) { 776 BeginWriteReturnsShouldWaitOnWillReadAndThenReturnsOK) {
777 SetUpRequest();
726 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); 778 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT);
727 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 779 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
728 size_t written = 0; 780 size_t written = 0;
729 while (true) { 781 while (true) {
730 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 782 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
731 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( 783 MockResourceLoader::Status result = mock_loader_->OnReadCompleted(
732 std::string(mock_loader_->io_buffer_size(), 'X')); 784 std::string(mock_loader_->io_buffer_size(), 'X'));
733 written += mock_loader_->io_buffer_size(); 785 written += mock_loader_->io_buffer_size();
734 if (result == MockResourceLoader::Status::CALLBACK_PENDING) 786 if (result == MockResourceLoader::Status::CALLBACK_PENDING)
735 break; 787 break;
(...skipping 17 matching lines...) Expand all
753 actual.append(buf, read_size); 805 actual.append(buf, read_size);
754 base::RunLoop().RunUntilIdle(); 806 base::RunLoop().RunUntilIdle();
755 } 807 }
756 808
757 EXPECT_EQ(std::string(written, 'X'), actual); 809 EXPECT_EQ(std::string(written, 'X'), actual);
758 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); 810 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status());
759 } 811 }
760 812
761 TEST_F(MojoAsyncResourceHandlerTest, 813 TEST_F(MojoAsyncResourceHandlerTest,
762 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) { 814 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) {
815 SetUpRequest();
763 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); 816 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2);
764 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 817 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
765 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN); 818 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN);
766 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1)); 819 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead(-1));
767 } 820 }
768 821
769 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) { 822 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) {
823 SetUpRequest();
770 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 824 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
771 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 825 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
772 826
773 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); 827 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT);
774 ASSERT_EQ(MockResourceLoader::Status::CANCELED, 828 ASSERT_EQ(MockResourceLoader::Status::CANCELED,
775 mock_loader_->OnReadCompleted( 829 mock_loader_->OnReadCompleted(
776 std::string(mock_loader_->io_buffer_size(), 'w'))); 830 std::string(mock_loader_->io_buffer_size(), 'w')));
777 } 831 }
778 832
779 TEST_F(MojoAsyncResourceHandlerTest, 833 TEST_F(MojoAsyncResourceHandlerTest,
780 EndWriteFailsOnReadCompletedWithInsufficientInitialCapacity) { 834 EndWriteFailsOnReadCompletedWithInsufficientInitialCapacity) {
835 SetUpRequest();
781 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); 836 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2);
782 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 837 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
783 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 838 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
784 839
785 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); 840 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT);
786 ASSERT_EQ(MockResourceLoader::Status::CANCELED, 841 ASSERT_EQ(MockResourceLoader::Status::CANCELED,
787 mock_loader_->OnReadCompleted( 842 mock_loader_->OnReadCompleted(
788 std::string(mock_loader_->io_buffer_size(), 'w'))); 843 std::string(mock_loader_->io_buffer_size(), 'w')));
789 } 844 }
790 845
791 TEST_F(MojoAsyncResourceHandlerTest, 846 TEST_F(MojoAsyncResourceHandlerTest,
792 EndWriteFailsOnResumeWithInsufficientInitialCapacity) { 847 EndWriteFailsOnResumeWithInsufficientInitialCapacity) {
848 SetUpRequest();
793 MojoAsyncResourceHandler::SetAllocationSizeForTesting(8); 849 MojoAsyncResourceHandler::SetAllocationSizeForTesting(8);
794 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 850 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
795 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 851 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
796 url_loader_client_.RunUntilResponseBodyArrived(); 852 url_loader_client_.RunUntilResponseBodyArrived();
797 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 853 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
798 854
799 while (true) { 855 while (true) {
800 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( 856 MockResourceLoader::Status result = mock_loader_->OnReadCompleted(
801 std::string(mock_loader_->io_buffer_size(), 'A')); 857 std::string(mock_loader_->io_buffer_size(), 'A'));
802 if (result == MockResourceLoader::Status::CALLBACK_PENDING) 858 if (result == MockResourceLoader::Status::CALLBACK_PENDING)
(...skipping 14 matching lines...) Expand all
817 ASSERT_EQ(MOJO_RESULT_OK, result); 873 ASSERT_EQ(MOJO_RESULT_OK, result);
818 } 874 }
819 875
820 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); 876 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT);
821 mock_loader_->WaitUntilIdleOrCanceled(); 877 mock_loader_->WaitUntilIdleOrCanceled();
822 EXPECT_FALSE(url_loader_client_.has_received_completion()); 878 EXPECT_FALSE(url_loader_client_.has_received_completion());
823 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); 879 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status());
824 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); 880 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code());
825 } 881 }
826 882
883 TEST_F(MojoAsyncResourceHandlerTest, UploadProgressHandling) {
884 net::URLRequestMockDataJob::AddUrlHandlerForHostname("foo");
885 FakeUploadDataStream* upload = new FakeUploadDataStream(0, 1000);
886 SetUpRequestWithUpload(base::WrapUnique(upload));
887 request_->Start();
888
889 net::UploadProgress progress = request_->GetUploadProgress();
890 EXPECT_EQ(0u, progress.position());
891 EXPECT_EQ(1000u, progress.size());
892
893 EXPECT_EQ(0, url_loader_client_.current_upload_position());
894 EXPECT_EQ(0, url_loader_client_.total_upload_size());
895
896 upload->set_position(1000);
897 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
mmenke 2017/01/18 17:00:46 So there are three paths to update the status, so
tzik 2017/01/19 11:53:09 Done.
898 base::RunLoop().RunUntilIdle();
899
900 EXPECT_EQ(1000, url_loader_client_.current_upload_position());
901 EXPECT_EQ(1000, url_loader_client_.total_upload_size());
902 }
903
827 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 904 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
828 OnWillReadWithLongContents) { 905 OnWillReadWithLongContents) {
906 SetUpRequest();
829 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 907 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
830 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 908 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
831 std::string expected; 909 std::string expected;
832 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) 910 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i)
833 expected += ('A' + i % 26); 911 expected += ('A' + i % 26);
834 912
835 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); 913 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0));
836 914
837 url_loader_client_.RunUntilResponseBodyArrived(); 915 url_loader_client_.RunUntilResponseBodyArrived();
838 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 916 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
(...skipping 28 matching lines...) Expand all
867 945
868 // Give mojo a chance pass data back and forth, and to request more data 946 // Give mojo a chance pass data back and forth, and to request more data
869 // from the handler. 947 // from the handler.
870 base::RunLoop().RunUntilIdle(); 948 base::RunLoop().RunUntilIdle();
871 } 949 }
872 EXPECT_EQ(expected, actual); 950 EXPECT_EQ(expected, actual);
873 } 951 }
874 952
875 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 953 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
876 BeginWriteFailsOnReadCompleted) { 954 BeginWriteFailsOnReadCompleted) {
955 SetUpRequest();
877 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 956 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
878 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 957 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
879 958
880 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); 959 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN);
881 ASSERT_EQ(MockResourceLoader::Status::CANCELED, 960 ASSERT_EQ(MockResourceLoader::Status::CANCELED,
882 mock_loader_->OnReadCompleted( 961 mock_loader_->OnReadCompleted(
883 std::string(mock_loader_->io_buffer_size(), 'A'))); 962 std::string(mock_loader_->io_buffer_size(), 'A')));
884 } 963 }
885 964
886 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 965 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
887 BeginWriteReturnsShouldWaitOnReadCompleted) { 966 BeginWriteReturnsShouldWaitOnReadCompleted) {
967 SetUpRequest();
888 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 968 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
889 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 969 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
890 970
891 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); 971 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT);
892 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, 972 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
893 mock_loader_->OnReadCompleted( 973 mock_loader_->OnReadCompleted(
894 std::string(mock_loader_->io_buffer_size(), 'A'))); 974 std::string(mock_loader_->io_buffer_size(), 'A')));
895 } 975 }
896 976
897 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 977 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
898 BeginWriteFailsOnResume) { 978 BeginWriteFailsOnResume) {
979 SetUpRequest();
899 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 980 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
900 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 981 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
901 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); 982 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0));
902 url_loader_client_.RunUntilResponseBodyArrived(); 983 url_loader_client_.RunUntilResponseBodyArrived();
903 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 984 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
904 985
905 while (true) { 986 while (true) {
906 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 987 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
907 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( 988 MockResourceLoader::Status result = mock_loader_->OnReadCompleted(
908 std::string(mock_loader_->io_buffer_size(), 'A')); 989 std::string(mock_loader_->io_buffer_size(), 'A'));
(...skipping 11 matching lines...) Expand all
920 MOJO_READ_DATA_FLAG_NONE); 1001 MOJO_READ_DATA_FLAG_NONE);
921 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); 1002 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT);
922 base::RunLoop().RunUntilIdle(); 1003 base::RunLoop().RunUntilIdle();
923 } 1004 }
924 1005
925 EXPECT_FALSE(url_loader_client_.has_received_completion()); 1006 EXPECT_FALSE(url_loader_client_.has_received_completion());
926 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); 1007 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code());
927 } 1008 }
928 1009
929 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) { 1010 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) {
1011 SetUpRequest();
930 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 1012 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
931 1013
932 while (true) { 1014 while (true) {
933 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 1015 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
934 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( 1016 MockResourceLoader::Status result = mock_loader_->OnReadCompleted(
935 std::string(mock_loader_->io_buffer_size(), 'A')); 1017 std::string(mock_loader_->io_buffer_size(), 'A'));
936 if (result == MockResourceLoader::Status::CALLBACK_PENDING) 1018 if (result == MockResourceLoader::Status::CALLBACK_PENDING)
937 break; 1019 break;
938 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); 1020 ASSERT_EQ(MockResourceLoader::Status::IDLE, result);
939 } 1021 }
(...skipping 21 matching lines...) Expand all
961 if (result == MOJO_RESULT_FAILED_PRECONDITION) 1043 if (result == MOJO_RESULT_FAILED_PRECONDITION)
962 break; 1044 break;
963 base::RunLoop().RunUntilIdle(); 1045 base::RunLoop().RunUntilIdle();
964 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); 1046 DCHECK(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK);
965 } 1047 }
966 1048
967 base::RunLoop().RunUntilIdle(); 1049 base::RunLoop().RunUntilIdle();
968 } 1050 }
969 1051
970 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, RedirectHandling) { 1052 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, RedirectHandling) {
1053 SetUpRequest();
971 rdh_delegate_.set_num_on_response_started_calls_expectation(1); 1054 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
972 1055
973 ASSERT_EQ(MockResourceLoader::Status::IDLE, 1056 ASSERT_EQ(MockResourceLoader::Status::IDLE,
974 mock_loader_->OnWillStart(request_->url())); 1057 mock_loader_->OnWillStart(request_->url()));
975 1058
976 net::RedirectInfo redirect_info; 1059 net::RedirectInfo redirect_info;
977 redirect_info.status_code = 301; 1060 redirect_info.status_code = 301;
978 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, 1061 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
979 mock_loader_->OnRequestRedirected( 1062 mock_loader_->OnRequestRedirected(
980 redirect_info, make_scoped_refptr(new ResourceResponse()))); 1063 redirect_info, make_scoped_refptr(new ResourceResponse())));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1109
1027 ASSERT_TRUE(url_loader_client_.has_received_response()); 1110 ASSERT_TRUE(url_loader_client_.has_received_response());
1028 ASSERT_TRUE(url_loader_client_.has_received_completion()); 1111 ASSERT_TRUE(url_loader_client_.has_received_completion());
1029 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code); 1112 EXPECT_EQ(net::OK, url_loader_client_.completion_status().error_code);
1030 } 1113 }
1031 1114
1032 // Test the case where th other process tells the ResourceHandler to follow a 1115 // Test the case where th other process tells the ResourceHandler to follow a
1033 // redirect, despite the fact that no redirect has been received yet. 1116 // redirect, despite the fact that no redirect has been received yet.
1034 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 1117 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
1035 MalformedFollowRedirectRequest) { 1118 MalformedFollowRedirectRequest) {
1119 SetUpRequest();
1036 handler_->FollowRedirect(); 1120 handler_->FollowRedirect();
1037 1121
1038 EXPECT_TRUE(handler_->has_received_bad_message()); 1122 EXPECT_TRUE(handler_->has_received_bad_message());
1039 } 1123 }
1040 1124
1041 // Typically ResourceHandler methods are called in this order. 1125 // Typically ResourceHandler methods are called in this order.
1042 TEST_P( 1126 TEST_P(
1043 MojoAsyncResourceHandlerWithAllocationSizeTest, 1127 MojoAsyncResourceHandlerWithAllocationSizeTest,
1044 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo nseCompleted) { 1128 OnWillStartThenOnResponseStartedThenOnWillReadThenOnReadCompletedThenOnRespo nseCompleted) {
1129 SetUpRequest();
1045 rdh_delegate_.set_num_on_response_started_calls_expectation(1); 1130 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
1046 1131
1047 ASSERT_EQ(MockResourceLoader::Status::IDLE, 1132 ASSERT_EQ(MockResourceLoader::Status::IDLE,
1048 mock_loader_->OnWillStart(request_->url())); 1133 mock_loader_->OnWillStart(request_->url()));
1049 ASSERT_EQ(MockResourceLoader::Status::IDLE, 1134 ASSERT_EQ(MockResourceLoader::Status::IDLE,
1050 mock_loader_->OnResponseStarted( 1135 mock_loader_->OnResponseStarted(
1051 make_scoped_refptr(new ResourceResponse()))); 1136 make_scoped_refptr(new ResourceResponse())));
1052 1137
1053 ASSERT_FALSE(url_loader_client_.has_received_response()); 1138 ASSERT_FALSE(url_loader_client_.has_received_response());
1054 url_loader_client_.RunUntilResponseReceived(); 1139 url_loader_client_.RunUntilResponseReceived();
(...skipping 30 matching lines...) Expand all
1085 body.append(buffer, read_size); 1170 body.append(buffer, read_size);
1086 } 1171 }
1087 } 1172 }
1088 EXPECT_EQ("A", body); 1173 EXPECT_EQ("A", body);
1089 } 1174 }
1090 1175
1091 // MimeResourceHandler calls delegated ResourceHandler's methods in this order. 1176 // MimeResourceHandler calls delegated ResourceHandler's methods in this order.
1092 TEST_P( 1177 TEST_P(
1093 MojoAsyncResourceHandlerWithAllocationSizeTest, 1178 MojoAsyncResourceHandlerWithAllocationSizeTest,
1094 OnWillStartThenOnWillReadThenOnResponseStartedThenOnReadCompletedThenOnRespo nseCompleted) { 1179 OnWillStartThenOnWillReadThenOnResponseStartedThenOnReadCompletedThenOnRespo nseCompleted) {
1180 SetUpRequest();
1095 rdh_delegate_.set_num_on_response_started_calls_expectation(1); 1181 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
1096 1182
1097 ASSERT_EQ(MockResourceLoader::Status::IDLE, 1183 ASSERT_EQ(MockResourceLoader::Status::IDLE,
1098 mock_loader_->OnWillStart(request_->url())); 1184 mock_loader_->OnWillStart(request_->url()));
1099 1185
1100 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 1186 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
1101 1187
1102 ASSERT_FALSE(url_loader_client_.response_body().is_valid()); 1188 ASSERT_FALSE(url_loader_client_.response_body().is_valid());
1103 url_loader_client_.RunUntilResponseBodyArrived(); 1189 url_loader_client_.RunUntilResponseBodyArrived();
1104 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); 1190 ASSERT_TRUE(url_loader_client_.response_body().is_valid());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1223 }
1138 } 1224 }
1139 EXPECT_EQ("B", body); 1225 EXPECT_EQ("B", body);
1140 } 1226 }
1141 1227
1142 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 1228 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
1143 MojoAsyncResourceHandlerWithAllocationSizeTest, 1229 MojoAsyncResourceHandlerWithAllocationSizeTest,
1144 ::testing::Values(8, 32 * 2014)); 1230 ::testing::Values(8, 32 * 2014));
1145 } // namespace 1231 } // namespace
1146 } // namespace content 1232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698