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 16 #include "test/unittest/core/pipeline/pipeline_context_test_ng.h" 17 18 #define private public 19 #define protected public 20 #include "core/components_ng/pattern/button/button_event_hub.h" 21 #include "core/components_ng/pattern/navigation/navigation_pattern.h" 22 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h" 23 #include "test/mock/core/common/mock_container.h" 24 using namespace testing; 25 using namespace testing::ext; 26 27 namespace OHOS::Ace { 28 namespace NG { 29 /** 30 * @tc.name: PipelineContextTestNg036 31 * @tc.desc: Test RequestFocus. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg036, TestSize.Level1) 35 { 36 /** 37 * @tc.steps1: initialize parameters and make sure pointers are not null. 38 */ 39 ASSERT_NE(context_, nullptr); 40 ASSERT_NE(frameNode_, nullptr); 41 context_->rootNode_ = frameNode_; 42 auto eventHub = frameNode_->GetEventHub<EventHub>(); 43 ASSERT_NE(eventHub, nullptr); 44 auto focusHub = eventHub->GetOrCreateFocusHub(); 45 ASSERT_NE(focusHub, nullptr); 46 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId(); 47 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr); 48 49 /** 50 * @tc.steps2: set host_and call UpdateInspectorId. 51 * @tc.expect: focusNode is not null . 52 */ 53 eventHub->host_ = frameNode_1; 54 frameNode_1->UpdateInspectorId("123"); 55 auto focusNode = focusHub->GetChildFocusNodeById("123"); 56 ASSERT_NE(focusNode, nullptr); 57 58 /** 59 * @tc.steps3: change host_,focusType_,enabled_, 60 focusable_,parentFocusable_,currentFocus_ 61 */ 62 auto eventHub1 = frameNode_1->GetEventHub<EventHub>(); 63 eventHub1->host_ = nullptr; 64 focusHub->focusType_ = FocusType::NODE; 65 eventHub->enabled_ = true; 66 focusHub->focusable_ = true; 67 focusHub->parentFocusable_ = true; 68 focusHub->currentFocus_ = true; 69 70 /** 71 * @tc.steps4: change isSubPipeline_ and call RequestFocus with empty string 72 * @tc.expect: RequestFocus empty string return false. 73 */ 74 context_->isSubPipeline_ = true; 75 auto rt = context_->RequestFocus(""); 76 EXPECT_FALSE(rt); 77 78 /** 79 * @tc.steps4: change isSubPipeline_ and call RequestFocus with 123 80 * @tc.expect: RequestFocus 123 success. 81 */ 82 context_->isSubPipeline_ = true; 83 rt = context_->RequestFocus("123"); 84 EXPECT_TRUE(rt); 85 86 /** 87 * @tc.steps4: change isSubPipeline_ and call RequestFocus with empty string 88 * @tc.expect: RequestFocus empty string return false. 89 */ 90 context_->isSubPipeline_ = false; 91 rt = context_->RequestFocus(""); 92 EXPECT_FALSE(rt); 93 94 /** 95 * @tc.steps4: change isSubPipeline_ and call RequestFocus with 123 96 * @tc.expect: RequestFocus 123 success. 97 */ 98 context_->isSubPipeline_ = false; 99 rt = context_->RequestFocus("123"); 100 EXPECT_TRUE(rt); 101 } 102 103 /** 104 * @tc.name: PipelineContextTestNg037 105 * @tc.desc: Test ExecuteSurfaceChangedCallbacks. 106 * @tc.type: FUNC 107 */ 108 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg037, TestSize.Level1) 109 { 110 /** 111 * @tc.steps1: initialize parameters and make sure pointers are not null. 112 set flag and creat callback then set into surfaceChangedCallbackMap_. 113 call ExecuteSurfaceChangedCallbacks. 114 * @tc.expect: flag turns true. 115 */ 116 ASSERT_NE(context_, nullptr); 117 bool flag = false; 118 auto callback = [&flag](int32_t input_1, int32_t input_2, int32_t input_3, int32_t input_4, __anon230df7e10102(int32_t input_1, int32_t input_2, int32_t input_3, int32_t input_4, WindowSizeChangeReason type) 119 WindowSizeChangeReason type) { flag = !flag; }; 120 context_->surfaceChangedCallbackMap_[0] = callback; 121 context_->surfaceChangedCallbackMap_[1] = nullptr; 122 context_->ExecuteSurfaceChangedCallbacks(0, 0, WindowSizeChangeReason::ROTATION); 123 EXPECT_TRUE(flag); 124 } 125 126 /** 127 * @tc.name: PipelineContextTestNg038 128 * @tc.desc: Test FlushWindowSizeChangeCallback. 129 * @tc.type: FUNC 130 */ 131 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg038, TestSize.Level1) 132 { 133 /** 134 * @tc.steps1: initialize parameters and make sure pointers are not null. 135 set onWindowSizeChangeCallbacks_. 136 * @tc.expect: the value 314 has been erased. 137 */ 138 ASSERT_NE(context_, nullptr); 139 context_->onWindowSizeChangeCallbacks_.emplace_back(314); 140 ASSERT_NE(frameNode_, nullptr); 141 context_->onWindowSizeChangeCallbacks_.emplace_back(frameNode_->GetId()); 142 context_->FlushWindowSizeChangeCallback(0, 0, WindowSizeChangeReason::UNDEFINED); 143 EXPECT_EQ(context_->onWindowSizeChangeCallbacks_.size(), 2); 144 } 145 146 /** 147 * @tc.name: PipelineContextTestNg039 148 * @tc.desc: Test GetCurrentFrameInfo. 149 * @tc.type: FUNC 150 */ 151 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg039, TestSize.Level1) 152 { 153 /** 154 * @tc.steps1: initialize parameters and make sure pointers are not null. 155 set dumpFrameCount_ and dumpFrameInfos_. 156 * @tc.expect: the return value of GetCurrentFrameInfo is null. 157 */ 158 ASSERT_NE(context_, nullptr); 159 SystemProperties::dumpFrameCount_ = 1; 160 context_->dumpFrameInfos_.push_back({}); 161 auto rt = context_->GetCurrentFrameInfo(DEFAULT_UINT64_1, DEFAULT_UINT64_2); 162 context_->DumpPipelineInfo(); 163 EXPECT_NE(rt, nullptr); 164 } 165 166 /** 167 * @tc.name: PipelineContextTestNg041 168 * @tc.desc: Test the function OnLayoutCompleted. 169 * @tc.type: FUNC 170 */ 171 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg041, TestSize.Level1) 172 { 173 /** 174 * @tc.steps1: initialize parameters. 175 * @tc.expected: frontend-ptr is non-null. 176 */ 177 ContainerScope scope(DEFAULT_INSTANCE_ID); 178 ASSERT_NE(context_, nullptr); 179 auto frontend = AceType::MakeRefPtr<MockFrontend>(); 180 context_->weakFrontend_ = frontend; 181 182 /** 183 * @tc.steps2: test the function OnLayoutCompleted by TEST_TAG. 184 * @tc.expected: frontend componentId_ is TEST_TAG 185 */ 186 context_->OnLayoutCompleted(TEST_TAG); 187 EXPECT_EQ(frontend->GetComponentId(), TEST_TAG); 188 context_->weakFrontend_.Reset(); 189 } 190 191 /** 192 * @tc.name: PipelineContextTestNg042 193 * @tc.desc: Test the function OnDrawCompleted. 194 * @tc.type: FUNC 195 */ 196 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg042, TestSize.Level1) 197 { 198 /** 199 * @tc.steps1: initialize parameters. 200 * @tc.expected: frontend-ptr is non-null. 201 */ 202 203 ContainerScope scope(DEFAULT_INSTANCE_ID); 204 ASSERT_NE(context_, nullptr); 205 auto frontend = AceType::MakeRefPtr<MockFrontend>(); 206 context_->weakFrontend_ = frontend; 207 208 /** 209 * @tc.steps4: test the function OnDrawCompleted by TEST_TAG. 210 * @tc.expected: frontend componentId_ is TEST_TAG 211 */ 212 context_->OnDrawCompleted(TEST_TAG); 213 EXPECT_EQ(frontend->GetComponentId(), TEST_TAG); 214 context_->weakFrontend_.Reset(); 215 } 216 217 /** 218 * @tc.name: UITaskSchedulerTestNg001 219 * @tc.desc: Test FlushLayoutTask. 220 * @tc.type: FUNC 221 */ 222 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg001, TestSize.Level1) 223 { 224 /** 225 * @tc.steps1: Create taskScheduler. 226 */ 227 UITaskScheduler taskScheduler; 228 229 /** 230 * @tc.steps2: Create frameInfo and StartRecordFrameInfo. 231 */ 232 FrameInfo frameInfo; 233 taskScheduler.StartRecordFrameInfo(&frameInfo); 234 235 /** 236 * @tc.steps3: Create some frameNode. 237 */ 238 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr); 239 frameNode->SetInDestroying(); 240 auto frameNode2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr); 241 242 /** 243 * @tc.steps4: Calling FlushLayoutTask with no layout. 244 * @tc.expected: frame info not record. 245 */ 246 taskScheduler.FlushLayoutTask(false); 247 EXPECT_EQ(frameInfo.layoutInfos_.size(), 0); 248 249 /** 250 * @tc.steps5: add some layoutNode and recall FlushLayoutTask with false . 251 * @tc.expected: frame info not record. 252 */ 253 taskScheduler.AddDirtyLayoutNode(frameNode); 254 taskScheduler.AddDirtyLayoutNode(frameNode2); 255 taskScheduler.FlushLayoutTask(false); 256 EXPECT_EQ(frameInfo.layoutInfos_.size(), 1); 257 258 /** 259 * @tc.steps6: add layoutNode again and set isLayoutDirtyMarked_ true and recall FlushLayoutTask with false . 260 * @tc.expected: frame info record true frameInfo.layoutInfos_.size is 2. 261 */ 262 taskScheduler.AddDirtyLayoutNode(frameNode2); 263 frameNode2->isLayoutDirtyMarked_ = true; 264 taskScheduler.FlushLayoutTask(false); 265 EXPECT_EQ(frameInfo.layoutInfos_.size(), 2); 266 267 /** 268 * @tc.steps7: add layoutNode again and call FlushLayoutTask with true . 269 * @tc.expected: frame info record true frameInfo.layoutInfos_.size is 3. 270 */ 271 taskScheduler.AddDirtyLayoutNode(frameNode2); 272 frameNode2->isLayoutDirtyMarked_ = true; 273 taskScheduler.FlushLayoutTask(true); 274 EXPECT_EQ(frameInfo.layoutInfos_.size(), 3); 275 276 /** 277 * @tc.steps8: finish FinishRecordFrameInfo and do step7. 278 * @tc.expected: frame info stop record frameInfo.layoutInfos_.size is 3. 279 */ 280 taskScheduler.FinishRecordFrameInfo(); 281 taskScheduler.AddDirtyLayoutNode(frameNode2); 282 frameNode2->isLayoutDirtyMarked_ = true; 283 taskScheduler.FlushLayoutTask(true); 284 EXPECT_EQ(frameInfo.layoutInfos_.size(), 3); 285 } 286 287 /** 288 * @tc.name: UITaskSchedulerTestNg002 289 * @tc.desc: Test FlushAfterLayoutTask. 290 * @tc.type: FUNC 291 */ 292 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg002, TestSize.Level1) 293 { 294 /** 295 * @tc.steps1: Create taskScheduler. 296 */ 297 UITaskScheduler taskScheduler; 298 299 /** 300 * @tc.steps2: Call FlushAfterLayoutTask. 301 */ 302 taskScheduler.FlushAfterLayoutTask(); 303 304 /** 305 * @tc.steps3: Call AddAfterLayoutTask. 306 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 2. 307 */ __anon230df7e10202() 308 taskScheduler.AddAfterLayoutTask([]() {}); 309 taskScheduler.AddAfterLayoutTask(nullptr); 310 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 2); 311 312 /** 313 * @tc.steps4: Call FlushTaskWithCheck. 314 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 0. 315 */ 316 taskScheduler.FlushTaskWithCheck(); 317 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 0); 318 } 319 320 /** 321 * @tc.name: UITaskSchedulerTestNg003 322 * @tc.desc: Test FlushAfterLayoutTask. 323 * @tc.type: FUNC 324 */ 325 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg003, TestSize.Level1) 326 { 327 /** 328 * @tc.steps1: Create taskScheduler. 329 */ 330 UITaskScheduler taskScheduler; 331 332 /** 333 * @tc.steps2: Call FlushPredictTask. 334 */ 335 taskScheduler.FlushPredictTask(0); 336 337 /** 338 * @tc.steps3: Call AddPredictTask. 339 * @tc.expected: predictTask_ in the taskScheduler size is 2. 340 */ __anon230df7e10302(int64_t, bool) 341 taskScheduler.AddPredictTask([](int64_t, bool) {}); 342 taskScheduler.AddPredictTask(nullptr); 343 EXPECT_EQ(taskScheduler.predictTask_.size(), 2); 344 345 /** 346 * @tc.steps4: Call FlushPredictTask. 347 * @tc.expected: predictTask_ in the taskScheduler size is 0. 348 */ 349 taskScheduler.FlushPredictTask(0); 350 EXPECT_EQ(taskScheduler.predictTask_.size(), 0); 351 } 352 353 /** 354 * @tc.name: UITaskSchedulerTestNg004 355 * @tc.desc: Test NeedAdditionalLayout. 356 * @tc.type: FUNC 357 */ 358 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg004, TestSize.Level1) 359 { 360 /** 361 * @tc.steps1: Create taskScheduler. 362 */ 363 UITaskScheduler taskScheduler; 364 365 /** 366 * @tc.steps2: Create some frameNode and configure the required parameters. 367 */ 368 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr); 369 frameNode->layoutProperty_ = nullptr; 370 auto frameNode2 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 2, nullptr); 371 372 /** 373 * @tc.steps3: Call AddDirtyLayoutNode with different parameters. 374 * @tc.expected: NeedAdditionalLayout return false. 375 */ 376 taskScheduler.AddDirtyLayoutNode(frameNode); 377 taskScheduler.AddDirtyLayoutNode(frameNode2); 378 EXPECT_FALSE(taskScheduler.NeedAdditionalLayout()); 379 380 /** 381 * @tc.steps4: Create a appropriate node and recall AddDirtyLayoutNode. 382 * @tc.expected: NeedAdditionalLayout return true. 383 */ 384 auto frameNode3 = FrameNode::GetOrCreateFrameNode(TEST_TAG, 3, nullptr); 385 auto geometryTransition = AceType::MakeRefPtr<NG::GeometryTransition>("test", frameNode3); 386 geometryTransition->hasOutAnim_ = true; 387 geometryTransition->inNode_ = frameNode2; 388 geometryTransition->outNode_ = frameNode3; 389 frameNode3->GetLayoutProperty()->geometryTransition_ = geometryTransition; 390 taskScheduler.AddDirtyLayoutNode(frameNode3); 391 EXPECT_TRUE(taskScheduler.NeedAdditionalLayout()); 392 taskScheduler.CleanUp(); 393 } 394 395 /** 396 * @tc.name: UITaskSchedulerTestNg005 397 * @tc.desc: Test FlushRenderTask. 398 * @tc.type: FUNC 399 */ 400 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg005, TestSize.Level1) 401 { 402 /** 403 * @tc.steps1: Create taskScheduler. 404 */ 405 UITaskScheduler taskScheduler; 406 407 /** 408 * @tc.steps2: Create frameInfo and StartRecordFrameInfo. 409 */ 410 FrameInfo frameInfo; 411 taskScheduler.StartRecordFrameInfo(&frameInfo); 412 413 /** 414 * @tc.steps3: Create some frameNode. 415 */ 416 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, 1, nullptr); 417 frameNode->SetInDestroying(); 418 taskScheduler.dirtyRenderNodes_[1].emplace(nullptr); 419 auto pattern = AceType::MakeRefPtr<Pattern>(); 420 auto frameNode2 = FrameNode::CreateFrameNode(TEST_TAG, 2, pattern); 421 422 /** 423 * @tc.steps4: Calling FlushRenderTask with no layout. 424 * @tc.expected: frame info not record. 425 */ 426 taskScheduler.FlushRenderTask(false); 427 428 /** 429 * @tc.steps5: add some layoutNode and recall FlushRenderTask with false . 430 * @tc.expected: frame info not record. 431 */ 432 taskScheduler.AddDirtyRenderNode(frameNode); 433 taskScheduler.AddDirtyRenderNode(frameNode2); 434 taskScheduler.FlushRenderTask(false); 435 EXPECT_EQ(frameInfo.renderInfos_.size(), 0); 436 } 437 438 /** 439 * @tc.name: UITaskSchedulerTestNg002 440 * @tc.desc: Test FlushAfterLayoutTask. 441 * @tc.type: FUNC 442 */ 443 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg006, TestSize.Level1) 444 { 445 /** 446 * @tc.steps1: Create taskScheduler. 447 */ 448 UITaskScheduler taskScheduler; 449 450 /** 451 * @tc.steps2: Call FlushAfterLayoutTask. 452 */ 453 taskScheduler.FlushAfterLayoutTask(); 454 455 /** 456 * @tc.steps3: Call AddAfterLayoutTask. 457 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 2. 458 */ __anon230df7e10402() 459 taskScheduler.AddPersistAfterLayoutTask([]() {}); 460 taskScheduler.AddPersistAfterLayoutTask(nullptr); 461 EXPECT_EQ(taskScheduler.persistAfterLayoutTasks_.size(), 2); 462 463 /** 464 * @tc.steps4: Call FlushTaskWithCheck. 465 * @tc.expected: afterLayoutTasks_ in the taskScheduler size is 0. 466 */ 467 taskScheduler.FlushTaskWithCheck(); 468 EXPECT_EQ(taskScheduler.afterLayoutTasks_.size(), 0); 469 } 470 471 /** 472 * @tc.name: PipelineContextTestNg044 473 * @tc.desc: Test the function FlushAnimation. 474 * @tc.type: FUNC 475 */ 476 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg044, TestSize.Level1) 477 { 478 /** 479 * @tc.steps1: initialize parameters. 480 * @tc.expected: All pointer is non-null. 481 */ 482 ASSERT_NE(context_, nullptr); 483 484 /** 485 * @tc.steps2: Call the function FlushAnimation with unempty scheduleTasks_. 486 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP. 487 */ 488 auto scheduleTask = AceType::MakeRefPtr<MockScheduleTask>(); 489 EXPECT_NE(scheduleTask->GetNanoTimestamp(), NANO_TIME_STAMP); 490 491 /** 492 * @tc.steps3: Call the function AddScheduleTask. 493 * @tc.expected: The scheduleTasks_ has the task id. 494 */ 495 auto id = context_->AddScheduleTask(scheduleTask); 496 EXPECT_EQ(context_->scheduleTasks_.count(id), 1); 497 498 /** 499 * @tc.steps4: Call the function RemoveScheduleTask. 500 * @tc.expected: The scheduleTasks_ does not have the task id. 501 */ 502 context_->RemoveScheduleTask(id); 503 EXPECT_EQ(context_->scheduleTasks_.count(id), 0); 504 } 505 506 /** 507 * @tc.name: PipelineContextTestNg045 508 * @tc.desc: Test the function FlushAnimation. 509 * @tc.type: FUNC 510 */ 511 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg045, TestSize.Level1) 512 { 513 /** 514 * @tc.steps1: initialize parameters. 515 * @tc.expected: All pointer is non-null. 516 */ 517 ASSERT_NE(context_, nullptr); 518 ASSERT_TRUE(context_->needRenderNode_.empty()); 519 /** 520 * @tc.steps2: Call the function FlushAnimation with unempty scheduleTasks_. 521 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP. 522 */ 523 auto pattern = AceType::MakeRefPtr<Pattern>(); 524 auto frameNode = FrameNode::CreateFrameNode(TEST_TAG, 3, pattern); 525 context_->SetNeedRenderNode(WeakPtr<FrameNode>(frameNode)); 526 EXPECT_EQ(context_->needRenderNode_.count(WeakPtr<FrameNode>(frameNode)), 1); 527 528 /** 529 * @tc.steps3: Call the function FlushPipelineImmediately. 530 * @tc.expected: The nanoTimestamp of scheduleTask is equal to NANO_TIME_STAMP. 531 */ 532 context_->FlushPipelineImmediately(); 533 EXPECT_TRUE(context_->isRebuildFinished_); 534 } 535 536 /** 537 * @tc.name: PipelineContextTestNg046 538 * @tc.desc: Test the function AddAnimationClosure and FlushAnimationClosure. 539 * @tc.type: FUNC 540 */ 541 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg046, TestSize.Level1) 542 { 543 /** 544 * @tc.steps1: initialize parameters. 545 * @tc.expected: All pointer is non-null. 546 */ 547 ASSERT_NE(context_, nullptr); 548 /** 549 * @tc.steps2: call AddAnimationClosure. 550 * @tc.expected: The animationClosuresList_ has 1 element. 551 */ __anon230df7e10502() 552 auto mockAnimation = []() -> void {}; 553 context_->AddAnimationClosure(mockAnimation); 554 EXPECT_EQ(context_->animationClosuresList_.size(), 1); 555 /** 556 * @tc.steps3: call FlushAnimationClosure. 557 * @tc.expected: The animationClosuresList_ has 1 element. 558 */ 559 context_->FlushAnimationClosure(); 560 EXPECT_TRUE(context_->animationClosuresList_.empty()); 561 } 562 563 /** 564 * @tc.name: PipelineContextTestNg046 565 * @tc.desc: Test the function GetStageManager. 566 * @tc.type: FUNC 567 */ 568 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg047, TestSize.Level1) 569 { 570 /** 571 * @tc.steps1: initialize parameters. 572 * @tc.expected: All pointer is non-null. 573 */ 574 ASSERT_NE(context_, nullptr); 575 /** 576 * @tc.steps2: call GetStageManager. 577 * @tc.expected: The stageManager is not null. 578 */ 579 context_->SetupRootElement(); 580 auto stageManager = context_->GetStageManager(); 581 EXPECT_NE(stageManager, nullptr); 582 } 583 584 /** 585 * @tc.name: PipelineContextTestNg048 586 * @tc.desc: Test the function GetSelectOverlayManager. 587 * @tc.type: FUNC 588 */ 589 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg048, TestSize.Level1) 590 { 591 /** 592 * @tc.steps1: initialize parameters. 593 * @tc.expected: All pointer is non-null. 594 */ 595 ASSERT_NE(context_, nullptr); 596 /** 597 * @tc.steps2: call SetupRootElement. 598 * @tc.expected: The selectOverlayManager is not null. 599 */ 600 context_->SetupRootElement(); 601 auto selectOverlayManager = context_->GetSelectOverlayManager(); 602 EXPECT_NE(selectOverlayManager, nullptr); 603 } 604 605 /** 606 * @tc.name: PipelineContextTestNg049 607 * @tc.desc: Test the function GetFullScreenManager. 608 * @tc.type: FUNC 609 */ 610 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg049, TestSize.Level1) 611 { 612 /** 613 * @tc.steps1: initialize parameters. 614 * @tc.expected: All pointer is non-null. 615 */ 616 ASSERT_NE(context_, nullptr); 617 /** 618 * @tc.steps2: call GetFullScreenManager. 619 * @tc.expected: The fullScreenManager is not null. 620 */ 621 context_->SetupRootElement(); 622 auto fullScreenManager = context_->GetFullScreenManager(); 623 EXPECT_NE(fullScreenManager, nullptr); 624 } 625 626 /** 627 * @tc.name: PipelineContextTestNg050 628 * @tc.desc: Test the function UpdateSystemSafeArea and UpdateCutoutSafeArea. 629 * @tc.type: FUNC 630 */ 631 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg050, TestSize.Level1) 632 { 633 /** 634 * @tc.steps1: initialize parameters. 635 * @tc.expected: All pointer is non-null. 636 */ 637 ASSERT_NE(context_, nullptr); 638 /** 639 * @tc.steps2: call AddAnimationClosure. 640 * @tc.expected: The GetFullScreenManager is not null. 641 */ 642 context_->SetMinPlatformVersion(10); 643 SafeAreaInsets::Inset left { 0, 1 }; 644 SafeAreaInsets::Inset top { 0, 2 }; 645 SafeAreaInsets::Inset right { 0, 3 }; 646 SafeAreaInsets::Inset bottom { 0, 4 }; 647 SafeAreaInsets safeAreaInsets(left, top, right, bottom); 648 context_->UpdateSystemSafeArea(safeAreaInsets); 649 EXPECT_EQ(context_->safeAreaManager_->systemSafeArea_, safeAreaInsets); 650 651 context_->UpdateCutoutSafeArea(safeAreaInsets); 652 EXPECT_NE(context_->safeAreaManager_->cutoutSafeArea_, safeAreaInsets); 653 654 context_->UpdateNavSafeArea(safeAreaInsets); 655 656 EXPECT_EQ(context_->safeAreaManager_->navSafeArea_, safeAreaInsets); 657 658 context_->SetIsLayoutFullScreen(true); 659 context_->SetIsLayoutFullScreen(false); 660 context_->SetIsNeedAvoidWindow(true); 661 context_->SetIsNeedAvoidWindow(false); 662 EXPECT_TRUE(context_->IsEnableKeyBoardAvoidMode()); 663 } 664 665 /** 666 * @tc.name: PipelineContextTestNg051 667 * @tc.desc: Test the function SetIgnoreViewSafeArea. 668 * @tc.type: FUNC 669 */ 670 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg051, TestSize.Level1) 671 { 672 /** 673 * @tc.steps1: initialize parameters. 674 * @tc.expected: All pointer is non-null. 675 */ 676 ASSERT_NE(context_, nullptr); 677 /** 678 * @tc.steps2: call SetIgnoreViewSafeArea. 679 * @tc.expected: The ignoreSafeArea_ is true. 680 */ 681 context_->safeAreaManager_->ignoreSafeArea_ = false; 682 context_->SetIgnoreViewSafeArea(true); 683 EXPECT_TRUE(context_->safeAreaManager_->ignoreSafeArea_); 684 } 685 686 /** 687 * @tc.name: PipelineContextTestNg052 688 * @tc.desc: Test the function SyncSafeArea. 689 * @tc.type: FUNC 690 */ 691 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg052, TestSize.Level1) 692 { 693 /** 694 * @tc.steps1: initialize parameters. 695 * @tc.expected: All pointer is non-null. 696 */ 697 ASSERT_NE(context_, nullptr); 698 /** 699 * @tc.steps2: call SyncSafeArea. 700 * @tc.expected: The isLayoutDirtyMarked_ is true. 701 */ 702 context_->SetupRootElement(); 703 auto frameNodeId = ElementRegister::GetInstance()->MakeUniqueId(); 704 auto frameNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId, nullptr); 705 context_->safeAreaManager_->AddGeoRestoreNode(frameNode); 706 context_->SyncSafeArea(SafeAreaSyncType::SYNC_TYPE_NONE); 707 EXPECT_TRUE(frameNode->isLayoutDirtyMarked_); 708 } 709 710 /** 711 * @tc.name: PipelineContextTestNg053 712 * @tc.desc: Test the function FindNavigationNodeToHandleBack. 713 * @tc.type: FUNC 714 */ 715 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg053, TestSize.Level1) 716 { 717 /** 718 * @tc.steps1: initialize parameters. 719 * @tc.expected: All pointer is non-null. 720 */ 721 ASSERT_NE(context_, nullptr); 722 /** 723 * @tc.steps2: call FindNavigationNodeToHandleBack. 724 * @tc.expected: The ret is nullptr. 725 */ 726 context_->SetupRootElement(); 727 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId(); 728 auto navigationStack = AceType::MakeRefPtr<NavigationStack>(); 729 auto node = NavigationGroupNode::GetOrCreateGroupNode( __anon230df7e10602() 730 TEST_TAG, nodeId, []() { return AceType::MakeRefPtr<NavigationPattern>(); }); 731 node->GetPattern<NavigationPattern>()->SetNavigationStack(std::move(navigationStack)); 732 auto childId = ElementRegister::GetInstance()->MakeUniqueId(); 733 auto childNode = NavigationGroupNode::GetOrCreateGroupNode( __anon230df7e10702() 734 TEST_TAG, childId, []() { return AceType::MakeRefPtr<NavigationPattern>(); }); 735 childNode->GetPattern<NavigationPattern>()->SetNavigationStack(std::move(navigationStack)); 736 node->AddChild(childNode); 737 context_->GetNavigationController(std::to_string(nodeId)); 738 context_->AddOrReplaceNavigationNode(std::to_string(childId), AceType::WeakClaim(AceType::RawPtr(childNode))); 739 context_->DeleteNavigationNode(std::to_string(childId)); 740 context_->AddNavigationNode(nodeId, AceType::WeakClaim(AceType::RawPtr(node))); 741 context_->RemoveNavigationNode(nodeId, nodeId); 742 context_->FirePageChanged(nodeId, false); 743 bool isEntry = false; 744 EXPECT_EQ(context_->FindNavigationNodeToHandleBack(node, isEntry), nullptr); 745 } 746 747 /** 748 * @tc.name: PipelineContextTestNg054 749 * @tc.desc: Test the function AddAfterLayoutTask and AddAfterRenderTask. 750 * @tc.type: FUNC 751 */ 752 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg054, TestSize.Level1) 753 { 754 /** 755 * @tc.steps1: initialize parameters. 756 * @tc.expected: All pointer is non-null. 757 */ 758 ASSERT_NE(context_, nullptr); 759 /** 760 * @tc.steps2: call AddAfterLayoutTask. 761 * @tc.expected: The afterLayoutTasks_ size is 1. 762 */ 763 context_->SetupRootElement(); __anon230df7e10802() 764 context_->AddAfterLayoutTask([]() -> void {}); 765 EXPECT_EQ(context_->taskScheduler_->afterLayoutTasks_.size(), 1); 766 /** 767 * @tc.steps3: call AddAfterLayoutTask. 768 * @tc.expected: The afterLayoutTasks_ size is 1. 769 */ __anon230df7e10902() 770 context_->AddAfterRenderTask([]() -> void {}); 771 EXPECT_EQ(context_->taskScheduler_->afterRenderTasks_.size(), 1); 772 } 773 774 /** 775 * @tc.name: PipelineContextTestNg055 776 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG. 777 * @tc.type: FUNC 778 */ 779 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg055, TestSize.Level1) 780 { 781 /** 782 * @tc.steps1: initialize parameters. 783 * @tc.expected: All pointer is non-null. 784 */ 785 ASSERT_NE(context_, nullptr); 786 /** 787 * @tc.steps2: call AddFontNodeNG. 788 * @tc.expected: fontNodesNG_.size() is 1. 789 */ 790 context_->SetupRootElement(); 791 context_->fontManager_ = AceType::MakeRefPtr<MockFontManager>(); 792 auto fontNodeId = ElementRegister::GetInstance()->MakeUniqueId(); 793 auto fontNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, fontNodeId, nullptr); 794 context_->AddFontNodeNG(fontNode); 795 EXPECT_EQ(context_->GetFontManager()->fontNodesNG_.size(), 1); 796 /** 797 * @tc.steps2: call RemoveFontNodeNG. 798 * @tc.expected: fontNodesNG_.size() is 0. 799 */ 800 context_->RemoveFontNodeNG(fontNode); 801 EXPECT_EQ(context_->GetFontManager()->fontNodesNG_.size(), 0); 802 } 803 804 /** 805 * @tc.name: PipelineContextTestNg056 806 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG. 807 * @tc.type: FUNC 808 */ 809 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg056, TestSize.Level1) 810 { 811 /** 812 * @tc.steps1: initialize parameters. 813 * @tc.expected: All pointer is non-null. 814 */ 815 ASSERT_NE(context_, nullptr); 816 /** 817 * @tc.steps2: call IsWindowSceneConsumed. 818 * @tc.expected: The return is false. 819 */ 820 context_->SetupRootElement(); 821 EXPECT_FALSE(context_->IsWindowSceneConsumed()); 822 /** 823 * @tc.steps2: call SetWindowSceneConsumed(true) and IsWindowSceneConsumed. 824 * @tc.expected: The return is true. 825 */ 826 context_->SetWindowSceneConsumed(true); 827 EXPECT_TRUE(context_->IsWindowSceneConsumed()); 828 } 829 830 /** 831 * @tc.name: PipelineContextTestNg057 832 * @tc.desc: Test the function AddFontNodeNG and RemoveFontNodeNG. 833 * @tc.type: FUNC 834 */ 835 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg057, TestSize.Level1) 836 { 837 /** 838 * @tc.steps1: initialize parameters. 839 * @tc.expected: All pointer is non-null. 840 */ 841 ASSERT_NE(context_, nullptr); 842 843 auto needRenderNodeId = ElementRegister::GetInstance()->MakeUniqueId(); 844 auto needRenderNode = FrameNode::GetOrCreateFrameNode(TEST_TAG, needRenderNodeId, nullptr); 845 context_->SetNeedRenderNode(WeakPtr<FrameNode>(needRenderNode)); 846 EXPECT_EQ(context_->needRenderNode_.count(WeakPtr<FrameNode>(needRenderNode)), 1); 847 context_->InspectDrew(); 848 EXPECT_EQ(context_->needRenderNode_.count(WeakPtr<FrameNode>(needRenderNode)), 0); 849 } 850 851 /** 852 * @tc.name: PipelineContextTestNg058 853 * @tc.desc: Test the function FlushMouseEventG. 854 * @tc.type: FUNC 855 */ 856 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg058, TestSize.Level1) 857 { 858 /** 859 * @tc.steps1: initialize parameters. 860 * @tc.expected: pointer is non-null. 861 */ 862 ASSERT_NE(context_, nullptr); 863 864 /** 865 * @tc.steps2: Call the function FlushMouseEvent with default action. 866 * @tc.expected: The function is called and cover branch mouseAction is not WINDOW_LEAVE. 867 */ 868 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(); 869 context_->FlushMouseEvent(); 870 auto result = context_->lastMouseEvent_->action == MouseAction::WINDOW_LEAVE; 871 EXPECT_FALSE(result); 872 873 /** 874 * @tc.steps3: Call the function FlushMouseEvent with lastMouseEvent_ is nullptr. 875 * @tc.expected: The function is called and cover branch lastMouseEvent_ is nullptr. 876 */ 877 context_->lastMouseEvent_ = nullptr; 878 context_->FlushMouseEvent(); 879 EXPECT_EQ(context_->lastMouseEvent_, nullptr); 880 881 /** 882 * @tc.steps4: Call the function FlushMouseEvent with mouseAction is WINDOW_LEAVE. 883 * @tc.expected: The function is called and cover branch mouseAction is WINDOW_LEAVE. 884 */ 885 context_->lastMouseEvent_ = std::make_unique<MouseEvent>(); 886 context_->lastMouseEvent_->action = MouseAction::WINDOW_LEAVE; 887 context_->FlushMouseEvent(); 888 result = context_->lastMouseEvent_->action == MouseAction::WINDOW_LEAVE; 889 EXPECT_TRUE(result); 890 } 891 892 /** 893 * @tc.name: PipelineContextTestNg059 894 * @tc.desc: Test the function OnIdle. 895 * @tc.type: FUNC 896 */ 897 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg059, TestSize.Level1) 898 { 899 /** 900 * @tc.steps1: initialize parameters. 901 * @tc.expected: All pointer is non-null. 902 */ 903 ASSERT_NE(context_, nullptr); 904 905 /** 906 * @tc.steps2: Call the function OnIdle with canUseLongPredictTask_. 907 * @tc.expected: called OnIdle and cover branch canUseLongPredictTask_ is true. 908 */ 909 context_->canUseLongPredictTask_ = true; 910 context_->OnIdle(1); 911 EXPECT_TRUE(context_->touchEvents_.empty()); 912 913 /** 914 * @tc.steps3: Call the function OnIdle with touchEvents_ is not empty. 915 * @tc.expected: The value of flagCbk changed. 916 */ 917 bool flagCbk = false; __anon230df7e10a02(int64_t, bool) 918 context_->AddPredictTask([&flagCbk](int64_t, bool) { flagCbk = true; }); 919 TouchEvent event; 920 event.id = RENDER_EVENT_ID; 921 context_->touchEvents_.push_back(event); 922 context_->canUseLongPredictTask_ = true; 923 context_->OnIdle(2); 924 EXPECT_TRUE(flagCbk); 925 } 926 927 /** 928 * @tc.name: PipelineContextTestNg062 929 * @tc.desc: Test the function SetCursor. 930 * @tc.type: FUNC 931 */ 932 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg062, TestSize.Level1) 933 { 934 /** 935 * @tc.steps1: initialize parameters. 936 * @tc.expected: All pointer is non-null. 937 */ 938 ASSERT_NE(context_, nullptr); 939 ASSERT_NE(context_->GetWindow(), nullptr); 940 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT); 941 942 /** 943 * @tc.steps2: set cursor with an exceptional value. 944 * @tc.expected: context_->cursor_ is MouseFormat::DEFAULT. 945 */ 946 context_->SetCursor(EXCEPTIONAL_CURSOR); 947 ASSERT_NE(context_->GetWindow(), nullptr); 948 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT); 949 950 /** 951 * @tc.steps3: set cursor with a normal value. 952 * @tc.expected: context_->cursor_ is correct value. 953 */ 954 context_->SetCursor(static_cast<int32_t>(MouseFormat::EAST)); 955 ASSERT_NE(context_->GetWindow(), nullptr); 956 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::EAST); 957 958 /** 959 * @tc.steps4: restore mouse style. 960 * @tc.expected: context_->cursor_ is MouseFormat::DEFAULT. 961 */ 962 context_->RestoreDefault(); 963 ASSERT_NE(context_->GetWindow(), nullptr); 964 ASSERT_EQ(context_->GetWindow()->cursor_, MouseFormat::DEFAULT); 965 } 966 967 /** 968 * @tc.name: PipelineContextTestNg063 969 * @tc.desc: Test the function OpenFrontendAnimation and CloseFrontendAnimation. 970 * @tc.type: FUNC 971 */ 972 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg063, TestSize.Level1) 973 { 974 decltype(context_->pendingFrontendAnimation_) temp; 975 std::swap(context_->pendingFrontendAnimation_, temp); 976 /** 977 * @tc.steps1: Call CloseFrontAnimation directly. 978 * @tc.expected: No animation is generated. The pending flag stack is empty. 979 */ 980 context_->CloseFrontendAnimation(); 981 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0); 982 /** 983 * @tc.steps2: Call OpenFrontendAnimation. 984 * @tc.expected: A pending flag is pushed to the stack. 985 */ 986 AnimationOption option(Curves::EASE, 1000); 987 context_->OpenFrontendAnimation(option, option.GetCurve(), nullptr); 988 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 1); 989 /** 990 * @tc.steps3: Call CloseFrontendAnimation after OpenFrontendAnimation. 991 * @tc.expected: The pending flag is out of stack. 992 */ 993 context_->CloseFrontendAnimation(); 994 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0); 995 } 996 997 /** 998 * @tc.name: PipelineContextTestNg064 999 * @tc.desc: Test history and current. 1000 * @tc.type: FUNC 1001 */ 1002 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg064, TestSize.Level1) 1003 { 1004 /** 1005 * @tc.steps1: history and current timestamps are equal to nanoTimeStamp 1006 * @tc.expected: Expect the result to be (0.0, 0.0) 1007 */ 1008 std::tuple<float, float, uint64_t> history_fs = std::make_tuple(1.0f, 1.0f, 1000); 1009 std::tuple<float, float, uint64_t> current_fs = std::make_tuple(2.0f, 2.0f, 2000); 1010 uint64_t nanoTimeStampFs = 1000; 1011 auto result_fs = context_->LinearInterpolation(history_fs, current_fs, nanoTimeStampFs); 1012 EXPECT_EQ(result_fs, std::make_tuple(0.0f, 0.0f, 0.0f, 0.0f)); 1013 1014 /** 1015 * @tc.steps2: history and current timestamps are equal to nanoTimeStamp 1016 * @tc.expected: Expect the result to be (0.0, 0.0) 1017 */ 1018 std::tuple<float, float, uint64_t> history_se = std::make_tuple(1.0f, 1.0f, 2000); 1019 std::tuple<float, float, uint64_t> current_se = std::make_tuple(2.0f, 2.0f, 1000); 1020 uint64_t nanoTimeStampSe = 1500; 1021 auto result_se = context_->LinearInterpolation(history_se, current_se, nanoTimeStampSe); 1022 EXPECT_EQ(result_se, std::make_tuple(0.0f, 0.0f, 0.0f, 0.0f)); 1023 1024 /** 1025 * @tc.steps3: history and current timestamps are equal to nanoTimeStamp 1026 * @tc.expected: Expect the result to be (1.75, 1.75) 1027 */ 1028 std::tuple<float, float, uint64_t> history_th = std::make_tuple(1.0f, 1.0f, 1000); 1029 std::tuple<float, float, uint64_t> current_th = std::make_tuple(2.0f, 2.0f, 3000); 1030 uint64_t nanoTimeStampTh = 2500; 1031 auto result_th = context_->LinearInterpolation(history_th, current_th, nanoTimeStampTh); 1032 EXPECT_EQ(result_th, std::make_tuple(1.75f, 1.75f, 500000.0f, 500000.0f)); 1033 1034 /** 1035 * @tc.steps4: nanoTimeStamp is less than history timestamp 1036 * @tc.expected: Expect the result to be (0.0, 0.0) 1037 */ 1038 std::tuple<float, float, uint64_t> history_for = std::make_tuple(1.0f, 1.0f, 1000); 1039 std::tuple<float, float, uint64_t> current_for = std::make_tuple(2.0f, 2.0f, 2000); 1040 uint64_t nanoTimeStampFor = 500; 1041 auto result_for = context_->LinearInterpolation(history_for, current_for, nanoTimeStampFor); 1042 EXPECT_EQ(result_for, std::make_tuple(0.0f, 0.0f, 0.0f, 0.0f)); 1043 1044 /** 1045 * @tc.steps5: nanoTimeStamp is less than current timestamp 1046 * @tc.expected: Expect non-zero value 1047 */ 1048 std::tuple<float, float, uint64_t> history_fie = std::make_tuple(1.0f, 1.0f, 1000); 1049 std::tuple<float, float, uint64_t> current_fie = std::make_tuple(2.0f, 2.0f, 2000); 1050 uint64_t nanoTimeStampFie = 1500; 1051 auto result_fie = context_->LinearInterpolation(history_fie, current_fie, nanoTimeStampFie); 1052 EXPECT_NE(result_fie, std::make_tuple(0.0f, 0.0f, 0.0f, 0.0f)); 1053 1054 /** 1055 * @tc.steps6: nanoTimeStamp is greater than current timestamp 1056 * @tc.expected: Expect non-zero value 1057 */ 1058 std::tuple<float, float, uint64_t> history_six = std::make_tuple(1.0f, 1.0f, 1000); 1059 std::tuple<float, float, uint64_t> current_six = std::make_tuple(2.0f, 2.0f, 2000); 1060 uint64_t nanoTimeStampSix = 2500; 1061 auto result_six = context_->LinearInterpolation(history_six, current_six, nanoTimeStampSix); 1062 EXPECT_NE(result_six, std::make_tuple(0.0f, 0.0f, 0.0f, 0.0f)); 1063 } 1064 1065 /** 1066 * @tc.name: PipelineContextTestNg065 1067 * @tc.desc: Test history and current. 1068 * @tc.type: FUNC 1069 */ 1070 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg065, TestSize.Level1) 1071 { 1072 /** 1073 * @tc.steps1: GetResampleCoord illegal value verification 1074 * @tc.expected: All result is 0.0f. 1075 */ 1076 std::vector<TouchEvent> emptyHistory; 1077 std::vector<TouchEvent> emptyCurrent; 1078 uint64_t nanoTimeStamp = 1234567890; 1079 bool isScreen = true; 1080 std::tuple<float, float, float, float> result = 1081 context_->GetResampleCoord(emptyHistory, emptyCurrent, nanoTimeStamp, isScreen); 1082 EXPECT_FLOAT_EQ(0.0f, std::get<0>(result)); 1083 EXPECT_FLOAT_EQ(0.0f, std::get<1>(result)); 1084 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1085 emptyHistory.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1086 result = context_->GetResampleCoord(emptyHistory, emptyCurrent, nanoTimeStamp, isScreen); 1087 EXPECT_FLOAT_EQ(0.0f, std::get<0>(result)); 1088 EXPECT_FLOAT_EQ(0.0f, std::get<1>(result)); 1089 emptyHistory.clear(); 1090 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1091 emptyCurrent.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampTwo)); 1092 result = context_->GetResampleCoord(emptyHistory, emptyCurrent, nanoTimeStamp, isScreen); 1093 EXPECT_FLOAT_EQ(0.0f, std::get<0>(result)); 1094 EXPECT_FLOAT_EQ(0.0f, std::get<1>(result)); 1095 } 1096 1097 /** 1098 * @tc.name: PipelineContextTestNg066 1099 * @tc.desc: Test history and current. 1100 * @tc.type: FUNC 1101 */ 1102 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg066, TestSize.Level1) 1103 { 1104 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1105 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1106 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1107 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(2000)); 1108 std::vector<TouchEvent> history; 1109 history.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1110 history.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1111 std::vector<TouchEvent> current; 1112 current.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampThree)); 1113 current.push_back(TouchEvent {}.SetX(250.0f).SetY(350.0f).SetTime(timeStampFour)); 1114 1115 auto resampledCoord = context_->GetResampleCoord(history, current, 30000000, true); 1116 1117 ASSERT_FLOAT_EQ(200.0f, std::get<0>(resampledCoord)); 1118 ASSERT_FLOAT_EQ(300.0f, std::get<1>(resampledCoord)); 1119 1120 SystemProperties::debugEnabled_ = true; 1121 resampledCoord = context_->GetResampleCoord(history, current, 2500, true); 1122 ASSERT_FLOAT_EQ(0.0f, std::get<0>(resampledCoord)); 1123 ASSERT_FLOAT_EQ(0.0f, std::get<1>(resampledCoord)); 1124 } 1125 1126 /** 1127 * @tc.name: PipelineContextTestNg068 1128 * @tc.desc: Test history and current. 1129 * @tc.type: FUNC 1130 */ 1131 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg068, TestSize.Level1) 1132 { 1133 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1134 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1135 std::vector<TouchEvent> current; 1136 current.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1137 current.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1138 uint64_t nanoTimeStamp = 1500; 1139 1140 TouchEvent latestPoint = context_->GetLatestPoint(current, nanoTimeStamp); 1141 1142 ASSERT_FLOAT_EQ(100.0f, latestPoint.x); 1143 ASSERT_FLOAT_EQ(200.0f, latestPoint.y); 1144 } 1145 1146 /** 1147 * @tc.name: PipelineContextTestNg069 1148 * @tc.desc: Test history and current. 1149 * @tc.type: FUNC 1150 */ 1151 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg069, TestSize.Level1) 1152 { 1153 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1154 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1155 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1156 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000)); 1157 std::vector<TouchEvent> history; 1158 history.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1159 history.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1160 std::vector<TouchEvent> current; 1161 current.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampThree)); 1162 current.push_back(TouchEvent {}.SetX(250.0f).SetY(350.0f).SetTime(timeStampFour)); 1163 uint64_t nanoTimeStamp = 2500; 1164 1165 TouchEvent resampledTouchEvent; 1166 context_->GetResampleTouchEvent(history, current, nanoTimeStamp, resampledTouchEvent); 1167 1168 ASSERT_FLOAT_EQ(175.0f, resampledTouchEvent.x); 1169 ASSERT_FLOAT_EQ(275.0f, resampledTouchEvent.y); 1170 } 1171 1172 /** 1173 * @tc.name: PipelineContextTestNg070 1174 * @tc.desc: Test GetLatestPoint. 1175 * @tc.type: FUNC 1176 */ 1177 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg070, TestSize.Level1) 1178 { 1179 std::vector<TouchEvent> events; 1180 1181 TouchEvent event; 1182 event.time = TimeStamp(std::chrono::nanoseconds(1000)); 1183 events.push_back(event); 1184 1185 TouchEvent result = context_->GetLatestPoint(events, 1000); 1186 ASSERT_EQ(static_cast<uint64_t>(result.time.time_since_epoch().count()), 1000); 1187 } 1188 1189 /** 1190 * @tc.name: PipelineContextTestNg071 1191 * @tc.desc: Test GetLatestPoint. 1192 * @tc.type: FUNC 1193 */ 1194 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg071, TestSize.Level1) 1195 { 1196 std::vector<TouchEvent> events; 1197 1198 TouchEvent eventAce; 1199 eventAce.time = TimeStamp(std::chrono::nanoseconds(2000)); 1200 events.push_back(eventAce); 1201 1202 TouchEvent eventTwo; 1203 eventTwo.time = TimeStamp(std::chrono::nanoseconds(3000)); 1204 events.push_back(eventTwo); 1205 1206 uint64_t nanoTimeStamp = 1500; 1207 1208 TouchEvent result = context_->GetLatestPoint(events, nanoTimeStamp); 1209 ASSERT_GT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp); 1210 } 1211 1212 /** 1213 * @tc.name: PipelineContextTestNg072 1214 * @tc.desc: Test GetLatestPoint. 1215 * @tc.type: FUNC 1216 */ 1217 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg072, TestSize.Level1) 1218 { 1219 std::vector<TouchEvent> events; 1220 1221 TouchEvent eventAce; 1222 eventAce.time = TimeStamp(std::chrono::nanoseconds(500)); 1223 events.push_back(eventAce); 1224 1225 TouchEvent eventTwo; 1226 eventTwo.time = TimeStamp(std::chrono::nanoseconds(1000)); 1227 events.push_back(eventTwo); 1228 1229 uint64_t nanoTimeStamp = 1500; 1230 1231 TouchEvent result = context_->GetLatestPoint(events, nanoTimeStamp); 1232 ASSERT_LT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp); 1233 } 1234 1235 /** 1236 * @tc.name: PipelineContextTestNg073 1237 * @tc.desc: Test the function GetSafeArea and GetSafeAreaWithoutProcess. 1238 * @tc.type: FUNC 1239 */ 1240 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg073, TestSize.Level1) 1241 { 1242 /** 1243 * @tc.steps1: initialize parameters. 1244 * @tc.expected: All pointer is non-null. 1245 */ 1246 ASSERT_NE(context_, nullptr); 1247 /** 1248 * @tc.steps2: call UpdateSystemSafeArea and SetIgnoreViewSafeArea, then check the value of GetSafeArea 1249 and GetSafeAreaWithoutProcess. 1250 * @tc.expected: The GetSafeArea is empty, and the GetSafeAreaWithoutProcess is systemSafeArea. 1251 */ 1252 SafeAreaInsets::Inset left { 0, 1 }; 1253 SafeAreaInsets::Inset top { 0, 2 }; 1254 SafeAreaInsets::Inset right { 0, 3 }; 1255 SafeAreaInsets::Inset bottom { 0, 4 }; 1256 SafeAreaInsets safeAreaInsets(left, top, right, bottom); 1257 1258 SafeAreaInsets::Inset inset {}; 1259 SafeAreaInsets emptySafeAreaInsets(inset, inset, inset, inset); 1260 1261 context_->UpdateSystemSafeArea(safeAreaInsets); 1262 context_->SetIgnoreViewSafeArea(true); 1263 1264 EXPECT_EQ(context_->safeAreaManager_->GetSafeArea(), emptySafeAreaInsets); 1265 } 1266 1267 /** 1268 * @tc.name: PipelineContextTestNg074 1269 * @tc.desc: Test the function SetOnceVsyncListener. 1270 * @tc.type: FUNC 1271 */ 1272 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg074, TestSize.Level1) 1273 { 1274 /** 1275 * @tc.steps1: initialize parameters. 1276 * @tc.expected: All pointer is non-null. 1277 */ 1278 ASSERT_NE(context_, nullptr); 1279 1280 /** 1281 * @tc.steps2: Set a non-null function to context. 1282 * @tc.expected: The onceVsyncListener_ is non-null. 1283 */ 1284 bool flag = false; __anon230df7e10b02() 1285 auto getVsyncFunc = [&flag]() { flag = !flag; }; 1286 context_->SetOnceVsyncListener(getVsyncFunc); 1287 EXPECT_TRUE(context_->HasOnceVsyncListener()); 1288 1289 /** 1290 * @tc.steps2: Set a null function to context. 1291 * @tc.expected: The onceVsyncListener_ is null. 1292 */ 1293 context_->SetOnceVsyncListener(nullptr); 1294 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1295 } 1296 1297 /** 1298 * @tc.name: PipelineContextTestNg075 1299 * @tc.desc: Test the function FlushOnceVsyncTask. 1300 * @tc.type: FUNC 1301 */ 1302 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg075, TestSize.Level1) 1303 { 1304 /** 1305 * @tc.steps1: initialize parameters. 1306 * @tc.expected: All pointer is non-null. 1307 */ 1308 ASSERT_NE(context_, nullptr); 1309 1310 /** 1311 * @tc.steps2: Set a non-null function to context and call FlushOnceVsyncTask. 1312 * @tc.expected: The onceVsyncListener_ is null and flag changes to true. 1313 */ 1314 bool flag = false; __anon230df7e10c02() 1315 auto getVsyncFunc = [&flag]() { flag = !flag; }; 1316 context_->SetOnceVsyncListener(getVsyncFunc); 1317 context_->FlushOnceVsyncTask(); 1318 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1319 EXPECT_TRUE(flag); 1320 1321 /** 1322 * @tc.steps2: Set a non-null function to context and call FlushOnceVsyncTask. 1323 * @tc.expected: The onceVsyncListener_ is null and flag is still true. 1324 */ 1325 context_->SetOnceVsyncListener(nullptr); 1326 context_->FlushOnceVsyncTask(); 1327 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1328 EXPECT_TRUE(flag); 1329 } 1330 1331 /** 1332 + * @tc.name: PipelineContextTestNg076 1333 + * @tc.desc: Test the function GetMainPipelineContext and NeedSoftKeyboard. 1334 + * @tc.type: FUNC 1335 + */ 1336 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg076, TestSize.Level1) 1337 { 1338 /** 1339 * @tc.steps1: initialize parameters. 1340 * @tc.expected: All pointer is non-null. 1341 */ 1342 ASSERT_NE(context_, nullptr); 1343 /** 1344 * @tc.steps2: Get current pipeline 1345 * @tc.expected: pipeline is not null. 1346 */ 1347 auto pipeline = PipelineContext::GetMainPipelineContext(); 1348 EXPECT_NE(pipeline, nullptr); 1349 EXPECT_FALSE(pipeline->NeedSoftKeyboard()); 1350 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 10, nullptr); 1351 EXPECT_FALSE(pipeline->NeedSoftKeyboard()); 1352 1353 /** 1354 * @tc.steps3: Get current pipeline through the Container 1355 * @tc.expected: pipeline is null. 1356 */ __anon230df7e10d02(FoldStatus folderStatus) 1357 pipeline->foldStatusChangedCallbackMap_.emplace(1, [](FoldStatus folderStatus) {}); 1358 pipeline->foldStatusChangedCallbackMap_.emplace(2, nullptr); __anon230df7e10e02(FoldDisplayMode foldDisplayMode) 1359 pipeline->foldDisplayModeChangedCallbackMap_.emplace(1, [](FoldDisplayMode foldDisplayMode) {}); 1360 pipeline->foldDisplayModeChangedCallbackMap_.emplace(2, nullptr); 1361 pipeline->transformHintChangedCallbackMap_.emplace(1, nullptr); __anon230df7e10f02(uint32_t num) 1362 pipeline->transformHintChangedCallbackMap_.emplace(2, [](uint32_t num) {}); 1363 pipeline->OnFoldStatusChange(FoldStatus::EXPAND); 1364 pipeline->OnFoldDisplayModeChange(FoldDisplayMode::FULL); 1365 pipeline->OnTransformHintChanged(0); 1366 EXPECT_NE(PipelineContext::GetContextByContainerId(0), nullptr); 1367 pipeline->AddDirtyPropertyNode(frameNode); 1368 EXPECT_TRUE(pipeline->hasIdleTasks_); 1369 DelayedTask delayedTask; 1370 pipeline->delayedTasks_.push_back(delayedTask); 1371 DelayedTask delayedTask1; 1372 delayedTask1.timeStamp = GetSysTimestamp(); 1373 delayedTask1.time = 1; 1374 pipeline->delayedTasks_.push_back(delayedTask1); 1375 pipeline->ProcessDelayTasks(); 1376 EXPECT_EQ(pipeline->delayedTasks_.size(), 1); 1377 } 1378 1379 /** 1380 + * @tc.name: PipelineContextTestNg077 1381 + * @tc.desc: Test the function HandleFocusNode. 1382 + * @tc.type: FUNC 1383 + */ 1384 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg077, TestSize.Level1) 1385 { 1386 /** 1387 * @tc.steps1: Get current pipeline 1388 * @tc.expected: pipeline is null. 1389 */ 1390 auto pipeline = PipelineContext::GetMainPipelineContext(); 1391 EXPECT_NE(pipeline, nullptr); 1392 1393 /** 1394 * @tc.steps2: Changing node information affects the return results. 1395 * @tc.expected:return frameNode is not null. 1396 */ 1397 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 5, nullptr); 1398 auto frameNode1 = FrameNode::GetOrCreateFrameNode("test", 6, nullptr); 1399 auto frameNode2 = FrameNode::GetOrCreateFrameNode("test", 7, nullptr); 1400 frameNode->GetOrCreateFocusHub(); 1401 frameNode1->GetOrCreateFocusHub()->currentFocus_ = false; 1402 frameNode2->GetOrCreateFocusHub()->currentFocus_ = true; 1403 frameNode1->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1404 frameNode2->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1405 frameNode->AddChild(frameNode1); 1406 frameNode->AddChild(frameNode2); 1407 pipeline->SetScreenNode(frameNode); 1408 frameNode1->GetOrCreateFocusHub()->currentFocus_ = true; 1409 auto frameNode3 = FrameNode::GetOrCreateFrameNode("test", 8, nullptr); 1410 auto frameNode4 = FrameNode::GetOrCreateFrameNode("test", 9, nullptr); 1411 frameNode2->AddChild(frameNode3); 1412 frameNode2->AddChild(frameNode4); 1413 frameNode2->GetOrCreateFocusHub()->focusable_ = true; 1414 frameNode3->GetOrCreateFocusHub()->currentFocus_ = false; 1415 frameNode4->GetOrCreateFocusHub()->currentFocus_ = true; 1416 frameNode4->GetOrCreateFocusHub()->focusable_ = false; 1417 frameNode3->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1418 frameNode4->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1419 } 1420 1421 /** 1422 + * @tc.name: PipelineContextTestNg078 1423 + * @tc.desc: Test the function HandleFocusNode. 1424 + * @tc.type: FUNC 1425 + */ 1426 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg078, TestSize.Level1) 1427 { 1428 /** 1429 * @tc.steps1: Get current pipeline 1430 * @tc.expected: pipeline is not null. 1431 */ 1432 auto pipeline = PipelineContext::GetMainPipelineContext(); 1433 EXPECT_NE(pipeline, nullptr); 1434 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 5, nullptr); 1435 pipeline->StartFullToMultWindowAnimation(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER); 1436 pipeline->StartFullToMultWindowAnimation(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::FULL_TO_FLOATING); 1437 pipeline->AvoidanceLogic(0.0); 1438 EXPECT_EQ(pipeline->finishFunctions_.size(), 0); 1439 auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 1440 EXPECT_FALSE(pipeline->DumpPageViewData(nullptr, viewDataWrap)); 1441 EXPECT_FALSE(pipeline->DumpPageViewData(frameNode, viewDataWrap)); 1442 EXPECT_FALSE(pipeline->CheckNeedAutoSave()); 1443 pipeline->NotifyFillRequestSuccess(AceAutoFillType::ACE_DETAIL_INFO_WITHOUT_STREET, viewDataWrap); 1444 pipeline->NotifyFillRequestFailed(frameNode, 101); 1445 1446 /** 1447 * @tc.steps2: Partial addition of function execution. 1448 * @tc.expected:Change the state of the pipeline. 1449 */ __anon230df7e11002(bool visible) 1450 auto formCallback = [](bool visible) {}; 1451 pipeline->ContainerModalUnFocus(); 1452 pipeline->windowModal_ = WindowModal::NORMAL; 1453 pipeline->SetContainerModalTitleHeight(0); 1454 pipeline->UpdateTitleInTargetPos(false, 0); 1455 pipeline->SetContainerModalTitleVisible(false, true); 1456 pipeline->SetCloseButtonStatus(false); 1457 pipeline->GetContainerModalTitleHeight(); 1458 pipeline->windowModal_ = WindowModal::CONTAINER_MODAL; 1459 pipeline->GetContainerModalTitleHeight(); 1460 pipeline->ContainerModalUnFocus(); 1461 pipeline->UpdateTitleInTargetPos(false, 0); 1462 pipeline->SetCloseButtonStatus(true); 1463 pipeline->SetContainerModalTitleVisible(true, false); 1464 pipeline->SetContainerModalTitleHeight(0); 1465 pipeline->SetAppBgColor(Color::BLACK); 1466 auto frameNode1 = FrameNode::GetOrCreateFrameNode("test", 6, nullptr); 1467 pipeline->activeNode_ = AceType::WeakClaim(AceType::RawPtr(frameNode1)); 1468 pipeline->GetCurrentExtraInfo(); 1469 pipeline->AddIsFocusActiveUpdateEvent(frameNode, formCallback); 1470 EXPECT_EQ(pipeline->isFocusActiveUpdateEvents_.size(), 1); 1471 pipeline->RemoveIsFocusActiveUpdateEvent(frameNode); 1472 EXPECT_EQ(pipeline->isFocusActiveUpdateEvents_.size(), 0); 1473 } 1474 1475 /** 1476 * @tc.name: PipelineContextTestNg074 1477 * @tc.desc: Test the function SetFontScale. 1478 * @tc.type: FUNC 1479 */ 1480 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg079, TestSize.Level1) 1481 { 1482 /** 1483 * @tc.steps1: initialize parameters. 1484 * @tc.expected: All pointer is non-null. 1485 */ 1486 ASSERT_NE(context_, nullptr); 1487 1488 float fontScale = 1.2f; 1489 context_->SetFontScale(fontScale); 1490 ASSERT_EQ(context_->fontScale_, fontScale); 1491 } 1492 1493 /** 1494 * @tc.name: PipelineContextTestNg075 1495 * @tc.desc: Test the function SetFontWeightScale. 1496 * @tc.type: FUNC 1497 */ 1498 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg080, TestSize.Level1) 1499 { 1500 /** 1501 * @tc.steps1: initialize parameters. 1502 * @tc.expected: All pointer is non-null. 1503 */ 1504 ASSERT_NE(context_, nullptr); 1505 1506 float fontWeightScale = 1.2f; 1507 context_->SetFontWeightScale(fontWeightScale); 1508 ASSERT_EQ(context_->fontWeightScale_, fontWeightScale); 1509 } 1510 1511 /** 1512 * @tc.name: PipelineContextTestNg081 1513 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1514 * @tc.type: FUNC 1515 */ 1516 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg081, TestSize.Level1) 1517 { 1518 /** 1519 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1520 * @tc.expected: Render alphaValue is not equal to 75. 1521 */ 1522 context_->isFormRender_ = false; 1523 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1524 Color color; 1525 context_->CheckNeedUpdateBackgroundColor(color); 1526 uint32_t alphaValue = color.GetAlpha(); 1527 ASSERT_NE(alphaValue, 75); 1528 } 1529 1530 /** 1531 * @tc.name: PipelineContextTestNg082 1532 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1533 * @tc.type: FUNC 1534 */ 1535 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg082, TestSize.Level1) 1536 { 1537 /** 1538 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1539 * @tc.expected: Render alphaValue is not equal to 75. 1540 */ 1541 context_->isFormRender_ = true; 1542 context_->renderingMode_ = RENDERINGMODE_FULL_COLOR; 1543 Color color; 1544 context_->CheckNeedUpdateBackgroundColor(color); 1545 uint32_t alphaValue = color.GetAlpha(); 1546 ASSERT_NE(alphaValue, 75); 1547 } 1548 1549 /** 1550 * @tc.name: PipelineContextTestNg083 1551 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1552 * @tc.type: FUNC 1553 */ 1554 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg083, TestSize.Level1) 1555 { 1556 /** 1557 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1558 * @tc.expected: Render alphaValue is equal to 75. 1559 */ 1560 context_->isFormRender_ = true; 1561 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1562 Color color; 1563 context_->CheckNeedUpdateBackgroundColor(color); 1564 uint32_t alphaValue = color.GetAlpha(); 1565 ASSERT_EQ(alphaValue, 75); 1566 } 1567 1568 /** 1569 * @tc.name: PipelineContextTestNg084 1570 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1571 * @tc.type: FUNC 1572 */ 1573 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg084, TestSize.Level1) 1574 { 1575 /** 1576 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1577 * @tc.expected: No update background image. 1578 */ 1579 context_->isFormRender_ = false; 1580 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1581 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1582 ASSERT_NE(isUpdateBGIamge, true); 1583 } 1584 1585 /** 1586 * @tc.name: PipelineContextTestNg085 1587 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1588 * @tc.type: FUNC 1589 */ 1590 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg085, TestSize.Level1) 1591 { 1592 /** 1593 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1594 * @tc.expected: No update background image. 1595 */ 1596 context_->isFormRender_ = true; 1597 context_->renderingMode_ = RENDERINGMODE_FULL_COLOR; 1598 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1599 ASSERT_NE(isUpdateBGIamge, true); 1600 } 1601 1602 /** 1603 * @tc.name: PipelineContextTestNg086 1604 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1605 * @tc.type: FUNC 1606 */ 1607 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg086, TestSize.Level1) 1608 { 1609 /** 1610 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1611 * @tc.expected: Update background image. 1612 */ 1613 context_->isFormRender_ = true; 1614 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1615 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1616 ASSERT_EQ(isUpdateBGIamge, true); 1617 } 1618 1619 /** 1620 * @tc.name: PipelineContextTestNg087 1621 * @tc.desc: Test the function ClearNode. 1622 * @tc.type: FUNC 1623 */ 1624 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg087, TestSize.Level1) 1625 { 1626 /** 1627 * @tc.steps1: initialize parameters. 1628 * @tc.expected: All pointer is non-null. 1629 */ 1630 ASSERT_NE(context_, nullptr); 1631 context_->dirtyPropertyNodes_.emplace(frameNode_); 1632 context_->needRenderNode_.emplace(WeakPtr<FrameNode>(frameNode_)); 1633 context_->dirtyFocusNode_ = frameNode_; 1634 context_->dirtyFocusScope_ = frameNode_; 1635 context_->dirtyRequestFocusNode_ = frameNode_; 1636 context_->activeNode_ = frameNode_; 1637 context_->focusNode_ = frameNode_; 1638 1639 /** 1640 * @tc.step2: detach framenode. 1641 */ 1642 context_->DetachNode(frameNode_); 1643 1644 EXPECT_NE(context_->dirtyPropertyNodes_.count(frameNode_), 1); 1645 EXPECT_NE(context_->needRenderNode_.count(WeakPtr<FrameNode>(frameNode_)), 1); 1646 EXPECT_NE(context_->dirtyFocusNode_, frameNode_); 1647 EXPECT_NE(context_->dirtyFocusScope_, frameNode_); 1648 EXPECT_NE(context_->dirtyRequestFocusNode_, frameNode_); 1649 EXPECT_NE(context_->activeNode_, frameNode_); 1650 EXPECT_NE(context_->focusNode_, frameNode_); 1651 } 1652 1653 /** 1654 * @tc.name: UITaskSchedulerTestNg007 1655 * @tc.desc: Test AddLayoutNode. 1656 * @tc.type: FUNC 1657 */ 1658 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg007, TestSize.Level1) 1659 { 1660 /** 1661 * @tc.steps1: Create taskScheduler add layoutNode. 1662 */ 1663 UITaskScheduler taskScheduler; 1664 auto layoutNode = AceType::MakeRefPtr<FrameNode>("test", -1, AceType::MakeRefPtr<Pattern>(), false); 1665 1666 /** 1667 * @tc.steps2: Call AddLayoutNode. 1668 * @tc.expected: taskScheduler.layoutNodes_.size() = 1 1669 */ 1670 taskScheduler.AddLayoutNode(layoutNode); 1671 EXPECT_EQ(taskScheduler.layoutNodes_.size(), 1); 1672 } 1673 1674 /** 1675 * @tc.name: UITaskSchedulerTestNg008 1676 * @tc.desc: Test SetLayoutNodeRect. 1677 * @tc.type: FUNC 1678 */ 1679 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg008, TestSize.Level1) 1680 { 1681 /** 1682 * @tc.steps1: Create taskScheduler add layoutNode. 1683 */ 1684 UITaskScheduler taskScheduler; 1685 auto layoutNode1 = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1686 auto layoutNode2 = AceType::MakeRefPtr<FrameNode>("test2", -1, AceType::MakeRefPtr<Pattern>(), false); 1687 auto layoutNode3 = AceType::MakeRefPtr<FrameNode>("test3", -1, AceType::MakeRefPtr<Pattern>(), false); 1688 auto layoutNode4 = AceType::MakeRefPtr<FrameNode>("test4", -1, AceType::MakeRefPtr<Pattern>(), false); 1689 layoutNode3->SetIsFind(true); 1690 layoutNode2->SetOverlayNode(layoutNode4); 1691 taskScheduler.AddLayoutNode(layoutNode1); 1692 taskScheduler.AddLayoutNode(layoutNode2); 1693 taskScheduler.AddLayoutNode(layoutNode3); 1694 1695 /** 1696 * @tc.steps2: Call SetLayoutNodeRect. 1697 */ 1698 taskScheduler.SetLayoutNodeRect(); 1699 } 1700 1701 /** 1702 * @tc.name: UITaskSchedulerTestNg009 1703 * @tc.desc: Test FlushPersistAfterLayoutTask/FlushAfterRenderTask/FlushAfterLayoutCallbackInImplicitAnimationTask 1704 * @tc.type: FUNC 1705 */ 1706 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg009, TestSize.Level1) 1707 { 1708 /** 1709 * @tc.steps1: Create taskScheduler add layoutNode. 1710 */ 1711 UITaskScheduler taskScheduler; __anon230df7e11102() 1712 taskScheduler.AddPersistAfterLayoutTask([]() {}); 1713 taskScheduler.AddPersistAfterLayoutTask(nullptr); 1714 taskScheduler.AddAfterRenderTask(nullptr); __anon230df7e11202() 1715 taskScheduler.AddAfterRenderTask([]() {}); 1716 1717 /** 1718 * @tc.steps2: Call FlushPersistAfterLayoutTask/FlushAfterRenderTask/FlushAfterLayoutCallbackInImplicitAnimationTask 1719 */ 1720 taskScheduler.FlushPersistAfterLayoutTask(); 1721 taskScheduler.FlushAfterRenderTask(); 1722 taskScheduler.FlushAfterLayoutCallbackInImplicitAnimationTask(); 1723 1724 /** 1725 * @tc.steps3: Call FlushAfterLayoutCallbackInImplicitAnimationTask/FlushTaskWithCheck 1726 */ 1727 taskScheduler.FlushTaskWithCheck(true); 1728 taskScheduler.FlushTaskWithCheck(false); __anon230df7e11302() 1729 taskScheduler.AddAfterLayoutTask([]() {}, true); 1730 taskScheduler.AddAfterLayoutTask(nullptr, true); 1731 taskScheduler.FlushAfterLayoutCallbackInImplicitAnimationTask(); 1732 taskScheduler.FlushTaskWithCheck(false); 1733 } 1734 1735 /** 1736 * @tc.name: PipelineContextTestNg095 1737 * @tc.desc: Test the function AddDirtyLayoutNode/AddDirtyRenderNode 1738 * @tc.type: FUNC 1739 */ 1740 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg095, TestSize.Level1) 1741 { 1742 /** 1743 * @tc.steps1: initialize parameters,destroyed_ is false/true 1744 */ 1745 auto frameNode1 = FrameNode::GetOrCreateFrameNode("test1", 1, nullptr); 1746 auto frameNode2 = FrameNode::GetOrCreateFrameNode("test2", 2, nullptr); 1747 context_->SetPredictNode(frameNode2); 1748 context_->PipelineContext::AddDirtyLayoutNode(frameNode1); 1749 } 1750 1751 /** 1752 * @tc.name: PipelineContextTestNg096 1753 * @tc.desc: Test the function FlushFocusScroll 1754 * @tc.type: FUNC 1755 */ 1756 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg096, TestSize.Level1) 1757 { 1758 /** 1759 * @tc.steps1: initialize parameters,isNeedTriggerScroll_ is false 1760 */ 1761 RefPtr<FocusManager> focusManager = context_->GetOrCreateFocusManager(); 1762 context_->PipelineContext::FlushFocusScroll(); 1763 1764 /** 1765 * @tc.steps2: initialize parameters,isNeedTriggerScroll_ is true 1766 */ 1767 focusManager->SetNeedTriggerScroll(true); 1768 context_->PipelineContext::FlushFocusScroll(); 1769 } 1770 1771 /** 1772 * @tc.name: PipelineContextTestNg097 1773 * @tc.desc: Test the function RegisterTouchEventListener 1774 * @tc.type: FUNC 1775 */ 1776 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg097, TestSize.Level1) 1777 { 1778 /** 1779 * @tc.steps1: initialize parameters,construct changeInfoListeners_ 1780 */ 1781 std::shared_ptr<ITouchEventCallback> touchEventCallback = nullptr; 1782 context_->RegisterTouchEventListener(touchEventCallback); 1783 ASSERT_EQ(context_->listenerVector_.size(), 0); 1784 } 1785 1786 /** 1787 * @tc.name: PipelineContextTestNg098 1788 * @tc.desc: Test the function AddChangedFrameNode 1789 * @tc.type: FUNC 1790 */ 1791 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg098, TestSize.Level1) 1792 { 1793 /** 1794 * @tc.steps1: AddChangedFrameNode 1795 */ 1796 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1797 EXPECT_FALSE(context_->AddChangedFrameNode(frameNode)); 1798 context_->CleanNodeChangeFlag(); 1799 EXPECT_FALSE(context_->AddChangedFrameNode(frameNode)); 1800 } 1801 1802 /** 1803 * @tc.name: PipelineContextTestNg099 1804 * @tc.desc: Test the function AddFrameNodeChangeListener 1805 * @tc.type: FUNC 1806 */ 1807 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg099, TestSize.Level1) 1808 { 1809 /** 1810 * @tc.steps1: AddFrameNodeChangeListener 1811 */ 1812 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1813 context_->AddFrameNodeChangeListener(frameNode); 1814 context_->FlushNodeChangeFlag(); 1815 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1816 context_->AddFrameNodeChangeListener(frameNode); 1817 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1818 context_->RemoveFrameNodeChangeListener(frameNode); 1819 context_->FlushNodeChangeFlag(); 1820 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1821 } 1822 1823 /** 1824 * @tc.name: PipelineContextTestNg100 1825 * @tc.desc: Test the function UpdateHalfFoldHoverStatus 1826 * @tc.type: FUNC 1827 */ 1828 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg100, TestSize.Level1) 1829 { 1830 /** 1831 * @tc.steps1: initialize parameters. 1832 * @tc.expected: All pointer is non-null. 1833 */ 1834 ASSERT_NE(context_, nullptr); 1835 context_->minPlatformVersion_ = static_cast<int32_t>(PlatformVersion::VERSION_THIRTEEN); 1836 RefPtr<DisplayInfo> displayInfo = AceType::MakeRefPtr<DisplayInfo>(); 1837 displayInfo->SetWidth(DEFAULT_INT10); 1838 displayInfo->SetHeight(DEFAULT_INT10); 1839 displayInfo->SetIsFoldable(true); 1840 displayInfo->SetFoldStatus(FoldStatus::HALF_FOLD); 1841 displayInfo->SetRotation(Rotation::ROTATION_90); 1842 MockContainer::Current()->SetDisplayInfo(displayInfo); 1843 context_->UpdateHalfFoldHoverStatus(DEFAULT_INT10, DEFAULT_INT10); 1844 ASSERT_EQ(context_->isHalfFoldHoverStatus_, true); 1845 } 1846 } // namespace NG 1847 } // namespace OHOS::Ace 1848