Commit 026da0aa authored by erikchen's avatar erikchen Committed by Commit Bot

Uniform initialization for WebContents in layout tests.

This CL begins the process of removing initialization races from Blink layout
tests.

Prior to this CL, a newly created main_window_ used a different navigation
mechanism than a reused main_window_. The latter would use a navigation with
ui::PAGE_TRANSITION_LINK [with an already constructed renderer]. The former
would spawn a renderer during the ui::PAGE_TRANSITION_TYPED navigation to the
layout test URL. This caused races between IPCs that occur during renderer
construction, and IPCs that occur as a result of loading the layout test.

This CL doesn't fix these races yet -- it simply converts initialization to use
the same mechanism for both cases [using ui::PAGE_TRANSITION_LINK with an
already constructed renderer].

Change-Id: I5a21bfdd9a47425f1eb9579235da5ffb4fbc19f7
Bug: 889036, 889952
Reviewed-on: https://chromium-review.googlesource.com/1257683Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595944}
parent 209fc9a3
......@@ -387,9 +387,16 @@ bool BlinkTestController::PrepareForLayoutTest(
test_url_.spec().find("compositing/") != std::string::npos;
initial_size_ = Shell::GetShellDefaultSize();
if (!main_window_) {
main_window_ = content::Shell::CreateNewWindow(browser_context, GURL(),
nullptr, initial_size_);
main_window_ = content::Shell::CreateNewWindow(
browser_context, GURL(url::kAboutBlankURL), nullptr, initial_size_);
WebContentsObserver::Observe(main_window_->web_contents());
// The render frame host is constructed before the call to
// WebContentsObserver::Observe, so we need to manually handle the creation
// of the new render frame host.
HandleNewRenderFrameHost(
main_window_->web_contents()->GetRenderViewHost()->GetMainFrame());
if (is_devtools_protocol_test) {
devtools_protocol_test_bindings_.reset(
new DevToolsProtocolTestBindings(main_window_->web_contents()));
......@@ -398,10 +405,24 @@ bool BlinkTestController::PrepareForLayoutTest(
default_prefs_ = main_window_->web_contents()
->GetRenderViewHost()
->GetWebkitPreferences();
if (is_devtools_js_test)
if (is_devtools_js_test) {
LoadDevToolsJSTest();
else
main_window_->LoadURL(test_url_);
} else {
// Loading the URL will immediately start the layout test. Manually call
// LoadURLWithParams on the WebContents to avoid extraneous calls from
// content::Shell such as SetFocus(), which could race with the layout
// test.
NavigationController::LoadURLParams params(test_url_);
// Using PAGE_TRANSITION_LINK avoids a BrowsingInstance/process swap
// between layout tests.
params.transition_type =
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK);
// Clear history to purge the prior navigation to about:blank.
params.should_clear_history_list = true;
main_window_->web_contents()->GetController().LoadURLWithParams(params);
}
} else {
#if defined(OS_MACOSX)
// Shell::SizeTo is not implemented on all platforms.
......
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