Commit 2cf2db5a authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Convert tests to use the NavigationSimulator.

In content/, this CL replace every renderer-initiated navigations
started with TestRenderFrameHost::SimulateNavigationStart() with a
navigation using the NavigationSimulator.

Bug: 728571

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_site_isolation;master.tryserver.chromium.linux:linux_chromium_browser_side_navigation_rel
Change-Id: Ibe7bf13c645d202af1a7bb1dd9aecdc20a50d288
Reviewed-on: https://chromium-review.googlesource.com/574865
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488625}
parent e5ed82db
......@@ -45,6 +45,7 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_side_navigation_test_utils.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_notification_tracker.h"
#include "content/public/test/test_utils.h"
#include "content/test/test_render_frame_host.h"
......@@ -1268,6 +1269,7 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
int entry_id = controller.GetPendingEntry()->GetUniqueID();
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigate(entry_id, true, kExistingURL);
main_test_rfh()->OnMessageReceived(FrameHostMsg_DidStopLoading(0));
EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0;
......@@ -1279,19 +1281,23 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
// Now make a pending new navigation, initiated by the renderer.
const GURL kNewURL("http://foo/bee");
main_test_rfh()->SimulateNavigationStart(kNewURL);
auto navigation =
NavigationSimulator::CreateRendererInitiated(kNewURL, main_test_rfh());
navigation->Start();
EXPECT_EQ(0U, notifications.size());
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(1, delegate->navigation_state_change_count());
// The delegate should have been notified twice: once for the loading state
// change, and once for the url change.
EXPECT_EQ(2, delegate->navigation_state_change_count());
// The visible entry should be the last committed URL, not the pending one.
EXPECT_EQ(kExistingURL, controller.GetVisibleEntry()->GetURL());
// Now the navigation redirects.
const GURL kRedirectURL("http://foo/see");
main_test_rfh()->SimulateRedirect(kRedirectURL);
navigation->Redirect(kRedirectURL);
// We don't want to change the NavigationEntry's url, in case it cancels.
// Prevents regression of http://crbug.com/77786.
......@@ -1299,14 +1305,16 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
// It may abort before committing, if it's a download or due to a stop or
// a new navigation from the user.
main_test_rfh()->SimulateNavigationError(kRedirectURL, net::ERR_ABORTED);
navigation->Fail(net::ERR_ABORTED);
// Because the pending entry is renderer initiated and not visible, we
// clear it when it fails.
EXPECT_EQ(-1, controller.GetPendingEntryIndex());
EXPECT_FALSE(controller.GetPendingEntry());
EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(2, delegate->navigation_state_change_count());
// The delegate should have been notified twice: once for the loading state
// change, and once for the url change.
EXPECT_EQ(4, delegate->navigation_state_change_count());
// The visible entry should be the last committed URL, not the pending one,
// so that no spoof is possible.
......
......@@ -18,6 +18,7 @@
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/test/test_render_frame_host.h"
......@@ -402,7 +403,9 @@ TEST_F(RenderProcessHostUnitTest, ReuseNavigationProcess) {
// Start a navigation. Now Getting RenderProcessHost with the
// REUSE_PENDING_OR_COMMITTED_SITE policy should return the current process.
main_test_rfh()->SimulateNavigationStart(kUrl1);
auto navigation =
NavigationSimulator::CreateRendererInitiated(kUrl1, main_test_rfh());
navigation->Start();
site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl1);
site_instance->set_process_reuse_policy(
SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE);
......@@ -411,8 +414,7 @@ TEST_F(RenderProcessHostUnitTest, ReuseNavigationProcess) {
// Finish the navigation and start a new cross-site one. Getting
// RenderProcessHost with the REUSE_PENDING_OR_COMMITTED_SITE policy should
// return the process of the speculative RenderFrameHost.
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigate(0, true, kUrl1);
navigation->Commit();
contents()->GetController().LoadURL(kUrl2, Referrer(),
ui::PAGE_TRANSITION_TYPED, std::string());
main_test_rfh()->SendBeforeUnloadACK(true);
......@@ -693,7 +695,9 @@ TEST_F(RenderProcessHostUnitTest, ReuseExpectedSiteURLChanges) {
// Start a navigation. Getting a RenderProcessHost with the
// REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the
// main RFH.
main_test_rfh()->SimulateNavigationStart(kUrl);
auto navigation =
NavigationSimulator::CreateRendererInitiated(kUrl, main_test_rfh());
navigation->Start();
site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl);
site_instance->set_process_reuse_policy(
SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE);
......@@ -714,8 +718,7 @@ TEST_F(RenderProcessHostUnitTest, ReuseExpectedSiteURLChanges) {
// Have the navigation commit. Getting a RenderProcessHost with the
// REUSE_PENDING_OR_COMMITTED_SITE policy should now return the process of the
// main RFH, as it was registered with the modified site URL at commit time.
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigate(0, true, kUrl);
navigation->Commit();
site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl);
site_instance->set_process_reuse_policy(
SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE);
......
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