• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <string>
17 
18 #include "gtest/gtest.h"
19 
20 #define private public
21 #define protected public
22 #include "core/components_ng/base/frame_node.h"
23 #include "core/components_ng/base/ui_node.h"
24 #include "core/components_ng/base/view_stack_processor.h"
25 #include "core/components_ng/event/long_press_event.h"
26 #include "core/components_ng/pattern/button/button_pattern.h"
27 #include "core/components_ng/pattern/linear_layout/column_model.h"
28 #include "core/components_ng/pattern/linear_layout/column_model_ng.h"
29 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
30 #include "core/components_ng/pattern/pattern.h"
31 #include "core/components_ng/pattern/text/span_node.h"
32 #include "core/components_ng/property/accessibility_property.h"
33 #include "core/components_v2/inspector/inspector_constants.h"
34 #include "core/components_ng/base/view_abstract_model_ng.h"
35 
36 using namespace testing;
37 using namespace testing::ext;
38 
39 namespace OHOS::Ace::NG {
40 class MockPattern : public Pattern {
41 public:
42     MockPattern() = default;
43     ~MockPattern() override = default;
44 };
45 class AccessibilityPropertyTestThreeNg : public testing::Test {
46 public:
SetUpTestCase()47     static void SetUpTestCase() {};
TearDownTestCase()48     static void TearDownTestCase() {};
49 };
50 
51 /**
52  * @tc.name: AccessibilityPropertyTest001
53  * @tc.desc: Test the method IsTagInSubTreeComponent.
54  * @tc.type: FUNC
55  */
56 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree001, TestSize.Level1)
57 {
58     std::string tag = V2::XCOMPONENT_ETS_TAG;
59     AccessibilityProperty accessibilityProperty;
60 
61     bool ret = accessibilityProperty.IsTagInSubTreeComponent(tag);
62     EXPECT_TRUE(ret);
63 }
64 
65 /**
66  * @tc.name: AccessibilityPropertyTest002
67  * @tc.desc: Test the method IsTagInSubTreeComponent.
68  * @tc.type: FUNC
69  */
70 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree002, TestSize.Level1)
71 {
72     std::string tag = V2::CHECKBOX_ETS_TAG;
73     AccessibilityProperty accessibilityProperty;
74 
75     bool ret = accessibilityProperty.IsAccessibilityFocusableTag(tag);
76     EXPECT_TRUE(ret);
77 
78     tag = "test";
79     ret = accessibilityProperty.IsAccessibilityFocusableTag(tag);
80     EXPECT_FALSE(ret);
81 }
82 
83 /**
84  * @tc.name: AccessibilityPropertyTest003
85  * @tc.desc: Test the method IsAccessibilityFocusableTag.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree003, TestSize.Level1)
89 {
90     std::string tag = V2::CHECKBOX_ETS_TAG;
91     AccessibilityProperty accessibilityProperty;
92 
93     bool ret = accessibilityProperty.IsAccessibilityFocusableTag(tag);
94     EXPECT_TRUE(ret);
95 
96     tag = "test";
97     ret = accessibilityProperty.IsAccessibilityFocusableTag(tag);
98     EXPECT_FALSE(ret);
99 }
100 
101 /**
102  * @tc.name: AccessibilityPropertyTest004
103  * @tc.desc: Test the method SetAccessibilityNextFocusInspectorKey && SetAccessibilityTextWithEvent
104  *           && SetAccessibilityDescriptionWithEvent.
105  * @tc.type: FUNC
106  */
107 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree004, TestSize.Level1)
108 {
109     std::string accessibilityNextFocusInspectorKey = "test";
110     AccessibilityProperty accessibilityProperty;
111 
112     accessibilityProperty.SetAccessibilityNextFocusInspectorKey(accessibilityNextFocusInspectorKey);
113     EXPECT_EQ(accessibilityNextFocusInspectorKey, accessibilityProperty.accessibilityNextFocusInspectorKey_);
114 
115     accessibilityNextFocusInspectorKey = "";
116     accessibilityProperty.SetAccessibilityNextFocusInspectorKey(accessibilityNextFocusInspectorKey);
117     EXPECT_EQ(accessibilityNextFocusInspectorKey,
118         accessibilityProperty.accessibilityNextFocusInspectorKey_.value_or(""));
119 
120     std::string text = "test";
121     accessibilityProperty.SetAccessibilityTextWithEvent(text);
122     EXPECT_EQ(text, accessibilityProperty.accessibilityText_);
123 
124     text = "";
125     accessibilityProperty.SetAccessibilityTextWithEvent(text);
126     EXPECT_EQ(text, accessibilityProperty.accessibilityText_.value_or(""));
127 
128     std::string accessibilityDescription = "";
129     accessibilityProperty.SetAccessibilityDescriptionWithEvent(accessibilityDescription);
130     EXPECT_EQ(accessibilityDescription, accessibilityProperty.accessibilityDescription_.value_or(""));
131 }
132 
133 /**
134  * @tc.name: AccessibilityPropertyTest005
135  * @tc.desc: Test the method ActActionClick.
136  * @tc.type: FUNC
137  */
138 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree005, TestSize.Level1)
139 {
140     AccessibilityProperty accessibilityProperty;
141 
142     uint32_t action = 1;
143     accessibilityProperty.accessibilityActions_ = 1;
__anon80c77d580102(uint32_t type)144     accessibilityProperty.actionsImpl_ = [](uint32_t type){};
145     bool actionsDefined = accessibilityProperty.ActionsDefined(action);
146     EXPECT_TRUE(actionsDefined);
147     actionsDefined = accessibilityProperty.ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CLICK));
148     EXPECT_TRUE(actionsDefined);
149     auto result = accessibilityProperty.ActActionClick();
150     EXPECT_TRUE(result);
151 
152     action = 0;
153     accessibilityProperty.accessibilityActions_ = 0;
154     accessibilityProperty.actionClickImpl_ = nullptr;
155     result = accessibilityProperty.ActActionClick();
156     EXPECT_FALSE(result);
157 }
158 
159 /**
160  * @tc.name: AccessibilityPropertyTest006
161  * @tc.desc: Test the method ActActionLongClick.
162  * @tc.type: FUNC
163  */
164 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree006, TestSize.Level1)
165 {
166     AccessibilityProperty accessibilityProperty;
167 
168     uint32_t action = 2;
169     accessibilityProperty.accessibilityActions_ = 2;
__anon80c77d580202(uint32_t type)170     accessibilityProperty.actionsImpl_ = [](uint32_t type){};
171     bool actionsDefined = accessibilityProperty.ActionsDefined(action);
172     EXPECT_TRUE(actionsDefined);
173     actionsDefined = accessibilityProperty.ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_LONG_CLICK));
174     EXPECT_TRUE(actionsDefined);
175     auto result = accessibilityProperty.ActActionLongClick();
176     EXPECT_TRUE(result);
177 
178     action = 0;
179     accessibilityProperty.accessibilityActions_ = 0;
180     accessibilityProperty.actionClickImpl_ = nullptr;
181     result = accessibilityProperty.ActActionLongClick();
182     EXPECT_FALSE(result);
183 }
184 
185 /**
186  * @tc.name: AccessibilityPropertyTest007
187  * @tc.desc: Test the method ActActionPaste.
188  * @tc.type: FUNC
189  */
190 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree007, TestSize.Level1)
191 {
192     AccessibilityProperty accessibilityProperty;
193 
194     uint32_t action = 16;
195     accessibilityProperty.accessibilityActions_ = 16;
__anon80c77d580302(uint32_t type)196     accessibilityProperty.actionsImpl_ = [](uint32_t type){};
197     bool actionsDefined = accessibilityProperty.ActionsDefined(action);
198     EXPECT_TRUE(actionsDefined);
199     actionsDefined = accessibilityProperty.ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_PASTE));
200     EXPECT_TRUE(actionsDefined);
201     auto result = accessibilityProperty.ActActionPaste();
202     EXPECT_TRUE(result);
203 }
204 
205 /**
206  * @tc.name: AccessibilityPropertyTest008
207  * @tc.desc: Test the method ActActionCut.
208  * @tc.type: FUNC
209  */
210 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree008, TestSize.Level1)
211 {
212     AccessibilityProperty accessibilityProperty;
213 
214     uint32_t action = 4;
215     accessibilityProperty.accessibilityActions_ = 4;
__anon80c77d580402(uint32_t type)216     accessibilityProperty.actionsImpl_ = [](uint32_t type){};
217     bool actionsDefined = accessibilityProperty.ActionsDefined(action);
218     EXPECT_TRUE(actionsDefined);
219     actionsDefined = accessibilityProperty.ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CUT));
220     EXPECT_TRUE(actionsDefined);
221     auto result = accessibilityProperty.ActActionCut();
222     EXPECT_TRUE(result);
223 }
224 
225 /**
226  * @tc.name: AccessibilityPropertyTest009
227  * @tc.desc: Test the method ActActionCopy.
228  * @tc.type: FUNC
229  */
230 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree009, TestSize.Level1)
231 {
232     AccessibilityProperty accessibilityProperty;
233 
234     uint32_t action = 8;
235     accessibilityProperty.accessibilityActions_ = 8;
__anon80c77d580502(uint32_t type)236     accessibilityProperty.actionsImpl_ = [](uint32_t type){};
237     bool actionsDefined = accessibilityProperty.ActionsDefined(action);
238     EXPECT_TRUE(actionsDefined);
239     actionsDefined = accessibilityProperty.ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_COPY));
240     EXPECT_TRUE(actionsDefined);
241     auto result = accessibilityProperty.ActActionCopy();
242     EXPECT_TRUE(result);
243 }
244 
245 /**
246  * @tc.name: AccessibilityPropertyTest010
247  * @tc.desc: Test the method UpdateHoverTestRect.
248  * @tc.type: FUNC
249  */
250 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree010, TestSize.Level1)
251 {
252     AccessibilityProperty accessibilityProperty;
253     RectF origRect;
254     auto node = FrameNode::GetOrCreateFrameNode(
__anon80c77d580602() 255         V2::BUTTON_ETS_TAG, 1, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
256     auto ret = accessibilityProperty.UpdateHoverTestRect(node);
257     EXPECT_EQ(origRect, ret);
258 }
259 
260 /**
261  * @tc.name: AccessibilityPropertyTest011
262  * @tc.desc: Test the method HoverTestRecursive.
263  * @tc.type: FUNC
264  */
265 HWTEST_F(AccessibilityPropertyTestThreeNg, AccessibilityPropertyTestThree011, TestSize.Level1)
266 {
267     AccessibilityProperty accessibilityProperty;
268     PointF parentPoint(1, 1);
269     auto node = FrameNode::GetOrCreateFrameNode(
__anon80c77d580702() 270         V2::BUTTON_ETS_TAG, 1, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
271     AccessibilityHoverTestPath path;
272     std::unique_ptr<AccessibilityProperty::HoverTestDebugTraceInfo> debugInfo = nullptr;
273     bool ancestorGroupFlag;
274 
275     node->SetAccessibilityNodeVirtual();
276     EXPECT_TRUE(node->IsAccessibilityVirtualNode());
277     debugInfo = std::make_unique<AccessibilityProperty::HoverTestDebugTraceInfo>();
278 
279     bool ret = accessibilityProperty.HoverTestRecursive(parentPoint, node, path, debugInfo, ancestorGroupFlag);
280     EXPECT_FALSE(ret);
281 
282     node->isActive_ = true;
283     ret = accessibilityProperty.HoverTestRecursive(parentPoint, node, path, debugInfo, ancestorGroupFlag);
284     EXPECT_FALSE(ret);
285 }
286 } // namespace OHOS::Ace::NG
287