• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2023 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 ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H
17 #define ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H
18 
19 #include "accessibility_ui_test_ability.h"
20 #include "i_accessible_ability_manager_service.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 class AccessibilityUITestAbilityImpl final : public AccessibilityUITestAbility {
25 public:
26     /**
27      * @brief Construct
28      */
29     AccessibilityUITestAbilityImpl() = default;
30 
31     /**
32      * @brief Destruct
33      */
34     ~AccessibilityUITestAbilityImpl() = default;
35 
36     /**
37      * @brief Register ability listener.
38      * @param listener The listener to add.
39      * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure.
40      */
41     virtual RetError RegisterAbilityListener(const std::shared_ptr<AccessibleAbilityListener> &listener) override;
42 
43     /**
44      * @brief Connect to AAMS. For UI test.
45      * @return Return RET_OK if the command of connection is sent successfully,
46      *         otherwise refer to the RetError for the failure.
47      */
48     virtual RetError Connect() override;
49 
50     /**
51      * @brief disconnect to AAMS. For UI test.
52      * @return Return RET_OK if the command of disconnect is sent successfully,
53      *         otherwise refer to the RetError for the failure.
54      */
55     virtual RetError Disconnect() override;
56 
57     /**
58      * @brief Obtains elementInfo of focus.
59      * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY.
60      * @param elementInfo The accessibilityElementInfo of focus.
61      * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure.
62      */
63     virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override;
64 
65     /**
66      * @brief Obtains elementInfo of focus.
67      * @param sourceInfo The source info to get focus.
68      * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY.
69      * @param elementInfo The accessibilityElementInfo of focus.
70      * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure.
71      */
72     virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType,
73         AccessibilityElementInfo &elementInfo) override;
74 
75     /**
76      * @brief Sends simulate gestures to the screen.
77      * @param gesturePath The gesture which need to send.
78      * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure.
79      */
80     virtual RetError InjectGesture(const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath) override;
81 
82     /**
83      * @brief Obtains elementInfo of the accessible root node.
84      * @param elementInfo The elementInfo of the accessible root node.
85      * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure.
86      */
87     virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) override;
88 
89     /**
90      * @brief Obtains elementInfo of the accessible root node.
91      * @param windowInfo The source window info to get root.
92      * @param elementInfo The elementInfo of the accessible root node.
93      * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure.
94      */
95     virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo,
96         AccessibilityElementInfo &elementInfo) override;
97 
98     /**
99      * @brief Get the window information related with the event
100      * @param windowId The window id.
101      * @param windowInfo The window information.
102      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
103      */
104     virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override;
105 
106     /**
107      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
108      * @param windows The information of windows.
109      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
110      */
111     virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) override;
112 
113     /**
114      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
115      * @param displayId the id of display
116      * @param windows The information of windows.
117      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
118      */
119     virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) override;
120 
121     /**
122      * @brief Gets the next focused node in the specified direction of the currently focused node.
123      * @param elementInfo The source info to get next info.
124      * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection
125      * @param nextElementInfo The info of next element.
126      * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure.
127      */
128     virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction,
129         AccessibilityElementInfo &nextElementInfo) override;
130 
131     /**
132      * @brief Get the child node information by childId
133      * @param index The index of the child.
134      * @param parent The parent info to get child.
135      * @param child The element info of child.
136      * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure.
137      */
138     virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent,
139         AccessibilityElementInfo &child) override;
140 
141     /**
142      * @brief Get the child node information
143      * @param parent The parent info to get child.
144      * @param children The element info of children.
145      * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure.
146      */
147     virtual RetError GetChildren(const AccessibilityElementInfo &parent,
148         std::vector<AccessibilityElementInfo> &children) override;
149 
150     /**
151      * @brief Searches for node information based on the specified content.
152      * @param elementInfo The source info.
153      * @param text specified content
154      * @param elementInfos The element infos of specified content.
155      * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure.
156      */
157     virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text,
158         std::vector<AccessibilityElementInfo> &elementInfos) override;
159 
160     /**
161      * @brief Get the node information related with the event
162      * @param eventInfo The source info to get source.
163      * @param elementInfo The element info of source.
164      * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure.
165      */
166     virtual RetError GetSource(const AccessibilityEventInfo &eventInfo,
167         AccessibilityElementInfo &elementInfo) override;
168 
169     /**
170      * @brief Get Parent node information
171      * @param child The child element info to get parent.
172      * @param parent The parent element info.
173      * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure.
174      */
175     virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child,
176         AccessibilityElementInfo &parent) override;
177 
178     /**
179      * @brief Executes a specified action.
180      * @param elementInfo The source info to execute action.
181      * @param action: the action type
182      * @param actionArguments: The parameter for action type. such as:
183      *      action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM,
184      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
185      *      action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM,
186      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
187      *      action: ACCESSIBILITY_ACTION_NEXT_TEXT,
188      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
189      *      action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT,
190      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
191      *      action: ACCESSIBILITY_ACTION_SET_SELECTION,
192      *                  actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)},
193      *                                  {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)})
194      *      action: ACCESSIBILITY_ACTION_SET_TEXT,
195      *                  actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted")
196      * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure.
197      */
198     virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action,
199         const std::map<std::string, std::string> &actionArguments) override;
200 
201     /**
202      * @brief Set target bundle names.
203      * @param targetBundleNames The target bundle name
204      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
205      */
206     virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override;
207 
208     /**
209      * @brief Set cache mode.
210      *        The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
211      *        GetChildren, GetSource, GetParentElementInfo.
212      * @param cacheMode The cache mode. It includes:
213      *             PREFETCH_PREDECESSORS: cache the parent node info also.
214      *             PREFETCH_SIBLINGS: cache the sister/brothers node info also.
215      *             PREFETCH_CHILDREN: cache the child node info also.
216      *             otherwise: no cache.
217      * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure.
218      */
219     virtual RetError SetCacheMode(const int32_t cacheMode) override;
220 
221 private:
222     sptr<IAccessibleAbilityManagerService> serviceProxy_ = nullptr;
223 };
224 } // namespace Accessibility
225 } // namespace OHOS
226 #endif  // ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H