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