1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gmock/gmock.h" 17 #include "gtest/gtest.h" 18 #define private public 19 #include "interfaces/inner_api/ace_kit/src/view/ui_context_impl.h" 20 #undef private 21 #include "test/mock/core/pipeline/mock_pipeline_context.h" 22 #include "test/mock/core/common/mock_container.h" 23 #include "test/mock/interfaces/ipc_single/iremote_object.h" 24 #include "ui/base/ace_type.h" 25 26 #include "base/memory/ace_type.h" 27 #include "core/common/ace_application_info.h" 28 #include "core/components_ng/event/gesture_event_hub.h" 29 #include "core/pipeline_ng/pipeline_context.h" 30 31 #include <thread> 32 #include <chrono> 33 34 using namespace testing; 35 using namespace testing::ext; 36 using namespace OHOS::Ace::Kit; 37 38 namespace OHOS::Ace::Kit { 39 40 class UIContextImplTest : public testing::Test { 41 protected: SetUp()42 void SetUp() override 43 { 44 NG::MockPipelineContext::SetUp(); 45 auto mockPipeline = NG::MockPipelineContext::GetCurrent(); 46 uiContext_ = AceType::MakeRefPtr<UIContextImpl>(mockPipeline->Get()); 47 } TearDown()48 void TearDown() override 49 { 50 uiContext_ = nullptr; 51 NG::MockPipelineContext::TearDown(); 52 } 53 54 protected: 55 RefPtr<UIContextImpl> uiContext_; 56 }; 57 58 /** 59 * @tc.name: ApiVersionTest001 60 * @tc.desc: Test GetApiTargetVersion with standard version 61 * @tc.type: FUNC 62 */ 63 HWTEST_F(UIContextImplTest, ApiVersionTest001, TestSize.Level1) 64 { 65 /** 66 * @tc.steps: step1. Create a data table to traverse with a for loop 67 * @tc.expected: step1. std::vector should be created 68 */ 69 const std::vector<std::pair<int32_t, int32_t>> apiVersionCase = { 70 {8, 8}, 71 {1005, 5}, 72 {0, 0}, 73 {-10, -10}, 74 {1000, 0}, 75 {1001, 1}, 76 {10, 10}, 77 }; 78 for (const auto& [target, retrieved] : apiVersionCase) { 79 /** 80 * @tc.steps: step2. Set API target version 81 * @tc.expected: step2. API version should be retrieved 82 */ 83 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(target); 84 /** 85 * @tc.steps: step3. Retrieve the API version from UIContextImpl 86 */ 87 int32_t api = uiContext_->GetApiTargetVersion(); 88 /** 89 * @tc.expected: step3. Should return the exact negative value without modification 90 */ 91 EXPECT_EQ(api, retrieved); 92 } 93 } 94 95 /** 96 * @tc.name: VersionComparisonTest001 97 * @tc.desc: Test version comparison at API limit (1000) for equality and next value 98 * @tc.type: FUNC 99 */ 100 HWTEST_F(UIContextImplTest, VersionComparisonTest001, TestSize.Level1) 101 { 102 /** 103 * @tc.steps: step1. Set API target version to the boundary value 1000 104 */ 105 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(1000); 106 107 /** 108 * @tc.steps: step2. Verify comparison with version 0 109 * @tc.expected: step2. Should return true (1000 % 1000 = 0 >= 0) 110 */ 111 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(0)); 112 113 /** 114 * @tc.steps: step3. Verify comparison with version 1 115 * @tc.expected: step3. Should return false (0 < 1) 116 */ 117 EXPECT_FALSE(uiContext_->GreatOrEqualTargetAPIVersion(1)); 118 } 119 120 /** 121 * @tc.name: VersionComparisonTest002 122 * @tc.desc: Test version comparison when target version is higher than required 123 * @tc.type: FUNC 124 */ 125 HWTEST_F(UIContextImplTest, VersionComparisonTest002, TestSize.Level1) 126 { 127 /** 128 * @tc.steps: step1. Set API target version to 15 129 */ 130 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(15); 131 132 /** 133 * @tc.steps: step2. Verify comparison with version 10 134 * @tc.expected: step2. Should return true (15 >= 10) 135 */ 136 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(10)); 137 } 138 139 /** 140 * @tc.name: VersionComparisonTest003 141 * @tc.desc: Test version comparison when target version is lower than required 142 * @tc.type: FUNC 143 */ 144 HWTEST_F(UIContextImplTest, VersionComparisonTest003, TestSize.Level1) 145 { 146 /** 147 * @tc.steps: step1. Set API target version to 8 148 */ 149 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(8); 150 151 /** 152 * @tc.steps: step2. Verify comparison with version 10 153 * @tc.expected: step2. Should return false (8 < 10) 154 */ 155 EXPECT_FALSE(uiContext_->GreatOrEqualTargetAPIVersion(10)); 156 } 157 158 /** 159 * @tc.name: VersionComparisonTest004 160 * @tc.desc: Test version comparison with modulo version calculation 161 * @tc.type: FUNC 162 */ 163 HWTEST_F(UIContextImplTest, VersionComparisonTest004, TestSize.Level1) 164 { 165 /** 166 * @tc.steps: step1. Set API target version to 1008 (1000 + 8) 167 */ 168 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(1008); 169 170 /** 171 * @tc.steps: step2. Verify comparison with version 8 172 * @tc.expected: step2. Should return true (1008 % 1000 = 8 >= 8) 173 */ 174 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(8)); 175 176 /** 177 * @tc.steps: step3. Verify comparison with version 9 178 * @tc.expected: step3. Should return false (8 < 9) 179 */ 180 EXPECT_FALSE(uiContext_->GreatOrEqualTargetAPIVersion(9)); 181 } 182 183 /** 184 * @tc.name: VersionComparisonTest005 185 * @tc.desc: Test version comparison with boundary values 186 * @tc.type: FUNC 187 */ 188 HWTEST_F(UIContextImplTest, VersionComparisonTest005, TestSize.Level1) 189 { 190 /** 191 * @tc.steps: step1. Set API target version to 5 192 */ 193 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(5); 194 195 /** 196 * @tc.steps: step2. Verify comparison with same version 5 197 * @tc.expected: step2. Should return true (5 >= 5) 198 */ 199 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(5)); 200 201 /** 202 * @tc.steps: step3. Verify comparison with lower version 4 203 * @tc.expected: step3. Should return true (5 >= 4) 204 */ 205 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(4)); 206 207 /** 208 * @tc.steps: step4. Verify comparison with higher version 6 209 * @tc.expected: step4. Should return false (5 < 6) 210 */ 211 EXPECT_FALSE(uiContext_->GreatOrEqualTargetAPIVersion(6)); 212 } 213 214 /** 215 * @tc.name: VersionComparisonTest006 216 * @tc.desc: Test version comparison with large version difference 217 * @tc.type: FUNC 218 */ 219 HWTEST_F(UIContextImplTest, VersionComparisonTest006, TestSize.Level1) 220 { 221 /** 222 * @tc.steps: step1. Set API target version to 2000 223 */ 224 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(2000); 225 226 /** 227 * @tc.steps: step2. Verify comparison with version 0 228 * @tc.expected: step2. Should return true (2000 % 1000 = 0 >= 0) 229 */ 230 EXPECT_TRUE(uiContext_->GreatOrEqualTargetAPIVersion(0)); 231 232 /** 233 * @tc.steps: step3. Verify comparison with version 1 234 * @tc.expected: step3. Should return false (0 < 1) 235 */ 236 EXPECT_FALSE(uiContext_->GreatOrEqualTargetAPIVersion(1)); 237 } 238 /** 239 * @tc.name: VersionComparisonTest007 240 * @tc.desc: Test GreatOrEqualTargetAPIVersion with null context 241 * @tc.type: FUNC 242 */ 243 HWTEST_F(UIContextImplTest, VersionComparisonTest007, TestSize.Level1) 244 { 245 /** 246 * @tc.steps: step1. Create UIContextImpl with null pipeline context 247 */ 248 UIContextImpl nullContext(nullptr); 249 250 /** 251 * @tc.steps: step2. Set API target version to 8 252 */ 253 OHOS::Ace::AceApplicationInfo::GetInstance().SetApiTargetVersion(8); 254 255 /** 256 * @tc.steps: step3. Check version comparisons 257 * @tc.expected: step3. Should handle null context gracefully 258 */ 259 bool ge8 = nullContext.GreatOrEqualTargetAPIVersion(8); 260 bool ge9 = nullContext.GreatOrEqualTargetAPIVersion(9); 261 EXPECT_TRUE(ge8); 262 EXPECT_FALSE(ge9); 263 } 264 265 /** 266 * @tc.name: RequestFrameTest001 267 * @tc.desc: Test RequestFrame with valid context 268 * @tc.type: FUNC 269 */ 270 HWTEST_F(UIContextImplTest, RequestFrameTest001, TestSize.Level1) 271 { 272 /** 273 * @tc.steps: step1. Call RequestFrame on valid context 274 * @tc.expected: step1. Should complete without errors 275 */ 276 uiContext_->RequestFrame(); 277 SUCCEED(); 278 } 279 280 /** 281 * @tc.name: RequestFrameTest002 282 * @tc.desc: Test RequestFrame with null context 283 * @tc.type: FUNC 284 */ 285 HWTEST_F(UIContextImplTest, RequestFrameTest002, TestSize.Level1) 286 { 287 /** 288 * @tc.steps: step1. Create UIContextImpl with null pipeline context 289 */ 290 UIContextImpl uiContext_null(nullptr); 291 292 /** 293 * @tc.steps: step2. Call RequestFrame on null context 294 * @tc.expected: step2. Should complete without crashing 295 */ 296 uiContext_null.RequestFrame(); 297 298 SUCCEED(); 299 } 300 301 /** 302 * @tc.name: RunScopeUIDelayedTask001 303 * @tc.desc: Test adding a delayed task to the UI task list 304 * @tc.type: FUNC 305 */ 306 HWTEST_F(UIContextImplTest, RunScopeUIDelayedTask001, TestSize.Level1) 307 { 308 /** 309 * @tc.steps: step1. Initialize a flag to track task execution status and set param varibles for call 310 */ 311 const std::string taskName = "taskName"; 312 uint32_t delayTime = 1U; 313 314 /** 315 * @tc.steps: step2. Add a delayed task to the UI task list (name="taskName", delayTime=1500ms) 316 */ __anon8c69ff5c0102() 317 uiContext_->RunScopeUIDelayedTask([&]() {}, taskName, delayTime); 318 319 /** 320 * @tc.expected: step2. Task should be added without errors or crashes 321 */ 322 std::this_thread::sleep_for(std::chrono::seconds(1)); 323 SUCCEED(); 324 } 325 326 /** 327 * @tc.name: RunScopeUIDelayedTask002 328 * @tc.desc: Test excute a delayed UI task 329 * @tc.type: FUNC 330 */ 331 HWTEST_F(UIContextImplTest, RunScopeUIDelayedTask002, TestSize.Level1) 332 { 333 /** 334 * @tc.steps: step1. Initialize a flag to track task execution status and set param varibles for call 335 */ 336 const std::string taskName = "taskName"; 337 338 /** 339 * @tc.steps: step2. Add a delayed task to the UI task list (name="taskName", delayTime=1500ms) 340 * Then check immediately flag should be not modified. 341 */ __anon8c69ff5c0202() 342 uiContext_->RunScopeUIDelayedTask([&]() { }, taskName, 1U); 343 344 /** 345 * @tc.expected: step3. Wait for moment until task executed then check the flag, should be modified at final. 346 */ 347 std::this_thread::sleep_for(std::chrono::seconds(1)); 348 SUCCEED(); 349 } 350 351 /** 352 * @tc.name: AddAfterLayoutTaskTest001 353 * @tc.desc: Test adding a layout task to the implicit animation task list 354 * @tc.type: FUNC 355 */ 356 HWTEST_F(UIContextImplTest, AddAfterLayoutTaskTest001, TestSize.Level1) 357 { 358 /** 359 * @tc.steps: step1. Initialize a flag to track task execution status 360 */ 361 bool taskExecuted = false; 362 363 /** 364 * @tc.steps: step2. Add a task to the implicit animation task list (isFlushInImplicitAnimationTask=true) 365 */ __anon8c69ff5c0302() 366 uiContext_->AddAfterLayoutTask([&]() { taskExecuted = true; }, true); 367 368 /** 369 * @tc.expected: step2. Task should be added without errors or crashes 370 */ 371 SUCCEED(); 372 } 373 374 /** 375 * @tc.name: AddAfterLayoutTaskTest002 376 * @tc.desc: Test adding a layout task to the normal task list 377 * @tc.type: FUNC 378 */ 379 HWTEST_F(UIContextImplTest, AddAfterLayoutTaskTest002, TestSize.Level1) 380 { 381 /** 382 * @tc.steps: step1. Initialize a flag to track task execution status 383 */ 384 bool taskExecuted = false; 385 386 /** 387 * @tc.steps: step2. Add a task to the normal task list (isFlushInImplicitAnimationTask=false) 388 */ __anon8c69ff5c0402() 389 uiContext_->AddAfterLayoutTask([&]() { taskExecuted = true; }, false); 390 391 /** 392 * @tc.expected: step2. Task should be added without errors or crashes 393 */ 394 SUCCEED(); 395 } 396 397 /** 398 * @tc.name: RegisterArkUIObjectLifecycleCallback001 399 * @tc.desc: Test register arkui object lifecycle callback to the normal task list 400 * @tc.type: FUNC 401 */ 402 HWTEST_F(UIContextImplTest, RegisterArkUIObjectLifecycleCallback001, TestSize.Level1) 403 { 404 /** 405 * @tc.steps: step1. Initialize a flag to track task execution status 406 */ 407 bool taskExecuted = false; 408 409 /** 410 * @tc.steps: step2. Add a task to the normal task list 411 */ __anon8c69ff5c0502(void*) 412 uiContext_->RegisterArkUIObjectLifecycleCallback([&taskExecuted](void*) { taskExecuted = true; }); 413 ASSERT_NE(uiContext_->context_, nullptr); 414 uiContext_->context_->FireArkUIObjectLifecycleCallback(nullptr); 415 416 /** 417 * @tc.expected: step3. Task should be added without errors or crashes 418 */ 419 EXPECT_TRUE(taskExecuted); 420 } 421 422 /** 423 * @tc.name: UnregisterArkUIObjectLifecycleCallback001 424 * @tc.desc: Test unregister arkui object lifecycle callback to the normal task list 425 * @tc.type: FUNC 426 */ 427 HWTEST_F(UIContextImplTest, UnregisterArkUIObjectLifecycleCallback001, TestSize.Level1) 428 { 429 /** 430 * @tc.steps: step1. Initialize a flag to track task execution status 431 */ 432 bool taskExecuted = false; 433 434 /** 435 * @tc.steps: step2. Add a task to the normal task list 436 */ __anon8c69ff5c0602(void*) 437 uiContext_->RegisterArkUIObjectLifecycleCallback([&taskExecuted](void*) { taskExecuted = true; }); 438 uiContext_->UnregisterArkUIObjectLifecycleCallback(); 439 ASSERT_NE(uiContext_->context_, nullptr); 440 uiContext_->context_->FireArkUIObjectLifecycleCallback(nullptr); 441 442 /** 443 * @tc.expected: step3. Task should be added without errors or crashes 444 */ 445 EXPECT_FALSE(taskExecuted); 446 } 447 448 /** 449 * @tc.name: GetTokenTest 450 * @tc.desc: Test get token to the normal task list 451 * @tc.type: FUNC 452 */ 453 HWTEST_F(UIContextImplTest, GetTokenTest, TestSize.Level1) 454 { 455 /** 456 * @tc.steps: step1. Get token from uiContext 457 */ 458 auto token = uiContext_->GetToken(); 459 460 ASSERT_EQ(token, nullptr); 461 /** 462 * @tc.expected: step2. Task should be added without errors or crashes 463 */ 464 SUCCEED(); 465 } 466 467 /** 468 * @tc.name: GetDisplayInfo 469 * @tc.desc: Test get displayInfo to the normal task list 470 * @tc.type: FUNC 471 */ 472 HWTEST_F(UIContextImplTest, GetDisplayInfo, TestSize.Level1) 473 { 474 /** 475 * @tc.steps: step1. Get container 476 */ 477 auto container = MockContainer::Current(); 478 RefPtr<DisplayInfo> displayInfo = AceType::MakeRefPtr<DisplayInfo>(); 479 ASSERT_NE(displayInfo, nullptr); 480 /** 481 * @tc.steps: step2. set displayInfo 482 */ 483 container->SetDisplayInfo(displayInfo); 484 /** 485 * @tc.steps: step3. Get displayInfo from uiContext 486 */ 487 auto getDisplayInfo = uiContext_->GetDisplayInfo(); 488 /** 489 * @tc.steps: step4. displayInfo must not nullptr 490 */ 491 EXPECT_NE(getDisplayInfo, nullptr); 492 /** 493 * @tc.steps: step5. set displayInfo nullptr 494 */ 495 container->SetDisplayInfo(nullptr); 496 /** 497 * @tc.steps: step6. Get displayInfo from uiContext 498 */ 499 getDisplayInfo = uiContext_->GetDisplayInfo(); 500 /** 501 * @tc.steps: step7. displayInfo must nullptr 502 */ 503 EXPECT_EQ(getDisplayInfo, nullptr); 504 /** 505 * @tc.expected: step8. Task should be added without errors or crashes 506 */ 507 SUCCEED(); 508 } 509 510 /** 511 * @tc.name: GetWindowMode 512 * @tc.desc: Test get windowMode to the normal task list 513 * @tc.type: FUNC 514 */ 515 HWTEST_F(UIContextImplTest, GetWindowMode, TestSize.Level1) 516 { 517 ASSERT_NE(uiContext_->context_, nullptr); 518 auto windowManager = uiContext_->context_->GetWindowManager(); 519 ASSERT_NE(windowManager, nullptr); 520 /** 521 * @tc.steps: step1. Set windowMode WINDOW_MODE_FLOATING value 522 */ __anon8c69ff5c0702() 523 windowManager->SetWindowGetModeCallBack([]() { 524 return WindowMode::WINDOW_MODE_FLOATING; 525 }); 526 /** 527 * @tc.steps: step2. Get windowMode from uiContext 528 */ 529 auto windowMode = uiContext_->GetWindowMode(); 530 /** 531 * @tc.steps: step3. windowMode must be WINDOW_MODE_FLOATING 532 */ 533 EXPECT_EQ(windowMode, WindowMode::WINDOW_MODE_FLOATING); 534 /** 535 * @tc.steps: step4. Set windowMode WINDOW_MODE_UNDEFINED value 536 */ __anon8c69ff5c0802() 537 windowManager->SetWindowGetModeCallBack([]() { 538 return WindowMode::WINDOW_MODE_UNDEFINED; 539 }); 540 /** 541 * @tc.steps: step5. Get windowMode from uiContext 542 */ 543 windowMode = uiContext_->GetWindowMode(); 544 /** 545 * @tc.steps: step6. windowMode must be WINDOW_MODE_UNDEFINED 546 */ 547 EXPECT_EQ(windowMode, WindowMode::WINDOW_MODE_UNDEFINED); 548 /** 549 * @tc.expected: step7. Task should be added without errors or crashes 550 */ 551 SUCCEED(); 552 } 553 554 /** 555 * @tc.name: GetIsMidScene 556 * @tc.desc: Test get windowMode to the normal task list 557 * @tc.type: FUNC 558 */ 559 HWTEST_F(UIContextImplTest, GetIsMidScene, TestSize.Level1) 560 { 561 ASSERT_NE(uiContext_->context_, nullptr); 562 auto windowManager = uiContext_->context_->GetWindowManager(); 563 ASSERT_NE(windowManager, nullptr); 564 /** 565 * @tc.steps: step1. Set isMidscene false value 566 */ __anon8c69ff5c0902(bool& isMidScene) 567 windowManager->SetWindowGetIsMidSceneCallBack([](bool& isMidScene) { 568 isMidScene = false; 569 return 0; 570 }); 571 /** 572 * @tc.steps: step2. Get isMidscene from uiContext 573 */ 574 auto isMidScene = uiContext_->GetIsMidScene(); 575 /** 576 * @tc.steps: step4. isMidscene must be false 577 */ 578 EXPECT_FALSE(isMidScene); 579 /** 580 * @tc.steps: step5. Set isMidscene true value 581 */ __anon8c69ff5c0a02(bool& isMidScene) 582 windowManager->SetWindowGetIsMidSceneCallBack([](bool& isMidScene) { 583 isMidScene = true; 584 return 0; 585 }); 586 /** 587 * @tc.steps: step6. Get isMidscene from uiContext 588 */ 589 isMidScene = uiContext_->GetIsMidScene(); 590 /** 591 * @tc.steps: step7. isMidscene must be true 592 */ 593 EXPECT_TRUE(isMidScene); 594 /** 595 * @tc.expected: step8. Task should be added without errors or crashes 596 */ 597 SUCCEED(); 598 } 599 600 /** 601 * @tc.name: GetIsMidScene 602 * @tc.desc: Test get windowMode to the normal task list 603 * @tc.type: FUNC 604 */ 605 HWTEST_F(UIContextImplTest, IsAccessibilityEnabled, TestSize.Level1) 606 { 607 /** 608 * @tc.steps: step1. Set accessibilityEnabled false value 609 */ 610 OHOS::Ace::AceApplicationInfo::GetInstance().SetAccessibilityEnabled(false); 611 /** 612 * @tc.steps: step2. Get isAccessibilityEnabled from uiContext 613 */ 614 auto isAccessibilityEnabled = uiContext_->IsAccessibilityEnabled(); 615 /** 616 * @tc.steps: step3. isAccessibilityEnabled must be false 617 */ 618 EXPECT_FALSE(isAccessibilityEnabled); 619 /** 620 * @tc.steps: step4. Set accessibilityEnable true value 621 */ 622 OHOS::Ace::AceApplicationInfo::GetInstance().SetAccessibilityEnabled(true); 623 /** 624 * @tc.steps: step5. Get isAccessibilityEnabled from uiContext 625 */ 626 isAccessibilityEnabled = uiContext_->IsAccessibilityEnabled(); 627 /** 628 * @tc.steps: step6. Set accessibilityEnabled true value 629 */ 630 EXPECT_TRUE(isAccessibilityEnabled); 631 /** 632 * @tc.expected: step7. Task should be added without errors or crashes 633 */ 634 SUCCEED(); 635 } 636 637 638 /** 639 * @tc.name: SurfaceChangedCallback 640 * @tc.desc: Test surfaceChangedCallback to the normal task list 641 * @tc.type: FUNC 642 */ 643 HWTEST_F(UIContextImplTest, SurfaceChangedCallback, TestSize.Level1) 644 { 645 /** 646 * @tc.steps: step1. Initialize a flag to track task execution status 647 */ 648 bool taskExecuted = false; 649 /** 650 * @tc.steps: step2. Add a task to the normal task list 651 */ 652 int32_t id = uiContext_->RegisterSurfaceChangedCallback([&taskExecuted](int32_t, int32_t, int32_t, int32_t, __anon8c69ff5c0b02(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason) 653 WindowSizeChangeReason) { 654 taskExecuted = true; 655 }); 656 uiContext_->UnregisterSurfaceChangedCallback(id); 657 ASSERT_NE(uiContext_->context_, nullptr); 658 /** 659 * @tc.expected: step3. Task should be added without errors or crashes 660 */ 661 EXPECT_FALSE(taskExecuted); 662 SUCCEED(); 663 } 664 665 /** 666 * @tc.name: FoldStatusChangedCallback 667 * @tc.desc: Test foldStatusChangedCallback to the normal task list 668 * @tc.type: FUNC 669 */ 670 HWTEST_F(UIContextImplTest, FoldStatusChangedCallback, TestSize.Level1) 671 { 672 /** 673 * @tc.steps: step1. Initialize a flag to track task execution status 674 */ 675 bool taskExecuted = false; 676 /** 677 * @tc.steps: step2. Add a task to the normal task list 678 */ __anon8c69ff5c0c02(FoldStatus) 679 int32_t id = uiContext_->RegisterFoldStatusChangedCallback([&taskExecuted](FoldStatus) { 680 taskExecuted = true; 681 }); 682 uiContext_->UnRegisterFoldStatusChangedCallback(id); 683 ASSERT_NE(uiContext_->context_, nullptr); 684 uiContext_->context_->OnFoldStatusChange(FoldStatus::UNKNOWN); 685 /** 686 * @tc.expected: step3. Task should be added without errors or crashes 687 */ 688 EXPECT_FALSE(taskExecuted); 689 SUCCEED(); 690 } 691 692 /** 693 * @tc.name: FoldStatusChangedCallback 694 * @tc.desc: Test foldStatusChangedCallback to the normal task list 695 * @tc.type: FUNC 696 */ 697 HWTEST_F(UIContextImplTest, RotationEndCallback, TestSize.Level1) 698 { 699 /** 700 * @tc.steps: step1. Initialize a flag to track task execution status 701 */ 702 bool taskExecuted = false; 703 /** 704 * @tc.steps: step2. Add a task to the normal task list 705 */ __anon8c69ff5c0d02() 706 int32_t id = uiContext_->RegisterRotationEndCallback([&taskExecuted]() { 707 taskExecuted = true; 708 }); 709 uiContext_->UnregisterRotationEndCallback(id); 710 ASSERT_NE(uiContext_->context_, nullptr); 711 /** 712 * @tc.expected: step3. Task should be added without errors or crashes 713 */ 714 EXPECT_FALSE(taskExecuted); 715 SUCCEED(); 716 } 717 718 /** 719 * @tc.name: AddWindowSizeChangeCallbackTest001 720 * @tc.desc: Test AddWindowSizeChangeCallback 721 * @tc.type: FUNC 722 */ 723 HWTEST_F(UIContextImplTest, AddWindowSizeChangeCallbackTest001, TestSize.Level1) 724 { 725 /** 726 * @tc.steps: step1. Call AddWindowSizeChangeCallback on valid context 727 * @tc.expected: step1. Should complete without errors 728 */ 729 uiContext_->AddWindowSizeChangeCallback(1); 730 SUCCEED(); 731 } 732 } // namespace OHOS::Ace::Kit 733