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