Commit d9f0f28f authored by craigdh@chromium.org's avatar craigdh@chromium.org

[chromedriver] Write command line file to both /data/local and /data/local/tmp...

[chromedriver] Write command line file to both /data/local and /data/local/tmp for Chrome on Android.

This supports the new feature where setting chrome as the debug app
causes Chrome to look for the command line file in tmp.

BUG=chromedriver:665
TEST=None

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247901 0039d316-1c4b-4281-b951-d872f2087c98
parent 67cea989
...@@ -26,6 +26,8 @@ class Adb { ...@@ -26,6 +26,8 @@ class Adb {
const std::string& package) = 0; const std::string& package) = 0;
virtual Status ClearAppData(const std::string& device_serial, virtual Status ClearAppData(const std::string& device_serial,
const std::string& package) = 0; const std::string& package) = 0;
virtual Status SetDebugApp(const std::string& device_serial,
const std::string& package) = 0;
virtual Status Launch(const std::string& device_serial, virtual Status Launch(const std::string& device_serial,
const std::string& package, const std::string& package,
const std::string& activity) = 0; const std::string& activity) = 0;
......
...@@ -160,6 +160,13 @@ Status AdbImpl::ClearAppData( ...@@ -160,6 +160,13 @@ Status AdbImpl::ClearAppData(
return Status(kOk); return Status(kOk);
} }
Status AdbImpl::SetDebugApp(
const std::string& device_serial, const std::string& package) {
std::string response;
return ExecuteHostShellCommand(
device_serial, "am set-debug-app --persistent " + package, &response);
}
Status AdbImpl::Launch( Status AdbImpl::Launch(
const std::string& device_serial, const std::string& package, const std::string& device_serial, const std::string& package,
const std::string& activity) { const std::string& activity) {
......
...@@ -38,6 +38,8 @@ class AdbImpl : public Adb { ...@@ -38,6 +38,8 @@ class AdbImpl : public Adb {
const std::string& package) OVERRIDE; const std::string& package) OVERRIDE;
virtual Status ClearAppData(const std::string& device_serial, virtual Status ClearAppData(const std::string& device_serial,
const std::string& package) OVERRIDE; const std::string& package) OVERRIDE;
virtual Status SetDebugApp(const std::string& device_serial,
const std::string& package) OVERRIDE;
virtual Status Launch(const std::string& device_serial, virtual Status Launch(const std::string& device_serial,
const std::string& package, const std::string& package,
const std::string& activity) OVERRIDE; const std::string& activity) OVERRIDE;
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "chrome/test/chromedriver/chrome/adb.h" #include "chrome/test/chromedriver/chrome/adb.h"
#include "chrome/test/chromedriver/chrome/status.h" #include "chrome/test/chromedriver/chrome/status.h"
// TODO(craigdh): Remove once Chromedriver no longer supports pre-m33 Chrome.
const char* kChromeCmdLineFileBeforeM33 = "/data/local/chrome-command-line";
const char* kChromeCmdLineFile = "/data/local/tmp/chrome-command-line";
Device::Device( Device::Device(
const std::string& device_serial, Adb* adb, const std::string& device_serial, Adb* adb,
base::Callback<void()> release_callback) base::Callback<void()> release_callback)
...@@ -38,7 +42,7 @@ Status Device::SetUp(const std::string& package, ...@@ -38,7 +42,7 @@ Status Device::SetUp(const std::string& package,
active_package_ + " was launched and has not been quit"); active_package_ + " was launched and has not been quit");
Status status = adb_->CheckAppInstalled(serial_, package); Status status = adb_->CheckAppInstalled(serial_, package);
if (!status.IsOk()) if (status.IsError())
return status; return status;
std::string known_activity; std::string known_activity;
...@@ -46,26 +50,32 @@ Status Device::SetUp(const std::string& package, ...@@ -46,26 +50,32 @@ Status Device::SetUp(const std::string& package,
std::string device_socket; std::string device_socket;
std::string exec_name; std::string exec_name;
if (package.compare("org.chromium.content_shell_apk") == 0) { if (package.compare("org.chromium.content_shell_apk") == 0) {
// Chromium content shell.
known_activity = ".ContentShellActivity"; known_activity = ".ContentShellActivity";
device_socket = "content_shell_devtools_remote"; device_socket = "content_shell_devtools_remote";
command_line_file = "/data/local/tmp/content-shell-command-line"; command_line_file = "/data/local/tmp/content-shell-command-line";
exec_name = "content_shell"; exec_name = "content_shell";
} else if (package.compare("org.chromium.chrome.testshell") == 0) { } else if (package.compare("org.chromium.chrome.testshell") == 0) {
// Chromium test shell.
known_activity = ".ChromiumTestShellActivity"; known_activity = ".ChromiumTestShellActivity";
device_socket = "chromium_testshell_devtools_remote"; device_socket = "chromium_testshell_devtools_remote";
command_line_file = "/data/local/tmp/chromium-testshell-command-line"; command_line_file = "/data/local/tmp/chromium-testshell-command-line";
exec_name = "chromium_testshell"; exec_name = "chromium_testshell";
} else if (package.find("chrome") != std::string::npos && } else if (package.find("chrome") != std::string::npos &&
package.find("webview") == std::string::npos) { package.find("webview") == std::string::npos) {
// Chrome.
known_activity = "com.google.android.apps.chrome.Main"; known_activity = "com.google.android.apps.chrome.Main";
device_socket = "chrome_devtools_remote"; device_socket = "chrome_devtools_remote";
command_line_file = "/data/local/chrome-command-line"; command_line_file = kChromeCmdLineFileBeforeM33;
exec_name = "chrome"; exec_name = "chrome";
status = adb_->SetDebugApp(serial_, package);
if (status.IsError())
return status;
} }
if (!use_running_app) { if (!use_running_app) {
status = adb_->ClearAppData(serial_, package); status = adb_->ClearAppData(serial_, package);
if (!status.IsOk()) if (status.IsError())
return status; return status;
if (!known_activity.empty()) { if (!known_activity.empty()) {
...@@ -78,15 +88,28 @@ Status Device::SetUp(const std::string& package, ...@@ -78,15 +88,28 @@ Status Device::SetUp(const std::string& package,
} }
if (!command_line_file.empty()) { if (!command_line_file.empty()) {
status = adb_->SetCommandLineFile(serial_, command_line_file, exec_name, // If Chrome is set as the debug app it looks in /data/local/tmp/.
args); // There's no way to know if this is set, so write to both locations.
if (!status.IsOk()) // This can be removed once support for pre-M33 is no longer needed.
return status; if (command_line_file == kChromeCmdLineFileBeforeM33) {
status = adb_->SetCommandLineFile(
serial_, kChromeCmdLineFileBeforeM33, exec_name, args);
Status status2 = adb_->SetCommandLineFile(
serial_, kChromeCmdLineFile, exec_name, args);
if (status.IsError() && status2.IsError())
return Status(kUnknownError,
"Failed to set Chrome's command line file on device " + serial_);
} else {
status = adb_->SetCommandLineFile(
serial_, command_line_file, exec_name, args);
if (status.IsError())
return status;
}
} }
status = adb_->Launch(serial_, package, status = adb_->Launch(serial_, package,
known_activity.empty() ? activity : known_activity); known_activity.empty() ? activity : known_activity);
if (!status.IsOk()) if (status.IsError())
return status; return status;
active_package_ = package; active_package_ = package;
...@@ -106,7 +129,7 @@ Status Device::ForwardDevtoolsPort(const std::string& package, ...@@ -106,7 +129,7 @@ Status Device::ForwardDevtoolsPort(const std::string& package,
Status status = adb_->GetPidByName(serial_, Status status = adb_->GetPidByName(serial_,
process.empty() ? package : process, process.empty() ? package : process,
&pid); &pid);
if (!status.IsOk()) { if (status.IsError()) {
if (process.empty()) if (process.empty())
status.AddDetails( status.AddDetails(
"process name must be specified if not equal to package name"); "process name must be specified if not equal to package name");
...@@ -122,7 +145,7 @@ Status Device::TearDown() { ...@@ -122,7 +145,7 @@ Status Device::TearDown() {
if (!active_package_.empty()) { if (!active_package_.empty()) {
std::string response; std::string response;
Status status = adb_->ForceStop(serial_, active_package_); Status status = adb_->ForceStop(serial_, active_package_);
if (!status.IsOk()) if (status.IsError())
return status; return status;
active_package_ = ""; active_package_ = "";
} }
...@@ -138,7 +161,7 @@ DeviceManager::~DeviceManager() {} ...@@ -138,7 +161,7 @@ DeviceManager::~DeviceManager() {}
Status DeviceManager::AcquireDevice(scoped_ptr<Device>* device) { Status DeviceManager::AcquireDevice(scoped_ptr<Device>* device) {
std::vector<std::string> devices; std::vector<std::string> devices;
Status status = adb_->GetDevices(&devices); Status status = adb_->GetDevices(&devices);
if (!status.IsOk()) if (status.IsError())
return status; return status;
if (devices.empty()) if (devices.empty())
...@@ -162,7 +185,7 @@ Status DeviceManager::AcquireSpecificDevice( ...@@ -162,7 +185,7 @@ Status DeviceManager::AcquireSpecificDevice(
const std::string& device_serial, scoped_ptr<Device>* device) { const std::string& device_serial, scoped_ptr<Device>* device) {
std::vector<std::string> devices; std::vector<std::string> devices;
Status status = adb_->GetDevices(&devices); Status status = adb_->GetDevices(&devices);
if (!status.IsOk()) if (status.IsError())
return status; return status;
if (std::find(devices.begin(), devices.end(), device_serial) == devices.end()) if (std::find(devices.begin(), devices.end(), device_serial) == devices.end())
......
...@@ -48,6 +48,11 @@ class FakeAdb : public Adb { ...@@ -48,6 +48,11 @@ class FakeAdb : public Adb {
return Status(kOk); return Status(kOk);
} }
virtual Status SetDebugApp(const std::string& device_serial,
const std::string& package) OVERRIDE {
return Status(kOk);
}
virtual Status Launch(const std::string& device_serial, virtual Status Launch(const std::string& device_serial,
const std::string& package, const std::string& package,
const std::string& activity) OVERRIDE { const std::string& activity) 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