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 Get the window information related with the event 104 * @param windowId The window id. 105 * @param windowInfo The window information. 106 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 107 */ 108 virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; 109 110 /** 111 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 112 * @param windows The information of windows. 113 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 114 */ 115 virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) = 0; 116 117 /** 118 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 119 * @param displayId the id of display 120 * @param windows The information of windows. 121 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 122 */ 123 virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) = 0; 124 125 /** 126 * @brief Gets the next focused node in the specified direction of the currently focused node. 127 * @param elementInfo The source info to get next info. 128 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 129 * @param nextElementInfo The info of next element. 130 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 131 */ 132 virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 133 AccessibilityElementInfo &nextElementInfo) = 0; 134 135 /** 136 * @brief Get the child node information by child index. 137 * @param index The index of the child. 138 * @param parent The parent info to get child. 139 * @param child The element info of child. 140 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 141 */ 142 virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 143 AccessibilityElementInfo &child) = 0; 144 145 /** 146 * @brief Get the children node information 147 * @param parent The parent info to get children. 148 * @param children The element info of children. 149 * @return Return RET_OK if gets children elementInfo successfully, otherwise refer to the RetError for the failure. 150 */ 151 virtual RetError GetChildren(const AccessibilityElementInfo &parent, 152 std::vector<AccessibilityElementInfo> &children) = 0; 153 154 /** 155 * @brief Searches for node information based on the specified content. 156 * @param elementInfo The source info. 157 * @param text specified content 158 * @param elementInfos The element infos of specified content. 159 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 160 */ 161 virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 162 std::vector<AccessibilityElementInfo> &elementInfos) = 0; 163 164 /** 165 * @brief Get the node information related with the event 166 * @param eventInfo The source info to get source. 167 * @param elementInfo The element info of source. 168 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 169 */ 170 virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; 171 172 /** 173 * @brief Get Parent node information 174 * @param child The child element info to get parent. 175 * @param parent The parent element info. 176 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 177 */ 178 virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; 179 180 /** 181 * @brief Executes a specified action. 182 * @param elementInfo The source info to execute action. 183 * @param action: the action type 184 * @param actionArguments: The parameter for action type. such as: 185 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 186 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 187 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 188 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 189 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 190 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 191 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 192 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 193 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 194 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 195 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 196 * action: ACCESSIBILITY_ACTION_SET_TEXT, 197 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 198 * @return Return RET_OK if performs action successfully, otherwise refer to the RetError for the failure. 199 */ 200 virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, 201 const std::map<std::string, std::string> &actionArguments) = 0; 202 203 /** 204 * @brief Set target bundle names. 205 * @param targetBundleNames The target bundle name 206 * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. 207 */ 208 virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0; 209 210 /** 211 * @brief Set cache mode. 212 * The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo, 213 * GetChildren, GetSource, GetParentElementInfo. 214 * @param cacheMode The cache mode. It includes: 215 * PREFETCH_PREDECESSORS: cache the parent node info also. 216 * PREFETCH_SIBLINGS: cache the sister/brothers node info also. 217 * PREFETCH_CHILDREN: cache the child node info also. 218 * otherwise: no cache. 219 * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. 220 */ 221 virtual RetError SetCacheMode(const int32_t cacheMode) = 0; 222 }; 223 } // namespace Accessibility 224 } // namespace OHOS 225 #endif // ACCESSIBILITY_UI_TEST_ABILITY_H