Commit fee9eca0 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: by default, open devtools panel matching the layout test folder.

BUG=335790

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251387 0039d316-1c4b-4281-b951-d872f2087c98
parent fb1a9cc0
......@@ -215,21 +215,18 @@ void Shell::UpdateNavigationControls() {
}
void Shell::ShowDevTools() {
if (!devtools_frontend_) {
devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents());
devtools_observer_.reset(new DevToolsWebContentsObserver(
this, devtools_frontend_->frontend_shell()->web_contents()));
}
devtools_frontend_->Activate();
devtools_frontend_->Focus();
InnerShowDevTools("");
}
void Shell::ShowDevToolsForElementAt(int x, int y) {
ShowDevTools();
InnerShowDevTools("");
devtools_frontend_->InspectElementAt(x, y);
}
void Shell::ShowDevToolsForTest(const std::string& settings) {
InnerShowDevTools(settings);
}
void Shell::CloseDevTools() {
if (!devtools_frontend_)
return;
......@@ -366,6 +363,17 @@ void Shell::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
PlatformSetTitle(entry->GetTitle());
}
void Shell::InnerShowDevTools(const std::string& settings) {
if (!devtools_frontend_) {
devtools_frontend_ = ShellDevToolsFrontend::Show(web_contents(), settings);
devtools_observer_.reset(new DevToolsWebContentsObserver(
this, devtools_frontend_->frontend_shell()->web_contents()));
}
devtools_frontend_->Activate();
devtools_frontend_->Focus();
}
void Shell::OnDevToolsWebContentsDestroyed() {
devtools_observer_.reset();
devtools_frontend_ = NULL;
......
......@@ -69,6 +69,7 @@ class Shell : public WebContentsDelegate,
void Close();
void ShowDevTools();
void ShowDevToolsForElementAt(int x, int y);
void ShowDevToolsForTest(const std::string& settings);
void CloseDevTools();
#if defined(TOOLKIT_GTK) || defined(OS_MACOSX)
// Resizes the main window to the given dimensions.
......@@ -212,6 +213,7 @@ class Shell : public WebContentsDelegate,
// WebContentsObserver
virtual void TitleWasSet(NavigationEntry* entry, bool explicit_set) OVERRIDE;
void InnerShowDevTools(const std::string& settings);
void OnDevToolsWebContentsDestroyed();
#if defined(TOOLKIT_GTK)
......
......@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_manager.h"
......@@ -24,7 +25,7 @@
namespace content {
// DevTools frontend path for inspector LayoutTests.
GURL GetDevToolsPathAsURL() {
GURL GetDevToolsPathAsURL(const std::string& settings) {
base::FilePath dir_exe;
if (!PathService::Get(base::DIR_EXE, &dir_exe)) {
NOTREACHED();
......@@ -38,12 +39,25 @@ GURL GetDevToolsPathAsURL() {
#endif
base::FilePath dev_tools_path = dir_exe.AppendASCII(
"resources/inspector/devtools.html");
return net::FilePathToFileURL(dev_tools_path);
GURL result = net::FilePathToFileURL(dev_tools_path);
if (!settings.empty())
result = GURL(base::StringPrintf("%s?settings=%s",
result.spec().c_str(),
settings.c_str()));
return result;
}
// static
ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
WebContents* inspected_contents) {
return ShellDevToolsFrontend::Show(inspected_contents, "");
}
// static
ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
WebContents* inspected_contents,
const std::string& settings) {
scoped_refptr<DevToolsAgentHost> agent(
DevToolsAgentHost::GetOrCreateFor(
inspected_contents->GetRenderViewHost()));
......@@ -59,7 +73,7 @@ ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
ShellDevToolsDelegate* delegate = ShellContentBrowserClient::Get()->
shell_browser_main_parts()->devtools_delegate();
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
shell->LoadURL(GetDevToolsPathAsURL());
shell->LoadURL(GetDevToolsPathAsURL(settings));
else
shell->LoadURL(delegate->devtools_http_handler()->GetFrontendURL());
......
......@@ -16,7 +16,7 @@
namespace content {
GURL GetDevToolsPathAsURL();
GURL GetDevToolsPathAsURL(const std::string& settings);
class RenderViewHost;
class Shell;
......@@ -26,6 +26,8 @@ class ShellDevToolsFrontend : public WebContentsObserver,
public DevToolsFrontendHostDelegate {
public:
static ShellDevToolsFrontend* Show(WebContents* inspected_contents);
static ShellDevToolsFrontend* Show(WebContents* inspected_contents,
const std::string& settings);
void Activate();
void Focus();
void InspectElementAt(int x, int y);
......
......@@ -568,11 +568,11 @@ void WebKitTestController::OnClearDevToolsLocalStorage() {
StoragePartition* storage_partition =
BrowserContext::GetStoragePartition(browser_context, NULL);
storage_partition->GetDOMStorageContext()->DeleteLocalStorage(
content::GetDevToolsPathAsURL().GetOrigin());
content::GetDevToolsPathAsURL("").GetOrigin());
}
void WebKitTestController::OnShowDevTools() {
main_window_->ShowDevTools();
void WebKitTestController::OnShowDevTools(const std::string& settings) {
main_window_->ShowDevToolsForTest(settings);
}
void WebKitTestController::OnCloseDevTools() {
......
......@@ -165,7 +165,7 @@ class WebKitTestController : public base::NonThreadSafe,
void OnOverridePreferences(const WebPreferences& prefs);
void OnTestFinished();
void OnClearDevToolsLocalStorage();
void OnShowDevTools();
void OnShowDevTools(const std::string& settings);
void OnCloseDevTools();
void OnGoToOffset(int offset);
void OnReload();
......
......@@ -84,7 +84,8 @@ IPC_SYNC_MESSAGE_ROUTED1_1(ShellViewHostMsg_ReadFileToString,
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_PrintMessage,
std::string /* message */)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_ClearDevToolsLocalStorage)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_ShowDevTools)
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_ShowDevTools,
std::string /* settings */)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CloseDevTools)
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_GoToOffset,
int /* offset */)
......
......@@ -6,6 +6,7 @@
#include <string>
#include "base/strings/stringprintf.h"
#include "content/shell/renderer/test_runner/AccessibilityController.h"
#include "content/shell/renderer/test_runner/EventSender.h"
#include "content/shell/renderer/test_runner/TestRunner.h"
......@@ -118,8 +119,18 @@ void TestInterfaces::configureForTestWithURL(const WebURL& testURL, bool generat
if (spec.find("/inspector/") != string::npos
|| spec.find("/inspector-enabled/") != string::npos)
m_testRunner->clearDevToolsLocalStorage();
if (spec.find("/inspector/") != string::npos)
m_testRunner->showDevTools();
if (spec.find("/inspector/") != string::npos) {
// Subfolder name determines default panel to open.
string settings = "";
string test_path = spec.substr(spec.find("/inspector/") + 11);
size_t slash_index = test_path.find("/");
if (slash_index != string::npos) {
settings = base::StringPrintf(
"{\"lastActivePanel\":\"\\\"%s\\\"\"}",
test_path.substr(0, slash_index).c_str());
}
m_testRunner->showDevTools(settings);
}
if (spec.find("/viewsource/") != string::npos) {
m_testRunner->setShouldEnableViewSource(true);
m_testRunner->setShouldGeneratePixelResults(false);
......
......@@ -803,9 +803,9 @@ void TestRunner::clearDevToolsLocalStorage()
m_delegate->clearDevToolsLocalStorage();
}
void TestRunner::showDevTools()
void TestRunner::showDevTools(const std::string& settings)
{
m_delegate->showDevTools();
m_delegate->showDevTools(settings);
}
void TestRunner::waitUntilDone(const CppArgumentList&, CppVariant* result)
......@@ -1714,9 +1714,12 @@ void TestRunner::setPluginsEnabled(const CppArgumentList& arguments, CppVariant*
result->setNull();
}
void TestRunner::showWebInspector(const CppArgumentList&, CppVariant* result)
void TestRunner::showWebInspector(const CppArgumentList& args, CppVariant* result)
{
showDevTools();
if (args.size() == 1 && args[0].isString())
showDevTools(args[0].toString());
else
showDevTools("");
result->setNull();
}
......
......@@ -103,7 +103,7 @@ public:
bool shouldDumpAsMarkup();
bool shouldDumpChildFrameScrollPositions() const;
bool shouldDumpChildFramesAsText() const;
void showDevTools();
void showDevTools(const std::string& settings);
void clearDevToolsLocalStorage();
void setShouldDumpAsText(bool);
void setShouldDumpAsMarkup(bool);
......
......@@ -89,7 +89,7 @@ public:
virtual void clearDevToolsLocalStorage() = 0;
// Opens and closes the inspector.
virtual void showDevTools() = 0;
virtual void showDevTools(const std::string& settings) = 0;
virtual void closeDevTools() = 0;
// Evaluate the given script in the DevTools agent.
......
......@@ -387,8 +387,8 @@ void WebKitTestRunner::clearDevToolsLocalStorage() {
Send(new ShellViewHostMsg_ClearDevToolsLocalStorage(routing_id()));
}
void WebKitTestRunner::showDevTools() {
Send(new ShellViewHostMsg_ShowDevTools(routing_id()));
void WebKitTestRunner::showDevTools(const std::string& settings) {
Send(new ShellViewHostMsg_ShowDevTools(routing_id(), settings));
}
void WebKitTestRunner::closeDevTools() {
......
......@@ -81,7 +81,7 @@ class WebKitTestRunner : public RenderViewObserver,
const blink::WebSize& max_size) OVERRIDE;
virtual void disableAutoResizeMode(const blink::WebSize& new_size) OVERRIDE;
virtual void clearDevToolsLocalStorage() OVERRIDE;
virtual void showDevTools() OVERRIDE;
virtual void showDevTools(const std::string& settings) OVERRIDE;
virtual void closeDevTools() OVERRIDE;
virtual void evaluateInWebInspector(long call_id,
const std::string& script) OVERRIDE;
......
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