Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: content/browser/loader/url_loader_factory_impl_unittest.cc

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 97f81a3f83baffe065a8131a917f5d6bee7944bb..a04f8a6987ada5abf39ea481e74eeb41a566143b 100644
--- a/content/browser/loader/url_loader_factory_impl_unittest.cc
+++ b/content/browser/loader/url_loader_factory_impl_unittest.cc
@@ -33,7 +33,6 @@
#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/content_paths.h"
-#include "content/public/common/process_type.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "mojo/public/c/system/data_pipe.h"
@@ -73,6 +72,8 @@ class RejectingResourceDispatcherHostDelegate final
DISALLOW_COPY_AND_ASSIGN(RejectingResourceDispatcherHostDelegate);
};
+} // namespace
+
// The test parameter is the number of bytes allocated for the buffer in the
// data pipe, for testing the case where the allocated size is smaller than the
// size the mime sniffer *implicitly* requires.
@@ -83,23 +84,19 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
browser_context_(new TestBrowserContext()),
resource_message_filter_(new ResourceMessageFilter(
kChildId,
- // If browser side navigation is enabled then
- // ResourceDispatcherHostImpl prevents main frame URL requests from
- // the renderer. Ensure that these checks don't trip us up by
- // setting the process type in ResourceMessageFilter as
- // PROCESS_TYPE_UNKNOWN.
- PROCESS_TYPE_UNKNOWN,
nullptr,
nullptr,
nullptr,
nullptr,
base::Bind(&URLLoaderFactoryImplTest::GetContexts,
base::Unretained(this)))) {
+ resource_message_filter_->OnFilterAdded(nullptr);
MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam());
rdh_.SetLoaderDelegate(&loader_deleate_);
- URLLoaderFactoryImpl::Create(resource_message_filter_,
- mojo::GetProxy(&factory_));
+ URLLoaderFactoryImpl::Create(
+ resource_message_filter_->requester_info()->clone(),
+ mojo::GetProxy(&factory_));
// Calling this function creates a request context.
browser_context_->GetResourceContext()->GetRequestContext();
@@ -149,7 +146,12 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
// Assume the file contents is small enough to be stored in the data pipe.
request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html");
request.method = "GET";
- request.is_main_frame = true;
+ // |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(GURL("http://localhost/"));
factory_->CreateLoaderAndStart(
mojo::GetProxy(&loader, factory_.associated_group()), kRoutingId,
kRequestId, request,
@@ -214,6 +216,12 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) {
request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
net::URLRequestFailedJob::START, net::ERR_TIMED_OUT);
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(GURL("http://localhost/"));
factory_->CreateLoaderAndStart(
mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
@@ -232,6 +240,12 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) {
TestURLLoaderClient client;
request.url = GURL();
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(GURL("http://localhost/"));
ASSERT_FALSE(request.url.is_valid());
factory_->CreateLoaderAndStart(
mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
@@ -253,6 +267,12 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) {
TestURLLoaderClient client;
request.url = GURL("http://localhost/");
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(GURL("http://localhost/"));
factory_->CreateLoaderAndStart(
mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
@@ -424,6 +444,4 @@ INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest,
URLLoaderFactoryImplTest,
::testing::Values(128, 32 * 1024));
-} // namespace
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698