Commit 045680dc authored by scottmg's avatar scottmg Committed by Commit bot

PlzNavigate: Fix DownloadRequestLimiterTest.DownloadRequestLimiter_RendererInitiated

Expose NavigateAndCommitRendererInitiated in TestRendererHost, use it to
fix download request limiter test for renderer-initiated case in
PlzNavigate.

R=clamy@chromium.org, dominickn@chromium.org
BUG=510836

Review-Url: https://codereview.chromium.org/2319733002
Cr-Commit-Position: refs/heads/master@{#417373}
parent d4faad4f
......@@ -239,12 +239,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
testing_delegate_.UpdateExpectations(action);
}
void NavigateAndCommitWithParams(
content::NavigationController::LoadURLParams& params) {
controller().LoadURLWithParams(params);
content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
}
scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
// Number of times ContinueDownload was invoked.
......@@ -364,12 +358,10 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
download_request_limiter_->GetDownloadStatus(web_contents()));
// Set up a renderer-initiated navigation to the same host.
content::NavigationController::LoadURLParams load_params(
GURL("http://foo.com/bar2"));
load_params.is_renderer_initiated = true;
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
load_params.referrer = content::Referrer();
NavigateAndCommitWithParams(load_params);
content::RenderFrameHostTester* rfh_tester =
content::RenderFrameHostTester::For(web_contents()->GetMainFrame());
rfh_tester->NavigateAndCommitRendererInitiated(1, true,
GURL("http://foo.com/bar2"));
LoadCompleted();
// The state should not be reset.
......@@ -377,15 +369,13 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
download_request_limiter_->GetDownloadStatus(web_contents()));
// Renderer-initiated nav to a different host shouldn't reset the state.
load_params.url = GURL("http://fooey.com/bar");
NavigateAndCommitWithParams(load_params);
rfh_tester->NavigateAndCommitRendererInitiated(2, true,
GURL("http://fooey.com/bar"));
LoadCompleted();
ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
download_request_limiter_->GetDownloadStatus(web_contents()));
// Set up a subframe. Navigations in the subframe shouldn't reset the state.
content::RenderFrameHostTester* rfh_tester =
content::RenderFrameHostTester::For(web_contents()->GetMainFrame());
content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe");
content::RenderFrameHostTester* subframe_tester =
content::RenderFrameHostTester::For(subframe);
......@@ -406,14 +396,14 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
// The state should not be reset on a renderer-initiated load to either the
// same host or a different host, in either the main frame or the subframe.
load_params.url = GURL("http://fooeybar.com/bar");
NavigateAndCommitWithParams(load_params);
rfh_tester->NavigateAndCommitRendererInitiated(
3, true, GURL("http://fooeybar.com/bar"));
LoadCompleted();
ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
download_request_limiter_->GetDownloadStatus(web_contents()));
load_params.url = GURL("http://foo.com/bar");
NavigateAndCommitWithParams(load_params);
rfh_tester->NavigateAndCommitRendererInitiated(4, true,
GURL("http://foo.com/bar"));
LoadCompleted();
ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
download_request_limiter_->GetDownloadStatus(web_contents()));
......@@ -451,8 +441,10 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
// The state should not be reset on a pending renderer-initiated load to
// the same host.
load_params.url = GURL("http://foobar.com/bar");
NavigateAndCommitWithParams(load_params);
rfh_tester =
content::RenderFrameHostTester::For(web_contents()->GetMainFrame());
rfh_tester->NavigateAndCommitRendererInitiated(5, true,
GURL("http://foobar.com/bar"));
LoadCompleted();
ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
download_request_limiter_->GetDownloadStatus(web_contents()));
......@@ -472,8 +464,8 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
// But a pending load to a different host in the main frame should reset the
// state.
load_params.url = GURL("http://foo.com");
NavigateAndCommitWithParams(load_params);
rfh_tester->NavigateAndCommitRendererInitiated(6, true,
GURL("http://foo.com"));
LoadCompleted();
ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
download_request_limiter_->GetDownloadStatus(web_contents()));
......
......@@ -127,6 +127,11 @@ class RenderFrameHostTester {
// Simulates the SwapOut_ACK that fires if you commit a cross-site
// navigation without making any network requests.
virtual void SimulateSwapOutACK() = 0;
// Simulate a renderer-initiated navigation up until commit.
virtual void NavigateAndCommitRendererInitiated(int page_id,
bool did_create_new_entry,
const GURL& url) = 0;
};
// An interface and utility for driving tests of RenderViewHost.
......
......@@ -231,6 +231,22 @@ void TestRenderFrameHost::SimulateSwapOutACK() {
OnSwappedOut();
}
void TestRenderFrameHost::NavigateAndCommitRendererInitiated(
int page_id,
bool did_create_new_entry,
const GURL& url) {
SendRendererInitiatedNavigationRequest(url, false);
// PlzNavigate: If no network request is needed by the navigation, then there
// will be no NavigationRequest, nor is it necessary to simulate the network
// stack commit.
if (frame_tree_node()->navigation_request())
PrepareForCommit();
bool browser_side_navigation = IsBrowserSideNavigationEnabled();
CHECK(!browser_side_navigation || is_loading());
CHECK(!browser_side_navigation || !frame_tree_node()->navigation_request());
SendNavigate(page_id, 0, did_create_new_entry, url);
}
void TestRenderFrameHost::SendNavigate(int page_id,
int nav_entry_id,
bool did_create_new_entry,
......@@ -365,22 +381,6 @@ void TestRenderFrameHost::SendNavigateWithParams(
OnDidCommitProvisionalLoad(msg);
}
void TestRenderFrameHost::NavigateAndCommitRendererInitiated(
int page_id,
bool did_create_new_entry,
const GURL& url) {
SendRendererInitiatedNavigationRequest(url, false);
// PlzNavigate: If no network request is needed by the navigation, then there
// will be no NavigationRequest, nor is it necessary to simulate the network
// stack commit.
if (frame_tree_node()->navigation_request())
PrepareForCommit();
bool browser_side_navigation = IsBrowserSideNavigationEnabled();
CHECK(!browser_side_navigation || is_loading());
CHECK(!browser_side_navigation || !frame_tree_node()->navigation_request());
SendNavigate(page_id, 0, did_create_new_entry, url);
}
void TestRenderFrameHost::SendRendererInitiatedNavigationRequest(
const GURL& url,
bool has_user_gesture) {
......
......@@ -79,6 +79,9 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
void SetContentsMimeType(const std::string& mime_type) override;
void SendBeforeUnloadACK(bool proceed) override;
void SimulateSwapOutACK() override;
void NavigateAndCommitRendererInitiated(int page_id,
bool did_create_new_entry,
const GURL& url) override;
void SendNavigateWithReplacement(int page_id,
int nav_entry_id,
......@@ -97,11 +100,6 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
void SendNavigateWithParams(
FrameHostMsg_DidCommitProvisionalLoad_Params* params);
// Simulate a renderer-initiated navigation up until commit.
void NavigateAndCommitRendererInitiated(int page_id,
bool did_create_new_entry,
const GURL& url);
// With the current navigation logic this method is a no-op.
// PlzNavigate: this method simulates receiving a BeginNavigation IPC.
void SendRendererInitiatedNavigationRequest(const GURL& url,
......
-DownloadRequestLimiterTest.DownloadRequestLimiter_RendererInitiated
-ExtensionProtocolTest.AllowFrameRequests
-ExtensionProtocolTest.IncognitoRequest
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