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