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 TEST_WUKONG_TREE_MANAGER_H 17 #define TEST_WUKONG_TREE_MANAGER_H 18 19 #include "ability_tree.h" 20 #include "accessibility_element_info.h" 21 #include "component_tree.h" 22 #include "page_tree.h" 23 24 namespace OHOS { 25 namespace WuKong { 26 namespace { 27 const uint32_t INVALIDED_INPUT_INDEX = 0xFFFFFFFF; 28 } 29 /** 30 * @brief Generate component tree, get AccessibilityElementInfo for current active components. 31 */ 32 class TreeManager : public DelayedSingleton<TreeManager> { 33 /** 34 * for test flow to get and set test element info. 35 */ 36 public: 37 /** 38 * @brief init and clear container. 39 */ InitContainer()40 void InitContainer() 41 { 42 elementInfoList_.clear(); 43 abilityTreeList_.clear(); 44 pageTreeList_.clear(); 45 componentTreeList_.clear(); 46 } 47 48 /** 49 * @brief update wukong tree by AccessibilityUITestAbility. 50 * @return An AccessibilityElementInfo 51 */ 52 ErrCode UpdateComponentInfo(); 53 54 /** 55 * @brief get AccessibilityElementInfo for the Preorder Traversal Algorithms. 56 * @return An AccessibilityElementInfo 57 */ GetElementInfoByOrder()58 const std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>& GetElementInfoByOrder() 59 { 60 return inputElementInfo_; 61 } 62 63 /** 64 * @brief get AccessibilityElementInfo list of active component. 65 * @return input AccessibilityElementInfo list 66 */ GetActiveElementInfos()67 const std::vector<std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>>& GetActiveElementInfos() 68 { 69 return inputElementInfoList_; 70 } 71 72 /** 73 * @brief set input event component, and input type. 74 * @param index index of active element info list. 75 * @param actionType component input type. 76 */ 77 void SetInputcomponentIndex(int actionType, uint32_t index = INVALIDED_INPUT_INDEX); 78 79 /** 80 * for scene update tree. 81 */ 82 public: 83 /** 84 * @brief set ComponentTree list of active component. 85 * @param inputComponentList ComponentTree list. 86 */ 87 void SetActiveComponent(const std::vector<std::shared_ptr<ComponentTree>>& inputComponentList); 88 89 /** 90 * @brief set a ComponentTree of active component. 91 * @param inputComponent a ComponentTree. 92 */ 93 void SetActiveComponent(const std::shared_ptr<ComponentTree>& inputComponent); 94 95 /** 96 * @brief get current component tree. 97 * @return A ComponentTree 98 */ GetCurrentComponents()99 const std::shared_ptr<ComponentTree>& GetCurrentComponents() 100 { 101 return currentComponentNode_; 102 } 103 /** 104 * @brief get new component tree 105 * @return A ComponentTree 106 */ GetNewComponents()107 const std::shared_ptr<ComponentTree>& GetNewComponents() 108 { 109 return newComponentNode_; 110 } 111 112 /** 113 * @brief get current page node. 114 * @return A ComponentTree 115 */ GetCurrentPage()116 const std::shared_ptr<PageTree>& GetCurrentPage() 117 { 118 return currentPageNode_; 119 } 120 121 /** 122 * @brief get new page node 123 * @return A ComponentTree 124 */ GetNewPage()125 const std::shared_ptr<PageTree>& GetNewPage() 126 { 127 return newPageNode_; 128 } 129 130 /** 131 * @brief get current ability node. 132 * @return A AblilityTree 133 */ GetCurrentAbility()134 const std::shared_ptr<AbilityTree>& GetCurrentAbility() 135 { 136 return currentAbilityNode_; 137 } 138 139 /** 140 * @brief get all app bundle tree. 141 * @return A AblilityTree list 142 */ GetBundleList()143 const std::vector<std::shared_ptr<AbilityTree>>& GetBundleList() 144 { 145 return abilityTreeList_; 146 } 147 148 /** 149 * @brief add current page as a new page 150 * @return add new page result 151 */ 152 bool AddPage(); 153 /** 154 * @brief remove new page. 155 * @return remove new page result 156 */ 157 bool SamePage(); 158 159 /** 160 * @brief back and goto existed page 161 * @param layer 0 update current page, < 0 update parent page, > 0 update child page 162 * @param index child index 163 * @return update page result 164 */ 165 bool UpdatePage(int layer, uint32_t index = INVALIDED_INPUT_INDEX); 166 GetNewElementInfoList(uint32_t index)167 const std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo> GetNewElementInfoList(uint32_t index) 168 { 169 if (index < newElementInfoList_.size()) { 170 return newElementInfoList_[index]; 171 } else { 172 return {}; 173 } 174 } 175 176 bool RecursComponent(const std::shared_ptr<ComponentTree>& componentTree); 177 DECLARE_DELAYED_SINGLETON(TreeManager); 178 179 private: 180 bool RecursGetChildElementInfo(const std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>& parent, 181 const std::shared_ptr<ComponentTree>& componentParent); 182 bool FindAbility(const std::shared_ptr<AbilityTree>& abilityNode); 183 ErrCode MakeAndCheckNewAbility(); 184 bool UpdateCurrentPage(bool isAdd = false); 185 bool RemovePage(); 186 187 std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo> inputElementInfo_; 188 std::shared_ptr<ComponentTree> inputComponent_; 189 std::vector<std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>> inputElementInfoList_; 190 std::vector<std::shared_ptr<ComponentTree>> inputComponentList_; 191 192 std::shared_ptr<ComponentTree> currentComponentNode_ = std::make_shared<ComponentTree>(); 193 std::shared_ptr<ComponentTree> newComponentNode_ = std::make_shared<ComponentTree>(); 194 195 std::shared_ptr<AbilityTree> currentAbilityNode_ = std::make_shared<AbilityTree>(); 196 std::shared_ptr<AbilityTree> newAbilityNode_ = std::make_shared<AbilityTree>(); 197 198 std::shared_ptr<PageTree> currentPageNode_ = std::make_shared<PageTree>(); 199 std::shared_ptr<PageTree> newPageNode_ = std::make_shared<PageTree>(); 200 201 std::vector<std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>> newElementInfoList_; 202 203 std::vector<std::shared_ptr<OHOS::Accessibility::AccessibilityElementInfo>> elementInfoList_; 204 205 std::vector<std::shared_ptr<AbilityTree>> abilityTreeList_; 206 std::map<std::uint32_t, std::shared_ptr<PageTree>> pageTreeList_; 207 std::map<std::uint32_t, std::shared_ptr<ComponentTree>> componentTreeList_; 208 209 bool isUpdateComponentFinished_ = false; 210 bool isNewAbility_ = false; 211 }; 212 } // namespace WuKong 213 } // namespace OHOS 214 #endif 215