• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 #include "test/unittest/core/base/frame_node_test_ng.h"
16 
17 using namespace testing;
18 using namespace testing::ext;
19 
20 namespace OHOS::Ace::NG {
SetUpTestSuite()21 void FrameNodeTestNg::SetUpTestSuite()
22 {
23     MockPipelineContext::SetUp();
24 }
25 
TearDownTestSuite()26 void FrameNodeTestNg::TearDownTestSuite()
27 {
28     MockPipelineContext::TearDown();
29 }
30 
31 /**
32  * @tc.name: FrameNodeTestNg001
33  * @tc.desc: Test frame node method
34  * @tc.type: FUNC
35  */
36 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg001, TestSize.Level1)
37 {
__anon08da311b0102() 38     auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
39     auto two = FrameNode::GetFrameNode("two", 1);
40     EXPECT_NE(one, nullptr);
41     EXPECT_EQ(two, nullptr);
42 
43     /**
44      * @tc.steps: step2. create FrameNode and set a callback
45      * @tc.expect: call DestroyCallback while object is destroyed
46      */
47     bool flag = false;
48     auto three = FrameNode::GetOrCreateFrameNode("one", 1, nullptr);
49     ASSERT_NE(three, nullptr);
__anon08da311b0202() 50     three->PushDestroyCallback([&flag]() { flag = !flag; });
51     three = nullptr;
52     EXPECT_TRUE(flag);
53 }
54 
55 /**
56  * @tc.name: FrameNodeTestNg002
57  * @tc.desc: Test frame node method
58  * @tc.type: FUNC
59  */
60 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg002, TestSize.Level1)
61 {
__anon08da311b0302() 62     auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
63     one->SetParent(FRAME_NODE_PARENT);
64     auto two = FrameNode::GetFrameNode("two", 1);
65     EXPECT_NE(one, nullptr);
66     EXPECT_EQ(two, nullptr);
67     ElementRegister::GetInstance()->Clear();
68 }
69 
70 /**
71  * @tc.name: FrameNodeTestNg004
72  * @tc.desc: Test frame node method
73  * @tc.type: FUNC
74  */
75 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg004, TestSize.Level1)
76 {
77     /**
78      * @tc.steps: step1. create framenode and initialize the params used in Test.
79      */
80     auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
81     node->AttachToMainTree();
82     node->GetRenderContext()->RequestNextFrame();
83     EXPECT_TRUE(node->IsOnMainTree());
84 
85     int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
86     const RefPtr<FrameNode> parentNode =
87         FrameNode::CreateFrameNode("RelativeContainer", nodeId, AceType::MakeRefPtr<Pattern>(), true);
88     node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
89 
90     /**
91      * @tc.steps: step2. call OnInspectorIdUpdate .
92      * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
93      * this parentNode is not MarkDirtyNode
94      */
95     node->OnInspectorIdUpdate("RelativeContainer");
96     EXPECT_EQ(parentNode->GetTag(), "RelativeContainer");
97 }
98 
99 /**
100  * @tc.name: FrameNodeTestNg007
101  * @tc.desc: Test frame node method
102  * @tc.type: FUNC
103  */
104 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg007, TestSize.Level1)
105 {
106     /**
107      * @tc.steps: step 1. create framenode and initialize the params used in Test.
108      */
109     auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
110 
111     int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
112     const RefPtr<FrameNode> parentNode =
113         FrameNode::CreateFrameNode("parent", nodeId, AceType::MakeRefPtr<Pattern>(), true);
114     node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
115 
116     const RefPtr<FrameNode> overlayNode =
117         FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
118 
119     /**
120      * @tc.steps: step 2. call OnInspectorIdUpdate .
121      * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
122      * this parentNode is not MarkDirtyNode
123      */
124 
125     node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
126     node->OnInspectorIdUpdate("RelativeContainer");
127     EXPECT_EQ(parentNode->GetTag(), "parent");
128 
129     /**
130      * @tc.steps: step 3. call LayoutOverlay .
131      * @tc.expect: FrameRect of overlayNode is 0.
132      */
133     node->SetOverlayNode(overlayNode);
134     node->LayoutOverlay();
135 
136     auto layoutProperty = overlayNode->GetLayoutProperty();
137     layoutProperty->positionProperty_ = std::make_unique<PositionProperty>();
138     node->LayoutOverlay();
139     EXPECT_EQ(overlayNode->GetGeometryNode()->GetFrameRect().GetX(), 0);
140 
141     /**
142      * @tc.steps: step 4. call GetFrameChildByIndex .
143      * @tc.expect: index == 0 return uiNode, index != 0 return null
144      */
145     EXPECT_TRUE(node->GetFrameChildByIndex(0, false));
146     EXPECT_FALSE(node->GetFrameChildByIndex(1, false));
147 
148     /**
149      * @tc.steps: step 5. call GetBaselineDistance .
150      * @tc.expect: node has not child return 0. if node has child return  childBaseline of child
151      */
152     EXPECT_EQ(node->GetBaselineDistance(), 0);
153     node->AddChild(FRAME_NODE);
154     EXPECT_EQ(node->GetBaselineDistance(), 0);
155     auto nodeLayoutProperty = node->GetLayoutProperty();
156     nodeLayoutProperty->geometryTransition_ =
157         ElementRegister::GetInstance()->GetOrCreateGeometryTransition("test", false, true);
158     node->Layout();
159     EXPECT_FALSE(node->IsRootMeasureNode());
160     node->SetRootMeasureNode();
161     node->Layout();
162     EXPECT_TRUE(node->IsRootMeasureNode());
163 }
164 
165 /**
166  * @tc.name: FrameNodeTestNg008
167  * @tc.desc: Test frame node method
168  * @tc.type: FUNC
169  */
170 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg008, TestSize.Level1)
171 {
172     /**
173      * @tc.steps: step 1. create framenode and initialize the params used in Test.
174      */
175     RefPtr<NG::DrawModifier> drawModifier = AceType::MakeRefPtr<NG::DrawModifier>();
176     ASSERT_NE(drawModifier, nullptr);
177 
178     /**
179      * @tc.steps: step 2. call get function .
180      * @tc.expect: expect the return value to be correct.
181      */
182     EXPECT_TRUE(FRAME_NODE->IsSupportDrawModifier());
183 
184     /**
185      * @tc.steps: step 3. call GetContentModifier when drawModifier is null.
186      * @tc.expect: expect the return value to be correct.
187      */
188     EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
189 
190     /**
191      * @tc.steps: step 4. Nodes created by virtual classes, call GetContentModifier when drawModifier is null.
192      * @tc.expect: expect the return value to be correct.
193      */
194     FRAME_NODE->SetDrawModifier(drawModifier);
195     EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
196 
197     /**
198      * @tc.steps: step 5. Nodes created by virtual classes, call SetRemoveCustomProperties.
199      * @tc.expect: expect call successfully.
200      */
__anon08da311b0402() 201     FRAME_NODE->SetRemoveCustomProperties([]() -> void {});
202 }
203 
204 /**
205  * @tc.name: FrameNodeTouchTest001
206  * @tc.desc: Test frame node method
207  * @tc.type: FUNC
208  */
209 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest, TestSize.Level1)
210 {
211     /**
212      * @tc.steps: step1. create framenode and initialize the params used in Test.
213      */
214     auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
215     node->AttachToMainTree();
216     node->GetOrCreateGestureEventHub();
217     auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
218     node->renderContext_ = mockRenderContext;
219     node->SetActive(true);
220     auto localPoint = PointF(10, 10);
221     auto parentLocalPoint = PointF(10, 10);
222     const NG::PointF point { 10, 10 };
223     const PointF parentLocalPointOne = { 10, 10 };
224     TouchRestrict touchRestrict = { TouchRestrict::NONE };
225     auto globalPoint = PointF(10, 10);
226     auto touchTestResult = std::list<RefPtr<TouchEventTarget>>();
227     ResponseLinkResult responseLinkResult;
228 
229     mockRenderContext->rect_ = RectF(0, 0, 100, 100);
230     EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
231 
232     /**
233      * @tc.steps: step2. create childnode
234      */
235     auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true);
236     childNode->SetExclusiveEventForChild(true);
237     auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>();
238     childNode->renderContext_ = mockRenderContextforChild;
239     mockRenderContext->rect_ = RectF(0, 0, 100, 100);
240     EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
241         .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
242     childNode->GetOrCreateGestureEventHub();
243     childNode->SetActive(true);
244     auto childEventHub = childNode->GetOrCreateGestureEventHub();
245 
246     /**
247      * @tc.steps: step3. add childnode to the framenode
248      */
249     std::list<RefPtr<FrameNode>> children;
250     children.push_back(childNode);
251     node->frameChildren_ = { children.begin(), children.end() };
252 
253     /**
254      * @tc.steps: step4. create grandChildNode
255      */
256 
257     auto grandChildNode = FrameNode::CreateFrameNode("main", 3, AceType::MakeRefPtr<Pattern>(), true);
258     grandChildNode->SetExclusiveEventForChild(true);
259     grandChildNode->renderContext_ = mockRenderContextforChild;
260     mockRenderContext->rect_ = RectF(0, 0, 100, 100);
261     EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
262         .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
263     grandChildNode->GetOrCreateGestureEventHub();
264     grandChildNode->SetActive(true);
265     auto grandChildEventHub = grandChildNode->GetOrCreateGestureEventHub();
266 
267     /**
268      * @tc.steps: step5. add grandChildNode to the childnode
269      */
270     std::list<RefPtr<FrameNode>> grandChild;
271     grandChild.push_back(grandChildNode);
272     childNode->frameChildren_ = { grandChild.begin(), grandChild.end() };
273 
274     /**
275      * @tc.steps: step6. compare hitTestResult which is retured in function TouchTest whith expected value.
276      * @tc.expected: step6. hitTestResult  is STOP_BUBBLING when hitTestModeofGrandChilds or hitTestModeofChild is
277      * HTMBLOCK;
278      */
279     HitTestMode hitTestModeofGrandChilds[] = { HitTestMode::HTMBLOCK, HitTestMode::HTMDEFAULT };
280     HitTestMode hitTestModeofChilds[] = { HitTestMode::HTMDEFAULT, HitTestMode::HTMBLOCK, HitTestMode::HTMTRANSPARENT,
281         HitTestMode::HTMNONE, HitTestMode::HTMTRANSPARENT_SELF };
282     bool isStacks[] = { true, false };
283 
284     for (auto hitTestModeofGrandChild : hitTestModeofGrandChilds) {
285         grandChildEventHub->SetHitTestMode(hitTestModeofGrandChild);
286         for (auto isStack : isStacks) {
287             for (auto hitTestModeofChild : hitTestModeofChilds) {
288                 childNode->SetExclusiveEventForChild(isStack);
289                 childEventHub->SetHitTestMode(hitTestModeofChild);
290                 auto result = childNode->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
291                     touchTestResult, 0, responseLinkResult, true);
292                 result = node->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
293                     touchTestResult, 0, responseLinkResult, true);
294             }
295         }
296     }
297 }
298 
299 /**
300  * @tc.name: FrameNodeTestNg005
301  * @tc.desc: Test frame node method
302  * @tc.type: FUNC
303  */
304 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg005, TestSize.Level1)
305 {
306     /**
307      * @tc.steps: step1. callback function.
308      * @tc.expected: expect The function is run ok.
309      */
310     auto one = FrameNode::CreateFrameNodeWithTree("main", 10, AceType::MakeRefPtr<Pattern>());
311     EXPECT_NE(one, nullptr);
312 
313     MeasureProperty calcLayoutConstraint;
314     FRAME_NODE->UpdateLayoutConstraint(std::move(calcLayoutConstraint));
315     EXPECT_EQ(FRAME_NODE2->layoutProperty_->propertyChangeFlag_, 1);
316 
317     FRAME_NODE2->needSyncRenderTree_ = true;
318     FRAME_NODE2->RebuildRenderContextTree();
319     EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
320 
321     /**
322      * @tc.steps: step 2. create and set overlayNode.
323      * @tc.expect:cover branch overlayNode is not null and function is run ok.
324      */
325     int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
326     const RefPtr<FrameNode> overlayNode =
327         FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
328     FRAME_NODE2->SetOverlayNode(overlayNode);
329     FRAME_NODE2->RebuildRenderContextTree();
330     EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
331 
332     FRAME_NODE2->OnMountToParentDone();
333 
334     FRAME_NODE2->FlushUpdateAndMarkDirty();
335 
336     std::list<RefPtr<FrameNode>> visibleList;
337     FRAME_NODE2->isActive_ = true;
338     FRAME_NODE2->OnGenerateOneDepthVisibleFrame(visibleList);
339     EXPECT_TRUE(FRAME_NODE2->IsVisible());
340 
341     FRAME_NODE2->OnGenerateOneDepthAllFrame(visibleList);
342     EXPECT_EQ(visibleList.size(), 2);
343 
344     auto pattern = FRAME_NODE2->GetPattern();
345     EXPECT_EQ(pattern, 1);
346 
347     auto atomicNode = FRAME_NODE2->IsAtomicNode();
348     EXPECT_TRUE(atomicNode);
349 
350     auto hitTestMode = FRAME_NODE2->GetHitTestMode();
351     EXPECT_EQ(hitTestMode, HitTestMode::HTMDEFAULT);
352 
353     auto touchable = FRAME_NODE2->GetTouchable();
354     EXPECT_TRUE(touchable);
355 
356     const PointF globalPoint;
357     const PointF parentLocalPoint;
358     MouseTestResult onMouseResult;
359     MouseTestResult onHoverResult;
360     RefPtr<FrameNode> hoverNode;
361     auto mouse = FRAME_NODE2->MouseTest(globalPoint, parentLocalPoint, onMouseResult, onHoverResult, hoverNode);
362     EXPECT_EQ(mouse, HitTestResult::BUBBLING);
363 }
364 
365 /**
366  * @tc.name: FrameNodeTestNg006
367  * @tc.desc: Test frame node method
368  * @tc.type: FUNC
369  */
370 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg006, TestSize.Level1)
371 {
372     /**
373      * @tc.steps: step1. callback function.
374      * @tc.expected: expect The function is run ok.
375      */
376     FRAME_NODE2->OnWindowShow();
377     FRAME_NODE2->OnWindowHide();
378     FRAME_NODE2->OnWindowFocused();
379     FRAME_NODE2->OnWindowUnfocused();
380     FRAME_NODE2->OnWindowSizeChanged(1, 1, WindowSizeChangeReason::CUSTOM_ANIMATION);
381 
382     OffsetF Offset = { 0, 0 };
383     FRAME_NODE2->SetParent(FRAME_NODE3);
384     auto relativeOffset = FRAME_NODE2->GetTransformRelativeOffset();
385     EXPECT_EQ(relativeOffset, Offset);
386 
387     FRAME_NODE2->SetParent(FRAME_NODE3);
388     auto rectOffset = FRAME_NODE2->GetPaintRectOffset(true);
389     EXPECT_EQ(rectOffset, Offset);
390 
391     FRAME_NODE2->OnNotifyMemoryLevel(true);
392 
393     auto childrenCount = FRAME_NODE2->GetAllDepthChildrenCount();
394     EXPECT_EQ(childrenCount, 1);
395 
396     DimensionRect dimensionRect;
397     FRAME_NODE2->AddHotZoneRect(dimensionRect);
398     FRAME_NODE2->RemoveLastHotZoneRect();
399     EXPECT_NE(FRAME_NODE2->eventHub_, nullptr);
400 
401     FRAME_NODE->ProcessOffscreenNode(FRAME_NODE3);
402     FRAME_NODE->GetTransformRectRelativeToWindow();
403     FRAME_NODE->GetPaintRectOffsetToPage();
404 
405     float x = 1.0;
406     float y = 1.0;
407     auto Position = FRAME_NODE->FindChildByPosition(x, y);
408     EXPECT_EQ(Position, nullptr);
409 
410     FRAME_NODE->ProvideRestoreInfo();
411     auto immediately = FRAME_NODE->RemoveImmediately();
412     EXPECT_TRUE(immediately);
413 }
414 
415 /**
416  * @tc.name: FrameNodeTestNg_DumpInfo006
417  * @tc.desc: Test frame node method
418  * @tc.type: FUNC
419  */
420 HWTEST_F(FrameNodeTestNg, FrameNodeDumpInfo006, TestSize.Level1)
421 {
422     /**
423      * @tc.steps: step1. callback DumpInfo
424      * @tc.expected: expect The function is run ok.
425      */
426     LayoutProperty layoutProperty;
427     FRAME_NODE->DumpInfo();
428 
429     FRAME_NODE->layoutProperty_->UpdatePadding(PaddingPropertyT<CalcLength>());
430     FRAME_NODE->layoutProperty_->GetPaddingProperty();
431     FRAME_NODE->DumpInfo();
432     EXPECT_EQ(layoutProperty.padding_, nullptr);
433 
434     FRAME_NODE->layoutProperty_->UpdateMargin(PaddingProperty());
435     FRAME_NODE->layoutProperty_->GetMarginProperty();
436     FRAME_NODE->DumpInfo();
437     EXPECT_EQ(layoutProperty.margin_, nullptr);
438 
439     FRAME_NODE->layoutProperty_->UpdateBorderWidth(BorderWidthPropertyT<Dimension>());
440     FRAME_NODE->layoutProperty_->GetBorderWidthProperty();
441     FRAME_NODE->DumpInfo();
442     EXPECT_EQ(layoutProperty.borderWidth_, nullptr);
443 
444     /**
445      * @tc.steps: step2. set layoutConstraintF_ an geometryNode_'sParentLayoutConstraint
446                 and call DumpInfo
447      * @tc.expected: expect The function is run ok.
448      */
449     FRAME_NODE->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
450     auto layoutConstraintF_ = LayoutConstraintF();
451     FRAME_NODE->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
452     FRAME_NODE->DumpInfo();
453     EXPECT_EQ(layoutProperty.calcLayoutConstraint_, nullptr);
454 }
455 
456 /**
457  * @tc.name: FrameNodeTestNg_ToJsonValue007
458  * @tc.desc: Test frame node method
459  * @tc.type: FUNC
460  */
461 HWTEST_F(FrameNodeTestNg, FrameNodeToJsonValue007, TestSize.Level1)
462 {
463     /**
464      * @tc.steps: step1. build a object to jsonValue
465      * @tc.expected: expect The function is run ok.
466      */
467     auto gestureEventHub = FRAME_NODE->GetOrCreateGestureEventHub();
468 
469     std::vector<DimensionRect> responseRegion;
470     responseRegion.push_back(DimensionRect());
471     gestureEventHub->SetResponseRegion(responseRegion);
472 
473     auto jsonValue = JsonUtil::Create(true);
474     FRAME_NODE->ToJsonValue(jsonValue, filter);
475     EXPECT_TRUE(jsonValue);
476 
477     /**
478      * @tc.steps: step2. build a object to jsonValue and call FromJson
479      * @tc.expected: expect The function is run ok.
480      */
481     FRAME_NODE->FromJson(jsonValue);
482     FRAME_NODE->renderContext_ = nullptr;
483     FRAME_NODE->eventHub_->focusHub_ = nullptr;
484     auto jsonValue2 = JsonUtil::Create(true);
485     FRAME_NODE->ToJsonValue(jsonValue2, filter);
486     FRAME_NODE->FromJson(jsonValue2);
487     EXPECT_TRUE(jsonValue2);
488 }
489 
490 /**
491  * @tc.name: FrameNodeTestNg_OnAttachToMainTree008
492  * @tc.desc: Test frame node method
493  * @tc.type: FUNC
494  */
495 HWTEST_F(FrameNodeTestNg, FrameNodeOnAttachToMainTree008, TestSize.Level1)
496 {
497     /**
498      * @tc.steps: step1. build a object to OnAttachToMainTree
499      * @tc.expected: expect The function is run ok.
500      */
501     FRAME_NODE2->OnAttachToMainTree(true);
502 
503     auto request = FRAME_NODE2->hasPendingRequest_ = true;
504     FRAME_NODE2->OnAttachToMainTree(true);
505     EXPECT_TRUE(request);
506 
507     /**
508      * @tc.steps: step2 set PositionProperty of FRAME_NODE2 and call OnAttachToMainTree
509      * @tc.expected: expect The function is run ok.
510      */
511     auto& posProperty = FRAME_NODE2->renderContext_->GetOrCreatePositionProperty();
512     posProperty->UpdateOffset(OffsetT<Dimension>()); // OffsetT<Dimension>
513     FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
514     auto testNode_ = TestNode::CreateTestNode(100);
515     FRAME_NODE_PARENT->SetParent(testNode_);
516     FRAME_NODE2->OnAttachToMainTree(true);
517     EXPECT_TRUE(request);
518 }
519 
520 /**
521  * @tc.name: FrameNodeTestNg_NotifyVisibleChange009
522  * @tc.desc: Test frame node method
523  * @tc.type: FUNC
524  */
525 HWTEST_F(FrameNodeTestNg, FrameNodeNotifyVisibleChange009, TestSize.Level1)
526 {
527     /**
528      * @tc.steps: step1. build a object to NotifyVisibleChange
529      * @tc.expected: expect The FRAME_NODE2 is not nullptr.
530      */
531     FRAME_NODE2->AddChild(FRAME_NODE3);
532     FRAME_NODE2->NotifyVisibleChange(VisibleType::VISIBLE, VisibleType::INVISIBLE);
533     FRAME_NODE2->Clean();
534     EXPECT_NE(FRAME_NODE2, nullptr);
535 }
536 
537 /**
538  * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread0010
539  * @tc.desc: Test frame node method
540  * @tc.type: FUNC
541  */
542 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirtyLayoutWrapperOnMainThread0010, TestSize.Level1)
543 {
544     /**
545      * @tc.steps: step1. build a object to SwapDirtyLayoutWrapperOnMainThread
546      */
547     RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
548 
549     /**
550      * @tc.steps: step2. callback SwapDirtyLayoutWrapperOnMainThread
551      * @tc.expected: expect layoutWrapper is not nullptr.
552      */
553     FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
554     EXPECT_NE(layoutWrapper, nullptr);
555     layoutWrapper->SetActive(true);
556     auto test = FRAME_NODE2->IsActive();
557 
558     /**
559      * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
560      * @tc.expected: expect isActive_ is false.
561      */
562     FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
563     EXPECT_TRUE(test);
564 }
565 
566 /**
567  * @tc.name: FrameNodeTestNg_AdjustGridOffset0011
568  * @tc.desc: Test frame node method
569  * @tc.type: FUNC
570  */
571 HWTEST_F(FrameNodeTestNg, FrameNodeAdjustGridOffset0011, TestSize.Level1)
572 {
573     /**
574      * @tc.steps: step1. build a object to AdjustGridOffset
575      * @tc.expected: expect active is true.
576      */
577     FRAME_NODE2->SetActive(true);
578     bool active = FRAME_NODE2->IsActive();
579     FRAME_NODE2->AdjustGridOffset();
580     EXPECT_TRUE(active);
581 
582     FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
583     FRAME_NODE2->GetAncestorNodeOfFrame();
584 
585     FRAME_NODE2->SetActive(false);
586 
587     /**
588      * @tc.steps: step2. build a object to AdjustGridOffset
589      * @tc.expected: expect active1 is false.
590      */
591     bool active1 = FRAME_NODE2->IsActive();
592     FRAME_NODE2->AdjustGridOffset();
593     EXPECT_FALSE(active1);
594 }
595 
596 /**
597  * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback0012
598  * @tc.desc: Test frame node method
599  * @tc.type: FUNC
600  */
601 HWTEST_F(FrameNodeTestNg, FrameNodeSetOnAreaChangeCallback0012, TestSize.Level1)
602 {
603     /**
604      * @tc.steps: step1. build a object to SetOnAreaChangeCallback
605      * @tc.expected: expect The function is run ok.
606      */
607     OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon08da311b0502(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 608                                      const OffsetF& origin) {};
609     FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
610     EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
611     EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
612 
613     /**
614      * @tc.steps: step2.test while callback is nullptr
615      * @tc.expected:expect The function is run ok.
616      */
617     FRAME_NODE2->lastFrameRect_ = nullptr;
618     FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
619     FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
620     EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
621     EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
622 }
623 
624 /**
625  * @tc.name: FrameNodeTestNg_TriggerOnAreaChangeCallback0013
626  * @tc.desc: Test frame node method
627  * @tc.type: FUNC
628  */
629 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerOnAreaChangeCallback0013, TestSize.Level1)
630 {
631     /**
632      * @tc.steps: step1. set a flag and init a callback(onAreaChanged)
633      */
634     bool flag = false;
635     OnAreaChangedFunc onAreaChanged = [&flag](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon08da311b0602(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 636                                           const OffsetF& origin) { flag = !flag; };
637 
638     /**
639      * @tc.steps: step2. call TriggerOnAreaChangeCallback before set callback
640      * @tc.expected: expect flag is still false
641      */
642     FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_1);
643     EXPECT_FALSE(flag);
644 
645     /**
646      * @tc.steps: step3.set callback and release lastParentOffsetToWindow_
647      * @tc.expected: expect flag is still false
648      */
649     FRAME_NODE2->eventHub_->SetOnAreaChanged(std::move(onAreaChanged));
650     FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
651     FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_2);
652     EXPECT_FALSE(flag);
653 
654     /**
655      * @tc.steps: step4. release lastFrameRect_
656      * @tc.expected: expect flag is still false
657      */
658     FRAME_NODE2->lastFrameRect_ = nullptr;
659     FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_3);
660     EXPECT_FALSE(flag);
661 
662     /**
663      * @tc.steps: step5.set lastParentOffsetToWindow_ and lastFrameRect_
664      * @tc.expected: expect flag is still false
665      */
666     FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
667     FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
668     FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_4);
669     EXPECT_FALSE(flag);
670 }
671 
672 /**
673  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback0014
674  * @tc.desc: Test frame node method
675  * @tc.type: FUNC
676  */
677 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback0014, TestSize.Level1)
678 {
679     /**
680      * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
681      * @tc.expected: expect The function is run ok.
682      */
683     VisibleCallbackInfo callbackInfo;
684     FRAME_NODE2->SetVisibleAreaUserCallback({ 0.0f }, callbackInfo);
685     FRAME_NODE2->TriggerVisibleAreaChangeCallback(1);
686 
687     /**
688      * @tc.steps: step2. callback SetParent
689      * @tc.expected: expect parent is same with parentNode.
690      */
691     auto parentNode = AceType::MakeRefPtr<FrameNode>("test", -1, AceType::MakeRefPtr<Pattern>(), false);
692     FRAME_NODE2->SetParent(FRAME_NODE3);
693     FRAME_NODE2->TriggerVisibleAreaChangeCallback(2);
694     auto parent = FRAME_NODE2->GetParent();
695     EXPECT_EQ(parent, 1);
696 
697     auto parentNode1 = FrameNode::CreateFrameNode("parent", 2, AceType::MakeRefPtr<Pattern>());
698     RefPtr<FrameNode> frameNodes[3] = { parentNode1, nullptr, nullptr };
699     FRAME_NODE2->TriggerVisibleAreaChangeCallback(3);
700     auto parent1 = FRAME_NODE2->GetParent();
701     EXPECT_EQ(parent1, 1);
702 
703     FRAME_NODE2->lastVisibleRatio_ = 1.0;
704     FRAME_NODE2->TriggerVisibleAreaChangeCallback(4);
705 
706     /**
707      * @tc.steps: step3. set onShow_ and call TriggerVisibleAreaChangeCallback
708      * @tc.expected: expect GetOnShow is true and lastVisibleRatio_ is zero.
709      */
710     auto context = PipelineContext::GetCurrentContext();
711     context->onShow_ = true;
712     FRAME_NODE2->TriggerVisibleAreaChangeCallback(5);
713     auto testNode_ = TestNode::CreateTestNode(101);
714     FRAME_NODE3->SetParent(testNode_);
715     FRAME_NODE3->isActive_ = true;
716     FRAME_NODE2->TriggerVisibleAreaChangeCallback(6);
717     FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::INVISIBLE);
718     FRAME_NODE2->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
719     FRAME_NODE2->isActive_ = true;
720     FRAME_NODE2->TriggerVisibleAreaChangeCallback(7);
721     FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
722     FRAME_NODE2->TriggerVisibleAreaChangeCallback(8);
723     EXPECT_TRUE(context->GetOnShow());
724 }
725 
726 /**
727  * @tc.name: FrameNodeTestNg_CreateLayoutTask0015
728  * @tc.desc: Test frame node method
729  * @tc.type: FUNC
730  */
731 HWTEST_F(FrameNodeTestNg, FrameNodeCreateLayoutTask0015, TestSize.Level1)
732 {
733     /**
734      * @tc.steps: step1. build a object to CreateLayoutTask
735      * @tc.expected: expect The function is run ok.
736      */
737     FRAME_NODE2->isLayoutDirtyMarked_ = true;
738     FRAME_NODE2->CreateLayoutTask(true);
739     EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
740 
741     FRAME_NODE2->CreateLayoutTask(true);
742 
743     FRAME_NODE2->isLayoutDirtyMarked_ = true;
744     FRAME_NODE2->CreateLayoutTask(false);
745     EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
746 }
747 
748 /**
749  * @tc.name: FrameNodeTestNg_CreateRenderTask0016
750  * @tc.desc: Test frame node method
751  * @tc.type: FUNC
752  */
753 HWTEST_F(FrameNodeTestNg, FrameNodeCreateRenderTask0016, TestSize.Level1)
754 {
755     /**
756      * @tc.steps: step1. build a object to CreateRenderTask
757      * @tc.expected: expect The isRenderDirtyMarked_ is false.
758      */
759     FRAME_NODE2->isRenderDirtyMarked_ = true;
760     FRAME_NODE2->CreateRenderTask(true);
761     EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
762 
763     FRAME_NODE2->isRenderDirtyMarked_ = true;
764     FRAME_NODE2->CreateRenderTask(false);
765 
766     FRAME_NODE2->CreateRenderTask(true);
767     EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
768 }
769 
770 /**
771  * @tc.name: FrameNodeTestNg_GetParentGlobalOffset0017
772  * @tc.desc: Test frame node method
773  * @tc.type: FUNC
774  */
775 HWTEST_F(FrameNodeTestNg, FrameNodeGetParentGlobalOffset0017, TestSize.Level1)
776 {
777     /**
778      * @tc.steps: step1. SetParent for FRAME_NODE2 and callback GetParentGlobalOffset.
779      * @tc.expected: expect The parent is same with 1.
780      */
781     FRAME_NODE2->GetParentGlobalOffset();
782     FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
783     auto parent = FRAME_NODE2->GetAncestorNodeOfFrame();
784     FRAME_NODE2->GetParentGlobalOffset();
785     EXPECT_EQ(parent, 1);
786 }
787 
788 /**
789  * @tc.name: FrameNodeTestNg_UpdateLayoutPropertyFlag0018
790  * @tc.desc: Test frame node method
791  * @tc.type: FUNC
792  */
793 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateLayoutPropertyFlag0018, TestSize.Level1)
794 {
795     /**
796      * @tc.steps: step1.call back UpdateLayoutPropertyFlag.
797      * @tc.expected: expect selfFlag is same with PROPERTY_UPDATE_BY_CHILD_REQUEST.
798      */
799     FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
800     auto selfFlag = FRAME_NODE2->layoutProperty_->GetPropertyChangeFlag();
801     FRAME_NODE2->UpdateLayoutPropertyFlag();
802     EXPECT_EQ(selfFlag, PROPERTY_UPDATE_BY_CHILD_REQUEST);
803 
804     FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
805     FRAME_NODE2->AddChild(FRAME_NODE3);
806     FRAME_NODE2->UpdateLayoutPropertyFlag();
807     FRAME_NODE2->Clean();
808 }
809 
810 /**
811  * @tc.name: FrameNodeTestNg_UpdateChildrenLayoutWrapper0019
812  * @tc.desc: Test frame node method
813  * @tc.type: FUNC
814  */
815 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateChildrenLayoutWrapper0019, TestSize.Level1)
816 {
817     /**
818      * @tc.steps: step1. AddChild for FRAME_NODE2 and callback UpdateChildrenLayoutWrapper.
819      * @tc.expected: expect The UpdateLayoutWrapper is true.
820      */
821     FRAME_NODE2->AddChild(FRAME_NODE3);
822     FRAME_NODE2->UpdateChildrenLayoutWrapper(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true), true, true);
823     FRAME_NODE2->Clean();
824     EXPECT_TRUE(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true));
825 }
826 
827 /**
828  * @tc.name: FrameNodeTestNg_MarkModifyDone0021
829  * @tc.desc: Test frame node method
830  * @tc.type: FUNC
831  */
832 HWTEST_F(FrameNodeTestNg, FrameNodeMarkModifyDone0021, TestSize.Level1)
833 {
834     /**
835      * @tc.steps: step1. build a object to MarkModifyDone.
836      * @tc.expected:expect The function is run ok.
837      */
838     FRAME_NODE2->MarkModifyDone();
839     EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
840     FRAME_NODE2->isRestoreInfoUsed_ = true;
841     FRAME_NODE2->MarkModifyDone();
842     EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
843 }
844 
845 /**
846  * @tc.name: FrameNodeTestNg_MarkNeedRender0022
847  * @tc.desc: Test frame node method
848  * @tc.type: FUNC
849  */
850 HWTEST_F(FrameNodeTestNg, FrameNodeMarkNeedRender0022, TestSize.Level1)
851 {
852     /**
853      * @tc.steps: step1. callback MarkNeedRenderOnly.
854      * @tc.expected: expect The function is run ok.
855      */
856     FRAME_NODE2->MarkNeedRenderOnly();
857     auto test = FRAME_NODE2->isRenderDirtyMarked_ = false;
858     auto test1 = FRAME_NODE2->isLayoutDirtyMarked_ = false;
859     FRAME_NODE2->MarkNeedRender(false);
860     FRAME_NODE2->MarkNeedRender(true);
861     EXPECT_FALSE(test);
862     EXPECT_FALSE(test1);
863 }
864 
865 /**
866  * @tc.name: FrameNodeTestNg_IsNeedRequestParentMeasure0023
867  * @tc.desc: Test frame node method
868  * @tc.type: FUNC
869  */
870 HWTEST_F(FrameNodeTestNg, FrameNodeIsNeedRequestParentMeasure0023, TestSize.Level1)
871 {
872     /**
873      * @tc.steps: step1. callback IsNeedRequestParentMeasure.
874      * @tc.expected: expect The function return value is true.
875      */
876     auto test = FRAME_NODE2->IsNeedRequestParentMeasure();
877     EXPECT_TRUE(test);
878 
879     FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
880     FRAME_NODE2->IsNeedRequestParentMeasure();
881 
882     FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
883     FRAME_NODE2->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
884     auto test1 = FRAME_NODE2->IsNeedRequestParentMeasure();
885     EXPECT_TRUE(test1);
886 }
887 
888 /**
889  * @tc.name: FrameNodeTestNg_OnGenerateOneDepthVisibleFrameWithTransition0024
890  * @tc.desc: Test frame node method
891  * @tc.type: FUNC
892  */
893 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithTransition0024, TestSize.Level1)
894 {
895     /**
896      * @tc.steps: step1. callback OnGenerateOneDepthVisibleFrameWithTransition.
897      * @tc.expected: expect The function is run ok.
898      */
899     std::list<RefPtr<FrameNode>> visibleList;
900     FRAME_NODE2->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
901 
902     /**
903      * @tc.steps: step2.push the framenode to visibleList and callback OnGenerateOneDepthVisibleFrameWithTransition
904      * @tc.expected: expect visibleList.size is 3.
905      */
906     visibleList.push_back(FRAME_NODE);
907     FRAME_NODE3->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
908     EXPECT_EQ(visibleList.size(), 3);
909 }
910 
911 /**
912  * @tc.name: FrameNodeTestNg_IsOutOfTouchTestRegion0025
913  * @tc.desc: Test frame node method
914  * @tc.type: FUNC
915  */
916 HWTEST_F(FrameNodeTestNg, FrameNodeIsOutOfTouchTestRegion0025, TestSize.Level1)
917 {
918     /**
919      * @tc.steps: step1. callback IsOutOfTouchTestRegion.
920      * @tc.expected: expect The function return value is true.
921      */
922     PointF pointF;
923     std::vector<RectF> rectF;
924     TouchEvent touchEvent;
925     auto test = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
926     EXPECT_TRUE(test);
927 
928     auto test1 = FRAME_NODE2->InResponseRegionList(pointF, rectF);
929     auto test2 = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
930     EXPECT_FALSE(test1);
931     EXPECT_TRUE(test2);
932 }
933 
934 /**
935  * @tc.name: FrameNodeTestNg_TouchTest0026
936  * @tc.desc: Test frame node method
937  * @tc.type: FUNC
938  */
939 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest0026, TestSize.Level1)
940 {
941     /**
942      * @tc.steps: step1. callback TouchTest.
943      * @tc.expected: expect The function return value is true.
944      */
945     PointF globalPoint;
946     PointF parentLocalPoint;
947     TouchRestrict touchRestrict;
948     TouchTestResult result;
949     ResponseLinkResult responseLinkResult;
950     SystemProperties::debugEnabled_ = true;
951     FRAME_NODE2->TouchTest(
952         globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
953 
954     SystemProperties::debugEnabled_ = false;
955     FRAME_NODE2->TouchTest(
956         globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
957 
958     /**
959      * @tc.steps: step2. set isActive_ and IsEnabled is false.
960      * @tc.expected: expect The function return value is OUT_OF_REGION.
961      */
962     FRAME_NODE2->isActive_ = false;
963     FRAME_NODE2->eventHub_->SetEnabled(false);
964     auto test = FRAME_NODE2->TouchTest(
965         globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
966     EXPECT_EQ(test, HitTestResult::OUT_OF_REGION);
967 }
968 
969 /**
970  * @tc.name: FrameNodeTestNg_AxisTest0027
971  * @tc.desc: Test frame node method
972  * @tc.type: FUNC
973  */
974 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest0027, TestSize.Level1)
975 {
976     /**
977      * @tc.steps: step1. callback AxisTest.
978      * @tc.expected: expect inputEventHub_ is run not null.
979      */
980     const PointF globalPoint;
981     const PointF parentLocalPoint;
982     AxisTestResult onAxisResult;
983     FRAME_NODE2->eventHub_->GetOrCreateInputEventHub();
984     FRAME_NODE2->AxisTest(globalPoint, parentLocalPoint, onAxisResult);
985     EXPECT_NE(FRAME_NODE2->eventHub_->inputEventHub_, nullptr);
986 }
987 
988 /**
989  * @tc.name: FrameNodeTestNg0028
990  * @tc.desc: Test frame node method
991  * @tc.type: FUNC
992  */
993 HWTEST_F(FrameNodeTestNg, FrameNodeOnAccessibilityEvent0028, TestSize.Level1)
994 {
995     /**
996      * @tc.steps: step1. callback OnAccessibilityEvent.
997      * @tc.expected: expect The function is true.
998      */
999     auto test = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = true;
1000     FRAME_NODE2->OnAccessibilityEvent(
1001         AccessibilityEventType::CHANGE, WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_SUBTREE);
1002     FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, "", "");
1003     EXPECT_TRUE(test);
1004 
1005     /**
1006      * @tc.steps: step2. callback OnAccessibilityEvent.
1007      * @tc.expected: expect The function is false.
1008      */
1009     auto test1 = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = false;
1010     FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::ACCESSIBILITY_FOCUSED);
1011     EXPECT_FALSE(test1);
1012 }
1013 
1014 /**
1015  * @tc.name: FrameNodeTestNg_MarkRemoving0029
1016  * @tc.desc: Test frame node method
1017  * @tc.type: FUNC
1018  */
1019 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving0029, TestSize.Level1)
1020 {
1021     /**
1022      * @tc.steps: step1. callback MarkRemoving.
1023      * @tc.expected: expect The function return value is true.
1024      */
1025     FRAME_NODE2->AddChild(FRAME_NODE3);
1026     FRAME_NODE2->layoutProperty_->UpdateGeometryTransition("id");
1027     auto mark = FRAME_NODE2->MarkRemoving();
1028     FRAME_NODE2->Clean();
1029     EXPECT_TRUE(mark);
1030 
1031     FRAME_NODE2->layoutProperty_ = nullptr;
1032     auto mark1 = FRAME_NODE2->MarkRemoving();
1033     EXPECT_FALSE(mark1);
1034 }
1035 
1036 /**
1037  * @tc.name: FrameNodeTestNg_CalculateCurrentVisibleRatio0030
1038  * @tc.desc: Test frame node method
1039  * @tc.type: FUNC
1040  */
1041 HWTEST_F(FrameNodeTestNg, FrameNodeCalculateCurrentVisibleRatio0030, TestSize.Level1)
1042 {
1043     /**
1044      * @tc.steps: step1. callback RemoveLastHotZoneRect.
1045      * @tc.expected: step1. expect The function is run ok.
1046      */
1047     RectF visibleRect;
1048     RectF renderRect;
1049     FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect);
1050     EXPECT_EQ(visibleRect.Width(), 0);
1051     EXPECT_EQ(renderRect.Width(), 0);
1052 
1053     /**
1054      * @tc.steps: step2. set wrong value and call CalculateCurrentVisibleRatio
1055      * @tc.expected: expect The function returns 0.
1056      */
1057     renderRect.SetWidth(-1);
1058     EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1059     visibleRect.SetWidth(-1);
1060     EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1061 }
1062 
1063 /**
1064  * @tc.name: FrameNodeTestNg_InitializePatternAndContext0032
1065  * @tc.desc: Test InitializePatternAndContext
1066  * @tc.type: FUNC
1067  */
1068 HWTEST_F(FrameNodeTestNg, FrameNodeInitializePatternAndContext0032, TestSize.Level1)
1069 {
1070     /**
1071      * @tc.steps: step1. create a node and set onMainTree_=false, then call InitializePatternAndContext
1072             and trigger the callback
1073      * @tc.expected: hasPendingRequest_ is true
1074      */
__anon08da311b0702() 1075     auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1076     one->onMainTree_ = false;
1077     one->InitializePatternAndContext();
1078     auto renderContext_ = one->renderContext_;
1079     renderContext_->RequestNextFrame();
1080     EXPECT_TRUE(one->hasPendingRequest_);
1081 }
1082 
1083 /**
1084  * @tc.name: FrameNodeTestNg_ProcessAllVisibleCallback0033
1085  * @tc.desc: Test ProcessAllVisibleCallback
1086  * @tc.type: FUNC
1087  */
1088 HWTEST_F(FrameNodeTestNg, FrameNodeProcessAllVisibleCallback0033, TestSize.Level1)
1089 {
1090     /**
1091      * @tc.steps: step1. create a node and init a vector for preparing for args, then set a flag
1092      */
__anon08da311b0802() 1093     auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1094     std::vector<double> visibleAreaRatios { 0.2, 0.8, 0.21, 0.79, 0.5 };
1095     int flag = 0;
__anon08da311b0902(bool input1, double input2) 1096     auto defaultCallback = [&flag](bool input1, double input2) { flag += 1; };
1097     VisibleCallbackInfo callbackInfo { defaultCallback, 1.0, false };
1098 
1099     /**
1100      * @tc.steps: step2. call ProcessAllVisibleCallback with 0.5 from 0
1101      * @tc.expected: flag is 1
1102      */
1103     one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0.5, 0);
1104     EXPECT_EQ(flag, 1);
1105 
1106     /**
1107      * @tc.steps: step3. call ProcessAllVisibleCallback with 0 from 0.5
1108      * @tc.expected: flag is 2
1109      */
1110     one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0.5);
1111     EXPECT_EQ(flag, 2);
1112 
1113     /**
1114      * @tc.steps: step4. call ProcessAllVisibleCallback with 0 from 0
1115      * @tc.expected: flag is 2
1116      */
1117     one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0);
1118     EXPECT_EQ(flag, 2);
1119 
1120     /**
1121      * @tc.steps: step5. call ProcessAllVisibleCallback with 1 from 0
1122      * @tc.expected: flag is 3
1123      */
1124     one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 0);
1125     EXPECT_EQ(flag, 3);
1126 
1127     /**
1128      * @tc.steps: step6. call ProcessAllVisibleCallback with 1 from 1
1129      * @tc.expected: flag is 3
1130      */
1131     one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 1);
1132     EXPECT_EQ(flag, 3);
1133 }
1134 
1135 /**
1136  * @tc.name: FrameNodeTestNg_AnimateHoverEffect0034
1137  * @tc.desc: Test AnimateHoverEffect
1138  * @tc.type: FUNC
1139  */
1140 HWTEST_F(FrameNodeTestNg, FrameNodeAnimateHoverEffect0034, TestSize.Level1)
1141 {
1142     /**
1143      * @tc.steps: step1. create a frame node and release inputEventHub_, then
1144             change hoverEffectType_ and call AnimateHoverEffect
1145      * @tc.expected: AnimateHoverEffectScale has been called
1146      */
__anon08da311b0a02() 1147     auto one = FrameNode::GetOrCreateFrameNode("one", 12, []() { return AceType::MakeRefPtr<Pattern>(); });
1148     one->eventHub_->inputEventHub_ = nullptr;
1149     auto renderContext = AceType::DynamicCast<MockRenderContext>(one->renderContext_);
1150     EXPECT_CALL(*renderContext, AnimateHoverEffectScale(_));
1151     one->AnimateHoverEffect(false);
1152     auto inputEventHub = one->eventHub_->GetOrCreateInputEventHub();
1153     inputEventHub->hoverEffectType_ = HoverEffectType::UNKNOWN;
1154     one->AnimateHoverEffect(false);
1155     inputEventHub->hoverEffectType_ = HoverEffectType::AUTO;
1156     one->AnimateHoverEffect(false);
1157     inputEventHub->hoverEffectType_ = HoverEffectType::SCALE;
1158     one->AnimateHoverEffect(false);
1159     inputEventHub->hoverEffectType_ = HoverEffectType::BOARD;
1160     one->AnimateHoverEffect(false);
1161     inputEventHub->hoverEffectType_ = HoverEffectType::OPACITY;
1162     one->AnimateHoverEffect(false);
1163     inputEventHub->hoverEffectType_ = HoverEffectType::NONE;
1164     one->AnimateHoverEffect(false);
1165 }
1166 
1167 /**
1168  * @tc.name: FrameNodeTestNg_CreateAnimatablePropertyFloat0035
1169  * @tc.desc: Test AnimateHoverEffect
1170  * @tc.type: FUNC
1171  */
1172 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatablePropertyFloat0035, TestSize.Level1)
1173 {
1174     /**
1175      * @tc.steps: step1. call CreateAnimatablePropertyFloat.
1176      * @tc.expected: expect GetRenderContext is not null.
1177      */
1178     FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1179 
1180     FRAME_NODE->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1181     FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1182 
1183     /**
1184      * @tc.steps: step2. put value to map and call CreateAnimatablePropertyFloat.
1185      * @tc.expected: expect iter is not equal map.
1186      */
1187     FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1188     FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1189     auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1190     auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1191     EXPECT_NE(iter, map);
1192 }
1193 
1194 /**
1195  * @tc.name: FrameNodeTestNg_UpdateAnimatablePropertyFloat0036
1196  * @tc.desc: Test AnimateHoverEffect
1197  * @tc.type: FUNC
1198  */
1199 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatablePropertyFloat0036, TestSize.Level1)
1200 {
1201     /**
1202      * @tc.steps: step1. call UpdateAnimatablePropertyFloat.
1203      * @tc.expected: expect iter is not equal map.
1204      */
1205     FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1206     FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1207     FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1208     FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1209     auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1210     auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1211     EXPECT_NE(iter, map);
1212 
1213     /**
1214      * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1215      * @tc.expected: expect property is nullptr.
1216      */
1217     FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1218     FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1219     auto property = AceType::DynamicCast<NodeAnimatablePropertyFloat>(iter->second);
1220     EXPECT_EQ(property, nullptr);
1221 }
1222 
1223 /**
1224  * @tc.name: FrameNodeTestNg_CreateAnimatableArithmeticProperty0037
1225  * @tc.desc: Test AnimateHoverEffect
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatableArithmeticProperty0037, TestSize.Level1)
1229 {
1230     /**
1231      * @tc.steps: step1. call CreateAnimatableArithmeticProperty.
1232      * @tc.expected: expect iter is not equal map.
1233      */
1234     RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1235     std::function<void(const RefPtr<NG::CustomAnimatableArithmetic>&)> onCallbackEvent;
1236     FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1237     FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1238     FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1239     auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1240     auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1241     EXPECT_NE(iter, map);
1242 }
1243 
1244 /**
1245  * @tc.name: FrameNodeTestNg_UpdateAnimatableArithmeticProperty0038
1246  * @tc.desc: Test AnimateHoverEffect
1247  * @tc.type: FUNC
1248  */
1249 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatableArithmeticProperty0038, TestSize.Level1)
1250 {
1251     /**
1252      * @tc.steps: step1. call UpdateAnimatableArithmeticProperty.
1253      * @tc.expected: expect iter is not equal map.
1254      */
1255     RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1256     FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1257     FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1258 
1259     FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1260     FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1261     auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1262     auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1263     EXPECT_NE(iter, map);
1264 
1265     /**
1266      * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1267      * @tc.expected: expect property is nullptr.
1268      */
1269     FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1270     FRAME_NODE->UpdateAnimatableArithmeticProperty("", value);
1271     auto property = AceType::DynamicCast<NodeAnimatableArithmeticProperty>(iter->second);
1272     EXPECT_EQ(property, nullptr);
1273 }
1274 
1275 /**
1276  * @tc.name: FrameNodeTestNg0039
1277  * @tc.desc: Test of FrameProxy
1278  * @tc.type: FUNC
1279  */
1280 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg0039, TestSize.Level1)
1281 {
1282     /**
1283      * @tc.steps: step1. creat childNode、create LazyForEachNode
1284      * @tc.expected: childNode is not null
1285      */
1286     auto childNode = FrameNode::CreateFrameNode(
1287         "child", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1288     auto itemNode = FrameNode::CreateFrameNode(
1289         "itemNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1290     childNode->AddChild(itemNode);
1291     /**
1292      * @tc.steps: step2. call SetIsOverlayNode.
1293      * @tc.expected: change IsOverlayNode().
1294      */
1295     ConfigurationChange configurationChange;
1296     childNode->OnConfigurationUpdate(configurationChange);
1297     configurationChange.languageUpdate = true;
1298     childNode->OnConfigurationUpdate(configurationChange);
1299     configurationChange.colorModeUpdate = true;
1300     childNode->OnConfigurationUpdate(configurationChange);
1301     configurationChange.directionUpdate = true;
1302     childNode->OnConfigurationUpdate(configurationChange);
1303     configurationChange.dpiUpdate = true;
1304     childNode->OnConfigurationUpdate(configurationChange);
1305     configurationChange.fontUpdate = true;
1306     configurationChange.iconUpdate = true;
1307     configurationChange.skinUpdate = true;
1308     configurationChange.fontWeightScaleUpdate = true;
1309     childNode->OnConfigurationUpdate(configurationChange);
1310     configurationChange.fontScaleUpdate = true;
1311     childNode->OnConfigurationUpdate(configurationChange);
1312 
1313     childNode->SetBackgroundLayoutConstraint(itemNode);
1314     childNode->ForceUpdateLayoutPropertyFlag(PROPERTY_UPDATE_MEASURE_SELF);
1315     childNode->GetPaintRectWithTransform();
1316     childNode->GetTransformScale();
1317     childNode->SetJSViewActive(true);
1318     auto layoutProperty = childNode->GetLayoutProperty();
1319     EXPECT_FALSE(layoutProperty->IsOverlayNode());
1320     layoutProperty->SetIsOverlayNode(true);
1321     childNode->DumpOverlayInfo();
1322     EXPECT_TRUE(layoutProperty->IsOverlayNode());
1323 }
1324 
1325 /**
1326  * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback040
1327  * @tc.desc: Test frame node method
1328  * @tc.type: FUNC
1329  */
1330 HWTEST_F(FrameNodeTestNg, SetOnAreaChangeCallback040, TestSize.Level1)
1331 {
1332     /**
1333      * @tc.steps: step1. build a object to SetOnAreaChangeCallback
1334      * @tc.expected: expect cover branch lastFrameRect_ non null and function is run ok.
1335      */
1336     OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon08da311b0b02(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 1337                                      const OffsetF& origin) {};
1338     FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
1339     FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
1340     EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
1341 
1342     /**
1343      * @tc.steps: step2.test while callback is nullptr
1344      * @tc.expected:expect cover branch lastParentOffsetToWindow_ non null and function is run ok.
1345      */
1346 
1347     FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
1348     FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
1349     EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
1350 }
1351 
1352 /**
1353  * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread040
1354  * @tc.desc: Test frame node method
1355  * @tc.type: FUNC
1356  */
1357 HWTEST_F(FrameNodeTestNg, SwapDirtyLayoutWrapperOnMainThread040, TestSize.Level1)
1358 {
1359     /**
1360      * @tc.steps: step1. creat frameNode and layoutProperty
1361      */
1362     RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
1363     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1364     auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>();
1365     ASSERT_NE(layoutProperty, nullptr);
1366 
1367     /**
1368      * @tc.steps: step2. setBorderWidth and updateBorderWidth.
1369      * @tc.expected: expect borderWidth property is not nullptr.
1370      */
1371     BorderWidthProperty overCountBorderWidth;
1372     overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP));
1373     layoutProperty->UpdateBorderWidth(overCountBorderWidth);
1374     frameNode->SetLayoutProperty(layoutProperty);
1375 
1376     /**
1377      * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
1378      * @tc.expected: expect GetBorderWidthProperty is not nullptr.
1379      */
1380     frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1381     EXPECT_NE(layoutProperty->GetBorderWidthProperty(), nullptr);
1382 
1383     /**
1384      * @tc.steps: step4. updatae layoutConstraint and set eventHub_.
1385      * @tc.expected: expect cover branch eventHub_ non null and function is run ok .
1386      */
1387     auto layoutConstraintF_ = LayoutConstraintF();
1388     layoutConstraintF_.maxSize = CONTAINER_SIZE;
1389     layoutConstraintF_.percentReference = CONTAINER_SIZE;
1390     frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
1391     layoutProperty->UpdateLayoutConstraint(layoutConstraintF_);
1392 
1393     frameNode->eventHub_->GetOrCreateFocusHub();
1394     frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1395     EXPECT_NE(frameNode->eventHub_, nullptr);
1396 
1397     /**
1398      * @tc.steps: step5. set currentFocus_ is true and call SwapDirtyLayoutWrapperOnMainThread.
1399      * @tc.expected: expect cover branch IsCurrentFocus() is true and function is run ok .
1400      */
1401     frameNode->eventHub_->GetOrCreateFocusHub()->currentFocus_ = true;
1402     frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1403     EXPECT_TRUE(frameNode->eventHub_->GetOrCreateFocusHub()->IsCurrentFocus());
1404 }
1405 
1406 /**
1407  * @tc.name: FrameNodeTouchTest047
1408  * @tc.desc: Test method GeometryNodeToJsonValue
1409  * @tc.type: FUNC
1410  */
1411 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest047, TestSize.Level1)
1412 {
1413     /**
1414      * @tc.steps: step1. construct parameters.
1415      */
1416     std::unique_ptr<JsonValue> value = JsonUtil::Create(true);
1417 
1418     /**
1419      * @tc.steps: step2. construct parameters.
1420      * @tc.expected: expect cover branch layoutProperty_ is nullptr.
1421      */
1422     FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1423     EXPECT_EQ(FRAME_NODE2->layoutProperty_, nullptr);
1424 
1425     /**
1426      * @tc.steps: step3. set layoutProperty_ and call GeometryNodeToJsonValue.
1427      * @tc.expected: expect cover branch layoutProperty_ is not nullptr.
1428      */
1429     auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1430     FRAME_NODE2->layoutProperty_ = layoutProperty;
1431     FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1432     EXPECT_NE(FRAME_NODE2->layoutProperty_, nullptr);
1433 
1434     /**
1435      * @tc.steps: step4. set calcLayoutConstraint_ and call GeometryNodeToJsonValue.
1436      * @tc.expected: expect cover branch calcLayoutConstraint_ is not nullptr.
1437      */
1438     FRAME_NODE2->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1439 
1440     FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1441     EXPECT_NE(FRAME_NODE2->layoutProperty_->calcLayoutConstraint_, nullptr);
1442 
1443     /**
1444      * @tc.steps: step5. set selfIdealSize and call GeometryNodeToJsonValue.
1445      * @tc.expected: expect cover branch selfIdealSize has value.
1446      */
1447     std::optional<CalcLength> len = CalcLength("auto");
1448     FRAME_NODE2->layoutProperty_->calcLayoutConstraint_->selfIdealSize = CalcSize(len, len);
1449     FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1450     EXPECT_NE(FRAME_NODE2->renderContext_, nullptr);
1451 
1452     FRAME_NODE2->layoutProperty_ = nullptr;
1453 }
1454 
1455 /**
1456  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback048
1457  * @tc.desc: Test frame node method
1458  * @tc.type: FUNC
1459  */
1460 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback048, TestSize.Level1)
1461 {
1462     /**
1463      * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1464      * @tc.expected: expect The function is run ok.
1465      */
1466     VisibleCallbackInfo callbackInfo;
1467     constexpr uint32_t minInterval = 100; // 100ms
1468     int flag = 0;
__anon08da311b0c02(bool input1, double input2) 1469     callbackInfo.callback = [&flag](bool input1, double input2) { flag += 1; };
1470     callbackInfo.period = minInterval;
1471     FRAME_NODE2->SetVisibleAreaUserCallback({ 0.2, 0.8, 0.21, 0.79, 0.5 }, callbackInfo);
1472     FRAME_NODE2->ProcessThrottledVisibleCallback();
1473     EXPECT_EQ(FRAME_NODE2->throttledCallbackOnTheWay_, false);
1474 }
1475 
1476 /**
1477  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback049
1478  * @tc.desc: Test the function GetValidLeafChildNumber
1479  * @tc.type: FUNC
1480  */
1481 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback049, TestSize.Level1)
1482 {
1483     /**
1484      * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1485      * @tc.expected: expect The function is run ok.
1486      */
1487     int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1488     const RefPtr<FrameNode> node =
1489         FrameNode::CreateFrameNode("TriggerVisibleAreaChangeCallback001", nodeId, AceType::MakeRefPtr<Pattern>(), true);
1490 
1491     /**
1492      * @tc.steps2: Call the function GetValidLeafChildNumber.
1493      * @tc.expected: Value returned as expected.
1494      */
1495     EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1496     const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>(), true);
1497     GET_CHILD1->UpdateInspectorId("child1");
1498     node->AddChild(GET_CHILD1);
1499     EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1500 
1501     const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>(), true);
1502     GET_CHILD2->UpdateInspectorId("child2");
1503     node->AddChild(GET_CHILD2);
1504     EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 3), 2);
1505 }
1506 
1507 /**
1508  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback050
1509  * @tc.desc: Test the function MarkAndCheckNewOpIncNode
1510  * @tc.type: FUNC
1511  */
1512 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback050, TestSize.Level1)
1513 {
1514     /**
1515      * @tc.steps: step1. creat node and generate a node tree.
1516      */
1517     RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>());
1518     RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>());
1519     RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>());
1520     GET_PARENT->AddChild(GET_CHILD1);
1521     GET_PARENT->AddChild(GET_CHILD2);
1522     GET_CHILD1->MarkAndCheckNewOpIncNode();
1523     EXPECT_FALSE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1524 
1525     /**
1526      * @tc.steps2: set suggestOpIncByte_ and call the function MarkAndCheckNewOpIncNode.
1527      * @tc.expected: Value returned as expected.
1528      */
1529     GET_PARENT->suggestOpIncByte_ = 7;
1530     GET_CHILD1->SetSuggestOpIncActivatedOnce();
1531     GET_PARENT->SetSuggestOpIncActivatedOnce();
1532     GET_CHILD1->MarkAndCheckNewOpIncNode();
1533     EXPECT_TRUE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1534     GET_CHILD1->suggestOpIncByte_ = 1;
1535     GET_CHILD1->MarkAndCheckNewOpIncNode();
1536 }
1537 
1538 /**
1539  * @tc.name: FrameNodeTouchTest051
1540  * @tc.desc: Test frameNode FindSuggestOpIncNode
1541  * @tc.type: FUNC
1542  */
1543 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest051, TestSize.Level1)
1544 {
1545     /**
1546      * @tc.steps: step1. initialize parameters.
1547      */
1548     std::string tag = "test";
1549     auto frameNode = FrameNode::CreateFrameNode(tag, 1, AceType::MakeRefPtr<Pattern>(), true);
1550     auto frameNode1 = FrameNode::CreateFrameNode("test1", 2, AceType::MakeRefPtr<Pattern>(), true);
1551     frameNode->AddChild(frameNode1);
1552     frameNode->GetBaselineDistance();
1553 
1554     /**
1555      * @tc.steps: step2. set frame size and call FindSuggestOpIncNode
1556      * @tc.expected: expect result value.
1557      */
1558     frameNode->geometryNode_->SetFrameSize(SizeF(20, 20));
1559     auto result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1560     EXPECT_EQ(result, 3);
1561     result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1562     EXPECT_EQ(result, 2);
1563     SystemProperties::debugEnabled_ = true;
1564     frameNode->suggestOpIncByte_ = 0;
1565     result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1566     EXPECT_EQ(result, 3);
1567 }
1568 
1569 /**
1570  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback052
1571  * @tc.desc: Test the function IsOpIncValidNode
1572  * @tc.type: FUNC
1573  */
1574 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback052, TestSize.Level1)
1575 {
1576     /**
1577      * @tc.steps: step1. initialize parameters.
1578      */
1579 
1580     SizeF boundary(1, 1);
1581     int32_t childNumber = 2;
1582 
1583     /**
1584      * @tc.steps2: call the function IsOpIncValidNode.
1585      * @tc.expected: Value returned as expected.
1586      */
1587     auto result = FRAME_NODE2->IsOpIncValidNode(boundary, childNumber);
1588     EXPECT_EQ(result, 2);
1589 
1590     FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1591     result = FRAME_NODE2->IsOpIncValidNode(boundary, childNumber);
1592     EXPECT_EQ(result, 3);
1593 
1594     SizeF boundary1(40, 40);
1595     FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1596     result = FRAME_NODE2->IsOpIncValidNode(boundary1, childNumber);
1597     EXPECT_EQ(result, 2);
1598 }
1599 
1600 /**
1601  * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback053
1602  * @tc.desc: Test the function MarkSuggestOpIncGroup
1603  * @tc.type: FUNC
1604  */
1605 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback053, TestSize.Level1)
1606 {
1607     /**
1608      * @tc.steps1: call the function MarkSuggestOpIncGroup.
1609      * @tc.expected: Value returned as expected.
1610      */
1611     EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1612 
1613     FRAME_NODE2->SetCanSuggestOpInc(true);
1614     FRAME_NODE2->SetSuggestOpIncMarked(true);
1615     FRAME_NODE2->SetOpIncGroupCheckedThrough(true);
1616     EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1617 
1618     FRAME_NODE2->SetSuggestOpIncMarked(false);
1619     FRAME_NODE2->SetCanSuggestOpInc(false);
1620     FRAME_NODE2->SetOpIncGroupCheckedThrough(false);
1621     EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1622 }
1623 
1624 /**
1625  * @tc.name: FrameNodeTestNg_IsPaintRectWithTransformValid054
1626  * @tc.desc: Test frame node method IsPaintRectWithTransformValid
1627  * @tc.type: FUNC
1628  */
1629 HWTEST_F(FrameNodeTestNg, FrameNodeIsPaintRectWithTransformValid054, TestSize.Level1)
1630 {
1631     /**
1632      * @tc.steps: step1. callback IsPaintRectWithTransformValid.
1633      * @tc.expected: expect The function return value is true when width or height is nearZero.
1634      */
1635     auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1636     auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
1637     node->renderContext_ = mockRenderContext;
1638 
1639     mockRenderContext->rect_ = RectF(0, 0, 0, 10);
1640     auto test1 = node->IsPaintRectWithTransformValid();
1641     EXPECT_TRUE(test1);
1642 
1643     mockRenderContext->rect_ = RectF(0, 0, 10, 0);
1644     auto test2 = node->IsPaintRectWithTransformValid();
1645     EXPECT_TRUE(test2);
1646 
1647     mockRenderContext->rect_ = RectF(0, 0, 10, 10);
1648     auto test3 = node->IsPaintRectWithTransformValid();
1649     EXPECT_FALSE(test3);
1650 
1651     mockRenderContext->rect_ = RectF(0, 0, 0, 0);
1652     auto test4 = node->IsPaintRectWithTransformValid();
1653     EXPECT_TRUE(test4);
1654 }
1655 
1656 /**
1657  * @tc.name: FrameNodeSetJSCustomProperty055
1658  * @tc.desc: Test SetJSCustomProperty isCNode true, expect result updateFlag is false.
1659  * @tc.type: FUNC
1660  */
1661 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty055, TestSize.Level1)
1662 {
1663     /**
1664      * @tc.steps: step1. initialize parameters.
1665      */
1666     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1667 
1668     /**
1669      * @tc.steps: step2. set isCNode true
1670      * @tc.expected: expect result updateFlag is false.
1671      */
1672     frameNode->setIsCNode(true);
__anon08da311b0d02() 1673     std::function<bool()> func = []() -> bool { return true; };
__anon08da311b0e02(const std::string& key) 1674     std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1675         return "getFuncA";
1676     };
1677     frameNode->SetJSCustomProperty(func, getFuncA);
1678     std::string value;
1679     bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", value);
1680     EXPECT_EQ(updateFlagValue, false);
1681 }
1682 
1683 /**
1684  * @tc.name: FrameNodeSetJSCustomProperty056
1685  * @tc.desc: Test SetJSCustomProperty isCNode false and func true, expect result updateFlag is true.
1686  * @tc.type: FUNC
1687  */
1688 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty056, TestSize.Level1)
1689 {
1690     /**
1691      * @tc.steps: step1. initialize parameters.
1692      */
1693     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1694 
1695     /**
1696      * @tc.steps: step2. set isCNode false and func true.
1697      * @tc.expected: expect result updateFlag is true.
1698      */
1699     frameNode->setIsCNode(false);
__anon08da311b0f02() 1700     std::function<bool()> func = []() -> bool { return true; };
__anon08da311b1002(const std::string& key) 1701     std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1702         return "getFuncA";
1703     };
1704     frameNode->SetJSCustomProperty(func, getFuncA);
1705     frameNode->setIsCNode(true);
1706     std::string flagValue;
1707     bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", flagValue);
1708     EXPECT_EQ(updateFlagValue, true);
1709     EXPECT_EQ(flagValue, "1");
1710 }
1711 
1712 /**
1713  * @tc.name: FrameNodeSetJSCustomProperty057
1714  * @tc.desc: Test SetJSCustomProperty isCNode false and func false, expect result updateFlag is false.
1715  * @tc.type: FUNC
1716  */
1717 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty057, TestSize.Level1)
1718 {
1719     /**
1720      * @tc.steps: step1. initialize parameters.
1721      */
1722     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1723 
1724     /**
1725      * @tc.steps: step2. set isCNode false and func false.
1726      * @tc.expected: expect result updateFlag is false.
1727      */
1728     frameNode->setIsCNode(false);
__anon08da311b1102() 1729     std::function<bool()> func = []() -> bool { return false; };
__anon08da311b1202(const std::string& key) 1730     std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1731         return "getFuncA";
1732     };
1733     frameNode->SetJSCustomProperty(func, getFuncA);
1734     frameNode->setIsCNode(true);
1735     std::string flagValue;
1736     bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", flagValue);
1737     EXPECT_EQ(updateFlagValue, false);
1738 }
1739 
1740 /**
1741  * @tc.name: FrameNodeGetJSCustomProperty058
1742  * @tc.desc: Test GetJSCustomProperty getCustomProperty_ value getFuncA, expect result value getFuncA.
1743  * @tc.type: FUNC
1744  */
1745 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty058, TestSize.Level1)
1746 {
1747     /**
1748      * @tc.steps: step1. initialize parameters.
1749      */
1750     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1751 
1752     /**
1753      * @tc.steps: step2. set getCustomProperty_ value getFuncA.
1754      * @tc.expected: expect result value getFuncA.
1755      */
__anon08da311b1302() 1756     std::function<bool()> func = []() -> bool { return true; };
__anon08da311b1402(const std::string& key) 1757     std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1758         return "getFuncA";
1759     };
1760     frameNode->SetJSCustomProperty(func, getFuncA);
1761     std::string getValue;
1762     bool result = frameNode->GetJSCustomProperty("key", getValue);
1763     EXPECT_EQ(result, true);
1764     EXPECT_EQ(getValue, "getFuncA");
1765 }
1766 
1767 /**
1768  * @tc.name: FrameNodeGetJSCustomProperty059
1769  * @tc.desc: Test GetJSCustomProperty getCustomProperty_ nullptr
1770  * @tc.type: FUNC
1771  */
1772 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty059, TestSize.Level1)
1773 {
1774     /**
1775      * @tc.steps: step1. initialize parameters.
1776      */
1777     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1778 
1779     /**
1780      * @tc.steps: step2. set getCustomProperty_ nullptr
1781      * @tc.expected: expect result GetJSCustomProperty false.
1782      */
__anon08da311b1502() 1783     std::function<bool()> func = []() -> bool { return true; };
1784     frameNode->SetJSCustomProperty(func, nullptr);
1785     std::string getValue;
1786     bool result = frameNode->GetJSCustomProperty("key", getValue);
1787     EXPECT_EQ(result, false);
1788 }
1789 
1790 /**
1791  * @tc.name: FrameNodeGetCapiCustomProperty060
1792  * @tc.desc: Test GetCapiCustomProperty no key value value value added.
1793  * @tc.type: FUNC
1794  */
1795 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty060, TestSize.Level1)
1796 {
1797     /**
1798      * @tc.steps: step1. initialize parameters.
1799      */
1800     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1801 
1802     /**
1803      * @tc.steps: step2. GetCapiCustomProperty
1804      * @tc.expected: expect result value false.
1805      */
1806     frameNode->setIsCNode(false);
1807     std::string value;
1808     bool result = frameNode->GetCapiCustomProperty("key", value);
1809     EXPECT_EQ(result, false);
1810 }
1811 
1812 /**
1813  * @tc.name: FrameNodeGetCapiCustomProperty061
1814  * @tc.desc: Test GetCapiCustomProperty the key value value value exists.
1815  * @tc.type: FUNC
1816  */
1817 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty061, TestSize.Level1)
1818 {
1819     /**
1820      * @tc.steps: step1. initialize parameters.
1821      */
1822     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1823 
1824     /**
1825      * @tc.steps: step2. add the key value as value1.
1826      * @tc.expected: expect result value1.
1827      */
1828     frameNode->setIsCNode(true);
1829     frameNode->AddCustomProperty("key", "value1");
1830     std::string value;
1831     bool result = frameNode->GetCapiCustomProperty("key", value);
1832     EXPECT_EQ(result, true);
1833     EXPECT_EQ(value, "value1");
1834 }
1835 
1836 /**
1837  * @tc.name: FrameNodeGetCapiCustomProperty062
1838  * @tc.desc: Test GetCapiCustomProperty the key value does not exist.
1839  * @tc.type: FUNC
1840  */
1841 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty062, TestSize.Level1)
1842 {
1843     /**
1844      * @tc.steps: step1. initialize parameters.
1845      */
1846     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1847 
1848     /**
1849      * @tc.steps: step2. set key is value1
1850      * @tc.expected: expect result value.
1851      */
1852     frameNode->setIsCNode(true);
1853     frameNode->AddCustomProperty("key", "value1");
1854     std::string value;
1855     bool result = frameNode->GetCapiCustomProperty("key1", value);
1856     EXPECT_EQ(result, false);
1857 }
1858 
1859 /**
1860  * @tc.name: FrameNodeRemoveCustomProperty063
1861  * @tc.desc: Test RemoveCustomProperty.
1862  * @tc.type: FUNC
1863  */
1864 HWTEST_F(FrameNodeTestNg, FrameNodeRemoveCustomProperty063, TestSize.Level1)
1865 {
1866     /**
1867      * @tc.steps: step1. initialize parameters.
1868      */
1869     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1870 
1871     /**
1872      * @tc.steps: step2. set key is value1, remove key.
1873      * @tc.expected: expect result false.
1874      */
1875     frameNode->setIsCNode(true);
1876     frameNode->AddCustomProperty("key", "value1");
1877     frameNode->RemoveCustomProperty("key");
1878     std::string value;
1879     bool result = frameNode->GetCapiCustomProperty("key", value);
1880     EXPECT_EQ(result, false);
1881 }
1882 } // namespace OHOS::Ace::NG
1883