Android: Use a different socketname for devtools in content_browsertests.

Sharing the same socket name causes tests to crash if
content_browsertests process is still running while running
content_shell instrumentation tests.

Examples failures can be seen on the tryjobs for: https://codereview.chromium.org/13445005/

BUG=230113

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194473 0039d316-1c4b-4281-b951-d872f2087c98
parent 488eb739
......@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/stringprintf.h"
......@@ -21,6 +22,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "content/public/common/content_switches.h"
#include "grit/devtools_discovery_page_resources.h"
#include "jni/DevToolsServer_jni.h"
#include "net/socket/unix_domain_socket_posix.h"
......@@ -31,7 +33,7 @@ namespace {
const char kFrontEndURL[] =
"http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html";
const char kSocketName[] = "chrome_devtools_remote";
const char kDefaultSocketName[] = "chrome_devtools_remote";
const char kTetheringSocketName[] = "chrome_devtools_tethering_%d";
// Delegate implementation for the devtools http handler on android. A new
......@@ -116,8 +118,14 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
DevToolsServer::DevToolsServer()
: use_bundled_frontend_resources_(false),
socket_name_(kSocketName),
socket_name_(kDefaultSocketName),
protocol_handler_(NULL) {
// Override the default socket name if one is specified on the command line.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
socket_name_ = command_line.GetSwitchValueASCII(
switches::kRemoteDebuggingSocketName);
}
}
DevToolsServer::DevToolsServer(bool use_bundled_frontend_resources,
......
......@@ -31,7 +31,7 @@ class DevToolsServer {
private:
bool use_bundled_frontend_resources_;
const std::string socket_name_;
std::string socket_name_;
content::DevToolsHttpHandler* protocol_handler_;
DISALLOW_COPY_AND_ASSIGN(DevToolsServer);
......
......@@ -560,6 +560,11 @@ const char kRegisterPepperPlugins[] = "register-pepper-plugins";
// Enables remote debug over HTTP on the specified port.
const char kRemoteDebuggingPort[] = "remote-debugging-port";
#if defined(OS_ANDROID)
// Enables remote debug over HTTP on the specified socket name.
const char kRemoteDebuggingSocketName[] = "remote-debugging-socket-name";
#endif
// Causes the renderer process to throw an assertion on launch.
const char kRendererAssertTest[] = "renderer-assert-test";
......
......@@ -171,6 +171,9 @@ CONTENT_EXPORT extern const char kProcessPerTab[];
CONTENT_EXPORT extern const char kProcessType[];
CONTENT_EXPORT extern const char kRegisterPepperPlugins[];
CONTENT_EXPORT extern const char kRemoteDebuggingPort[];
#if defined(OS_ANDROID)
CONTENT_EXPORT extern const char kRemoteDebuggingSocketName[];
#endif
CONTENT_EXPORT extern const char kRendererAssertTest[];
extern const char kRendererCmdPrefix[];
CONTENT_EXPORT extern const char kRendererProcess[];
......
......@@ -77,6 +77,10 @@ static void RunTests(JNIEnv* env,
// Append required switches.
command_line->AppendSwitch(content::kSingleProcessTestsFlag);
command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
// Specify a socket name to not conflict with the default one used
// in content_shell.
command_line->AppendSwitchASCII(switches::kRemoteDebuggingSocketName,
"content_browsertests_devtools_remote");
// Create fifo and redirect stdout and stderr to it.
base::FilePath files_dir(
......
......@@ -8,7 +8,6 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "cc/base/switches.h"
......@@ -113,25 +112,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
Shell::Initialize();
net::NetModule::SetResourceProvider(PlatformResourceProvider);
int port = 0;
// On android the port number isn't used.
#if !defined(OS_ANDROID)
// See if the user specified a port on the command line (useful for
// automation). If not, use an ephemeral port by specifying 0.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
int temp_port;
std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) &&
temp_port > 0 && temp_port < 65535) {
port = temp_port;
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
#endif
devtools_delegate_ = new ShellDevToolsDelegate(browser_context_.get(), port);
devtools_delegate_ = new ShellDevToolsDelegate(browser_context_.get());
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
Shell::CreateNewWindow(browser_context_.get(),
......
......@@ -4,9 +4,14 @@
#include "content/shell/shell_devtools_delegate.h"
#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/shell/shell.h"
#include "grit/shell_resources.h"
......@@ -16,26 +21,46 @@
#if defined(OS_ANDROID)
#include "content/public/browser/android/devtools_auth.h"
#include "net/socket/unix_domain_socket_posix.h"
#endif
namespace {
const char kSocketName[] = "content_shell_devtools_remote";
}
net::StreamListenSocketFactory* CreateSocketFactory() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
#if defined(OS_ANDROID)
std::string socket_name = "content_shell_devtools_remote";
if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
socket_name = command_line.GetSwitchValueASCII(
switches::kRemoteDebuggingSocketName);
}
return new net::UnixDomainSocketWithAbstractNamespaceFactory(
socket_name, base::Bind(&content::CanUserConnectToDevTools));
#else
// See if the user specified a port on the command line (useful for
// automation). If not, use an ephemeral port by specifying 0.
int port = 0;
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
int temp_port;
std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) &&
temp_port > 0 && temp_port < 65535) {
port = temp_port;
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
return new net::TCPListenSocketFactory("127.0.0.1", port);
#endif
}
} // namespace
namespace content {
ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context,
int port)
ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context)
: browser_context_(browser_context) {
devtools_http_handler_ = DevToolsHttpHandler::Start(
#if defined(OS_ANDROID)
new net::UnixDomainSocketWithAbstractNamespaceFactory(
kSocketName, base::Bind(&CanUserConnectToDevTools)),
#else
new net::TCPListenSocketFactory("127.0.0.1", port),
#endif
std::string(),
this);
devtools_http_handler_ =
DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this);
}
ShellDevToolsDelegate::~ShellDevToolsDelegate() {
......
......@@ -5,8 +5,6 @@
#ifndef CONTENT_SHELL_SHELL_DEVTOOLS_DELEGATE_H_
#define CONTENT_SHELL_SHELL_DEVTOOLS_DELEGATE_H_
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
......@@ -18,7 +16,7 @@ class DevToolsHttpHandler;
class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate {
public:
ShellDevToolsDelegate(BrowserContext* browser_context, int port);
explicit ShellDevToolsDelegate(BrowserContext* browser_context);
virtual ~ShellDevToolsDelegate();
// Stops http server.
......
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