Commit 55275645 authored by pfeldman's avatar pfeldman Committed by Commit bot

Test runner: make inspector tests reuse a single inspector process.

BUG=454481

Review URL: https://codereview.chromium.org/870883008

Cr-Commit-Position: refs/heads/master@{#314358}
parent 74a89f06
...@@ -33,15 +33,6 @@ LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( ...@@ -33,15 +33,6 @@ LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show(
return devtools_frontend; return devtools_frontend;
} }
LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend(
Shell* frontend_shell,
DevToolsAgentHost* agent_host)
: ShellDevToolsFrontend(frontend_shell, agent_host) {
}
LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() {
}
// static. // static.
GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL( GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
const std::string& settings, const std::string& settings,
...@@ -70,6 +61,27 @@ GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL( ...@@ -70,6 +61,27 @@ GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
return result; return result;
} }
void LayoutTestDevToolsFrontend::ReuseFrontend(WebContents* inspected_contents,
const std::string& settings,
const std::string frontend_url) {
AttachTo(inspected_contents);
frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
}
LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend(
Shell* frontend_shell,
DevToolsAgentHost* agent_host)
: ShellDevToolsFrontend(frontend_shell, agent_host) {
}
LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() {
}
void LayoutTestDevToolsFrontend::AgentHostClosed(
DevToolsAgentHost* agent_host, bool replaced) {
// Do not close the front-end shell.
}
void LayoutTestDevToolsFrontend::RenderProcessGone( void LayoutTestDevToolsFrontend::RenderProcessGone(
base::TerminationStatus status) { base::TerminationStatus status) {
WebKitTestController::Get()->DevToolsProcessCrashed(); WebKitTestController::Get()->DevToolsProcessCrashed();
......
...@@ -24,11 +24,18 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend { ...@@ -24,11 +24,18 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend {
static GURL GetDevToolsPathAsURL(const std::string& settings, static GURL GetDevToolsPathAsURL(const std::string& settings,
const std::string& frontend_url); const std::string& frontend_url);
void ReuseFrontend(WebContents* inspected_contents,
const std::string& settings,
const std::string frontend_url);
private: private:
LayoutTestDevToolsFrontend(Shell* frontend_shell, LayoutTestDevToolsFrontend(Shell* frontend_shell,
DevToolsAgentHost* agent_host); DevToolsAgentHost* agent_host);
~LayoutTestDevToolsFrontend() override; ~LayoutTestDevToolsFrontend() override;
// content::DevToolsAgentHostClient implementation.
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
// WebContentsObserver implementation. // WebContentsObserver implementation.
void RenderProcessGone(base::TerminationStatus status) override; void RenderProcessGone(base::TerminationStatus status) override;
......
...@@ -248,19 +248,14 @@ void Shell::UpdateNavigationControls(bool to_different_document) { ...@@ -248,19 +248,14 @@ void Shell::UpdateNavigationControls(bool to_different_document) {
} }
void Shell::ShowDevTools() { void Shell::ShowDevTools() {
InnerShowDevTools("", ""); InnerShowDevTools();
} }
void Shell::ShowDevToolsForElementAt(int x, int y) { void Shell::ShowDevToolsForElementAt(int x, int y) {
InnerShowDevTools("", ""); InnerShowDevTools();
devtools_frontend_->InspectElementAt(x, y); devtools_frontend_->InspectElementAt(x, y);
} }
void Shell::ShowDevToolsForTest(const std::string& settings,
const std::string& frontend_url) {
InnerShowDevTools(settings, frontend_url);
}
void Shell::CloseDevTools() { void Shell::CloseDevTools() {
if (!devtools_frontend_) if (!devtools_frontend_)
return; return;
...@@ -418,16 +413,9 @@ void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) { ...@@ -418,16 +413,9 @@ void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
PlatformSetTitle(entry->GetTitle()); PlatformSetTitle(entry->GetTitle());
} }
void Shell::InnerShowDevTools(const std::string& settings, void Shell::InnerShowDevTools() {
const std::string& frontend_url) {
if (!devtools_frontend_) { if (!devtools_frontend_) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch( devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
switches::kDumpRenderTree)) {
devtools_frontend_ = LayoutTestDevToolsFrontend::Show(
web_contents(), settings, frontend_url);
} else {
devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
}
devtools_observer_.reset(new DevToolsWebContentsObserver( devtools_observer_.reset(new DevToolsWebContentsObserver(
this, devtools_frontend_->frontend_shell()->web_contents())); this, devtools_frontend_->frontend_shell()->web_contents()));
} }
......
...@@ -70,8 +70,6 @@ class Shell : public WebContentsDelegate, ...@@ -70,8 +70,6 @@ class Shell : public WebContentsDelegate,
void Close(); void Close();
void ShowDevTools(); void ShowDevTools();
void ShowDevToolsForElementAt(int x, int y); void ShowDevToolsForElementAt(int x, int y);
void ShowDevToolsForTest(const std::string& settings,
const std::string& frontend_url);
void CloseDevTools(); void CloseDevTools();
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Resizes the web content view to the given dimensions. // Resizes the web content view to the given dimensions.
...@@ -216,8 +214,7 @@ class Shell : public WebContentsDelegate, ...@@ -216,8 +214,7 @@ class Shell : public WebContentsDelegate,
// WebContentsObserver // WebContentsObserver
void TitleWasSet(NavigationEntry* entry, bool explicit_set) override; void TitleWasSet(NavigationEntry* entry, bool explicit_set) override;
void InnerShowDevTools(const std::string& settings, void InnerShowDevTools();
const std::string& frontend_url);
void OnDevToolsWebContentsDestroyed(); void OnDevToolsWebContentsDestroyed();
scoped_ptr<ShellJavaScriptDialogManager> dialog_manager_; scoped_ptr<ShellJavaScriptDialogManager> dialog_manager_;
......
...@@ -60,13 +60,21 @@ void ShellDevToolsFrontend::Focus() { ...@@ -60,13 +60,21 @@ void ShellDevToolsFrontend::Focus() {
} }
void ShellDevToolsFrontend::InspectElementAt(int x, int y) { void ShellDevToolsFrontend::InspectElementAt(int x, int y) {
agent_host_->InspectElement(x, y); if (agent_host_)
agent_host_->InspectElement(x, y);
} }
void ShellDevToolsFrontend::Close() { void ShellDevToolsFrontend::Close() {
frontend_shell_->Close(); frontend_shell_->Close();
} }
void ShellDevToolsFrontend::DisconnectFromTarget() {
if (!agent_host_)
return;
agent_host_->DetachClient();
agent_host_ = NULL;
}
ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell,
DevToolsAgentHost* agent_host) DevToolsAgentHost* agent_host)
: WebContentsObserver(frontend_shell->web_contents()), : WebContentsObserver(frontend_shell->web_contents()),
...@@ -82,17 +90,26 @@ void ShellDevToolsFrontend::RenderViewCreated( ...@@ -82,17 +90,26 @@ void ShellDevToolsFrontend::RenderViewCreated(
if (!frontend_host_) { if (!frontend_host_) {
frontend_host_.reset( frontend_host_.reset(
DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this)); DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this));
agent_host_->AttachClient(this);
} }
} }
void ShellDevToolsFrontend::DidNavigateMainFrame(
const LoadCommittedDetails& details,
const FrameNavigateParams& params) {
if (agent_host_)
agent_host_->AttachClient(this);
}
void ShellDevToolsFrontend::WebContentsDestroyed() { void ShellDevToolsFrontend::WebContentsDestroyed() {
agent_host_->DetachClient(); if (agent_host_)
agent_host_->DetachClient();
delete this; delete this;
} }
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
const std::string& message) { const std::string& message) {
if (!agent_host_)
return;
std::string method; std::string method;
int id = 0; int id = 0;
base::ListValue* params = NULL; base::ListValue* params = NULL;
...@@ -127,7 +144,8 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( ...@@ -127,7 +144,8 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
const std::string& message) { const std::string& message) {
agent_host_->DispatchProtocolMessage(message); if (agent_host_)
agent_host_->DispatchProtocolMessage(message);
} }
void ShellDevToolsFrontend::DispatchProtocolMessage( void ShellDevToolsFrontend::DispatchProtocolMessage(
...@@ -151,6 +169,11 @@ void ShellDevToolsFrontend::DispatchProtocolMessage( ...@@ -151,6 +169,11 @@ void ShellDevToolsFrontend::DispatchProtocolMessage(
} }
} }
void ShellDevToolsFrontend::AttachTo(WebContents* inspected_contents) {
DisconnectFromTarget();
agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents);
}
void ShellDevToolsFrontend::AgentHostClosed( void ShellDevToolsFrontend::AgentHostClosed(
DevToolsAgentHost* agent_host, bool replaced) { DevToolsAgentHost* agent_host, bool replaced) {
frontend_shell_->Close(); frontend_shell_->Close();
......
...@@ -30,15 +30,26 @@ class ShellDevToolsFrontend : public WebContentsObserver, ...@@ -30,15 +30,26 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void InspectElementAt(int x, int y); void InspectElementAt(int x, int y);
void Close(); void Close();
void DisconnectFromTarget();
Shell* frontend_shell() const { return frontend_shell_; } Shell* frontend_shell() const { return frontend_shell_; }
protected: protected:
ShellDevToolsFrontend(Shell* frontend_shell, DevToolsAgentHost* agent_host); ShellDevToolsFrontend(Shell* frontend_shell, DevToolsAgentHost* agent_host);
~ShellDevToolsFrontend() override; ~ShellDevToolsFrontend() override;
// content::DevToolsAgentHostClient implementation.
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
const std::string& message) override;
void AttachTo(WebContents* inspected_contents);
private: private:
// WebContentsObserver overrides // WebContentsObserver overrides
void RenderViewCreated(RenderViewHost* render_view_host) override; void RenderViewCreated(RenderViewHost* render_view_host) override;
void DidNavigateMainFrame(
const LoadCommittedDetails& details,
const FrameNavigateParams& params) override;
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
// content::DevToolsFrontendHost::Delegate implementation. // content::DevToolsFrontendHost::Delegate implementation.
...@@ -46,11 +57,6 @@ class ShellDevToolsFrontend : public WebContentsObserver, ...@@ -46,11 +57,6 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void HandleMessageFromDevToolsFrontendToBackend( void HandleMessageFromDevToolsFrontendToBackend(
const std::string& message) override; const std::string& message) override;
// content::DevToolsAgentHostClient implementation.
void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
const std::string& message) override;
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
Shell* frontend_shell_; Shell* frontend_shell_;
scoped_refptr<DevToolsAgentHost> agent_host_; scoped_refptr<DevToolsAgentHost> agent_host_;
scoped_ptr<DevToolsFrontendHost> frontend_host_; scoped_ptr<DevToolsFrontendHost> frontend_host_;
......
...@@ -205,7 +205,8 @@ WebKitTestController::WebKitTestController() ...@@ -205,7 +205,8 @@ WebKitTestController::WebKitTestController()
is_leak_detection_enabled_( is_leak_detection_enabled_(
base::CommandLine::ForCurrentProcess()->HasSwitch( base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLeakDetection)), switches::kEnableLeakDetection)),
crash_when_leak_found_(false) { crash_when_leak_found_(false),
devtools_frontend_(NULL) {
CHECK(!instance_); CHECK(!instance_);
instance_ = this; instance_ = this;
...@@ -433,7 +434,9 @@ void WebKitTestController::RenderProcessGone(base::TerminationStatus status) { ...@@ -433,7 +434,9 @@ void WebKitTestController::RenderProcessGone(base::TerminationStatus status) {
void WebKitTestController::DevToolsProcessCrashed() { void WebKitTestController::DevToolsProcessCrashed() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
printer_->AddErrorMessage("#CRASHED - devtools"); printer_->AddErrorMessage("#CRASHED - devtools");
DiscardMainWindow(); if (devtools_frontend_)
devtools_frontend_->Close();
devtools_frontend_ = NULL;
} }
void WebKitTestController::WebContentsDestroyed() { void WebKitTestController::WebContentsDestroyed() {
...@@ -586,11 +589,20 @@ void WebKitTestController::OnClearDevToolsLocalStorage() { ...@@ -586,11 +589,20 @@ void WebKitTestController::OnClearDevToolsLocalStorage() {
void WebKitTestController::OnShowDevTools(const std::string& settings, void WebKitTestController::OnShowDevTools(const std::string& settings,
const std::string& frontend_url) { const std::string& frontend_url) {
main_window_->ShowDevToolsForTest(settings, frontend_url); if (!devtools_frontend_) {
devtools_frontend_ = LayoutTestDevToolsFrontend::Show(
main_window_->web_contents(), settings, frontend_url);
} else {
devtools_frontend_->ReuseFrontend(
main_window_->web_contents(), settings, frontend_url);
}
devtools_frontend_->Activate();
devtools_frontend_->Focus();
} }
void WebKitTestController::OnCloseDevTools() { void WebKitTestController::OnCloseDevTools() {
main_window_->CloseDevTools(); if (devtools_frontend_)
devtools_frontend_->DisconnectFromTarget();
} }
void WebKitTestController::OnGoToOffset(int offset) { void WebKitTestController::OnGoToOffset(int offset) {
...@@ -653,8 +665,10 @@ void WebKitTestController::OnCaptureSessionHistory() { ...@@ -653,8 +665,10 @@ void WebKitTestController::OnCaptureSessionHistory() {
void WebKitTestController::OnCloseRemainingWindows() { void WebKitTestController::OnCloseRemainingWindows() {
DevToolsAgentHost::DetachAllClients(); DevToolsAgentHost::DetachAllClients();
std::vector<Shell*> open_windows(Shell::windows()); std::vector<Shell*> open_windows(Shell::windows());
Shell* devtools_shell = devtools_frontend_ ?
devtools_frontend_->frontend_shell() : NULL;
for (size_t i = 0; i < open_windows.size(); ++i) { for (size_t i = 0; i < open_windows.size(); ++i) {
if (open_windows[i] != main_window_) if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell)
open_windows[i]->Close(); open_windows[i]->Close();
} }
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
......
...@@ -28,6 +28,7 @@ class SkBitmap; ...@@ -28,6 +28,7 @@ class SkBitmap;
namespace content { namespace content {
class LayoutTestDevToolsFrontend;
class Shell; class Shell;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -214,6 +215,8 @@ class WebKitTestController : public base::NonThreadSafe, ...@@ -214,6 +215,8 @@ class WebKitTestController : public base::NonThreadSafe,
const bool is_leak_detection_enabled_; const bool is_leak_detection_enabled_;
bool crash_when_leak_found_; bool crash_when_leak_found_;
LayoutTestDevToolsFrontend* devtools_frontend_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Because of the nested message pump implementation, Android needs to allow // Because of the nested message pump implementation, Android needs to allow
// waiting on the UI thread while layout tests are being ran. // waiting on the UI thread while layout tests are being ran.
......
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