| 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::CALLBACK_PENDING, | 588 EXPECT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status()); |
| 589 mock_loader_->status()); | |
| 590 } | 589 } |
| 591 | 590 |
| 592 TEST_F(MojoAsyncResourceHandlerTest, | 591 TEST_F(MojoAsyncResourceHandlerTest, |
| 593 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) { | 592 IOBufferFromOnWillReadShouldRemainValidEvenIfHandlerIsGone) { |
| 594 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 593 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 595 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 594 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 596 // The io_buffer size that the mime sniffer requires implicitly. | 595 // The io_buffer size that the mime sniffer requires implicitly. |
| 597 ASSERT_GE(mock_loader_->io_buffer_size(), | 596 ASSERT_GE(mock_loader_->io_buffer_size(), |
| 598 kSizeMimeSnifferRequiresForFirstOnWillRead); | 597 kSizeMimeSnifferRequiresForFirstOnWillRead); |
| 599 | 598 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 break; | 715 break; |
| 717 ASSERT_TRUE(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); | 716 ASSERT_TRUE(result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_OK); |
| 718 } | 717 } |
| 719 } | 718 } |
| 720 | 719 |
| 721 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) { | 720 TEST_F(MojoAsyncResourceHandlerTest, OutOfBandCancelDuringBodyTransmission) { |
| 722 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 721 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 723 | 722 |
| 724 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 723 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 725 std::string data(mock_loader_->io_buffer_size(), 'a'); | 724 std::string data(mock_loader_->io_buffer_size(), 'a'); |
| 725 ASSERT_EQ(MockResourceLoader::Status::IDLE, |
| 726 mock_loader_->OnReadCompleted(data)); |
| 726 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | 727 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, |
| 727 mock_loader_->OnReadCompleted(data)); | 728 mock_loader_->OnWillRead()); |
| 728 url_loader_client_.RunUntilResponseBodyArrived(); | 729 url_loader_client_.RunUntilResponseBodyArrived(); |
| 729 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 730 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 730 | 731 |
| 731 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); | 732 net::URLRequestStatus status(net::URLRequestStatus::FAILED, net::ERR_FAILED); |
| 732 ASSERT_EQ( | 733 ASSERT_EQ( |
| 733 MockResourceLoader::Status::IDLE, | 734 MockResourceLoader::Status::IDLE, |
| 734 mock_loader_->OnResponseCompletedFromExternalOutOfBandCancel(status)); | 735 mock_loader_->OnResponseCompletedFromExternalOutOfBandCancel(status)); |
| 735 | 736 |
| 736 url_loader_client_.RunUntilComplete(); | 737 url_loader_client_.RunUntilComplete(); |
| 737 EXPECT_TRUE(url_loader_client_.has_received_completion()); | 738 EXPECT_TRUE(url_loader_client_.has_received_completion()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 757 } | 758 } |
| 758 | 759 |
| 759 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) { | 760 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteFailsOnWillRead) { |
| 760 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 761 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 761 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 762 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 762 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | 763 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 763 } | 764 } |
| 764 | 765 |
| 765 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) { | 766 TEST_F(MojoAsyncResourceHandlerTest, BeginWriteReturnsShouldWaitOnWillRead) { |
| 766 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 767 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 768 |
| 767 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 769 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 768 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 770 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); |
| 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()); |
| 769 } | 884 } |
| 770 | 885 |
| 771 TEST_F(MojoAsyncResourceHandlerTest, | 886 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, | |
| 809 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) { | 887 EndWriteFailsOnWillReadWithInsufficientInitialCapacity) { |
| 810 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); | 888 MojoAsyncResourceHandler::SetAllocationSizeForTesting(2); |
| 811 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 889 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 812 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN); | 890 handler_->set_end_write_expectation(MOJO_RESULT_UNKNOWN); |
| 813 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); | 891 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 814 } | 892 } |
| 815 | 893 |
| 816 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) { | 894 TEST_F(MojoAsyncResourceHandlerTest, EndWriteFailsOnReadCompleted) { |
| 817 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 895 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 818 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 896 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 MOJO_READ_DATA_FLAG_NONE); | 940 MOJO_READ_DATA_FLAG_NONE); |
| 863 if (result == MOJO_RESULT_SHOULD_WAIT) | 941 if (result == MOJO_RESULT_SHOULD_WAIT) |
| 864 break; | 942 break; |
| 865 ASSERT_EQ(MOJO_RESULT_OK, result); | 943 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 866 } | 944 } |
| 867 | 945 |
| 868 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 946 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); |
| 869 mock_loader_->WaitUntilIdleOrCanceled(); | 947 mock_loader_->WaitUntilIdleOrCanceled(); |
| 870 EXPECT_FALSE(url_loader_client_.has_received_completion()); | 948 EXPECT_FALSE(url_loader_client_.has_received_completion()); |
| 871 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); | 949 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); |
| 872 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); | 950 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code()); |
| 873 } | 951 } |
| 874 | 952 |
| 875 TEST_F(MojoAsyncResourceHandlerUploadTest, UploadProgressHandling) { | 953 TEST_F(MojoAsyncResourceHandlerUploadTest, UploadProgressHandling) { |
| 876 ASSERT_TRUE(CallOnWillStart()); | 954 ASSERT_TRUE(CallOnWillStart()); |
| 877 | 955 |
| 878 // Expect no report for no progress. | 956 // Expect no report for no progress. |
| 879 set_upload_progress(net::UploadProgress(0, 1000)); | 957 set_upload_progress(net::UploadProgress(0, 1000)); |
| 880 handler_->PollUploadProgress(); | 958 handler_->PollUploadProgress(); |
| 881 EXPECT_FALSE(url_loader_client_.has_received_upload_progress()); | 959 EXPECT_FALSE(url_loader_client_.has_received_upload_progress()); |
| 882 EXPECT_EQ(0, url_loader_client_.current_upload_position()); | 960 EXPECT_EQ(0, url_loader_client_.current_upload_position()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 EXPECT_EQ(net::LOWEST, request_->priority()); | 1013 EXPECT_EQ(net::LOWEST, request_->priority()); |
| 936 | 1014 |
| 937 handler_->SetPriority(net::RequestPriority::HIGHEST, kIntraPriority); | 1015 handler_->SetPriority(net::RequestPriority::HIGHEST, kIntraPriority); |
| 938 | 1016 |
| 939 EXPECT_EQ(net::HIGHEST, request_->priority()); | 1017 EXPECT_EQ(net::HIGHEST, request_->priority()); |
| 940 } | 1018 } |
| 941 | 1019 |
| 942 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1020 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 943 OnWillReadWithLongContents) { | 1021 OnWillReadWithLongContents) { |
| 944 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1022 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 945 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1023 |
| 946 std::string expected; | 1024 std::string expected; |
| 947 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) | 1025 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) |
| 948 expected += ('A' + i % 26); | 1026 expected += ('A' + i % 26); |
| 949 | 1027 |
| 950 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); | |
| 951 | |
| 952 size_t written = 0; | 1028 size_t written = 0; |
| 953 std::string actual; | 1029 std::string actual; |
| 954 while (actual.size() < expected.size()) { | 1030 while (actual.size() < expected.size()) { |
| 955 while (written < expected.size() && | 1031 while (written < expected.size() && |
| 956 mock_loader_->status() == MockResourceLoader::Status::IDLE) { | 1032 mock_loader_->status() == MockResourceLoader::Status::IDLE) { |
| 957 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1033 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 958 const size_t to_be_written = | 1034 size_t to_be_written = |
| 959 std::min(static_cast<size_t>(mock_loader_->io_buffer_size()), | 1035 std::min(static_cast<size_t>(mock_loader_->io_buffer_size()), |
| 960 expected.size() - written); | 1036 expected.size() - written); |
| 961 | 1037 |
| 962 // Request should be resumed or paused. | 1038 // Request should be resumed or paused. |
| 963 ASSERT_NE(MockResourceLoader::Status::CANCELED, | 1039 ASSERT_NE(MockResourceLoader::Status::CANCELED, |
| 964 mock_loader_->OnReadCompleted( | 1040 mock_loader_->OnReadCompleted( |
| 965 expected.substr(written, to_be_written))); | 1041 expected.substr(written, to_be_written))); |
| 966 | 1042 |
| 967 written += to_be_written; | 1043 written += to_be_written; |
| 968 } | 1044 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 986 base::RunLoop().RunUntilIdle(); | 1062 base::RunLoop().RunUntilIdle(); |
| 987 } | 1063 } |
| 988 EXPECT_EQ(expected, actual); | 1064 EXPECT_EQ(expected, actual); |
| 989 } | 1065 } |
| 990 | 1066 |
| 991 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1067 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 992 BeginWriteFailsOnReadCompleted) { | 1068 BeginWriteFailsOnReadCompleted) { |
| 993 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1069 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 994 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1070 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 995 | 1071 |
| 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. |
| 996 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 1075 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 997 ASSERT_EQ(MockResourceLoader::Status::CANCELED, | 1076 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( |
| 998 mock_loader_->OnReadCompleted( | 1077 std::string(mock_loader_->io_buffer_size(), 'A')); |
| 999 std::string(mock_loader_->io_buffer_size(), 'A'))); | 1078 if (result == MockResourceLoader::Status::CANCELED) |
| 1079 return; |
| 1080 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 1081 ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 1000 } | 1082 } |
| 1001 | 1083 |
| 1002 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1084 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1003 BeginWriteReturnsShouldWaitOnReadCompleted) { | 1085 BeginWriteReturnsShouldWaitOnReadCompleted) { |
| 1004 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1086 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1005 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1087 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); |
| 1006 | 1088 |
| 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. |
| 1007 handler_->set_begin_write_expectation(MOJO_RESULT_SHOULD_WAIT); | 1092 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 |
| 1008 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, | 1098 ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING, |
| 1009 mock_loader_->OnReadCompleted( | 1099 mock_loader_->OnWillRead()); |
| 1010 std::string(mock_loader_->io_buffer_size(), 'A'))); | |
| 1011 } | 1100 } |
| 1012 | 1101 |
| 1013 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1102 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1014 BeginWriteFailsOnResume) { | 1103 BeginWriteFailsOnResume) { |
| 1015 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1104 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1016 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | |
| 1017 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); | |
| 1018 | 1105 |
| 1019 while (true) { | 1106 while (true) { |
| 1020 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1107 // Whether the next OnReadCompleted call or OnWillRead call completes |
| 1021 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( | 1108 // asynchronously depends on whether or not an intermediary buffer is being |
| 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( |
| 1022 std::string(mock_loader_->io_buffer_size(), 'A')); | 1115 std::string(mock_loader_->io_buffer_size(), 'A')); |
| 1023 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | 1116 if (result == MockResourceLoader::Status::CALLBACK_PENDING) |
| 1024 break; | 1117 break; |
| 1025 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | 1118 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 1026 } | 1119 } |
| 1027 url_loader_client_.RunUntilResponseBodyArrived(); | 1120 url_loader_client_.RunUntilResponseBodyArrived(); |
| 1028 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 1121 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 1029 | 1122 |
| 1030 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); | 1123 handler_->set_begin_write_expectation(MOJO_RESULT_UNKNOWN); |
| 1031 | 1124 |
| 1032 while (mock_loader_->status() != MockResourceLoader::Status::CANCELED) { | 1125 while (mock_loader_->status() != MockResourceLoader::Status::CANCELED) { |
| 1033 char buf[256]; | 1126 char buf[256]; |
| 1034 uint32_t read_size = sizeof(buf); | 1127 uint32_t read_size = sizeof(buf); |
| 1035 MojoResult result = | 1128 MojoResult result = |
| 1036 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, | 1129 mojo::ReadDataRaw(url_loader_client_.response_body(), buf, &read_size, |
| 1037 MOJO_READ_DATA_FLAG_NONE); | 1130 MOJO_READ_DATA_FLAG_NONE); |
| 1038 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); | 1131 ASSERT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT); |
| 1039 base::RunLoop().RunUntilIdle(); | 1132 base::RunLoop().RunUntilIdle(); |
| 1040 } | 1133 } |
| 1041 | 1134 |
| 1135 if (mock_loader_->status() == MockResourceLoader::Status::IDLE) |
| 1136 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead()); |
| 1137 |
| 1042 EXPECT_FALSE(url_loader_client_.has_received_completion()); | 1138 EXPECT_FALSE(url_loader_client_.has_received_completion()); |
| 1043 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); | 1139 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, mock_loader_->error_code()); |
| 1044 } | 1140 } |
| 1045 | 1141 |
| 1046 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) { | 1142 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, CancelWhileWaiting) { |
| 1047 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); | 1143 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); |
| 1048 | 1144 |
| 1049 while (true) { | 1145 while (true) { |
| 1050 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead()); | 1146 // Whether the next OnReadCompleted call or OnWillRead call completes |
| 1051 MockResourceLoader::Status result = mock_loader_->OnReadCompleted( | 1147 // asynchronously depends on whether or not an intermediary buffer is being |
| 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( |
| 1052 std::string(mock_loader_->io_buffer_size(), 'A')); | 1154 std::string(mock_loader_->io_buffer_size(), 'A')); |
| 1053 if (result == MockResourceLoader::Status::CALLBACK_PENDING) | 1155 if (result == MockResourceLoader::Status::CALLBACK_PENDING) |
| 1054 break; | 1156 break; |
| 1055 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); | 1157 ASSERT_EQ(MockResourceLoader::Status::IDLE, result); |
| 1056 } | 1158 } |
| 1057 | 1159 |
| 1058 url_loader_client_.RunUntilResponseBodyArrived(); | 1160 url_loader_client_.RunUntilResponseBodyArrived(); |
| 1059 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); | 1161 ASSERT_TRUE(url_loader_client_.response_body().is_valid()); |
| 1060 | 1162 |
| 1061 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 1163 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 } | 1354 } |
| 1253 } | 1355 } |
| 1254 EXPECT_EQ("B", body); | 1356 EXPECT_EQ("B", body); |
| 1255 } | 1357 } |
| 1256 | 1358 |
| 1257 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1359 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1258 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1360 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1259 ::testing::Values(8, 32 * 2014)); | 1361 ::testing::Values(8, 32 * 2014)); |
| 1260 } // namespace | 1362 } // namespace |
| 1261 } // namespace content | 1363 } // namespace content |
| OLD | NEW |