| Index: content/child/resource_dispatcher_unittest.cc
|
| diff --git a/content/child/resource_dispatcher_unittest.cc b/content/child/resource_dispatcher_unittest.cc
|
| index efedbf46b342c54a5ab6a2a9eac76a7081031b88..c63692e1acb157c1530be5645ed9faf1a834862d 100644
|
| --- a/content/child/resource_dispatcher_unittest.cc
|
| +++ b/content/child/resource_dispatcher_unittest.cc
|
| @@ -22,7 +22,6 @@
|
| #include "base/run_loop.h"
|
| #include "base/stl_util.h"
|
| #include "content/child/request_extra_data.h"
|
| -#include "content/child/request_info.h"
|
| #include "content/common/appcache_interfaces.h"
|
| #include "content/common/resource_messages.h"
|
| #include "content/common/resource_request.h"
|
| @@ -32,10 +31,14 @@
|
| #include "content/public/child/request_peer.h"
|
| #include "content/public/child/resource_dispatcher_delegate.h"
|
| #include "content/public/common/content_features.h"
|
| +#include "content/public/common/request_context_frame_type.h"
|
| #include "content/public/common/resource_response.h"
|
| #include "net/base/net_errors.h"
|
| +#include "net/base/request_priority.h"
|
| #include "net/http/http_response_headers.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
|
| +#include "url/gurl.h"
|
|
|
| namespace content {
|
|
|
| @@ -304,34 +307,35 @@ class ResourceDispatcherTest : public testing::Test, public IPC::Sender {
|
| ResourceMsg_RequestComplete(request_id, request_complete_data)));
|
| }
|
|
|
| - RequestInfo* CreateRequestInfo(bool download_to_file) {
|
| - RequestInfo* request_info = new RequestInfo();
|
| - request_info->method = "GET";
|
| - request_info->url = GURL(kTestPageUrl);
|
| - request_info->first_party_for_cookies = GURL(kTestPageUrl);
|
| - request_info->referrer = Referrer();
|
| - request_info->headers = std::string();
|
| - request_info->load_flags = 0;
|
| - request_info->requestor_pid = 0;
|
| - request_info->request_type = RESOURCE_TYPE_SUB_RESOURCE;
|
| - request_info->appcache_host_id = kAppCacheNoHostId;
|
| - request_info->should_reset_appcache = false;
|
| - request_info->routing_id = 0;
|
| - request_info->download_to_file = download_to_file;
|
| - RequestExtraData extra_data;
|
| -
|
| - return request_info;
|
| + std::unique_ptr<ResourceRequest> CreateResourceRequest(
|
| + bool download_to_file) {
|
| + std::unique_ptr<ResourceRequest> request(new ResourceRequest());
|
| +
|
| + request->method = "GET";
|
| + request->url = GURL(kTestPageUrl);
|
| + request->first_party_for_cookies = GURL(kTestPageUrl);
|
| + request->referrer_policy = blink::WebReferrerPolicyDefault;
|
| + request->resource_type = RESOURCE_TYPE_SUB_RESOURCE;
|
| + request->priority = net::LOW;
|
| + request->fetch_request_mode = FETCH_REQUEST_MODE_NO_CORS;
|
| + request->fetch_frame_type = REQUEST_CONTEXT_FRAME_TYPE_NONE;
|
| + request->download_to_file = download_to_file;
|
| +
|
| + const RequestExtraData extra_data;
|
| + extra_data.CopyToResourceRequest(request.get());
|
| +
|
| + return request;
|
| }
|
|
|
| ResourceDispatcher* dispatcher() { return dispatcher_.get(); }
|
|
|
| - int StartAsync(const RequestInfo& request_info,
|
| + int StartAsync(std::unique_ptr<ResourceRequest> request,
|
| ResourceRequestBodyImpl* request_body,
|
| TestRequestPeer::Context* peer_context) {
|
| std::unique_ptr<TestRequestPeer> peer(
|
| new TestRequestPeer(dispatcher(), peer_context));
|
| int request_id = dispatcher()->StartAsync(
|
| - request_info, request_body, std::move(peer),
|
| + std::move(request), 0, nullptr, GURL(), std::move(peer),
|
| blink::WebURLRequest::LoadingIPCType::ChromeIPC, nullptr);
|
| peer_context->request_id = request_id;
|
| return request_id;
|
| @@ -353,9 +357,9 @@ TEST_F(ResourceDispatcherTest, RoundTrip) {
|
| const size_t kFirstReceiveSize = 2;
|
| ASSERT_LT(kFirstReceiveSize, strlen(kTestPageContents));
|
|
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -386,9 +390,9 @@ TEST_F(ResourceDispatcherTest, ResponseWithInlinedData) {
|
| features::kOptimizeLoadingIPCForSmallResources.name, std::string());
|
| base::FeatureList::ClearInstanceForTesting();
|
| base::FeatureList::SetInstance(std::move(feature_list));
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -413,13 +417,13 @@ TEST_F(ResourceDispatcherTest, ResponseWithInlinedData) {
|
| TEST_F(ResourceDispatcherTest, MultipleRequests) {
|
| const char kTestPageContents2[] = "Not kTestPageContents";
|
|
|
| - std::unique_ptr<RequestInfo> request_info1(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request1(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context1;
|
| - StartAsync(*request_info1.get(), NULL, &peer_context1);
|
| + StartAsync(std::move(request1), NULL, &peer_context1);
|
|
|
| - std::unique_ptr<RequestInfo> request_info2(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request2(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context2;
|
| - StartAsync(*request_info2.get(), NULL, &peer_context2);
|
| + StartAsync(std::move(request2), NULL, &peer_context2);
|
|
|
| int id1 = ConsumeRequestResource();
|
| int id2 = ConsumeRequestResource();
|
| @@ -454,9 +458,9 @@ TEST_F(ResourceDispatcherTest, MultipleRequests) {
|
|
|
| // Tests that the cancel method prevents other messages from being received.
|
| TEST_F(ResourceDispatcherTest, Cancel) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -479,9 +483,9 @@ TEST_F(ResourceDispatcherTest, Cancel) {
|
|
|
| // Tests that calling cancel during a callback works as expected.
|
| TEST_F(ResourceDispatcherTest, CancelDuringCallback) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
| peer_context.cancel_on_receive_response = true;
|
|
|
| int id = ConsumeRequestResource();
|
| @@ -571,9 +575,9 @@ class TestResourceDispatcherDelegate : public ResourceDispatcherDelegate {
|
| };
|
|
|
| TEST_F(ResourceDispatcherTest, DelegateTest) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), nullptr, &peer_context);
|
| + StartAsync(std::move(request), nullptr, &peer_context);
|
|
|
| // Set the delegate that inserts a new peer in OnReceivedResponse.
|
| TestResourceDispatcherDelegate delegate;
|
| @@ -608,9 +612,9 @@ TEST_F(ResourceDispatcherTest, DelegateTest) {
|
| }
|
|
|
| TEST_F(ResourceDispatcherTest, CancelDuringCallbackWithWrapperPeer) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), nullptr, &peer_context);
|
| + StartAsync(std::move(request), nullptr, &peer_context);
|
| peer_context.cancel_on_receive_response = true;
|
|
|
| // Set the delegate that inserts a new peer in OnReceivedResponse.
|
| @@ -652,9 +656,9 @@ TEST_F(ResourceDispatcherTest, CancelDuringCallbackWithWrapperPeer) {
|
|
|
| // Checks that redirects work as expected.
|
| TEST_F(ResourceDispatcherTest, Redirect) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
|
|
| @@ -683,9 +687,9 @@ TEST_F(ResourceDispatcherTest, Redirect) {
|
| // Tests that that cancelling during a redirect method prevents other messages
|
| // from being received.
|
| TEST_F(ResourceDispatcherTest, CancelDuringRedirect) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
| peer_context.follow_redirects = false;
|
|
|
| int id = ConsumeRequestResource();
|
| @@ -713,9 +717,9 @@ TEST_F(ResourceDispatcherTest, CancelDuringRedirect) {
|
|
|
| // Checks that deferring a request delays messages until it's resumed.
|
| TEST_F(ResourceDispatcherTest, Defer) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -747,9 +751,9 @@ TEST_F(ResourceDispatcherTest, Defer) {
|
| // Checks that deferring a request during a redirect delays messages until it's
|
| // resumed.
|
| TEST_F(ResourceDispatcherTest, DeferOnRedirect) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
| peer_context.defer_on_redirect = true;
|
|
|
| int id = ConsumeRequestResource();
|
| @@ -786,9 +790,9 @@ TEST_F(ResourceDispatcherTest, DeferOnRedirect) {
|
|
|
| // Checks that a deferred request that's cancelled doesn't receive any messages.
|
| TEST_F(ResourceDispatcherTest, CancelDeferredRequest) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -809,9 +813,9 @@ TEST_F(ResourceDispatcherTest, CancelDeferredRequest) {
|
| }
|
|
|
| TEST_F(ResourceDispatcherTest, DownloadToFile) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(true));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
| const int kDownloadedIncrement = 100;
|
| const int kEncodedIncrement = 50;
|
|
|
| @@ -851,9 +855,9 @@ TEST_F(ResourceDispatcherTest, DownloadToFile) {
|
|
|
| // Make sure that when a download to file is cancelled, the file is destroyed.
|
| TEST_F(ResourceDispatcherTest, CancelDownloadToFile) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(true));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(true));
|
| TestRequestPeer::Context peer_context;
|
| - int request_id = StartAsync(*request_info.get(), NULL, &peer_context);
|
| + int request_id = StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| int id = ConsumeRequestResource();
|
| EXPECT_EQ(0u, queued_messages());
|
| @@ -884,9 +888,9 @@ class TimeConversionTest : public ResourceDispatcherTest {
|
| }
|
|
|
| void PerformTest(const ResourceResponseHead& response_head) {
|
| - std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
|
| + std::unique_ptr<ResourceRequest> request(CreateResourceRequest(false));
|
| TestRequestPeer::Context peer_context;
|
| - StartAsync(*request_info.get(), NULL, &peer_context);
|
| + StartAsync(std::move(request), NULL, &peer_context);
|
|
|
| dispatcher()->OnMessageReceived(
|
| ResourceMsg_ReceivedResponse(0, response_head));
|
|
|