• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UI_CONTROLLER_H
17 #define UI_CONTROLLER_H
18 
19 #include <list>
20 #include <string>
21 #include <sstream>
22 #include <memory>
23 #include <mutex>
24 #include <functional>
25 #include "json.hpp"
26 #include "ui_action.h"
27 
28 namespace OHOS::uitest {
29     struct UiEventSourceInfo {
30         std::string bundleName;
31         std::string text;
32         std::string type;
33     };
34 
35     class UiEventListener {
36     public:
37         UiEventListener() = default;
38         virtual ~UiEventListener() = default;
OnEvent(const std::string & event,const UiEventSourceInfo & source)39         virtual void OnEvent(const std::string &event, const UiEventSourceInfo &source) {};
40     };
41 
42     class UiController {
43     public:
UiController()44         UiController() {};
45 
46         virtual ~UiController() = default;
47 
Initialize()48         virtual bool Initialize()
49         {
50             return true;
51         };
52 
53         virtual void GetUiHierarchy(std::vector<std::pair<Window, nlohmann::json>> &out, bool getWidgetNodes,
54             string targetApp = "") {};
55 
WaitForUiSteady(uint32_t idleThresholdMs,uint32_t timeoutSec)56         virtual bool WaitForUiSteady(uint32_t idleThresholdMs, uint32_t timeoutSec) const
57         {
58             return false;
59         };
60 
InjectTouchEventSequence(const PointerMatrix & events)61         virtual void InjectTouchEventSequence(const PointerMatrix& events) const {};
62 
InjectKeyEventSequence(const std::vector<KeyEvent> & events)63         virtual void InjectKeyEventSequence(const std::vector<KeyEvent>& events) const {};
64 
PutTextToClipboard(std::string_view text)65         virtual void PutTextToClipboard(std::string_view text) const {};
66 
TakeScreenCap(int32_t fd,std::stringstream & errReceiver,Rect rect)67         virtual bool TakeScreenCap(int32_t fd, std::stringstream &errReceiver, Rect rect) const
68         {
69             return false;
70         };
71 
GetCharKeyCode(char ch,int32_t & code,int32_t & ctrlCode)72         virtual bool GetCharKeyCode(char ch, int32_t& code, int32_t& ctrlCode) const
73         {
74             return false;
75         };
76 
SetDisplayRotation(DisplayRotation rotation)77         virtual void SetDisplayRotation(DisplayRotation rotation) const {};
78 
GetDisplayRotation()79         virtual DisplayRotation GetDisplayRotation() const
80         {
81             return ROTATION_0;
82         };
83 
SetDisplayRotationEnabled(bool enabled)84         virtual void SetDisplayRotationEnabled(bool enabled) const {};
85 
GetDisplaySize()86         virtual Point GetDisplaySize() const
87         {
88             return Point(0, 0);
89         };
90 
GetDisplayDensity()91         virtual Point GetDisplayDensity() const
92         {
93             return Point(0, 0);
94         };
95 
IsScreenOn()96         virtual bool IsScreenOn() const
97         {
98             return true;
99         };
100 
101         /**
102          * Tells if this controller is effective for current UI.
103          * */
104         virtual bool IsWorkable() const = 0;
105 
InjectMouseClick(MouseOpArgs mouseOpArgs)106         virtual void InjectMouseClick(MouseOpArgs mouseOpArgs) const {};
107 
InjectMouseMove(MouseOpArgs mouseOpArgs)108         virtual void InjectMouseMove(MouseOpArgs mouseOpArgs) const {};
109 
InjectMouseScroll(MouseOpArgs mouseOpArgs)110         virtual void InjectMouseScroll(MouseOpArgs mouseOpArgs) const {};
111 
InjectMouseEventSequence(const PointerMatrix & events)112         virtual void InjectMouseEventSequence(const PointerMatrix &events) const {};
113 
RegisterUiEventListener(std::shared_ptr<UiEventListener> listener)114         virtual void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const {};
115     };
116 }
117 
118 #endif