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