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