Commit 237ee066 authored by Camille Lamy's avatar Camille Lamy Committed by Commit Bot

Add support for custom PageState in NavigationSimulator

This CL allows to set a custom PageState in the NavigationSimulator and
converst one unit test that needed this functionality to using
NavigationSimulator.

Bug: 728571
Change-Id: Ie62b87f328f52e6ae51357a3ebfa9f295ea7ac80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569017Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Commit-Queue: Camille Lamy <clamy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652508}
parent 1e9f9a24
......@@ -26,6 +26,7 @@
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/test/mock_widget_impl.h"
#include "content/test/navigation_simulator_impl.h"
#include "content/test/test_content_browser_client.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
......@@ -240,35 +241,27 @@ TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) {
EXPECT_EQ(1, process()->bad_msg_count());
}
namespace {
void SetBadFilePath(const GURL& url,
const base::FilePath& file_path,
FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
params->page_state =
PageState::CreateForTesting(url, false, "data", &file_path);
}
}
TEST_F(RenderViewHostTest, NavigationWithBadHistoryItemFiles) {
GURL url("http://www.google.com");
base::FilePath file_path;
EXPECT_TRUE(base::PathService::Get(base::DIR_TEMP, &file_path));
file_path = file_path.AppendASCII("bar");
auto set_bad_file_path_callback = base::Bind(SetBadFilePath, url, file_path);
EXPECT_EQ(0, process()->bad_msg_count());
main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
main_test_rfh()->PrepareForCommit();
contents()->GetMainFrame()->SendNavigateWithModificationCallback(
1, true, url, set_bad_file_path_callback);
auto navigation1 =
NavigationSimulatorImpl::CreateRendererInitiated(url, main_test_rfh());
navigation1->set_page_state(
PageState::CreateForTesting(url, false, "data", &file_path));
navigation1->Commit();
EXPECT_EQ(1, process()->bad_msg_count());
ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
process()->GetID(), file_path);
main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false);
main_test_rfh()->PrepareForCommit();
contents()->GetMainFrame()->SendNavigateWithModificationCallback(
2, true, url, std::move(set_bad_file_path_callback));
auto navigation2 =
NavigationSimulatorImpl::CreateRendererInitiated(url, main_test_rfh());
navigation2->set_page_state(
PageState::CreateForTesting(url, false, "data", &file_path));
navigation2->Commit();
EXPECT_EQ(1, process()->bad_msg_count());
}
......
......@@ -1271,9 +1271,10 @@ NavigationSimulatorImpl::BuildDidCommitProvisionalLoadParams(
params->document_sequence_number = ++g_unique_identifier;
}
params->page_state = PageState::CreateForTestingWithSequenceNumbers(
navigation_url_, params->item_sequence_number,
params->document_sequence_number);
params->page_state =
page_state_.value_or(PageState::CreateForTestingWithSequenceNumbers(
navigation_url_, params->item_sequence_number,
params->document_sequence_number));
return params;
}
......
......@@ -147,6 +147,8 @@ class NavigationSimulatorImpl : public NavigationSimulator,
block_on_before_unload_ack_ = block_on_before_unload_ack;
}
void set_page_state(const PageState& page_state) { page_state_ = page_state; }
private:
NavigationSimulatorImpl(const GURL& original_url,
bool browser_initiated,
......@@ -271,6 +273,7 @@ class NavigationSimulatorImpl : public NavigationSimulator,
net::HttpResponseInfo::ConnectionInfo http_connection_info_ =
net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN;
base::Optional<net::SSLInfo> ssl_info_;
base::Optional<PageState> page_state_;
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