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

Replace NavigationURLLoader unittest [3/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.LoaderDetached and adds
BrowserSideNavigationBrowserTest.FetchResponseAfterNavigationURLLoaderDeleted.

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

Bug: 705744
Change-Id: I0c133c5f464d483df187c111853031766218e7a1
Reviewed-on: https://chromium-review.googlesource.com/868136
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533700}
parent df6321bf
...@@ -536,6 +536,55 @@ IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, BackFollowedByReload) { ...@@ -536,6 +536,55 @@ IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, BackFollowedByReload) {
EXPECT_EQ(url2, shell()->web_contents()->GetLastCommittedURL()); EXPECT_EQ(url2, shell()->web_contents()->GetLastCommittedURL());
} }
// Test that a navigation response can be entirely fetched, even after the
// NavigationURLLoader has been deleted.
IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBaseBrowserTest,
FetchResponseAfterNavigationURLLoaderDeleted) {
net::test_server::ControllableHttpResponse response(embedded_test_server(),
"/main_document");
ASSERT_TRUE(embedded_test_server()->Start());
// Load a new document.
GURL url(embedded_test_server()->GetURL("/main_document"));
TestNavigationManager navigation_manager(shell()->web_contents(), url);
shell()->LoadURL(url);
// The navigation starts.
EXPECT_TRUE(navigation_manager.WaitForRequestStart());
navigation_manager.ResumeNavigation();
// A NavigationRequest exists at this point.
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetMainFrame()
->frame_tree_node();
EXPECT_TRUE(root->navigation_request());
// The response's headers are received.
response.WaitForRequest();
response.Send(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html; charset=utf-8\r\n"
"\r\n"
"...");
EXPECT_TRUE(navigation_manager.WaitForResponse());
navigation_manager.ResumeNavigation();
// The renderer commits the navigation and the browser deletes its
// NavigationRequest.
navigation_manager.WaitForNavigationFinished();
EXPECT_FALSE(root->navigation_request());
// The NavigationURLLoader has been deleted by now. Check that the renderer
// can still receive more bytes.
DOMMessageQueue dom_message_queue(WebContents::FromRenderFrameHost(
shell()->web_contents()->GetMainFrame()));
response.Send(
"<script>window.domAutomationController.send('done');</script>");
std::string done;
EXPECT_TRUE(dom_message_queue.WaitForMessage(&done));
EXPECT_EQ("\"done\"", done);
}
// Navigation are started in the browser process. After the headers are // Navigation are started in the browser process. After the headers are
// received, the URLLoaderClient is transfered from the browser process to the // received, the URLLoaderClient is transfered from the browser process to the
// renderer process. This test ensures that when the the URLLoader is deleted // renderer process. This test ensures that when the the URLLoader is deleted
......
...@@ -339,33 +339,6 @@ TEST_F(NavigationURLLoaderTest, CancelByContext) { ...@@ -339,33 +339,6 @@ TEST_F(NavigationURLLoaderTest, CancelByContext) {
EXPECT_EQ(1, delegate.on_request_handled_counter()); EXPECT_EQ(1, delegate.on_request_handled_counter());
} }
// Tests that ownership leaves the loader once the response is received.
TEST_F(NavigationURLLoaderTest, LoaderDetached) {
// Fake a top-level request to a URL whose body does not load immediately.
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader =
MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate);
// Wait for the response to come back.
delegate.WaitForResponseStarted();
// Proceed with the response.
loader->ProceedWithResponse();
// Check the response is correct.
EXPECT_EQ("text/html", delegate.response()->head.mime_type);
EXPECT_EQ(200, delegate.response()->head.headers->response_code());
// Destroy the loader.
loader.reset();
base::RunLoop().RunUntilIdle();
// Check the body can still be fetched through the StreamHandle.
EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
EXPECT_EQ(net::URLRequestTestJob::test_data_2(),
FetchURL(delegate.body()->GetURL()));
}
// Tests that the request is owned by the body StreamHandle. // Tests that the request is owned by the body StreamHandle.
TEST_F(NavigationURLLoaderTest, OwnedByHandle) { TEST_F(NavigationURLLoaderTest, OwnedByHandle) {
// 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