1 /*
2 * Copyright (c) 2023 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 <optional>
17 #include <string>
18 #include <vector>
19
20 #include "gtest/gtest.h"
21
22 #define private public
23 #define protected public
24 #include "base/geometry/dimension.h"
25 #include "base/memory/ace_type.h"
26 #include "base/memory/referenced.h"
27 #include "core/components_ng/animation/geometry_transition.h"
28 #include "core/components_ng/base/view_stack_processor.h"
29 #include "test/mock/core/pipeline/mock_pipeline_context.h"
30
31 using namespace testing;
32 using namespace testing::ext;
33
34 namespace OHOS::Ace::NG {
35 namespace {
36 auto node1 = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
37 WeakPtr<FrameNode> weakNode1 = AceType::WeakClaim(AceType::RawPtr(node1));
38
39 auto node2 = AceType::MakeRefPtr<FrameNode>("test2", 2, AceType::MakeRefPtr<Pattern>());
40 WeakPtr<FrameNode> weakNode2 = AceType::WeakClaim(AceType::RawPtr(node2));
41
42 auto node3 = AceType::MakeRefPtr<FrameNode>("test3", 3, AceType::MakeRefPtr<Pattern>());
43 WeakPtr<FrameNode> weakNode3 = AceType::WeakClaim(AceType::RawPtr(node3));
44
45 const int32_t DURATION_TIMES = 100;
46 } // namespace
47
48 class GeometryTransitionTestNg : public testing::Test {
49 public:
50 static void SetUpTestSuite();
51 static void TearDownTestSuite();
52 void SetUp() override;
53 void TearDown() override;
54
55 void Create(const WeakPtr<FrameNode>& frameNode, bool followWithoutTransition = false);
56
57 RefPtr<FrameNode> CreateHolderNode(const RefPtr<FrameNode>& node);
58 RefPtr<GeometryTransition> gt_;
59 };
60
SetUpTestSuite()61 void GeometryTransitionTestNg::SetUpTestSuite()
62 {
63 MockPipelineContext::SetUp();
64 node2->AddChild(node1);
65 }
66
TearDownTestSuite()67 void GeometryTransitionTestNg::TearDownTestSuite()
68 {
69 MockPipelineContext::TearDown();
70 }
71
SetUp()72 void GeometryTransitionTestNg::SetUp() {}
73
TearDown()74 void GeometryTransitionTestNg::TearDown()
75 {
76 gt_ = nullptr;
77 }
78
Create(const WeakPtr<FrameNode> & node,bool followWithoutTransition)79 void GeometryTransitionTestNg::Create(const WeakPtr<FrameNode>& node, bool followWithoutTransition)
80 {
81 gt_ = AceType::MakeRefPtr<GeometryTransition>("test", followWithoutTransition);
82 // The constructor has been modified and requires additional assignments
83 gt_->inNode_ = node;
84 }
85
CreateHolderNode(const RefPtr<FrameNode> & node)86 RefPtr<FrameNode> GeometryTransitionTestNg::CreateHolderNode(const RefPtr<FrameNode>& node)
87 {
88 CHECK_NULL_RETURN(node, nullptr);
89 auto newNode = FrameNode::CreateFrameNode(
90 node->GetTag(), ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
91 newNode->SetGeometryNode(node->GetGeometryNode()->Clone());
92 auto frameSize = node->GetGeometryNode()->GetFrameSize();
93 newNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
94 CalcSize(CalcLength(frameSize.Width()), CalcLength(frameSize.Height())));
95 return newNode;
96 }
97
98 /**
99 * @tc.name: GeometryTransition001
100 * @tc.desc: Test
101 * @tc.type: FUNC
102 */
103 HWTEST_F(GeometryTransitionTestNg, GeometryTransition001, TestSize.Level1)
104 {
105 /**
106 * @tc.steps: step1. Build with empty node.
107 * @tc.expected: hasInAnim_ and hasOutAnim_ are false
108 */
109 Create(nullptr);
110 EXPECT_TRUE(gt_->IsInAndOutEmpty());
111 gt_->Build(nullptr, true);
112 EXPECT_FALSE(gt_->hasInAnim_);
113 EXPECT_FALSE(gt_->hasOutAnim_);
114
115 Create(weakNode1, true);
116 gt_->Build(weakNode1, false);
117 gt_->WillLayout(node1);
118 gt_->DidLayout(node1);
119 gt_->Build(weakNode2, true);
120 gt_->WillLayout(node2);
121 gt_->DidLayout(node2);
122 EXPECT_TRUE(gt_->hasInAnim_);
123 EXPECT_TRUE(gt_->hasOutAnim_);
124
125 Create(weakNode1, true);
126 gt_->Build(weakNode1, true);
127 gt_->WillLayout(node1);
128 gt_->DidLayout(node1);
129 EXPECT_FALSE(gt_->hasInAnim_);
130 EXPECT_FALSE(gt_->hasOutAnim_);
131
132 Create(weakNode1, true);
133 gt_->Build(weakNode2, true);
134 gt_->WillLayout(node2);
135 gt_->DidLayout(node2);
136 EXPECT_TRUE(gt_->hasInAnim_);
137 EXPECT_FALSE(gt_->hasOutAnim_);
138
139 Create(weakNode1, true);
140 weakNode2.Upgrade()->isRemoving_ = true;
141 gt_->Build(weakNode2, true);
142 gt_->WillLayout(node2);
143 gt_->DidLayout(node2);
144 EXPECT_TRUE(gt_->hasInAnim_);
145 EXPECT_FALSE(gt_->hasOutAnim_);
146
147 /**
148 * @tc.steps: step1. Build with empty node.
149 * @tc.expected: hasInAnim_ and hasOutAnim_ are false and state_ is ACTIVE
150 */
151 auto weakNodeTemp = weakNode3.Upgrade();
152 weakNode2.Upgrade()->isRemoving_ = false;
153 weakNodeTemp->isRemoving_ = false;
154 weakNodeTemp->onMainTree_ = true;
155 Create(weakNode3, true);
156 gt_->outNode_ = weakNode1;
157 gt_->Build(weakNode2, true);
158 gt_->WillLayout(node2);
159 gt_->DidLayout(node2);
160 EXPECT_FALSE(gt_->hasInAnim_);
161 EXPECT_FALSE(gt_->hasOutAnim_);
162 EXPECT_FALSE(gt_->state_ == GeometryTransition::State::ACTIVE);
163 }
164
165 /**
166 * @tc.name: GeometryTransition002
167 * @tc.desc: Test
168 * @tc.type: FUNC
169 */
170 HWTEST_F(GeometryTransitionTestNg, GeometryTransition002, TestSize.Level1)
171 {
172 Create(weakNode1, true);
173 gt_->inNode_ = weakNode1;
174 gt_->outNode_ = weakNode2;
175 gt_->WillLayout(node2);
176 gt_->DidLayout(node2);
177 node2->SetRootMeasureNode();
178 node1->SetRootMeasureNode();
179 gt_->WillLayout(node2);
180 gt_->DidLayout(node2);
181 gt_->SyncGeometry(true);
182 gt_->hasOutAnim_ = true;
183 gt_->WillLayout(node2);
184 node2->GetLayoutProperty()->UpdateAspectRatio(1.0f);
185 gt_->WillLayout(node2);
186 gt_->inNode_.Upgrade()->GetGeometryNode()->SetFrameSize(SizeF(1.0f, 1.0f));
187 gt_->WillLayout(node2);
188 gt_->DidLayout(node2);
189 gt_->state_ = GeometryTransition::State::ACTIVE;
190 gt_->hasInAnim_ = true;
191 gt_->WillLayout(node1);
192 gt_->DidLayout(node1);
193 gt_->state_ = GeometryTransition::State::IDENTITY;
194 gt_->DidLayout(node1);
195 gt_->outNode_.Upgrade()->isRemoving_ = true;
196 gt_->SyncGeometry(true);
197 gt_->outNode_.Upgrade()->isRemoving_ = false;
198 bool ret = gt_->Update(weakNode1, weakNode1);
199 EXPECT_TRUE(ret);
200 ret = gt_->Update(weakNode2, weakNode2);
201 EXPECT_TRUE(ret);
202 ret = gt_->Update(nullptr, weakNode2);
203 EXPECT_FALSE(ret);
204 gt_->SyncGeometry(false);
205 weakNode1.Upgrade()->MarkRemoving();
206 gt_->SyncGeometry(false);
207 }
208
209 /**
210 * @tc.name: GeometryTransition003
211 * @tc.desc: Test the Build function in the GeometryTransition
212 * @tc.type: FUNC
213 */
214 HWTEST_F(GeometryTransitionTestNg, GeometryTransition003, TestSize.Level1)
215 {
216 /**
217 * @tc.steps: step1. create GeometryTransition with weakNode1.
218 */
219 Create(weakNode1, true);
220 weakNode1.Upgrade()->isRemoving_ = false;
221 /**
222 * @tc.steps: step2. try build with some condition.
223 * @tc.expected: weakNode1 in the GeometryTransition swap to weakNode2.
224 */
225 gt_->Build(weakNode1, false);
226 gt_->Build(weakNode1, false);
227 gt_->Build(weakNode2, false);
228 EXPECT_EQ(weakNode1, gt_->outNode_);
229 gt_->inNode_ = weakNode2;
230 /**
231 * @tc.steps: step3. try change node status.
232 * @tc.expected: the location of weakNode1 and weakNode2 meetings expectations.
233 */
234 gt_->Build(weakNode1, true);
235 EXPECT_EQ(gt_->inNode_, gt_->outNode_);
236 gt_->inNode_.Upgrade()->isRemoving_ = true;
237 gt_->outNode_ = weakNode2;
238 gt_->Build(gt_->inNode_, true);
239
240 /**
241 * @tc.steps: Cover all situations for InAnim and OutAnim
242 * @tc.expected: the location of weakNode1 and weakNode2 meetings expectations.
243 */
244 bool bFlagIn = gt_->hasInAnim_;
245 bool bFlagOut = gt_->hasOutAnim_;
246 bool bFlagFollow = gt_->followWithoutTransition_;
247 gt_->hasInAnim_ = false;
248 gt_->hasOutAnim_ = true;
249 gt_->followWithoutTransition_ = true;
250 gt_->Build(weakNode2, true);
251
252 /**
253 * @tc.steps: Cover all situations for InAnim and OutAnim
254 */
255 gt_->hasInAnim_ = false;
256 gt_->hasOutAnim_ = false;
257 gt_->Build(weakNode2, true);
258
259 /**
260 * @tc.step: Cover all situations for InAnim and OutAnim
261 */
262 gt_->hasInAnim_ = true;
263 gt_->hasOutAnim_ = false;
264 gt_->Build(weakNode2, true);
265
266 /**
267 * @tc.expected: IsRunning is false.
268 */
269 bool bResult = false;
270 bResult = gt_->IsRunning(weakNode3);
271 EXPECT_FALSE(bResult);
272
273 /**
274 * @tc.expected: IsRunning is true.
275 */
276 weakNode2.Upgrade()->layoutPriority_ = 1;
277 bResult = gt_->IsRunning(weakNode2);
278 EXPECT_TRUE(bResult);
279 /**
280 * @tc.steps: Reduction
281 */
282 gt_->hasInAnim_ = bFlagIn;
283 gt_->hasOutAnim_ = bFlagOut;
284 gt_->followWithoutTransition_ = bFlagFollow;
285
286 EXPECT_EQ(weakNode2, gt_->inNode_);
287 gt_->hasInAnim_ = false;
288 gt_->Build(weakNode2, false);
289 gt_->inNode_.Upgrade()->isRemoving_ = false;
290 gt_->inNode_.Upgrade()->onMainTree_ = true;
291 gt_->hasOutAnim_ = false;
292 gt_->Build(weakNode2, true);
293 EXPECT_EQ(weakNode2, gt_->inNode_);
294 gt_->outNode_.Upgrade()->onMainTree_ = false;
295 weakNode1.Upgrade()->isRemoving_ = false;
296 gt_->Build(weakNode1, true);
297 EXPECT_EQ(weakNode1, gt_->inNode_);
298 }
299
300 /**
301 * @tc.name: GeometryTransition004
302 * @tc.desc: Test the OnReSync and OnAdditionalLayout function in the GeometryTransition
303 * @tc.type: FUNC
304 */
305 HWTEST_F(GeometryTransitionTestNg, GeometryTransition004, TestSize.Level1)
306 {
307 /**
308 * @tc.steps: step1. create GeometryTransition with weakNode1.
309 */
310 Create(weakNode1, true);
311 node2->AddChild(node1);
312 gt_->inNode_ = weakNode1;
313 gt_->outNode_ = weakNode2;
314 /**
315 * @tc.steps: step2. call OnReSync with some useless condition.
316 * @tc.expected: hasOutAnim_ in GeometryTransition is false
317 */
318 gt_->holder_ = CreateHolderNode(gt_->outNode_.Upgrade());
319 gt_->OnReSync();
320 weakNode1.Upgrade()->GetRenderContext()->isSynced_ = true;
321 gt_->OnReSync();
322 weakNode2.Upgrade()->MarkRemoving();
323 gt_->OnReSync();
324 EXPECT_FALSE(gt_->hasOutAnim_);
325 /**
326 * @tc.steps: step3. make outNodeTargetAbsRect_ and recall OnReSync.
327 * @tc.expected: hasOutAnim_ in GeometryTransition is true
328 */
329 gt_->outNodeTargetAbsRect_ = RectF(1.0f, 1.0f, 1.0f, 1.0f);
330 gt_->OnReSync();
331 EXPECT_FALSE(gt_->hasOutAnim_);
332
333 /**
334 * @tc.steps: step4. during outNode animation is running target inNode's frame is changed
335 */
336 gt_->RecordAnimationOption(weakNode3, AnimationOption());
337 EXPECT_FALSE(gt_->animationOption_.IsValid());
338
339 /**
340 * @tc.steps: step5. call OnAdditionalLayout with different condition.
341 * @tc.expected: the result meetings expectations.
342 */
343 EXPECT_FALSE(gt_->OnAdditionalLayout(weakNode1));
344 EXPECT_FALSE(gt_->OnAdditionalLayout(weakNode2));
345 gt_->hasInAnim_ = true;
346 gt_->state_ = GeometryTransition::State::ACTIVE;
347 EXPECT_TRUE(gt_->OnAdditionalLayout(weakNode1));
348 weakNode1.Upgrade()->parent_ = nullptr;
349 EXPECT_FALSE(gt_->OnAdditionalLayout(weakNode1));
350
351 auto weakNodeTemp = weakNode1.Upgrade();
352 weakNodeTemp->onMainTree_ = true;
353 weakNodeTemp->renderContext_->isSynced_ = true;
354 weakNode2.Upgrade()->isRemoving_ = true;
355 gt_->outNodeTargetAbsRect_ = RectF(10.0f, 10.0f, 10.0f, 10.0f);
356 gt_->inNode_ = weakNode1;
357 gt_->outNode_ = weakNode2;
358 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
359 gt_->OnReSync(trigger);
360 gt_->OnReSync();
361 gt_->ToString();
362 EXPECT_FALSE(gt_->hasOutAnim_);
363
364 // posChanged is true
365 gt_->hasOutAnim_ = false;
366 gt_->outNodeTargetAbsRect_ = RectF(1.0f, 10.0f, 1.0f, 1.0f);
367 gt_->OnReSync();
368 EXPECT_FALSE(gt_->hasOutAnim_);
369
370 // posChanged is true
371 gt_->outNodeTargetAbsRect_ = RectF(10.0f, 1.0f, 1.0f, 1.0f);
372 gt_->OnReSync();
373 EXPECT_FALSE(gt_->hasOutAnim_);
374
375 // sizeChanged is true
376 gt_->outNodeTargetAbsRect_ = RectF(1.0f, 1.0f, 10.0f, 1.0f);
377 gt_->OnReSync();
378 EXPECT_FALSE(gt_->hasOutAnim_);
379
380 // sizeChanged is true
381 gt_->outNodeTargetAbsRect_ = RectF(1.0f, 1.0f, 1.0f, 10.0f);
382 gt_->OnReSync();
383 EXPECT_FALSE(gt_->hasOutAnim_);
384 }
385
386 /**
387 * @tc.name: GeometryTransitionTest005
388 * @tc.desc: Test OnFollowWithoutTransition()
389 * @tc.type: FUNC
390 */
391 HWTEST_F(GeometryTransitionTestNg, GeometryTransitionTest005, TestSize.Level1)
392 {
393 /**
394 * @tc.steps: step1. create GeometryTransition with weakNode1.
395 */
396 Create(weakNode1, true);
397 node2->AddChild(node1);
398 gt_->inNode_ = weakNode1;
399 gt_->outNode_ = weakNode2;
400
401 /**
402 * @tc.steps: step2. assign value to followWithoutTransition_ and call OnFollowWithoutTransition.
403 * @tc.expected: called OnFollowWithoutTransition and result is expected
404 */
405 gt_->followWithoutTransition_ = true;
406 bool result = gt_->OnFollowWithoutTransition(true);
407 EXPECT_FALSE(result);
408
409 // direction has value is false
410 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
411 gt_->holder_ = CreateHolderNode(gt_->outNode_.Upgrade());
412 trigger->AddChild(gt_->holder_);
413 result = gt_->OnFollowWithoutTransition();
414 EXPECT_FALSE(result);
415
416 // direction is false
417 gt_->holder_ = CreateHolderNode(gt_->outNode_.Upgrade());
418 trigger->AddChild(gt_->holder_);
419 result = gt_->OnFollowWithoutTransition(false);
420 EXPECT_TRUE(result);
421
422 // direction is true
423 gt_->followWithoutTransition_ = false;
424 result = gt_->OnFollowWithoutTransition(true);
425 EXPECT_FALSE(result);
426 }
427
428 /**
429 * @tc.name: GeometryTransitionTest006
430 * @tc.desc: Test RecordAnimationOption()
431 * @tc.type: FUNC
432 */
433 HWTEST_F(GeometryTransitionTestNg, GeometryTransitionTest006, TestSize.Level1)
434 {
435 /**
436 * @tc.steps: step1. create GeometryTransition with node.
437 */
438 Create(weakNode1, true);
439 node2->AddChild(node1);
440 gt_->inNode_ = weakNode1;
441 gt_->outNode_ = weakNode2;
442
443 /**
444 * @tc.steps: step2. construt input parameters and call OnReSync RecordAnimationOption.
445 * @tc.expected: called RecordAnimationOption and result is expected.
446 */
447 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
448 AnimationOption option = AnimationOption();
449 gt_->RecordAnimationOption(trigger, option);
450 bool result = option.IsValid();
451 EXPECT_FALSE(result);
452
453 /**
454 * @tc.steps: step3.set animation option attribute and call OnReSync RecordAnimationOption.
455 * @tc.expected: called RecordAnimationOption and cover branch animationOption is false.
456 */
457 auto* stack = ViewStackProcessor::GetInstance();
458 auto implicitAnimationOption = stack->GetImplicitAnimationOption();
459 implicitAnimationOption.SetDuration(DURATION_TIMES);
460 gt_->RecordAnimationOption(trigger, option);
461 result = option.IsValid();
462 EXPECT_FALSE(result);
463
464 /**
465 * @tc.steps: step4. set animation option attribute and call OnReSync RecordAnimationOption.
466 * @tc.expected: called RecordAnimationOption and cover branch animationOption is true.
467 */
468 option.SetDuration(DURATION_TIMES);
469 gt_->RecordAnimationOption(trigger, option);
470 result = option.IsValid();
471 EXPECT_TRUE(result);
472
473 /**
474 * @tc.steps: IsParent(trigger, inNode_) is true
475 * @tc.expected: option is not IsValid
476 */
477 trigger->AddChild(gt_->inNode_.Upgrade());
478 gt_->RecordAnimationOption(trigger, option);
479 result = option.IsValid();
480 EXPECT_TRUE(result);
481
482 /**
483 * @tc.steps: set option Duration(0);
484 * @tc.expected: option is not IsValid
485 */
486 option.SetDuration(0);
487 AnimationOption optionTemp = AnimationOption();
488 optionTemp.SetDuration(DURATION_TIMES);
489 stack->SetImplicitAnimationOption(optionTemp);
490 gt_->RecordAnimationOption(trigger, option);
491 result = option.IsValid();
492 EXPECT_FALSE(result);
493
494 stack->SetImplicitAnimationOption(option);
495 gt_->animationOption_ = optionTemp;
496 result = option.IsValid();
497 EXPECT_FALSE(result);
498
499 /**
500 * @tc.steps: Remove inNode from trigger
501 */
502 trigger->RemoveChild(gt_->inNode_.Upgrade());
503 gt_->RecordAnimationOption(trigger, option);
504 result = option.IsValid();
505 EXPECT_FALSE(result);
506 }
507
508 /**
509 * @tc.name: GeometryTransition007
510 * @tc.desc: Test the Build function in the GeometryTransition
511 * @tc.type: FUNC
512 */
513 HWTEST_F(GeometryTransitionTestNg, GeometryTransition007, TestSize.Level1)
514 {
515 /**
516 * @tc.steps: step1. create GeometryTransition with weakNode1.
517 */
518 Create(weakNode1, true);
519
520 gt_->hasInAnim_ = false;
521 gt_->outNode_ = weakNode2;
522 gt_->hasOutAnim_ = true;
523
524 /**
525 * @tc.steps: step2. create holder_ with out.
526 */
527 gt_->holder_ = CreateHolderNode(gt_->outNode_.Upgrade());
528
529 /**
530 * @tc.steps: step3. set holder_ is son of node1.
531 */
532 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
533 trigger->AddChild(gt_->holder_);
534
535 /**
536 * @tc.steps: step4. call Build.
537 * @tc.expected: gt_->holder_ is nullptr and hasout is true.
538 */
539 gt_->Build(weakNode3, false);
540 EXPECT_FALSE(gt_->holder_);
541 EXPECT_TRUE(gt_->hasOutAnim_);
542 EXPECT_FALSE(gt_->hasInAnim_);
543 }
544
545 /**
546 * @tc.name: GeometryTransitionTest008
547 * @tc.desc: Test OnAdditionalLayout()
548 * @tc.type: FUNC
549 */
550 HWTEST_F(GeometryTransitionTestNg, GeometryTransition008, TestSize.Level1)
551 {
552 /**
553 * @tc.steps: step1. create GeometryTransition with weakNode1.
554 */
555 Create(weakNode1, true);
556 gt_->state_ = GeometryTransition::State::IDENTITY;
557
558 /**
559 * @tc.steps: step2. set Out is weakNode2.
560 */
561 gt_->outNode_ = weakNode2;
562 gt_->hasOutAnim_ = true;
563
564 /**
565 * @tc.steps: step3. call OnAdditionalLayout.
566 * @tc.expected: True.
567 */
568 bool bResult = gt_->OnAdditionalLayout(weakNode2);
569 EXPECT_TRUE(bResult);
570 }
571
572 /**
573 * @tc.name: GeometryTransitionTest009
574 * @tc.desc: Test RecordAnimationOption()
575 * @tc.type: FUNC
576 */
577 HWTEST_F(GeometryTransitionTestNg, GeometryTransitionTest009, TestSize.Level1)
578 {
579 /**
580 * @tc.steps: step1. create GeometryTransition with node.
581 */
582 Create(weakNode1, true);
583 node2->AddChild(node1);
584 gt_->inNode_ = weakNode1;
585 gt_->outNode_ = weakNode2;
586
587 /**
588 * @tc.steps: step2. construt input parameters and call OnReSync RecordAnimationOption.
589 * @tc.expected: called RecordAnimationOption and result is expected.
590 */
591 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
592 AnimationOption option = AnimationOption();
593 gt_->RecordAnimationOption(trigger, option);
594 bool result = option.IsValid();
595 EXPECT_FALSE(result);
596
597 /**
598 * @tc.steps: step3. set animation option attribute and call OnReSync RecordAnimationOption.
599 * @tc.expected: called RecordAnimationOption and cover branch animationOption is true.
600 */
601 option.SetDuration(DURATION_TIMES);
602 gt_->RecordAnimationOption(trigger, option);
603 result = option.IsValid();
604 EXPECT_TRUE(result);
605
606 /**
607 * @tc.steps:step4 IsParent(trigger, inNode_) is true
608 * @tc.expected: option is not IsValid
609 */
610 trigger->AddChild(gt_->inNode_.Upgrade());
611 gt_->RecordAnimationOption(trigger, option);
612 result = option.IsValid();
613 EXPECT_TRUE(result);
614
615 /**
616 * @tc.steps:step5 set option Duration(0);
617 */
618 option.SetDuration(0);
619 AnimationOption optionTemp = AnimationOption();
620
621 /**
622 * @tc.steps:step6 set pipeline->GetSyncAnimationOption() IsValid;
623 * @tc.expected: animationOption_ is not IsValid
624 */
625 optionTemp.SetDuration(DURATION_TIMES);
626 auto pipeline = PipelineBase::GetCurrentContext();
627 pipeline->animationOption_ = optionTemp;
628 gt_->RecordAnimationOption(trigger, option);
629 EXPECT_TRUE(gt_->animationOption_.IsValid());
630
631 /**
632 * @tc.steps:step7 Remove child from trigger
633 * @tc.expected: gt_->animationOption_ is not IsValid
634 */
635 gt_->animationOption_ = AnimationOption();
636 trigger->RemoveChild(gt_->inNode_.Upgrade());
637 gt_->RecordAnimationOption(trigger, option);
638 EXPECT_FALSE(gt_->animationOption_.IsValid());
639
640 /**
641 * @tc.steps:step8 pipeline->animationOption_ is not Valid
642 * @tc.expected: gt_->animationOption_ is not IsValid
643 */
644 pipeline->animationOption_ = gt_->animationOption_;
645 gt_->RecordAnimationOption(trigger, option);
646 EXPECT_FALSE(gt_->animationOption_.IsValid());
647 }
648
649 /**
650 * @tc.name: GeometryTransitionTest010
651 * @tc.desc: Test RecordAnimationOption()
652 * @tc.type: FUNC
653 */
654 HWTEST_F(GeometryTransitionTestNg, GeometryTransitionTest010, TestSize.Level1)
655 {
656 /**
657 * @tc.steps: step1. create GeometryTransition with node.
658 */
659 Create(weakNode1, true);
660 node2->AddChild(node1);
661 gt_->inNode_ = weakNode1;
662 gt_->outNode_ = weakNode2;
663
664 /**
665 * @tc.steps: step2. construt input parameters and call OnReSync RecordAnimationOption.
666 * @tc.expected: called RecordAnimationOption and result is expected.
667 */
668 RefPtr<FrameNode> trigger = AceType::MakeRefPtr<FrameNode>("test1", 1, AceType::MakeRefPtr<Pattern>());
669 AnimationOption option = AnimationOption();
670 gt_->RecordAnimationOption(trigger, option);
671 bool result = option.IsValid();
672 EXPECT_FALSE(result);
673
674 /**
675 * @tc.steps: step3.set animation option attribute and call OnReSync RecordAnimationOption.
676 * @tc.expected: called RecordAnimationOption and cover branch animationOption is True.
677 */
678 auto* stack = ViewStackProcessor::GetInstance();
679 auto implicitAnimationOption = stack->GetImplicitAnimationOption();
680 implicitAnimationOption.SetDuration(DURATION_TIMES);
681 stack->SetImplicitAnimationOption(implicitAnimationOption);
682 gt_->RecordAnimationOption(trigger, option);
683 result = stack->GetImplicitAnimationOption().IsValid();
684 EXPECT_TRUE(result);
685 }
686 } // namespace OHOS::Ace::NG
687