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