Commit bc67cf4f authored by Camille Lamy's avatar Camille Lamy Committed by Commit Bot

Improve POST support in NavigationSimulator

This CL ensures that we can simulate browser-initiated POST navigations
in NavigationSimulator as well as set a post id.

Bug: 728571
Change-Id: I9f5bf213a06feedf76a9b8102736bdafc08d504e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578571
Commit-Queue: Camille Lamy <clamy@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653546}
parent 6ae4926d
......@@ -785,19 +785,10 @@ TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) {
const GURL url1("http://foo1");
controller.LoadURL(
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
FrameHostMsg_DidCommitProvisionalLoad_Params params;
params.nav_entry_id = controller.GetPendingEntry()->GetUniqueID();
params.did_create_new_entry = true;
params.url = url1;
params.transition = ui::PAGE_TRANSITION_TYPED;
params.method = "POST";
params.post_id = 123;
params.page_state =
PageState::CreateForTesting(url1, false, nullptr, nullptr);
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigateWithParams(&params, false);
auto navigation1 =
NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
navigation1->SetIsPostWithId(123);
navigation1->Commit();
// The post data should be visible.
NavigationEntry* entry = controller.GetVisibleEntry();
......@@ -805,19 +796,17 @@ TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) {
EXPECT_TRUE(entry->GetHasPostData());
EXPECT_EQ(entry->GetPostID(), 123);
controller.LoadURL(
url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
main_test_rfh()->PrepareForCommit();
main_test_rfh()->SendNavigateWithTransition(
controller.GetPendingEntry()->GetUniqueID(),
false, url1, ui::PAGE_TRANSITION_TYPED);
auto navigation2 =
NavigationSimulatorImpl::CreateBrowserInitiated(url1, contents());
navigation2->set_did_create_new_entry(false);
navigation2->Commit();
// We should not have produced a new session history entry.
ASSERT_EQ(controller.GetVisibleEntry(), entry);
// The post data should have been cleared due to the GET.
EXPECT_FALSE(entry->GetHasPostData());
EXPECT_EQ(entry->GetPostID(), 0);
EXPECT_EQ(entry->GetPostID(), -1);
}
// Tests loading a URL but discarding it before the load commits.
......@@ -1468,6 +1457,7 @@ TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) {
// Fake a commit response.
navigation->set_should_replace_current_entry(true);
navigation->Commit();
// Certain values that are only used for pending entries get reset after
// commit.
......
......@@ -349,6 +349,11 @@ NavigationSimulatorImpl::NavigationSimulatorImpl(
NavigationSimulatorImpl::~NavigationSimulatorImpl() {}
void NavigationSimulatorImpl::SetIsPostWithId(int64_t post_id) {
post_id_ = post_id;
SetMethod("POST");
}
void NavigationSimulatorImpl::InitializeFromStartedRequest(
NavigationRequest* request) {
CHECK(request);
......@@ -907,8 +912,13 @@ void NavigationSimulatorImpl::BrowserInitiatedStartAndWaitBeforeUnload() {
web_contents_->GetController().LoadURLWithParams(*load_url_params_);
load_url_params_ = nullptr;
} else {
web_contents_->GetController().LoadURL(navigation_url_, referrer_,
transition_, std::string());
NavigationController::LoadURLParams load_url_params(navigation_url_);
load_url_params.referrer = referrer_;
load_url_params.transition_type = transition_;
if (initial_method_ == "POST")
load_url_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST;
web_contents_->GetController().LoadURLWithParams(load_url_params);
}
}
......@@ -1240,6 +1250,7 @@ NavigationSimulatorImpl::BuildDidCommitProvisionalLoadParams(
params->navigation_token = request_
? request_->commit_params().navigation_token
: base::UnguessableToken::Create();
params->post_id = post_id_;
if (intended_as_new_entry_.has_value())
params->intended_as_new_entry = intended_as_new_entry_.value();
......
......@@ -151,6 +151,8 @@ class NavigationSimulatorImpl : public NavigationSimulator,
void set_origin(const url::Origin& origin) { origin_ = origin; }
void SetIsPostWithId(int64_t post_id);
private:
NavigationSimulatorImpl(const GURL& original_url,
bool browser_initiated,
......@@ -277,6 +279,7 @@ class NavigationSimulatorImpl : public NavigationSimulator,
base::Optional<net::SSLInfo> ssl_info_;
base::Optional<PageState> page_state_;
base::Optional<url::Origin> origin_;
int64_t post_id_ = -1;
bool auto_advance_ = true;
bool drop_swap_out_ack_ = false;
......
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