1 /* 2 * Copyright (c) 2024 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 #include "test/unittest/core/base/frame_node_test_ng.h" 16 17 #include "base/memory/ace_type.h" 18 #include "base/memory/referenced.h" 19 #include "frameworks/core/components_ng/pattern/image/image_pattern.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 24 namespace OHOS::Ace::NG { 25 namespace { 26 const PanDirection DRAG_DIRECTION = { PanDirection::LEFT }; 27 constexpr int32_t FINGERS_NUMBER = 2; 28 constexpr float DISTANCE = 10.5f; 29 constexpr float DEFAULT_OPACITY = 0.95f; 30 constexpr float PARA_OPACITY_VALUE_1 = 0.1f; 31 constexpr float PARA_OPACITY_VALUE_2 = 0.2f; 32 constexpr float PARA_OPACITY_VALUE_3 = 0.3f; 33 constexpr float PARA_OPACITY_VALUE_4 = 0.4f; 34 constexpr float PARA_OPACITY_VALUE_5 = 0.5f; 35 constexpr float PARA_OPACITY_VALUE_6 = 0.6f; 36 constexpr float PARA_OPACITY_VALUE_7 = 0.7f; 37 constexpr float PARA_OPACITY_VALUE_8 = 1.0f; 38 constexpr float MIN_OPACITY { 0.0f }; 39 constexpr float MAX_OPACITY { 1.0f }; 40 } // namespace 41 42 /** 43 * @tc.name: FrameNodeTestNg_TouchTest041 44 * @tc.desc: Test frameNode TouchTest 45 * @tc.type: FUNC 46 */ 47 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest041, TestSize.Level1) 48 { 49 /** 50 * @tc.steps: step1. construct TouchTest parameters. 51 */ 52 PointF globalPoint; 53 PointF parentLocalPoint; 54 TouchRestrict touchRestrict; 55 TouchTestResult result; 56 ResponseLinkResult responseLinkResult; 57 /** 58 * @tc.steps: step2. set isActive_ and debugEnabled_ is true and FRAME_NODE2 eventHub is HTMBLOCK. 59 * @tc.expected: expect The function return value is STOP_BUBBLING. 60 */ 61 FRAME_NODE2->isActive_ = true; 62 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 63 SystemProperties::debugEnabled_ = true; 64 auto eventHub = FRAME_NODE2->GetOrCreateGestureEventHub(); 65 eventHub->SetHitTestMode(HitTestMode::HTMBLOCK); 66 auto test = FRAME_NODE2->TouchTest( 67 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 68 EXPECT_EQ(test, HitTestResult::OUT_OF_REGION); 69 } 70 71 /** 72 * @tc.name: FrameNodeTestNg_TouchTest042 73 * @tc.desc: Test frameNode TouchTest 74 * @tc.type: FUNC 75 */ 76 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest042, TestSize.Level1) 77 { 78 /** 79 * @tc.steps: step1. construct TouchTest parameters. 80 */ 81 PointF globalPoint; 82 PointF parentLocalPoint; 83 TouchRestrict touchRestrict; 84 TouchTestResult result; 85 ResponseLinkResult responseLinkResult; 86 87 /** 88 * @tc.steps: step2. set debugEnabled_ is true. 89 */ 90 FRAME_NODE2->isActive_ = true; 91 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 92 SystemProperties::debugEnabled_ = true; 93 auto test = FRAME_NODE2->TouchTest( 94 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 95 96 /** 97 * @tc.steps: step3. create childnode. 98 */ 99 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 100 childNode->SetExclusiveEventForChild(true); 101 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 102 childNode->renderContext_ = mockRenderContextforChild; 103 auto localPoint = PointF(10, 10); 104 mockRenderContextforChild->rect_ = RectF(0, 0, 100, 100); 105 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 106 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 107 auto childEventHub = childNode->GetOrCreateGestureEventHub(); 108 childEventHub->SetHitTestMode(HitTestMode::HTMBLOCK); 109 childNode->SetActive(true); 110 111 /** 112 * @tc.steps: step4. add childnode to the framenode. 113 * @tc.expected: expect The function return value is STOP_BUBBLING. 114 */ 115 std::list<RefPtr<FrameNode>> children; 116 children.push_back(childNode); 117 FRAME_NODE2->frameChildren_ = { children.begin(), children.end() }; 118 test = FRAME_NODE2->TouchTest( 119 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 120 EXPECT_EQ(test, HitTestResult::OUT_OF_REGION); 121 } 122 123 /** 124 * @tc.name: FrameNodeTestNg_TouchTest043 125 * @tc.desc: Test frameNode TouchTest 126 * @tc.type: FUNC 127 */ 128 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest043, TestSize.Level1) 129 { 130 /** 131 * @tc.steps: step1. construct TouchTest parameters. 132 */ 133 PointF globalPoint; 134 PointF parentLocalPoint; 135 TouchRestrict touchRestrict; 136 TouchTestResult result; 137 ResponseLinkResult responseLinkResult; 138 /** 139 * @tc.steps: step2. eventHub_->GetGestureEventHub() != nullptr and callback != null. 140 * @tc.expected: expect The function return value is STOP_BUBBLING. 141 */ 142 FRAME_NODE2->isActive_ = true; 143 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 144 SystemProperties::debugEnabled_ = true; __anon78b9b8440202(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) 145 auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>& info) { 146 return GestureJudgeResult::REJECT; 147 }; 148 auto gestureEventHub = FRAME_NODE2->GetEventHub<EventHub>()->GetOrCreateGestureEventHub(); 149 gestureEventHub->SetOnGestureJudgeBegin(gestureJudgeFunc); 150 auto test = FRAME_NODE2->TouchTest( 151 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 152 EXPECT_EQ(test, HitTestResult::OUT_OF_REGION); 153 } 154 155 /** 156 * @tc.name: FrameNodeTouchTest044 157 * @tc.desc: Test method TransferExecuteAction 158 * @tc.type: FUNC 159 */ 160 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest044, TestSize.Level1) 161 { 162 /** 163 * @tc.steps: step1. construct parameters. 164 */ 165 FRAME_NODE2->isActive_ = true; 166 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 167 SystemProperties::debugEnabled_ = true; 168 auto eventHub = FRAME_NODE2->GetOrCreateGestureEventHub(); 169 eventHub->SetHitTestMode(HitTestMode::HTMBLOCK); 170 std::map<std::string, std::string> actionArguments; 171 172 /** 173 * @tc.steps: step2. call TransferExecuteAction. 174 * @tc.expected: expect result is false. 175 */ 176 bool result = FRAME_NODE2->TransferExecuteAction(1, actionArguments, 1, 1); 177 EXPECT_FALSE(result); 178 } 179 180 /** 181 * @tc.name: FrameNodeTouchTest045 182 * @tc.desc: Test method GetUiExtensionId 183 * @tc.type: FUNC 184 */ 185 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest045, TestSize.Level1) 186 { 187 /** 188 * @tc.steps: step1. construct parameters. 189 */ 190 FRAME_NODE2->isActive_ = true; 191 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 192 SystemProperties::debugEnabled_ = true; 193 194 /** 195 * @tc.steps: step2. call GetUiExtensionId. 196 * @tc.expected: expect result is -1. 197 */ 198 int32_t result = FRAME_NODE2->GetUiExtensionId(); 199 EXPECT_EQ(result, -1); 200 } 201 202 /** 203 * @tc.name: FrameNodeTouchTest046 204 * @tc.desc: Test method WrapExtensionAbilityId 205 * @tc.type: FUNC 206 */ 207 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest046, TestSize.Level1) 208 { 209 /** 210 * @tc.steps: step1. construct parameters. 211 */ 212 FRAME_NODE2->isActive_ = true; 213 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 214 SystemProperties::debugEnabled_ = true; 215 216 int32_t extensionOffset = 1; 217 int32_t abilityId = 1; 218 219 /** 220 * @tc.steps: step2. call WrapExtensionAbilityId. 221 * @tc.expected: expect result is -1. 222 */ 223 int32_t result = FRAME_NODE2->WrapExtensionAbilityId(extensionOffset, abilityId); 224 EXPECT_EQ(result, -1); 225 } 226 227 /** 228 * @tc.name: FrameNodeTouchTest048 229 * @tc.desc: Test method DumpViewDataPageNode 230 * @tc.type: FUNC 231 */ 232 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest048, TestSize.Level1) 233 { 234 /** 235 * @tc.steps: step1. construct parameters. 236 */ 237 FRAME_NODE2->isActive_ = true; 238 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 239 SystemProperties::debugEnabled_ = true; 240 auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 241 242 /** 243 * @tc.steps: step2. call DumpViewDataPageNode. 244 * @tc.expected: expect renderContext_ not nullptr. 245 */ 246 247 FRAME_NODE2->DumpViewDataPageNode(viewDataWrap); 248 EXPECT_NE(FRAME_NODE2->renderContext_, nullptr); 249 } 250 251 /** 252 * @tc.name: FrameNodeTouchTest049 253 * @tc.desc: Test method GetResponseRegionList 254 * @tc.type: FUNC 255 */ 256 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest049, TestSize.Level1) 257 { 258 /** 259 * @tc.steps: step1. construct parameters. 260 */ 261 FRAME_NODE2->isActive_ = true; 262 FRAME_NODE2->GetEventHub<EventHub>()->SetEnabled(true); 263 264 DimensionRect responseRect(Dimension(0), Dimension(0), DimensionOffset(OFFSETF)); 265 std::vector<DimensionRect> mouseResponseRegion; 266 mouseResponseRegion.emplace_back(responseRect); 267 268 /** 269 * @tc.steps: step2. call GetResponseRegionList. 270 * @tc.expected: expect MouseResponseRegion is not empty. 271 */ 272 auto gestureEventHub = FRAME_NODE2->GetEventHub<EventHub>()->GetOrCreateGestureEventHub(); 273 gestureEventHub->SetMouseResponseRegion(mouseResponseRegion); 274 275 auto paintRect = FRAME_NODE2->renderContext_->GetPaintRectWithoutTransform(); 276 FRAME_NODE2->GetResponseRegionList(paintRect, 1); 277 EXPECT_FALSE(gestureEventHub->GetMouseResponseRegion().empty()); 278 } 279 280 /** 281 * @tc.name: FrameNodeTouchTest050 282 * @tc.desc: Test method GetResponseRegionList 283 * @tc.type: FUNC 284 */ 285 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest050, TestSize.Level1) 286 { 287 /** 288 * @tc.steps: step1. construct parameters. 289 */ 290 FRAME_NODE2->isActive_ = true; 291 292 /** 293 * @tc.steps: step2. call GetResponseRegionList. 294 * @tc.expected: expect GetResponseRegion is not empty. 295 */ 296 std::vector<DimensionRect> responseRegion; 297 responseRegion.push_back(DimensionRect()); 298 auto gestureEventHub = FRAME_NODE2->GetEventHub<EventHub>()->GetOrCreateGestureEventHub(); 299 gestureEventHub->SetResponseRegion(responseRegion); 300 auto paintRect = FRAME_NODE2->renderContext_->GetPaintRectWithoutTransform(); 301 FRAME_NODE2->GetResponseRegionList(paintRect, 1); 302 EXPECT_FALSE(gestureEventHub->GetResponseRegion().empty()); 303 } 304 305 /** 306 * @tc.name: FrameNodeTestNg_DumpAdvanceInfo001 307 * @tc.desc: Test frame node method DumpAdvanceInfo 308 * @tc.type: FUNC 309 */ 310 HWTEST_F(FrameNodeTestNg, DumpAdvanceInfo001, TestSize.Level1) 311 { 312 /** 313 * @tc.steps: step1. initialize parameters. 314 */ 315 FRAME_NODE3->isActive_ = true; 316 FRAME_NODE3->GetEventHub<EventHub>()->SetEnabled(true); 317 SystemProperties::debugEnabled_ = true; 318 319 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 320 FRAME_NODE3->renderContext_ = mockRenderContext; 321 FRAME_NODE3->DumpInfo(); 322 323 /** 324 * @tc.steps: step2. initialize layoutProperty_ and call DumpAdvanceInfo. 325 * @tc.expected: expect DumpAdvanceInfo run ok. 326 */ 327 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 328 FRAME_NODE2->layoutProperty_ = layoutProperty; 329 FRAME_NODE3->layoutProperty_->geometryTransition_ = 330 ElementRegister::GetInstance()->GetOrCreateGeometryTransition("test", false, true); 331 FRAME_NODE3->DumpAdvanceInfo(); 332 EXPECT_NE(FRAME_NODE3->renderContext_, nullptr); 333 } 334 335 /** 336 * @tc.name: FrameNodeTestNg_GetOnChildTouchTestRet001 337 * @tc.desc: Test frame node method GetOnChildTouchTestRet 338 * @tc.type: FUNC 339 */ 340 HWTEST_F(FrameNodeTestNg, GetOnChildTouchTestRet001, TestSize.Level1) 341 { 342 /** 343 * @tc.steps: step1. initialize parameters. 344 */ 345 std::vector<TouchTestInfo> touchInfos; 346 TouchTestInfo info; 347 touchInfos.emplace_back(info); 348 349 TouchResult touchResult; 350 touchResult.strategy = TouchTestStrategy::DEFAULT; 351 touchResult.id = "test1"; 352 __anon78b9b8440302(const std::vector<TouchTestInfo>& touchInfo) 353 OnChildTouchTestFunc callback = [](const std::vector<TouchTestInfo>& touchInfo) { 354 TouchResult res; 355 res.strategy = TouchTestStrategy::DEFAULT; 356 res.id = "test1"; 357 return res; 358 }; 359 360 /** 361 * @tc.steps: step2. set parent node and initialize gestureHub. 362 */ 363 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 364 auto gestureHub = GET_PARENT->GetOrCreateGestureEventHub(); 365 gestureHub->SetOnTouchTestFunc(std::move(callback)); 366 367 /** 368 * @tc.steps: step3. call GetOnChildTouchTestRet. 369 * @tc.expected: expect GetOnChildTouchTestRet run ok. 370 */ 371 TouchResult test = GET_PARENT->GetOnChildTouchTestRet(touchInfos); 372 EXPECT_EQ(test.id, touchResult.id); 373 } 374 375 /** 376 * @tc.name: FrameNodeTestNg_GetOnTouchTestFunc001 377 * @tc.desc: Test frame node method GetOnTouchTestFunc 378 * @tc.type: FUNC 379 */ 380 HWTEST_F(FrameNodeTestNg, GetOnTouchTestFunc001, TestSize.Level1) 381 { 382 /** 383 * @tc.steps: step1. set parent node and call GetOnTouchTestFunc. 384 */ 385 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 386 OnChildTouchTestFunc test = GET_PARENT->GetOnTouchTestFunc(); 387 388 /** 389 * @tc.expected: expect GetOnTouchTestFunc ruturn nullptr. 390 */ 391 EXPECT_EQ(test, nullptr); 392 __anon78b9b8440402(const std::vector<TouchTestInfo>& touchInfo) 393 OnChildTouchTestFunc callback = [](const std::vector<TouchTestInfo>& touchInfo) { 394 TouchResult result; 395 return result; 396 }; 397 398 /** 399 * @tc.steps: step2. set parent node and initialize gestureHub. 400 */ 401 auto gestureHub = GET_PARENT->GetOrCreateGestureEventHub(); 402 gestureHub->SetOnTouchTestFunc(std::move(callback)); 403 404 /** 405 * @tc.steps: step3. call GetOnTouchTestFunc. 406 * @tc.expected: expect GetOnTouchTestFunc run ok. 407 */ 408 OnChildTouchTestFunc res = GET_PARENT->GetOnTouchTestFunc(); 409 EXPECT_NE(res, nullptr); 410 } 411 412 /** 413 * @tc.name: FrameNodeTestNg_GetDispatchFrameNode001 414 * @tc.desc: Test frame node method GetDispatchFrameNode 415 * @tc.type: FUNC 416 */ 417 HWTEST_F(FrameNodeTestNg, GetDispatchFrameNode001, TestSize.Level1) 418 { 419 /** 420 * @tc.steps: step1. creat node and generate a node tree. 421 */ 422 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 423 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 424 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 425 GET_CHILD1->UpdateInspectorId("child1"); 426 GET_CHILD2->UpdateInspectorId("child2"); 427 GET_PARENT->frameChildren_.insert(GET_CHILD1); 428 GET_PARENT->frameChildren_.insert(GET_CHILD2); 429 430 /** 431 * @tc.steps: step2. initialize parentEventHub and set HitTestMode. 432 */ 433 auto parentEventHub = GET_PARENT->GetOrCreateGestureEventHub(); 434 parentEventHub->SetHitTestMode(HitTestMode::HTMBLOCK); 435 TouchResult touchResult; 436 437 /** 438 * @tc.steps: step3. call GetDispatchFrameNode. 439 * @tc.expected: expect GetDispatchFrameNode ruturn nullptr. 440 */ 441 auto test = GET_PARENT->GetDispatchFrameNode(touchResult); 442 EXPECT_EQ(test, nullptr); 443 } 444 445 /** 446 * @tc.name: FrameNodeTestNg_GetDispatchFrameNode002 447 * @tc.desc: Test frame node method GetDispatchFrameNode 448 * @tc.type: FUNC 449 */ 450 HWTEST_F(FrameNodeTestNg, GetDispatchFrameNode002, TestSize.Level1) 451 { 452 /** 453 * @tc.steps: step1. creat node and generate a node tree. 454 */ 455 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 456 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 457 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 458 GET_CHILD1->UpdateInspectorId("child1"); 459 GET_CHILD2->UpdateInspectorId("child2"); 460 GET_PARENT->frameChildren_.insert(GET_CHILD1); 461 GET_PARENT->frameChildren_.insert(GET_CHILD2); 462 463 /** 464 * @tc.steps: step2. initialize parentEventHub, set HitTestMode and TouchTestStrategy. 465 */ 466 auto parentEventHub = GET_PARENT->GetOrCreateGestureEventHub(); 467 parentEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 468 TouchResult touchResult; 469 touchResult.strategy = TouchTestStrategy::FORWARD_COMPETITION; 470 touchResult.id = "child1"; 471 472 /** 473 * @tc.steps: step3. call GetDispatchFrameNode. 474 * @tc.expected: expect GetDispatchFrameNode run ok. 475 */ 476 auto test = GET_PARENT->GetDispatchFrameNode(touchResult); 477 EXPECT_EQ(test, GET_CHILD1); 478 } 479 480 /** 481 * @tc.name: FrameNodeTestNg_GetDispatchFrameNode003 482 * @tc.desc: Test frame node method GetDispatchFrameNode 483 * @tc.type: FUNC 484 */ 485 HWTEST_F(FrameNodeTestNg, GetDispatchFrameNode003, TestSize.Level1) 486 { 487 /** 488 * @tc.steps: step1. creat node and generate a node tree. 489 */ 490 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 491 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 492 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 493 GET_CHILD1->UpdateInspectorId("child1"); 494 GET_CHILD2->UpdateInspectorId("child2"); 495 GET_PARENT->frameChildren_.insert(GET_CHILD1); 496 GET_PARENT->frameChildren_.insert(GET_CHILD2); 497 498 /** 499 * @tc.steps: step2. initialize parentEventHub, set HitTestMode and TouchTestStrategy. 500 */ 501 auto parentEventHub = GET_PARENT->GetOrCreateGestureEventHub(); 502 parentEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 503 TouchResult touchResult; 504 touchResult.strategy = TouchTestStrategy::DEFAULT; 505 506 /** 507 * @tc.steps: step3. call GetDispatchFrameNode. 508 * @tc.expected: expect GetDispatchFrameNode ruturn nullptr. 509 */ 510 auto test = GET_PARENT->GetDispatchFrameNode(touchResult); 511 EXPECT_EQ(test, nullptr); 512 } 513 514 /** 515 * @tc.name: FrameNodeTestNg_CollectTouchInfos001 516 * @tc.desc: Test frame node method CollectTouchInfos 517 * @tc.type: FUNC 518 */ 519 HWTEST_F(FrameNodeTestNg, CollectTouchInfos001, TestSize.Level1) 520 { 521 /** 522 * @tc.steps: step1. initialize parameters. 523 */ 524 PointF globalPoint; 525 PointF parentRevertPoint; 526 std::vector<TouchTestInfo> touchInfos; 527 528 /** 529 * @tc.steps: step2. creat node and generate a node tree. 530 */ 531 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 532 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 533 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 534 GET_CHILD1->UpdateInspectorId("child1"); 535 GET_CHILD2->UpdateInspectorId("child2"); 536 GET_PARENT->frameChildren_.insert(GET_CHILD1); 537 GET_PARENT->frameChildren_.insert(GET_CHILD2); 538 __anon78b9b8440502(const std::vector<TouchTestInfo>& touchInfo) 539 OnChildTouchTestFunc callback = [](const std::vector<TouchTestInfo>& touchInfo) { 540 TouchResult result; 541 return result; 542 }; 543 544 /** 545 * @tc.steps: step3. initialize gestureHub and set HitTestMode. 546 */ 547 auto gestureHub = GET_PARENT->GetOrCreateGestureEventHub(); 548 gestureHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 549 gestureHub->SetOnTouchTestFunc(std::move(callback)); 550 551 /** 552 * @tc.steps: step4. call CollectTouchInfos. 553 * @tc.expected: expect CollectTouchInfos run ok. 554 */ 555 GET_PARENT->CollectTouchInfos(globalPoint, parentRevertPoint, touchInfos); 556 EXPECT_EQ(touchInfos.size(), 2); 557 } 558 559 /** 560 * @tc.name: FrameNodeTestNg_CollectTouchInfos002 561 * @tc.desc: Test frame node method CollectTouchInfos 562 * @tc.type: FUNC 563 */ 564 HWTEST_F(FrameNodeTestNg, CollectTouchInfos002, TestSize.Level1) 565 { 566 /** 567 * @tc.steps: step1. initialize parameters. 568 */ 569 PointF globalPoint; 570 PointF parentRevertPoint; 571 std::vector<TouchTestInfo> touchInfos; 572 573 /** 574 * @tc.steps: step2. creat node and generate a node tree. 575 */ 576 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 577 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 578 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 579 GET_CHILD1->UpdateInspectorId("child1"); 580 GET_CHILD2->UpdateInspectorId("child2"); 581 GET_PARENT->frameChildren_.insert(GET_CHILD1); 582 GET_PARENT->frameChildren_.insert(GET_CHILD2); 583 584 /** 585 * @tc.steps: step3. initialize gestureHub and set HitTestMode. 586 */ 587 auto gestureHub = GET_PARENT->GetOrCreateGestureEventHub(); 588 gestureHub->SetHitTestMode(HitTestMode::HTMBLOCK); 589 590 /** 591 * @tc.steps: step4. call CollectTouchInfos. 592 * @tc.expected: expect CollectTouchInfos return touchInfos.size is 0. 593 */ 594 GET_PARENT->CollectTouchInfos(globalPoint, parentRevertPoint, touchInfos); 595 EXPECT_EQ(touchInfos.size(), 0); 596 } 597 598 /** 599 * @tc.name: FrameNodeTestNg_CollectTouchInfos003 600 * @tc.desc: Test frame node method CollectTouchInfos 601 * @tc.type: FUNC 602 */ 603 HWTEST_F(FrameNodeTestNg, CollectTouchInfos003, TestSize.Level1) 604 { 605 /** 606 * @tc.steps: step1. initialize parameters. 607 */ 608 PointF globalPoint; 609 PointF parentRevertPoint; 610 std::vector<TouchTestInfo> touchInfos; 611 612 /** 613 * @tc.steps: step2. creat node and generate a node tree. 614 */ 615 const RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>()); 616 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>()); 617 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>()); 618 GET_CHILD1->UpdateInspectorId("child1"); 619 GET_CHILD2->UpdateInspectorId("child2"); 620 GET_PARENT->frameChildren_.insert(GET_CHILD1); 621 GET_PARENT->frameChildren_.insert(GET_CHILD2); 622 623 /** 624 * @tc.steps: step3. initialize gestureHub and set HitTestMode. 625 */ 626 auto gestureHub = GET_PARENT->GetOrCreateGestureEventHub(); 627 gestureHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 628 629 /** 630 * @tc.steps: step4. call CollectTouchInfos. 631 * @tc.expected: expect CollectTouchInfos return touchInfos.size is 0. 632 */ 633 GET_PARENT->CollectTouchInfos(globalPoint, parentRevertPoint, touchInfos); 634 EXPECT_EQ(touchInfos.size(), 0); 635 } 636 637 /** 638 * @tc.name: FrameNodeTestNg_GetPreviewScaleVal001 639 * @tc.desc: Test frame node method GetPreviewScaleVal 640 * @tc.type: FUNC 641 */ 642 HWTEST_F(FrameNodeTestNg, GetPreviewScaleVal001, TestSize.Level1) 643 { 644 auto frameNode = FRAME_NODE; 645 /** 646 * @tc.steps: step1. initialize parameters. 647 */ 648 frameNode->isActive_ = true; 649 frameNode->GetEventHub<EventHub>()->SetEnabled(true); 650 SystemProperties::debugEnabled_ = true; 651 652 /** 653 * @tc.steps: step2. call GetPreviewScaleVal 654 * @tc.expected: expect GetPreviewScaleVal return scale value. 655 */ 656 auto geometryNode = frameNode->GetGeometryNode(); 657 geometryNode->SetFrameSize(CONTAINER_SIZE_ZERO); 658 EXPECT_FLOAT_EQ(frameNode->GetPreviewScaleVal(), 1.0f); 659 660 double screenWidth = 1216.0; 661 ScreenSystemManager::GetInstance().SetWindowInfo(screenWidth, 1.0, 1.0); 662 geometryNode->SetFrameSize(CONTAINER_SIZE_SMALL); 663 EXPECT_FLOAT_EQ(frameNode->GetPreviewScaleVal(), 1.0f); 664 665 /** 666 * @tc.steps: step3. set a large size and call GetPreviewScaleVal. 667 * @tc.expected: expect GetPreviewScaleVal return scale value. 668 */ 669 geometryNode->SetFrameSize(CONTAINER_SIZE_HUGE); 670 EXPECT_LT(frameNode->GetPreviewScaleVal(), 1.0f); 671 } 672 673 /** 674 * @tc.name: FrameNodeTestNg_GetPreviewScaleVal002 675 * @tc.desc: Test frame node method GetPreviewScaleVal 676 * @tc.type: FUNC 677 */ 678 HWTEST_F(FrameNodeTestNg, GetPreviewScaleVal002, TestSize.Level1) 679 { 680 auto frameNode = FRAME_NODE; 681 /** 682 * @tc.steps: step1. initialize parameters. 683 */ 684 frameNode->isActive_ = true; 685 frameNode->GetEventHub<EventHub>()->SetEnabled(true); 686 SystemProperties::debugEnabled_ = true; 687 688 /** 689 * @tc.steps: step2. set frame size to huge and drag preview options to disable scale then call GetPreviewScaleVal 690 * @tc.expected: expect GetPreviewScaleVal return scale value. 691 */ 692 auto geometryNode = frameNode->GetGeometryNode(); 693 geometryNode->SetFrameSize(CONTAINER_SIZE_HUGE); 694 NG::DragPreviewOption option { false }; 695 frameNode->SetDragPreviewOptions(option); 696 EXPECT_FLOAT_EQ(frameNode->GetPreviewScaleVal(), 1.0f); 697 698 /** 699 * @tc.steps: step3. set set drag preview options to auto and call GetPreviewScaleVal. 700 * @tc.expected: expect GetPreviewScaleVal return scale value. 701 */ 702 option = { true }; 703 frameNode->SetDragPreviewOptions(option); 704 EXPECT_LT(frameNode->GetPreviewScaleVal(), 1.0f); 705 } 706 707 /** 708 * @tc.name: FrameNodeTestNg_GetPreviewApplyVal001 709 * @tc.desc: Test frame node method GetPreviewApplyVal001 710 * @tc.type: FUNC 711 */ 712 HWTEST_F(FrameNodeTestNg, GetPreviewApplyVal001, TestSize.Level1) 713 { 714 auto frameNode = FRAME_NODE; 715 /** 716 * @tc.steps: step1. initialize parameters. 717 */ 718 frameNode->isActive_ = true; 719 frameNode->GetEventHub<EventHub>()->SetEnabled(true); 720 SystemProperties::debugEnabled_ = true; 721 722 /** 723 * @tc.steps: step2. set drag preview options and call GetDragPreviewOption. 724 * @tc.expected: expect GetDragPreviewOption return apply . 725 */ 726 auto geometryNode = frameNode->GetGeometryNode(); 727 geometryNode->SetFrameSize(CONTAINER_SIZE_HUGE); 728 NG::DragPreviewOption previewOption; __anon78b9b8440602(WeakPtr<NG::FrameNode> frameNode) 729 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) {}; 730 frameNode->SetDragPreviewOptions(previewOption); 731 EXPECT_NE(frameNode->GetDragPreviewOption().onApply, nullptr); 732 } 733 734 /** 735 * @tc.name: FrameNodeTestNg_GetPreviewScaleVal003 736 * @tc.desc: Test frame node method GetPreviewScaleVal 737 * @tc.type: FUNC 738 */ 739 HWTEST_F(FrameNodeTestNg, GetPreviewScaleVal003, TestSize.Level1) 740 { 741 auto frameNode = FRAME_NODE_WEB_ETS_TAG; 742 /** 743 * @tc.steps: step1. initialize parameters. 744 */ 745 frameNode->isActive_ = true; 746 frameNode->GetEventHub<EventHub>()->SetEnabled(true); 747 SystemProperties::debugEnabled_ = true; 748 749 /** 750 * @tc.steps: step2. call GetPreviewScaleVal 751 * @tc.expected: expect GetPreviewScaleVal return scale value. 752 */ 753 auto geometryNode = frameNode->GetGeometryNode(); 754 geometryNode->SetFrameSize(CONTAINER_SIZE_HUGE); 755 756 EXPECT_FLOAT_EQ(frameNode->GetPreviewScaleVal(), 1.0f); 757 } 758 759 /** 760 * @tc.name: FrameNodeTestNg_IsPreviewNeedScale001 761 * @tc.desc: Test frame node method IsPreviewNeedScale 762 * @tc.type: FUNC 763 */ 764 HWTEST_F(FrameNodeTestNg, IsPreviewNeedScale001, TestSize.Level1) 765 { 766 auto frameNode = FRAME_NODE; 767 /** 768 * @tc.steps: step1. initialize parameters. 769 */ 770 FRAME_NODE->isActive_ = true; 771 FRAME_NODE->GetEventHub<EventHub>()->SetEnabled(true); 772 SystemProperties::debugEnabled_ = true; 773 774 /** 775 * @tc.steps: step2. call IsPreviewNeedScale 776 * @tc.expected: expect IsPreviewNeedScale return false. 777 */ 778 auto geometryNode = frameNode->GetGeometryNode(); 779 geometryNode->SetFrameSize(CONTAINER_SIZE_SMALL); 780 EXPECT_FALSE(FRAME_NODE->IsPreviewNeedScale()); 781 782 /** 783 * @tc.steps: step2. set a large size and call IsPreviewNeedScale. 784 * @tc.expected: expect IsPreviewNeedScale return true. 785 */ 786 geometryNode->SetFrameSize(CONTAINER_SIZE_HUGE); 787 EXPECT_TRUE(FRAME_NODE->IsPreviewNeedScale()); 788 } 789 790 /** 791 * @tc.name: FrameNodeTestNg_GetOffsetInScreen001 792 * @tc.desc: Test frame node method GetOffsetInScreen 793 * @tc.type: FUNC 794 */ 795 HWTEST_F(FrameNodeTestNg, GetOffsetInScreen001, TestSize.Level1) 796 { 797 /** 798 * @tc.steps: step1. initialize parameters. 799 */ 800 FRAME_NODE->isActive_ = true; 801 FRAME_NODE->GetEventHub<EventHub>()->SetEnabled(true); 802 SystemProperties::debugEnabled_ = true; 803 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 804 ASSERT_NE(mockRenderContext, nullptr); 805 mockRenderContext->rect_ = RectF(DEFAULT_X, DEFAULT_Y, DEFAULT_X, DEFAULT_Y); 806 FRAME_NODE->renderContext_ = mockRenderContext; 807 808 /** 809 * @tc.steps: step2. call GetOffsetInScreen. 810 * @tc.expected: expect GetOffsetInScreen return the result which is not (0, 0). 811 */ 812 EXPECT_EQ(FRAME_NODE->GetOffsetInScreen(), OffsetF(0.0f, 0.0f)); 813 } 814 815 /** 816 * @tc.name: FrameNodeTestNg_GetPixelMap001 817 * @tc.desc: Test frame node method GetPixelMap 818 * @tc.type: FUNC 819 */ 820 HWTEST_F(FrameNodeTestNg, GetPixelMap001, TestSize.Level1) 821 { 822 /** 823 * @tc.steps: step1. initialize parameters. 824 */ 825 FRAME_NODE->isActive_ = true; 826 FRAME_NODE->GetEventHub<EventHub>()->SetEnabled(true); 827 SystemProperties::debugEnabled_ = true; 828 auto gestureHub = FRAME_NODE->GetOrCreateGestureEventHub(); 829 ASSERT_NE(gestureHub, nullptr); 830 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 831 ASSERT_NE(mockRenderContext, nullptr); 832 FRAME_NODE->renderContext_ = mockRenderContext; 833 834 /** 835 * @tc.steps: step2. Don't initialize pixelMap and rosenNode. 836 * @tc.expected: expect GetPixelMap() == nullptr. 837 */ 838 EXPECT_EQ(FRAME_NODE->GetDragPixelMap(), nullptr); 839 840 /** 841 * @tc.steps: step3. set a pixelMap of gestureHub, and call GetPixelMap. 842 * @tc.expected: expect GetPixelMap() != nullptr. 843 */ 844 void* voidPtr = static_cast<void*>(new char[0]); 845 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr); 846 ASSERT_NE(pixelMap, nullptr); 847 gestureHub->SetPixelMap(pixelMap); 848 EXPECT_NE(FRAME_NODE->GetDragPixelMap(), nullptr); 849 850 /** 851 * @tc.steps: step4. set a pixelMap of the renderContext, and call GetPixelMap. 852 * @tc.expected: expect GetPixelMap() != nullptr. 853 */ 854 gestureHub->SetPixelMap(nullptr); 855 EXPECT_EQ(FRAME_NODE->GetDragPixelMap(), nullptr); 856 } 857 858 /** 859 * @tc.name: FindChildByNameTest001 860 * @tc.desc: Test FindChildByName with one tree 861 * @tc.type: FUNC 862 */ 863 HWTEST_F(FrameNodeTestNg, FindChildByNameTest001, TestSize.Level1) 864 { 865 /** 866 * @tc.steps: step1. Create frameNode and set the parent and children. 867 */ 868 const std::string parentNodeName = "nodeParent"; 869 const std::string thisNodeName = "nodeThis"; 870 const std::string childrenNodeName = "nodeChildren"; 871 const std::string testChildNodeName = "test"; 872 auto nodeParent = FrameNode::CreateFrameNode(parentNodeName, 10, AceType::MakeRefPtr<Pattern>(), true); 873 auto nodeThis = FrameNode::CreateFrameNode(thisNodeName, 20, AceType::MakeRefPtr<Pattern>()); 874 auto nodeChildren = FrameNode::CreateFrameNode(childrenNodeName, 30, AceType::MakeRefPtr<Pattern>()); 875 876 /** 877 * @tc.steps: step1. Set the node's relation. 878 */ 879 nodeParent->AddChild(nodeThis); 880 nodeParent->AddChild(nodeChildren); 881 882 /** 883 * @tc.steps: step3. Init inspectorId. 884 */ 885 nodeParent->UpdateInspectorId(parentNodeName); 886 nodeChildren->UpdateInspectorId(childrenNodeName); 887 nodeThis->UpdateInspectorId(thisNodeName); 888 889 /** 890 * @tc.steps: step4. Traversal the frameNodeTree. 891 */ 892 auto finalResult = FrameNode::FindChildByName(nodeParent, childrenNodeName); 893 EXPECT_EQ(finalResult, nodeChildren); 894 895 auto noChildResult = FrameNode::FindChildByName(nodeParent, testChildNodeName); 896 EXPECT_EQ(noChildResult, nullptr); 897 898 nodeParent->Clean(); 899 auto noHaveResult = FrameNode::FindChildByName(nodeParent, childrenNodeName); 900 EXPECT_EQ(noHaveResult, nullptr); 901 } 902 903 /** 904 * @tc.name: FindChildByNameTest002 905 * @tc.desc: Test FindChildByName with two tree 906 * @tc.type: FUNC 907 */ 908 HWTEST_F(FrameNodeTestNg, FindChildByNameTest002, TestSize.Level1) 909 { 910 /** 911 * @tc.steps: step1. Create frameNode and set the parent and children. 912 */ 913 const std::string parentNodeName = "nodeParent"; 914 const std::string nodeOneName = "nodeOne"; 915 const std::string nodeOneChildName = "nodeOneChildren"; 916 const std::string nodeTwoName = "nodeTwo"; 917 const std::string nodeTwoChildName = "nodeTwoChildren"; 918 const std::string testChildNodeName = "test"; 919 auto nodeParent = FrameNode::CreateFrameNode(parentNodeName, 10, AceType::MakeRefPtr<Pattern>(), true); 920 auto nodeOne = FrameNode::CreateFrameNode(nodeOneName, 20, AceType::MakeRefPtr<Pattern>()); 921 auto nodeOneChildren = FrameNode::CreateFrameNode(nodeOneChildName, 30, AceType::MakeRefPtr<Pattern>()); 922 auto nodeTwo = FrameNode::CreateFrameNode(nodeTwoName, 40, AceType::MakeRefPtr<Pattern>()); 923 auto nodeTwoChildren = FrameNode::CreateFrameNode(nodeTwoChildName, 50, AceType::MakeRefPtr<Pattern>()); 924 925 /** 926 * @tc.steps: step1. Set the node's relation. 927 */ 928 nodeParent->AddChild(nodeOne); 929 nodeParent->AddChild(nodeTwo); 930 nodeOne->AddChild(nodeOneChildren); 931 nodeTwo->AddChild(nodeTwoChildren); 932 933 /** 934 * @tc.steps: step3. Init inspectorId. 935 */ 936 nodeParent->UpdateInspectorId(parentNodeName); 937 nodeOne->UpdateInspectorId(nodeOneName); 938 nodeOneChildren->UpdateInspectorId(nodeOneChildName); 939 nodeTwo->UpdateInspectorId(nodeTwoName); 940 nodeTwoChildren->UpdateInspectorId(nodeTwoChildName); 941 942 /** 943 * @tc.steps: step4. Traversal the frameNodeTree. 944 */ 945 auto finalResult = FrameNode::FindChildByName(nodeParent, nodeOneChildName); 946 EXPECT_EQ(finalResult, nodeOneChildren); 947 948 auto noChildResult = FrameNode::FindChildByName(nodeParent, testChildNodeName); 949 EXPECT_EQ(noChildResult, nullptr); 950 951 nodeParent->Clean(); 952 auto noHaveResult = FrameNode::FindChildByName(nodeParent, nodeTwoChildName); 953 EXPECT_EQ(noHaveResult, nullptr); 954 } 955 956 /** 957 * @tc.name: SetOnSizeChangeCallback001 958 * @tc.desc: Test SetOnSizeChangeCallback 959 * @tc.type: FUNC 960 */ 961 HWTEST_F(FrameNodeTestNg, SetOnSizeChangeCallback001, TestSize.Level1) 962 { 963 /** 964 * @tc.steps: step1. build a object to SetOnSizeChangeCallback 965 * @tc.expected: expect cover branch lastFrameNodeRect_ non null and function is run ok. 966 */ __anon78b9b8440702(const RectF& oldRect, const RectF& rect) 967 OnSizeChangedFunc callback = [](const RectF& oldRect, const RectF& rect) {}; 968 FRAME_NODE2->SetOnSizeChangeCallback(std::move(callback)); 969 EXPECT_NE(FRAME_NODE2->lastFrameNodeRect_, nullptr); 970 auto eventHub = FRAME_NODE2->GetEventHub<NG::EventHub>(); 971 EXPECT_NE(eventHub, nullptr); 972 EXPECT_TRUE(eventHub->HasOnSizeChanged()); 973 974 /** 975 * @tc.steps: step2.test while callback is nullptr 976 * @tc.expected:expect cover branch lastFrameNodeRect_ non null and function is run ok. 977 */ 978 FRAME_NODE2->lastFrameNodeRect_ = std::make_unique<RectF>(); 979 FRAME_NODE2->SetOnSizeChangeCallback(nullptr); 980 EXPECT_NE(FRAME_NODE2->lastFrameNodeRect_, nullptr); 981 EXPECT_NE(eventHub, nullptr); 982 EXPECT_FALSE(eventHub->HasOnSizeChanged()); 983 } 984 985 /** 986 * @tc.name: TriggerOnSizeChangeCallback001 987 * @tc.desc: Test frame node method 988 * @tc.type: FUNC 989 */ 990 HWTEST_F(FrameNodeTestNg, TriggerOnSizeChangeCallback001, TestSize.Level1) 991 { 992 /** 993 * @tc.steps: step1. set a flag and init a callback(onSizeChanged) 994 */ 995 bool flag = false; __anon78b9b8440802(const RectF& oldRect, const RectF& rect) 996 OnSizeChangedFunc onSizeChanged = [&flag](const RectF& oldRect, const RectF& rect) { flag = !flag; }; 997 998 /** 999 * @tc.steps: step2. call TriggerOnSizeChangeCallback before set callback 1000 * @tc.expected: expect flag is still false 1001 */ 1002 FRAME_NODE2->TriggerOnSizeChangeCallback(); 1003 EXPECT_FALSE(flag); 1004 1005 /** 1006 * @tc.steps: step3.set callback and release lastFrameNodeRect_ 1007 * @tc.expected: expect flag is still false 1008 */ 1009 FRAME_NODE2->GetEventHub<EventHub>()->SetOnSizeChanged(std::move(onSizeChanged)); 1010 FRAME_NODE2->lastFrameNodeRect_ = nullptr; 1011 FRAME_NODE2->TriggerOnSizeChangeCallback(); 1012 EXPECT_FALSE(flag); 1013 1014 /** 1015 * @tc.steps: step4.set lastFrameNodeRect_ 1016 * @tc.expected: expect flag is still false 1017 */ 1018 FRAME_NODE2->lastFrameNodeRect_ = std::make_unique<RectF>(); 1019 FRAME_NODE2->TriggerOnSizeChangeCallback(); 1020 EXPECT_FALSE(flag); 1021 } 1022 1023 /** 1024 * @tc.name: OnTouchInterceptTest001 1025 * @tc.desc: Test onTouchIntercept method 1026 * @tc.type: FUNC 1027 */ 1028 HWTEST_F(FrameNodeTestNg, OnTouchInterceptTest001, TestSize.Level1) 1029 { 1030 /** 1031 * @tc.steps: step1. construct TouchTest parameters. 1032 */ 1033 PointF globalPoint; 1034 PointF parentLocalPoint; 1035 TouchRestrict touchRestrict; 1036 TouchTestResult result; 1037 ResponseLinkResult responseLinkResult; 1038 1039 /** 1040 * @tc.steps: step2. create node and set callback. 1041 */ 1042 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1043 childNode->SetExclusiveEventForChild(true); 1044 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1045 childNode->renderContext_ = mockRenderContextforChild; 1046 auto localPoint = PointF(10, 10); 1047 mockRenderContextforChild->rect_ = RectF(0, 0, 100, 100); 1048 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1049 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1050 auto childEventHub = childNode->GetOrCreateGestureEventHub(); 1051 childEventHub->SetHitTestMode(HitTestMode::HTMBLOCK); 1052 childNode->SetActive(true); 1053 EXPECT_NE(childNode->GetEventHub<EventHub>()->GetGestureEventHub(), nullptr); __anon78b9b8440902(TouchEventInfo& event) 1054 auto callback = [](TouchEventInfo& event) -> HitTestMode { return HitTestMode::HTMNONE; }; 1055 childEventHub->SetOnTouchIntercept(callback); 1056 1057 /** 1058 * @tc.steps: step3. trigger touch test. 1059 * @tc.expected: expect the touch test mode is correct. 1060 */ 1061 HitTestMode hitTestModeofChilds[] = { HitTestMode::HTMDEFAULT, HitTestMode::HTMBLOCK, HitTestMode::HTMTRANSPARENT, 1062 HitTestMode::HTMNONE, HitTestMode::HTMTRANSPARENT_SELF }; 1063 int32_t i = 0; 1064 for (auto hitTestModeofChild : hitTestModeofChilds) { 1065 childEventHub->SetHitTestMode(hitTestModeofChild); 1066 childNode->TouchTest( 1067 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 1068 auto mode = childEventHub->GetHitTestMode(); 1069 EXPECT_EQ(mode, hitTestModeofChilds[i++]); 1070 } 1071 1072 /** 1073 * @tc.steps: step4. modify callback and trigger touch test. 1074 * @tc.expected: expect the touch test mode is correct. 1075 */ 1076 i = 0; __anon78b9b8440a02(TouchEventInfo& event) 1077 auto blockCallback = [](TouchEventInfo& event) -> HitTestMode { return HitTestMode::HTMBLOCK; }; 1078 childEventHub->SetOnTouchIntercept(blockCallback); 1079 for (auto hitTestModeofChild : hitTestModeofChilds) { 1080 childEventHub->SetHitTestMode(hitTestModeofChild); 1081 childNode->TouchTest( 1082 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult); 1083 auto mode = childEventHub->GetHitTestMode(); 1084 EXPECT_EQ(mode, hitTestModeofChilds[i++]); 1085 } 1086 } 1087 1088 /** 1089 * @tc.name: FrameNodeTestNg0040 1090 * @tc.desc: Test frame node method 1091 * @tc.type: FUNC 1092 */ 1093 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg0040, TestSize.Level1) 1094 { 1095 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1096 std::set<std::string> allowDropSet; 1097 frameNode->SetAllowDrop(allowDropSet); 1098 std::set<std::string> allowDrop = frameNode->GetAllowDrop(); 1099 EXPECT_TRUE(allowDrop.empty()); 1100 } 1101 1102 /** 1103 * @tc.name: FrameNodeTestNg0050 1104 * @tc.desc: Test frame node method 1105 * @tc.type: FUNC 1106 */ 1107 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg0050, TestSize.Level1) 1108 { 1109 auto context = PipelineContext::GetCurrentContext(); 1110 ASSERT_NE(context, nullptr); 1111 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1112 ASSERT_NE(node, nullptr); 1113 node->GetOrCreateGestureEventHub(); 1114 node->AttachContext(AceType::RawPtr(context)); 1115 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1116 node->renderContext_ = mockRenderContext; 1117 EXPECT_EQ(node->context_, AceType::RawPtr(context)); 1118 1119 node->DetachContext(true); 1120 EXPECT_EQ(node->context_, nullptr); 1121 } 1122 1123 /** 1124 * @tc.name: FrameNodeTestNg_GetPositionToScreen001 1125 * @tc.desc: Test frame node method GetPositionToScreen 1126 * @tc.type: FUNC 1127 */ 1128 HWTEST_F(FrameNodeTestNg, GetPositionToScreen001, TestSize.Level1) 1129 { 1130 OffsetF Offset = { 0, 0 }; 1131 FRAME_NODE2->SetParent(FRAME_NODE3); 1132 auto screenOffset = FRAME_NODE2->GetPositionToScreen(); 1133 EXPECT_EQ(screenOffset, Offset); 1134 } 1135 1136 /** 1137 * @tc.name: FrameNodeTestNg_GetPositionToParentWithTransform001 1138 * @tc.desc: Test frame node method GetPositionToParentWithTransform 1139 * @tc.type: FUNC 1140 */ 1141 HWTEST_F(FrameNodeTestNg, GetPositionToParentWithTransform001, TestSize.Level1) 1142 { 1143 OffsetF Offset = { 0, 0 }; 1144 FRAME_NODE2->SetParent(FRAME_NODE3); 1145 auto parentOffsetWithTransform = FRAME_NODE2->GetPositionToParentWithTransform(); 1146 EXPECT_EQ(parentOffsetWithTransform, Offset); 1147 } 1148 1149 /** 1150 * @tc.name: FrameNodeTestNg_GetPositionToParentWithTransform001 1151 * @tc.desc: Test frame node method GetPositionToParentWithTransform 1152 * @tc.type: FUNC 1153 */ 1154 HWTEST_F(FrameNodeTestNg, GetPositionToScreenWithTransform001, TestSize.Level1) 1155 { 1156 OffsetF Offset = { 0, 0 }; 1157 FRAME_NODE2->SetParent(FRAME_NODE3); 1158 auto screenOffsetWithTransform = FRAME_NODE2->GetPositionToScreenWithTransform(); 1159 EXPECT_EQ(screenOffsetWithTransform, Offset); 1160 } 1161 1162 /** 1163 * @tc.name: FrameNodeTestNg_GetPositionToWindowWithTransform001 1164 * @tc.desc: Test frame node method GetPositionToWindowWithTransform 1165 * @tc.type: FUNC 1166 */ 1167 HWTEST_F(FrameNodeTestNg, GetPositionToWindowWithTransform001, TestSize.Level1) 1168 { 1169 OffsetF Offset = { 0, 0 }; 1170 FRAME_NODE2->SetParent(FRAME_NODE3); 1171 auto windowOffsetWithTransform = FRAME_NODE2->GetPositionToWindowWithTransform(); 1172 EXPECT_EQ(windowOffsetWithTransform, Offset); 1173 } 1174 1175 /** 1176 * @tc.name: GetPreviewOptionFromModifier001 1177 * @tc.desc: Test UpdatePreviewOptionFromModifier 1178 * @tc.type: FUNC 1179 * @tc.author: 1180 */ 1181 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier001, TestSize.Level1) 1182 { 1183 /** 1184 * @tc.steps: step1. Create FrameNode. 1185 */ 1186 auto frameNode = FrameNode::CreateFrameNode( 1187 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1188 EXPECT_NE(frameNode, nullptr); 1189 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1190 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1191 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1192 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1193 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1194 /** 1195 * @tc.steps: step2. get DragPreviewOption. 1196 */ 1197 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1198 /** 1199 * @tc.steps: step3. set opacity. 1200 */ 1201 dragPreviewOption.options.opacity = -50.0f; 1202 frameNode->SetDragPreviewOptions(dragPreviewOption); 1203 /** 1204 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1205 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1206 */ 1207 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1208 dragPreviewOption = frameNode->GetDragPreviewOption(); 1209 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1210 } 1211 1212 /** 1213 * @tc.name: GetPreviewOptionFromModifier002 1214 * @tc.desc: Test UpdatePreviewOptionFromModifier 1215 * @tc.type: FUNC 1216 * @tc.author: 1217 */ 1218 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier002, TestSize.Level1) 1219 { 1220 /** 1221 * @tc.steps: step1. Create FrameNode. 1222 */ 1223 auto frameNode = FrameNode::CreateFrameNode( 1224 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1225 EXPECT_NE(frameNode, nullptr); 1226 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1227 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1228 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1229 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1230 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1231 /** 1232 * @tc.steps: step2. get DragPreviewOption. 1233 */ 1234 NG::DragPreviewOption previewOption; __anon78b9b8440b02(WeakPtr<NG::FrameNode> frameNode) 1235 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1236 auto node = frameNode.Upgrade(); 1237 CHECK_NULL_VOID(node); 1238 if ((PARA_OPACITY_VALUE_1 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_1 > MIN_OPACITY)) { 1239 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_1); 1240 } else { 1241 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1242 } 1243 }; 1244 /** 1245 * @tc.steps: step3. set opacity. 1246 */ 1247 frameNode->SetDragPreviewOptions(previewOption); 1248 /** 1249 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1250 * @tc.expected: opacity in DragPreviewOption is equal to 0.1f. 1251 */ 1252 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1253 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.1f); 1254 } 1255 1256 /** 1257 * @tc.name: GetPreviewOptionFromModifier003 1258 * @tc.desc: Test UpdatePreviewOptionFromModifier 1259 * @tc.type: FUNC 1260 * @tc.author: 1261 */ 1262 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier003, TestSize.Level1) 1263 { 1264 /** 1265 * @tc.steps: step1. Create FrameNode. 1266 */ 1267 auto frameNode = FrameNode::CreateFrameNode( 1268 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1269 EXPECT_NE(frameNode, nullptr); 1270 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1271 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1272 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1273 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1274 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1275 /** 1276 * @tc.steps: step2. get DragPreviewOption. 1277 */ 1278 NG::DragPreviewOption previewOption; __anon78b9b8440c02(WeakPtr<NG::FrameNode> frameNode) 1279 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1280 auto node = frameNode.Upgrade(); 1281 CHECK_NULL_VOID(node); 1282 if ((PARA_OPACITY_VALUE_2 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_2 > MIN_OPACITY)) { 1283 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_2); 1284 } else { 1285 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1286 } 1287 }; 1288 /** 1289 * @tc.steps: step3. set opacity. 1290 */ 1291 frameNode->SetDragPreviewOptions(previewOption); 1292 /** 1293 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1294 * @tc.expected: opacity in DragPreviewOption is equal to 0.2f. 1295 */ 1296 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1297 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.2f); 1298 } 1299 1300 /** 1301 * @tc.name: GetPreviewOptionFromModifier004 1302 * @tc.desc: Test UpdatePreviewOptionFromModifier 1303 * @tc.type: FUNC 1304 * @tc.author: 1305 */ 1306 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier004, TestSize.Level1) 1307 { 1308 /** 1309 * @tc.steps: step1. Create FrameNode. 1310 */ 1311 auto frameNode = FrameNode::CreateFrameNode( 1312 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1313 EXPECT_NE(frameNode, nullptr); 1314 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1315 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1316 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1317 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1318 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1319 /** 1320 * @tc.steps: step2. get DragPreviewOption. 1321 */ 1322 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1323 /** 1324 * @tc.steps: step3. set opacity. 1325 */ 1326 dragPreviewOption.options.opacity = 0.0f; 1327 frameNode->SetDragPreviewOptions(dragPreviewOption); 1328 /** 1329 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1330 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1331 */ 1332 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1333 dragPreviewOption = frameNode->GetDragPreviewOption(); 1334 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1335 } 1336 1337 /** 1338 * @tc.name: GetPreviewOptionFromModifier005 1339 * @tc.desc: Test UpdatePreviewOptionFromModifier 1340 * @tc.type: FUNC 1341 * @tc.author: 1342 */ 1343 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier005, TestSize.Level1) 1344 { 1345 /** 1346 * @tc.steps: step1. Create FrameNode. 1347 */ 1348 auto frameNode = FrameNode::CreateFrameNode( 1349 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1350 EXPECT_NE(frameNode, nullptr); 1351 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1352 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1353 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1354 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1355 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1356 /** 1357 * @tc.steps: step2. get DragPreviewOption. 1358 */ 1359 NG::DragPreviewOption previewOption; __anon78b9b8440d02(WeakPtr<NG::FrameNode> frameNode) 1360 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1361 auto node = frameNode.Upgrade(); 1362 CHECK_NULL_VOID(node); 1363 if ((PARA_OPACITY_VALUE_3 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_3 > MIN_OPACITY)) { 1364 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_3); 1365 } else { 1366 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1367 } 1368 }; 1369 /** 1370 * @tc.steps: step3. set opacity. 1371 */ 1372 frameNode->SetDragPreviewOptions(previewOption); 1373 /** 1374 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1375 * @tc.expected: opacity in DragPreviewOption is equal to 0.3f. 1376 */ 1377 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1378 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.3f); 1379 } 1380 1381 /** 1382 * @tc.name: GetPreviewOptionFromModifier006 1383 * @tc.desc: Test UpdatePreviewOptionFromModifier 1384 * @tc.type: FUNC 1385 * @tc.author: 1386 */ 1387 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier006, TestSize.Level1) 1388 { 1389 /** 1390 * @tc.steps: step1. Create FrameNode. 1391 */ 1392 auto frameNode = FrameNode::CreateFrameNode( 1393 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1394 EXPECT_NE(frameNode, nullptr); 1395 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1396 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1397 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1398 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1399 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1400 /** 1401 * @tc.steps: step2. get DragPreviewOption. 1402 */ 1403 NG::DragPreviewOption previewOption; __anon78b9b8440e02(WeakPtr<NG::FrameNode> frameNode) 1404 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1405 auto node = frameNode.Upgrade(); 1406 CHECK_NULL_VOID(node); 1407 if ((PARA_OPACITY_VALUE_4 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_4 > MIN_OPACITY)) { 1408 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_4); 1409 } else { 1410 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1411 } 1412 }; 1413 /** 1414 * @tc.steps: step3. set opacity. 1415 */ 1416 frameNode->SetDragPreviewOptions(previewOption); 1417 /** 1418 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1419 * @tc.expected: opacity in DragPreviewOption is equal to 0.4f. 1420 */ 1421 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1422 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.4f); 1423 } 1424 1425 /** 1426 * @tc.name: GetPreviewOptionFromModifier007 1427 * @tc.desc: Test UpdatePreviewOptionFromModifier 1428 * @tc.type: FUNC 1429 * @tc.author: 1430 */ 1431 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier007, TestSize.Level1) 1432 { 1433 /** 1434 * @tc.steps: step1. Create FrameNode. 1435 */ 1436 auto frameNode = FrameNode::CreateFrameNode( 1437 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1438 EXPECT_NE(frameNode, nullptr); 1439 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1440 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1441 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1442 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1443 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1444 /** 1445 * @tc.steps: step2. get DragPreviewOption. 1446 */ 1447 NG::DragPreviewOption previewOption; __anon78b9b8440f02(WeakPtr<NG::FrameNode> frameNode) 1448 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1449 auto node = frameNode.Upgrade(); 1450 CHECK_NULL_VOID(node); 1451 if ((PARA_OPACITY_VALUE_5 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_5 > MIN_OPACITY)) { 1452 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_5); 1453 } else { 1454 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1455 } 1456 }; 1457 /** 1458 * @tc.steps: step3. set opacity. 1459 */ 1460 frameNode->SetDragPreviewOptions(previewOption); 1461 /** 1462 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1463 * @tc.expected: opacity in DragPreviewOption is equal to 0.5f. 1464 */ 1465 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1466 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.5f); 1467 } 1468 1469 /** 1470 * @tc.name: GetPreviewOptionFromModifier008 1471 * @tc.desc: Test UpdatePreviewOptionFromModifier 1472 * @tc.type: FUNC 1473 * @tc.author: 1474 */ 1475 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier008, TestSize.Level1) 1476 { 1477 /** 1478 * @tc.steps: step1. Create FrameNode. 1479 */ 1480 auto frameNode = FrameNode::CreateFrameNode( 1481 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1482 EXPECT_NE(frameNode, nullptr); 1483 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1484 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1485 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1486 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1487 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1488 /** 1489 * @tc.steps: step2. get DragPreviewOption. 1490 */ 1491 NG::DragPreviewOption previewOption; __anon78b9b8441002(WeakPtr<NG::FrameNode> frameNode) 1492 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1493 auto node = frameNode.Upgrade(); 1494 CHECK_NULL_VOID(node); 1495 if ((PARA_OPACITY_VALUE_6 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_6 > MIN_OPACITY)) { 1496 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_6); 1497 } else { 1498 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1499 } 1500 }; 1501 /** 1502 * @tc.steps: step3. set opacity. 1503 */ 1504 frameNode->SetDragPreviewOptions(previewOption); 1505 /** 1506 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1507 * @tc.expected: opacity in DragPreviewOption is equal to 0.6f. 1508 */ 1509 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1510 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.6f); 1511 } 1512 1513 /** 1514 * @tc.name: GetPreviewOptionFromModifier009 1515 * @tc.desc: Test UpdatePreviewOptionFromModifier 1516 * @tc.type: FUNC 1517 * @tc.author: 1518 */ 1519 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier009, TestSize.Level1) 1520 { 1521 /** 1522 * @tc.steps: step1. Create FrameNode. 1523 */ 1524 auto frameNode = FrameNode::CreateFrameNode( 1525 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1526 EXPECT_NE(frameNode, nullptr); 1527 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1528 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1529 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1530 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1531 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1532 /** 1533 * @tc.steps: step2. get DragPreviewOption. 1534 */ 1535 NG::DragPreviewOption previewOption; __anon78b9b8441102(WeakPtr<NG::FrameNode> frameNode) 1536 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1537 auto node = frameNode.Upgrade(); 1538 CHECK_NULL_VOID(node); 1539 if ((PARA_OPACITY_VALUE_7 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_7 > MIN_OPACITY)) { 1540 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_7); 1541 } else { 1542 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1543 } 1544 }; 1545 /** 1546 * @tc.steps: step3. set opacity. 1547 */ 1548 frameNode->SetDragPreviewOptions(previewOption); 1549 /** 1550 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1551 * @tc.expected: opacity in DragPreviewOption is equal to 0.7f. 1552 */ 1553 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1554 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 0.7f); 1555 } 1556 1557 /** 1558 * @tc.name: GetPreviewOptionFromModifier010 1559 * @tc.desc: Test UpdatePreviewOptionFromModifier 1560 * @tc.type: FUNC 1561 * @tc.author: 1562 */ 1563 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier010, TestSize.Level1) 1564 { 1565 /** 1566 * @tc.steps: step1. Create FrameNode. 1567 */ 1568 auto frameNode = FrameNode::CreateFrameNode( 1569 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1570 EXPECT_NE(frameNode, nullptr); 1571 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1572 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1573 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1574 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1575 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1576 /** 1577 * @tc.steps: step2. get DragPreviewOption. 1578 */ 1579 NG::DragPreviewOption previewOption; __anon78b9b8441202(WeakPtr<NG::FrameNode> frameNode) 1580 previewOption.onApply = [](WeakPtr<NG::FrameNode> frameNode) { 1581 auto node = frameNode.Upgrade(); 1582 CHECK_NULL_VOID(node); 1583 if ((PARA_OPACITY_VALUE_8 <= MAX_OPACITY) && (PARA_OPACITY_VALUE_8 > MIN_OPACITY)) { 1584 node->GetRenderContext()->UpdateOpacity(PARA_OPACITY_VALUE_8); 1585 } else { 1586 node->GetRenderContext()->UpdateOpacity(DEFAULT_OPACITY); 1587 } 1588 }; 1589 /** 1590 * @tc.steps: step3. set opacity. 1591 */ 1592 frameNode->SetDragPreviewOptions(previewOption); 1593 /** 1594 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1595 * @tc.expected: opacity in DragPreviewOption is equal to 1.0f. 1596 */ 1597 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1598 EXPECT_EQ(frameNode->GetDragPreviewOption().options.opacity, 1.0f); 1599 } 1600 1601 /** 1602 * @tc.name: GetPreviewOptionFromModifier011 1603 * @tc.desc: Test UpdatePreviewOptionFromModifier 1604 * @tc.type: FUNC 1605 * @tc.author: 1606 */ 1607 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier011, TestSize.Level1) 1608 { 1609 /** 1610 * @tc.steps: step1. Create FrameNode. 1611 */ 1612 auto frameNode = FrameNode::CreateFrameNode( 1613 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1614 EXPECT_NE(frameNode, nullptr); 1615 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1616 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1617 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1618 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1619 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1620 /** 1621 * @tc.steps: step2. get DragPreviewOption. 1622 */ 1623 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1624 /** 1625 * @tc.steps: step3. set opacity. 1626 */ 1627 dragPreviewOption.options.opacity = 2.0f; 1628 frameNode->SetDragPreviewOptions(dragPreviewOption); 1629 /** 1630 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1631 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1632 */ 1633 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1634 dragPreviewOption = frameNode->GetDragPreviewOption(); 1635 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1636 } 1637 1638 /** 1639 * @tc.name: GetPreviewOptionFromModifier012 1640 * @tc.desc: Test UpdatePreviewOptionFromModifier 1641 * @tc.type: FUNC 1642 * @tc.author: 1643 */ 1644 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier012, TestSize.Level1) 1645 { 1646 /** 1647 * @tc.steps: step1. Create FrameNode. 1648 */ 1649 auto frameNode = FrameNode::CreateFrameNode( 1650 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1651 EXPECT_NE(frameNode, nullptr); 1652 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1653 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1654 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1655 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1656 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1657 /** 1658 * @tc.steps: step2. get DragPreviewOption. 1659 */ 1660 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1661 /** 1662 * @tc.steps: step3. set opacity. 1663 */ 1664 dragPreviewOption.options.opacity = 50.0f; 1665 frameNode->SetDragPreviewOptions(dragPreviewOption); 1666 /** 1667 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1668 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1669 */ 1670 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1671 dragPreviewOption = frameNode->GetDragPreviewOption(); 1672 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1673 } 1674 1675 /** 1676 * @tc.name: GetPreviewOptionFromModifier013 1677 * @tc.desc: Test UpdatePreviewOptionFromModifier 1678 * @tc.type: FUNC 1679 * @tc.author: 1680 */ 1681 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier013, TestSize.Level1) 1682 { 1683 /** 1684 * @tc.steps: step1. Create FrameNode. 1685 */ 1686 auto frameNode = FrameNode::CreateFrameNode( 1687 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1688 EXPECT_NE(frameNode, nullptr); 1689 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1690 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1691 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1692 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1693 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1694 /** 1695 * @tc.steps: step2. get DragPreviewOption. 1696 */ 1697 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1698 /** 1699 * @tc.steps: step3. set opacity. 1700 */ 1701 dragPreviewOption.options.opacity = 60.0f; 1702 frameNode->SetDragPreviewOptions(dragPreviewOption); 1703 /** 1704 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1705 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1706 */ 1707 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1708 dragPreviewOption = frameNode->GetDragPreviewOption(); 1709 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1710 } 1711 1712 /** 1713 * @tc.name: GetPreviewOptionFromModifier014 1714 * @tc.desc: Test UpdatePreviewOptionFromModifier 1715 * @tc.type: FUNC 1716 * @tc.author: 1717 */ 1718 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier014, TestSize.Level1) 1719 { 1720 /** 1721 * @tc.steps: step1. Create FrameNode. 1722 */ 1723 auto frameNode = FrameNode::CreateFrameNode( 1724 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1725 EXPECT_NE(frameNode, nullptr); 1726 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1727 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1728 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1729 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1730 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1731 /** 1732 * @tc.steps: step2. get DragPreviewOption. 1733 */ 1734 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1735 /** 1736 * @tc.steps: step3. set opacity. 1737 */ 1738 dragPreviewOption.options.opacity = -60.0f; 1739 frameNode->SetDragPreviewOptions(dragPreviewOption); 1740 /** 1741 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1742 * @tc.expected: opacity in DragPreviewOption is equal to 0.95f. 1743 */ 1744 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1745 dragPreviewOption = frameNode->GetDragPreviewOption(); 1746 EXPECT_EQ(dragPreviewOption.options.opacity, 0.95f); 1747 } 1748 1749 /** 1750 * @tc.name: GetPreviewOptionFromModifier015 1751 * @tc.desc: Test UpdatePreviewOptionFromModifier 1752 * @tc.type: FUNC 1753 * @tc.author: 1754 */ 1755 HWTEST_F(FrameNodeTestNg, GetPreviewOptionFromModifier015, TestSize.Level1) 1756 { 1757 /** 1758 * @tc.steps: step1. Create FrameNode. 1759 */ 1760 auto frameNode = FrameNode::CreateFrameNode( 1761 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>()); 1762 EXPECT_NE(frameNode, nullptr); 1763 auto eventHub = AceType::MakeRefPtr<EventHub>(); 1764 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode)); 1765 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub))); 1766 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>( 1767 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE); 1768 /** 1769 * @tc.steps: step2. get DragPreviewOption. 1770 */ 1771 auto dragPreviewOption = frameNode->GetDragPreviewOption(); 1772 /** 1773 * @tc.steps: step3. set auto scrolling when drag to the edge of scrollable component. 1774 */ 1775 dragPreviewOption.enableEdgeAutoScroll = false; 1776 frameNode->SetDragPreviewOptions(dragPreviewOption); 1777 /** 1778 * @tc.steps: step4. call UpdatePreviewOptionFromModifier 1779 * @tc.expected: enableEdgeAutoScroll is false. 1780 */ 1781 dragEventActuator->UpdatePreviewOptionFromModifier(frameNode); 1782 dragPreviewOption = frameNode->GetDragPreviewOption(); 1783 EXPECT_EQ(dragPreviewOption.enableEdgeAutoScroll, false); 1784 } 1785 1786 /** 1787 * @tc.name: FrameNodeJSCustomProperty 1788 * @tc.desc: Test JSCustomProperty. 1789 * @tc.type: FUNC 1790 */ 1791 HWTEST_F(FrameNodeTestNg, FrameNodeJSCustomProperty, TestSize.Level1) 1792 { 1793 /** 1794 * @tc.steps: step1. initialize parameters. 1795 */ 1796 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1797 std::string getValue; 1798 /** 1799 * @tc.steps: step2. set isCNode true 1800 * @tc.expected: expect result is false. 1801 */ 1802 frameNode->setIsCNode(true); __anon78b9b8441302() 1803 std::function<bool()> func = []() -> bool { return true; }; __anon78b9b8441402(const std::string& key) 1804 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string { 1805 return "getFuncA"; 1806 }; 1807 frameNode->SetJSCustomProperty(func, getFuncA); 1808 bool result = frameNode->GetCapiCustomProperty("key", getValue); 1809 EXPECT_EQ(result, false); 1810 1811 /** 1812 * @tc.steps: step3. set isCNode false and func true. 1813 * @tc.expected: expect result1 is false. 1814 */ 1815 frameNode->setIsCNode(false); __anon78b9b8441502() 1816 func = []() -> bool { return true; }; __anon78b9b8441602(const std::string& key) 1817 getFuncA = [](const std::string& key) -> std::string { 1818 return "getFuncA"; 1819 }; 1820 frameNode->SetJSCustomProperty(func, getFuncA); 1821 frameNode->setIsCNode(true); 1822 bool result1 = frameNode->GetCapiCustomProperty("key", getValue); 1823 EXPECT_EQ(result1, false); 1824 1825 /** 1826 * @tc.steps: step4. set isCNode false and func false. 1827 * @tc.expected: expect result2 is false. 1828 */ 1829 frameNode->setIsCNode(false); __anon78b9b8441702() 1830 func = []() -> bool { return false; }; __anon78b9b8441802(const std::string& key) 1831 getFuncA = [](const std::string& key) -> std::string { 1832 return "getFuncA"; 1833 }; 1834 frameNode->SetJSCustomProperty(func, getFuncA); 1835 frameNode->setIsCNode(true); 1836 bool result2 = frameNode->GetCapiCustomProperty("key", getValue); 1837 EXPECT_EQ(result2, false); 1838 1839 /** 1840 * @tc.steps: step5. set getCustomProperty_ value getFuncA. 1841 * @tc.expected: expect result3 value getFuncA. 1842 */ __anon78b9b8441902() 1843 func = []() -> bool { return true; }; __anon78b9b8441a02(const std::string& key) 1844 getFuncA = [](const std::string& key) -> std::string { 1845 return "getFuncA"; 1846 }; 1847 frameNode->SetJSCustomProperty(func, getFuncA); 1848 frameNode->SetCustomPropertyMapFlagByKey("key"); 1849 bool result3 = frameNode->GetJSCustomProperty("key", getValue); 1850 EXPECT_EQ(result3, true); 1851 EXPECT_EQ(getValue, "getFuncA"); 1852 } 1853 1854 /** 1855 * @tc.name: FrameNodeCapiCustomProperty 1856 * @tc.desc: Test CapiCustomProperty. 1857 * @tc.type: FUNC 1858 */ 1859 HWTEST_F(FrameNodeTestNg, FrameNodeCapiCustomProperty, TestSize.Level1) 1860 { 1861 /** 1862 * @tc.steps: step1. initialize parameters. 1863 */ 1864 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1865 std::string value; 1866 1867 /** 1868 * @tc.steps: step2. GetCapiCustomProperty 1869 * @tc.expected: expect result value false. 1870 */ 1871 frameNode->setIsCNode(false); 1872 bool result = frameNode->GetCapiCustomProperty("key", value); 1873 EXPECT_EQ(result, false); 1874 1875 /** 1876 * @tc.steps: step3. add the key value as value1. 1877 * @tc.expected: expect result value1. 1878 */ 1879 frameNode->setIsCNode(true); 1880 frameNode->AddCustomProperty("key", "value1"); 1881 result = frameNode->GetCapiCustomProperty("key", value); 1882 EXPECT_EQ(result, true); 1883 EXPECT_EQ(value, "value1"); 1884 1885 /** 1886 * @tc.steps: step4. set key is value1 1887 * @tc.expected: expect result value. 1888 */ 1889 frameNode->setIsCNode(true); 1890 frameNode->AddCustomProperty("key", "value1"); 1891 result = frameNode->GetCapiCustomProperty("key1", value); 1892 EXPECT_EQ(result, false); 1893 1894 /** 1895 * @tc.steps: step5. set key is value1, remove key. 1896 * @tc.expected: expect result false. 1897 */ 1898 frameNode->setIsCNode(true); 1899 frameNode->AddCustomProperty("key", "value1"); 1900 frameNode->RemoveCustomProperty("key"); 1901 result = frameNode->GetCapiCustomProperty("key", value); 1902 EXPECT_EQ(result, false); 1903 } 1904 1905 /** 1906 * @tc.name: FrameNodeCapiCustomProperty 1907 * @tc.desc: Test CapiCustomProperty. 1908 * @tc.type: FUNC 1909 */ 1910 HWTEST_F(FrameNodeTestNg, FrameDumpOnSizeChangeInfo, TestSize.Level1) 1911 { 1912 /** 1913 * @tc.steps: step1. create frameNode. 1914 * @tc.expected: expect is not nullptr. 1915 */ 1916 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1917 EXPECT_NE(frameNode, nullptr); 1918 1919 /** 1920 * @tc.steps: step2. onSizeChangeDumpInfos push_back. 1921 * @tc.expected: expect is not nullptr. 1922 */ 1923 frameNode->onSizeChangeDumpInfos.clear(); 1924 frameNode->onSizeChangeDumpInfos.push_back({1625491200, RectF{}, RectF{}}); 1925 frameNode->onSizeChangeDumpInfos.push_back({1625494800, RectF{}, RectF{}}); 1926 EXPECT_EQ(frameNode->onSizeChangeDumpInfos.size(), 2); 1927 1928 /** 1929 * @tc.steps: step3. create json. 1930 * @tc.expected: expect is not nullptr. 1931 */ 1932 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 1933 EXPECT_NE(json, nullptr); 1934 1935 /** 1936 * @tc.steps: step4. test DumpOnSizeChangeInfo. 1937 * @tc.expected: expect is "". 1938 */ 1939 frameNode->DumpOnSizeChangeInfo(json); 1940 EXPECT_EQ(json->GetString(), ""); 1941 } 1942 1943 /** 1944 * @tc.name: FrameNodeDumpOverlayInfo001 1945 * @tc.desc: Test DumpOverlayInfo. 1946 * @tc.type: FUNC 1947 */ 1948 HWTEST_F(FrameNodeTestNg, FrameDumpOverlayInfo001, TestSize.Level1) 1949 { 1950 /** 1951 * @tc.steps: step1. create frameNode. 1952 * @tc.expected: expect is nullptr. 1953 */ 1954 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1955 EXPECT_NE(frameNode, nullptr); 1956 1957 /** 1958 * @tc.steps: step2. create json. 1959 * @tc.expected: expect is nullptr. 1960 */ 1961 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 1962 EXPECT_NE(json, nullptr); 1963 1964 /** 1965 * @tc.steps: step3. test DumpOverlayInfo. 1966 * @tc.expected: expect is FALSE. 1967 */ 1968 frameNode->DumpOverlayInfo(json); 1969 const auto& valueNode = json->GetValue("IsOverlayNode"); 1970 bool hasKeyNode = !(valueNode->IsNull()); 1971 EXPECT_FALSE(hasKeyNode); 1972 1973 const auto& valueOffset = json->GetValue("OverlayOffset"); 1974 bool hasKeyOffset = !(valueNode->IsNull()); 1975 EXPECT_FALSE(hasKeyOffset); 1976 } 1977 1978 /** 1979 * @tc.name: FrameNodeDumpOverlayInfo002 1980 * @tc.desc: Test DumpOverlayInfo. 1981 * @tc.type: FUNC 1982 */ 1983 HWTEST_F(FrameNodeTestNg, FrameDumpOverlayInfo002, TestSize.Level1) 1984 { 1985 /** 1986 * @tc.steps: step1. create frameNode. 1987 * @tc.expected: expect is nullptr. 1988 */ 1989 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 1990 EXPECT_NE(frameNode, nullptr); 1991 1992 /** 1993 * @tc.steps: step2. create json. 1994 * @tc.expected: expect is nullptr. 1995 */ 1996 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 1997 EXPECT_NE(json, nullptr); 1998 1999 /** 2000 * @tc.steps: step3. set layoutProperty. 2001 * @tc.expected: expect is TRUE. 2002 */ 2003 auto layoutProperty = frameNode->GetLayoutProperty(); 2004 layoutProperty->SetIsOverlayNode(true); 2005 2006 /** 2007 * @tc.steps: step4. test DumpOverlayInfo. 2008 * @tc.expected: expect is TRUE. 2009 */ 2010 frameNode->DumpOverlayInfo(json); 2011 const auto& valueNode = json->GetValue("IsOverlayNode"); 2012 bool hasKeyNode = !(valueNode->IsNull()); 2013 EXPECT_TRUE(hasKeyNode); 2014 2015 const auto& valueOffset = json->GetValue("OverlayOffset"); 2016 bool hasKeyOffset = !(valueOffset->IsNull()); 2017 EXPECT_TRUE(hasKeyOffset); 2018 } 2019 2020 /** 2021 * @tc.name: FrameNodeDumpDragInfo 2022 * @tc.desc: Test DumpDragInfo. 2023 * @tc.type: FUNC 2024 */ 2025 HWTEST_F(FrameNodeTestNg, FrameDumpOverlayInfo, TestSize.Level1) 2026 { 2027 /** 2028 * @tc.steps: step1. create frameNode. 2029 * @tc.expected: expect is nullptr. 2030 */ 2031 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2032 EXPECT_NE(frameNode, nullptr); 2033 2034 /** 2035 * @tc.steps: step2. create json. 2036 * @tc.expected: expect is nullptr. 2037 */ 2038 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2039 EXPECT_NE(json, nullptr); 2040 2041 /** 2042 * @tc.steps: step3. test DumpDragInfo. 2043 * @tc.expected: expect is TRUE. 2044 */ 2045 frameNode->DumpDragInfo(json); 2046 const auto& valueDrag = json->GetValue("Draggable"); 2047 bool hasKeyDrag = !(valueDrag->IsNull()); 2048 EXPECT_TRUE(hasKeyDrag); 2049 2050 const auto& valueUser = json->GetValue("UserSet"); 2051 bool hasKeyUser = !(valueUser->IsNull()); 2052 EXPECT_TRUE(hasKeyUser); 2053 2054 const auto& valueCustomer = json->GetValue("CustomerSet"); 2055 bool hasKeyCustomer = !(valueCustomer->IsNull()); 2056 EXPECT_TRUE(hasKeyCustomer); 2057 2058 const auto& valuePreview = json->GetValue("DragPreview"); 2059 bool hasKeyPreview = !(valuePreview->IsNull()); 2060 EXPECT_TRUE(hasKeyPreview); 2061 2062 const auto& valueEvent = json->GetValue("Event"); 2063 bool hasKeyEvent = !(valueEvent->IsNull()); 2064 EXPECT_TRUE(hasKeyEvent); 2065 } 2066 2067 /** 2068 * @tc.name: FrameNodeDumpAlignRulesInfo 2069 * @tc.desc: Test DumpAlignRulesInfo. 2070 * @tc.type: FUNC 2071 */ 2072 HWTEST_F(FrameNodeTestNg, FrameNodeDumpAlignRulesInfo, TestSize.Level1) 2073 { 2074 /** 2075 * @tc.steps: step1. create frameNode. 2076 * @tc.expected: expect is nullptr. 2077 */ 2078 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2079 EXPECT_NE(frameNode, nullptr); 2080 2081 /** 2082 * @tc.steps: step2. create json. 2083 * @tc.expected: expect is nullptr. 2084 */ 2085 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2086 EXPECT_NE(json, nullptr); 2087 2088 /** 2089 * @tc.steps: step3. set layoutProperty. 2090 * @tc.expected: expect is TRUE. 2091 */ 2092 auto layoutProperty = frameNode->GetLayoutProperty(); 2093 2094 /** 2095 * @tc.steps: step5. test DumpAlignRulesInfo. 2096 * @tc.expected: expect is FALSE. 2097 */ 2098 frameNode->DumpAlignRulesInfo(json); 2099 const auto& valueAlignRules = json->GetValue("AlignRules"); 2100 bool hasKeyAlignRules = !(valueAlignRules->IsNull()); 2101 EXPECT_FALSE(hasKeyAlignRules); 2102 } 2103 2104 /** 2105 * @tc.name: FrameNodeDumpSafeAreaInfo 2106 * @tc.desc: Test DumpSafeAreaInfo. 2107 * @tc.type: FUNC 2108 */ 2109 HWTEST_F(FrameNodeTestNg, FrameNodeDumpSafeAreaInfo, TestSize.Level1) 2110 { 2111 /** 2112 * @tc.steps: step1. create frameNode. 2113 * @tc.expected: expect is nullptr. 2114 */ 2115 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2116 EXPECT_NE(frameNode, nullptr); 2117 2118 /** 2119 * @tc.steps: step2. create json. 2120 * @tc.expected: expect is nullptr. 2121 */ 2122 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2123 EXPECT_NE(json, nullptr); 2124 2125 /** 2126 * @tc.steps: step3. set layoutProperty. 2127 * @tc.expected: expect is TRUE. 2128 */ 2129 auto layoutProperty = frameNode->GetLayoutProperty(); 2130 2131 /** 2132 * @tc.steps: step5. test DumpSafeAreaInfo. 2133 * @tc.expected: expect is FALSE. 2134 */ 2135 frameNode->DumpSafeAreaInfo(json); 2136 2137 SafeAreaExpandOpts opts; 2138 opts.switchToNone = true; 2139 frameNode->GetLayoutProperty()->UpdateSafeAreaExpandOpts(opts); 2140 SafeAreaInsets safeArea; 2141 frameNode->GetLayoutProperty()->UpdateSafeAreaInsets(safeArea); 2142 frameNode->DumpSafeAreaInfo(json); 2143 2144 /** 2145 * @tc.steps: step6. safeAreaExpandOpts_ is nullptr. 2146 * @tc.expected: expect is FALSE. 2147 */ 2148 const auto& valueExpandOpts = json->GetValue("SafeAreaExpandOpts"); 2149 bool hasKeyExpandOpts = !(valueExpandOpts->IsNull()); 2150 EXPECT_TRUE(hasKeyExpandOpts); 2151 2152 /** 2153 * @tc.steps: step7. safeAreaInsets_ is nullptr. 2154 * @tc.expected: expect is FALSE. 2155 */ 2156 const auto& valueInsets = json->GetValue("SafeAreaInsets"); 2157 bool hasKeyInsets = !(valueInsets->IsNull()); 2158 EXPECT_TRUE(hasKeyInsets); 2159 2160 /** 2161 * @tc.steps: step8. OrParentExpansive_ is nullptr. 2162 * @tc.expected: expect is FALSE. 2163 */ 2164 const auto& valueSelf = json->GetValue("selfAdjust"); 2165 bool hasKeySelf = !(valueSelf->IsNull()); 2166 EXPECT_FALSE(hasKeySelf); 2167 2168 const auto& valueParent = json->GetValue("parentAdjust"); 2169 bool hasKeyParent = !(valueParent->IsNull()); 2170 EXPECT_FALSE(hasKeyParent); 2171 2172 /** 2173 * @tc.steps: step9. safeSafeAreaManager_ is nullptr. 2174 * @tc.expected: expect is FALSE. 2175 */ 2176 const auto& valueIgnore = json->GetValue("ignoreSafeArea"); 2177 bool hasKeyIgnore = !(valueIgnore->IsNull()); 2178 EXPECT_FALSE(hasKeyIgnore); 2179 2180 const auto& valueNeedAvoid = json->GetValue("isNeedAvoidWindow"); 2181 bool hasKeyNeedAvoid = !(valueNeedAvoid->IsNull()); 2182 EXPECT_FALSE(hasKeyNeedAvoid); 2183 2184 const auto& valueFullScreen = json->GetValue("isFullScreen"); 2185 bool hasKeyFullScreen = !(valueFullScreen->IsNull()); 2186 EXPECT_FALSE(hasKeyFullScreen); 2187 2188 const auto& valueKeyboard = json->GetValue("isKeyboardAvoidMode"); 2189 bool hasKeyKeyboard = !(valueKeyboard->IsNull()); 2190 EXPECT_FALSE(hasKeyKeyboard); 2191 2192 const auto& valueUseCutout = json->GetValue("isUseCutout"); 2193 bool hasKeyUseCutout = !(valueUseCutout->IsNull()); 2194 EXPECT_FALSE(hasKeyUseCutout); 2195 } 2196 2197 /** 2198 * @tc.name: FrameNodeBuildLayoutInfo 2199 * @tc.desc: Test BuildLayoutInfo. 2200 * @tc.type: FUNC 2201 */ 2202 HWTEST_F(FrameNodeTestNg, FrameNodeBuildLayoutInfo, TestSize.Level1) 2203 { 2204 /** 2205 * @tc.steps: step1. create frameNode. 2206 * @tc.expected: expect is nullptr. 2207 */ 2208 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2209 EXPECT_NE(frameNode, nullptr); 2210 2211 /** 2212 * @tc.steps: step2. create json. 2213 * @tc.expected: expect is nullptr. 2214 */ 2215 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2216 EXPECT_NE(json, nullptr); 2217 2218 /** 2219 * @tc.steps: step3. set layoutProperty. 2220 * @tc.expected: expect is TRUE. 2221 */ 2222 auto layoutProperty = frameNode->GetLayoutProperty(); 2223 2224 /** 2225 * @tc.steps: step4. set geometryNode. 2226 * @tc.expected: expect is TRUE. 2227 */ 2228 auto geometryNode = frameNode->GetGeometryNode(); 2229 2230 /** 2231 * @tc.steps: step5. test BuildLayoutInfo. 2232 * @tc.expected: expect is FALSE. 2233 */ 2234 frameNode->BuildLayoutInfo(json); 2235 2236 auto layoutConstraintF_ = LayoutConstraintF(); 2237 layoutConstraintF_.maxSize = CONTAINER_SIZE; 2238 layoutConstraintF_.percentReference = CONTAINER_SIZE; 2239 frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_); 2240 frameNode->geometryNode_->SetFrameOffset(OffsetF(1.0f, 0.0f)); 2241 frameNode->layoutProperty_->UpdateVisibility(VisibleType::INVISIBLE); 2242 PaddingProperty padding; 2243 padding.left = CalcLength(0.0f); 2244 padding.right = CalcLength(0.0f); 2245 padding.top = CalcLength(0.0f); 2246 padding.bottom = CalcLength(0.0f); 2247 frameNode->layoutProperty_->UpdatePadding(padding); 2248 frameNode->layoutProperty_->UpdateSafeAreaPadding(padding); 2249 BorderWidthProperty overCountBorderWidth; 2250 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP)); 2251 frameNode->layoutProperty_->UpdateBorderWidth(overCountBorderWidth); 2252 MarginProperty marginProperty; 2253 frameNode->layoutProperty_->UpdateMargin(marginProperty); 2254 NG::RectF testRect = { 10.0f, 10.0f, 10.0f, 10.0f }; 2255 frameNode->layoutProperty_->SetLayoutRect(testRect); 2256 frameNode->BuildLayoutInfo(json); 2257 2258 /** 2259 * @tc.steps: step5. ParentLayoutConstraint is nullptr. 2260 * @tc.expected: expect is FALSE. 2261 */ 2262 const auto& valueConstraint = json->GetValue("ParentLayoutConstraint"); 2263 bool hasKeyConstraint = !(valueConstraint->IsNull()); 2264 EXPECT_TRUE(hasKeyConstraint); 2265 2266 const auto& valuetop = json->GetValue("top"); 2267 bool hasKeytop = !(valuetop->IsNull()); 2268 EXPECT_TRUE(hasKeytop); 2269 2270 const auto& valueleft = json->GetValue("left"); 2271 bool hasKeyleft = !(valueleft->IsNull()); 2272 EXPECT_TRUE(hasKeyleft); 2273 2274 const auto& valueActive = json->GetValue("Active"); 2275 bool hasKeyActive = !(valueActive->IsNull()); 2276 EXPECT_TRUE(hasKeyActive); 2277 2278 const auto& valueVisible = json->GetValue("Visible"); 2279 bool hasKeyVisible = !(valueVisible->IsNull()); 2280 EXPECT_TRUE(hasKeyVisible); 2281 2282 const auto& valuePadding = json->GetValue("Padding"); 2283 bool hasKeyPadding = !(valuePadding->IsNull()); 2284 EXPECT_TRUE(hasKeyPadding); 2285 2286 const auto& valueBorder = json->GetValue("Border"); 2287 bool hasKeyBorder = !(valueBorder->IsNull()); 2288 EXPECT_TRUE(hasKeyBorder); 2289 2290 const auto& valueMargin = json->GetValue("Margin"); 2291 bool hasKeyMargin = !(valueMargin->IsNull()); 2292 EXPECT_TRUE(hasKeyMargin); 2293 2294 const auto& valueLayout = json->GetValue("LayoutRect"); 2295 bool hasKeyLayout = !(valueLayout->IsNull()); 2296 EXPECT_TRUE(hasKeyLayout); 2297 } 2298 2299 /** 2300 * @tc.name: FrameNodeMarkRemoving001 2301 * @tc.desc: Test MarkRemoving. 2302 * @tc.type: FUNC 2303 */ 2304 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving001, TestSize.Level1) 2305 { 2306 /** 2307 * @tc.steps: step1. create frameNode. 2308 * @tc.expected: expect is nullptr. 2309 */ 2310 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2311 EXPECT_NE(frameNode, nullptr); 2312 2313 /** 2314 * @tc.steps: step2. test MarkRemoving. 2315 * @tc.expected: expect is false. 2316 */ 2317 auto pendingRemove = frameNode->MarkRemoving(); 2318 EXPECT_FALSE(pendingRemove); 2319 } 2320 2321 /** 2322 * @tc.name: FrameNodeMarkRemoving002 2323 * @tc.desc: Test MarkRemoving. 2324 * @tc.type: FUNC 2325 */ 2326 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving002, TestSize.Level1) 2327 { 2328 /** 2329 * @tc.steps: step1. create frameNode. 2330 * @tc.expected: expect is nullptr. 2331 */ 2332 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2333 EXPECT_NE(frameNode, nullptr); 2334 2335 /** 2336 * @tc.steps: step2. set layoutProperty. 2337 * @tc.expected: expect is nullptr. 2338 */ 2339 auto layoutProperty = frameNode->GetLayoutProperty(); 2340 2341 /** 2342 * @tc.steps: step3. test MarkRemoving. 2343 * @tc.expected: expect is false. 2344 */ 2345 auto pendingRemove = frameNode->MarkRemoving(); 2346 EXPECT_FALSE(pendingRemove); 2347 } 2348 2349 /** 2350 * @tc.name: FrameNodeMarkRemoving003 2351 * @tc.desc: Test MarkRemoving. 2352 * @tc.type: FUNC 2353 */ 2354 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving003, TestSize.Level1) 2355 { 2356 /** 2357 * @tc.steps: step1. create frameNode. 2358 * @tc.expected: expect is nullptr. 2359 */ 2360 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2361 EXPECT_NE(frameNode, nullptr); 2362 2363 /** 2364 * @tc.steps: step2. set geometryNode. 2365 * @tc.expected: expect is nullptr. 2366 */ 2367 auto geometryNode = frameNode->GetGeometryNode(); 2368 2369 /** 2370 * @tc.steps: step3. test MarkRemoving. 2371 * @tc.expected: expect is false. 2372 */ 2373 auto pendingRemove = frameNode->MarkRemoving(); 2374 EXPECT_FALSE(pendingRemove); 2375 } 2376 2377 /** 2378 * @tc.name: FrameNodeMarkRemoving004 2379 * @tc.desc: Test MarkRemoving. 2380 * @tc.type: FUNC 2381 */ 2382 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving004, TestSize.Level1) 2383 { 2384 /** 2385 * @tc.steps: step1. create frameNode. 2386 * @tc.expected: expect is nullptr. 2387 */ 2388 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2389 EXPECT_NE(frameNode, nullptr); 2390 2391 /** 2392 * @tc.steps: step2. set geometryNode and layoutProperty. 2393 * @tc.expected: expect is nullptr. 2394 */ 2395 auto geometryNode = frameNode->GetGeometryNode(); 2396 auto layoutProperty = frameNode->GetLayoutProperty(); 2397 2398 /** 2399 * @tc.steps: step3. test MarkRemoving. 2400 * @tc.expected: expect is false. 2401 */ 2402 auto pendingRemove = frameNode->MarkRemoving(); 2403 EXPECT_FALSE(pendingRemove); 2404 } 2405 2406 /** 2407 * @tc.name: FrameNodeOnConfigurationUpdate 2408 * @tc.desc: Test of OnConfigurationUpdate 2409 * @tc.type: FUNC 2410 */ 2411 HWTEST_F(FrameNodeTestNg, FrameNodeOnConfigurationUpdate, TestSize.Level1) 2412 { 2413 /** 2414 * @tc.steps: step1. create childNode and itemNode 2415 * @tc.expected: childNode and itemNode is not null 2416 */ 2417 auto childNode = FrameNode::CreateFrameNode( 2418 "child", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>()); 2419 auto itemNode = FrameNode::CreateFrameNode( 2420 "itemNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>()); 2421 childNode->AddChild(itemNode); 2422 2423 /** 2424 * @tc.steps: step2. create configurationChange. 2425 */ 2426 ConfigurationChange configurationChange; 2427 2428 /** 2429 * @tc.steps: step3. childNode Update Configuration. 2430 * @tc.expected: update success 2431 */ 2432 childNode->OnConfigurationUpdate(configurationChange); 2433 2434 /** 2435 * @tc.steps: step4. set languageUpdate is true. 2436 * @tc.expected: update success 2437 */ 2438 configurationChange.languageUpdate = true; 2439 childNode->OnConfigurationUpdate(configurationChange); 2440 2441 /** 2442 * @tc.steps: step5. set colorModeUpdate is true 2443 * @tc.expected: update success 2444 */ 2445 configurationChange.colorModeUpdate = true; 2446 childNode->OnConfigurationUpdate(configurationChange); 2447 2448 /** 2449 * @tc.steps: step6. set directionUpdate is true 2450 * @tc.expected: update success 2451 */ 2452 configurationChange.directionUpdate = true; 2453 childNode->OnConfigurationUpdate(configurationChange); 2454 2455 /** 2456 * @tc.steps: step7. set dpiUpdate is true 2457 * @tc.expected: update success 2458 */ 2459 configurationChange.dpiUpdate = true; 2460 childNode->OnConfigurationUpdate(configurationChange); 2461 2462 /** 2463 * @tc.steps: step8. set fontUpdate is true 2464 * @tc.expected: update success 2465 */ 2466 configurationChange.fontUpdate = true; 2467 configurationChange.iconUpdate = true; 2468 configurationChange.skinUpdate = true; 2469 configurationChange.fontWeightScaleUpdate = true; 2470 childNode->OnConfigurationUpdate(configurationChange); 2471 2472 /** 2473 * @tc.steps: step9. set fontScaleUpdate is true 2474 * @tc.expected: update success 2475 */ 2476 configurationChange.fontScaleUpdate = true; 2477 childNode->OnConfigurationUpdate(configurationChange); 2478 2479 childNode->SetBackgroundLayoutConstraint(itemNode); 2480 childNode->ForceUpdateLayoutPropertyFlag(PROPERTY_UPDATE_MEASURE_SELF); 2481 childNode->GetPaintRectWithTransform(); 2482 childNode->GetTransformScale(); 2483 childNode->SetJSViewActive(true); 2484 2485 /** 2486 * @tc.steps: step10. create layoutProperty 2487 * @tc.expected: layoutProperty is nullptr 2488 */ 2489 auto layoutProperty = childNode->GetLayoutProperty(); 2490 EXPECT_FALSE(layoutProperty->IsOverlayNode()); 2491 layoutProperty->SetIsOverlayNode(true); 2492 childNode->DumpOverlayInfo(); 2493 EXPECT_TRUE(layoutProperty->IsOverlayNode()); 2494 } 2495 2496 /** 2497 * @tc.name: FrameNodeOnRemoveFromParent001 2498 * @tc.desc: Test OnRemoveFromParent. 2499 * @tc.type: FUNC 2500 */ 2501 HWTEST_F(FrameNodeTestNg, FrameNodeOnRemoveFromParent001, TestSize.Level1) 2502 { 2503 /** 2504 * @tc.steps: step1. create frameNode. 2505 * @tc.expected: expect is nullptr. 2506 */ 2507 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2508 EXPECT_NE(frameNode, nullptr); 2509 2510 /** 2511 * @tc.steps: step2. set allowTransition. 2512 * @tc.expected: expect is true. 2513 */ 2514 auto allowTransition = true; 2515 2516 /** 2517 * @tc.steps: step3. test OnRemoveFromParent. 2518 * @tc.expected: expect is true. 2519 */ 2520 auto removeFrom = frameNode->OnRemoveFromParent(allowTransition); 2521 EXPECT_TRUE(removeFrom); 2522 } 2523 2524 /** 2525 * @tc.name: FrameNodeOnRemoveFromParent002 2526 * @tc.desc: Test OnRemoveFromParent. 2527 * @tc.type: FUNC 2528 */ 2529 HWTEST_F(FrameNodeTestNg, FrameNodeOnRemoveFromParent002, TestSize.Level1) 2530 { 2531 /** 2532 * @tc.steps: step1. create frameNode. 2533 * @tc.expected: expect is nullptr. 2534 */ 2535 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2536 EXPECT_NE(frameNode, nullptr); 2537 2538 /** 2539 * @tc.steps: step2. set allowTransition. 2540 * @tc.expected: expect is false. 2541 */ 2542 auto allowTransition = false; 2543 2544 /** 2545 * @tc.steps: step3. test OnRemoveFromParent. 2546 * @tc.expected: expect is true. 2547 */ 2548 auto removeFrom = frameNode->OnRemoveFromParent(allowTransition); 2549 EXPECT_TRUE(removeFrom); 2550 } 2551 2552 /** 2553 * @tc.name: FrameNodeFindChildByName 2554 * @tc.desc: Test FindChildByName. 2555 * @tc.type: FUNC 2556 */ 2557 HWTEST_F(FrameNodeTestNg, FrameNodeFindChildByName, TestSize.Level1) 2558 { 2559 /** 2560 * @tc.steps: step1. create frameNode. 2561 * @tc.expected: expect is not nullptr. 2562 */ 2563 const std::string parentName = "Parent"; 2564 const std::string oneName = "One"; 2565 const std::string oneChildName = "OneChild"; 2566 const std::string twoName = "Two"; 2567 const std::string twoChildName = "TwoChild"; 2568 const std::string testName = "test"; 2569 auto parent = FrameNode::CreateFrameNode(parentName, 10, AceType::MakeRefPtr<Pattern>(), true); 2570 auto one = FrameNode::CreateFrameNode(oneName, 20, AceType::MakeRefPtr<Pattern>()); 2571 auto oneChild = FrameNode::CreateFrameNode(oneChildName, 30, AceType::MakeRefPtr<Pattern>()); 2572 auto two = FrameNode::CreateFrameNode(twoName, 40, AceType::MakeRefPtr<Pattern>()); 2573 auto twoChild = FrameNode::CreateFrameNode(twoChildName, 50, AceType::MakeRefPtr<Pattern>()); 2574 2575 EXPECT_NE(parent, nullptr); 2576 EXPECT_NE(one, nullptr); 2577 EXPECT_NE(oneChild, nullptr); 2578 EXPECT_NE(two, nullptr); 2579 EXPECT_NE(twoChild, nullptr); 2580 2581 /** 2582 * @tc.steps: step1. Set the node's relation. 2583 * @tc.expected: expect is null nullptr. 2584 */ 2585 parent->AddChild(one); 2586 parent->AddChild(two); 2587 one->AddChild(oneChild); 2588 two->AddChild(twoChild); 2589 2590 EXPECT_NE(parent, nullptr); 2591 EXPECT_NE(one, nullptr); 2592 EXPECT_NE(two, nullptr); 2593 2594 /** 2595 * @tc.steps: step3. update InspectorId. 2596 * @tc.expected: update success 2597 */ 2598 parent->UpdateInspectorId(parentName); 2599 one->UpdateInspectorId(oneName); 2600 oneChild->UpdateInspectorId(oneChildName); 2601 two->UpdateInspectorId(twoName); 2602 twoChild->UpdateInspectorId(twoChildName); 2603 2604 /** 2605 * @tc.steps: step3. find oneChild. 2606 * @tc.expected: success 2607 */ 2608 auto finalResult = FrameNode::FindChildByName(parent, oneName); 2609 EXPECT_NE(finalResult, oneChild); 2610 2611 /** 2612 * @tc.steps: step3. find testName. 2613 * @tc.expected: fail 2614 */ 2615 auto noChildResult = FrameNode::FindChildByName(parent, testName); 2616 EXPECT_EQ(noChildResult, nullptr); 2617 2618 /** 2619 * @tc.steps: step3. clear parent to find twoChild. 2620 * @tc.expected: fail 2621 */ 2622 parent->Clean(); 2623 auto noHaveResult = FrameNode::FindChildByName(parent, twoChildName); 2624 EXPECT_EQ(noHaveResult, nullptr); 2625 } 2626 2627 /** 2628 * @tc.name: FrameNodeSwapDirty 2629 * @tc.desc: Test SwapDirtyLayoutWrapperOnMainThread 2630 * @tc.type: FUNC 2631 */ 2632 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirty001, TestSize.Level1) 2633 { 2634 /** 2635 * @tc.steps: step1. creat frameNode and layoutProperty 2636 */ 2637 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true); 2638 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2639 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>(); 2640 EXPECT_NE(layoutProperty, nullptr); 2641 2642 /** 2643 * @tc.steps: step2. setBorderWidth and updateBorderWidth. 2644 * @tc.expected: expect borderWidth property is not nullptr. 2645 */ 2646 BorderWidthProperty overCountBorderWidth; 2647 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP)); 2648 layoutProperty->UpdateBorderWidth(overCountBorderWidth); 2649 frameNode->SetLayoutProperty(layoutProperty); 2650 2651 /** 2652 * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread 2653 * @tc.expected: expect GetBorderWidthProperty is not nullptr. 2654 */ 2655 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper); 2656 EXPECT_NE(layoutProperty->GetBorderWidthProperty(), nullptr); 2657 } 2658 2659 /** 2660 * @tc.name: FrameNodeSwapDirty 2661 * @tc.desc: Test SwapDirtyLayoutWrapperOnMainThread 2662 * @tc.type: FUNC 2663 */ 2664 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirty002, TestSize.Level1) 2665 { 2666 /** 2667 * @tc.steps: step1. creat frameNode and layoutProperty 2668 */ 2669 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true); 2670 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2671 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>(); 2672 EXPECT_NE(layoutProperty, nullptr); 2673 2674 /** 2675 * @tc.steps: step2. setBorderWidth and updateBorderWidth. 2676 * @tc.expected: expect borderWidth property is not nullptr. 2677 */ 2678 BorderWidthProperty overCountBorderWidth; 2679 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP)); 2680 layoutProperty->UpdateBorderWidth(overCountBorderWidth); 2681 frameNode->SetLayoutProperty(layoutProperty); 2682 2683 /** 2684 * @tc.steps: step3. updatae layoutConstraint and set eventHub_. 2685 * @tc.expected: nullptr. 2686 */ 2687 auto layoutConstraintF_ = LayoutConstraintF(); 2688 layoutConstraintF_.maxSize = CONTAINER_SIZE; 2689 layoutConstraintF_.percentReference = CONTAINER_SIZE; 2690 frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_); 2691 layoutProperty->UpdateLayoutConstraint(layoutConstraintF_); 2692 2693 frameNode->GetEventHub<EventHub>()->GetOrCreateFocusHub(); 2694 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper); 2695 EXPECT_NE(frameNode->eventHub_, nullptr); 2696 } 2697 2698 /** 2699 * @tc.name: FrameNodeSwapDirty 2700 * @tc.desc: Test SwapDirtyLayoutWrapperOnMainThread 2701 * @tc.type: FUNC 2702 */ 2703 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirty003, TestSize.Level1) 2704 { 2705 /** 2706 * @tc.steps: step1. creat frameNode and layoutProperty 2707 */ 2708 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true); 2709 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2710 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>(); 2711 EXPECT_NE(layoutProperty, nullptr); 2712 2713 /** 2714 * @tc.steps: step2. setBorderWidth and updateBorderWidth. 2715 * @tc.expected: expect borderWidth property is not nullptr. 2716 */ 2717 BorderWidthProperty overCountBorderWidth; 2718 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP)); 2719 layoutProperty->UpdateBorderWidth(overCountBorderWidth); 2720 frameNode->SetLayoutProperty(layoutProperty); 2721 2722 /** 2723 * @tc.steps: step5. set currentFocus_ is true and call SwapDirtyLayoutWrapperOnMainThread. 2724 * @tc.expected: expect cover branch IsCurrentFocus() is true and function is run ok . 2725 */ 2726 auto layoutConstraintF_ = LayoutConstraintF(); 2727 layoutConstraintF_.maxSize = CONTAINER_SIZE; 2728 layoutConstraintF_.percentReference = CONTAINER_SIZE; 2729 frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_); 2730 layoutProperty->UpdateLayoutConstraint(layoutConstraintF_); 2731 2732 frameNode->GetEventHub<EventHub>()->GetOrCreateFocusHub()->currentFocus_ = true; 2733 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper); 2734 EXPECT_TRUE(frameNode->GetEventHub<EventHub>()->GetOrCreateFocusHub()->IsCurrentFocus()); 2735 } 2736 2737 /** 2738 * @tc.name: FrameNodeGeometryNodeToJsonValue 2739 * @tc.desc: Test method GeometryNodeToJsonValue 2740 * @tc.type: FUNC 2741 */ 2742 HWTEST_F(FrameNodeTestNg, FrameNodeGeometryNodeToJsonValue, TestSize.Level1) 2743 { 2744 /** 2745 * @tc.steps: step1. create value. 2746 */ 2747 auto value = JsonUtil::Create(true); 2748 2749 /** 2750 * @tc.steps: step2. construct parameters. 2751 * @tc.expected: expect cover branch layoutProperty_ is nullptr. 2752 */ 2753 auto frameNode = FrameNode::CreateFrameNode("frameNode", 2, AceType::MakeRefPtr<Pattern>()); 2754 InspectorFilter filter; 2755 frameNode->GeometryNodeToJsonValue(value, filter); 2756 EXPECT_NE(frameNode->layoutProperty_, nullptr); 2757 2758 /** 2759 * @tc.steps: step3. set layoutProperty_ and call GeometryNodeToJsonValue. 2760 * @tc.expected: expect cover branch layoutProperty_ is not nullptr. 2761 */ 2762 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 2763 frameNode->layoutProperty_ = layoutProperty; 2764 frameNode->GeometryNodeToJsonValue(value, filter); 2765 EXPECT_NE(frameNode->layoutProperty_, nullptr); 2766 2767 /** 2768 * @tc.steps: step4. set calcLayoutConstraint_ and call GeometryNodeToJsonValue. 2769 * @tc.expected: expect cover branch calcLayoutConstraint_ is not nullptr. 2770 */ 2771 frameNode->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>(); 2772 2773 frameNode->GeometryNodeToJsonValue(value, filter); 2774 EXPECT_NE(frameNode->layoutProperty_->calcLayoutConstraint_, nullptr); 2775 2776 /** 2777 * @tc.steps: step5. set selfIdealSize and call GeometryNodeToJsonValue. 2778 * @tc.expected: expect cover branch selfIdealSize has value. 2779 */ 2780 std::optional<CalcLength> len = CalcLength("auto"); 2781 frameNode->layoutProperty_->calcLayoutConstraint_->selfIdealSize = CalcSize(len, len); 2782 frameNode->GeometryNodeToJsonValue(value, filter); 2783 EXPECT_NE(frameNode->renderContext_, nullptr); 2784 } 2785 2786 /** 2787 * @tc.name: FrameNodeDumpSimplifyCommonInfo 2788 * @tc.desc: Test DumpSimplifyCommonInfo. 2789 * @tc.type: FUNC 2790 */ 2791 HWTEST_F(FrameNodeTestNg, FrameNodeDumpSimplifyCommonInfo, TestSize.Level1) 2792 { 2793 /** 2794 * @tc.steps: step1. create frameNode. 2795 * @tc.expected: expect is nullptr. 2796 */ 2797 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2798 EXPECT_NE(frameNode, nullptr); 2799 2800 /** 2801 * @tc.steps: step2. create json. 2802 * @tc.expected: expect is nullptr. 2803 */ 2804 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2805 EXPECT_NE(json, nullptr); 2806 2807 /** 2808 * @tc.steps: step3. test DumpOverlayInfo. 2809 * @tc.expected: expect is FALSE. 2810 */ 2811 frameNode->DumpSimplifyCommonInfo(json); 2812 const auto& valueFrameRect = json->GetValue("FrameRect"); 2813 bool hasvalueFrameRect = !(valueFrameRect->IsNull()); 2814 EXPECT_FALSE(hasvalueFrameRect); 2815 2816 const auto& valueTransform = json->GetValue("PaintRectWithoutTransform"); 2817 bool hasKeyTransform = !(valueTransform->IsNull()); 2818 EXPECT_FALSE(hasKeyTransform); 2819 2820 const auto& valueColor = json->GetValue("BackgroundColor"); 2821 bool hasKeyColor = !(valueColor->IsNull()); 2822 EXPECT_FALSE(hasKeyColor); 2823 2824 const auto& valueOffset = json->GetValue("Offset"); 2825 bool hasKeyOffset = !(valueOffset->IsNull()); 2826 EXPECT_FALSE(hasKeyOffset); 2827 2828 const auto& valueVisible = json->GetValue("Visible"); 2829 bool hasKeyVisible = !(valueVisible->IsNull()); 2830 EXPECT_FALSE(hasKeyVisible); 2831 2832 const auto& valueLayoutRect = json->GetValue("LayoutRect"); 2833 bool hasKeyLayoutRect = !(valueLayoutRect->IsNull()); 2834 EXPECT_FALSE(hasKeyLayoutRect); 2835 2836 const auto& valueConstraint = json->GetValue("UserDefinedConstraint"); 2837 bool hasKeyConstraint = !(valueConstraint->IsNull()); 2838 EXPECT_FALSE(hasKeyConstraint); 2839 2840 const auto& valueContent = json->GetValue("ContentConstraint"); 2841 bool hasKeyContent = !(valueContent->IsNull()); 2842 EXPECT_FALSE(hasKeyContent); 2843 2844 const auto& valueParentLayout = json->GetValue("ParentLayoutConstraint"); 2845 bool hasKeyParentLayout = !(valueParentLayout->IsNull()); 2846 EXPECT_FALSE(hasKeyParentLayout); 2847 } 2848 2849 /** 2850 * @tc.name: FrameNodeDumpSimplifySafeAreaInfo 2851 * @tc.desc: Test DumpSimplifySafeAreaInfo. 2852 * @tc.type: FUNC 2853 */ 2854 HWTEST_F(FrameNodeTestNg, FrameNodeDumpSimplifySafeAreaInfo, TestSize.Level1) 2855 { 2856 /** 2857 * @tc.steps: step1. create frameNode. 2858 * @tc.expected: expect is nullptr. 2859 */ 2860 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2861 EXPECT_NE(frameNode, nullptr); 2862 2863 /** 2864 * @tc.steps: step2. create json. 2865 * @tc.expected: expect is nullptr. 2866 */ 2867 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2868 EXPECT_NE(json, nullptr); 2869 2870 /** 2871 * @tc.steps: step3. test DumpSimplifySafeAreaInfo. 2872 * @tc.expected: expect is FALSE. 2873 */ 2874 frameNode->DumpSimplifySafeAreaInfo(json); 2875 const auto& valueExpandOpts = json->GetValue("SafeAreaExpandOpts"); 2876 bool hasvalueExpandOpts = !(valueExpandOpts->IsNull()); 2877 EXPECT_FALSE(hasvalueExpandOpts); 2878 2879 const auto& valueInsets = json->GetValue("SafeAreaInsets"); 2880 bool hasKeyInsets = !(valueInsets->IsNull()); 2881 EXPECT_FALSE(hasKeyInsets); 2882 2883 const auto& valueSelfAdjust = json->GetValue("SelfAdjust"); 2884 bool hasKeySelfAdjust = !(valueSelfAdjust->IsNull()); 2885 EXPECT_FALSE(hasKeySelfAdjust); 2886 2887 const auto& valueParentSelfAdjust = json->GetValue("ParentSelfAdjust"); 2888 bool hasKeyParentSelfAdjust = !(valueParentSelfAdjust->IsNull()); 2889 EXPECT_FALSE(hasKeyParentSelfAdjust); 2890 2891 const auto& valueIgnore = json->GetValue("IgnoreSafeArea"); 2892 bool hasKeyIgnore = !(valueIgnore->IsNull()); 2893 EXPECT_FALSE(hasKeyIgnore); 2894 2895 const auto& valueAvoidWindow = json->GetValue("IsNeedAvoidWindow"); 2896 bool hasKeyAvoidWindow = !(valueAvoidWindow->IsNull()); 2897 EXPECT_FALSE(hasKeyAvoidWindow); 2898 2899 const auto& valueIsFullScreen = json->GetValue("IsFullScreen"); 2900 bool hasKeyIsFullScreen = !(valueIsFullScreen->IsNull()); 2901 EXPECT_FALSE(hasKeyIsFullScreen); 2902 2903 const auto& valueIsKeyboard = json->GetValue("IsKeyboardAvoidMode"); 2904 bool hasKeyIsKeyboard = !(valueIsKeyboard->IsNull()); 2905 EXPECT_FALSE(hasKeyIsKeyboard); 2906 2907 const auto& valueIsUseCutout = json->GetValue("IsUseCutout"); 2908 bool hasKeyIsUseCutout = !(valueIsUseCutout->IsNull()); 2909 EXPECT_FALSE(hasKeyIsUseCutout); 2910 } 2911 2912 /** 2913 * @tc.name: FrameNodeDumpCommonInfo 2914 * @tc.desc: Test DumpCommonInfo. 2915 * @tc.type: FUNC 2916 */ 2917 HWTEST_F(FrameNodeTestNg, FrameNodeDumpCommonInfo, TestSize.Level1) 2918 { 2919 /** 2920 * @tc.steps: step1. create frameNode. 2921 * @tc.expected: expect is nullptr. 2922 */ 2923 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2924 EXPECT_NE(frameNode, nullptr); 2925 2926 /** 2927 * @tc.steps: step2. create json. 2928 * @tc.expected: expect is nullptr. 2929 */ 2930 std::unique_ptr<JsonValue> json = JsonUtil::Create(true); 2931 EXPECT_NE(json, nullptr); 2932 2933 /** 2934 * @tc.steps: step3. test DumpCommonInfo. 2935 * @tc.expected: expect is FALSE. 2936 */ 2937 frameNode->DumpCommonInfo(json); 2938 2939 frameNode->renderContext_->UpdateBackgroundColor(Color::BLUE); 2940 MeasureProperty constraint; 2941 frameNode->layoutProperty_->UpdateCalcLayoutProperty(constraint); 2942 frameNode->propInspectorId_ = "test"; 2943 frameNode->DumpCommonInfo(json); 2944 MarginProperty marginProperty; 2945 frameNode->layoutProperty_->UpdateMargin(marginProperty); 2946 frameNode->DumpCommonInfo(json); 2947 BorderWidthProperty overCountBorderWidth; 2948 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP)); 2949 frameNode->layoutProperty_->UpdateBorderWidth(overCountBorderWidth); 2950 frameNode->DumpCommonInfo(json); 2951 PaddingProperty padding; 2952 frameNode->layoutProperty_->UpdatePadding(padding); 2953 frameNode->DumpCommonInfo(json); 2954 2955 const auto& valueFrameRect = json->GetValue("FrameRect"); 2956 bool hasvalueFrameRect = !(valueFrameRect->IsNull()); 2957 EXPECT_TRUE(hasvalueFrameRect); 2958 2959 const auto& valuePaintRect = json->GetValue("PaintRect without transform"); 2960 bool hasvaluePaintRect = !(valuePaintRect->IsNull()); 2961 EXPECT_TRUE(hasvaluePaintRect); 2962 2963 const auto& valueBackgroundColor= json->GetValue("BackgroundColor"); 2964 bool hasvalueBackgroundColor = !(valueBackgroundColor->IsNull()); 2965 EXPECT_TRUE(hasvalueBackgroundColor); 2966 2967 frameNode->DumpInfo(json); 2968 frameNode->DumpAdvanceInfo(json); 2969 const auto& valueConstraint = json->GetValue("ParentLayoutConstraint"); 2970 bool hasKeyConstraint = !(valueConstraint->IsNull()); 2971 EXPECT_FALSE(hasKeyConstraint); 2972 } 2973 2974 /** 2975 * @tc.name: FrameNodeGetJSCustomProperty001 2976 * @tc.desc: Test GetJSCustomProperty. 2977 * @tc.type: FUNC 2978 */ 2979 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty001, TestSize.Level1) 2980 { 2981 /** 2982 * @tc.steps: step1. create frameNode. 2983 * @tc.expected: expect is not nullptr. 2984 */ 2985 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 2986 EXPECT_NE(frameNode, nullptr); 2987 2988 /** 2989 * @tc.steps: step2. test GetJSCustomProperty. 2990 * @tc.expected: expect false. 2991 */ 2992 const std::string key = "testKey"; 2993 std::string value = "testValue"; 2994 auto hasKey = frameNode->GetJSCustomProperty(key, value); 2995 2996 EXPECT_FALSE(hasKey); 2997 } 2998 2999 /** 3000 * @tc.name: FrameNodeGetJSCustomProperty002 3001 * @tc.desc: Test GetJSCustomProperty 3002 * @tc.type: FUNC 3003 */ 3004 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty002, TestSize.Level1) 3005 { 3006 /** 3007 * @tc.steps: step1. create frameNode. 3008 * @tc.expected: expect is not nullptr. 3009 */ 3010 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 3011 EXPECT_NE(frameNode, nullptr); 3012 3013 /** 3014 * @tc.steps: step2. set getCustomProperty_ value test. 3015 * @tc.expected: expect result value test. 3016 */ __anon78b9b8441b02() 3017 std::function<bool()> func = []() -> bool { return true; }; __anon78b9b8441c02(const std::string& key) 3018 std::function<std::string(const std::string&)> getFunc = [](const std::string& key) -> std::string { 3019 return "test";}; 3020 frameNode->SetJSCustomProperty(func, getFunc); 3021 3022 /** 3023 * @tc.steps: step2. test GetJSCustomProperty. 3024 * @tc.expected: expect true. 3025 */ 3026 const std::string key = "testKey"; 3027 std::string value = "testValue"; 3028 frameNode->SetCustomPropertyMapFlagByKey("testKey"); 3029 auto hasKey = frameNode->GetJSCustomProperty(key, value); 3030 3031 EXPECT_TRUE(hasKey); 3032 EXPECT_EQ(value, "test"); 3033 } 3034 3035 /** 3036 * @tc.name: FrameNodeGetCapiCustomProperty001 3037 * @tc.desc: Test GetCapiCustomProperty. 3038 * @tc.type: FUNC 3039 */ 3040 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty001, TestSize.Level1) 3041 { 3042 /** 3043 * @tc.steps: step1. create frameNode. 3044 * @tc.expected: expect is not nullptr. 3045 */ 3046 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 3047 EXPECT_NE(frameNode, nullptr); 3048 3049 /** 3050 * @tc.steps: step2. GetCapiCustomProperty 3051 * @tc.expected: expect result value false. 3052 */ 3053 frameNode->setIsCNode(false); 3054 std::string value; 3055 bool hasKey = frameNode->GetCapiCustomProperty("key", value); 3056 EXPECT_FALSE(hasKey); 3057 } 3058 3059 /** 3060 * @tc.name: FrameNodeGetCapiCustomProperty002 3061 * @tc.desc: Test GetCapiCustomProperty. 3062 * @tc.type: FUNC 3063 */ 3064 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty002, TestSize.Level1) 3065 { 3066 /** 3067 * @tc.steps: step1. create frameNode. 3068 * @tc.expected: expect is not nullptr. 3069 */ 3070 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 3071 EXPECT_NE(frameNode, nullptr); 3072 3073 /** 3074 * @tc.steps: step2. GetCapiCustomProperty. 3075 * @tc.expected: expect result true. 3076 */ 3077 frameNode->setIsCNode(true); 3078 frameNode->AddCustomProperty("key", "value"); 3079 std::string value; 3080 bool result = frameNode->GetCapiCustomProperty("key", value); 3081 EXPECT_TRUE(result); 3082 EXPECT_EQ(value, "value"); 3083 } 3084 3085 /** 3086 * @tc.name: FrameNodeSetCustomPropertyMapFlagByKey001 3087 * @tc.desc: Test SetCustomPropertyMapFlagByKey. 3088 * @tc.type: FUNC 3089 */ 3090 HWTEST_F(FrameNodeTestNg, FrameNodeSetCustomPropertyMapFlagByKey001, TestSize.Level1) 3091 { 3092 /** 3093 * @tc.steps: step1. create frameNode. 3094 * @tc.expected: expect is not nullptr. 3095 */ 3096 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true); 3097 EXPECT_NE(frameNode, nullptr); 3098 3099 /** 3100 * @tc.steps: step2. SetCustomPropertyMapFlagByKey. 3101 * @tc.expected: expect result true, value empty and flag 0. 3102 */ 3103 frameNode->setIsCNode(true); 3104 frameNode->SetCustomPropertyMapFlagByKey("key"); 3105 std::string value; 3106 bool result = frameNode->GetCapiCustomProperty("key", value); 3107 std::string flagValue = frameNode->customPropertyMap_["key"][1]; 3108 EXPECT_TRUE(result); 3109 EXPECT_EQ(value, ""); 3110 EXPECT_EQ(flagValue, "0"); 3111 3112 /** 3113 * @tc.steps: step2. SetCustomPropertyMapFlagByKey. 3114 * @tc.expected: expect result true, value not empty and flag right. 3115 */ 3116 frameNode->AddCustomProperty("key1", "value1"); 3117 std::string value1; 3118 bool result1 = frameNode->GetCapiCustomProperty("key1", value1); 3119 std::string flagValue1 = frameNode->customPropertyMap_["key1"][1]; 3120 EXPECT_TRUE(result1); 3121 EXPECT_EQ(value1, "value1"); 3122 EXPECT_EQ(flagValue1, "1"); 3123 frameNode->SetCustomPropertyMapFlagByKey("key1"); 3124 result1 = frameNode->GetCapiCustomProperty("key1", value1); 3125 flagValue1 = frameNode->customPropertyMap_["key1"][1]; 3126 EXPECT_TRUE(result1); 3127 EXPECT_EQ(value1, "value1"); 3128 EXPECT_EQ(flagValue1, "0"); 3129 } 3130 } // namespace OHOS::Ace::NG