Commit 6c452f51 authored by ananta's avatar ananta Committed by Commit bot

Fixes for the failing URLLoaderFactoryImplTest content_unittests with PlzNavigate enabled

The main resource requests which the content_unittests were making using
mojo were failing in RDHI because the renderer is not supposed to make
main resource requests with PlzNavigate. Worked around this by setting
the process type to PROCESS_TYPE_UNKNOWN in ResourceMessageFilter for
these unittests and added a check in the related code to only enforce
these checks for PROCESS_TYPE_RENDERER.

The other change was in the TestURLLoaderClient methods which run the
message loop waiting for states like response received, body received etc.
For some reason, with PlzNavigate enabled the response for the body
arrives immediately following the header response causing the next wait to
just block. The fixes were to see if already have a response_body_ in the
TestURLLoaderClient::RunUntilResponseBodyArrived method and return
immediately and a similar check in TestURLLoaderClient::RunUntilComplete()

BUG=439423

Review-Url: https://codereview.chromium.org/2283473002
Cr-Commit-Position: refs/heads/master@{#414640}
parent 9f7e8c4d
...@@ -335,6 +335,7 @@ specific_include_rules = { ...@@ -335,6 +335,7 @@ specific_include_rules = {
"+content/public/browser/resource_context.h", "+content/public/browser/resource_context.h",
"+content/public/browser/resource_dispatcher_host_delegate.h", "+content/public/browser/resource_dispatcher_host_delegate.h",
"+content/public/common/content_paths.h", "+content/public/common/content_paths.h",
"+content/public/common/process_type.h",
"+content/public/test/test_browser_context.h", "+content/public/test/test_browser_context.h",
"+content/public/test/test_browser_thread_bundle.h", "+content/public/test/test_browser_thread_bundle.h",
], ],
......
...@@ -1211,8 +1211,10 @@ void ResourceDispatcherHostImpl::BeginRequest( ...@@ -1211,8 +1211,10 @@ void ResourceDispatcherHostImpl::BeginRequest(
bool is_navigation_stream_request = bool is_navigation_stream_request =
IsBrowserSideNavigationEnabled() && IsBrowserSideNavigationEnabled() &&
IsResourceTypeFrame(request_data.resource_type); IsResourceTypeFrame(request_data.resource_type);
if (is_navigation_stream_request && // The process_type check is to ensure that unittests are not blocked from
!request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) { // issuing http requests.
if ((process_type == PROCESS_TYPE_RENDERER) && is_navigation_stream_request
&& !request_data.resource_body_stream_url.SchemeIs(url::kBlobScheme)) {
bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_URL); bad_message::ReceivedBadMessage(filter_, bad_message::RDH_INVALID_URL);
return; return;
} }
...@@ -1327,7 +1329,8 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest( ...@@ -1327,7 +1329,8 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
bool is_navigation_stream_request = bool is_navigation_stream_request =
IsBrowserSideNavigationEnabled() && IsBrowserSideNavigationEnabled() &&
IsResourceTypeFrame(request_data.resource_type); IsResourceTypeFrame(request_data.resource_type) &&
process_type == PROCESS_TYPE_RENDERER;
ResourceContext* resource_context = NULL; ResourceContext* resource_context = NULL;
net::URLRequestContext* request_context = NULL; net::URLRequestContext* request_context = NULL;
...@@ -1616,8 +1619,10 @@ ResourceDispatcherHostImpl::AddStandardHandlers( ...@@ -1616,8 +1619,10 @@ ResourceDispatcherHostImpl::AddStandardHandlers(
// PlzNavigate: do not add ResourceThrottles for main resource requests from // PlzNavigate: do not add ResourceThrottles for main resource requests from
// the renderer. Decisions about the navigation should have been done in the // the renderer. Decisions about the navigation should have been done in the
// initial request. // initial request.
if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type) && bool is_renderer =
child_id != -1) { filter_ ? (filter_->process_type() == PROCESS_TYPE_RENDERER) : false;
if (is_renderer && IsBrowserSideNavigationEnabled() &&
IsResourceTypeFrame(resource_type)) {
DCHECK(request->url().SchemeIs(url::kBlobScheme)); DCHECK(request->url().SchemeIs(url::kBlobScheme));
return handler; return handler;
} }
......
...@@ -51,6 +51,8 @@ void TestURLLoaderClient::RunUntilResponseReceived() { ...@@ -51,6 +51,8 @@ void TestURLLoaderClient::RunUntilResponseReceived() {
} }
void TestURLLoaderClient::RunUntilResponseBodyArrived() { void TestURLLoaderClient::RunUntilResponseBodyArrived() {
if (response_body_.is_valid())
return;
base::RunLoop run_loop; base::RunLoop run_loop;
quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure(); quit_closure_for_on_start_loading_response_body_ = run_loop.QuitClosure();
run_loop.Run(); run_loop.Run();
...@@ -58,6 +60,8 @@ void TestURLLoaderClient::RunUntilResponseBodyArrived() { ...@@ -58,6 +60,8 @@ void TestURLLoaderClient::RunUntilResponseBodyArrived() {
} }
void TestURLLoaderClient::RunUntilComplete() { void TestURLLoaderClient::RunUntilComplete() {
if (has_received_completion_)
return;
base::RunLoop run_loop; base::RunLoop run_loop;
quit_closure_for_on_complete_ = run_loop.QuitClosure(); quit_closure_for_on_complete_ = run_loop.QuitClosure();
run_loop.Run(); run_loop.Run();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h" #include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/content_paths.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_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "mojo/public/c/system/data_pipe.h" #include "mojo/public/c/system/data_pipe.h"
...@@ -75,7 +76,12 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { ...@@ -75,7 +76,12 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
browser_context_(new TestBrowserContext()), browser_context_(new TestBrowserContext()),
resource_message_filter_(new ResourceMessageFilter( resource_message_filter_(new ResourceMessageFilter(
0, 0,
0, // 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,
nullptr, nullptr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment