Commit df220aeb authored by Nasko Oskov's avatar Nasko Oskov Committed by Commit Bot

Move some NavigationController unit tests to use NavigationSimulator.

This CL updates some navigation unit tests to use the NavigationSimulator
code, which abstracts a lot of details in how navigation works away
and allows navigation unit tests to focus on the key properties to test
without lots of boilerplate code.

Bug: 918565
Change-Id: If13f329f8ffa8b051eb4fc9f912fadc23783700a
Reviewed-on: https://chromium-review.googlesource.com/c/1453582Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Commit-Queue: Nasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629584}
parent 0d3b226d
...@@ -1905,47 +1905,34 @@ TEST_F(NavigationControllerTest, Redirect) { ...@@ -1905,47 +1905,34 @@ TEST_F(NavigationControllerTest, Redirect) {
const GURL url2("http://foo2"); // Redirection target const GURL url2("http://foo2"); // Redirection target
// First request. // First request.
controller.LoadURL( auto navigation =
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
int entry_id = controller.GetPendingEntry()->GetUniqueID(); navigation->Start();
EXPECT_EQ(0U, navigation_entry_changed_counter_); EXPECT_EQ(0U, navigation_entry_changed_counter_);
EXPECT_EQ(0U, navigation_list_pruned_counter_); EXPECT_EQ(0U, navigation_list_pruned_counter_);
FrameHostMsg_DidCommitProvisionalLoad_Params params; navigation->Redirect(url2);
params.nav_entry_id = entry_id; navigation->Commit();
params.did_create_new_entry = true;
params.url = url2;
params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
params.redirects.push_back(GURL("http://foo1"));
params.redirects.push_back(GURL("http://foo2"));
params.should_update_history = false;
params.gesture = NavigationGestureAuto;
params.method = "GET";
params.page_state = PageState::CreateFromURL(url2);
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigateWithParams(&params, false);
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
// Second request. // Second request.
controller.LoadURL( auto navigation2 =
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
entry_id = controller.GetPendingEntry()->GetUniqueID(); navigation2->Start();
EXPECT_TRUE(controller.GetPendingEntry()); EXPECT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(controller.GetPendingEntryIndex(), -1); EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
params.nav_entry_id = entry_id;
params.did_create_new_entry = false;
EXPECT_EQ(0U, navigation_entry_changed_counter_); EXPECT_EQ(0U, navigation_entry_changed_counter_);
EXPECT_EQ(0U, navigation_list_pruned_counter_); EXPECT_EQ(0U, navigation_list_pruned_counter_);
LoadCommittedDetailsObserver observer(contents()); LoadCommittedDetailsObserver observer(contents());
main_test_rfh()->PrepareForCommit(); navigation2->set_did_create_new_entry(false);
main_test_rfh()->SendNavigateWithParams(&params, false); navigation2->Redirect(url2);
navigation2->Commit();
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
...@@ -1971,49 +1958,36 @@ TEST_F(NavigationControllerTest, PostThenRedirect) { ...@@ -1971,49 +1958,36 @@ TEST_F(NavigationControllerTest, PostThenRedirect) {
const GURL url2("http://foo2"); // Redirection target const GURL url2("http://foo2"); // Redirection target
// First request as POST. // First request as POST.
controller.LoadURL( auto navigation =
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
int entry_id = controller.GetPendingEntry()->GetUniqueID(); navigation->SetMethod("POST");
controller.GetVisibleEntry()->SetHasPostData(true); navigation->Start();
EXPECT_EQ(0U, navigation_entry_changed_counter_); EXPECT_EQ(0U, navigation_entry_changed_counter_);
EXPECT_EQ(0U, navigation_list_pruned_counter_); EXPECT_EQ(0U, navigation_list_pruned_counter_);
FrameHostMsg_DidCommitProvisionalLoad_Params params; navigation->Redirect(url2);
params.nav_entry_id = entry_id; navigation->Commit();
params.did_create_new_entry = true;
params.url = url2;
params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
params.redirects.push_back(GURL("http://foo1"));
params.redirects.push_back(GURL("http://foo2"));
params.should_update_history = false;
params.gesture = NavigationGestureAuto;
params.method = "POST";
params.page_state = PageState::CreateFromURL(url2);
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigateWithParams(&params, false);
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
// Second request. // Second request.
controller.LoadURL( auto navigation2 =
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
entry_id = controller.GetPendingEntry()->GetUniqueID(); navigation2->Start();
EXPECT_TRUE(controller.GetPendingEntry()); EXPECT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(controller.GetPendingEntryIndex(), -1); EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
params.nav_entry_id = entry_id;
params.did_create_new_entry = false;
params.method = "GET";
EXPECT_EQ(0U, navigation_entry_changed_counter_); EXPECT_EQ(0U, navigation_entry_changed_counter_);
EXPECT_EQ(0U, navigation_list_pruned_counter_); EXPECT_EQ(0U, navigation_list_pruned_counter_);
LoadCommittedDetailsObserver observer(contents()); LoadCommittedDetailsObserver observer(contents());
main_test_rfh()->PrepareForCommit(); navigation2->set_did_create_new_entry(false);
main_test_rfh()->SendNavigateWithParams(&params, false); navigation2->Redirect(GURL("http://foo2"));
navigation2->Commit();
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
...@@ -2038,32 +2012,19 @@ TEST_F(NavigationControllerTest, ImmediateRedirect) { ...@@ -2038,32 +2012,19 @@ TEST_F(NavigationControllerTest, ImmediateRedirect) {
const GURL url2("http://foo2"); // Redirection target const GURL url2("http://foo2"); // Redirection target
// First request // First request
controller.LoadURL( auto navigation =
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
int entry_id = controller.GetPendingEntry()->GetUniqueID(); navigation->Start();
EXPECT_TRUE(controller.GetPendingEntry()); EXPECT_TRUE(controller.GetPendingEntry());
EXPECT_EQ(controller.GetPendingEntryIndex(), -1); EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.nav_entry_id = entry_id;
params.did_create_new_entry = true;
params.url = url2;
params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
params.redirects.push_back(GURL("http://foo1"));
params.redirects.push_back(GURL("http://foo2"));
params.should_update_history = false;
params.gesture = NavigationGestureAuto;
params.method = "GET";
params.page_state = PageState::CreateFromURL(url2);
LoadCommittedDetailsObserver observer(contents());
EXPECT_EQ(0U, navigation_entry_changed_counter_); EXPECT_EQ(0U, navigation_entry_changed_counter_);
EXPECT_EQ(0U, navigation_list_pruned_counter_); EXPECT_EQ(0U, navigation_list_pruned_counter_);
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigateWithParams(&params, false); LoadCommittedDetailsObserver observer(contents());
navigation->Redirect(GURL("http://foo2"));
navigation->Commit();
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
...@@ -2141,55 +2102,15 @@ TEST_F(NavigationControllerTest, NewSubframe) { ...@@ -2141,55 +2102,15 @@ TEST_F(NavigationControllerTest, NewSubframe) {
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
// Prereq: add a subframe with an initial auto-subframe navigation. // Prereq: add a subframe with an initial auto-subframe navigation.
std::string unique_name("uniqueName0");
main_test_rfh()->OnCreateChildFrame(
process()->GetNextRoutingID(),
TestRenderFrameHost::CreateStubInterfaceProviderRequest(),
TestRenderFrameHost::CreateStubDocumentInterfaceBrokerRequest(),
TestRenderFrameHost::CreateStubDocumentInterfaceBrokerRequest(),
blink::WebTreeScopeType::kDocument, std::string(), unique_name, false,
base::UnguessableToken::Create(), blink::FramePolicy(),
FrameOwnerProperties(), blink::FrameOwnerElementType::kIframe);
TestRenderFrameHost* subframe = static_cast<TestRenderFrameHost*>(
contents()->GetFrameTree()->root()->child_at(0)->current_frame_host());
const GURL subframe_url("http://foo1/subframe"); const GURL subframe_url("http://foo1/subframe");
{ TestRenderFrameHost* subframe = main_test_rfh()->AppendChild("subframe");
FrameHostMsg_DidCommitProvisionalLoad_Params params; NavigationSimulator::NavigateAndCommitFromDocument(subframe_url, subframe);
params.nav_entry_id = 0; EXPECT_EQ(1u, navigation_entry_changed_counter_);
params.did_create_new_entry = false;
params.url = subframe_url;
params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
params.should_update_history = false;
params.gesture = NavigationGestureUser;
params.method = "GET";
params.page_state = PageState::CreateFromURL(subframe_url);
// Navigating should do nothing.
subframe->SendRendererInitiatedNavigationRequest(subframe_url, false);
subframe->PrepareForCommit();
subframe->SendNavigateWithParams(&params, false);
// We notify of a PageState update here rather than during UpdateState for
// auto subframe navigations.
EXPECT_EQ(1u, navigation_entry_changed_counter_);
}
// Now do a new navigation in the frame. // Now do a new navigation in the frame.
const GURL url2("http://foo2"); const GURL url2("http://foo2");
FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.nav_entry_id = 0;
params.did_create_new_entry = true;
params.url = url2;
params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
params.should_update_history = false;
params.gesture = NavigationGestureUser;
params.method = "GET";
params.page_state = PageState::CreateFromURL(url2);
LoadCommittedDetailsObserver observer(contents()); LoadCommittedDetailsObserver observer(contents());
subframe->SendRendererInitiatedNavigationRequest(url2, true); NavigationSimulator::NavigateAndCommitFromDocument(url2, subframe);
subframe->PrepareForCommit();
subframe->SendNavigateWithParams(&params, false);
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
EXPECT_EQ(url1, observer.previous_url()); EXPECT_EQ(url1, observer.previous_url());
......
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