• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "core/event/touch_event.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS::Ace::NG {
23 namespace {} // namespace
24 
25 /**
26  * @tc.name: ResetLayoutAlgorithmTest1
27  * @tc.desc: Test the function ResetLayoutAlgorithm with default param
28  * @tc.type: FUNC
29  */
30 HWTEST_F(FrameNodeTestNg, ResetLayoutAlgorithmTest1, TestSize.Level1)
31 {
32     /**
33      * @tc.steps: step1. create frameNode.
34      */
35     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
36     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>());
37     auto frameNode3 = FrameNode::CreateFrameNode("framenode", 3, AceType::MakeRefPtr<Pattern>());
38     /**
39      * @tc.steps: step2. mount nodes and create layoutAlgorithm
40      */
41     frameNode2->MountToParent(frameNode1);
42     frameNode3->MountToParent(frameNode2);
43     EXPECT_NE(frameNode1->GetLayoutAlgorithm(), nullptr);
44     EXPECT_NE(frameNode2->GetLayoutAlgorithm(), nullptr);
45     EXPECT_NE(frameNode3->GetLayoutAlgorithm(), nullptr);
46     /**
47      * @tc.steps: step2. start to clear. layoutAlgo of frameNode1 will not not be cleared
48      */
49     frameNode1->ClearSubtreeLayoutAlgorithm(false);
50     EXPECT_TRUE(frameNode1->HasLayoutAlgorithm());
51     EXPECT_FALSE(frameNode2->HasLayoutAlgorithm());
52     EXPECT_FALSE(frameNode3->HasLayoutAlgorithm());
53 }
54 
55 /**
56  * @tc.name: ResetLayoutAlgorithmTest2
57  * @tc.desc: Test the function ResetLayoutAlgorithm with default param
58  * @tc.type: FUNC
59  */
60 HWTEST_F(FrameNodeTestNg, ResetLayoutAlgorithmTest2, TestSize.Level1)
61 {
62     /**
63      * @tc.steps: step1. create frameNode.
64      */
65     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
66     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>());
67     auto frameNode3 = FrameNode::CreateFrameNode("framenode", 3, AceType::MakeRefPtr<Pattern>());
68 
69     /**
70      * @tc.steps: step2. mount nodes and create layoutAlgorithm
71      */
72     frameNode2->MountToParent(frameNode1);
73     frameNode3->MountToParent(frameNode2);
74     EXPECT_NE(frameNode1->GetLayoutAlgorithm(), nullptr);
75     EXPECT_NE(frameNode2->GetLayoutAlgorithm(), nullptr);
76     EXPECT_NE(frameNode3->GetLayoutAlgorithm(), nullptr);
77     /**
78      * @tc.steps: step3. start to clear. layoutAlgo of frameNode1 will not not be cleared
79      */
80     frameNode1->ClearSubtreeLayoutAlgorithm(true);
81     EXPECT_FALSE(frameNode1->HasLayoutAlgorithm());
82     EXPECT_FALSE(frameNode2->HasLayoutAlgorithm());
83     EXPECT_FALSE(frameNode3->HasLayoutAlgorithm());
84 }
85 
86 /**
87  * @tc.name: ResetLayoutAlgorithmTest3
88  * @tc.desc: Test the function ResetLayoutAlgorithm and node3 should still have layoutAlgorithm
89  * because chain broke at node2
90  * @tc.type: FUNC
91  */
92 HWTEST_F(FrameNodeTestNg, ResetLayoutAlgorithmTest3, TestSize.Level1)
93 {
94     /**
95      * @tc.steps: step1. create frameNode.
96      */
97     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
98     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>());
99     auto frameNode3 = FrameNode::CreateFrameNode("framenode", 3, AceType::MakeRefPtr<Pattern>());
100     /**
101      * @tc.steps: step2. mount nodes and create layoutAlgorithm
102      */
103     frameNode2->MountToParent(frameNode1);
104     frameNode3->MountToParent(frameNode2);
105     EXPECT_NE(frameNode1->GetLayoutAlgorithm(), nullptr);
106     EXPECT_NE(frameNode3->GetLayoutAlgorithm(), nullptr);
107     /**
108      * @tc.steps: step3. start to clear. layoutAlgo of frameNode1 will not not be cleared
109      */
110     frameNode1->ClearSubtreeLayoutAlgorithm(true);
111     EXPECT_FALSE(frameNode1->HasLayoutAlgorithm());
112     EXPECT_FALSE(frameNode2->HasLayoutAlgorithm());
113     EXPECT_TRUE(frameNode3->HasLayoutAlgorithm());
114 }
115 
116 /**
117  * @tc.name: ResetLayoutAlgorithmTest4
118  * @tc.desc: Test the function ResetLayoutAlgorithm with clearing the whole tree
119  * @tc.type: FUNC
120  */
121 HWTEST_F(FrameNodeTestNg, ResetLayoutAlgorithmTest4, TestSize.Level1)
122 {
123     /**
124      * @tc.steps: step1. create frameNode.
125      */
126     auto frameNode1 = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
127     auto frameNode2 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>());
128     auto frameNode3 = FrameNode::CreateFrameNode("framenode", 3, AceType::MakeRefPtr<Pattern>());
129     /**
130      * @tc.steps: step2. mount nodes and create layoutAlgorithm
131      */
132     frameNode2->MountToParent(frameNode1);
133     frameNode3->MountToParent(frameNode2);
134     EXPECT_NE(frameNode1->GetLayoutAlgorithm(), nullptr);
135     EXPECT_NE(frameNode3->GetLayoutAlgorithm(), nullptr);
136     /**
137      * @tc.steps: step3. start to clear. layoutAlgo of frameNode1 will not not be cleared
138      */
139     frameNode1->ClearSubtreeLayoutAlgorithm(true, true);
140     EXPECT_FALSE(frameNode1->HasLayoutAlgorithm());
141     EXPECT_FALSE(frameNode2->HasLayoutAlgorithm());
142     EXPECT_FALSE(frameNode3->HasLayoutAlgorithm());
143 }
144 /**
145  * @tc.name: FrameNodeGetExtraCustomProperty001
146  * @tc.desc: Test GetExtraCustomProperty.
147  * @tc.type: FUNC
148  */
149 HWTEST_F(FrameNodeTestNg, FrameNodeGetExtraCustomProperty001, TestSize.Level1)
150 {
151     /**
152      * @tc.steps: step1. initialize parameters.
153      */
154     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
155     char value[7]= "value1";
156     /**
157      * @tc.steps: step2. set key is value1
158      * @tc.expected: expect result value.
159      */
160     frameNode->setIsCNode(true);
161     frameNode->AddExtraCustomProperty("key", value);
162     bool result = frameNode->GetExtraCustomProperty("key1");
163     EXPECT_EQ(result, false);
164 }
165 
166 /**
167  * @tc.name: FrameNodeGetExtraCustomProperty002
168  * @tc.desc: Test GetExtraCustomProperty.
169  * @tc.type: FUNC
170  */
171 HWTEST_F(FrameNodeTestNg, FrameNodeGetExtraCustomProperty002, TestSize.Level1)
172 {
173     /**
174      * @tc.steps: step1. initialize parameters.
175      */
176     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
177 
178     /**
179      * @tc.steps: step2. set key is value
180      * @tc.expected: expect result value.
181      */
182     char value[7]= "value1";
183     frameNode->setIsCNode(true);
184     frameNode->AddExtraCustomProperty("key", value);
185     bool result = frameNode->GetExtraCustomProperty("key");
186     EXPECT_EQ(result, true);
187 }
188 
189 /**
190  * @tc.name: FrameNodeRemoveExtraCustomProperty001
191  * @tc.desc: Test RemoveExtraCustomProperty.
192  * @tc.type: FUNC
193  */
194 HWTEST_F(FrameNodeTestNg, FrameNodeRemoveExtraCustomProperty001, TestSize.Level1)
195 {
196     /**
197      * @tc.steps: step1. initialize parameters.
198      */
199     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
200 
201     /**
202      * @tc.steps: step2. set key is value1, remove key.
203      * @tc.expected: expect result false.
204      */
205     char value[7]= "value1";
206     frameNode->setIsCNode(true);
207     frameNode->AddExtraCustomProperty("key", value);
208     frameNode->RemoveExtraCustomProperty("key");
209     bool result = frameNode->GetExtraCustomProperty("key");
210     EXPECT_EQ(result, false);
211 }
212 
213 /**
214  * @tc.name: FrameTestNg100
215  * @tc.desc: Test CollectSelfAxisResult.
216  * @tc.type: FUNC
217  */
218 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg100, TestSize.Level1)
219 {
220     /**
221      * @tc.steps: step1. initialize parameters.
222      */
223     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
224     PointF globalPoint;
225     PointF localPoint;
226     PointF parentRevertPoint;
227     AxisTestResult onAxisResult;
228     HitTestResult testResult;
229     TouchRestrict touchRestrict;
230     bool isConsumed = true;
231     bool isPreventBubbling = false;
232     SystemProperties::debugEnabled_ = true;
233     auto eventHub = AceType::MakeRefPtr<EventHub>();
234     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
235     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
236     gestureEventHub->SetHitTestMode(HitTestMode::HTMNONE);
237     eventHub->SetGestureEventHub(gestureEventHub);
238     frameNode->eventHub_ = eventHub;
239     frameNode->CollectSelfAxisResult(globalPoint, localPoint, isConsumed, parentRevertPoint,
240             onAxisResult, isPreventBubbling, testResult, touchRestrict, false);
241     EXPECT_EQ(testResult, HitTestResult::BUBBLING);
242     gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
243     isConsumed = false;
244     frameNode->CollectSelfAxisResult(globalPoint, localPoint, isConsumed, parentRevertPoint,
245             onAxisResult, isPreventBubbling, testResult, touchRestrict, false);
246     EXPECT_EQ(testResult, HitTestResult::STOP_BUBBLING);
247 }
248 
249 /**
250  * @tc.name: FrameTestNg101
251  * @tc.desc: Test GetOrCreateFocusHub.
252  * @tc.type: FUNC
253  */
254 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg101, TestSize.Level1)
255 {
256     /**
257      * @tc.steps: step1. initialize parameters.
258      */
259     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
260     frameNode->focusHub_ = nullptr;
261     frameNode->pattern_ = nullptr;
262     auto focusHub = frameNode->GetOrCreateFocusHub();
263     EXPECT_NE(focusHub, nullptr);
264     auto focusHub2 = frameNode->GetOrCreateFocusHub();
265     EXPECT_NE(focusHub2, nullptr);
266     frameNode->focusHub_ = nullptr;
267     frameNode->pattern_ = AceType::MakeRefPtr<Pattern>();
268     auto focusHub3 = frameNode->GetOrCreateFocusHub();
269     EXPECT_NE(focusHub3, nullptr);
270     FocusPattern focusPattern = { FocusType::NODE, false };
271     auto focusHub4 = frameNode->GetOrCreateFocusHub(focusPattern);
272     EXPECT_NE(focusHub4, nullptr);
273     frameNode->focusHub_ = nullptr;
274     frameNode->pattern_ = nullptr;
275     auto focusHub5 = frameNode->GetOrCreateFocusHub(focusPattern);
276     frameNode->pattern_ = AceType::MakeRefPtr<Pattern>();
277     EXPECT_NE(focusHub5, nullptr);
278 }
279 
280 /**
281  * @tc.name: FrameTestNg102
282  * @tc.desc: Test Window state and position.
283  * @tc.type: FUNC
284  */
285 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg102, TestSize.Level1)
286 {
287     /**
288      * @tc.steps: step1. initialize parameters.
289      */
290     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
291     frameNode->OnWindowActivated();
292     frameNode->OnWindowDeactivated();
293     frameNode->GetPositionToScreen();
294     frameNode->GetPositionToScreenWithTransform();
295     EXPECT_NE(frameNode->renderContext_, nullptr);
296     auto parent = FrameNode::CreateFrameNode("Parent", 10, AceType::MakeRefPtr<Pattern>(), true);
297     auto one = FrameNode::CreateFrameNode("One", 20, AceType::MakeRefPtr<Pattern>());
298     parent->AddChild(one);
299     parent->topWindowBoundary_ = false;
300     one->GetPaintRectOffsetNG(true, false);
301     EXPECT_NE(one->renderContext_, nullptr);
302 }
303 
304 /**
305  * @tc.name: FrameTestNg103
306  * @tc.desc: Test GetPaintRectToWindowWithTransform.
307  * @tc.type: FUNC
308  */
309 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg103, TestSize.Level1)
310 {
311     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
312     auto child = FrameNode::CreateFrameNode("child", 20, AceType::MakeRefPtr<Pattern>());
313     frameNode->AddChild(child);
314     child->GetPaintRectToWindowWithTransform();
315     EXPECT_NE(child->geometryNode_, nullptr);
316 }
317 
318 /**
319  * @tc.name: FrameTestNg104
320  * @tc.desc: Test UpdateAccessibilityNodeRect.
321  * @tc.type: FUNC
322  */
323 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg104, TestSize.Level1)
324 {
325     auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
326     AceApplicationInfo::GetInstance().SetAccessibilityScreenReadEnabled(true);
327     frameNode->OnAccessibilityEvent(AccessibilityEventType::CLICK, "");
328     frameNode->UpdateAccessibilityNodeRect();
329     EXPECT_NE(frameNode->renderContext_, nullptr);
330 
331     AceApplicationInfo::GetInstance().SetAccessibilityScreenReadEnabled(false);
332     frameNode->UpdateAccessibilityNodeRect();
333     EXPECT_NE(frameNode->renderContext_, nullptr);
334 }
335 
336 /**
337  * @tc.name: FrameTestNg105
338  * @tc.desc: Test OnAutoEventParamUpdate.
339  * @tc.type: FUNC
340  */
341 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg105, TestSize.Level1)
342 {
343     auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
344     auto jsonValue = std::make_unique<JsonValue>();
345     jsonValue->Put(Recorder::ORIGIN_PARAM, "ORIGIN_PARAM");
346     frameNode->exposureProcessor_ = nullptr;
347     auto exposureCfg = std::make_unique<JsonValue>();
348     exposureCfg->Put(Recorder::EXPOSURE_CONFIG_RATIO, 2.2f);
349     exposureCfg->Put(Recorder::EXPOSURE_CONFIG_DURATION, 5);
350     jsonValue->Put(Recorder::EXPOSURE_CONFIG_PARAM, exposureCfg);
351     frameNode->OnAutoEventParamUpdate(jsonValue->ToString());
352     EXPECT_EQ(frameNode->exposureProcessor_, nullptr);
353     auto ep = AceType::MakeRefPtr<Recorder::ExposureProcessor>("test", "0");
354     frameNode->SetExposureProcessor(ep);
355     EXPECT_NE(frameNode->exposureProcessor_, nullptr);
356     RectF visibleRect;
357     RectF frameRect;
358     frameNode->GetVisibleRect(visibleRect, frameRect);
359     EXPECT_NE(frameNode->renderContext_, nullptr);
360 }
361 
362 /**
363  * @tc.name: FrameTestNg106
364  * @tc.desc: Test GetVisibleRectWithClip.
365  * @tc.type: FUNC
366  */
367 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg106, TestSize.Level1)
368 {
369     auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true);
370     RectF visibleRect, visibleInnerRect, frameRect;
371     frameNode->GetVisibleRectWithClip(visibleRect, visibleInnerRect, frameRect);
372     auto parent = FrameNode::CreateFrameNode("parent", 20, AceType::MakeRefPtr<Pattern>());
373     parent->AddChild(frameNode);
374     frameNode->isWindowBoundary_ = false;
375     frameNode->onMainTree_ = true;
376     frameNode->GetVisibleRectWithClip(visibleRect, visibleInnerRect, frameRect);
377     EXPECT_FALSE(frameNode->isWindowBoundary_);
378 }
379 
380 /**
381  * @tc.name: GetGlobalPositionOnDisplay001
382  * @tc.desc: Test frame node method GetGlobalPositionOnDisplay
383  * @tc.type: FUNC
384  */
385 HWTEST_F(FrameNodeTestNg, GetGlobalPositionOnDisplay001, TestSize.Level1)
386 {
387     OffsetF Offset = { 0, 0 };
388     FRAME_NODE2->SetParent(FRAME_NODE3);
389     auto globalDisplayOffset = FRAME_NODE2->GetGlobalPositionOnDisplay();
390     EXPECT_EQ(globalDisplayOffset, Offset);
391 }
392 
393 /**
394  * @tc.name: GetCacheVisibleRectTest
395  * @tc.desc: Test GetCacheVisibleRectTest.
396  * @tc.type: FUNC
397  */
398  HWTEST_F(FrameNodeTestNg, GetCacheVisibleRectTest001, TestSize.Level1)
399  {
400     /**
401      * @tc.steps: step1. initialize parameters.
402      */
403     auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), true);
404     auto parentNode = FrameNode::CreateFrameNode("testParent", 1, AceType::MakeRefPtr<Pattern>(), true);
405     parentNode->AddChild(frameNode);
406     /**
407      * @tc.steps: step2. set key is value1, remove key.
408      * @tc.expected: expect result false.
409      */
410     auto result = frameNode->GetCacheVisibleRect(0, false);
411     EXPECT_EQ(result.cumulativeScale.x, 1.0);
412     parentNode->GetRenderContext()->UpdateClipEdge(true);
413     result = frameNode->GetCacheVisibleRect(1, true);
414     EXPECT_EQ(result.cumulativeScale.x, 1.0);
415     frameNode->isWindowBoundary_ = true;
416     result = frameNode->GetCacheVisibleRect(1, true);
417     EXPECT_EQ(result.cumulativeScale.x, 1.0);
418 }
419 
420 /**
421  * @tc.name: DumpSafeAreaInfoTest
422  * @tc.desc: Test DumpSafeAreaInfo.
423  * @tc.type: FUNC
424  */
425  HWTEST_F(FrameNodeTestNg, DumpSafeAreaInfoTest001, TestSize.Level1)
426  {
427     /**
428      * @tc.steps: step1. initialize parameters.
429      */
430     auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), true);
431     std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
432     /**
433      * @tc.steps: step2. set key is value1, remove key.
434      * @tc.expected: expect result false.
435      */
436     frameNode->DumpExtensionHandlerInfo(json);
437 
438     RefPtr<NG::DrawModifier> drawModifier = AceType::MakeRefPtr<NG::DrawModifier>();
439     ASSERT_NE(drawModifier, nullptr);
440     frameNode->SetDrawModifier(drawModifier);
441 
442     frameNode->DumpExtensionHandlerInfo(json);
443     EXPECT_FALSE(json->GetValue("HasCustomerMeasure")->GetBool());
444 }
445 
446 /**
447  * @tc.name: GetCurrentPageRootNodeTest001
448  * @tc.desc: Test GetCurrentPageRootNode.
449  * @tc.type: FUNC
450  */
451  HWTEST_F(FrameNodeTestNg, GetCurrentPageRootNodeTest001, TestSize.Level1)
452  {
453     /**
454      * @tc.steps: step1. initialize parameters.
455      */
456     auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
457     auto child = FrameNode::CreateFrameNode(V2::JS_VIEW_ETS_TAG, 3, AceType::MakeRefPtr<Pattern>(), true);
458     frameNode->AddChild(child);
459     EXPECT_FALSE(frameNode->GetCurrentPageRootNode() != nullptr);
460 }
461 
462 /**
463  * @tc.name: GetCurrentPageRootNodeTest002
464  * @tc.desc: Test GetCurrentPageRootNode.
465  * @tc.type: FUNC
466  */
467  HWTEST_F(FrameNodeTestNg, GetCurrentPageRootNodeTest002, TestSize.Level1)
468  {
469     /**
470      * @tc.steps: step1. initialize parameters.
471      */
472     auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
473     auto child = FrameNode::CreateFrameNode("text", 3, AceType::MakeRefPtr<Pattern>(), true);
474     frameNode->AddChild(child);
475     EXPECT_TRUE(frameNode->GetCurrentPageRootNode() != nullptr);
476 }
477 
478 /**
479  * @tc.name: TriggerVisibleAreaChangeCallback100
480  * @tc.desc: Test TriggerVisibleAreaChangeCallback.
481  * @tc.type: FUNC
482  */
483 HWTEST_F(FrameNodeTestNg, TriggerVisibleAreaChangeCallback100, TestSize.Level1)
484 {
485     /**
486      * @tc.steps: step1. initialize parameters.
487      */
488     auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
489     auto child = FrameNode::CreateFrameNode("column", 3, AceType::MakeRefPtr<Pattern>(), false);
490     frameNode->SetActive(true);
491     child->SetActive(true);
492     frameNode->AddChild(child);
493     auto context = PipelineContext::GetCurrentContext();
494     ASSERT_NE(context, nullptr);
495     context->onShow_ = true;
496     frameNode->AttachContext(AceType::RawPtr(context));
497     child->AttachContext(AceType::RawPtr(context));
498 
499     RectF rect = RectF(0, 0, 100, 100);
500     child->renderContext_->UpdatePaintRect(rect);
501     frameNode->renderContext_->UpdatePaintRect(rect);
502     auto eventHub = child->GetOrCreateEventHub<EventHub>();
503     ASSERT_NE(eventHub, nullptr);
__anonb7bb34c50202(bool visible, double ratio) 504     auto onVisibleChange = [](bool visible, double ratio) {};
505     std::vector<double> ratioList = { 0.0, 1.0 };
506     VisibleCallbackInfo addInfo;
507     addInfo.callback = std::move(onVisibleChange);
508     addInfo.isCurrentVisible = false;
509     child->SetVisibleAreaUserCallback(ratioList, addInfo);
510     auto& visibleAreaUserCallback = eventHub->GetVisibleAreaCallback(true);
511     child->TriggerVisibleAreaChangeCallback(1, false);
512     EXPECT_FALSE(visibleAreaUserCallback.isOutOfBoundsAllowed);
513     visibleAreaUserCallback.isOutOfBoundsAllowed = true;
514     child->TriggerVisibleAreaChangeCallback(2, false);
515     EXPECT_TRUE(visibleAreaUserCallback.isOutOfBoundsAllowed);
516 }
517 } // namespace OHOS::Ace::NG