Commit ff74cd6f authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

DevTools: unflake the new devtools harness.

This changes reliably waits for the inspected page to be loaded prior to engaging for debugging.
Prior to this change, inspected page was racing with the test code and base was not reliably set
in the inspected page. Network service was making this race run in favor of the test script.

Bug: 
Change-Id: I709b2c0c2ddee1515cb5d4bf5c319aa7917b6f1b
Reviewed-on: https://chromium-review.googlesource.com/764402
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarWill Chen <chenwilliam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515758}
parent bd829cad
...@@ -469,11 +469,9 @@ Shell* BlinkTestController::SecondaryWindow() { ...@@ -469,11 +469,9 @@ Shell* BlinkTestController::SecondaryWindow() {
void BlinkTestController::LoadDevToolsJSTest() { void BlinkTestController::LoadDevToolsJSTest() {
devtools_window_ = main_window_; devtools_window_ = main_window_;
Shell* secondary = SecondaryWindow(); Shell* secondary = SecondaryWindow();
devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( devtools_bindings_ = base::MakeUnique<LayoutTestDevToolsBindings>(
devtools_window_->web_contents(), secondary->web_contents(), "", devtools_window_->web_contents(), secondary->web_contents(), "",
test_url_.spec())); test_url_, true);
secondary->LoadURL(
LayoutTestDevToolsBindings::GetInspectedPageURL(test_url_));
} }
bool BlinkTestController::ResetAfterLayoutTest() { bool BlinkTestController::ResetAfterLayoutTest() {
...@@ -970,9 +968,9 @@ void BlinkTestController::OnClearDevToolsLocalStorage() { ...@@ -970,9 +968,9 @@ void BlinkTestController::OnClearDevToolsLocalStorage() {
void BlinkTestController::OnShowDevTools(const std::string& settings, void BlinkTestController::OnShowDevTools(const std::string& settings,
const std::string& frontend_url) { const std::string& frontend_url) {
devtools_window_ = SecondaryWindow(); devtools_window_ = SecondaryWindow();
devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( devtools_bindings_ = base::MakeUnique<LayoutTestDevToolsBindings>(
devtools_window_->web_contents(), main_window_->web_contents(), settings, devtools_window_->web_contents(), main_window_->web_contents(), settings,
frontend_url)); GURL(frontend_url), false);
devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
devtools_window_->web_contents()->Focus(); devtools_window_->web_contents()->Focus();
} }
......
...@@ -19,8 +19,42 @@ ...@@ -19,8 +19,42 @@
#include "content/shell/common/layout_test/layout_test_switches.h" #include "content/shell/common/layout_test/layout_test_switches.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
namespace {
GURL GetInspectedPageURL(const GURL& test_url) {
std::string spec = test_url.spec();
std::string test_query_param = "&test=";
std::string test_script_url =
spec.substr(spec.find(test_query_param) + test_query_param.length());
std::string inspected_page_url = test_script_url.replace(
test_script_url.find("/devtools/"), std::string::npos,
"/devtools/resources/inspected-page.html");
return GURL(inspected_page_url);
}
} // namespace
namespace content { namespace content {
class LayoutTestDevToolsBindings::SecondaryObserver
: public WebContentsObserver {
public:
explicit SecondaryObserver(LayoutTestDevToolsBindings* bindings)
: WebContentsObserver(bindings->inspected_contents()),
bindings_(bindings) {}
// WebContentsObserver implementation.
void DocumentAvailableInMainFrame() override {
if (bindings_)
bindings_->NavigateDevToolsFrontend();
bindings_ = nullptr;
}
private:
LayoutTestDevToolsBindings* bindings_;
DISALLOW_COPY_AND_ASSIGN(SecondaryObserver);
};
// static. // static.
GURL LayoutTestDevToolsBindings::GetDevToolsPathAsURL( GURL LayoutTestDevToolsBindings::GetDevToolsPathAsURL(
const std::string& frontend_url) { const std::string& frontend_url) {
...@@ -73,35 +107,13 @@ GURL LayoutTestDevToolsBindings::MapTestURLIfNeeded(const GURL& test_url, ...@@ -73,35 +107,13 @@ GURL LayoutTestDevToolsBindings::MapTestURLIfNeeded(const GURL& test_url,
return GURL(url_string); return GURL(url_string);
} }
// static void LayoutTestDevToolsBindings::NavigateDevToolsFrontend() {
LayoutTestDevToolsBindings* LayoutTestDevToolsBindings::LoadDevTools( GURL devtools_url = GetDevToolsPathAsURL(frontend_url_.spec());
WebContents* devtools_contents_,
WebContents* inspected_contents_,
const std::string& settings,
const std::string& frontend_url) {
LayoutTestDevToolsBindings* bindings =
new LayoutTestDevToolsBindings(devtools_contents_, inspected_contents_);
bindings->SetPreferences(settings);
GURL devtools_url =
LayoutTestDevToolsBindings::GetDevToolsPathAsURL(frontend_url);
NavigationController::LoadURLParams params(devtools_url); NavigationController::LoadURLParams params(devtools_url);
params.transition_type = ui::PageTransitionFromInt( params.transition_type = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
bindings->web_contents()->GetController().LoadURLWithParams(params); web_contents()->GetController().LoadURLWithParams(params);
bindings->web_contents()->Focus(); web_contents()->Focus();
return bindings;
}
// static.
GURL LayoutTestDevToolsBindings::GetInspectedPageURL(const GURL& test_url) {
std::string spec = test_url.spec();
std::string test_query_param = "&test=";
std::string test_script_url =
spec.substr(spec.find(test_query_param) + test_query_param.length());
std::string inspected_page_url = test_script_url.replace(
test_script_url.find("/devtools/"), std::string::npos,
"/devtools/resources/inspected-page.html");
return GURL(inspected_page_url);
} }
void LayoutTestDevToolsBindings::EvaluateInFrontend(int call_id, void LayoutTestDevToolsBindings::EvaluateInFrontend(int call_id,
...@@ -122,9 +134,25 @@ void LayoutTestDevToolsBindings::EvaluateInFrontend(int call_id, ...@@ -122,9 +134,25 @@ void LayoutTestDevToolsBindings::EvaluateInFrontend(int call_id,
LayoutTestDevToolsBindings::LayoutTestDevToolsBindings( LayoutTestDevToolsBindings::LayoutTestDevToolsBindings(
WebContents* devtools_contents, WebContents* devtools_contents,
WebContents* inspected_contents) WebContents* inspected_contents,
const std::string& settings,
const GURL& frontend_url,
bool new_harness)
: ShellDevToolsBindings(devtools_contents, inspected_contents, nullptr), : ShellDevToolsBindings(devtools_contents, inspected_contents, nullptr),
ready_for_test_(false) {} frontend_url_(frontend_url) {
SetPreferences(settings);
if (new_harness) {
NavigationController::LoadURLParams params(
GetInspectedPageURL(frontend_url));
params.transition_type = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
inspected_contents->GetController().LoadURLWithParams(params);
secondary_observer_ = base::MakeUnique<SecondaryObserver>(this);
} else {
NavigateDevToolsFrontend();
}
}
LayoutTestDevToolsBindings::~LayoutTestDevToolsBindings() {} LayoutTestDevToolsBindings::~LayoutTestDevToolsBindings() {}
......
...@@ -20,20 +20,18 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings { ...@@ -20,20 +20,18 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings {
static GURL MapTestURLIfNeeded(const GURL& test_url, static GURL MapTestURLIfNeeded(const GURL& test_url,
bool* is_devtools_js_test); bool* is_devtools_js_test);
static GURL GetInspectedPageURL(const GURL& test_url); LayoutTestDevToolsBindings(WebContents* devtools_contents,
WebContents* inspected_contents,
const std::string& settings,
const GURL& frontend_url,
bool new_harness);
static LayoutTestDevToolsBindings* LoadDevTools(
WebContents* devtools_contents_,
WebContents* inspected_contents_,
const std::string& settings,
const std::string& frontend_url);
void EvaluateInFrontend(int call_id, const std::string& expression); void EvaluateInFrontend(int call_id, const std::string& expression);
~LayoutTestDevToolsBindings() override; ~LayoutTestDevToolsBindings() override;
private: private:
LayoutTestDevToolsBindings(WebContents* devtools_contents, class SecondaryObserver;
WebContents* inspected_contents);
// ShellDevToolsBindings overrides. // ShellDevToolsBindings overrides.
void HandleMessageFromDevToolsFrontend(const std::string& message) override; void HandleMessageFromDevToolsFrontend(const std::string& message) override;
...@@ -42,8 +40,12 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings { ...@@ -42,8 +40,12 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings {
void RenderProcessGone(base::TerminationStatus status) override; void RenderProcessGone(base::TerminationStatus status) override;
void RenderFrameCreated(RenderFrameHost* render_frame_host) override; void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
bool ready_for_test_; void NavigateDevToolsFrontend();
bool ready_for_test_ = false;
GURL frontend_url_;
std::vector<std::pair<int, std::string>> pending_evaluations_; std::vector<std::pair<int, std::string>> pending_evaluations_;
std::unique_ptr<SecondaryObserver> secondary_observer_;
DISALLOW_COPY_AND_ASSIGN(LayoutTestDevToolsBindings); DISALLOW_COPY_AND_ASSIGN(LayoutTestDevToolsBindings);
}; };
......
...@@ -53,6 +53,8 @@ class ShellDevToolsBindings : public WebContentsObserver, ...@@ -53,6 +53,8 @@ class ShellDevToolsBindings : public WebContentsObserver,
const base::Value* arg3); const base::Value* arg3);
~ShellDevToolsBindings() override; ~ShellDevToolsBindings() override;
WebContents* inspected_contents() { return inspected_contents_; }
protected: protected:
// content::DevToolsAgentHostClient implementation. // content::DevToolsAgentHostClient implementation.
void AgentHostClosed(DevToolsAgentHost* agent_host) override; void AgentHostClosed(DevToolsAgentHost* agent_host) override;
......
...@@ -183,6 +183,11 @@ crbug.com/764474 http/tests/security/contentSecurityPolicy/1.1/plugintypes-affec ...@@ -183,6 +183,11 @@ crbug.com/764474 http/tests/security/contentSecurityPolicy/1.1/plugintypes-affec
crbug.com/764474 fast/loader/reload-zero-byte-plugin.html [ Failure ] crbug.com/764474 fast/loader/reload-zero-byte-plugin.html [ Failure ]
crbug.com/764474 plugins/plugin-document-back-forward.html [ Crash Failure Timeout ] crbug.com/764474 plugins/plugin-document-back-forward.html [ Crash Failure Timeout ]
# DevTools crbug.com/783982
crbug.com/783982 http/tests/devtools/startup/console/console-uncaught-promise-no-inspector.html [ Failure ]
crbug.com/783982 http/tests/devtools/elements/styles-2/property-ui-location.html [ Failure ]
crbug.com/783982 http/tests/devtools/elements/styles-1/empty-background-url.html [ Failure ]
# http/tests/fetch # http/tests/fetch
crbug.com/778721 http/tests/fetch/serviceworker-proxied/thorough/auth-base-https-other-https.html [ Pass Failure Timeout ] crbug.com/778721 http/tests/fetch/serviceworker-proxied/thorough/auth-base-https-other-https.html [ Pass Failure Timeout ]
crbug.com/778721 http/tests/fetch/serviceworker-proxied/thorough/cookie-nocors-other-https.html [ Pass Failure Timeout ] crbug.com/778721 http/tests/fetch/serviceworker-proxied/thorough/cookie-nocors-other-https.html [ Pass Failure Timeout ]
......
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