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 Obtains elementInfos of the accessible root node in batchs. 100 * @param elementInfos ElementInfos of the accessible root node and its recursive subnodes. 101 * @return Return RET_OK if obtains elementInfos successfully, otherwise refer to the RetError for the failure. 102 */ 103 virtual RetError GetRootBatch(std::vector<AccessibilityElementInfo>& elementInfos) override; 104 105 /** 106 * @brief Obtains elementInfos of the accessible root node in batchs. 107 * @param windowInfo The source window info to get root. 108 * @param elementInfos ElementInfos of the accessible root node and its recursive subnodes. 109 * @param isFilter Indicates whether to filter nodes. 110 * @param needCut Indicates whether to remove invisible nodes. 111 * @return Return RET_OK if obtains elementInfos successfully, otherwise refer to the RetError for the failure. 112 */ 113 virtual RetError GetRootByWindowBatch(const AccessibilityWindowInfo &windowInfo, 114 std::vector<AccessibilityElementInfo>& elementInfos, bool isFilter, bool needCut) override; 115 116 /** 117 * @brief Get the window information related with the event 118 * @param windowId The window id. 119 * @param windowInfo The window information. 120 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 121 */ 122 virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; 123 124 /** 125 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 126 * @param windows The information of windows. 127 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 128 */ 129 virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) override; 130 131 /** 132 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 133 * @param displayId the id of display 134 * @param windows The information of windows. 135 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 136 */ 137 virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) override; 138 139 /** 140 * @brief Gets the next focused node in the specified direction of the currently focused node. 141 * @param elementInfo The source info to get next info. 142 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 143 * @param nextElementInfo The info of next element. 144 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 145 */ 146 virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 147 AccessibilityElementInfo &nextElementInfo) override; 148 149 /** 150 * @brief Get the child node information by childId 151 * @param index The index of the child. 152 * @param parent The parent info to get child. 153 * @param child The element info of child. 154 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 155 */ 156 virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 157 AccessibilityElementInfo &child) override; 158 159 /** 160 * @brief Get the child node information 161 * @param parent The parent info to get child. 162 * @param children The element info of children. 163 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 164 */ 165 virtual RetError GetChildren(const AccessibilityElementInfo &parent, 166 std::vector<AccessibilityElementInfo> &children) override; 167 168 /** 169 * @brief Searches for node information based on the specified content. 170 * @param elementInfo The source info. 171 * @param text specified content 172 * @param elementInfos The element infos of specified content. 173 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 174 */ 175 virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 176 std::vector<AccessibilityElementInfo> &elementInfos) override; 177 178 /** 179 * @brief Get the node information related with the event 180 * @param eventInfo The source info to get source. 181 * @param elementInfo The element info of source. 182 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 183 */ 184 virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, 185 AccessibilityElementInfo &elementInfo) override; 186 187 /** 188 * @brief Get Parent node information 189 * @param child The child element info to get parent. 190 * @param parent The parent element info. 191 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 192 */ 193 virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, 194 AccessibilityElementInfo &parent) override; 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 succeed, 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) override; 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) override; 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) override; 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) override; 252 253 private: 254 sptr<IAccessibleAbilityManagerService> serviceProxy_ = nullptr; 255 }; 256 } // namespace Accessibility 257 } // namespace OHOS 258 #endif // ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H