Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/test/chromedriver/chrome/device_manager.cc

Issue 138873003: [chromedriver] Write command line file to both /data/local and /data/local/tmp for Chrome on Androi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/chromedriver/chrome/device_manager.h" 5 #include "chrome/test/chromedriver/chrome/device_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/test/chromedriver/chrome/adb.h" 16 #include "chrome/test/chromedriver/chrome/adb.h"
17 #include "chrome/test/chromedriver/chrome/status.h" 17 #include "chrome/test/chromedriver/chrome/status.h"
18 18
19 const char* kChromeCmdLineFile = "/data/local/chrome-command-line";
bulach 2014/01/15 12:58:43 you may want to create bug and a TODO, link this
craigdh 2014/01/22 22:11:44 So after some discussion it was decided to not set
20
19 Device::Device( 21 Device::Device(
20 const std::string& device_serial, Adb* adb, 22 const std::string& device_serial, Adb* adb,
21 base::Callback<void()> release_callback) 23 base::Callback<void()> release_callback)
22 : serial_(device_serial), 24 : serial_(device_serial),
23 adb_(adb), 25 adb_(adb),
24 release_callback_(release_callback) {} 26 release_callback_(release_callback) {}
25 27
26 Device::~Device() { 28 Device::~Device() {
27 release_callback_.Run(); 29 release_callback_.Run();
28 } 30 }
29 31
30 Status Device::SetUp(const std::string& package, 32 Status Device::SetUp(const std::string& package,
31 const std::string& activity, 33 const std::string& activity,
32 const std::string& process, 34 const std::string& process,
33 const std::string& args, 35 const std::string& args,
34 bool use_running_app, 36 bool use_running_app,
35 int port) { 37 int port) {
36 if (!active_package_.empty()) 38 if (!active_package_.empty())
37 return Status(kUnknownError, 39 return Status(kUnknownError,
38 active_package_ + " was launched and has not been quit"); 40 active_package_ + " was launched and has not been quit");
39 41
40 Status status = adb_->CheckAppInstalled(serial_, package); 42 Status status = adb_->CheckAppInstalled(serial_, package);
41 if (!status.IsOk()) 43 if (status.IsError())
42 return status; 44 return status;
43 45
44 std::string known_activity; 46 std::string known_activity;
45 std::string command_line_file; 47 std::string command_line_file;
46 std::string device_socket; 48 std::string device_socket;
47 std::string exec_name; 49 std::string exec_name;
48 if (package.compare("org.chromium.content_shell_apk") == 0) { 50 if (package.compare("org.chromium.content_shell_apk") == 0) {
49 known_activity = ".ContentShellActivity"; 51 known_activity = ".ContentShellActivity";
50 device_socket = "content_shell_devtools_remote"; 52 device_socket = "content_shell_devtools_remote";
51 command_line_file = "/data/local/tmp/content-shell-command-line"; 53 command_line_file = "/data/local/tmp/content-shell-command-line";
52 exec_name = "content_shell"; 54 exec_name = "content_shell";
53 } else if (package.compare("org.chromium.chrome.testshell") == 0) { 55 } else if (package.compare("org.chromium.chrome.testshell") == 0) {
54 known_activity = ".ChromiumTestShellActivity"; 56 known_activity = ".ChromiumTestShellActivity";
55 device_socket = "chromium_testshell_devtools_remote"; 57 device_socket = "chromium_testshell_devtools_remote";
56 command_line_file = "/data/local/tmp/chromium-testshell-command-line"; 58 command_line_file = "/data/local/tmp/chromium-testshell-command-line";
57 exec_name = "chromium_testshell"; 59 exec_name = "chromium_testshell";
58 } else if (package.find("chrome") != std::string::npos && 60 } else if (package.find("chrome") != std::string::npos &&
59 package.find("webview") == std::string::npos) { 61 package.find("webview") == std::string::npos) {
60 known_activity = "com.google.android.apps.chrome.Main"; 62 known_activity = "com.google.android.apps.chrome.Main";
61 device_socket = "chrome_devtools_remote"; 63 device_socket = "chrome_devtools_remote";
62 command_line_file = "/data/local/chrome-command-line"; 64 command_line_file = kChromeCmdLineFile;
63 exec_name = "chrome"; 65 exec_name = "chrome";
64 } 66 }
65 67
66 if (!use_running_app) { 68 if (!use_running_app) {
67 status = adb_->ClearAppData(serial_, package); 69 status = adb_->ClearAppData(serial_, package);
68 if (!status.IsOk()) 70 if (status.IsError())
69 return status; 71 return status;
70 72
71 if (!known_activity.empty()) { 73 if (!known_activity.empty()) {
72 if (!activity.empty() || 74 if (!activity.empty() ||
73 !process.empty()) 75 !process.empty())
74 return Status(kUnknownError, "known package " + package + 76 return Status(kUnknownError, "known package " + package +
75 " does not accept activity/process"); 77 " does not accept activity/process");
76 } else if (activity.empty()) { 78 } else if (activity.empty()) {
77 return Status(kUnknownError, "WebView apps require activity name"); 79 return Status(kUnknownError, "WebView apps require activity name");
78 } 80 }
79 81
80 if (!command_line_file.empty()) { 82 if (!command_line_file.empty()) {
81 status = adb_->SetCommandLineFile(serial_, command_line_file, exec_name, 83 // If Chrome is set as the debug app it looks in /data/local/tmp/.
82 args); 84 // There's no way to know if this is set, so write to both locations.
83 if (!status.IsOk()) 85 if (command_line_file == kChromeCmdLineFile) {
84 return status; 86 status = adb_->SetCommandLineFile(
87 serial_, kChromeCmdLineFile, exec_name, args);
88 Status status2 = adb_->SetCommandLineFile(
89 serial_, "/data/local/tmp/chrome-command-line", exec_name, args);
bulach 2014/01/15 12:58:43 see above, this would then become kChromeCmdLineFi
90 if (status.IsError() && status2.IsError())
91 return Status(kUnknownError,
92 "Failed to set Chrome's command line file on device " + serial_);
93 } else {
94 status = adb_->SetCommandLineFile(
95 serial_, command_line_file, exec_name, args);
96 if (status.IsError())
97 return status;
98 }
85 } 99 }
86 100
87 status = adb_->Launch(serial_, package, 101 status = adb_->Launch(serial_, package,
88 known_activity.empty() ? activity : known_activity); 102 known_activity.empty() ? activity : known_activity);
89 if (!status.IsOk()) 103 if (status.IsError())
90 return status; 104 return status;
91 105
92 active_package_ = package; 106 active_package_ = package;
93 } 107 }
94 this->ForwardDevtoolsPort(package, process, device_socket, port); 108 this->ForwardDevtoolsPort(package, process, device_socket, port);
95 109
96 return status; 110 return status;
97 } 111 }
98 112
99 Status Device::ForwardDevtoolsPort(const std::string& package, 113 Status Device::ForwardDevtoolsPort(const std::string& package,
100 const std::string& process, 114 const std::string& process,
101 std::string& device_socket, 115 std::string& device_socket,
102 int port) { 116 int port) {
103 if (device_socket.empty()) { 117 if (device_socket.empty()) {
104 // Assume this is a WebView app. 118 // Assume this is a WebView app.
105 int pid; 119 int pid;
106 Status status = adb_->GetPidByName(serial_, 120 Status status = adb_->GetPidByName(serial_,
107 process.empty() ? package : process, 121 process.empty() ? package : process,
108 &pid); 122 &pid);
109 if (!status.IsOk()) { 123 if (status.IsError()) {
110 if (process.empty()) 124 if (process.empty())
111 status.AddDetails( 125 status.AddDetails(
112 "process name must be specified if not equal to package name"); 126 "process name must be specified if not equal to package name");
113 return status; 127 return status;
114 } 128 }
115 device_socket = base::StringPrintf("webview_devtools_remote_%d", pid); 129 device_socket = base::StringPrintf("webview_devtools_remote_%d", pid);
116 } 130 }
117 131
118 return adb_->ForwardPort(serial_, port, device_socket); 132 return adb_->ForwardPort(serial_, port, device_socket);
119 } 133 }
120 134
121 Status Device::TearDown() { 135 Status Device::TearDown() {
122 if (!active_package_.empty()) { 136 if (!active_package_.empty()) {
123 std::string response; 137 std::string response;
124 Status status = adb_->ForceStop(serial_, active_package_); 138 Status status = adb_->ForceStop(serial_, active_package_);
125 if (!status.IsOk()) 139 if (status.IsError())
126 return status; 140 return status;
127 active_package_ = ""; 141 active_package_ = "";
128 } 142 }
129 return Status(kOk); 143 return Status(kOk);
130 } 144 }
131 145
132 DeviceManager::DeviceManager(Adb* adb) : adb_(adb) { 146 DeviceManager::DeviceManager(Adb* adb) : adb_(adb) {
133 CHECK(adb_); 147 CHECK(adb_);
134 } 148 }
135 149
136 DeviceManager::~DeviceManager() {} 150 DeviceManager::~DeviceManager() {}
137 151
138 Status DeviceManager::AcquireDevice(scoped_ptr<Device>* device) { 152 Status DeviceManager::AcquireDevice(scoped_ptr<Device>* device) {
139 std::vector<std::string> devices; 153 std::vector<std::string> devices;
140 Status status = adb_->GetDevices(&devices); 154 Status status = adb_->GetDevices(&devices);
141 if (!status.IsOk()) 155 if (status.IsError())
142 return status; 156 return status;
143 157
144 if (devices.empty()) 158 if (devices.empty())
145 return Status(kUnknownError, "There are no devices online"); 159 return Status(kUnknownError, "There are no devices online");
146 160
147 base::AutoLock lock(devices_lock_); 161 base::AutoLock lock(devices_lock_);
148 status = Status(kUnknownError, "All devices are in use (" + 162 status = Status(kUnknownError, "All devices are in use (" +
149 base::IntToString(devices.size()) + " online)"); 163 base::IntToString(devices.size()) + " online)");
150 std::vector<std::string>::iterator iter; 164 std::vector<std::string>::iterator iter;
151 for (iter = devices.begin(); iter != devices.end(); iter++) { 165 for (iter = devices.begin(); iter != devices.end(); iter++) {
152 if (!IsDeviceLocked(*iter)) { 166 if (!IsDeviceLocked(*iter)) {
153 device->reset(LockDevice(*iter)); 167 device->reset(LockDevice(*iter));
154 status = Status(kOk); 168 status = Status(kOk);
155 break; 169 break;
156 } 170 }
157 } 171 }
158 return status; 172 return status;
159 } 173 }
160 174
161 Status DeviceManager::AcquireSpecificDevice( 175 Status DeviceManager::AcquireSpecificDevice(
162 const std::string& device_serial, scoped_ptr<Device>* device) { 176 const std::string& device_serial, scoped_ptr<Device>* device) {
163 std::vector<std::string> devices; 177 std::vector<std::string> devices;
164 Status status = adb_->GetDevices(&devices); 178 Status status = adb_->GetDevices(&devices);
165 if (!status.IsOk()) 179 if (status.IsError())
166 return status; 180 return status;
167 181
168 if (std::find(devices.begin(), devices.end(), device_serial) == devices.end()) 182 if (std::find(devices.begin(), devices.end(), device_serial) == devices.end())
169 return Status(kUnknownError, 183 return Status(kUnknownError,
170 "Device " + device_serial + " is not online"); 184 "Device " + device_serial + " is not online");
171 185
172 base::AutoLock lock(devices_lock_); 186 base::AutoLock lock(devices_lock_);
173 if (IsDeviceLocked(device_serial)) { 187 if (IsDeviceLocked(device_serial)) {
174 status = Status(kUnknownError, 188 status = Status(kUnknownError,
175 "Device " + device_serial + " is already in use"); 189 "Device " + device_serial + " is already in use");
(...skipping 14 matching lines...) Expand all
190 return new Device(device_serial, adb_, 204 return new Device(device_serial, adb_,
191 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this), 205 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this),
192 device_serial)); 206 device_serial));
193 } 207 }
194 208
195 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) { 209 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) {
196 return std::find(active_devices_.begin(), active_devices_.end(), 210 return std::find(active_devices_.begin(), active_devices_.end(),
197 device_serial) != active_devices_.end(); 211 device_serial) != active_devices_.end();
198 } 212 }
199 213
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698