diff options
Diffstat (limited to 'chromium/content/browser/loader/url_loader_factory_impl_unittest.cc')
-rw-r--r-- | chromium/content/browser/loader/url_loader_factory_impl_unittest.cc | 131 |
1 files changed, 2 insertions, 129 deletions
diff --git a/chromium/content/browser/loader/url_loader_factory_impl_unittest.cc b/chromium/content/browser/loader/url_loader_factory_impl_unittest.cc index e6ede61511d..9385955b5c5 100644 --- a/chromium/content/browser/loader/url_loader_factory_impl_unittest.cc +++ b/chromium/content/browser/loader/url_loader_factory_impl_unittest.cc @@ -203,8 +203,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) { client.completion_status().encoded_data_length); EXPECT_EQ(static_cast<int64_t>(expected.size()), client.completion_status().encoded_body_length); - // OnTransferSizeUpdated is not dispatched as report_raw_headers is not set. - EXPECT_EQ(0, client.body_transfer_size()); + EXPECT_EQ(static_cast<int64_t>(expected.size()), client.body_transfer_size()); + EXPECT_GT(client.body_transfer_size(), 0); EXPECT_GT(client.response_head().encoded_data_length, 0); EXPECT_GT(client.completion_status().encoded_data_length, 0); } @@ -322,133 +322,6 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) { EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); } -TEST_P(URLLoaderFactoryImplTest, DownloadToFile) { - constexpr int32_t kRoutingId = 1; - constexpr int32_t kRequestId = 2; - - network::mojom::URLLoaderPtr loader; - base::FilePath root; - base::PathService::Get(DIR_TEST_DATA, &root); - net::URLRequestMockHTTPJob::AddUrlHandlers(root); - - network::ResourceRequest request; - network::TestURLLoaderClient client; - request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html"); - request.method = "GET"; - request.resource_type = RESOURCE_TYPE_XHR; - request.download_to_file = true; - request.request_initiator = url::Origin::Create(request.url); - factory_->CreateLoaderAndStart( - mojo::MakeRequest(&loader), kRoutingId, kRequestId, 0, request, - client.CreateInterfacePtr(), - net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); - ASSERT_FALSE(client.has_received_response()); - ASSERT_FALSE(client.has_data_downloaded()); - ASSERT_FALSE(client.has_received_completion()); - - client.RunUntilResponseReceived(); - - net::URLRequest* url_request = - rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId)); - ASSERT_TRUE(url_request); - ResourceRequestInfoImpl* request_info = - ResourceRequestInfoImpl::ForRequest(url_request); - ASSERT_TRUE(request_info); - EXPECT_EQ(kChildId, request_info->GetChildID()); - EXPECT_EQ(kRoutingId, request_info->GetRouteID()); - EXPECT_EQ(kRequestId, request_info->GetRequestID()); - - ASSERT_FALSE(client.has_received_completion()); - - client.RunUntilComplete(); - ASSERT_TRUE(client.has_data_downloaded()); - ASSERT_TRUE(client.has_received_completion()); - - EXPECT_EQ(200, client.response_head().headers->response_code()); - std::string content_type; - client.response_head().headers->GetNormalizedHeader("content-type", - &content_type); - EXPECT_EQ("text/html", content_type); - EXPECT_EQ(0, client.completion_status().error_code); - - std::string contents; - base::ReadFileToString(client.response_head().download_file_path, &contents); - - EXPECT_EQ(static_cast<int64_t>(contents.size()), - client.download_data_length()); - EXPECT_EQ(static_cast<int64_t>(contents.size()), - client.encoded_download_data_length()); - - std::string expected; - base::ReadFileToString( - root.Append(base::FilePath(FILE_PATH_LITERAL("hello.html"))), &expected); - EXPECT_EQ(expected, contents); - EXPECT_EQ(static_cast<int64_t>(expected.size()) + - client.response_head().encoded_data_length, - client.completion_status().encoded_data_length); - EXPECT_EQ(static_cast<int64_t>(expected.size()), - client.completion_status().encoded_body_length); -} - -TEST_P(URLLoaderFactoryImplTest, DownloadToFileFailure) { - constexpr int32_t kRoutingId = 1; - constexpr int32_t kRequestId = 2; - - network::mojom::URLLoaderPtr loader; - base::FilePath root; - base::PathService::Get(DIR_TEST_DATA, &root); - net::URLRequestSlowDownloadJob::AddUrlHandler(); - - network::ResourceRequest request; - network::TestURLLoaderClient client; - request.url = GURL(net::URLRequestSlowDownloadJob::kKnownSizeUrl); - request.method = "GET"; - request.resource_type = RESOURCE_TYPE_XHR; - request.download_to_file = true; - request.request_initiator = url::Origin::Create(request.url); - factory_->CreateLoaderAndStart( - mojo::MakeRequest(&loader), kRoutingId, kRequestId, 0, request, - client.CreateInterfacePtr(), - net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); - ASSERT_FALSE(client.has_received_response()); - ASSERT_FALSE(client.has_data_downloaded()); - ASSERT_FALSE(client.has_received_completion()); - - client.RunUntilResponseReceived(); - - net::URLRequest* url_request = - rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId)); - ASSERT_TRUE(url_request); - ResourceRequestInfoImpl* request_info = - ResourceRequestInfoImpl::ForRequest(url_request); - ASSERT_TRUE(request_info); - EXPECT_EQ(kChildId, request_info->GetChildID()); - EXPECT_EQ(kRoutingId, request_info->GetRouteID()); - EXPECT_EQ(kRequestId, request_info->GetRequestID()); - - ASSERT_FALSE(client.has_received_completion()); - - client.RunUntilDataDownloaded(); - ASSERT_TRUE(client.has_data_downloaded()); - ASSERT_FALSE(client.has_received_completion()); - EXPECT_LT(0, client.download_data_length()); - EXPECT_GE( - static_cast<int64_t>(net::URLRequestSlowDownloadJob::kFirstDownloadSize), - client.download_data_length()); - EXPECT_LT(0, client.encoded_download_data_length()); - EXPECT_GE( - static_cast<int64_t>(net::URLRequestSlowDownloadJob::kFirstDownloadSize), - client.encoded_download_data_length()); - - url_request->Cancel(); - client.RunUntilComplete(); - - ASSERT_TRUE(client.has_received_completion()); - - EXPECT_EQ(200, client.response_head().headers->response_code()); - EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); -} - TEST_P(URLLoaderFactoryImplTest, OnTransferSizeUpdated) { constexpr int32_t kRoutingId = 81; constexpr int32_t kRequestId = 28; |