1 /* 2 * Copyright (c) 2022 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 <gtest/gtest.h> 17 #include <transaction/rs_transaction.h> 18 #include "display_manager.h" 19 #include "input_window_monitor.h" 20 #include "iremote_object_mocker.h" 21 #include "minimize_app.h" 22 #include "mock_RSIWindowAnimationController.h" 23 #include "remote_animation.h" 24 #include "starting_window.h" 25 #include "window_helper.h" 26 using namespace testing; 27 using namespace testing::ext; 28 29 namespace OHOS { 30 namespace Rosen { 31 namespace { 32 constexpr uint32_t SLEEP_TIME_IN_US = 10000; 33 } 34 35 class RemoteAnimationTest : public testing::Test { 36 public: 37 static void SetUpTestCase(); 38 static void TearDownTestCase(); 39 void SetUp() override; 40 void TearDown() override; 41 void InitRemoteAnimation(); 42 void CreateWindowNodeContainer(); 43 private: 44 RSSurfaceNode::SharedPtr CreateRSSurfaceNode(uint32_t windowId); 45 sptr<WindowProperty> CreateWindowProperty(uint32_t windowId); 46 Rect GetSurfaceBoundsRect(sptr<WindowNode> node); 47 sptr<RSIWindowAnimationController> animationController_; 48 sptr<WindowRoot> windowRoot_; 49 sptr<WindowController> windowController_; 50 std::shared_ptr<AppExecFwk::EventHandler> wmsTaskHandler_; 51 sptr<WindowTransitionInfo> transitionInfo_ = nullptr; 52 sptr<WindowNode> node_ = nullptr; 53 }; 54 SetUpTestCase()55 void RemoteAnimationTest::SetUpTestCase() 56 { 57 } 58 TearDownTestCase()59 void RemoteAnimationTest::TearDownTestCase() 60 { 61 } 62 SetUp()63 void RemoteAnimationTest::SetUp() 64 { 65 InitRemoteAnimation(); 66 CreateWindowNodeContainer(); 67 transitionInfo_ = new WindowTransitionInfo(); 68 sptr<IRemoteObject> token = new IRemoteObjectMocker(); 69 transitionInfo_->SetAbilityToken(token); 70 transitionInfo_->displayId_ = 0; 71 transitionInfo_->supportWindowModes_ = { 72 AppExecFwk::SupportWindowMode::FULLSCREEN, 73 AppExecFwk::SupportWindowMode::SPLIT, 74 AppExecFwk::SupportWindowMode::FLOATING 75 }; 76 windowController_->StartingWindow(transitionInfo_, nullptr, 0xFFFFFFFF, true); 77 node_ = windowRoot_->FindWindowNodeWithToken(transitionInfo_->GetAbilityToken()); 78 EXPECT_NE(nullptr, node_); 79 } 80 TearDown()81 void RemoteAnimationTest::TearDown() 82 { 83 if (node_ != nullptr) { 84 windowController_->DestroyWindow(node_->GetWindowId(), false); 85 node_ = nullptr; 86 } 87 animationController_ = nullptr; 88 wmsTaskHandler_ = nullptr; 89 windowRoot_ = nullptr; 90 windowController_ = nullptr; 91 transitionInfo_ = nullptr; 92 } 93 InitRemoteAnimation()94 void RemoteAnimationTest::InitRemoteAnimation() 95 { 96 animationController_ = new RSIWindowAnimationControllerMocker(); 97 EXPECT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(animationController_)); 98 RemoteAnimation::isRemoteAnimationEnable_ = true; 99 RemoteAnimation::animationFirst_ = true; 100 windowRoot_ = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {}); 101 sptr<InputWindowMonitor> inputMonitor = new InputWindowMonitor(windowRoot_); 102 windowController_ = new WindowController(windowRoot_, inputMonitor); 103 RemoteAnimation::SetWindowControllerAndRoot(windowController_, windowRoot_); 104 auto runner = AppExecFwk::EventRunner::Create("RemoteAnimationTest"); 105 wmsTaskHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner); 106 RemoteAnimation::SetMainTaskHandler(wmsTaskHandler_); 107 } 108 CreateWindowNodeContainer()109 void RemoteAnimationTest::CreateWindowNodeContainer() 110 { 111 auto display = DisplayManager::GetInstance().GetDefaultDisplay(); 112 ASSERT_TRUE((display != nullptr)); 113 sptr<DisplayInfo> displayInfo = display->GetDisplayInfo(); 114 ASSERT_TRUE((displayInfo != nullptr)); 115 windowRoot_->CreateWindowNodeContainer(0, displayInfo); 116 } 117 CreateWindowProperty(uint32_t windowId)118 sptr<WindowProperty> RemoteAnimationTest::CreateWindowProperty(uint32_t windowId) 119 { 120 sptr<WindowProperty> property = new WindowProperty(); 121 property->SetWindowId(windowId); 122 return property; 123 } 124 GetSurfaceBoundsRect(sptr<WindowNode> node)125 Rect RemoteAnimationTest::GetSurfaceBoundsRect(sptr<WindowNode> node) 126 { 127 if (!node->leashWinSurfaceNode_) { 128 return {0, 0, 0, 0}; 129 } 130 auto& stagingProperties = node->leashWinSurfaceNode_->GetStagingProperties(); 131 auto bounds = stagingProperties.GetBounds(); 132 Rect rect = {bounds[0], bounds[1], bounds[2], bounds[3]}; // 1, 2, 3 is index 133 return rect; 134 } 135 CreateRSSurfaceNode(uint32_t windowId)136 RSSurfaceNode::SharedPtr RemoteAnimationTest::CreateRSSurfaceNode(uint32_t windowId) 137 { 138 struct RSSurfaceNodeConfig rsSurfaceNodeConfig; 139 rsSurfaceNodeConfig.SurfaceNodeName = "AppSurfaceNode" + std::to_string(windowId); 140 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); 141 return surfaceNode; 142 } 143 144 namespace { 145 /** 146 * @tc.name: IsRemoteAnimationEnabledAndFirst01 147 * @tc.desc: IsRemoteAnimationEnabledAndFirst return false since animationFirst false 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(RemoteAnimationTest, IsRemoteAnimationEnabledAndFirst01, Function | SmallTest | Level2) 151 { 152 RemoteAnimation::SetAnimationFirst(false); 153 EXPECT_EQ(false, RemoteAnimation::animationFirst_); 154 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 155 } 156 157 /** 158 * @tc.name: IsRemoteAnimationEnabledAndFirst02 159 * @tc.desc: IsRemoteAnimationEnabledAndFirst return true since animationFirst true 160 * @tc.type: FUNC 161 */ 162 HWTEST_F(RemoteAnimationTest, IsRemoteAnimationEnabledAndFirst02, Function | SmallTest | Level2) 163 { 164 EXPECT_EQ(true, RemoteAnimation::animationFirst_); 165 EXPECT_EQ(true, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 166 } 167 168 /** 169 * @tc.name: IsRemoteAnimationEnabledAndFirst03 170 * @tc.desc: IsRemoteAnimationEnabledAndFirst return false since CheckRemoteAnimationEnabled false 171 * @tc.type: FUNC 172 */ 173 HWTEST_F(RemoteAnimationTest, IsRemoteAnimationEnabledAndFirst03, Function | SmallTest | Level2) 174 { 175 RemoteAnimation::windowRoot_ = nullptr; 176 EXPECT_EQ(false, RemoteAnimation::CheckRemoteAnimationEnabled(0)); 177 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 178 RemoteAnimation::windowRoot_ = windowRoot_; 179 auto container = RemoteAnimation::windowRoot_->GetOrCreateWindowNodeContainer(0); 180 EXPECT_NE(nullptr, container); 181 container->isScreenLocked_ = true; 182 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 183 } 184 185 /** 186 * @tc.name: IsRemoteAnimationEnabledAndFirst04 187 * @tc.desc: return false since CheckRemoteAnimationEnabled false, set animationController nullptr 188 * @tc.type: FUNC 189 */ 190 HWTEST_F(RemoteAnimationTest, IsRemoteAnimationEnabledAndFirst04, Function | SmallTest | Level2) 191 { 192 sptr<RSIWindowAnimationController> controller = nullptr; 193 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, RemoteAnimation::SetWindowAnimationController(controller)); 194 RemoteAnimation::windowAnimationController_ = nullptr; 195 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 196 controller = new RSIWindowAnimationControllerMocker(); 197 RemoteAnimation::isRemoteAnimationEnable_ = false; 198 EXPECT_EQ(WMError::WM_ERROR_NO_REMOTE_ANIMATION, RemoteAnimation::SetWindowAnimationController(controller)); 199 EXPECT_EQ(false, RemoteAnimation::CheckRemoteAnimationEnabled(0)); 200 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 201 RemoteAnimation::isRemoteAnimationEnable_ = true; 202 EXPECT_EQ(WMError::WM_OK, RemoteAnimation::SetWindowAnimationController(controller)); 203 EXPECT_EQ(true, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 204 RemoteAnimation::SetAnimationFirst(false); 205 EXPECT_EQ(false, RemoteAnimation::animationFirst_); 206 EXPECT_EQ(false, RemoteAnimation::IsRemoteAnimationEnabledAndFirst(0)); 207 } 208 209 /** 210 * @tc.name: CheckTransition01 211 * @tc.desc: CheckTransition return false 212 * @tc.type: FUNC 213 */ 214 HWTEST_F(RemoteAnimationTest, CheckTransition01, Function | SmallTest | Level2) 215 { 216 const sptr<WindowNode> node = nullptr; 217 EXPECT_EQ(false, RemoteAnimation::CheckTransition(transitionInfo_, node, transitionInfo_, node)); 218 sptr<WindowNode> srcNode = StartingWindow::CreateWindowNode(transitionInfo_, 0); 219 ASSERT_NE(nullptr, srcNode); 220 srcNode->leashWinSurfaceNode_ = nullptr; // leash and app surface node is nullptr 221 EXPECT_EQ(false, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, srcNode)); 222 srcNode->surfaceNode_ = CreateRSSurfaceNode(0); // leash is null, but surfaceNode is not 223 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, srcNode)); 224 srcNode = StartingWindow::CreateWindowNode(transitionInfo_, 0); // leash and app surfaceNode both not nullptr 225 ASSERT_NE(nullptr, srcNode); 226 sptr<WindowNode> dstNode = StartingWindow::CreateWindowNode(transitionInfo_, 1); 227 ASSERT_NE(nullptr, dstNode); 228 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, node, transitionInfo_, dstNode)); 229 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, node)); 230 dstNode->leashWinSurfaceNode_ = nullptr; 231 EXPECT_EQ(false, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, dstNode)); 232 dstNode->surfaceNode_ = CreateRSSurfaceNode(1); // leash is null, but surfaceNode is not 233 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, dstNode)); 234 } 235 236 /** 237 * @tc.name: CheckTransition02 238 * @tc.desc: CheckTransition return false since windowMode not support 239 * @tc.type: FUNC 240 */ 241 HWTEST_F(RemoteAnimationTest, CheckTransition02, Function | SmallTest | Level2) 242 { 243 sptr<WindowNode> srcNode = StartingWindow::CreateWindowNode(transitionInfo_, 0); 244 ASSERT_NE(nullptr, srcNode); 245 sptr<WindowNode> dstNode = StartingWindow::CreateWindowNode(transitionInfo_, 1); 246 ASSERT_NE(nullptr, dstNode); 247 dstNode->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); 248 dstNode->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); 249 ASSERT_EQ(false, WindowHelper::CheckSupportWindowMode(dstNode->GetWindowMode(), 250 dstNode->GetModeSupportInfo(), transitionInfo_)); 251 EXPECT_EQ(false, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, dstNode)); 252 } 253 254 /** 255 * @tc.name: CheckTransition03 256 * @tc.desc: CheckTransition return true 257 * @tc.type: FUNC 258 */ 259 HWTEST_F(RemoteAnimationTest, CheckTransition03, Function | SmallTest | Level2) 260 { 261 sptr<WindowNode> srcNode = StartingWindow::CreateWindowNode(transitionInfo_, 0); 262 ASSERT_NE(nullptr, srcNode); 263 sptr<WindowNode> dstNode = StartingWindow::CreateWindowNode(transitionInfo_, 1); 264 ASSERT_NE(nullptr, dstNode); 265 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, nullptr, dstNode)); 266 EXPECT_EQ(true, RemoteAnimation::CheckTransition(transitionInfo_, srcNode, transitionInfo_, dstNode)); 267 } 268 269 /** 270 * @tc.name: OnRemoteDieAndCallbackTimeOutProcess01 271 * @tc.desc: OnRemoteDie and setAnimationController nullptr 272 * @tc.type: FUNC 273 */ 274 HWTEST_F(RemoteAnimationTest, OnRemoteDieAndCallbackTimeOutProcess01, Function | SmallTest | Level2) 275 { 276 auto testController = RemoteAnimation::windowAnimationController_; 277 ASSERT_EQ(true, RemoteAnimation::windowAnimationController_->AsObject() == animationController_->AsObject()); 278 RemoteAnimation::OnRemoteDie(animationController_->AsObject()); // controller is not nullptr 279 EXPECT_EQ(false, RemoteAnimation::CheckAnimationController()); 280 RemoteAnimation::OnRemoteDie(testController->AsObject()); // controller is nullptr 281 RemoteAnimation::SetAnimationFirst(false); 282 RemoteAnimation::OnRemoteDie(testController->AsObject()); // controller is nullptr 283 } 284 285 /** 286 * @tc.name: OnRemoteDieAndCallbackTimeOutProcess02 287 * @tc.desc: OnRemoteDie and not set animation controller 288 * @tc.type: FUNC 289 */ 290 HWTEST_F(RemoteAnimationTest, OnRemoteDieAndCallbackTimeOutProcess02, Function | SmallTest | Level2) 291 { 292 sptr<IRemoteObject> remoteObject = nullptr; 293 RemoteAnimation::windowRoot_ = nullptr; 294 RemoteAnimation::OnRemoteDie(remoteObject); // controller is not nullptr 295 EXPECT_EQ(true, RemoteAnimation::CheckAnimationController()); 296 } 297 298 /** 299 * @tc.name: OnRemoteDieAndCallbackTimeOutProcess03 300 * @tc.desc: OnRemoteDie and timeout process success 301 * @tc.type: FUNC 302 */ 303 HWTEST_F(RemoteAnimationTest, OnRemoteDieAndCallbackTimeOutProcess03, Function | SmallTest | Level2) 304 { 305 auto root = RemoteAnimation::windowRoot_; 306 node_->stateMachine_.TransitionTo(WindowNodeState::SHOW_ANIMATION_PLAYING); 307 auto testController = RemoteAnimation::windowAnimationController_; 308 RemoteAnimation::OnRemoteDie(testController->AsObject()); // controller is not nullptr 309 EXPECT_EQ(false, RemoteAnimation::CheckAnimationController()); 310 EXPECT_EQ(true, node_->stateMachine_.currState_ == WindowNodeState::SHOW_ANIMATION_DONE); 311 } 312 313 /** 314 * @tc.name: CreateWindowAnimationTarget01 315 * @tc.desc: CreateWindowAnimationTarget with null node/different windowType 316 * @tc.type: FUNC 317 */ 318 HWTEST_F(RemoteAnimationTest, CreateWindowAnimationTarget01, Function | SmallTest | Level2) 319 { 320 sptr<WindowNode> node = nullptr; 321 EXPECT_EQ(nullptr, RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, node)); 322 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(1)); // 1 is windowId 323 EXPECT_EQ(nullptr, RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, srcNode)); // no surfaceNode 324 srcNode->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); 325 EXPECT_EQ(nullptr, RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, srcNode)); // no surfaceNode 326 EXPECT_NE(nullptr, RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, node_)); 327 node_->startingWinSurfaceNode_ = nullptr; 328 EXPECT_NE(nullptr, RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, node_)); // start win null 329 } 330 331 /** 332 * @tc.name: CreateShowAnimationFinishedCallback01 333 * @tc.desc: CreateShowAnimationFinishedCallback with animationFirst false 334 * @tc.type: FUNC 335 */ 336 HWTEST_F(RemoteAnimationTest, CreateShowAnimationFinishedCallback01, Function | SmallTest | Level2) 337 { 338 RemoteAnimation::SetAnimationFirst(false); 339 auto finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(node_, node_, true); 340 EXPECT_NE(nullptr, finishCallback); 341 finishCallback->OnAnimationFinished(); // not animation playing 342 usleep(SLEEP_TIME_IN_US); 343 344 node_->stateMachine_.TransitionTo(WindowNodeState::SHOW_ANIMATION_PLAYING); 345 finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(node_, node_, true); 346 EXPECT_NE(nullptr, finishCallback); 347 finishCallback->OnAnimationFinished(); // leashSurfaceNode is not nullptr 348 usleep(SLEEP_TIME_IN_US); 349 350 sptr<WindowNode> dstNode = nullptr; 351 finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(node_, dstNode, true); 352 EXPECT_NE(nullptr, finishCallback); 353 finishCallback->OnAnimationFinished(); // dstNode is nullptr 354 usleep(SLEEP_TIME_IN_US); 355 356 dstNode = new WindowNode(CreateWindowProperty(1)); // leashSurfaceNode is nullptr 357 dstNode->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 358 finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(node_, dstNode, true); 359 EXPECT_NE(nullptr, finishCallback); 360 finishCallback->OnAnimationFinished(); 361 usleep(SLEEP_TIME_IN_US); 362 } 363 364 /** 365 * @tc.name: CreateShowAnimationFinishedCallback02 366 * @tc.desc: CreateShowAnimationFinishedCallback with animationFirst true 367 * @tc.type: FUNC 368 */ 369 HWTEST_F(RemoteAnimationTest, CreateShowAnimationFinishedCallback02, Function | SmallTest | Level2) 370 { 371 sptr<WindowNode> dstNode = nullptr; 372 auto finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(node_, dstNode, true); 373 EXPECT_NE(nullptr, finishCallback); 374 finishCallback->OnAnimationFinished(); // dstNode is nullptr 375 usleep(SLEEP_TIME_IN_US); 376 377 sptr<WindowNode> srcNode = nullptr; 378 finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(srcNode, node_, true); 379 EXPECT_NE(nullptr, finishCallback); 380 finishCallback->OnAnimationFinished(); // process srcNode state task with nullptr, node task count < 0 381 usleep(SLEEP_TIME_IN_US); 382 383 srcNode = nullptr; 384 node_->stateMachine_.ResetAnimationTaskCount(2); // 2 is animationCount 385 finishCallback = RemoteAnimation::CreateShowAnimationFinishedCallback(srcNode, node_, false); 386 EXPECT_NE(nullptr, finishCallback); 387 finishCallback->OnAnimationFinished(); // process srcNode state task with nullptr, node task count > 0 388 usleep(SLEEP_TIME_IN_US); 389 } 390 391 /** 392 * @tc.name: CreateHideAnimationFinishedCallback01 393 * @tc.desc: CreateHideAnimationFinishedCallback with animationFirst false 394 * @tc.type: FUNC 395 */ 396 HWTEST_F(RemoteAnimationTest, CreateHideAnimationFinishedCallback01, Function | SmallTest | Level2) 397 { 398 RemoteAnimation::SetAnimationFirst(false); 399 sptr<WindowNode> srcNode = nullptr; 400 auto finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(srcNode, TransitionEvent::MINIMIZE); 401 EXPECT_NE(nullptr, finishCallback); 402 finishCallback->OnAnimationFinished(); // srcNode is nullptr 403 usleep(SLEEP_TIME_IN_US); 404 405 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::MINIMIZE); 406 EXPECT_NE(nullptr, finishCallback); 407 finishCallback->OnAnimationFinished(); // not hide animation playing 408 usleep(SLEEP_TIME_IN_US); 409 EXPECT_NE(WindowNodeState::HIDE_ANIMATION_DONE, node_->stateMachine_.currState_); 410 411 node_->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 412 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::CLOSE); 413 EXPECT_NE(nullptr, finishCallback); 414 finishCallback->OnAnimationFinished(); // hide animation playing and with close 415 usleep(SLEEP_TIME_IN_US); 416 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, node_->stateMachine_.currState_); 417 418 node_->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 419 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::MINIMIZE); 420 EXPECT_NE(nullptr, finishCallback); 421 finishCallback->OnAnimationFinished(); // hide animation playing and with MINIMIZE 422 usleep(SLEEP_TIME_IN_US); 423 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, node_->stateMachine_.currState_); 424 425 node_->stateMachine_.TransitionTo(WindowNodeState::STARTING_CREATED); 426 node_->abilityToken_ = nullptr; 427 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::MINIMIZE); 428 EXPECT_NE(nullptr, finishCallback); 429 finishCallback->OnAnimationFinished(); // abilityToken is nullptr 430 usleep(SLEEP_TIME_IN_US); 431 EXPECT_EQ(WindowNodeState::STARTING_CREATED, node_->stateMachine_.currState_); 432 } 433 434 /** 435 * @tc.name: CreateHideAnimationFinishedCallback02 436 * @tc.desc: CreateHideAnimationFinishedCallback with animationFirst true 437 * @tc.type: FUNC 438 */ 439 HWTEST_F(RemoteAnimationTest, CreateHideAnimationFinishedCallback02, Function | SmallTest | Level2) 440 { 441 sptr<WindowNode> srcNode = nullptr; 442 auto finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(srcNode, TransitionEvent::CLOSE); 443 EXPECT_NE(nullptr, finishCallback); 444 finishCallback->OnAnimationFinished(); // srcNode is nullptr 445 usleep(SLEEP_TIME_IN_US); 446 447 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::MINIMIZE); 448 EXPECT_NE(nullptr, finishCallback); 449 finishCallback->OnAnimationFinished(); // with minimize 450 usleep(SLEEP_TIME_IN_US); 451 452 node_->firstFrameAvailable_ = true; 453 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::CLOSE); 454 EXPECT_NE(nullptr, finishCallback); 455 finishCallback->OnAnimationFinished(); // create hide callback with firstFrameAvailable_ true 456 usleep(SLEEP_TIME_IN_US); 457 458 node_->firstFrameAvailable_ = false; 459 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::CLOSE); 460 EXPECT_NE(nullptr, finishCallback); 461 finishCallback->OnAnimationFinished(); // create hide callback with surfaceNode null 462 usleep(SLEEP_TIME_IN_US); 463 464 node_->firstFrameAvailable_ = false; 465 node_->surfaceNode_ = CreateRSSurfaceNode(1); 466 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::CLOSE); 467 EXPECT_NE(nullptr, finishCallback); 468 finishCallback->OnAnimationFinished(); // create hide callback with surfaceNode not null 469 usleep(SLEEP_TIME_IN_US); 470 471 node_->leashWinSurfaceNode_ = CreateRSSurfaceNode(1); 472 finishCallback = RemoteAnimation::CreateHideAnimationFinishedCallback(node_, TransitionEvent::CLOSE); 473 EXPECT_NE(nullptr, finishCallback); 474 finishCallback->OnAnimationFinished(); // create hide callback with leashWinSurfaceNode_ null 475 usleep(SLEEP_TIME_IN_US); 476 } 477 478 /** 479 * @tc.name: ProcessNodeStateTask01 480 * @tc.desc: ProcessNodeStateTask with different node state 481 * @tc.type: FUNC 482 */ 483 HWTEST_F(RemoteAnimationTest, ProcessNodeStateTask01, Function | SmallTest | Level2) 484 { 485 // ExecuteFinalStateTask with task is nullptr 486 node_->stateMachine_.ResetAnimationTaskCount(1); 487 RemoteAnimation::ProcessNodeStateTask(node_); 488 usleep(SLEEP_TIME_IN_US); 489 EXPECT_EQ(WindowNodeState::STARTING_CREATED, node_->stateMachine_.currState_); 490 491 node_->stateMachine_.ResetAnimationTaskCount(1); 492 node_->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 493 RemoteAnimation::ProcessNodeStateTask(node_); // hide animation playing 494 usleep(SLEEP_TIME_IN_US); 495 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, node_->stateMachine_.currState_); 496 497 RemoteAnimation::windowRoot_ = nullptr; 498 node_->stateMachine_.ResetAnimationTaskCount(1); 499 RemoteAnimation::ProcessNodeStateTask(node_); // hide animation playing and windowRoot is nullptr 500 usleep(SLEEP_TIME_IN_US); 501 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, node_->stateMachine_.currState_); 502 503 RemoteAnimation::windowRoot_ = windowRoot_; 504 node_->stateMachine_.TransitionTo(WindowNodeState::SHOW_ANIMATION_PLAYING); 505 node_->stateMachine_.ResetAnimationTaskCount(1); 506 RemoteAnimation::ProcessNodeStateTask(node_); // show animation playing 507 usleep(SLEEP_TIME_IN_US); 508 EXPECT_EQ(WindowNodeState::SHOW_ANIMATION_DONE, node_->stateMachine_.currState_); 509 510 bool taskExecute = false; __anon9b4652ba0402null511 node_->stateMachine_.SetDestroyTask([&taskExecute] {taskExecute = true;}); 512 node_->stateMachine_.ResetAnimationTaskCount(1); 513 RemoteAnimation::ProcessNodeStateTask(node_); // execute destroy task 514 usleep(SLEEP_TIME_IN_US); 515 EXPECT_EQ(true, taskExecute); 516 517 RemoteAnimation::windowRoot_ = nullptr; 518 node_->stateMachine_.ResetAnimationTaskCount(1); 519 RemoteAnimation::ProcessNodeStateTask(node_); // show animation playing and windowRoot is nullptr 520 usleep(SLEEP_TIME_IN_US); 521 EXPECT_EQ(WindowNodeState::SHOW_ANIMATION_DONE, node_->stateMachine_.currState_); 522 523 wmsTaskHandler_ = nullptr; 524 RemoteAnimation::wmsTaskHandler_ = wmsTaskHandler_; 525 node_->stateMachine_.ResetAnimationTaskCount(1); __anon9b4652ba0502null526 node_->stateMachine_.SetDestroyTask([&taskExecute] {taskExecute = false;}); 527 RemoteAnimation::ExecuteFinalStateTask(node_); // handler is nullptr 528 usleep(SLEEP_TIME_IN_US); 529 EXPECT_EQ(true, taskExecute); 530 } 531 532 /** 533 * @tc.name: PostProcessShowCallback01 534 * @tc.desc: PostProcessShowCallback with different leashWinSurfaceNode 535 * @tc.type: FUNC 536 */ 537 HWTEST_F(RemoteAnimationTest, PostProcessShowCallback01, Function | SmallTest | Level2) 538 { 539 sptr<WindowNode> dstNode = nullptr; 540 RemoteAnimation::PostProcessShowCallback(dstNode); 541 usleep(SLEEP_TIME_IN_US); 542 543 Rect expectRect = {0, 0, 100, 100}; // 100 is test data 544 node_->SetWindowRect(expectRect); 545 RemoteAnimation::PostProcessShowCallback(node_); 546 usleep(SLEEP_TIME_IN_US); 547 Rect actualRect = GetSurfaceBoundsRect(node_); 548 EXPECT_EQ(expectRect, actualRect); 549 node_->leashWinSurfaceNode_ = nullptr; 550 RemoteAnimation::PostProcessShowCallback(node_); 551 } 552 553 /** 554 * @tc.name: GetTransitionEvent01 555 * @tc.desc: GetTransitionEvent with reason not ability_transition 556 * @tc.type: FUNC 557 */ 558 HWTEST_F(RemoteAnimationTest, GetTransitionEvent01, Function | SmallTest | Level2) 559 { 560 transitionInfo_->SetTransitionReason(TransitionReason::MINIMIZE); 561 auto event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 562 EXPECT_EQ(TransitionEvent::MINIMIZE, event); 563 564 transitionInfo_->SetTransitionReason(TransitionReason::BACK_TRANSITION); 565 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 566 EXPECT_EQ(TransitionEvent::BACK_TRANSITION, event); 567 568 transitionInfo_->SetTransitionReason(TransitionReason::CLOSE); 569 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 570 EXPECT_EQ(TransitionEvent::CLOSE, event); 571 572 node_->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 573 transitionInfo_->SetTransitionReason(TransitionReason::CLOSE); 574 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 575 EXPECT_EQ(TransitionEvent::UNKNOWN, event); 576 } 577 578 /** 579 * @tc.name: GetTransitionEvent02 580 * @tc.desc: GetTransitionEvent with reason ability_transition 581 * @tc.type: FUNC 582 */ 583 HWTEST_F(RemoteAnimationTest, GetTransitionEvent02, Function | SmallTest | Level2) 584 { 585 sptr<WindowNode> srcNode = nullptr; 586 transitionInfo_->SetTransitionReason(TransitionReason::ABILITY_TRANSITION); 587 auto event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, srcNode, node_); 588 EXPECT_EQ(TransitionEvent::APP_TRANSITION, event); 589 590 sptr<WindowNode> dstNode = nullptr; 591 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, dstNode); 592 EXPECT_EQ(TransitionEvent::UNKNOWN, event); 593 594 node_->stateMachine_.TransitionTo(WindowNodeState::SHOW_ANIMATION_PLAYING); 595 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 596 EXPECT_EQ(TransitionEvent::UNKNOWN, event); 597 598 transitionInfo_->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); 599 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 600 EXPECT_EQ(TransitionEvent::HOME, event); 601 602 transitionInfo_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); 603 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, node_); 604 EXPECT_EQ(TransitionEvent::UNKNOWN, event); 605 606 transitionInfo_->SetAbilityToken(nullptr); 607 event = RemoteAnimation::GetTransitionEvent(transitionInfo_, transitionInfo_, node_, dstNode); 608 EXPECT_EQ(TransitionEvent::UNKNOWN, event); 609 } 610 611 /** 612 * @tc.name: GetExpectRect01 613 * @tc.desc: GetExpectRect 614 * @tc.type: FUNC 615 */ 616 HWTEST_F(RemoteAnimationTest, GetExpectRect01, Function | SmallTest | Level2) 617 { 618 auto target = RemoteAnimation::CreateWindowAnimationTarget(transitionInfo_, node_); 619 RemoteAnimation::GetExpectRect(node_, target); 620 Rect actualRect = GetSurfaceBoundsRect(node_); 621 EXPECT_EQ(node_->GetWindowRect(), actualRect); // avoidRect is empty thus return 622 623 sptr<WindowNode> statusBar = new WindowNode(CreateWindowProperty(0)); 624 ASSERT_NE(nullptr, statusBar); 625 statusBar->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); 626 statusBar->SetWindowRect({0, 0, 100, 100}); 627 windowRoot_->windowNodeMap_[0] = statusBar; 628 629 Rect avoidRect = windowRoot_->GetDisplayRectWithoutSystemBarAreas(node_); 630 EXPECT_FALSE(WindowHelper::IsEmptyRect(avoidRect)); 631 632 RemoteAnimation::GetExpectRect(node_, target); 633 actualRect = GetSurfaceBoundsRect(node_); 634 EXPECT_EQ(avoidRect, actualRect); // get expect rect 635 636 node_->leashWinSurfaceNode_ = nullptr; 637 RemoteAnimation::GetExpectRect(node_, target); 638 639 node_->GetWindowProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); 640 RemoteAnimation::GetExpectRect(node_, target); 641 EXPECT_FALSE(WindowHelper::IsMainFullScreenWindow(node_->GetWindowType(), node_->GetWindowMode())); 642 643 RemoteAnimation::windowRoot_ = nullptr; 644 RemoteAnimation::GetExpectRect(node_, target); 645 646 node_->GetWindowProperty()->SetWindowFlags(0); 647 RemoteAnimation::GetExpectRect(node_, target); 648 bool needAvoid = (node_->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID)); 649 EXPECT_EQ(false, needAvoid); 650 } 651 652 /** 653 * @tc.name: NotifyAnimationTransition01 654 * @tc.desc: NotifyAnimationTransition failed 655 * @tc.type: FUNC 656 */ 657 HWTEST_F(RemoteAnimationTest, NotifyAnimationTransition01, Function | SmallTest | Level2) 658 { 659 sptr<WindowNode> dstNode = nullptr; 660 WMError ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, node_, dstNode); 661 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); // 662 dstNode = new WindowNode(CreateWindowProperty(1)); // leashSurfaceNode is nullptr 663 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, node_, dstNode); 664 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // no surfaceNode thus target is nullptr 665 } 666 667 /** 668 * @tc.name: NotifyAnimationTransition02 669 * @tc.desc: NotifyAnimationTransition with OnAppTransition 670 * @tc.type: FUNC 671 */ 672 HWTEST_F(RemoteAnimationTest, NotifyAnimationTransition02, Function | SmallTest | Level2) 673 { 674 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 675 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::OTHER_WINDOW); 676 677 WMError ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 678 EXPECT_EQ(WMError::WM_OK, ret); // 679 EXPECT_EQ(0, MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::OTHER_WINDOW).size()); 680 681 RemoteAnimation::SetAnimationFirst(false); 682 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::OTHER_WINDOW); 683 684 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 685 EXPECT_EQ(WMError::WM_OK, ret); // 686 EXPECT_EQ(1, MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::OTHER_WINDOW).size()); 687 688 RemoteAnimation::windowController_ = nullptr; 689 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 690 EXPECT_EQ(WMError::WM_OK, ret); 691 } 692 693 /** 694 * @tc.name: NotifyAnimationTransition03 695 * @tc.desc: NotifyAnimationTransition with NotifyAnimationStartApp 696 * @tc.type: FUNC 697 */ 698 HWTEST_F(RemoteAnimationTest, NotifyAnimationTransition03, Function | SmallTest | Level2) 699 { 700 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 701 srcNode->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); 702 node_->surfaceNode_ = CreateRSSurfaceNode(2); 703 WMError ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 704 EXPECT_EQ(WMError::WM_OK, ret); // srcNode is nullptr, from launcher 705 706 srcNode->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); 707 transitionInfo_->SetIsRecent(true); 708 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 709 EXPECT_EQ(WMError::WM_OK, ret); // srcNode is nullptr, from recent 710 711 srcNode = nullptr; 712 transitionInfo_->SetIsRecent(false); 713 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 714 EXPECT_EQ(WMError::WM_OK, ret); // srcNode is null && need minimize false, from other 715 716 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::OTHER_WINDOW); 717 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 718 EXPECT_EQ(WMError::WM_OK, ret); // srcNode is nullptr, but need minimize true, from other 719 720 RemoteAnimation::SetAnimationFirst(false); 721 ret = RemoteAnimation::NotifyAnimationTransition(transitionInfo_, transitionInfo_, srcNode, node_); 722 EXPECT_EQ(WMError::WM_OK, ret); // srcNode is nullptr, but need minimize true, from other 723 } 724 725 /** 726 * @tc.name: NotifyAnimationMinimize01 727 * @tc.desc: NotifyAnimationMinimize 728 * @tc.type: FUNC 729 */ 730 HWTEST_F(RemoteAnimationTest, NotifyAnimationMinimize01, Function | SmallTest | Level2) 731 { 732 WMError ret = RemoteAnimation::NotifyAnimationMinimize(transitionInfo_, node_); 733 EXPECT_EQ(WMError::WM_OK, ret); 734 735 RemoteAnimation::windowController_ = nullptr; 736 ret = RemoteAnimation::NotifyAnimationMinimize(transitionInfo_, node_); 737 EXPECT_EQ(WMError::WM_OK, ret); 738 739 node_->leashWinSurfaceNode_ = nullptr; 740 ret = RemoteAnimation::NotifyAnimationMinimize(transitionInfo_, node_); 741 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // srcTarget is nullptr 742 } 743 744 /** 745 * @tc.name: NotifyAnimationClose01 746 * @tc.desc: NotifyAnimationClose 747 * @tc.type: FUNC 748 */ 749 HWTEST_F(RemoteAnimationTest, NotifyAnimationClose01, Function | SmallTest | Level2) 750 { 751 WMError ret = RemoteAnimation::NotifyAnimationClose(transitionInfo_, node_, TransitionEvent::CLOSE); 752 EXPECT_EQ(WMError::WM_OK, ret); 753 754 RemoteAnimation::windowController_ = nullptr; 755 ret = RemoteAnimation::NotifyAnimationClose(transitionInfo_, node_, TransitionEvent::CLOSE); 756 EXPECT_EQ(WMError::WM_OK, ret); 757 758 node_->leashWinSurfaceNode_ = nullptr; 759 ret = RemoteAnimation::NotifyAnimationClose(transitionInfo_, node_, TransitionEvent::CLOSE); 760 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // srcTarget is nullptr 761 } 762 763 /** 764 * @tc.name: NotifyAnimationBackTransition01 765 * @tc.desc: NotifyAnimationBackTransition failed 766 * @tc.type: FUNC 767 */ 768 HWTEST_F(RemoteAnimationTest, NotifyAnimationBackTransition01, Function | SmallTest | Level2) 769 { 770 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 771 TransitionEvent event = TransitionEvent::BACK_TRANSITION; 772 srcNode->leashWinSurfaceNode_ = nullptr; 773 WMError ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, node_, 774 event); 775 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // only src Target is null 776 777 sptr<WindowNode> dstNode = new WindowNode(CreateWindowProperty(3)); // 3 is windowId 778 dstNode->leashWinSurfaceNode_ = nullptr; 779 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, node_, dstNode, event); 780 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // only dstTarget is null 781 782 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, dstNode, event); 783 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); // both srcTarget and dstTarget art null 784 785 srcNode = nullptr; 786 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, node_, event); 787 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); // only srcNode is null 788 789 dstNode = nullptr; 790 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, node_, dstNode, event); 791 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); // only dstNode is null 792 793 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, dstNode, event); 794 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); // both srcNode and dstNode are null 795 796 RemoteAnimation::SetAnimationFirst(false); 797 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, node_, node_, event); 798 EXPECT_EQ(WMError::WM_ERROR_NO_REMOTE_ANIMATION, ret); 799 } 800 801 /** 802 * @tc.name: NotifyAnimationBackTransition02 803 * @tc.desc: NotifyAnimationBackTransition success 804 * @tc.type: FUNC 805 */ 806 HWTEST_F(RemoteAnimationTest, NotifyAnimationBackTransition02, Function | SmallTest | Level2) 807 { 808 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 809 TransitionEvent event = TransitionEvent::BACK_TRANSITION; 810 srcNode->leashWinSurfaceNode_ = CreateRSSurfaceNode(2); // 2 is windowId 811 WMError ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, node_, 812 event); 813 EXPECT_EQ(WMError::WM_OK, ret); 814 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 815 animationController_.GetRefPtr()); 816 EXPECT_NE(nullptr, testController->finishedCallback_); 817 testController->finishedCallback_->OnAnimationFinished(); 818 usleep(SLEEP_TIME_IN_US); 819 820 RemoteAnimation::windowController_ = nullptr; 821 ret = RemoteAnimation::NotifyAnimationBackTransition(transitionInfo_, transitionInfo_, srcNode, node_, event); 822 EXPECT_EQ(WMError::WM_OK, ret); 823 testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 824 animationController_.GetRefPtr()); 825 EXPECT_NE(nullptr, testController->finishedCallback_); 826 testController->finishedCallback_->OnAnimationFinished(); 827 usleep(SLEEP_TIME_IN_US); 828 } 829 830 /** 831 * @tc.name: NotifyAnimationByHome01 832 * @tc.desc: NotifyAnimationByHome with animationFirst false and create animationTarget failed 833 * @tc.type: FUNC 834 */ 835 HWTEST_F(RemoteAnimationTest, NotifyAnimationByHome01, Function | SmallTest | Level2) 836 { 837 RemoteAnimation::SetAnimationFirst(false); 838 WMError ret = RemoteAnimation::NotifyAnimationByHome(); 839 EXPECT_EQ(WMError::WM_OK, ret); // no node need home 840 841 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 842 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::MINIMIZE_ALL); 843 ret = RemoteAnimation::NotifyAnimationByHome(); 844 EXPECT_EQ(WMError::WM_OK, ret); // create animationTarget failed with no surface, and no callback 845 846 srcNode->leashWinSurfaceNode_ = CreateRSSurfaceNode(2); // 2 is windowId 847 srcNode->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); 848 ret = RemoteAnimation::NotifyAnimationByHome(); 849 EXPECT_EQ(WMError::WM_OK, ret); // create animationTarget failed, and no callback 850 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 851 animationController_.GetRefPtr()); 852 EXPECT_NE(nullptr, testController->finishedCallback_); 853 testController->finishedCallback_->OnAnimationFinished(); 854 usleep(SLEEP_TIME_IN_US); 855 EXPECT_NE(WindowNodeState::HIDE_ANIMATION_DONE, srcNode->stateMachine_.currState_); 856 857 srcNode->stateMachine_.TransitionTo(WindowNodeState::HIDE_ANIMATION_PLAYING); 858 ret = RemoteAnimation::NotifyAnimationByHome(); 859 EXPECT_EQ(WMError::WM_OK, ret); // create animationTarget failed, and no callback 860 861 srcNode->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); 862 ret = RemoteAnimation::NotifyAnimationByHome(); 863 EXPECT_EQ(WMError::WM_OK, ret); // create animationTarget failed, and no callback 864 } 865 866 /* 867 * @tc.name: NotifyAnimationByHome02 868 * @tc.desc: NotifyAnimationByHome with animationFirst false and create animationTarget success 869 * @tc.type: FUNC 870 */ 871 HWTEST_F(RemoteAnimationTest, NotifyAnimationByHome02, Function | SmallTest | Level2) 872 { 873 RemoteAnimation::SetAnimationFirst(false); 874 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 875 srcNode->leashWinSurfaceNode_ = CreateRSSurfaceNode(2); // 2 is windowId 876 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::MINIMIZE_ALL); 877 WMError ret = RemoteAnimation::NotifyAnimationByHome(); 878 EXPECT_EQ(WMError::WM_OK, ret); 879 880 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 881 animationController_.GetRefPtr()); 882 EXPECT_NE(nullptr, testController->finishedCallback_); 883 testController->finishedCallback_->OnAnimationFinished(); 884 usleep(SLEEP_TIME_IN_US); 885 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, srcNode->stateMachine_.currState_); 886 } 887 888 /* 889 * @tc.name: NotifyAnimationByHome03 890 * @tc.desc: NotifyAnimationByHome with animationFirst true and create animationTarget success 891 * @tc.type: FUNC 892 */ 893 HWTEST_F(RemoteAnimationTest, NotifyAnimationByHome03, Function | SmallTest | Level2) 894 { 895 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(2)); // 2 is windowId 896 srcNode->leashWinSurfaceNode_ = CreateRSSurfaceNode(2); // 2 is windowId 897 MinimizeApp::AddNeedMinimizeApp(srcNode, MinimizeReason::MINIMIZE_ALL); 898 EXPECT_EQ(1, MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MINIMIZE_ALL).size()); 899 WMError ret = RemoteAnimation::NotifyAnimationByHome(); 900 EXPECT_EQ(WMError::WM_OK, ret); 901 EXPECT_EQ(0, MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MINIMIZE_ALL).size()); 902 903 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 904 animationController_.GetRefPtr()); 905 EXPECT_NE(nullptr, testController->finishedCallback_); 906 testController->finishedCallback_->OnAnimationFinished(); 907 usleep(SLEEP_TIME_IN_US); 908 EXPECT_EQ(WindowNodeState::HIDE_ANIMATION_DONE, srcNode->stateMachine_.currState_); 909 } 910 911 /* 912 * @tc.name: NotifyAnimationTargetsUpdate01 913 * @tc.desc: NotifyAnimationTargetsUpdate failed 914 * @tc.type: FUNC 915 */ 916 HWTEST_F(RemoteAnimationTest, NotifyAnimationTargetsUpdate01, Function | SmallTest | Level2) 917 { 918 std::vector<uint32_t> fullScreenWinIds; 919 std::vector<uint32_t> floatWinIds; 920 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); // fullScreenAnimationTarget is empty 921 usleep(SLEEP_TIME_IN_US); 922 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 923 animationController_.GetRefPtr()); 924 EXPECT_EQ(nullptr, testController->animationTarget_); 925 EXPECT_EQ(0, testController->floatingWindowTargets_.size()); 926 927 RemoteAnimation::windowRoot_ = nullptr; 928 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); 929 usleep(SLEEP_TIME_IN_US); 930 testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 931 animationController_.GetRefPtr()); 932 EXPECT_EQ(nullptr, testController->animationTarget_); 933 EXPECT_EQ(0, testController->floatingWindowTargets_.size()); 934 935 RemoteAnimation::windowAnimationController_ = nullptr; 936 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); 937 usleep(SLEEP_TIME_IN_US); 938 testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 939 animationController_.GetRefPtr()); 940 EXPECT_EQ(nullptr, testController->animationTarget_); 941 EXPECT_EQ(0, testController->floatingWindowTargets_.size()); 942 943 wmsTaskHandler_ = nullptr; 944 RemoteAnimation::wmsTaskHandler_ = wmsTaskHandler_; 945 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); 946 usleep(SLEEP_TIME_IN_US); 947 testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 948 animationController_.GetRefPtr()); 949 EXPECT_EQ(nullptr, testController->animationTarget_); 950 EXPECT_EQ(0, testController->floatingWindowTargets_.size()); 951 } 952 953 /* 954 * @tc.name: NotifyAnimationTargetsUpdate02 955 * @tc.desc: NotifyAnimationTargetsUpdate success 956 * @tc.type: FUNC 957 */ 958 HWTEST_F(RemoteAnimationTest, NotifyAnimationTargetsUpdate02, Function | SmallTest | Level2) 959 { 960 std::vector<uint32_t> fullScreenWinIds; 961 std::vector<uint32_t> floatWinIds; 962 fullScreenWinIds.push_back(2); // 2 is windowId 963 floatWinIds.push_back(2); // 2 is windowId 964 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); // CreateWindowAnimationTarget nullptr 965 usleep(SLEEP_TIME_IN_US); 966 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 967 animationController_.GetRefPtr()); 968 EXPECT_EQ(nullptr, testController->animationTarget_); 969 EXPECT_EQ(0, testController->floatingWindowTargets_.size()); 970 971 fullScreenWinIds.push_back(node_->GetWindowId()); // 1, 2 in vector 972 floatWinIds.push_back(node_->GetWindowId()); // CreateWindowAnimationTarget success 973 RemoteAnimation::NotifyAnimationTargetsUpdate(fullScreenWinIds, floatWinIds); 974 usleep(SLEEP_TIME_IN_US); 975 testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 976 animationController_.GetRefPtr()); 977 EXPECT_NE(nullptr, testController->animationTarget_); 978 EXPECT_EQ(1, testController->floatingWindowTargets_.size()); 979 } 980 981 /* 982 * @tc.name: NotifyAnimationScreenUnlock01 983 * @tc.desc: NotifyAnimationScreenUnlock success 984 * @tc.type: FUNC 985 */ 986 HWTEST_F(RemoteAnimationTest, NotifyAnimationScreenUnlock01, Function | SmallTest | Level2) 987 { 988 std::function<void(void)> callback = nullptr; 989 WMError ret = RemoteAnimation::NotifyAnimationScreenUnlock(callback, nullptr); 990 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, ret); 991 __anon9b4652ba0602() 992 callback = []() {}; 993 ret = RemoteAnimation::NotifyAnimationScreenUnlock(callback, node_); 994 EXPECT_EQ(WMError::WM_OK, ret); 995 996 RemoteAnimation::windowAnimationController_ = nullptr; 997 ret = RemoteAnimation::NotifyAnimationScreenUnlock(callback, node_); 998 EXPECT_EQ(WMError::WM_ERROR_NO_REMOTE_ANIMATION, ret); 999 } 1000 1001 /* 1002 * @tc.name: NotifyAnimationUpdateWallpaper01 1003 * @tc.desc: NotifyAnimationUpdateWallpaper success 1004 * @tc.type: FUNC 1005 */ 1006 HWTEST_F(RemoteAnimationTest, NotifyAnimationUpdateWallpaper01, Function | SmallTest | Level2) 1007 { 1008 RemoteAnimation::NotifyAnimationUpdateWallpaper(node_); 1009 RSIWindowAnimationControllerMocker* testController = reinterpret_cast<RSIWindowAnimationControllerMocker*>( 1010 animationController_.GetRefPtr()); 1011 EXPECT_NE(nullptr, testController->animationTarget_); 1012 1013 testController->animationTarget_ = nullptr; 1014 RemoteAnimation::windowAnimationController_ = nullptr; 1015 RemoteAnimation::NotifyAnimationUpdateWallpaper(node_); 1016 EXPECT_EQ(nullptr, testController->animationTarget_); 1017 } 1018 1019 /* 1020 * @tc.name: CreateAnimationFinishedCallback01 1021 * @tc.desc: CreateAnimationFinishedCallback 1022 * @tc.type: FUNC 1023 */ 1024 HWTEST_F(RemoteAnimationTest, CreateAnimationFinishedCallback01, Function | SmallTest | Level2) 1025 { 1026 std::function<void(void)> callback = nullptr; 1027 EXPECT_EQ(nullptr, RemoteAnimation::CreateAnimationFinishedCallback(callback, node_)); 1028 1029 bool testFlag = false; __anon9b4652ba0702() 1030 callback = [&testFlag]() { testFlag = true; }; 1031 auto finishCallback = RemoteAnimation::CreateAnimationFinishedCallback(callback, node_); 1032 EXPECT_NE(nullptr, finishCallback); 1033 finishCallback->OnAnimationFinished(); 1034 usleep(SLEEP_TIME_IN_US); 1035 EXPECT_EQ(true, testFlag); 1036 1037 wmsTaskHandler_ = nullptr; 1038 RemoteAnimation::wmsTaskHandler_ = wmsTaskHandler_; __anon9b4652ba0802() 1039 callback = [&testFlag]() { testFlag = false; }; 1040 finishCallback = RemoteAnimation::CreateAnimationFinishedCallback(callback, node_); 1041 EXPECT_NE(nullptr, finishCallback); 1042 finishCallback->OnAnimationFinished(); 1043 usleep(SLEEP_TIME_IN_US); 1044 EXPECT_EQ(true, testFlag); 1045 } 1046 1047 /* 1048 * @tc.name: GetWindowAnimationTargets01 1049 * @tc.desc: GetWindowAnimationTargets for null window root 1050 * @tc.type: FUNC 1051 */ 1052 HWTEST_F(RemoteAnimationTest, GetWindowAnimationTargets01, Function | SmallTest | Level2) 1053 { 1054 RemoteAnimation::windowRoot_ = nullptr; 1055 std::vector<uint32_t> missionIds; 1056 std::vector<sptr<RSWindowAnimationTarget>> targets; 1057 EXPECT_EQ(WMError::WM_ERROR_NO_MEM, RemoteAnimation::GetWindowAnimationTargets(missionIds, targets)); 1058 } 1059 1060 /* 1061 * @tc.name: GetWindowAnimationTargets02 1062 * @tc.desc: GetWindowAnimationTargets for not exit mission 1063 * @tc.type: FUNC 1064 */ 1065 HWTEST_F(RemoteAnimationTest, GetWindowAnimationTargets02, Function | SmallTest | Level2) 1066 { 1067 std::vector<uint32_t> missionIds; 1068 missionIds.push_back(1); 1069 std::vector<sptr<RSWindowAnimationTarget>> targets; 1070 WMError ret = RemoteAnimation::GetWindowAnimationTargets(missionIds, targets); 1071 EXPECT_EQ(WMError::WM_OK, ret); 1072 EXPECT_EQ(true, targets.empty()); 1073 } 1074 1075 /* 1076 * @tc.name: GetWindowAnimationTargets03 1077 * @tc.desc: GetWindowAnimationTargets successful 1078 * @tc.type: FUNC 1079 */ 1080 HWTEST_F(RemoteAnimationTest, GetWindowAnimationTargets03, Function | SmallTest | Level2) 1081 { 1082 sptr<WindowNode> srcNode = new WindowNode(CreateWindowProperty(1)); // 1 is windowId 1083 srcNode->abilityInfo_.missionId_ = 1; 1084 srcNode->surfaceNode_ = CreateRSSurfaceNode(0); 1085 windowRoot_->windowNodeMap_[1] = srcNode; 1086 std::vector<uint32_t> missionIds; 1087 missionIds.push_back(1); 1088 std::vector<sptr<RSWindowAnimationTarget>> targets; 1089 WMError ret = RemoteAnimation::GetWindowAnimationTargets(missionIds, targets); 1090 EXPECT_EQ(WMError::WM_OK, ret); 1091 ASSERT_GE(targets.size(), 1); 1092 ASSERT_NE(targets[0], nullptr); 1093 EXPECT_EQ(true, targets[0]->missionId_ == 1); 1094 usleep(SLEEP_TIME_IN_US); 1095 } 1096 } 1097 } 1098 } 1099