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 * @return Return RET_OK if obtains elementInfos successfully, otherwise refer to the RetError for the failure. 110 */ 111 virtual RetError GetRootByWindowBatch(const AccessibilityWindowInfo &windowInfo, 112 std::vector<AccessibilityElementInfo>& elementInfos, bool isFilter) override; 113 114 /** 115 * @brief Get the window information related with the event 116 * @param windowId The window id. 117 * @param windowInfo The window information. 118 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 119 */ 120 virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; 121 122 /** 123 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 124 * @param windows The information of windows. 125 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 126 */ 127 virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) override; 128 129 /** 130 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 131 * @param displayId the id of display 132 * @param windows The information of windows. 133 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 134 */ 135 virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) override; 136 137 /** 138 * @brief Gets the next focused node in the specified direction of the currently focused node. 139 * @param elementInfo The source info to get next info. 140 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 141 * @param nextElementInfo The info of next element. 142 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 143 */ 144 virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 145 AccessibilityElementInfo &nextElementInfo) override; 146 147 /** 148 * @brief Get the child node information by childId 149 * @param index The index of the child. 150 * @param parent The parent info to get child. 151 * @param child The element info of child. 152 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 153 */ 154 virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 155 AccessibilityElementInfo &child) override; 156 157 /** 158 * @brief Get the child node information 159 * @param parent The parent info to get child. 160 * @param children The element info of children. 161 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 162 */ 163 virtual RetError GetChildren(const AccessibilityElementInfo &parent, 164 std::vector<AccessibilityElementInfo> &children) override; 165 166 /** 167 * @brief Searches for node information based on the specified content. 168 * @param elementInfo The source info. 169 * @param text specified content 170 * @param elementInfos The element infos of specified content. 171 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 172 */ 173 virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 174 std::vector<AccessibilityElementInfo> &elementInfos) override; 175 176 /** 177 * @brief Get the node information related with the event 178 * @param eventInfo The source info to get source. 179 * @param elementInfo The element info of source. 180 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 181 */ 182 virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, 183 AccessibilityElementInfo &elementInfo) override; 184 185 /** 186 * @brief Get Parent node information 187 * @param child The child element info to get parent. 188 * @param parent The parent element info. 189 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 190 */ 191 virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, 192 AccessibilityElementInfo &parent) override; 193 194 /** 195 * @brief Executes a specified action. 196 * @param elementInfo The source info to execute action. 197 * @param action: the action type 198 * @param actionArguments: The parameter for action type. such as: 199 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 200 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 201 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 202 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 203 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 204 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 205 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 206 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 207 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 208 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 209 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 210 * action: ACCESSIBILITY_ACTION_SET_TEXT, 211 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 212 * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. 213 */ 214 virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, 215 const std::map<std::string, std::string> &actionArguments) override; 216 217 /** 218 * @brief Set target bundle names. 219 * @param targetBundleNames The target bundle name 220 * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. 221 */ 222 virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override; 223 224 /** 225 * @brief Set cache mode. 226 * The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo, 227 * GetChildren, GetSource, GetParentElementInfo. 228 * @param cacheMode The cache mode. It includes: 229 * PREFETCH_PREDECESSORS: cache the parent node info also. 230 * PREFETCH_SIBLINGS: cache the sister/brothers node info also. 231 * PREFETCH_CHILDREN: cache the child node info also. 232 * otherwise: no cache. 233 * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. 234 */ 235 virtual RetError SetCacheMode(const int32_t cacheMode) override; 236 237 /** 238 * @brief Find the node information by accessibility ID. 239 * @param accessibilityWindowId The window id that the component belongs to. 240 * @param elementId: The unique id of the component ID. 241 * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. 242 * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. 243 * PREFETCH_CHILDREN: Need to make the child node info also. 244 * otherwise: Make the node information by elementId only. 245 * @param info[out] The components information matched conditions searched. 246 * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure. 247 */ 248 virtual RetError SearchElementInfoByAccessibilityId(const int32_t windowId, const int64_t elementId, 249 const uint32_t mode, AccessibilityElementInfo &info, bool isFilter = false) override; 250 251 private: 252 sptr<IAccessibleAbilityManagerService> serviceProxy_ = nullptr; 253 }; 254 } // namespace Accessibility 255 } // namespace OHOS 256 #endif // ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H