Roll src/third_party/skia 2440fcd:4de8c3a
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_devtools_frontend.cc
blob199999166b4b31f7ce912f9671267b03a364f9b3
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/strings/stringprintf.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/shell/browser/blink_test_controller.h"
12 #include "content/shell/browser/shell.h"
13 #include "net/base/filename_util.h"
15 namespace content {
17 // static
18 LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show(
19 WebContents* inspected_contents,
20 const std::string& settings,
21 const std::string& frontend_url) {
22 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(),
23 GURL(),
24 NULL,
25 gfx::Size());
26 LayoutTestDevToolsFrontend* devtools_frontend =
27 new LayoutTestDevToolsFrontend(shell, inspected_contents);
29 shell->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
31 return devtools_frontend;
34 // static.
35 GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
36 const std::string& settings,
37 const std::string& frontend_url) {
38 if (!frontend_url.empty())
39 return GURL(frontend_url);
40 base::FilePath dir_exe;
41 if (!PathService::Get(base::DIR_EXE, &dir_exe)) {
42 NOTREACHED();
43 return GURL();
45 #if defined(OS_MACOSX)
46 // On Mac, the executable is in
47 // out/Release/Content Shell.app/Contents/MacOS/Content Shell.
48 // We need to go up 3 directories to get to out/Release.
49 dir_exe = dir_exe.AppendASCII("../../..");
50 #endif
51 base::FilePath dev_tools_path =
52 dir_exe.AppendASCII("resources/inspector/inspector.html");
54 GURL result = net::FilePathToFileURL(dev_tools_path);
55 if (!settings.empty())
56 result = GURL(base::StringPrintf("%s?settings=%s&experiments=true",
57 result.spec().c_str(),
58 settings.c_str()));
59 return result;
62 void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings,
63 const std::string frontend_url) {
64 DisconnectFromTarget();
65 preferences()->Clear();
66 frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
69 LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend(
70 Shell* frontend_shell,
71 WebContents* inspected_contents)
72 : ShellDevToolsFrontend(frontend_shell, inspected_contents) {
75 LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() {
78 void LayoutTestDevToolsFrontend::AgentHostClosed(
79 DevToolsAgentHost* agent_host, bool replaced) {
80 // Do not close the front-end shell.
83 void LayoutTestDevToolsFrontend::RenderProcessGone(
84 base::TerminationStatus status) {
85 BlinkTestController::Get()->DevToolsProcessCrashed();
88 } // namespace content