| OLD | NEW |
| 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 uint32_t read_size = sizeof(buffer); | 578 uint32_t read_size = sizeof(buffer); |
| 579 MojoResult result = | 579 MojoResult result = |
| 580 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer, | 580 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer, |
| 581 &read_size, MOJO_READ_DATA_FLAG_NONE); | 581 &read_size, MOJO_READ_DATA_FLAG_NONE); |
| 582 if (result == MOJO_RESULT_SHOULD_WAIT) | 582 if (result == MOJO_RESULT_SHOULD_WAIT) |
| 583 continue; | 583 continue; |
| 584 ASSERT_EQ(MOJO_RESULT_OK, result); | 584 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 585 contents.append(buffer, read_size); | 585 contents.append(buffer, read_size); |
| 586 } | 586 } |
| 587 EXPECT_EQ(data, contents); | 587 EXPECT_EQ(data, contents); |
| 588 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); | 588 EXPECT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, |
| 589 mock_loader_->status()); |
| 589 } | 590 } |
| 590 | 591 |
| 591 TEST_F(MojoAsyncResourceHandlerTest, | 592 TEST_F(MojoAsyncResourceHandlerTest, |
| 592 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) { | 593 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) { |
| 593 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 594 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 594 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 595 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 595 // The io_buffer size that the mime sniffer requires implicitly. | 596 // The io_buffer size that the mime sniffer requires implicitly. |
| 596 ASSERT_GE(mock_loader_->io_buffer_size(), | 597 ASSERT_GE(mock_loader_->io_buffer_size(), |
| 597 kSizeMimeSnifferRequiresForFirstOnWillRead); | 598 kSizeMimeSnifferRequiresForFirstOnWillRead); |
| 598 | 599 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 break; | 716 break; |
| 716 ASSERT_TRUE(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); | 717 ASSERT_TRUE(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); |
| 717 } | 718 } |
| 718 } | 719 } |
| 719 | 720 |
| 720 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) { | 721 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) { |
| 721 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 722 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 722 | 723 |
| 723 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 724 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 724 std::string data(mock_loader_->io_buffer_size(), 'a'); | 725 std::string data(mock_loader_->io_buffer_size(), 'a'); |
| 725 ASSERT_EQ(MockResourceLoader::Status::IDLE, | 726 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, |
| 726 mock_loader_->OnReadCompleted(data)); | 727 mock_loader_->OnReadCompleted(data)); |
| 727 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | |
| 728 mock_loader_->OnWillRead()); | |
| 729 url_loader_client_.RunUntilResponseBodyArrived(); | 728 url_loader_client_.RunUntilResponseBodyArrived(); |
| 730 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 729 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 731 | 730 |
| 732 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); | 731 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); |
| 733 ASSERT_EQ( | 732 ASSERT_EQ( |
| 734 MockResourceLoader::Status::IDLE, | 733 MockResourceLoader::Status::IDLE, |
| 735 mock_loader_->OnResponseCompletedFromExternalOutOfBandCancel(status)); | 734 mock_loader_->OnResponseCompletedFromExternalOutOfBandCancel(status)); |
| 736 | 735 |
| 737 url_loader_client_.RunUntilComplete(); | 736 url_loader_client_.RunUntilComplete(); |
| 738 EXPECT_TRUE(url_loader_client_.has_received_completion()); | 737 EXPECT_TRUE(url_loader_client_.has_received_completion()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 758 } | 757 } |
| 759 | 758 |
| 760 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) { | 759 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) { |
| 761 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 760 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 762 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 761 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 763 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | 762 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 764 } | 763 } |
| 765 | 764 |
| 766 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) { | 765 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) { |
| 767 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 766 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 768 | |
| 769 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 767 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 770 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); | 768 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 771 | |
| 772 // Bytes are read one-at-a-time, and each OnWillRead() call completes | |
| 773 // asynchronously. Note that this loop runs 4 times (once for the terminal | |
| 774 // '\0'). | |
| 775 const char kReadData[] = "ABC"; | |
| 776 for (const char read_char : kReadData) { | |
| 777 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | |
| 778 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | |
| 779 mock_loader_->OnWillRead()); | |
| 780 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); | |
| 781 | |
| 782 handler_->ResetBeginWriteExpectation(); | |
| 783 handler_->OnWritableForTesting(); | |
| 784 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); | |
| 785 | |
| 786 ASSERT_EQ(MockResourceLoader::Status::IDLE, | |
| 787 mock_loader_->OnReadCompleted(std::string(1, read_char))); | |
| 788 url_loader_client_.RunUntilResponseBodyArrived(); | |
| 789 | |
| 790 // Keep on trying to read the data until it succeeds. | |
| 791 while (true) { | |
| 792 char buffer[16]; | |
| 793 uint32_t read_size = sizeof(buffer); | |
| 794 MojoResult result = | |
| 795 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer, | |
| 796 &read_size, MOJO_READ_DATA_FLAG_NONE); | |
| 797 if (result != MOJO_RESULT_SHOULD_WAIT) { | |
| 798 ASSERT_EQ(MOJO_RESULT_OK, result); | |
| 799 ASSERT_EQ(1u, read_size); | |
| 800 EXPECT_EQ(read_char, buffer[0]); | |
| 801 break; | |
| 802 } | |
| 803 | |
| 804 base::RunLoop().RunUntilIdle(); | |
| 805 } | |
| 806 } | |
| 807 | |
| 808 // Should only count as one in-flight request. | |
| 809 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); | |
| 810 | |
| 811 ASSERT_EQ(MockResourceLoader::Status::IDLE, | |
| 812 mock_loader_->OnResponseCompleted( | |
| 813 net::URLRequestStatus::FromError(net::OK))); | |
| 814 | |
| 815 url_loader_client_.RunUntilComplete(); | |
| 816 EXPECT_TRUE(url_loader_client_.has_received_completion()); | |
| 817 | |
| 818 handler_.reset(); | |
| 819 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); | |
| 820 } | |
| 821 | |
| 822 // Same as above, but after the first OnWriteable() call, BeginWrite() indicates | |
| 823 // should wait again. Unclear if this can happen in practice, but seems best to | |
| 824 // support it. | |
| 825 TEST_F(MojoAsyncResourceHandlerTest, | |
| 826 BeginWriteReturnsShouldWaitTwiceOnWillRead) { | |
| 827 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | |
| 828 | |
| 829 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | |
| 830 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); | |
| 831 | |
| 832 // Bytes are read one-at-a-time, and each OnWillRead() call completes | |
| 833 // asynchronously. Note that this loop runs 4 times (once for the terminal | |
| 834 // '\0'). | |
| 835 const char kReadData[] = "ABC"; | |
| 836 for (const char read_char : kReadData) { | |
| 837 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | |
| 838 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | |
| 839 mock_loader_->OnWillRead()); | |
| 840 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); | |
| 841 | |
| 842 handler_->OnWritableForTesting(); | |
| 843 EXPECT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | |
| 844 mock_loader_->status()); | |
| 845 | |
| 846 handler_->ResetBeginWriteExpectation(); | |
| 847 handler_->OnWritableForTesting(); | |
| 848 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); | |
| 849 | |
| 850 ASSERT_EQ(MockResourceLoader::Status::IDLE, | |
| 851 mock_loader_->OnReadCompleted(std::string(1, read_char))); | |
| 852 url_loader_client_.RunUntilResponseBodyArrived(); | |
| 853 | |
| 854 // Keep on trying to read the data until it succeeds. | |
| 855 while (true) { | |
| 856 char buffer[16]; | |
| 857 uint32_t read_size = sizeof(buffer); | |
| 858 MojoResult result = | |
| 859 mojo::ReadDataRaw(url_loader_client_.response_body(), buffer, | |
| 860 &read_size, MOJO_READ_DATA_FLAG_NONE); | |
| 861 if (result != MOJO_RESULT_SHOULD_WAIT) { | |
| 862 ASSERT_EQ(MOJO_RESULT_OK, result); | |
| 863 ASSERT_EQ(1u, read_size); | |
| 864 EXPECT_EQ(read_char, buffer[0]); | |
| 865 break; | |
| 866 } | |
| 867 | |
| 868 base::RunLoop().RunUntilIdle(); | |
| 869 } | |
| 870 } | |
| 871 | |
| 872 // Should only count as one in-flight request. | |
| 873 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); | |
| 874 | |
| 875 ASSERT_EQ(MockResourceLoader::Status::IDLE, | |
| 876 mock_loader_->OnResponseCompleted( | |
| 877 net::URLRequestStatus::FromError(net::OK))); | |
| 878 | |
| 879 url_loader_client_.RunUntilComplete(); | |
| 880 EXPECT_TRUE(url_loader_client_.has_received_completion()); | |
| 881 | |
| 882 handler_.reset(); | |
| 883 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); | |
| 884 } | 769 } |
| 885 | 770 |
| 886 TEST_F(MojoAsyncResourceHandlerTest, | 771 TEST_F(MojoAsyncResourceHandlerTest, |
| 772 BeginWriteReturnsShouldWaitOnWillReadAndThenReturnsOK) { |
| 773 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 774 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 775 size_t written = 0; |
| 776 while (true) { |
| 777 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 778 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( |
| 779 std::string(mock_loader_->io_buffer_size(), 'X')); |
| 780 written += mock_loader_->io_buffer_size(); |
| 781 if (result == MockResourceLoader::Status::CALLBACK_PENDING) |
| 782 break; |
| 783 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 784 } |
| 785 |
| 786 url_loader_client_.RunUntilResponseBodyArrived(); |
| 787 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 788 handler_->ResetBeginWriteExpectation(); |
| 789 handler_->OnWritableForTesting(); |
| 790 |
| 791 std::string actual; |
| 792 while (actual.size() < written) { |
| 793 char buf[16]; |
| 794 uint32_t read_size = sizeof(buf); |
| 795 MojoResult result = |
| 796 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, |
| 797 MOJO_READ_DATA_FLAG_NONE); |
| 798 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); |
| 799 if (result == MOJO_RESULT_OK) |
| 800 actual.append(buf, read_size); |
| 801 base::RunLoop().RunUntilIdle(); |
| 802 } |
| 803 |
| 804 EXPECT_EQ(std::string(written, 'X'), actual); |
| 805 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); |
| 806 } |
| 807 |
| 808 TEST_F(MojoAsyncResourceHandlerTest, |
| 887 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) { | 809 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) { |
| 888 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); | 810 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); |
| 889 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 811 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 890 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN); | 812 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN); |
| 891 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | 813 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 892 } | 814 } |
| 893 | 815 |
| 894 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) { | 816 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) { |
| 895 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 817 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 896 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 818 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 MOJO_READ_DATA_FLAG_NONE); | 862 MOJO_READ_DATA_FLAG_NONE); |
| 941 if (result == MOJO_RESULT_SHOULD_WAIT) | 863 if (result == MOJO_RESULT_SHOULD_WAIT) |
| 942 break; | 864 break; |
| 943 ASSERT_EQ(MOJO_RESULT_OK, result); | 865 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 944 } | 866 } |
| 945 | 867 |
| 946 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 868 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 947 mock_loader_->WaitUntilIdleOrCanceled(); | 869 mock_loader_->WaitUntilIdleOrCanceled(); |
| 948 EXPECT_FALSE(url_loader_client_.has_received_completion()); | 870 EXPECT_FALSE(url_loader_client_.has_received_completion()); |
| 949 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); | 871 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); |
| 950 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code()); | 872 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); |
| 951 } | 873 } |
| 952 | 874 |
| 953 TEST_F(MojoAsyncResourceHandlerUploadTest, UploadProgressHandling) { | 875 TEST_F(MojoAsyncResourceHandlerUploadTest, UploadProgressHandling) { |
| 954 ASSERT_TRUE(CallOnWillStart()); | 876 ASSERT_TRUE(CallOnWillStart()); |
| 955 | 877 |
| 956 // Expect no report for no progress. | 878 // Expect no report for no progress. |
| 957 set_upload_progress(net::UploadProgress(0, 1000)); | 879 set_upload_progress(net::UploadProgress(0, 1000)); |
| 958 handler_->PollUploadProgress(); | 880 handler_->PollUploadProgress(); |
| 959 EXPECT_FALSE(url_loader_client_.has_received_upload_progress()); | 881 EXPECT_FALSE(url_loader_client_.has_received_upload_progress()); |
| 960 EXPECT_EQ(0, url_loader_client_.current_upload_position()); | 882 EXPECT_EQ(0, url_loader_client_.current_upload_position()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 EXPECT_EQ(net::LOWEST, request_->priority()); | 935 EXPECT_EQ(net::LOWEST, request_->priority()); |
| 1014 | 936 |
| 1015 handler_->SetPriority(net::RequestPriority::HIGHEST, kIntraPriority); | 937 handler_->SetPriority(net::RequestPriority::HIGHEST, kIntraPriority); |
| 1016 | 938 |
| 1017 EXPECT_EQ(net::HIGHEST, request_->priority()); | 939 EXPECT_EQ(net::HIGHEST, request_->priority()); |
| 1018 } | 940 } |
| 1019 | 941 |
| 1020 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 942 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1021 OnWillReadWithLongContents) { | 943 OnWillReadWithLongContents) { |
| 1022 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 944 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1023 | 945 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1024 std::string expected; | 946 std::string expected; |
| 1025 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) | 947 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) |
| 1026 expected += ('A' + i % 26); | 948 expected += ('A' + i % 26); |
| 1027 | 949 |
| 950 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); |
| 951 |
| 1028 size_t written = 0; | 952 size_t written = 0; |
| 1029 std::string actual; | 953 std::string actual; |
| 1030 while (actual.size() < expected.size()) { | 954 while (actual.size() < expected.size()) { |
| 1031 while (written < expected.size() && | 955 while (written < expected.size() && |
| 1032 mock_loader_->status() == MockResourceLoader::Status::IDLE) { | 956 mock_loader_->status() == MockResourceLoader::Status::IDLE) { |
| 1033 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 957 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1034 size_t to_be_written = | 958 const size_t to_be_written = |
| 1035 std::min(static_cast<size_t>(mock_loader_->io_buffer_size()), | 959 std::min(static_cast<size_t>(mock_loader_->io_buffer_size()), |
| 1036 expected.size() - written); | 960 expected.size() - written); |
| 1037 | 961 |
| 1038 // Request should be resumed or paused. | 962 // Request should be resumed or paused. |
| 1039 ASSERT_NE(MockResourceLoader::Status::CANCELED, | 963 ASSERT_NE(MockResourceLoader::Status::CANCELED, |
| 1040 mock_loader_->OnReadCompleted( | 964 mock_loader_->OnReadCompleted( |
| 1041 expected.substr(written, to_be_written))); | 965 expected.substr(written, to_be_written))); |
| 1042 | 966 |
| 1043 written += to_be_written; | 967 written += to_be_written; |
| 1044 } | 968 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1062 base::RunLoop().RunUntilIdle(); | 986 base::RunLoop().RunUntilIdle(); |
| 1063 } | 987 } |
| 1064 EXPECT_EQ(expected, actual); | 988 EXPECT_EQ(expected, actual); |
| 1065 } | 989 } |
| 1066 | 990 |
| 1067 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 991 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1068 BeginWriteFailsOnReadCompleted) { | 992 BeginWriteFailsOnReadCompleted) { |
| 1069 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 993 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1070 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 994 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1071 | 995 |
| 1072 // Whether the next OnReadCompleted call or OnWillRead returns the error | |
| 1073 // depends on whether or not an intermediary buffer is being used by the | |
| 1074 // MojoAsyncResourceHandler. | |
| 1075 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 996 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 1076 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( | 997 ASSERT_EQ(MockResourceLoader::Status::CANCELED, |
| 1077 std::string(mock_loader_->io_buffer_size(), 'A')); | 998 mock_loader_->OnReadCompleted( |
| 1078 if (result == MockResourceLoader::Status::CANCELED) | 999 std::string(mock_loader_->io_buffer_size(), 'A'))); |
| 1079 return; | |
| 1080 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | |
| 1081 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | |
| 1082 } | 1000 } |
| 1083 | 1001 |
| 1084 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1002 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1085 BeginWriteReturnsShouldWaitOnReadCompleted) { | 1003 BeginWriteReturnsShouldWaitOnReadCompleted) { |
| 1086 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1004 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1087 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1005 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1088 | 1006 |
| 1089 // Whether the next OnReadCompleted call or OnWillRead call completes | |
| 1090 // asynchronously depends on whether or not an intermediary buffer is being | |
| 1091 // used by the MojoAsyncResourceHandler. | |
| 1092 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 1007 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 1093 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( | |
| 1094 std::string(mock_loader_->io_buffer_size() - 1, 'A')); | |
| 1095 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | |
| 1096 return; | |
| 1097 | |
| 1098 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | 1008 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, |
| 1099 mock_loader_->OnWillRead()); | 1009 mock_loader_->OnReadCompleted( |
| 1010 std::string(mock_loader_->io_buffer_size(), 'A'))); |
| 1100 } | 1011 } |
| 1101 | 1012 |
| 1102 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1013 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1103 BeginWriteFailsOnResume) { | 1014 BeginWriteFailsOnResume) { |
| 1104 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1015 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1016 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1017 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); |
| 1105 | 1018 |
| 1106 while (true) { | 1019 while (true) { |
| 1107 // Whether the next OnReadCompleted call or OnWillRead call completes | 1020 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1108 // asynchronously depends on whether or not an intermediary buffer is being | 1021 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( |
| 1109 // used by the MojoAsyncResourceHandler. | |
| 1110 MockResourceLoader::Status result = mock_loader_->OnWillRead(); | |
| 1111 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | |
| 1112 break; | |
| 1113 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | |
| 1114 result = mock_loader_->OnReadCompleted( | |
| 1115 std::string(mock_loader_->io_buffer_size(), 'A')); | 1022 std::string(mock_loader_->io_buffer_size(), 'A')); |
| 1116 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | 1023 if (result == MockResourceLoader::Status::CALLBACK_PENDING) |
| 1117 break; | 1024 break; |
| 1118 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | 1025 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 1119 } | 1026 } |
| 1120 url_loader_client_.RunUntilResponseBodyArrived(); | 1027 url_loader_client_.RunUntilResponseBodyArrived(); |
| 1121 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 1028 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 1122 | 1029 |
| 1123 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 1030 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 1124 | 1031 |
| 1125 while (mock_loader_->status() != MockResourceLoader::Status::CANCELED) { | 1032 while (mock_loader_->status() != MockResourceLoader::Status::CANCELED) { |
| 1126 char buf[256]; | 1033 char buf[256]; |
| 1127 uint32_t read_size = sizeof(buf); | 1034 uint32_t read_size = sizeof(buf); |
| 1128 MojoResult result = | 1035 MojoResult result = |
| 1129 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, | 1036 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, |
| 1130 MOJO_READ_DATA_FLAG_NONE); | 1037 MOJO_READ_DATA_FLAG_NONE); |
| 1131 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); | 1038 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); |
| 1132 base::RunLoop().RunUntilIdle(); | 1039 base::RunLoop().RunUntilIdle(); |
| 1133 } | 1040 } |
| 1134 | 1041 |
| 1135 if (mock_loader_->status() == MockResourceLoader::Status::IDLE) | |
| 1136 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | |
| 1137 | |
| 1138 EXPECT_FALSE(url_loader_client_.has_received_completion()); | 1042 EXPECT_FALSE(url_loader_client_.has_received_completion()); |
| 1139 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code()); | 1043 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); |
| 1140 } | 1044 } |
| 1141 | 1045 |
| 1142 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) { | 1046 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) { |
| 1143 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1047 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1144 | 1048 |
| 1145 while (true) { | 1049 while (true) { |
| 1146 // Whether the next OnReadCompleted call or OnWillRead call completes | 1050 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1147 // asynchronously depends on whether or not an intermediary buffer is being | 1051 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( |
| 1148 // used by the MojoAsyncResourceHandler. | |
| 1149 MockResourceLoader::Status result = mock_loader_->OnWillRead(); | |
| 1150 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | |
| 1151 break; | |
| 1152 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | |
| 1153 result = mock_loader_->OnReadCompleted( | |
| 1154 std::string(mock_loader_->io_buffer_size(), 'A')); | 1052 std::string(mock_loader_->io_buffer_size(), 'A')); |
| 1155 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | 1053 if (result == MockResourceLoader::Status::CALLBACK_PENDING) |
| 1156 break; | 1054 break; |
| 1157 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | 1055 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 1158 } | 1056 } |
| 1159 | 1057 |
| 1160 url_loader_client_.RunUntilResponseBodyArrived(); | 1058 url_loader_client_.RunUntilResponseBodyArrived(); |
| 1161 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 1059 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 1162 | 1060 |
| 1163 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 1061 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1252 } |
| 1355 } | 1253 } |
| 1356 EXPECT_EQ("B", body); | 1254 EXPECT_EQ("B", body); |
| 1357 } | 1255 } |
| 1358 | 1256 |
| 1359 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1257 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1360 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1258 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1361 ::testing::Values(8, 32 * 2014)); | 1259 ::testing::Values(8, 32 * 2014)); |
| 1362 } // namespace | 1260 } // namespace |
| 1363 } // namespace content | 1261 } // namespace content |
| OLD | NEW |