Commit 2f57a961 authored by Caleb Rouleau's avatar Caleb Rouleau Committed by Commit Bot

[Cast Shell] Write DevTools port file to DIR_CAST_HOME.

When you send --remote-debugging-port=0 to Chrome, devtools chooses
its own port and writes it to chrome::DIR_USER_DATA as a file
named "DevToolsActivePort". Cast doesn't have a user data dir,
so this CL writes the file to chromecast::DIR_CAST_HOME.

The ability to specify a 0 as the port is needed to avoid the
race condition of some other process binding to a port that you
choose before Chrome gets a chance to bind to it. ChromeDriver
switched to using DevToolsActivePort to fix a race condition:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2161

ChromeDriver does not natively work with cast_shell, but you
can pass a shell script as the chrome binary to ChromeDriver
and then have the shell script write a symbolic link from
DevToolsActivePort in the user-data-dir flag value that
ChromeDriver provides to the DIR_CAST_HOME directory.

Therefore, this change allows cast_shell to work with
ChromeDriver again.

Note that the "Devtools started: port=X" log is not needed
since DevTools code logs something like
"DevTools listening on
ws://0.0.0.0:45447/devtools/browser/665edec7-dbee-4547-816e-1d5e0c4a5dd3"

already.

Bug: 854864, chromedriver:2161
Change-Id: I55c20881607d581f628840cdf906569807f541ca
Reviewed-on: https://chromium-review.googlesource.com/1114378
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarStephen Lanham <slan@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570526}
parent bd80614f
......@@ -11,9 +11,11 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chromecast/base/cast_paths.h"
#include "chromecast/browser/cast_browser_process.h"
#include "chromecast/browser/devtools/cast_devtools_manager_delegate.h"
#include "chromecast/common/cast_content_client.h"
......@@ -183,9 +185,21 @@ void RemoteDebuggingServer::StartIfNeeded() {
if (is_started_)
return;
base::FilePath output_dir;
if (!port_) {
// Providing a defined output_dir causes DevTools to write the port
// number chosen to a file named DevToolsActivePort. This file is
// used by test automation tools like ChromeDriver. ChromeDriver passes
// in --remote-debugging-port=0 so that cast_shell picks its own port to
// binds to so that there is no race condition.
bool result =
base::PathService::Get(chromecast::DIR_CAST_HOME, &output_dir);
DCHECK(result);
}
content::DevToolsAgentHost::StartRemoteDebuggingServer(
CreateSocketFactory(port_), base::FilePath(), base::FilePath());
LOG(INFO) << "Devtools started: port=" << port_;
CreateSocketFactory(port_), output_dir, base::FilePath());
LOG(INFO) << "Devtools started";
is_started_ = true;
}
......
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