Index: content/browser/loader/url_loader_factory_impl_unittest.cc |
diff --git a/content/browser/loader/url_loader_factory_impl_unittest.cc b/content/browser/loader/url_loader_factory_impl_unittest.cc |
index 8eefe67405012bdcfd50ff06e5f1270e58628ae6..2716bf9a49723bede49297e25df30deec863bd96 100644 |
--- a/content/browser/loader/url_loader_factory_impl_unittest.cc |
+++ b/content/browser/loader/url_loader_factory_impl_unittest.cc |
@@ -20,6 +20,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/path_service.h" |
#include "base/run_loop.h" |
+#include "content/browser/child_process_security_policy_impl.h" |
#include "content/browser/loader/mojo_async_resource_handler.h" |
#include "content/browser/loader/navigation_resource_throttle.h" |
#include "content/browser/loader/resource_dispatcher_host_impl.h" |
@@ -89,6 +90,7 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { |
nullptr, |
base::Bind(&URLLoaderFactoryImplTest::GetContexts, |
base::Unretained(this)))) { |
+ ChildProcessSecurityPolicyImpl::GetInstance()->Add(kChildId); |
mmenke
2016/12/13 20:01:25
Why is this now needed?
yhirano
2016/12/14 16:47:27
Added comments.
|
resource_message_filter_->InitializeForTest(); |
MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); |
rdh_.SetLoaderDelegate(&loader_deleate_); |
@@ -103,6 +105,7 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { |
} |
~URLLoaderFactoryImplTest() override { |
+ ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId); |
rdh_.SetDelegate(nullptr); |
net::URLRequestFilter::GetInstance()->ClearHandlers(); |
@@ -208,6 +211,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()); |
mmenke
2016/12/13 20:01:25
Is this any different from client.completion_statu
mmenke
2016/12/13 20:01:25
Maybe check head.encoded_data_length in this test,
yhirano
2016/12/14 16:47:27
Done.
yhirano
2016/12/14 16:47:27
Yes, it's different. OnTransferSizeUpdated is noti
|
} |
TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) { |
@@ -447,6 +452,42 @@ TEST_P(URLLoaderFactoryImplTest, DownloadToFileFailure) { |
EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); |
} |
+TEST_P(URLLoaderFactoryImplTest, OnTransferSizeUpdated) { |
+ constexpr int32_t kRoutingId = 81; |
+ constexpr int32_t kRequestId = 28; |
+ NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); |
+ mojom::URLLoaderAssociatedPtr loader; |
+ base::FilePath root; |
+ PathService::Get(DIR_TEST_DATA, &root); |
+ net::URLRequestMockHTTPJob::AddUrlHandlers(root, |
+ BrowserThread::GetBlockingPool()); |
+ ResourceRequest request; |
+ TestURLLoaderClient client; |
+ // Assume the file contents is small enough to be stored in the data pipe. |
+ request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html"); |
+ request.method = "GET"; |
+ // |resource_type| can't be a frame type. It is because when PlzNavigate is |
+ // enabled, the url scheme of frame type requests from the renderer process |
+ // must be blob scheme. |
+ request.resource_type = RESOURCE_TYPE_XHR; |
+ // Need to set |request_initiator| for non main frame type request. |
+ request.request_initiator = url::Origin(); |
+ request.report_raw_headers = true; |
+ ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies(kChildId); |
+ factory_->CreateLoaderAndStart( |
+ mojo::GetProxy(&loader, factory_.associated_group()), kRoutingId, |
+ kRequestId, request, |
+ client.CreateRemoteAssociatedPtrInfo(factory_.associated_group())); |
+ |
+ client.RunUntilComplete(); |
+ |
+ EXPECT_GT(client.body_transfer_size(), 0); |
+ EXPECT_EQ(200, client.response_head().headers->response_code()); |
+ EXPECT_EQ( |
+ client.response_head().encoded_data_length + client.body_transfer_size(), |
+ client.completion_status().encoded_data_length); |
mmenke
2016/12/13 20:01:25
URLRequestMockHTTPJob doesn't claim to receive any
yhirano
2016/12/14 16:47:27
Done.
|
+} |
+ |
// Removing the loader in the remote side will cancel the request. |
TEST_P(URLLoaderFactoryImplTest, CancelFromRenderer) { |
constexpr int32_t kRoutingId = 81; |