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 namespace { 30 struct TouchTimeTestCase { 31 uint64_t vsyncTime; 32 uint64_t compensationValue; 33 std::vector<uint64_t> touchEventTimes; 34 uint32_t targetTouchEventSize; 35 uint32_t originTouchEventSize; 36 }; 37 38 const std::vector<TouchTimeTestCase> COLLECT_TOUCH_EVENTS_TESTCASES = { 39 { AFTER_VSYNC_TIME, BEFORE_VSYNC_TIME, { BEFORE_VSYNC_TIME, DEFAULT_VSYNC_TIME }, 2, 0 }, 40 { DEFAULT_VSYNC_TIME, 0, { BEFORE_VSYNC_TIME, DEFAULT_VSYNC_TIME }, 2, 0 }, 41 { DEFAULT_VSYNC_TIME, 0, { DEFAULT_VSYNC_TIME, AFTER_VSYNC_TIME }, 1, 1 }, 42 { DEFAULT_VSYNC_TIME, 0, { AFTER_VSYNC_TIME, AFTER_VSYNC_TIME }, 0, 2 }, 43 }; 44 45 const std::vector<TouchTimeTestCase> FLUSH_TOUCH_EVENTS_TESTCASES = { 46 { DEFAULT_VSYNC_TIME, 0, {}, 0, 0 }, 47 { DEFAULT_VSYNC_TIME, 0, { BEFORE_VSYNC_TIME }, 0, 1 }, 48 { DEFAULT_VSYNC_TIME, 0, { BEFORE_VSYNC_TIME, BEFORE_VSYNC_TIME }, 0, 2 }, 49 { DEFAULT_VSYNC_TIME, 0, { DEFAULT_VSYNC_TIME, AFTER_VSYNC_TIME }, 1, 2 }, 50 }; 51 } // namespace 52 /** 53 * @tc.name: PipelineContextTestNg036 54 * @tc.desc: Test RequestFocus. 55 * @tc.type: FUNC 56 */ 57 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg036, TestSize.Level1) 58 { 59 /** 60 * @tc.steps1: initialize parameters and make sure pointers are not null. 61 */ 62 ASSERT_NE(context_, nullptr); 63 ASSERT_NE(frameNode_, nullptr); 64 context_->rootNode_ = frameNode_; 65 auto eventHub = frameNode_->GetEventHub<EventHub>(); 66 ASSERT_NE(eventHub, nullptr); 67 auto focusHub = eventHub->GetOrCreateFocusHub(); 68 ASSERT_NE(focusHub, nullptr); 69 frameNodeId_ = ElementRegister::GetInstance()->MakeUniqueId(); 70 auto frameNode_1 = FrameNode::GetOrCreateFrameNode(TEST_TAG, frameNodeId_, nullptr); 71 eventHub->host_ = frameNode_1; 72 frameNode_1->UpdateInspectorId("123"); 73 74 /** 75 * @tc.steps3: change host_,focusType_,enabled_, 76 focusable_,parentFocusable_,currentFocus_ 77 */ 78 auto eventHub1 = frameNode_1->GetEventHub<EventHub>(); 79 eventHub1->host_ = nullptr; 80 focusHub->focusType_ = FocusType::NODE; 81 eventHub->enabled_ = true; 82 focusHub->focusable_ = true; 83 focusHub->parentFocusable_ = true; 84 focusHub->currentFocus_ = true; 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_ = true; 91 auto rt = context_->RequestFocus(""); 92 EXPECT_FALSE(rt); 93 94 /** 95 * @tc.steps4: change isSubPipeline_ and call RequestFocus with empty string 96 * @tc.expect: RequestFocus empty string return false. 97 */ 98 context_->isSubPipeline_ = false; 99 rt = context_->RequestFocus(""); 100 EXPECT_FALSE(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, __anon23a81be90202(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 -1 has been erased. 137 */ 138 ASSERT_NE(context_, nullptr); 139 context_->onWindowSizeChangeCallbacks_.emplace_back(-1); 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(), 1); 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 */ __anon23a81be90302() 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 */ __anon23a81be90402(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 */ __anon23a81be90502() 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 */ __anon23a81be90602() 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( __anon23a81be90702() 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( __anon23a81be90802() 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(); __anon23a81be90902() 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 */ __anon23a81be90a02() 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; __anon23a81be90b02(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: PipelineContextTestNg063 929 * @tc.desc: Test the function OpenFrontendAnimation and CloseFrontendAnimation. 930 * @tc.type: FUNC 931 */ 932 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg063, TestSize.Level1) 933 { 934 decltype(context_->pendingFrontendAnimation_) temp; 935 std::swap(context_->pendingFrontendAnimation_, temp); 936 /** 937 * @tc.steps1: Call CloseFrontAnimation directly. 938 * @tc.expected: No animation is generated. The pending flag stack is empty. 939 */ 940 context_->CloseFrontendAnimation(); 941 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0); 942 /** 943 * @tc.steps2: Call OpenFrontendAnimation. 944 * @tc.expected: A pending flag is pushed to the stack. 945 */ 946 AnimationOption option(Curves::EASE, 1000); 947 context_->OpenFrontendAnimation(option, option.GetCurve(), nullptr); 948 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 1); 949 /** 950 * @tc.steps3: Call CloseFrontendAnimation after OpenFrontendAnimation. 951 * @tc.expected: The pending flag is out of stack. 952 */ 953 context_->CloseFrontendAnimation(); 954 EXPECT_EQ(context_->pendingFrontendAnimation_.size(), 0); 955 } 956 957 /** 958 * @tc.name: PipelineContextTestNg064 959 * @tc.desc: Test history and current. 960 * @tc.type: FUNC 961 */ 962 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg064, TestSize.Level1) 963 { 964 /** 965 * @tc.steps1: history and current timestamps are equal to nanoTimeStamp 966 * @tc.expected: Expect the result to be (0.0, 0.0) 967 */ 968 AvgPoint history_fs = { 969 .x = 1.0f, 970 .y = 2.0f, 971 .time = 1000 972 }; 973 AvgPoint current_fs = { 974 .x = 2.0f, 975 .y = 2.0f, 976 .time = 2000 977 }; 978 uint64_t nanoTimeStampFs = 1000; 979 auto result_fs = ResampleAlgo::LinearInterpolation(history_fs, current_fs, nanoTimeStampFs); 980 EXPECT_EQ(result_fs.x, 0.0f); 981 EXPECT_EQ(result_fs.y, 0.0f); 982 EXPECT_EQ(result_fs.inputXDeltaSlope, 0.0f); 983 EXPECT_EQ(result_fs.inputYDeltaSlope, 0.0f); 984 985 /** 986 * @tc.steps2: history and current timestamps are equal to nanoTimeStamp 987 * @tc.expected: Expect the result to be (0.0, 0.0) 988 */ 989 AvgPoint history_se = { 990 .x = 1.0f, 991 .y = 1.0f, 992 .time = 2000 993 }; 994 AvgPoint current_se = { 995 .x = 2.0f, 996 .y = 2.0f, 997 .time = 1000 998 }; 999 uint64_t nanoTimeStampSe = 1500; 1000 auto result_se = ResampleAlgo::LinearInterpolation(history_se, current_se, nanoTimeStampSe); 1001 EXPECT_EQ(result_se.x, 0.0f); 1002 EXPECT_EQ(result_se.y, 0.0f); 1003 EXPECT_EQ(result_se.inputXDeltaSlope, 0.0f); 1004 EXPECT_EQ(result_se.inputYDeltaSlope, 0.0f); 1005 1006 /** 1007 * @tc.steps3: history and current timestamps are equal to nanoTimeStamp 1008 * @tc.expected: Expect the result to be (1.75, 1.75) 1009 */ 1010 AvgPoint history_th = { 1011 .x = 1.0f, 1012 .y = 1.0f, 1013 .time = 1000 1014 }; 1015 AvgPoint current_th = { 1016 .x = 2.0f, 1017 .y = 2.0f, 1018 .time = 3000 1019 }; 1020 uint64_t nanoTimeStampTh = 2500; 1021 auto result_th = ResampleAlgo::LinearInterpolation(history_th, current_th, nanoTimeStampTh); 1022 EXPECT_EQ(result_th.x, 1.75f); 1023 EXPECT_EQ(result_th.y, 1.75f); 1024 EXPECT_EQ(result_th.inputXDeltaSlope, 500000.0f); 1025 EXPECT_EQ(result_th.inputYDeltaSlope, 500000.0f); 1026 } 1027 1028 /** 1029 * @tc.name: PipelineContextTestNg065 1030 * @tc.desc: Test history and current. 1031 * @tc.type: FUNC 1032 */ 1033 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg065, TestSize.Level1) 1034 { 1035 /** 1036 * @tc.steps1: GetResampleCoord illegal value verification 1037 * @tc.expected: All result is 0.0f. 1038 */ 1039 std::vector<TouchEvent> emptyHistory; 1040 std::vector<TouchEvent> emptyCurrent; 1041 uint64_t nanoTimeStamp = 1234567890; 1042 bool isScreen = true; 1043 auto result = 1044 ResampleAlgo::GetResampleCoord(std::vector<PointerEvent>(emptyHistory.begin(), emptyHistory.end()), 1045 std::vector<PointerEvent>(emptyCurrent.begin(), emptyCurrent.end()), nanoTimeStamp, isScreen); 1046 EXPECT_FLOAT_EQ(0.0f, result.x); 1047 EXPECT_FLOAT_EQ(0.0f, result.y); 1048 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1049 emptyHistory.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1050 result = ResampleAlgo::GetResampleCoord(std::vector<PointerEvent>(emptyHistory.begin(), emptyHistory.end()), 1051 std::vector<PointerEvent>(emptyCurrent.begin(), emptyCurrent.end()), nanoTimeStamp, isScreen); 1052 EXPECT_FLOAT_EQ(0.0f, result.x); 1053 EXPECT_FLOAT_EQ(0.0f, result.y); 1054 emptyHistory.clear(); 1055 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1056 emptyCurrent.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampTwo)); 1057 result = ResampleAlgo::GetResampleCoord(std::vector<PointerEvent>(emptyHistory.begin(), emptyHistory.end()), 1058 std::vector<PointerEvent>(emptyCurrent.begin(), emptyCurrent.end()), nanoTimeStamp, isScreen); 1059 EXPECT_FLOAT_EQ(0.0f, result.x); 1060 EXPECT_FLOAT_EQ(0.0f, result.y); 1061 } 1062 1063 /** 1064 * @tc.name: PipelineContextTestNg066 1065 * @tc.desc: Test history and current. 1066 * @tc.type: FUNC 1067 */ 1068 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg066, TestSize.Level1) 1069 { 1070 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1071 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1072 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1073 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(2000)); 1074 std::vector<TouchEvent> history; 1075 history.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1076 history.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1077 std::vector<TouchEvent> current; 1078 current.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampThree)); 1079 current.push_back(TouchEvent {}.SetX(250.0f).SetY(350.0f).SetTime(timeStampFour)); 1080 1081 auto resampledCoord = ResampleAlgo::GetResampleCoord(std::vector<PointerEvent>(history.begin(), history.end()), 1082 std::vector<PointerEvent>(current.begin(), current.end()), 30000000, true); 1083 1084 ASSERT_FLOAT_EQ(200.0f, resampledCoord.x); 1085 ASSERT_FLOAT_EQ(300.0f, resampledCoord.y); 1086 1087 SystemProperties::debugEnabled_ = true; 1088 resampledCoord = ResampleAlgo::GetResampleCoord(std::vector<PointerEvent>(history.begin(), history.end()), 1089 std::vector<PointerEvent>(current.begin(), current.end()), 2500, true); 1090 ASSERT_FLOAT_EQ(0.0f, resampledCoord.x); 1091 ASSERT_FLOAT_EQ(0.0f, resampledCoord.y); 1092 } 1093 1094 /** 1095 * @tc.name: PipelineContextTestNg067 1096 * @tc.desc: Test history and current. 1097 * @tc.type: FUNC 1098 */ 1099 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg067, TestSize.Level1) 1100 { 1101 /** 1102 * @tc.steps1: nanoTimeStamp is less than history timestamp 1103 * @tc.expected: Expect the result to be (0.0, 0.0) 1104 */ 1105 AvgPoint history_for = { 1106 .x = 1.0f, 1107 .y = 1.0f, 1108 .time = 1000 1109 }; 1110 AvgPoint current_for = { 1111 .x = 2.0f, 1112 .y = 2.0f, 1113 .time = 2000 1114 }; 1115 uint64_t nanoTimeStampFor = 500; 1116 auto result_for = ResampleAlgo::LinearInterpolation(history_for, current_for, nanoTimeStampFor); 1117 EXPECT_EQ(result_for.x, 0.0f); 1118 EXPECT_EQ(result_for.y, 0.0f); 1119 EXPECT_EQ(result_for.inputXDeltaSlope, 0.0f); 1120 EXPECT_EQ(result_for.inputYDeltaSlope, 0.0f); 1121 1122 /** 1123 * @tc.steps2: nanoTimeStamp is less than current timestamp 1124 * @tc.expected: Expect non-zero value 1125 */ 1126 AvgPoint history_fie = { 1127 .x = 1.0f, 1128 .y = 1.0f, 1129 .time = 1000 1130 }; 1131 AvgPoint current_fie = { 1132 .x = 2.0f, 1133 .y = 2.0f, 1134 .time = 2000 1135 }; 1136 uint64_t nanoTimeStampFie = 1500; 1137 auto result_fie = ResampleAlgo::LinearInterpolation(history_fie, current_fie, nanoTimeStampFie); 1138 EXPECT_NE(result_fie.x, 0.0f); 1139 EXPECT_NE(result_fie.y, 0.0f); 1140 EXPECT_NE(result_fie.inputXDeltaSlope, 0.0f); 1141 EXPECT_NE(result_fie.inputYDeltaSlope, 0.0f); 1142 1143 /** 1144 * @tc.steps3: nanoTimeStamp is greater than current timestamp 1145 * @tc.expected: Expect non-zero value 1146 */ 1147 AvgPoint history_six = { 1148 .x = 1.0f, 1149 .y = 1.0f, 1150 .time = 1000 1151 }; 1152 AvgPoint current_six = { 1153 .x = 2.0f, 1154 .y = 2.0f, 1155 .time = 2000 1156 }; 1157 uint64_t nanoTimeStampSix = 2500; 1158 auto result_six = ResampleAlgo::LinearInterpolation(history_six, current_six, nanoTimeStampSix); 1159 EXPECT_NE(result_six.x, 0.0f); 1160 EXPECT_NE(result_six.y, 0.0f); 1161 EXPECT_NE(result_six.inputXDeltaSlope, 0.0f); 1162 EXPECT_NE(result_six.inputYDeltaSlope, 0.0f); 1163 } 1164 1165 /** 1166 * @tc.name: PipelineContextTestNg068 1167 * @tc.desc: Test history and current. 1168 * @tc.type: FUNC 1169 */ 1170 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg068, TestSize.Level1) 1171 { 1172 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1173 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1174 std::vector<TouchEvent> current; 1175 current.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1176 current.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1177 uint64_t nanoTimeStamp = 1500; 1178 1179 TouchEvent latestPoint = context_->eventManager_->GetLatestPoint(current, nanoTimeStamp); 1180 1181 ASSERT_FLOAT_EQ(100.0f, latestPoint.x); 1182 ASSERT_FLOAT_EQ(200.0f, latestPoint.y); 1183 } 1184 1185 /** 1186 * @tc.name: PipelineContextTestNg069 1187 * @tc.desc: Test history and current. 1188 * @tc.type: FUNC 1189 */ 1190 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg069, TestSize.Level1) 1191 { 1192 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1193 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1194 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1195 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000)); 1196 std::vector<TouchEvent> history; 1197 history.push_back(TouchEvent {}.SetX(100.0f).SetY(200.0f).SetTime(timeStampAce)); 1198 history.push_back(TouchEvent {}.SetX(150.0f).SetY(250.0f).SetTime(timeStampTwo)); 1199 std::vector<TouchEvent> current; 1200 current.push_back(TouchEvent {}.SetX(200.0f).SetY(300.0f).SetTime(timeStampThree)); 1201 current.push_back(TouchEvent {}.SetX(250.0f).SetY(350.0f).SetTime(timeStampFour)); 1202 uint64_t nanoTimeStamp = 2500; 1203 1204 TouchEvent resampledTouchEvent; 1205 context_->eventManager_->GetResampleTouchEvent(history, current, 1206 nanoTimeStamp, resampledTouchEvent); 1207 1208 ASSERT_FLOAT_EQ(175.0f, resampledTouchEvent.x); 1209 ASSERT_FLOAT_EQ(275.0f, resampledTouchEvent.y); 1210 } 1211 1212 /** 1213 * @tc.name: PipelineContextTestNg070 1214 * @tc.desc: Test GetLatestPoint. 1215 * @tc.type: FUNC 1216 */ 1217 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg070, TestSize.Level1) 1218 { 1219 std::vector<TouchEvent> events; 1220 1221 TouchEvent event; 1222 event.time = TimeStamp(std::chrono::nanoseconds(1000)); 1223 events.push_back(event); 1224 1225 TouchEvent result = context_->eventManager_->GetLatestPoint(events, 1000); 1226 ASSERT_EQ(static_cast<uint64_t>(result.time.time_since_epoch().count()), 1000); 1227 } 1228 1229 /** 1230 * @tc.name: PipelineContextTestNg071 1231 * @tc.desc: Test GetLatestPoint. 1232 * @tc.type: FUNC 1233 */ 1234 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg071, TestSize.Level1) 1235 { 1236 std::vector<TouchEvent> events; 1237 1238 TouchEvent eventAce; 1239 eventAce.time = TimeStamp(std::chrono::nanoseconds(2000)); 1240 events.push_back(eventAce); 1241 1242 TouchEvent eventTwo; 1243 eventTwo.time = TimeStamp(std::chrono::nanoseconds(3000)); 1244 events.push_back(eventTwo); 1245 1246 uint64_t nanoTimeStamp = 1500; 1247 1248 TouchEvent result = context_->eventManager_->GetLatestPoint(events, nanoTimeStamp); 1249 ASSERT_GT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp); 1250 } 1251 1252 /** 1253 * @tc.name: PipelineContextTestNg072 1254 * @tc.desc: Test GetLatestPoint. 1255 * @tc.type: FUNC 1256 */ 1257 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg072, TestSize.Level1) 1258 { 1259 std::vector<TouchEvent> events; 1260 1261 TouchEvent eventAce; 1262 eventAce.time = TimeStamp(std::chrono::nanoseconds(500)); 1263 events.push_back(eventAce); 1264 1265 TouchEvent eventTwo; 1266 eventTwo.time = TimeStamp(std::chrono::nanoseconds(1000)); 1267 events.push_back(eventTwo); 1268 1269 uint64_t nanoTimeStamp = 1500; 1270 1271 TouchEvent result = context_->eventManager_->GetLatestPoint(events, nanoTimeStamp); 1272 ASSERT_LT(static_cast<uint64_t>(result.time.time_since_epoch().count()), nanoTimeStamp); 1273 } 1274 1275 /** 1276 * @tc.name: PipelineContextTestNg073 1277 * @tc.desc: Test the function GetSafeArea and GetSafeAreaWithoutProcess. 1278 * @tc.type: FUNC 1279 */ 1280 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg073, TestSize.Level1) 1281 { 1282 /** 1283 * @tc.steps1: initialize parameters. 1284 * @tc.expected: All pointer is non-null. 1285 */ 1286 ASSERT_NE(context_, nullptr); 1287 /** 1288 * @tc.steps2: call UpdateSystemSafeArea and SetIgnoreViewSafeArea, then check the value of GetSafeArea 1289 and GetSafeAreaWithoutProcess. 1290 * @tc.expected: The GetSafeArea is empty, and the GetSafeAreaWithoutProcess is systemSafeArea. 1291 */ 1292 SafeAreaInsets::Inset left { 0, 1 }; 1293 SafeAreaInsets::Inset top { 0, 2 }; 1294 SafeAreaInsets::Inset right { 0, 3 }; 1295 SafeAreaInsets::Inset bottom { 0, 4 }; 1296 SafeAreaInsets safeAreaInsets(left, top, right, bottom); 1297 1298 SafeAreaInsets::Inset inset {}; 1299 SafeAreaInsets emptySafeAreaInsets(inset, inset, inset, inset); 1300 1301 context_->UpdateSystemSafeArea(safeAreaInsets); 1302 context_->SetIgnoreViewSafeArea(true); 1303 1304 EXPECT_EQ(context_->safeAreaManager_->GetSafeArea(), emptySafeAreaInsets); 1305 } 1306 1307 /** 1308 * @tc.name: PipelineContextTestNg074 1309 * @tc.desc: Test the function SetOnceVsyncListener. 1310 * @tc.type: FUNC 1311 */ 1312 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg074, TestSize.Level1) 1313 { 1314 /** 1315 * @tc.steps1: initialize parameters. 1316 * @tc.expected: All pointer is non-null. 1317 */ 1318 ASSERT_NE(context_, nullptr); 1319 1320 /** 1321 * @tc.steps2: Set a non-null function to context. 1322 * @tc.expected: The onceVsyncListener_ is non-null. 1323 */ 1324 bool flag = false; __anon23a81be90c02() 1325 auto getVsyncFunc = [&flag]() { flag = !flag; }; 1326 context_->SetOnceVsyncListener(getVsyncFunc); 1327 EXPECT_TRUE(context_->HasOnceVsyncListener()); 1328 1329 /** 1330 * @tc.steps2: Set a null function to context. 1331 * @tc.expected: The onceVsyncListener_ is null. 1332 */ 1333 context_->SetOnceVsyncListener(nullptr); 1334 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1335 } 1336 1337 /** 1338 * @tc.name: PipelineContextTestNg075 1339 * @tc.desc: Test the function FlushOnceVsyncTask. 1340 * @tc.type: FUNC 1341 */ 1342 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg075, TestSize.Level1) 1343 { 1344 /** 1345 * @tc.steps1: initialize parameters. 1346 * @tc.expected: All pointer is non-null. 1347 */ 1348 ASSERT_NE(context_, nullptr); 1349 1350 /** 1351 * @tc.steps2: Set a non-null function to context and call FlushOnceVsyncTask. 1352 * @tc.expected: The onceVsyncListener_ is null and flag changes to true. 1353 */ 1354 bool flag = false; __anon23a81be90d02() 1355 auto getVsyncFunc = [&flag]() { flag = !flag; }; 1356 context_->SetOnceVsyncListener(getVsyncFunc); 1357 context_->FlushOnceVsyncTask(); 1358 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1359 EXPECT_TRUE(flag); 1360 1361 /** 1362 * @tc.steps2: Set a non-null function to context and call FlushOnceVsyncTask. 1363 * @tc.expected: The onceVsyncListener_ is null and flag is still true. 1364 */ 1365 context_->SetOnceVsyncListener(nullptr); 1366 context_->FlushOnceVsyncTask(); 1367 EXPECT_FALSE(context_->HasOnceVsyncListener()); 1368 EXPECT_TRUE(flag); 1369 } 1370 1371 /** 1372 + * @tc.name: PipelineContextTestNg076 1373 + * @tc.desc: Test the function GetMainPipelineContext and NeedSoftKeyboard. 1374 + * @tc.type: FUNC 1375 + */ 1376 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg076, TestSize.Level1) 1377 { 1378 /** 1379 * @tc.steps1: initialize parameters. 1380 * @tc.expected: All pointer is non-null. 1381 */ 1382 ASSERT_NE(context_, nullptr); 1383 /** 1384 * @tc.steps2: Get current pipeline 1385 * @tc.expected: pipeline is not null. 1386 */ 1387 auto pipeline = PipelineContext::GetMainPipelineContext(); 1388 EXPECT_NE(pipeline, nullptr); 1389 EXPECT_FALSE(pipeline->NeedSoftKeyboard()); 1390 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 10, nullptr); 1391 EXPECT_FALSE(pipeline->NeedSoftKeyboard()); 1392 1393 /** 1394 * @tc.steps3: Get current pipeline through the Container 1395 * @tc.expected: pipeline is null. 1396 */ __anon23a81be90e02(FoldStatus folderStatus) 1397 pipeline->foldStatusChangedCallbackMap_.emplace(1, [](FoldStatus folderStatus) {}); 1398 pipeline->foldStatusChangedCallbackMap_.emplace(2, nullptr); __anon23a81be90f02(FoldDisplayMode foldDisplayMode) 1399 pipeline->foldDisplayModeChangedCallbackMap_.emplace(1, [](FoldDisplayMode foldDisplayMode) {}); 1400 pipeline->foldDisplayModeChangedCallbackMap_.emplace(2, nullptr); 1401 pipeline->transformHintChangedCallbackMap_.emplace(1, nullptr); __anon23a81be91002(uint32_t num) 1402 pipeline->transformHintChangedCallbackMap_.emplace(2, [](uint32_t num) {}); 1403 pipeline->OnFoldStatusChange(FoldStatus::EXPAND); 1404 pipeline->OnFoldDisplayModeChange(FoldDisplayMode::FULL); 1405 pipeline->OnTransformHintChanged(0); 1406 EXPECT_NE(PipelineContext::GetContextByContainerId(0), nullptr); 1407 pipeline->AddDirtyPropertyNode(frameNode); 1408 EXPECT_TRUE(pipeline->hasIdleTasks_); 1409 DelayedTask delayedTask; 1410 pipeline->delayedTasks_.push_back(delayedTask); 1411 DelayedTask delayedTask1; 1412 delayedTask1.timeStamp = GetSysTimestamp(); 1413 delayedTask1.time = 1; 1414 pipeline->delayedTasks_.push_back(delayedTask1); 1415 pipeline->ProcessDelayTasks(); 1416 EXPECT_EQ(pipeline->delayedTasks_.size(), 1); 1417 } 1418 1419 /** 1420 + * @tc.name: PipelineContextTestNg077 1421 + * @tc.desc: Test the function HandleFocusNode. 1422 + * @tc.type: FUNC 1423 + */ 1424 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg077, TestSize.Level1) 1425 { 1426 /** 1427 * @tc.steps1: Get current pipeline 1428 * @tc.expected: pipeline is null. 1429 */ 1430 auto pipeline = PipelineContext::GetMainPipelineContext(); 1431 EXPECT_NE(pipeline, nullptr); 1432 1433 /** 1434 * @tc.steps2: Changing node information affects the return results. 1435 * @tc.expected:return frameNode is not null. 1436 */ 1437 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 5, nullptr); 1438 auto frameNode1 = FrameNode::GetOrCreateFrameNode("test", 6, nullptr); 1439 auto frameNode2 = FrameNode::GetOrCreateFrameNode("test", 7, nullptr); 1440 frameNode->GetOrCreateFocusHub(); 1441 frameNode1->GetOrCreateFocusHub()->currentFocus_ = false; 1442 frameNode2->GetOrCreateFocusHub()->currentFocus_ = true; 1443 frameNode1->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1444 frameNode2->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1445 frameNode->AddChild(frameNode1); 1446 frameNode->AddChild(frameNode2); 1447 pipeline->SetScreenNode(frameNode); 1448 frameNode1->GetOrCreateFocusHub()->currentFocus_ = true; 1449 auto frameNode3 = FrameNode::GetOrCreateFrameNode("test", 8, nullptr); 1450 auto frameNode4 = FrameNode::GetOrCreateFrameNode("test", 9, nullptr); 1451 frameNode2->AddChild(frameNode3); 1452 frameNode2->AddChild(frameNode4); 1453 frameNode2->GetOrCreateFocusHub()->focusable_ = true; 1454 frameNode3->GetOrCreateFocusHub()->currentFocus_ = false; 1455 frameNode4->GetOrCreateFocusHub()->currentFocus_ = true; 1456 frameNode4->GetOrCreateFocusHub()->focusable_ = false; 1457 frameNode3->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1458 frameNode4->GetOrCreateFocusHub()->SetFocusType(FocusType::NODE); 1459 } 1460 1461 /** 1462 + * @tc.name: PipelineContextTestNg078 1463 + * @tc.desc: Test the function HandleFocusNode. 1464 + * @tc.type: FUNC 1465 + */ 1466 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg078, TestSize.Level1) 1467 { 1468 /** 1469 * @tc.steps1: Get current pipeline 1470 * @tc.expected: pipeline is not null. 1471 */ 1472 auto pipeline = PipelineContext::GetMainPipelineContext(); 1473 EXPECT_NE(pipeline, nullptr); 1474 auto frameNode = FrameNode::GetOrCreateFrameNode("test", 5, nullptr); 1475 pipeline->StartFullToMultWindowAnimation(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::RECOVER); 1476 pipeline->StartFullToMultWindowAnimation(DEFAULT_INT3, DEFAULT_INT3, WindowSizeChangeReason::FULL_TO_FLOATING); 1477 pipeline->AvoidanceLogic(0.0); 1478 EXPECT_EQ(pipeline->finishFunctions_.size(), 0); 1479 auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 1480 EXPECT_FALSE(pipeline->DumpPageViewData(nullptr, viewDataWrap)); 1481 EXPECT_FALSE(pipeline->DumpPageViewData(frameNode, viewDataWrap)); 1482 EXPECT_FALSE(pipeline->CheckNeedAutoSave()); 1483 pipeline->NotifyFillRequestSuccess(AceAutoFillType::ACE_DETAIL_INFO_WITHOUT_STREET, viewDataWrap); 1484 pipeline->NotifyFillRequestFailed(frameNode, 101); 1485 1486 /** 1487 * @tc.steps2: Partial addition of function execution. 1488 * @tc.expected:Change the state of the pipeline. 1489 */ __anon23a81be91102(bool visible) 1490 auto formCallback = [](bool visible) {}; 1491 pipeline->ContainerModalUnFocus(); 1492 pipeline->windowModal_ = WindowModal::NORMAL; 1493 pipeline->SetContainerModalTitleHeight(0); 1494 pipeline->UpdateTitleInTargetPos(false, 0); 1495 pipeline->SetContainerModalTitleVisible(false, true); 1496 pipeline->SetCloseButtonStatus(false); 1497 pipeline->GetContainerModalTitleHeight(); 1498 pipeline->windowModal_ = WindowModal::CONTAINER_MODAL; 1499 pipeline->GetContainerModalTitleHeight(); 1500 pipeline->ContainerModalUnFocus(); 1501 pipeline->UpdateTitleInTargetPos(false, 0); 1502 pipeline->SetCloseButtonStatus(true); 1503 pipeline->SetContainerModalTitleVisible(true, false); 1504 pipeline->SetContainerModalTitleHeight(0); 1505 pipeline->SetAppBgColor(Color::BLACK); 1506 auto frameNode1 = FrameNode::GetOrCreateFrameNode("test", 6, nullptr); 1507 pipeline->activeNode_ = AceType::WeakClaim(AceType::RawPtr(frameNode1)); 1508 pipeline->GetCurrentExtraInfo(); 1509 pipeline->AddIsFocusActiveUpdateEvent(frameNode, formCallback); 1510 EXPECT_EQ(pipeline->isFocusActiveUpdateEvents_.size(), 1); 1511 pipeline->RemoveIsFocusActiveUpdateEvent(frameNode); 1512 EXPECT_EQ(pipeline->isFocusActiveUpdateEvents_.size(), 0); 1513 } 1514 1515 /** 1516 * @tc.name: PipelineContextTestNg074 1517 * @tc.desc: Test the function SetFontScale. 1518 * @tc.type: FUNC 1519 */ 1520 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg079, TestSize.Level1) 1521 { 1522 /** 1523 * @tc.steps1: initialize parameters. 1524 * @tc.expected: All pointer is non-null. 1525 */ 1526 ASSERT_NE(context_, nullptr); 1527 1528 float fontScale = 1.2f; 1529 context_->SetFontScale(fontScale); 1530 ASSERT_EQ(context_->fontScale_, fontScale); 1531 } 1532 1533 /** 1534 * @tc.name: PipelineContextTestNg075 1535 * @tc.desc: Test the function SetFontWeightScale. 1536 * @tc.type: FUNC 1537 */ 1538 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg080, TestSize.Level1) 1539 { 1540 /** 1541 * @tc.steps1: initialize parameters. 1542 * @tc.expected: All pointer is non-null. 1543 */ 1544 ASSERT_NE(context_, nullptr); 1545 1546 float fontWeightScale = 1.2f; 1547 context_->SetFontWeightScale(fontWeightScale); 1548 ASSERT_EQ(context_->fontWeightScale_, fontWeightScale); 1549 } 1550 1551 /** 1552 * @tc.name: PipelineContextTestNg081 1553 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1554 * @tc.type: FUNC 1555 */ 1556 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg081, TestSize.Level1) 1557 { 1558 /** 1559 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1560 * @tc.expected: Render alphaValue is not equal to 75. 1561 */ 1562 context_->isFormRender_ = false; 1563 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1564 Color color; 1565 context_->CheckNeedUpdateBackgroundColor(color); 1566 uint32_t alphaValue = color.GetAlpha(); 1567 ASSERT_NE(alphaValue, 75); 1568 } 1569 1570 /** 1571 * @tc.name: PipelineContextTestNg082 1572 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1573 * @tc.type: FUNC 1574 */ 1575 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg082, TestSize.Level1) 1576 { 1577 /** 1578 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1579 * @tc.expected: Render alphaValue is not equal to 75. 1580 */ 1581 context_->isFormRender_ = true; 1582 context_->renderingMode_ = RENDERINGMODE_FULL_COLOR; 1583 Color color; 1584 context_->CheckNeedUpdateBackgroundColor(color); 1585 uint32_t alphaValue = color.GetAlpha(); 1586 ASSERT_NE(alphaValue, 75); 1587 } 1588 1589 /** 1590 * @tc.name: PipelineContextTestNg083 1591 * @tc.desc: Test the function CheckNeedUpdateBackgroundColor. 1592 * @tc.type: FUNC 1593 */ 1594 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg083, TestSize.Level1) 1595 { 1596 /** 1597 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1598 * @tc.expected: Render alphaValue is equal to 75. 1599 */ 1600 context_->isFormRender_ = true; 1601 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1602 Color color; 1603 context_->CheckNeedUpdateBackgroundColor(color); 1604 uint32_t alphaValue = color.GetAlpha(); 1605 ASSERT_EQ(alphaValue, 75); 1606 } 1607 1608 /** 1609 * @tc.name: PipelineContextTestNg084 1610 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1611 * @tc.type: FUNC 1612 */ 1613 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg084, TestSize.Level1) 1614 { 1615 /** 1616 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1617 * @tc.expected: No update background image. 1618 */ 1619 context_->isFormRender_ = false; 1620 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1621 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1622 ASSERT_NE(isUpdateBGIamge, true); 1623 } 1624 1625 /** 1626 * @tc.name: PipelineContextTestNg085 1627 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1628 * @tc.type: FUNC 1629 */ 1630 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg085, TestSize.Level1) 1631 { 1632 /** 1633 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1634 * @tc.expected: No update background image. 1635 */ 1636 context_->isFormRender_ = true; 1637 context_->renderingMode_ = RENDERINGMODE_FULL_COLOR; 1638 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1639 ASSERT_NE(isUpdateBGIamge, true); 1640 } 1641 1642 /** 1643 * @tc.name: PipelineContextTestNg086 1644 * @tc.desc: Test the function CheckNeedDisableUpdateBackgroundImage. 1645 * @tc.type: FUNC 1646 */ 1647 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg086, TestSize.Level1) 1648 { 1649 /** 1650 * @tc.step1: Set pipelineContext attribute isFormRender_ and renderingMode_. 1651 * @tc.expected: Update background image. 1652 */ 1653 context_->isFormRender_ = true; 1654 context_->renderingMode_ = RENDERINGMODE_SINGLE_COLOR; 1655 bool isUpdateBGIamge = context_->CheckNeedDisableUpdateBackgroundImage(); 1656 ASSERT_EQ(isUpdateBGIamge, true); 1657 } 1658 1659 /** 1660 * @tc.name: PipelineContextTestNg087 1661 * @tc.desc: Test the function ClearNode. 1662 * @tc.type: FUNC 1663 */ 1664 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg087, TestSize.Level1) 1665 { 1666 /** 1667 * @tc.steps1: initialize parameters. 1668 * @tc.expected: All pointer is non-null. 1669 */ 1670 ASSERT_NE(context_, nullptr); 1671 context_->dirtyPropertyNodes_.emplace(frameNode_); 1672 context_->needRenderNode_.emplace(WeakPtr<FrameNode>(frameNode_)); 1673 context_->dirtyFocusNode_ = frameNode_; 1674 context_->dirtyFocusScope_ = frameNode_; 1675 context_->dirtyRequestFocusNode_ = frameNode_; 1676 context_->activeNode_ = frameNode_; 1677 context_->focusNode_ = frameNode_; 1678 1679 /** 1680 * @tc.step2: detach framenode. 1681 */ 1682 context_->DetachNode(frameNode_); 1683 1684 EXPECT_NE(context_->dirtyPropertyNodes_.count(frameNode_), 1); 1685 EXPECT_NE(context_->needRenderNode_.count(WeakPtr<FrameNode>(frameNode_)), 1); 1686 EXPECT_NE(context_->dirtyFocusNode_, frameNode_); 1687 EXPECT_NE(context_->dirtyFocusScope_, frameNode_); 1688 EXPECT_NE(context_->dirtyRequestFocusNode_, frameNode_); 1689 EXPECT_NE(context_->activeNode_, frameNode_); 1690 EXPECT_NE(context_->focusNode_, frameNode_); 1691 } 1692 1693 /** 1694 * @tc.name: UITaskSchedulerTestNg007 1695 * @tc.desc: Test AddLayoutNode. 1696 * @tc.type: FUNC 1697 */ 1698 HWTEST_F(PipelineContextTestNg, UITaskSchedulerTestNg007, TestSize.Level1) 1699 { 1700 /** 1701 * @tc.steps1: Create taskScheduler add layoutNode. 1702 */ 1703 UITaskScheduler taskScheduler; 1704 auto layoutNode = AceType::MakeRefPtr<FrameNode>("test", -1, AceType::MakeRefPtr<Pattern>(), false); 1705 1706 /** 1707 * @tc.steps2: Call AddLayoutNode. 1708 * @tc.expected: taskScheduler.layoutNodes_.size() = 1 1709 */ 1710 taskScheduler.AddLayoutNode(layoutNode); 1711 EXPECT_EQ(taskScheduler.layoutNodes_.size(), 1); 1712 } 1713 1714 /** 1715 * @tc.name: PipelineContextTestNg097 1716 * @tc.desc: Test the function RegisterTouchEventListener 1717 * @tc.type: FUNC 1718 */ 1719 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg097, TestSize.Level1) 1720 { 1721 /** 1722 * @tc.steps1: initialize parameters,construct changeInfoListeners_ 1723 */ 1724 std::shared_ptr<ITouchEventCallback> touchEventCallback = nullptr; 1725 context_->RegisterTouchEventListener(touchEventCallback); 1726 ASSERT_EQ(context_->listenerVector_.size(), 0); 1727 } 1728 1729 /** 1730 * @tc.name: PipelineContextTestNg098 1731 * @tc.desc: Test the function AddChangedFrameNode 1732 * @tc.type: FUNC 1733 */ 1734 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg098, TestSize.Level1) 1735 { 1736 /** 1737 * @tc.steps1: AddChangedFrameNode 1738 */ 1739 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1740 EXPECT_FALSE(context_->AddChangedFrameNode(frameNode)); 1741 context_->CleanNodeChangeFlag(); 1742 EXPECT_FALSE(context_->AddChangedFrameNode(frameNode)); 1743 } 1744 1745 /** 1746 * @tc.name: PipelineContextTestNg099 1747 * @tc.desc: Test the function AddFrameNodeChangeListener 1748 * @tc.type: FUNC 1749 */ 1750 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg099, TestSize.Level1) 1751 { 1752 /** 1753 * @tc.steps1: AddFrameNodeChangeListener 1754 */ 1755 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1756 context_->AddFrameNodeChangeListener(frameNode); 1757 context_->FlushNodeChangeFlag(); 1758 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1759 context_->AddFrameNodeChangeListener(frameNode); 1760 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1761 context_->RemoveFrameNodeChangeListener(frameNode); 1762 context_->FlushNodeChangeFlag(); 1763 EXPECT_EQ(context_->changeInfoListeners_.size(), 1); 1764 } 1765 1766 /** 1767 * @tc.name: PipelineContextTestNg100 1768 * @tc.desc: Test the function UpdateHalfFoldHoverStatus 1769 * @tc.type: FUNC 1770 */ 1771 HWTEST_F(PipelineContextTestNg, PipelineContextTestNg100, TestSize.Level1) 1772 { 1773 /** 1774 * @tc.steps1: initialize parameters. 1775 * @tc.expected: All pointer is non-null. 1776 */ 1777 ASSERT_NE(context_, nullptr); 1778 context_->minPlatformVersion_ = static_cast<int32_t>(PlatformVersion::VERSION_THIRTEEN); 1779 RefPtr<DisplayInfo> displayInfo = AceType::MakeRefPtr<DisplayInfo>(); 1780 displayInfo->SetWidth(DEFAULT_INT10); 1781 displayInfo->SetHeight(DEFAULT_INT10); 1782 displayInfo->SetIsFoldable(true); 1783 displayInfo->SetFoldStatus(FoldStatus::HALF_FOLD); 1784 displayInfo->SetRotation(Rotation::ROTATION_90); 1785 MockContainer::Current()->SetDisplayInfo(displayInfo); 1786 context_->UpdateHalfFoldHoverStatus(DEFAULT_INT10, DEFAULT_INT10); 1787 ASSERT_EQ(context_->isHalfFoldHoverStatus_, true); 1788 } 1789 1790 /** 1791 * @tc.name: MouseEvent01 1792 * @tc.desc: Test GetResampleMouseEvent 1793 * @tc.type: FUNC 1794 */ 1795 HWTEST_F(PipelineContextTestNg, MouseEvent01, TestSize.Level1) 1796 { 1797 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1798 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1799 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1800 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000)); 1801 std::vector<MouseEvent> history; 1802 MouseEvent historyMouseEvent1; 1803 historyMouseEvent1.x = 100.0f; 1804 historyMouseEvent1.y = 200.0f; 1805 historyMouseEvent1.time = timeStampAce; 1806 history.push_back(historyMouseEvent1); 1807 MouseEvent historyMouseEvent2; 1808 historyMouseEvent2.x = 150.0f; 1809 historyMouseEvent2.y = 250.0f; 1810 historyMouseEvent2.time = timeStampTwo; 1811 history.push_back(historyMouseEvent2); 1812 std::vector<MouseEvent> current; 1813 MouseEvent currentMouseEvent1; 1814 currentMouseEvent1.x = 200.0f; 1815 currentMouseEvent1.y = 300.0f; 1816 currentMouseEvent1.time = timeStampThree; 1817 current.push_back(currentMouseEvent1); 1818 MouseEvent currentMouseEvent2; 1819 currentMouseEvent2.x = 250.0f; 1820 currentMouseEvent2.y = 350.0f; 1821 currentMouseEvent2.time = timeStampFour; 1822 current.push_back(currentMouseEvent2); 1823 uint64_t nanoTimeStamp = 2500; 1824 1825 MouseEvent resampledMouseEvent = context_->eventManager_->GetResampleMouseEvent(history, current, nanoTimeStamp); 1826 EXPECT_EQ(175.0f, resampledMouseEvent.x); 1827 EXPECT_EQ(275.0f, resampledMouseEvent.y); 1828 } 1829 1830 /** 1831 * @tc.name: DragEvent01 1832 * @tc.desc: Test GetResamplePointerEvent 1833 * @tc.type: FUNC 1834 */ 1835 HWTEST_F(PipelineContextTestNg, DragEvent01, TestSize.Level1) 1836 { 1837 auto timeStampAce = TimeStamp(std::chrono::nanoseconds(1000)); 1838 auto timeStampTwo = TimeStamp(std::chrono::nanoseconds(2000)); 1839 auto timeStampThree = TimeStamp(std::chrono::nanoseconds(3000)); 1840 auto timeStampFour = TimeStamp(std::chrono::nanoseconds(4000)); 1841 1842 std::vector<DragPointerEvent> history; 1843 DragPointerEvent historyDrageEvent1; 1844 historyDrageEvent1.x = 200; 1845 historyDrageEvent1.y = 300; 1846 historyDrageEvent1.time = timeStampAce; 1847 history.push_back(historyDrageEvent1); 1848 DragPointerEvent historyDrageEvent2; 1849 historyDrageEvent2.x = 250; 1850 historyDrageEvent2.y = 350; 1851 historyDrageEvent2.time = timeStampTwo; 1852 history.push_back(historyDrageEvent2); 1853 std::vector<DragPointerEvent> current; 1854 DragPointerEvent currentDragEvent1; 1855 currentDragEvent1.x = 300; 1856 currentDragEvent1.y = 400; 1857 currentDragEvent1.time = timeStampThree; 1858 current.push_back(currentDragEvent1); 1859 DragPointerEvent currentDragEvent2; 1860 currentDragEvent2.x = 350; 1861 currentDragEvent2.y = 450; 1862 currentDragEvent2.time = timeStampFour; 1863 current.push_back(currentDragEvent2); 1864 uint64_t nanoTimeStamp = 3100; 1865 1866 DragPointerEvent resampledPointerEvent = context_->eventManager_->GetResamplePointerEvent( 1867 history, current, nanoTimeStamp); 1868 EXPECT_EQ(305, resampledPointerEvent.x); 1869 EXPECT_EQ(405, resampledPointerEvent.y); 1870 } 1871 1872 /** 1873 * @tc.name: PipelineCancelDragIfRightBtnPressedTest001 1874 * @tc.desc: Test CancelDragIfRightBtnPressed 1875 * @tc.type: FUNC 1876 */ 1877 HWTEST_F(PipelineContextTestNg, PipelineCancelDragIfRightBtnPressedTest001, TestSize.Level1) 1878 { 1879 /** 1880 * @tc.steps1: initialize parameters. 1881 * @tc.expected: All pointer is non-null. 1882 */ 1883 ASSERT_NE(context_, nullptr); 1884 context_->SetupRootElement(); 1885 auto manager = context_->GetDragDropManager(); 1886 ASSERT_NE(manager, nullptr); 1887 MouseEvent event; 1888 1889 /** 1890 * @tc.steps2: test function with mouse event button is None. 1891 * @tc.expected: dragDropManager's dragCancel flag is false. 1892 */ 1893 manager->SetIsDragCancel(true); 1894 context_->CancelDragIfRightBtnPressed(event); 1895 EXPECT_FALSE(manager->isDragCancel_); 1896 1897 /** 1898 * @tc.steps3: test function with mouse event button is Right Button. 1899 * @tc.expected: dragDropManager's dragCancel flag is true. 1900 */ 1901 event.button = MouseButton::RIGHT_BUTTON; 1902 event.action = MouseAction::PRESS; 1903 context_->CancelDragIfRightBtnPressed(event); 1904 EXPECT_TRUE(manager->isDragCancel_); 1905 1906 /** 1907 * @tc.steps4: test function without dragDropManager_. 1908 * @tc.expected: dragDropManager's dragCancel flag is true. 1909 */ 1910 context_->dragDropManager_ = nullptr; 1911 context_->CancelDragIfRightBtnPressed(event); 1912 EXPECT_TRUE(manager->isDragCancel_); 1913 } 1914 1915 /** 1916 * @tc.name: PipelineOnDragEvent001 1917 * @tc.desc: Test reset drag frameNode with pull in. 1918 * @tc.type: FUNC 1919 */ 1920 HWTEST_F(PipelineContextTestNg, PipelineOnDragEvent001, TestSize.Level1) 1921 { 1922 /** 1923 * @tc.steps1: initialize parameters. 1924 * @tc.expected: All pointer is non-null. 1925 */ 1926 ASSERT_NE(context_, nullptr); 1927 context_->SetupRootElement(); 1928 auto manager = context_->GetDragDropManager(); 1929 ASSERT_NE(manager, nullptr); 1930 auto frameNode = AceType::MakeRefPtr<FrameNode>("test1", -1, AceType::MakeRefPtr<Pattern>(), false); 1931 manager->preTargetFrameNode_ = frameNode; 1932 1933 DragPointerEvent dragEvent; 1934 DragEventAction action = DragEventAction::DRAG_EVENT_START; 1935 context_->OnDragEvent(dragEvent, action); 1936 EXPECT_NE(manager->preTargetFrameNode_, frameNode); 1937 } 1938 1939 /** 1940 * @tc.name: PipelineFlushTouchEvents001 1941 * @tc.desc: Test the function CollectTouchEventsBeforeVsync. 1942 * @tc.type: FUNC 1943 */ 1944 HWTEST_F(PipelineContextTestNg, PipelineFlushTouchEvents001, TestSize.Level1) 1945 { 1946 /** 1947 * @tc.steps1: initialize parameters. 1948 * @tc.expected: All pointer is non-null. 1949 */ 1950 ASSERT_NE(context_, nullptr); 1951 context_->SetupRootElement(); 1952 1953 for (auto& testCase : COLLECT_TOUCH_EVENTS_TESTCASES) { 1954 context_->touchEvents_.clear(); 1955 context_->vsyncTime_ = testCase.vsyncTime; 1956 context_->compensationValue_ = testCase.compensationValue; 1957 for (auto& touchTimes : testCase.touchEventTimes) { 1958 TouchEvent event; 1959 event.time = TimeStamp(std::chrono::nanoseconds(touchTimes)); 1960 context_->touchEvents_.emplace_back(event); 1961 } 1962 std::list<TouchEvent> touchEvents; 1963 context_->CollectTouchEventsBeforeVsync(touchEvents); 1964 EXPECT_EQ(touchEvents.size(), testCase.targetTouchEventSize); 1965 EXPECT_EQ(context_->touchEvents_.size(), testCase.originTouchEventSize); 1966 } 1967 } 1968 1969 /** 1970 * @tc.name: PipelineFlushTouchEvents002 1971 * @tc.desc: Test the function FlushTouchEvents with normal touchEvents. 1972 * @tc.type: FUNC 1973 */ 1974 HWTEST_F(PipelineContextTestNg, PipelineFlushTouchEvents002, TestSize.Level1) 1975 { 1976 /** 1977 * @tc.steps1: initialize parameters. 1978 * @tc.expected: All pointer is non-null. 1979 */ 1980 ASSERT_NE(context_, nullptr); 1981 ASSERT_NE(context_->eventManager_, nullptr); 1982 context_->SetupRootElement(); 1983 context_->vsyncTime_ = AFTER_VSYNC_TIME; 1984 context_->eventManager_->idToTouchPoints_.clear(); 1985 1986 for (auto& testCase : FLUSH_TOUCH_EVENTS_TESTCASES) { 1987 context_->resampleTimeStamp_ = testCase.vsyncTime; 1988 context_->compensationValue_ = testCase.compensationValue; 1989 context_->touchEvents_.clear(); 1990 context_->historyPointsById_.clear(); 1991 for (auto& touchTimes : testCase.touchEventTimes) { 1992 TouchEvent event; 1993 event.type = TouchType::MOVE; 1994 event.time = TimeStamp(std::chrono::nanoseconds(touchTimes)); 1995 context_->touchEvents_.emplace_back(event); 1996 } 1997 context_->FlushTouchEvents(); 1998 EXPECT_EQ(context_->historyPointsById_.size(), testCase.targetTouchEventSize); 1999 auto idToTouchPoint = context_->eventManager_->GetIdToTouchPoint(); 2000 EXPECT_EQ(idToTouchPoint[DEFAULT_INT0].history.size(), testCase.originTouchEventSize); 2001 } 2002 } 2003 2004 HWTEST_F(PipelineContextTestNg, PipelineOnHoverMove001, TestSize.Level1) 2005 { 2006 /** 2007 * @tc.steps1: initialize parameters. 2008 * @tc.expected: All pointer is non-null. 2009 */ 2010 ASSERT_NE(context_, nullptr); 2011 ASSERT_NE(context_->eventManager_, nullptr); 2012 2013 TouchEvent event; 2014 RefPtr<HoverEventTarget> penHoverMoveEventTarget_ = AceType::MakeRefPtr<HoverEventTarget>("Button", 25); 2015 penHoverMoveEventTarget_->onPenHoverMoveEventCallback_ = nullptr; 2016 bool ret = penHoverMoveEventTarget_->HandlePenHoverMoveEvent(event); 2017 EXPECT_EQ(ret, false); 2018 } 2019 2020 HWTEST_F(PipelineContextTestNg, PipelineOnHoverMove002, TestSize.Level1) 2021 { 2022 /** 2023 * @tc.steps1: initialize parameters. 2024 * @tc.expected: All pointer is non-null. 2025 */ 2026 ASSERT_NE(context_, nullptr); 2027 ASSERT_NE(context_->eventManager_, nullptr); 2028 2029 TouchEvent event; 2030 RefPtr<HoverEventTarget> penHoverMoveEventTarget_ = AceType::MakeRefPtr<HoverEventTarget>("Button", 25); __anon23a81be91202(HoverInfo& penHoverMoveInfo) 2031 penHoverMoveEventTarget_->onPenHoverMoveEventCallback_ = [](HoverInfo& penHoverMoveInfo) {}; 2032 bool ret = penHoverMoveEventTarget_->HandlePenHoverMoveEvent(event); 2033 EXPECT_EQ(ret, true); 2034 } 2035 } // namespace NG 2036 } // namespace OHOS::Ace 2037