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