1 /* 2 * Copyright (c) 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 #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 35 using namespace testing; 36 using namespace testing::ext; 37 38 namespace OHOS::Ace::NG { 39 namespace { 40 const InspectorFilter filter; 41 const size_t ARRAY_SIZE = 1; 42 } // namespace 43 44 class MockPattern : public Pattern { 45 public: 46 MockPattern() = default; 47 ~MockPattern() override = default; 48 }; 49 class AccessibilityPropertyTestNg : public testing::Test { 50 public: SetUpTestCase()51 static void SetUpTestCase() {}; TearDownTestCase()52 static void TearDownTestCase() {}; 53 }; 54 55 /** 56 * @tc.name: AccessibilityPropertyTest001 57 * @tc.desc: Set show value into supportActions_ and get SupportAction length. 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest001, TestSize.Level1) 61 { 62 /** 63 * @tc.steps: step1. supportActions_ Use default values 64 * @tc.expected: Make the array length returned by the GetSupportAction function 0 65 */ 66 AccessibilityProperty props; 67 auto actions = props.GetSupportAction(); 68 EXPECT_EQ(actions.size(), 0); 69 70 /** 71 * @tc.steps: step2. supportActions_ = AceAction::ACTION_SCROLL_FORWARD 72 * @tc.expected: Make the array length returned by the GetSupportAction function 1 73 */ 74 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_SCROLL_FORWARD); 75 actions = props.GetSupportAction(); 76 EXPECT_EQ(actions.size(), ARRAY_SIZE); 77 78 /** 79 * @tc.steps: step3. supportActions_ = AceAction::ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY 80 * @tc.expected: Make the array length returned by the GetSupportAction function 1 81 */ 82 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); 83 actions = props.GetSupportAction(); 84 EXPECT_EQ(actions.size(), 2); 85 86 /** 87 * @tc.steps: step4. supportActions_ = AceAction::ACTION_SET_TEXT 88 * @tc.expected: Make the array length returned by the GetSupportAction function 1 89 */ 90 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_SET_TEXT); 91 actions = props.GetSupportAction(); 92 EXPECT_EQ(actions.size(), ARRAY_SIZE); 93 94 /** 95 * @tc.steps: step5. supportActions_ = AceAction::ACTION_COPY 96 * @tc.expected: Make the array length returned by the GetSupportAction function 1 97 */ 98 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_COPY); 99 actions = props.GetSupportAction(); 100 EXPECT_EQ(actions.size(), 2); 101 102 /** 103 * @tc.steps: step6. supportActions_ = AceAction::ACTION_PASTE 104 * @tc.expected: Make the array length returned by the GetSupportAction function 1 105 */ 106 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_PASTE); 107 actions = props.GetSupportAction(); 108 EXPECT_EQ(actions.size(), 2); 109 110 /** 111 * @tc.steps: step7. supportActions_ = AceAction::ACTION_CUT 112 * @tc.expected: Make the array length returned by the GetSupportAction function 1 113 */ 114 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_CUT); 115 actions = props.GetSupportAction(); 116 EXPECT_EQ(actions.size(), 3); 117 118 /** 119 * @tc.steps: step8. supportActions_ = AceAction::ACTION_SELECT 120 * @tc.expected: Make the array length returned by the GetSupportAction function 1 121 */ 122 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_SELECT); 123 actions = props.GetSupportAction(); 124 EXPECT_EQ(actions.size(), 0); 125 126 /** 127 * @tc.steps: step9. supportActions_ = AceAction::ACTION_SELECT 128 * @tc.expected: Make the array length returned by the GetSupportAction function 1 129 */ 130 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_SET_SELECTION); 131 actions = props.GetSupportAction(); 132 EXPECT_EQ(actions.size(), 1); 133 134 /** 135 * @tc.steps: step10. supportActions_ = AceAction::ACTION_CLEAR_SELECTION 136 * @tc.expected: Make the array length returned by the GetSupportAction function 1 137 */ 138 props.supportActions_ = static_cast<uint32_t>(AceAction::ACTION_CLEAR_SELECTION); 139 actions = props.GetSupportAction(); 140 EXPECT_EQ(actions.size(), 1); 141 } 142 143 /** 144 * @tc.name: AccessibilityPropertyTest002 145 * @tc.desc: Set action and execute it. 146 * @tc.type: FUNC 147 */ 148 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest002, TestSize.Level1) 149 { 150 /** 151 * @tc.steps: step1. actions is empty 152 * @tc.expected: act every action return false 153 */ 154 AccessibilityProperty props; 155 EXPECT_FALSE(props.ActActionClearSelection()); 156 EXPECT_FALSE(props.ActActionCopy()); 157 EXPECT_FALSE(props.ActActionCut()); 158 EXPECT_FALSE(props.ActActionMoveText(1, true)); 159 EXPECT_FALSE(props.ActActionPaste()); 160 EXPECT_FALSE(props.ActActionScrollBackward()); 161 EXPECT_FALSE(props.ActActionScrollForward()); 162 EXPECT_FALSE(props.ActActionSelect()); 163 EXPECT_FALSE(props.ActActionSetSelection(0, 1)); 164 EXPECT_FALSE(props.ActActionSetText("abc")); 165 166 /** 167 * @tc.steps: step2. Set action functions 168 * @tc.expected: act every action return true 169 */ __anon005966390202() 170 props.SetActionClearSelection([]() {}); 171 EXPECT_TRUE(props.ActActionClearSelection()); __anon005966390302() 172 props.SetActionCopy([]() {}); 173 EXPECT_TRUE(props.ActActionCopy()); __anon005966390402() 174 props.SetActionCut([]() {}); 175 EXPECT_TRUE(props.ActActionCut()); __anon005966390502(int32_t moveUnit, bool forward) 176 props.SetActionMoveText([](int32_t moveUnit, bool forward) {}); 177 EXPECT_TRUE(props.ActActionMoveText(1, true)); __anon005966390602() 178 props.SetActionPaste([]() {}); 179 EXPECT_TRUE(props.ActActionPaste()); __anon005966390702() 180 props.SetActionScrollBackward([]() {}); 181 EXPECT_TRUE(props.ActActionScrollBackward()); __anon005966390802() 182 props.SetActionScrollForward([]() {}); 183 EXPECT_TRUE(props.ActActionScrollForward()); __anon005966390902() 184 props.SetActionSelect([]() {}); 185 EXPECT_TRUE(props.ActActionSelect()); __anon005966390a02(int32_t start, int32_t end, bool isforward) 186 props.SetActionSetSelection([](int32_t start, int32_t end, bool isforward) {}); 187 EXPECT_TRUE(props.ActActionSetSelection(0, 1)); __anon005966390b02(std::string text) 188 props.SetActionSetText([](std::string text) {}); 189 EXPECT_TRUE(props.ActActionSetText("abc")); 190 } 191 192 /** 193 * @tc.name: AccessibilityPropertyTest003 194 * @tc.desc: Set and get accessibility property. 195 * @tc.type: FUNC 196 */ 197 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest003, TestSize.Level1) 198 { 199 /** 200 * @tc.steps: step1. Set accessibility property value 201 * @tc.expected: Get default property value 202 */ 203 AccessibilityProperty props; 204 props.SetText("test"); 205 EXPECT_EQ(props.GetText(), "test"); 206 auto json = std::make_unique<JsonValue>(); 207 props.ToJsonValue(json, filter); 208 EXPECT_FALSE(json->GetBool("scrollable", false)); 209 EXPECT_FALSE(props.IsCheckable()); 210 EXPECT_FALSE(props.IsChecked()); 211 EXPECT_FALSE(props.IsSelected()); 212 EXPECT_FALSE(props.IsPassword()); 213 EXPECT_FALSE(props.IsEditable()); 214 EXPECT_FALSE(props.IsMultiLine()); 215 EXPECT_FALSE(props.IsDeletable()); 216 217 EXPECT_FALSE(props.IsHint()); 218 EXPECT_FALSE(props.IsScrollable()); 219 EXPECT_EQ(props.GetCurrentIndex(), -1); 220 EXPECT_EQ(props.GetBeginIndex(), -1); 221 EXPECT_EQ(props.GetEndIndex(), -1); 222 EXPECT_FALSE(props.HasRange()); 223 EXPECT_EQ(props.GetAccessibilityValue().min, 0.0); 224 EXPECT_EQ(props.GetAccessibilityValue().current, 0.0); 225 EXPECT_EQ(props.GetAccessibilityValue().max, 0.0); 226 EXPECT_EQ(props.GetHintText(), ""); 227 EXPECT_EQ(props.GetTextLengthLimit(), -1); 228 EXPECT_EQ(props.GetCollectionInfo().columns, 0); 229 EXPECT_EQ(props.GetCollectionInfo().rows, 0); 230 EXPECT_EQ(props.GetCollectionInfo().selectMode, 0); 231 EXPECT_EQ(props.GetCollectionItemInfo().column, 0); 232 EXPECT_EQ(props.GetCollectionItemInfo().columnSpan, 0); 233 EXPECT_EQ(props.GetCollectionItemInfo().row, 0); 234 EXPECT_EQ(props.GetCollectionItemInfo().rowSpan, 0); 235 EXPECT_FALSE(props.GetCollectionItemInfo().heading); 236 EXPECT_EQ(props.GetErrorText(), ""); 237 EXPECT_EQ(props.GetTextSelectionStart(), 0); 238 EXPECT_EQ(props.GetTextSelectionEnd(), 0); 239 EXPECT_EQ(props.GetTextInputType(), AceTextCategory::INPUT_TYPE_DEFAULT); 240 EXPECT_EQ(props.GetCollectionItemCounts(), 0); 241 EXPECT_TRUE(props.GetContentInvalid()); 242 props.ResetSupportAction(); 243 auto actions = props.GetSupportAction(); 244 EXPECT_EQ(actions.size(), 0); 245 } 246 247 /** 248 * @tc.name: AccessibilityPropertyTest004 249 * @tc.desc: Set show value into supportActions_ and get SupportAction length. 250 * @tc.type: FUNC 251 */ 252 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest004, TestSize.Level1) 253 { 254 /** 255 * @tc.steps: step1. supportActions_ Use default values 256 * @tc.expected: Make the array length returned by the GetSupportAction function 0 257 */ 258 auto columnFrameNode1 = FrameNode::GetOrCreateFrameNode( __anon005966390c02() 259 V2::COLUMN_ETS_TAG, 0, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); }); 260 auto columnFrameNode2 = FrameNode::GetOrCreateFrameNode( __anon005966390d02() 261 V2::COLUMN_ETS_TAG, 1, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); }); 262 auto buttonNode1 = __anon005966390e02() 263 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 2, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 264 auto buttonNode2 = __anon005966390f02() 265 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 3, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 266 auto buttonNode3 = __anon005966391002() 267 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 4, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 268 auto buttonNode4 = __anon005966391102() 269 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 5, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 270 auto buttonAccessibilityProperty1 = buttonNode1->GetAccessibilityProperty<AccessibilityProperty>(); 271 auto buttonAccessibilityProperty2 = buttonNode2->GetAccessibilityProperty<AccessibilityProperty>(); 272 auto buttonAccessibilityProperty3 = buttonNode3->GetAccessibilityProperty<AccessibilityProperty>(); 273 auto buttonAccessibilityProperty4 = buttonNode4->GetAccessibilityProperty<AccessibilityProperty>(); 274 auto columnAccessibilityProperty2 = columnFrameNode2->GetAccessibilityProperty<AccessibilityProperty>(); 275 buttonAccessibilityProperty1->SetText("Button1"); 276 buttonAccessibilityProperty2->SetText("Button2"); 277 buttonAccessibilityProperty3->SetText("Button3"); 278 buttonAccessibilityProperty4->SetText("Button4"); 279 columnAccessibilityProperty2->SetAccessibilityText("column2"); 280 buttonAccessibilityProperty1->SetAccessibilityDescription("Button1"); 281 282 columnFrameNode1->frameChildren_.emplace(buttonNode1); 283 columnFrameNode1->frameChildren_.emplace(buttonNode2); 284 columnFrameNode1->frameChildren_.emplace(columnFrameNode2); 285 columnFrameNode2->frameChildren_.emplace(buttonNode3); 286 columnFrameNode2->frameChildren_.emplace(buttonNode4); 287 288 auto columnAccessibilityProperty1 = columnFrameNode1->GetAccessibilityProperty<AccessibilityProperty>(); 289 columnAccessibilityProperty1->SetAccessibilityGroup(true); 290 columnAccessibilityProperty1->SetAccessibilityLevel("yes"); 291 292 auto columnAccessibilityText1 = columnAccessibilityProperty1->GetGroupText(); 293 /** 294 * @tc.expected: step1. expect target text combine 295 */ 296 EXPECT_EQ(buttonAccessibilityProperty1->GetAccessibilityDescription(), "Button1"); 297 EXPECT_EQ(columnAccessibilityText1, "Button1, Button2, Button3, Button4"); 298 299 columnAccessibilityProperty1->SetAccessibilityLevel("no-hide-descendants"); 300 columnAccessibilityText1 = columnAccessibilityProperty1->GetGroupText(); 301 EXPECT_EQ(columnAccessibilityText1, ""); 302 } 303 304 /** 305 * @tc.name: AccessibilityPropertyTest005 306 * @tc.desc: Set show value into supportActions_ and get SupportAction length. 307 * @tc.type: FUNC 308 */ 309 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest005, TestSize.Level1) 310 { 311 std::string tag = "root"; 312 313 auto spanNode = SpanNode::GetOrCreateSpanNode(1); 314 auto columnFrameNode1 = FrameNode::GetOrCreateFrameNode( __anon005966391202() 315 V2::COLUMN_ETS_TAG, 0, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); }); 316 auto buttonNode1 = __anon005966391302() 317 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 2, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 318 spanNode->AddChild(buttonNode1); 319 columnFrameNode1->AddChild(spanNode); 320 321 std::list<RefPtr<FrameNode>> children; 322 323 auto columnAccessibilityProperty1 = columnFrameNode1->GetAccessibilityProperty<AccessibilityProperty>(); 324 columnAccessibilityProperty1->SetAccessibilityGroup(true); 325 columnAccessibilityProperty1->SetAccessibilityLevel("yes"); 326 columnAccessibilityProperty1->SetAccessibilityText("column1"); 327 328 auto text = columnAccessibilityProperty1->GetAccessibilityText(); 329 EXPECT_EQ(text, "column1"); 330 } 331 332 /** 333 * @tc.name: AccessibilityPropertyTest006 334 * @tc.desc: Set show value into supportActions_ and get SupportAction length. 335 * @tc.type: FUNC 336 */ 337 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest006, TestSize.Level1) 338 { 339 /** 340 * @tc.steps1: Create FrameNode and Add Children 341 */ 342 std::string tag = "root"; 343 auto spanNode = SpanNode::GetOrCreateSpanNode(1); 344 auto columnFrameNode1 = FrameNode::GetOrCreateFrameNode( __anon005966391402() 345 V2::COLUMN_ETS_TAG, 0, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); }); 346 auto buttonNode1 = __anon005966391502() 347 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 2, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 348 auto customFrameNode2 = CustomNode::CreateCustomNode(1, "Column"); 349 spanNode->AddChild(buttonNode1); 350 spanNode->AddChild(customFrameNode2); 351 columnFrameNode1->AddChild(spanNode); 352 columnFrameNode1->AddChild(buttonNode1); 353 auto columnAccessibilityProperty1 = columnFrameNode1->GetAccessibilityProperty<AccessibilityProperty>(); 354 columnAccessibilityProperty1->SetAccessibilityGroup(true); 355 columnAccessibilityProperty1->SetAccessibilityLevel("yes"); 356 columnAccessibilityProperty1->SetAccessibilityText("column1"); 357 358 /** 359 * @tc.steps2: call GetAccessibilityText 360 * @tc.expected: 'column1' 361 */ 362 auto text = columnAccessibilityProperty1->GetAccessibilityText(); 363 EXPECT_EQ(text, "column1"); 364 365 /** 366 * @tc.steps3: reset accessibilityText_ and call GetAccessibilityText 367 * @tc.expected: '' 368 */ 369 columnAccessibilityProperty1->accessibilityText_.reset(); 370 text = columnAccessibilityProperty1->GetAccessibilityText(); 371 EXPECT_EQ(text, ""); 372 373 /** 374 * @tc.steps4: add a new frameNode and SetAccessibilityText 375 * @tc.expected: 'test' 376 */ 377 auto buttonNode2 = __anon005966391602() 378 FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 3, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 379 buttonNode2->GetAccessibilityProperty<AccessibilityProperty>()->SetAccessibilityText("test"); 380 text = buttonNode2->GetAccessibilityProperty<AccessibilityProperty>()->GetAccessibilityText(); 381 EXPECT_EQ(text, "test"); 382 } 383 384 /** 385 * @tc.name: AccessibilityPropertyTest007 386 * @tc.desc: Set action and execute it. 387 * @tc.type: FUNC 388 */ 389 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest007, TestSize.Level1) 390 { 391 /** 392 * @tc.steps: step1. actions is empty 393 * @tc.expected: act every action return false 394 */ 395 AccessibilityProperty props; __anon005966391702(int32_t start, int32_t end, bool isforward) 396 props.SetActionSetSelection([](int32_t start, int32_t end, bool isforward) {}); 397 EXPECT_TRUE(props.ActActionSetSelection(0, 1)); __anon005966391802(int32_t start) 398 props.SetActionSetIndex([](int32_t start) {}); 399 EXPECT_TRUE(props.ActActionSetIndex(1)); __anon005966391902() 400 props.SetActionGetIndex([]() {return 2;}); 401 EXPECT_TRUE(props.ActActionGetIndex()); 402 } 403 404 /** 405 * @tc.name: AccessibilityPropertyTest008 406 * @tc.desc: GetScrollOffSet 407 * @tc.type: FUNC 408 */ 409 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest008, TestSize.Level1) 410 { 411 AccessibilityProperty accessibilityProperty; 412 auto result = accessibilityProperty.GetScrollOffSet(); 413 EXPECT_EQ(result, -1.0f); 414 } 415 416 /** 417 * @tc.name: AccessibilityPropertyTest009 418 * @tc.desc: HoverTest 419 * @tc.type: FUNC 420 */ 421 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest009, TestSize.Level1) 422 { 423 AccessibilityProperty accessibilityProperty; 424 auto root = FrameNode::GetOrCreateFrameNode( __anon005966391a02() 425 V2::BUTTON_ETS_TAG, 11, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 426 NG::PointF hoverPoint(0, 0); 427 auto debugInfo = std::make_unique<AccessibilityProperty::HoverTestDebugTraceInfo>(); 428 auto result = accessibilityProperty.HoverTest(hoverPoint, root, debugInfo); 429 EXPECT_EQ(result.size(), 0); 430 } 431 432 /** 433 * @tc.name: AccessibilityPropertyTest010 434 * @tc.desc: CreateNodeSearchInfo 435 * @tc.type: FUNC 436 */ 437 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest010, TestSize.Level1) 438 { 439 AccessibilityProperty accessibilityProperty; 440 bool ancestorGroupFlag = false; 441 auto root = FrameNode::CreateFrameNode( 442 V2::BUTTON_ETS_TAG, 12, AceType::MakeRefPtr<Pattern>(), true); 443 NG::PointF hoverPoint(0, 0); 444 auto result = accessibilityProperty.CreateNodeSearchInfo(root, hoverPoint, ancestorGroupFlag); 445 EXPECT_TRUE(root->IsRootNode()); 446 447 auto subNode = FrameNode::GetOrCreateFrameNode( __anon005966391b02() 448 V2::BUTTON_ETS_TAG, 1, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 449 root->AddChild(subNode); 450 EXPECT_FALSE(subNode->IsRootNode()); 451 result = accessibilityProperty.CreateNodeSearchInfo(subNode, hoverPoint, ancestorGroupFlag); 452 EXPECT_TRUE(result->Contains("parent")); 453 EXPECT_TRUE(result->Contains("visible")); 454 455 auto accessibilityPropertyRoot = root->GetAccessibilityProperty<NG::AccessibilityProperty>(); 456 EXPECT_NE(accessibilityPropertyRoot, nullptr); 457 EXPECT_TRUE(result->Contains("accessibilityLevel")); 458 459 root->SetHitTestMode(HitTestMode::HTMDEFAULT); 460 result = accessibilityProperty.CreateNodeSearchInfo(subNode, hoverPoint, ancestorGroupFlag); 461 EXPECT_TRUE(result->Contains("hitTestMode")); 462 std::string value = result->GetString("hitTestMode"); 463 EXPECT_EQ(value, "Default"); 464 465 auto subNode1 = FrameNode::GetOrCreateFrameNode( __anon005966391c02() 466 V2::BUTTON_ETS_TAG, 2, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 467 root->AddChild(subNode1); 468 subNode1->SetHitTestMode(HitTestMode::HTMBLOCK); 469 auto result1 = accessibilityProperty.CreateNodeSearchInfo(subNode1, hoverPoint, ancestorGroupFlag); 470 EXPECT_TRUE(result1->Contains("hitTestMode")); 471 std::string value1 = result1->GetString("hitTestMode"); 472 EXPECT_EQ(value1, "Block"); 473 474 auto subNode2 = FrameNode::GetOrCreateFrameNode( __anon005966391d02() 475 V2::BUTTON_ETS_TAG, 3, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 476 root->AddChild(subNode2); 477 subNode2->SetHitTestMode(HitTestMode::HTMTRANSPARENT); 478 auto result2 = accessibilityProperty.CreateNodeSearchInfo(subNode2, hoverPoint, ancestorGroupFlag); 479 EXPECT_TRUE(result2->Contains("hitTestMode")); 480 std::string value2 = result2->GetString("hitTestMode"); 481 EXPECT_EQ(value2, "Transparent"); 482 } 483 484 /** 485 * @tc.name: AccessibilityPropertyTest011 486 * @tc.desc: HoverTestRecursive 487 * @tc.type: FUNC 488 */ 489 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest011, TestSize.Level1) 490 { 491 GTEST_LOG_(INFO) << "AccessibilityPropertyTest011 start"; 492 AccessibilityProperty accessibilityProperty; 493 AccessibilityHoverTestPath path; 494 auto root = FrameNode::GetOrCreateFrameNode( __anon005966391e02() 495 V2::BUTTON_ETS_TAG, 1, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 496 NG::PointF hoverPoint(0, 0); 497 auto debugInfo = std::make_unique<AccessibilityProperty::HoverTestDebugTraceInfo>(); 498 499 bool ancestorGroupFlag = false; 500 501 root->SetActive(false); 502 auto result = accessibilityProperty.HoverTestRecursive(hoverPoint, root, path, debugInfo, ancestorGroupFlag); 503 EXPECT_EQ(result, false); 504 root->SetActive(true); 505 506 root->SetInternal(); 507 result = accessibilityProperty.HoverTestRecursive(hoverPoint, root, path, debugInfo, ancestorGroupFlag); 508 EXPECT_EQ(result, false); 509 510 root->SetActive(true); 511 root->isInternal_ = false; 512 } 513 514 /** 515 * @tc.name: AccessibilityPropertyTest012 516 * @tc.desc: GetSearchStrategy 517 * @tc.type: FUNC 518 */ 519 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest012, TestSize.Level1) 520 { 521 AccessibilityProperty accessibilityProperty; 522 bool ancestorGroupFlag = false; 523 auto frameNode = FrameNode::GetOrCreateFrameNode( __anon005966391f02() 524 V2::BUTTON_ETS_TAG, 14, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 525 auto result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 526 EXPECT_EQ(result, std::make_tuple(true, true, false)); 527 528 auto accessibilityPropertyNew = frameNode->GetAccessibilityProperty<NG::AccessibilityProperty>(); 529 EXPECT_NE(accessibilityPropertyNew, nullptr); 530 auto levelBak = accessibilityPropertyNew->GetAccessibilityLevel(); 531 accessibilityPropertyNew->SetAccessibilityLevel(AccessibilityProperty::Level::YES_STR); 532 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 533 EXPECT_EQ(result, std::make_tuple(true, true, false)); 534 535 bool hasGroupOrVirtualNodeBak = accessibilityPropertyNew->IsAccessibilityGroup(); 536 accessibilityPropertyNew->SetAccessibilityGroup(true); 537 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 538 EXPECT_EQ(result, std::make_tuple(true, true, true)); 539 accessibilityPropertyNew->SetAccessibilityGroup(hasGroupOrVirtualNodeBak); 540 accessibilityPropertyNew->SetAccessibilityLevel(levelBak); 541 542 accessibilityPropertyNew->SetAccessibilityLevel(AccessibilityProperty::Level::NO_HIDE_DESCENDANTS); 543 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 544 EXPECT_EQ(result, std::make_tuple(false, false, false)); 545 accessibilityPropertyNew->SetAccessibilityLevel(levelBak); 546 547 hasGroupOrVirtualNodeBak = accessibilityPropertyNew->IsAccessibilityGroup(); 548 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 549 EXPECT_EQ(result, std::make_tuple(true, true, false)); 550 551 accessibilityPropertyNew->SetAccessibilityGroup(true); 552 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 553 EXPECT_EQ(result, std::make_tuple(true, true, true)); 554 accessibilityPropertyNew->SetAccessibilityGroup(hasGroupOrVirtualNodeBak); 555 556 accessibilityPropertyNew->SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR); 557 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 558 EXPECT_EQ(result, std::make_tuple(false, true, false)); 559 560 accessibilityPropertyNew->SetAccessibilityLevel(AccessibilityProperty::Level::AUTO); 561 accessibilityPropertyNew->SetAccessibilityGroup(true); 562 bool hasGroupOrVirtualNode = accessibilityPropertyNew->IsAccessibilityGroup() || 563 accessibilityPropertyNew->HasAccessibilityVirtualNode(); 564 EXPECT_TRUE(hasGroupOrVirtualNode); 565 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 566 EXPECT_EQ(result, std::make_tuple(true, true, true)); 567 accessibilityPropertyNew->SetAccessibilityGroup(hasGroupOrVirtualNodeBak); 568 } 569 570 /** 571 * @tc.name: AccessibilityPropertyTest013 572 * @tc.desc: IsAccessibilityFocusableDebug 573 * @tc.type: FUNC 574 */ 575 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest013, TestSize.Level1) 576 { 577 AccessibilityProperty accessibilityProperty; 578 auto root = FrameNode::CreateFrameNode( 579 V2::BUTTON_ETS_TAG, 15, AceType::MakeRefPtr<Pattern>(), true); 580 std::unique_ptr<JsonValue> info = JsonUtil::Create(); 581 582 auto result = accessibilityProperty.IsAccessibilityFocusableDebug(root, info); 583 EXPECT_EQ(result, false); 584 585 bool isRoot = root->IsRootNode(); 586 EXPECT_EQ(isRoot, true); 587 auto buttonNode = FrameNode::GetOrCreateFrameNode( __anon005966392002() 588 V2::BUTTON_ETS_TAG, 6, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 589 root->AddChild(buttonNode); 590 result = accessibilityProperty.IsAccessibilityFocusableDebug(buttonNode, info); 591 EXPECT_EQ(result, false); 592 EXPECT_TRUE(info->Contains("parent")); 593 594 auto accessibilityPropertyBt = buttonNode->GetAccessibilityProperty<NG::AccessibilityProperty>(); 595 EXPECT_NE(accessibilityPropertyBt, nullptr); 596 EXPECT_TRUE(info->Contains("hasAction")); 597 } 598 599 600 /** 601 * @tc.name: AccessibilityPropertyTest014 602 * @tc.desc: IsAccessibilityFocusable 603 * @tc.type: FUNC 604 */ 605 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest014, TestSize.Level1) 606 { 607 AccessibilityProperty accessibilityProperty1; 608 auto root = FrameNode::CreateFrameNode( 609 V2::BUTTON_ETS_TAG, 15, AceType::MakeRefPtr<Pattern>(), true); 610 auto result = accessibilityProperty1.IsAccessibilityFocusable(root); 611 EXPECT_EQ(result, false); 612 613 auto frameNode = FrameNode::GetOrCreateFrameNode( __anon005966392102() 614 V2::BUTTON_ETS_TAG, 6, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 615 auto accessibilityProperty = frameNode->GetAccessibilityProperty<NG::AccessibilityProperty>(); 616 auto levelBak = accessibilityProperty->GetAccessibilityLevel(); 617 EXPECT_NE(accessibilityProperty, nullptr); 618 619 accessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::YES_STR); 620 result = accessibilityProperty->IsAccessibilityFocusable(frameNode); 621 EXPECT_EQ(result, true); 622 623 accessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR); 624 result = accessibilityProperty->IsAccessibilityFocusable(frameNode); 625 EXPECT_EQ(result, false); 626 627 accessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::AUTO); 628 accessibilityProperty->SetAccessibilityGroup(true); 629 result = accessibilityProperty->IsAccessibilityFocusable(frameNode); 630 EXPECT_EQ(result, true); 631 632 633 auto eventHub = frameNode->GetEventHub<EventHub>(); 634 bool isEnableBak = eventHub->IsEnabled(); 635 eventHub->SetEnabledInternal(false); 636 result = accessibilityProperty->IsAccessibilityFocusable(frameNode); 637 EXPECT_EQ(result, true); 638 eventHub->SetEnabledInternal(isEnableBak); 639 640 auto gestureEventHubBak = eventHub->GetGestureEventHub(); 641 auto gestureEventHubNew = eventHub->GetOrCreateGestureEventHub(); 642 EXPECT_TRUE(gestureEventHubNew != nullptr); 643 644 645 result = accessibilityProperty->IsAccessibilityFocusable(frameNode); 646 EXPECT_EQ(result, true); 647 eventHub->SetGestureEventHub(gestureEventHubBak); 648 } 649 650 /** 651 * @tc.name: AccessibilityPropertyTest027 652 * @tc.desc: test GetGroupTextRecursive 653 * @tc.type: FUNC 654 */ 655 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest027, TestSize.Level1) 656 { 657 AccessibilityProperty accessibilityProperty; 658 const std::string textValue = "textValue"; 659 accessibilityProperty.SetUserTextValue(textValue); 660 WeakPtr<FrameNode> hostBak = accessibilityProperty.host_; 661 accessibilityProperty.SetHost(nullptr); 662 std::string text = ""; 663 accessibilityProperty.GetGroupTextRecursive(false, text, false); 664 EXPECT_EQ(text, ""); 665 666 accessibilityProperty.SetHost(hostBak); 667 accessibilityProperty.GetGroupTextRecursive(false, text, false); 668 EXPECT_EQ(text, ""); 669 670 std::string levelBak = accessibilityProperty.GetAccessibilityLevel(); 671 accessibilityProperty.SetAccessibilityLevel(AccessibilityProperty::Level::YES_STR); 672 accessibilityProperty.GetGroupTextRecursive(false, text, false); 673 EXPECT_EQ(text, ""); 674 size_t found = text.find(','); 675 EXPECT_FALSE(found != std::string::npos); 676 accessibilityProperty.SetAccessibilityLevel(levelBak); 677 678 text = ""; 679 levelBak = accessibilityProperty.GetAccessibilityLevel(); 680 accessibilityProperty.SetAccessibilityLevel(AccessibilityProperty::Level::NO_HIDE_DESCENDANTS); 681 accessibilityProperty.GetGroupTextRecursive(false, text, false); 682 EXPECT_EQ(text, ""); 683 accessibilityProperty.SetAccessibilityLevel(levelBak); 684 685 text = ""; 686 levelBak = accessibilityProperty.GetAccessibilityLevel(); 687 accessibilityProperty.SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR); 688 accessibilityProperty.GetGroupTextRecursive(false, text, false); 689 EXPECT_EQ(text, ""); 690 accessibilityProperty.SetAccessibilityLevel(levelBak); 691 692 text = ""; 693 levelBak = accessibilityProperty.GetAccessibilityLevel(); 694 bool isAccessibilityGroup = accessibilityProperty.IsAccessibilityGroup(); 695 accessibilityProperty.SetAccessibilityLevel(AccessibilityProperty::Level::AUTO); 696 accessibilityProperty.SetAccessibilityGroup(true); 697 accessibilityProperty.GetGroupTextRecursive(true, text, false); 698 found = text.find(','); 699 EXPECT_FALSE(found != std::string::npos); 700 accessibilityProperty.SetAccessibilityLevel(levelBak); 701 accessibilityProperty.SetAccessibilityGroup(isAccessibilityGroup); 702 } 703 704 /** 705 * @tc.name: AccessibilityPropertyTest028 706 * @tc.desc: test ActionsDefined 707 * @tc.type: FUNC 708 */ 709 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest028, TestSize.Level1) 710 { 711 AccessibilityProperty accessibilityProperty; 712 uint32_t actions = static_cast<uint32_t>(ArkUI_AccessibilityActionType::ARKUI_ACCESSIBILITY_ACTION_COPY); 713 accessibilityProperty.ResetAccessibilityActions(); 714 bool isDefined = accessibilityProperty.ActionsDefined(actions); 715 EXPECT_FALSE(isDefined); 716 717 accessibilityProperty.SetAccessibilityActions(actions); 718 isDefined = accessibilityProperty.ActionsDefined(actions); 719 ActionsImpl actionsImplBak = accessibilityProperty.actionsImpl_; 720 accessibilityProperty.SetActions(nullptr); 721 isDefined = accessibilityProperty.ActionsDefined(actions); 722 EXPECT_FALSE(isDefined); 723 __anon005966392202(uint32_t type)724 ActionsImpl actionsImpl = [](uint32_t type){}; 725 accessibilityProperty.SetActions(actionsImpl); 726 isDefined = accessibilityProperty.ActionsDefined(actions); 727 EXPECT_TRUE(isDefined); 728 } 729 730 /** 731 * @tc.name: AccessibilityPropertyTest029 732 * @tc.desc: test CreateNodeSearchInfo 733 * @tc.type: FUNC 734 */ 735 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest029, TestSize.Level1) 736 { 737 AccessibilityProperty accessibilityProperty; 738 bool ancestorGroupFlag = false; 739 auto root = FrameNode::CreateFrameNode( 740 V2::BUTTON_ETS_TAG, 12, AceType::MakeRefPtr<Pattern>(), true); 741 NG::PointF hoverPoint(0, 0); 742 auto result = accessibilityProperty.CreateNodeSearchInfo(root, hoverPoint, ancestorGroupFlag); 743 EXPECT_TRUE(root->IsRootNode()); 744 745 auto subNode = FrameNode::GetOrCreateFrameNode( __anon005966392302() 746 V2::BUTTON_ETS_TAG, 1, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 747 root->AddChild(subNode); 748 EXPECT_FALSE(subNode->IsRootNode()); 749 result = accessibilityProperty.CreateNodeSearchInfo(subNode, hoverPoint, ancestorGroupFlag); 750 EXPECT_TRUE(result->Contains("parent")); 751 EXPECT_TRUE(result->Contains("visible")); 752 753 auto accessibilityPropertyRoot = root->GetAccessibilityProperty<NG::AccessibilityProperty>(); 754 EXPECT_NE(accessibilityPropertyRoot, nullptr); 755 EXPECT_TRUE(result->Contains("accessibilityLevel")); 756 757 auto subNode3 = FrameNode::GetOrCreateFrameNode( __anon005966392402() 758 V2::BUTTON_ETS_TAG, 4, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 759 root->AddChild(subNode3); 760 subNode3->SetHitTestMode(HitTestMode::HTMNONE); 761 auto result3 = accessibilityProperty.CreateNodeSearchInfo(subNode3, hoverPoint, ancestorGroupFlag); 762 EXPECT_TRUE(result3->Contains("hitTestMode")); 763 std::string value3 = result3->GetString("hitTestMode"); 764 EXPECT_EQ(value3, "None"); 765 766 auto subNode4 = FrameNode::GetOrCreateFrameNode( __anon005966392502() 767 V2::BUTTON_ETS_TAG, 5, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 768 root->AddChild(subNode4); 769 subNode4->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF); 770 auto result4 = accessibilityProperty.CreateNodeSearchInfo(subNode4, hoverPoint, ancestorGroupFlag); 771 EXPECT_TRUE(result4->Contains("hitTestMode")); 772 std::string value4 = result4->GetString("hitTestMode"); 773 EXPECT_EQ(value4, "Unsupported"); 774 } 775 776 /** 777 * @tc.name: AccessibilityPropertyTest030 778 * @tc.desc: GetSearchStrategy 779 * @tc.type: FUNC 780 */ 781 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest030, TestSize.Level1) 782 { 783 AccessibilityProperty accessibilityProperty; 784 bool ancestorGroupFlag = false; 785 auto frameNode = FrameNode::GetOrCreateFrameNode( __anon005966392602() 786 V2::BUTTON_ETS_TAG, 14, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 787 788 auto accessibilityPropertyNew = frameNode->GetAccessibilityProperty<NG::AccessibilityProperty>(); 789 EXPECT_NE(accessibilityPropertyNew, nullptr); 790 auto levelBak = accessibilityPropertyNew->GetAccessibilityLevel(); 791 accessibilityPropertyNew->SetAccessibilityLevel(AccessibilityProperty::Level::YES_STR); 792 auto result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 793 EXPECT_EQ(result, std::make_tuple(true, true, false)); 794 795 bool hasGroupOrVirtualNodeBak = accessibilityPropertyNew->IsAccessibilityGroup(); 796 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 797 EXPECT_EQ(result, std::make_tuple(true, true, false)); 798 799 accessibilityPropertyNew->SetAccessibilityGroup(true); 800 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 801 EXPECT_EQ(result, std::make_tuple(true, true, true)); 802 accessibilityPropertyNew->SetAccessibilityGroup(hasGroupOrVirtualNodeBak); 803 804 accessibilityPropertyNew->SetAccessibilityText("test"); 805 bool hasAccessibilityText = accessibilityPropertyNew->HasAccessibilityTextOrDescription(); 806 EXPECT_TRUE(hasAccessibilityText); 807 result = accessibilityPropertyNew->GetSearchStrategy(frameNode, ancestorGroupFlag); 808 EXPECT_EQ(result, std::make_tuple(true, true, false)); 809 accessibilityPropertyNew->SetAccessibilityLevel(levelBak); 810 811 frameNode->accessibilityProperty_ = nullptr; 812 auto accessibilityProperty2 = frameNode->GetAccessibilityProperty<NG::AccessibilityProperty>(); 813 EXPECT_EQ(accessibilityProperty2, nullptr); 814 815 auto eventHub = frameNode->GetEventHub<EventHub>(); 816 eventHub->SetEnabled(false); 817 EXPECT_FALSE(eventHub->IsEnabled()); 818 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 819 EXPECT_EQ(result, std::make_tuple(true, false, false)); 820 821 frameNode->SetHitTestMode(HitTestMode::HTMBLOCK); 822 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 823 EXPECT_EQ(result, std::make_tuple(true, false, false)); 824 825 frameNode->SetHitTestMode(HitTestMode::HTMTRANSPARENT); 826 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 827 EXPECT_EQ(result, std::make_tuple(true, false, false)); 828 829 frameNode->SetHitTestMode(HitTestMode::HTMNONE); 830 result = accessibilityProperty.GetSearchStrategy(frameNode, ancestorGroupFlag); 831 EXPECT_EQ(result, std::make_tuple(false, false, false)); 832 } 833 834 /** 835 * @tc.name: AccessibilityPropertyTest031 836 * @tc.desc: GetSearchStrategy 837 * @tc.type: FUNC 838 */ 839 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest031, TestSize.Level1) 840 { 841 bool ancestorGroupFlag = true; 842 auto frameNode = FrameNode::GetOrCreateFrameNode( __anon005966392702() 843 V2::BUTTON_ETS_TAG, 14, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 844 auto vNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), 845 AceType::MakeRefPtr<LinearLayoutPattern>(true)); 846 auto vChildNode = FrameNode::CreateFrameNode(V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), 847 AceType::MakeRefPtr<ButtonPattern>()); 848 vNode->AddChild(vChildNode); 849 auto accessibilityProperty = frameNode->GetAccessibilityProperty<AccessibilityProperty>(); 850 accessibilityProperty->SetAccessibilityLevel("yes"); 851 accessibilityProperty->SetAccessibilityGroup(false); 852 accessibilityProperty->SaveAccessibilityVirtualNode(vNode); 853 854 auto result = accessibilityProperty->GetSearchStrategy(frameNode, ancestorGroupFlag); 855 EXPECT_EQ(accessibilityProperty->HasAccessibilityVirtualNode(), true); 856 EXPECT_EQ(result, std::make_tuple(true, true, true)); 857 } 858 859 /** 860 * @tc.name: AccessibilityPropertyTest032 861 * @tc.desc: ProcessHoverTestRecursive 862 * @tc.type: FUNC 863 */ 864 HWTEST_F(AccessibilityPropertyTestNg, AccessibilityPropertyTest032, TestSize.Level1) 865 { 866 AccessibilityProperty accessibilityProperty; 867 AccessibilityHoverTestPath path; 868 auto root = FrameNode::GetOrCreateFrameNode( __anon005966392802() 869 V2::BUTTON_ETS_TAG, 13, []() { return AceType::MakeRefPtr<ButtonPattern>(); }); 870 NG::PointF hoverPoint(0, 0); 871 auto debugInfo = std::make_unique<AccessibilityProperty::HoverTestDebugTraceInfo>(); 872 AccessibilityProperty::RecursiveParam recursiveParam; 873 recursiveParam.hitTarget = true; 874 recursiveParam.ancestorGroupFlag = true; 875 auto result = accessibilityProperty.ProcessHoverTestRecursive(hoverPoint, root, path, debugInfo, recursiveParam); 876 EXPECT_EQ(result, true); 877 } 878 } // namespace OHOS::Ace::NG 879