Commit df6321bf authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Replace NavigationURLLoader unittest [2/n]

With NavigationMojoResponse (or the NetworkService), the
NavigationURLLoader implementation is no more the
NavigationURLLoaderImpl but the NavigationURLLoaderNetworkService. Some
NavigationURLLoader unittests needs to be rewritten.

This CL removes NavigationURLLoaderTest.RequestBlocked and adds
BrowserSideNavigationBrowserTest.RequestBlockedByResourceDispatcherHostDelegate.

Design doc: https://goo.gl/Rrrc7n (NavigationMojoResponse)

Bug: 705744
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I2c2788e25182d8c3302daf77557160fa57313b84
Reviewed-on: https://chromium-review.googlesource.com/867951
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533699}
parent f55fc475
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/common/frame_messages.h" #include "content/common/frame_messages.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -40,6 +41,22 @@ ...@@ -40,6 +41,22 @@
namespace content { namespace content {
namespace {
class RequestBlockingResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
// ResourceDispatcherHostDelegate implementation:
bool ShouldBeginRequest(const std::string& method,
const GURL& url,
ResourceType resource_type,
ResourceContext* resource_context) override {
return false;
}
};
} // namespace
// Test with BrowserSideNavigation enabled (aka PlzNavigate). // Test with BrowserSideNavigation enabled (aka PlzNavigate).
// If you don't need a custom embedded test server, please use the next class // If you don't need a custom embedded test server, please use the next class
// below (BrowserSideNavigationBrowserTest), it will automatically start the // below (BrowserSideNavigationBrowserTest), it will automatically start the
...@@ -849,4 +866,41 @@ IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, ...@@ -849,4 +866,41 @@ IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
} }
} }
// Requests not allowed by a ResourceDispatcherHostDelegate must be aborted.
IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
RequestBlockedByResourceDispatcherHostDelegate) {
// The Network Service doesn't use a ResourceDispatcherHost. A request can't
// be canceled by a ResourceDispatcherHostDelegate.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
return;
// Add a ResourceDispatcherHost blocking every requests.
RequestBlockingResourceDispatcherHostDelegate delegate;
base::RunLoop loop;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(
[](base::OnceClosure resume,
ResourceDispatcherHostDelegate* delegate) {
ResourceDispatcherHost::Get()->SetDelegate(delegate);
std::move(resume).Run();
},
loop.QuitClosure(), &delegate));
loop.Run();
// Navigate somewhere. The navigation will be aborted.
GURL simple_url(embedded_test_server()->GetURL("/simple_page.html"));
TestNavigationManager manager(shell()->web_contents(), simple_url);
NavigationHandleObserver handle_observer(shell()->web_contents(), simple_url);
shell()->LoadURL(simple_url);
EXPECT_TRUE(manager.WaitForRequestStart());
EXPECT_FALSE(manager.WaitForResponse());
manager.WaitForNavigationFinished();
EXPECT_FALSE(handle_observer.has_committed());
EXPECT_TRUE(handle_observer.is_error());
EXPECT_EQ(net::ERR_ABORTED, handle_observer.net_error_code());
}
} // namespace content } // namespace content
...@@ -71,18 +71,6 @@ class StreamProtocolHandler ...@@ -71,18 +71,6 @@ class StreamProtocolHandler
DISALLOW_COPY_AND_ASSIGN(StreamProtocolHandler); DISALLOW_COPY_AND_ASSIGN(StreamProtocolHandler);
}; };
class RequestBlockingResourceDispatcherHostDelegate
: public ResourceDispatcherHostDelegate {
public:
// ResourceDispatcherHostDelegate implementation:
bool ShouldBeginRequest(const std::string& method,
const GURL& url,
ResourceType resource_type,
ResourceContext* resource_context) override {
return false;
}
};
std::unique_ptr<ResourceHandler> CreateTestResourceHandler( std::unique_ptr<ResourceHandler> CreateTestResourceHandler(
net::URLRequest* request) { net::URLRequest* request) {
return std::make_unique<TestResourceHandler>(); return std::make_unique<TestResourceHandler>();
...@@ -351,26 +339,6 @@ TEST_F(NavigationURLLoaderTest, CancelByContext) { ...@@ -351,26 +339,6 @@ TEST_F(NavigationURLLoaderTest, CancelByContext) {
EXPECT_EQ(1, delegate.on_request_handled_counter()); EXPECT_EQ(1, delegate.on_request_handled_counter());
} }
// Tests that, if the request is blocked by the ResourceDispatcherHostDelegate,
// the caller is informed appropriately.
TEST_F(NavigationURLLoaderTest, RequestBlocked) {
RequestBlockingResourceDispatcherHostDelegate rdh_delegate;
host_.SetDelegate(&rdh_delegate);
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader =
MakeTestLoader(net::URLRequestTestJob::test_url_1(), &delegate);
// Wait for the request to fail as expected.
delegate.WaitForRequestFailed();
EXPECT_EQ(net::ERR_ABORTED, delegate.net_error());
// Failing before start means OnRequestStarted is never called.
EXPECT_EQ(0, delegate.on_request_handled_counter());
host_.SetDelegate(nullptr);
}
// Tests that ownership leaves the loader once the response is received. // Tests that ownership leaves the loader once the response is received.
TEST_F(NavigationURLLoaderTest, LoaderDetached) { TEST_F(NavigationURLLoaderTest, LoaderDetached) {
// Fake a top-level request to a URL whose body does not load immediately. // Fake a top-level request to a URL whose body does not load immediately.
......
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