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/chrome_android_impl.h"
6
7 #include <utility>
8
9 #include "base/strings/string_split.h"
10 #include "chrome/test/chromedriver/chrome/device_manager.h"
11 #include "chrome/test/chromedriver/chrome/devtools_client.h"
12 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
13 #include "chrome/test/chromedriver/chrome/devtools_http_client.h"
14 #include "chrome/test/chromedriver/chrome/status.h"
15 #include "chrome/test/chromedriver/chrome/web_view_impl.h"
16
ChromeAndroidImpl(std::unique_ptr<DevToolsHttpClient> http_client,std::unique_ptr<DevToolsClient> websocket_client,std::vector<std::unique_ptr<DevToolsEventListener>> devtools_event_listeners,std::string page_load_strategy,std::unique_ptr<Device> device)17 ChromeAndroidImpl::ChromeAndroidImpl(
18 std::unique_ptr<DevToolsHttpClient> http_client,
19 std::unique_ptr<DevToolsClient> websocket_client,
20 std::vector<std::unique_ptr<DevToolsEventListener>>
21 devtools_event_listeners,
22 std::string page_load_strategy,
23 std::unique_ptr<Device> device)
24 : ChromeImpl(std::move(http_client),
25 std::move(websocket_client),
26 std::move(devtools_event_listeners),
27 page_load_strategy),
28 device_(std::move(device)) {}
29
~ChromeAndroidImpl()30 ChromeAndroidImpl::~ChromeAndroidImpl() {}
31
GetAsDesktop(ChromeDesktopImpl ** desktop)32 Status ChromeAndroidImpl::GetAsDesktop(ChromeDesktopImpl** desktop) {
33 return Status(kUnknownError, "operation is unsupported on Android");
34 }
35
GetOperatingSystemName()36 std::string ChromeAndroidImpl::GetOperatingSystemName() {
37 return "ANDROID";
38 }
39
GetWindow(const std::string & target_id,Window * window)40 Status ChromeAndroidImpl::GetWindow(const std::string& target_id,
41 Window* window) {
42 WebView* web_view = nullptr;
43 Status status = GetWebViewById(target_id, &web_view);
44 if (status.IsError())
45 return status;
46
47 std::unique_ptr<base::Value> result;
48 std::string expression =
49 "[window.screenX, window.screenY, window.outerWidth, window.outerHeight]";
50 status = web_view->EvaluateScript(target_id, expression, false, &result);
51 if (status.IsError())
52 return status;
53
54 window->left = static_cast<int>(result->GetList()[0].GetDouble());
55 window->top = static_cast<int>(result->GetList()[1].GetDouble());
56 window->width = static_cast<int>(result->GetList()[2].GetDouble());
57 window->height = static_cast<int>(result->GetList()[3].GetDouble());
58 // Android does not use Window.id or have window states
59 window->id = 0;
60 window->state = "";
61
62 return status;
63 }
64
HasTouchScreen() const65 bool ChromeAndroidImpl::HasTouchScreen() const {
66 return true;
67 }
68
QuitImpl()69 Status ChromeAndroidImpl::QuitImpl() {
70 return device_->TearDown();
71 }
72
73