OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/test/chromedriver/chrome_android_impl.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/process_util.h" | |
10 #include "base/string_number_conversions.h" | |
11 #include "chrome/test/chromedriver/net/sync_websocket_impl.h" | |
12 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | |
13 #include "chrome/test/chromedriver/status.h" | |
14 #include "chrome/test/chromedriver/web_view.h" | |
15 | |
16 ChromeAndroidImpl::ChromeAndroidImpl( | |
17 URLRequestContextGetter* context_getter, | |
18 int port, | |
19 const SyncWebSocketFactory& socket_factory) | |
20 : ChromeImpl(context_getter, port, socket_factory) {} | |
21 | |
22 ChromeAndroidImpl::~ChromeAndroidImpl() {} | |
23 | |
24 Status ChromeAndroidImpl::Launch(const std::string& package_name) { | |
25 // TODO(frankf): Figure out how this should be installed to | |
26 // make this work for all platforms. | |
27 base::FilePath adb_commands(FILE_PATH_LITERAL("adb_commands.py")); | |
28 CommandLine command(adb_commands); | |
29 command.AppendSwitchASCII("package", package_name); | |
30 command.AppendSwitch("launch"); | |
31 command.AppendSwitchASCII("port", base::IntToString(GetPort())); | |
32 | |
33 std::string output; | |
34 if (!base::GetAppOutput(command, &output)) { | |
35 if (output.empty()) | |
36 return Status( | |
37 kUnknownError, | |
38 "failed to run adb_commands.py. Make sure it is set in PATH."); | |
39 else | |
40 return Status(kUnknownError, "android app failed to start.\n" + output); | |
41 } | |
42 | |
43 Status status = Init(); | |
44 if (status.IsError()) { | |
45 Quit(); | |
46 return status; | |
47 } | |
48 std::list<WebView*> web_views; | |
49 status = GetWebViews(&web_views); | |
50 if (status.IsError() || web_views.empty()) { | |
51 Quit(); | |
52 return status.IsError() ? status : | |
53 Status(kUnknownError, "unable to discover open window in chrome"); | |
54 } | |
55 | |
56 return Status(kOk); | |
57 } | |
58 | |
59 std::string ChromeAndroidImpl::GetOperatingSystemName() { | |
60 return "ANDROID"; | |
61 } | |
62 | |
63 Status ChromeAndroidImpl::Quit() { | |
64 // NOOP. | |
65 return Status(kOk); | |
66 } | |
67 | |
OLD | NEW |