• 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 
16 #include <algorithm>
17 
18 #include "gtest/gtest.h"
19 
20 #define protected public
21 #define private public
22 
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24 
25 #include "base/hiviewdfx/hichecker/interfaces/native/innerkits/include/hichecker.h"
26 #include "base/log/ace_trace.h"
27 #include "base/memory/ace_type.h"
28 #include "base/utils/utils.h"
29 #include "core/components/common/layout/constants.h"
30 #include "core/components_ng/base/frame_node.h"
31 #include "core/components_ng/base/ui_node.h"
32 #include "core/components_ng/layout/layout_wrapper_builder.h"
33 #include "core/components_ng/layout/layout_wrapper_node.h"
34 #include "core/components_ng/pattern/custom/custom_node.h"
35 #include "core/components_ng/pattern/flex/flex_layout_algorithm.h"
36 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
37 #include "core/components_ng/pattern/list/list_pattern.h"
38 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
39 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
40 #include "core/components_ng/property/layout_constraint.h"
41 #include "core/components_ng/property/property.h"
42 #include "core/components_ng/property/safe_area_insets.h"
43 #include "core/components_ng/syntax/lazy_for_each_model.h"
44 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
45 #include "core/components_v2/inspector/inspector_constants.h"
46 #include "core/pipeline_ng/ui_task_scheduler.h"
47 
48 #undef private
49 #undef protected
50 
51 using namespace testing;
52 using namespace testing::ext;
53 
54 namespace OHOS::Ace::NG {
55 
56 class SyntaxNode : public UINode {
57     DECLARE_ACE_TYPE(SyntaxNode, UINode);
58 public:
CreateNode(const std::string & tag,int32_t nodeId)59     static RefPtr<SyntaxNode> CreateNode(const std::string& tag, int32_t nodeId)
60     {
61         auto spanNode = MakeRefPtr<SyntaxNode>(tag, nodeId);
62         return spanNode;
63     }
64 
IsAtomicNode() const65     bool IsAtomicNode() const override
66     {
67         return true;
68     }
69 
SyntaxNode(const std::string & tag,int32_t nodeId)70     explicit SyntaxNode(const std::string& tag, int32_t nodeId) : UINode(tag, nodeId) {}
71     ~SyntaxNode() override = default;
72 };
73 
74 class TestPattern : public Pattern {
75     DECLARE_ACE_TYPE(TestPattern, Pattern);
76 public:
77     TestPattern() = default;
78     ~TestPattern() override = default;
ConsumeChildrenAdjustment(const OffsetF &)79     bool ConsumeChildrenAdjustment(const OffsetF& /* offset */) override
80     {
81         return true;
82     }
83 };
84 
85 namespace {
86 constexpr int32_t NODE_ID_0 = 0;
87 constexpr int32_t NODE_ID_1 = 1;
88 constexpr int32_t NODE_ID_2 = 2;
89 constexpr int32_t NODE_ID_3 = 3;
90 
91 constexpr float RK356_WIDTH = 720.0f;
92 constexpr float RK356_HEIGHT = 1136.0f;
93 constexpr float ROW_HEIGHT = 120.0f;
94 
95 const SizeF CONTAINER_SIZE { RK356_WIDTH, RK356_HEIGHT };
96 SizeF SELF_IDEAL_SIZE { RK356_WIDTH, ROW_HEIGHT };
97 SizeF FRAME_SIZE { 0, 0 };
98 const SizeF TEST_FRAME_SIZE { 0, 0 };
99 OptionalSize IDEAL_SIZE { 0, 0 };
100 
101 const std::string TEST_TAG = "";
102 const std::string ROW_FRAME_NODE = "rowFrameNode";
103 const std::string FIRST_FRAME_NODE = "TabContent";
104 const std::string FIRST_CHILD_FRAME_NODE = "firstChildFrameNode";
105 const std::string SECOND_CHILD_FRAME_NODE = "secondChildFrameNode";
106 const std::string THIRD_CHILD_FRAME_NODE = "thirdChildFrameNode";
107 
CreateNodeAndWrapper(const std::string & tag,int32_t nodeId,RectF rf=RectF ())108 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateNodeAndWrapper(
109     const std::string& tag,
110     int32_t nodeId,
111     RectF rf = RectF())
112 {
113     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
114     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
115     geometryNode->frame_.rect_ = rf;
116     RefPtr<LayoutWrapperNode> layoutWrapper =
117         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
118 
119     return std::make_pair(node, layoutWrapper);
120 }
121 
CreateNodeAndWrapperTestPattern(const std::string & tag,int32_t nodeId,RectF rf=RectF ())122 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateNodeAndWrapperTestPattern(
123     const std::string& tag,
124     int32_t nodeId,
125     RectF rf = RectF())
126 {
127     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<TestPattern>());
128     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
129     geometryNode->frame_.rect_ = rf;
130     RefPtr<LayoutWrapperNode> layoutWrapper =
131         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
132 
133     return std::make_pair(node, layoutWrapper);
134 }
135 
CreateLayoutWrapper(const std::string & tag,int32_t nodeId)136 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(const std::string& tag, int32_t nodeId)
137 {
138     auto rowFrameNode = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<LinearLayoutPattern>(false));
139     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
140     RefPtr<LayoutWrapperNode> layoutWrapper =
141         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
142 
143     return layoutWrapper;
144 }
145 
CreateScrollableWrapper(int32_t nodeId,RectF rf=RectF ())146 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateScrollableWrapper(int32_t nodeId, RectF rf = RectF())
147 {
148     auto frameNode = FrameNode::GetOrCreateFrameNode(
149         V2::SCROLL_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ScrollPattern>(); });
150     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
151     geometryNode->frame_.rect_ = rf;
152     RefPtr<LayoutWrapperNode> layoutWrapper =
153         AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
154 
155     return std::make_pair(frameNode, layoutWrapper);
156 }
157 
MakeLayoutConstraintF()158 std::optional<LayoutConstraintF> MakeLayoutConstraintF()
159 {
160     std::optional<LayoutConstraintF> constraint;
161     constraint = std::make_optional<LayoutConstraintF>();
162     constraint->minSize = SizeF{1.0f, 2.0f};
163     constraint->maxSize = SizeF{100.0f, 200.0f};
164     constraint->percentReference = SizeF{10.0f, 20.0f};
165     constraint->parentIdealSize = OptionalSize<float>{10.0f, 20.0f};
166     constraint->selfIdealSize = OptionalSize<float>{10.0f, 20.0f};
167     return constraint;
168 }
169 
170 } // namespace
171 
172 class LayoutWrapperTestTwoNg : public testing::Test {
173 public:
174     static void SetUpTestSuite();
175     static void TearDownTestSuite();
176 };
177 
SetUpTestSuite()178 void LayoutWrapperTestTwoNg::SetUpTestSuite()
179 {
180     MockPipelineContext::SetUp();
181 }
182 
TearDownTestSuite()183 void LayoutWrapperTestTwoNg::TearDownTestSuite()
184 {
185     MockPipelineContext::TearDown();
186 }
187 
188 /**
189  * @tc.name: LayoutWrapperTest001
190  * @tc.desc: Test GetParentGlobalOffsetWithSafeArea.
191  * @tc.type: FUNC
192  */
193 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest001, TestSize.Level1)
194 {
195     auto pipeline = PipelineContext::GetCurrentContext();
196     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
197     auto [child0, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
198     child0->MountToParent(parent);
199     auto [child1, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
200     child1->MountToParent(child0);
201     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
202     child2->MountToParent(child1);
203 
204     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
205     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
206     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
207     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
208 
209     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
210     auto pageRenderContext = child1->GetRenderContext();
211 
212     child1->renderContext_ = nullptr;
213     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
214     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
215     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
216     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
217 
218     child1->renderContext_ = pageRenderContext;
219     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
220     pageRenderContext->GetOrCreatePositionProperty();
221 
222     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
223     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
224     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
225     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
226 
227     pageRenderContext->GetPositionProperty()->UpdatePosition(OffsetT<Dimension>(Dimension(10.0), Dimension(10.0)));
228 
229     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
230     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
231     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
232     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
233 
234     child1->layoutProperty_->layoutConstraint_ = MakeLayoutConstraintF();
235     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
236     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(10.0f, 10.0f));
237 }
238 
239 /**
240  * @tc.name: LayoutWrapperTest002
241  * @tc.desc: Test GetFrameRectWithoutSafeArea.
242  * @tc.type: FUNC
243  */
244 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest002, TestSize.Level1)
245 {
246     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
247     RefPtr<LayoutWrapperNode> layoutWrapper =
248         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
249     EXPECT_EQ(layoutWrapper->GetFrameRectWithoutSafeArea(), RectF());
250     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
251     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
252     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
253     EXPECT_EQ(layoutWrapper->GetFrameRectWithoutSafeArea(), gn->frame_.rect_);
254 }
255 
256 /**
257  * @tc.name: LayoutWrapperTest003
258  * @tc.desc: Test OffsetNodeToSafeArea.
259  * @tc.type: FUNC
260  */
261 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest003, TestSize.Level1)
262 {
263     auto layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
264     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
265         SafeAreaInsets({}, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
266     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT - 2 });
267 
268     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 1 });
269     layoutWrapper->OffsetNodeToSafeArea();
270     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
271 
272     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 5 });
273     layoutWrapper->OffsetNodeToSafeArea();
274     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
275 
276     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
277     layoutWrapper->OffsetNodeToSafeArea();
278     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
279 
280     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
281         SafeAreaInsets({ 0, 5 }, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
282     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
283     layoutWrapper->OffsetNodeToSafeArea();
284     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
285 
286     // set right and bottom again
287     layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
288     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
289         SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }));
290     layoutWrapper->OffsetNodeToSafeArea();
291     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 1);
292     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
293 
294     layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
295     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
296         SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT + 1, RK356_HEIGHT }, { RK356_HEIGHT + 1, RK356_HEIGHT }));
297     layoutWrapper->OffsetNodeToSafeArea();
298     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 0);
299     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
300 }
301 
302 /**
303  * @tc.name: LayoutWrapperTest004
304  * @tc.desc: Test CreateRootConstraint.
305  * @tc.type: FUNC
306  */
307 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest004, TestSize.Level1)
308 {
309     auto context = PipelineContext::GetCurrentContext();
310     context->rootHeight_ = RK356_HEIGHT;
311     context->rootWidth_ = RK356_WIDTH;
312 
313     auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
314     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT });
315     layoutWrapper->CreateRootConstraint();
316     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT);
317     layoutWrapper->layoutProperty_->UpdateAspectRatio(0.0001);
318     layoutWrapper->CreateRootConstraint();
319     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), 0);
320     layoutWrapper->layoutProperty_->UpdateAspectRatio(2.0);
321     layoutWrapper->CreateRootConstraint();
322     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT / 2);
323 }
324 
325 /**
326  * @tc.name: LayoutWrapperTest005
327  * @tc.desc: Test ApplyConstraintWithoutMeasure.
328  * @tc.type: FUNC
329  */
330 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest005, TestSize.Level1)
331 {
332     auto context = PipelineContext::GetCurrentContext();
333     context->rootHeight_ = RK356_HEIGHT;
334     context->rootWidth_ = RK356_WIDTH;
335 
336     auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
337     std::optional<LayoutConstraintF> constraint;
338     layoutWrapper->ApplyConstraintWithoutMeasure(constraint);
339     constraint = MakeLayoutConstraintF();
340     layoutWrapper->ApplyConstraintWithoutMeasure(constraint);
341 }
342 
343 /**
344  * @tc.name: LayoutWrapperTest006
345  * @tc.desc: Test GetPageCurrentOffset.
346  * @tc.type: FUNC
347  */
348 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest006, TestSize.Level1)
349 {
350     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::PAGE_ETS_TAG, NODE_ID_0);
351     auto pipeline = PipelineContext::GetCurrentContext();
352     CHECK_NULL_VOID(pipeline);
353     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
354 
355     auto [pageNode, layoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
356     EXPECT_FALSE(layoutWrapper1 == nullptr);
357     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(pageNode);
358     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
359     auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
360     child->MountToParent(pageNode);
361     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
362 
363     pipeline->safeAreaManager_->SetIsFullScreen(true);
364     pipeline->safeAreaManager_->SetIsAtomicService(true);
365     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
366     EXPECT_EQ(layoutWrapper1->GetPageCurrentOffset(), 0.0f);
367     pipeline->safeAreaManager_->SetIsAtomicService(false);
368     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
369         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
370     pipeline->safeAreaManager_->UpdateSystemSafeArea(
371         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
372     pipeline->safeAreaManager_->UpdateNavSafeArea(
373         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
374     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), -70.0f);
375     EXPECT_EQ(layoutWrapper1->GetPageCurrentOffset(), -70.0f);
376 }
377 
378 /**
379  * @tc.name: LayoutWrapperTest007
380  * @tc.desc: Test ExpandIntoKeyboard.
381  * @tc.type: FUNC
382  */
383 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest007, TestSize.Level1)
384 {
385     auto pipeline = PipelineContext::GetCurrentContext();
386     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
387     auto [child0, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
388     child0->MountToParent(parent);
389     auto [child1, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
390     child1->MountToParent(child0);
391     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
392     child2->MountToParent(child1);
393     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
394     auto pageRenderContext = child1->GetRenderContext();
395     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
396 
397     pipeline->safeAreaManager_->SetIsAtomicService(true);
398     pipeline->safeAreaManager_->SetIsFullScreen(true);
399     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
400         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
401     pipeline->safeAreaManager_->UpdateSystemSafeArea(
402         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
403     pipeline->safeAreaManager_->UpdateNavSafeArea(
404         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
405     pipeline->safeAreaManager_->UpdateKeyboardOffset(50.0f);
406 
407     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
408     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
409     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
410     EXPECT_EQ(child2->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
411 
412     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
413     pageRenderContext->GetOrCreatePositionProperty();
414     pipeline->safeAreaManager_->SetIsAtomicService(false);
415 
416     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
417     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
418     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
419     EXPECT_EQ(child2->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
420     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
421     child0->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
422     child1->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
423     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
424     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
425     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
426 }
427 
428 /**
429  * @tc.name: LayoutWrapperTest008
430  * @tc.desc: Test CheckValidSafeArea.
431  * @tc.type: FUNC
432  */
433 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest008, TestSize.Level1)
434 {
435     auto pipeline = PipelineContext::GetCurrentContext();
436     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
437     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
438     child0->MountToParent(parent);
439 
440     auto [child1, childWrapper1] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
441     child1->MountToParent(child0);
442 
443     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
444     child2->MountToParent(child1);
445 
446     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
447         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
448     pipeline->safeAreaManager_->UpdateSystemSafeArea(
449         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
450     pipeline->safeAreaManager_->UpdateNavSafeArea(
451         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
452 
453     EXPECT_FALSE(layoutWrapper->CheckValidSafeArea());
454     EXPECT_FALSE(childWrapper0->CheckValidSafeArea());
455     EXPECT_FALSE(childWrapper1->CheckValidSafeArea());
456     EXPECT_FALSE(childWrapper2->CheckValidSafeArea());
457     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
458     childWrapper0->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
459     childWrapper1->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
460     childWrapper2->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
461     EXPECT_TRUE(layoutWrapper->CheckValidSafeArea());
462     EXPECT_TRUE(childWrapper0->CheckValidSafeArea());
463     EXPECT_TRUE(childWrapper1->CheckValidSafeArea());
464     EXPECT_TRUE(childWrapper2->CheckValidSafeArea());
465 
466     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
467     auto pageRenderContext = child1->GetRenderContext();
468     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
469     pageRenderContext->GetOrCreatePositionProperty();
470 
471     pipeline->safeAreaManager_->SetIsAtomicService(true);
472     pipeline->safeAreaManager_->SetIsFullScreen(true);
473     EXPECT_TRUE(layoutWrapper->CheckValidSafeArea());
474     EXPECT_TRUE(childWrapper0->CheckValidSafeArea());
475     EXPECT_TRUE(childWrapper1->CheckValidSafeArea());
476     EXPECT_TRUE(childWrapper2->CheckValidSafeArea());
477 }
478 
479 /**
480  * @tc.name: LayoutWrapperTest009
481  * @tc.desc: Test AdjustNotExpandNode.
482  * @tc.type: FUNC
483  */
484 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest009, TestSize.Level1)
485 {
486     auto pipeline = PipelineContext::GetCurrentContext();
487     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
488 
489     layoutWrapper->AdjustNotExpandNode();
490 
491     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
492         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
493     pipeline->safeAreaManager_->UpdateSystemSafeArea(
494         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
495     pipeline->safeAreaManager_->UpdateNavSafeArea(
496         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
497     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
498     layoutWrapper->AdjustNotExpandNode();
499     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
500     layoutWrapper->AdjustNotExpandNode();
501     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
502         NG::SafeAreaInsets({40.0f, 10.0f}, {50.0f, 20.0f}, {710.0f, 680.0f}, {1260.0f, 1230.0f}));
503     pipeline->safeAreaManager_->UpdateSystemSafeArea(
504         NG::SafeAreaInsets({30.0f, 0.0f}, {30.0f, 0.0f}, {720.0f, 690.0f}, {1280.0f, 1250.0f}));
505     pipeline->safeAreaManager_->UpdateNavSafeArea(
506         NG::SafeAreaInsets({50.0f, 20.0f}, {70.0f, 40.0f}, {700.0f, 670.0f}, {1240.0f, 1210.0f}));
507     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
508     layoutWrapper->AdjustNotExpandNode();
509     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
510     layoutWrapper->AdjustNotExpandNode();
511 }
512 
513 /**
514  * @tc.name: LayoutWrapperTest010
515  * @tc.desc: Test ExpandSafeArea.
516  * @tc.type: FUNC
517  */
518 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest010, TestSize.Level1)
519 {
520     auto pipeline = PipelineContext::GetCurrentContext();
521     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
522     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
523     childWrapper0->geometryNode_->frame_.rect_ = RectF(0.0f, 0.0f, 100.0f, 100.0f);
524     child0->MountToParent(parent);
525     auto render0 = child0->GetRenderContext();
526 
527     auto [child1, childWrapper1] = CreateScrollableWrapper(NODE_ID_2, RectF(30.0f, 40.0f, 40.0f, 50.0f));
528     child1->MountToParent(child0);
529     auto render1 = child1->GetRenderContext();
530 
531     auto [child2, childWrapper2] = CreateScrollableWrapper(NODE_ID_3, RectF(40.0f, 40.0f, 20.0f, 10.0f));
532     child2->MountToParent(child1);
533 
534     childWrapper0->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
535     childWrapper1->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
536     childWrapper0->layoutProperty_->safeAreaExpandOpts_->switchToNone = true;
537     childWrapper1->layoutProperty_->safeAreaExpandOpts_->switchToNone = true;
538     childWrapper0->ExpandSafeArea();
539     childWrapper1->ExpandSafeArea();
540     childWrapper0->layoutProperty_->safeAreaExpandOpts_->edges |= SAFE_AREA_EDGE_BOTTOM;
541     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
542     childWrapper0->ExpandSafeArea();
543     childWrapper1->ExpandSafeArea();
544     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
545     childWrapper0->ExpandSafeArea();
546     childWrapper1->ExpandSafeArea();
547 
548     childWrapper0->layoutProperty_->safeAreaExpandOpts_->type |= SAFE_AREA_TYPE_KEYBOARD;
549     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
550     childWrapper0->ExpandSafeArea();
551     childWrapper1->ExpandSafeArea();
552     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
553     childWrapper0->ExpandSafeArea();
554     childWrapper1->ExpandSafeArea();
555 
556     childWrapper0->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
557     childWrapper1->layoutProperty_->safeAreaExpandOpts_->type |= SAFE_AREA_TYPE_KEYBOARD;
558     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
559     childWrapper0->ExpandSafeArea();
560     childWrapper1->ExpandSafeArea();
561     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
562     childWrapper0->ExpandSafeArea();
563     childWrapper1->ExpandSafeArea();
564 }
565 
566 /**
567  * @tc.name: LayoutWrapperTest011
568  * @tc.desc: Test AdjustFixedSizeNode.
569  * @tc.type: FUNC
570  */
571 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest011, TestSize.Level1)
572 {
573     RectF frame;
574     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
575     RefPtr<LayoutWrapperNode> layoutWrapper =
576         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, nullptr);
577     layoutWrapper->AdjustFixedSizeNode(frame);
578     EXPECT_EQ(frame, RectF());
579 
580     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
581     layoutWrapper->AdjustFixedSizeNode(frame);
582     EXPECT_EQ(frame, RectF());
583 
584     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
585     gn->frame_.rect_ = RectF{10.0f, 20.0f, 1200.0f, 1200.0f};
586     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
587     layoutWrapper->AdjustFixedSizeNode(frame);
588     EXPECT_EQ(frame, RectF());
589 
590     node->GetLayoutProperty()->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
591     node->GetLayoutProperty()->calcLayoutConstraint_->selfIdealSize =
592                 std::make_optional<CalcSize>(CalcLength(10.0), CalcLength(20.0));
593 
594     node->GetLayoutProperty()->magicItemProperty_.UpdateAspectRatio(20.0f);
595     layoutWrapper->AdjustFixedSizeNode(frame);
596     EXPECT_EQ(frame, RectF(0.0f, 0.0f, 1200.0f, 60.0f));
597 }
598 
599 /**
600  * @tc.name: LayoutWrapperTest012
601  * @tc.desc: Test AccumulateExpandCacheHit.
602  * @tc.type: FUNC
603  */
604 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest012, TestSize.Level1)
605 {
606     ExpandEdges totalExpand;
607     PaddingPropertyF innerSpace;
608     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
609 
610     RefPtr<LayoutWrapperNode> layoutWrapper =
611             AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
612     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
613     EXPECT_EQ(totalExpand, ExpandEdges());
614 
615     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
616     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
617     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
618     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
619     EXPECT_EQ(totalExpand, ExpandEdges());
620 
621     ExpandEdges safeAreaPadding;
622     safeAreaPadding.left = std::make_optional<float>(10.0f);
623     safeAreaPadding.right = std::make_optional<float>(20.0f);
624     safeAreaPadding.top = std::make_optional<float>(30.0f);
625     safeAreaPadding.bottom = std::make_optional<float>(40.0f);
626     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
627     EXPECT_EQ(totalExpand, ExpandEdges());
628     layoutWrapper->geometryNode_->SetAccumulatedSafeAreaEdges(safeAreaPadding);
629     EXPECT_TRUE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
630     EXPECT_EQ(totalExpand, ExpandEdges());
631     totalExpand.left = std::make_optional<float>(100.0f);
632     totalExpand.right = std::make_optional<float>(200.0f);
633     totalExpand.top = std::make_optional<float>(300.0f);
634     totalExpand.bottom = std::make_optional<float>(400.0f);
635 
636     EXPECT_TRUE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
637     ExpandEdges safeAreaPadding1;
638     safeAreaPadding1.left = std::make_optional<float>(110.0f);
639     safeAreaPadding1.right = std::make_optional<float>(220.0f);
640     safeAreaPadding1.top = std::make_optional<float>(330.0f);
641     safeAreaPadding1.bottom = std::make_optional<float>(440.0f);
642     EXPECT_EQ(totalExpand, safeAreaPadding1);
643 }
644 
645 /**
646  * @tc.name: LayoutWrapperTest014
647  * @tc.desc: Test GetAccumulatedSafeAreaExpandHelper.
648  * @tc.type: FUNC
649  */
650 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest014, TestSize.Level1)
651 {
652     RectF adjustingRect;
653     ExpandEdges totalExpand;
654     auto pipeline = PipelineContext::GetCurrentContext();
655     auto [parent, layoutWrapper] =
656             CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 100.0f, 100.0f));
657     auto [child0, nodeLayoutWrapper1] =
658             CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 50.0f, 40.0f));
659     child0->MountToParent(parent);
660     auto [child1, childWrapper] =
661             CreateNodeAndWrapper(V2::STAGE_ETS_TAG, NODE_ID_2, RectF(20.0f, 30.0f, 30.0f, 25.0f));
662     child1->MountToParent(child0);
663     auto [child2, childWrapper2] =
664             CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3, RectF(25.0f, 32.0f, 10.0f, 10.0f));
665     child2->MountToParent(child1);
666 
667     child1->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
668     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
669     child2->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
670     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
671 
672     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
673     auto pageRenderContext = child1->GetRenderContext();
674     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
675     pageRenderContext->GetOrCreatePositionProperty();
676 
677     pipeline->safeAreaManager_->SetIsAtomicService(true);
678     pipeline->safeAreaManager_->SetIsFullScreen(true);
679     pipeline->safeAreaManager_->UpdateSystemSafeArea(
680         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
681 
682     child1->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
683     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
684     child2->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
685     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
686 }
687 
688 /**
689  * @tc.name: LayoutWrapperTest015
690  * @tc.desc: Test AvoidKeyboard.
691  * @tc.type: FUNC
692  */
693 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest015, TestSize.Level1)
694 {
695     auto node = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
696     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
697     RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
698     RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
699     focusHub->currentFocus_ = false;
700     node->focusHub_ = focusHub;
701     node->eventHub_ = eventHub;
702 
703     RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
704     safeAreamanager->keyboardOffset_ = -1.0f;
705 
706     auto pipeline = PipelineContext::GetCurrentContext();
707     CHECK_NULL_VOID(pipeline);
708     safeAreamanager->SetIsAtomicService(true);
709     pipeline->safeAreaManager_ = safeAreamanager;
710 
711     node->SetActive(true);
712     EXPECT_TRUE(layoutWrapper->AvoidKeyboard());
713     EXPECT_FALSE(layoutWrapper->AvoidKeyboard(false));
714     EXPECT_TRUE(node->GetFocusHub());
715     EXPECT_TRUE(!node->GetFocusHub()->IsCurrentFocus());
716     EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
717 }
718 
719 /**
720  * @tc.name: LayoutWrapperTest016
721  * @tc.desc: Test GetFrameRectWithSafeArea.
722  * @tc.type: FUNC
723  */
724 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest016, TestSize.Level1)
725 {
726     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
727     RefPtr<LayoutWrapperNode> tmoWrapper =
728         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
729     EXPECT_EQ(tmoWrapper->GetFrameRectWithSafeArea(), RectF());
730     auto pipeline = PipelineContext::GetCurrentContext();
731     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
732     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
733     childWrapper0->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
734     childWrapper0->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
735     child0->MountToParent(parent);
736     auto [child1, childWrapper1] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
737     childWrapper1->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
738     childWrapper1->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
739     child1->MountToParent(child0);
740     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
741     childWrapper2->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
742     childWrapper2->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
743     child2->MountToParent(child1);
744 
745     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
746     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
747     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
748     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
749     auto pageRenderContext = child1->GetRenderContext();
750     child1->renderContext_ = nullptr;
751     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
752     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
753     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
754     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
755     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
756     child1->renderContext_ = pageRenderContext;
757     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
758     pageRenderContext->GetOrCreatePositionProperty();
759     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
760     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
761     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
762     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
763     pageRenderContext->GetPositionProperty()->UpdatePosition(OffsetT<Dimension>(Dimension(10.0), Dimension(10.0)));
764     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
765     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF());
766     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
767     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
768     child1->layoutProperty_->layoutConstraint_ = MakeLayoutConstraintF();
769     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
770     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 10.0f, 30.0f, 40.0f));
771     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
772     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
773 }
774 
775 /**
776  * @tc.name: LayoutWrapperTest017
777  * @tc.desc: Test ResetSafeAreaPadding.
778  * @tc.type: FUNC
779  */
780 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest017, TestSize.Level1)
781 {
782     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
783     RefPtr<LayoutWrapperNode> layoutWrapper =
784         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, nullptr);
785     layoutWrapper->ResetSafeAreaPadding();
786 
787     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
788     layoutWrapper->ResetSafeAreaPadding();
789 
790     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
791     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
792     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
793     layoutWrapper->ResetSafeAreaPadding();
794 }
795 
796 /**
797  * @tc.name: LayoutWrapperTest018
798  * @tc.desc: Test ExpandHelper.
799  * @tc.type: FUNC
800  */
801 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest018, TestSize.Level1)
802 {
803     std::unique_ptr<SafeAreaExpandOpts> opts = nullptr;
804     RectF tmpFrame = RectF{20.0f, 30.0f, 670.0f, 1220.0f};
805     auto pipeline = PipelineContext::GetCurrentContext();
806     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
807     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
808     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
809     RefPtr<LayoutWrapperNode> layoutWrapper =
810             AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
811     RectF frame = tmpFrame;
812     layoutWrapper->ExpandHelper(opts, frame);
813     EXPECT_EQ(frame, tmpFrame);
814     frame = tmpFrame;
815 
816     opts = std::make_unique<SafeAreaExpandOpts>();
817     layoutWrapper->ExpandHelper(opts, frame);
818     EXPECT_EQ(frame, tmpFrame);
819     frame = tmpFrame;
820     opts->edges |= SAFE_AREA_EDGE_START;
821     opts->edges |= SAFE_AREA_EDGE_TOP;
822     opts->edges |= SAFE_AREA_EDGE_END;
823     opts->edges |= SAFE_AREA_EDGE_BOTTOM;
824     layoutWrapper->ExpandHelper(opts, frame);
825     EXPECT_EQ(frame, tmpFrame);
826 
827     opts->type |= SAFE_AREA_TYPE_SYSTEM;
828     pipeline->safeAreaManager_->SetIsFullScreen(true);
829     pipeline->safeAreaManager_->UpdateSystemSafeArea(
830         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
831     layoutWrapper->ExpandHelper(opts, frame);
832     EXPECT_EQ(frame, RectF(10.0f, 20.0f, 700.0f, 1240.0f));
833 }
834 
835 /**
836  * @tc.name: LayoutWrapperTest019
837  * @tc.desc: Test IsSyntaxNode
838  * @tc.type: FUNC
839  */
840 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest019, TestSize.Level1)
841 {
842     auto [parent, layoutWrapper] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
843 
844     auto node = SyntaxNode::CreateNode(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
845     parent->MountToParent(node);
846     layoutWrapper->AdjustChild(node, OffsetF(), false);
847     node = SyntaxNode::CreateNode(V2::JS_FOR_EACH_ETS_TAG, NODE_ID_0);
848     layoutWrapper->AdjustChild(node, OffsetF(), false);
849     node = SyntaxNode::CreateNode(V2::JS_IF_ELSE_ETS_TAG, NODE_ID_0);
850     layoutWrapper->AdjustChild(node, OffsetF(), false);
851     node = SyntaxNode::CreateNode(V2::JS_LAZY_FOR_EACH_ETS_TAG, NODE_ID_0);
852     layoutWrapper->AdjustChild(node, OffsetF(), false);
853     node = SyntaxNode::CreateNode(V2::JS_SYNTAX_ITEM_ETS_TAG, NODE_ID_0);
854     layoutWrapper->AdjustChild(node, OffsetF(), false);
855     node = SyntaxNode::CreateNode(V2::JS_NODE_SLOT_ETS_TAG, NODE_ID_0);
856     layoutWrapper->AdjustChild(node, OffsetF(), false);
857     node = SyntaxNode::CreateNode(V2::TOAST_ETS_TAG, NODE_ID_0);
858     layoutWrapper->AdjustChild(node, OffsetF(), false);
859 
860     layoutWrapper->AdjustChild(parent, OffsetF(), false);
861     layoutWrapper->AdjustChild(parent, OffsetF(), true);
862 }
863 
864 /**
865  * @tc.name: LayoutWrapperTest020
866  * @tc.desc: Test AdjustChildren
867  * @tc.type: FUNC
868  */
869 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest020, TestSize.Level1)
870 {
871     auto [parent0, layoutWrapper0] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
872     layoutWrapper0->hostNode_ = nullptr;
873     layoutWrapper0->AdjustChildren(OffsetF(), false);
874     auto [parent1, layoutWrapper1] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
875     layoutWrapper1->AdjustChildren(OffsetF(), false);
876     auto [parent2, layoutWrapper2] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
877     layoutWrapper2->AdjustChildren(OffsetF(), false);
878     auto [parent3, layoutWrapper3] = CreateNodeAndWrapperTestPattern(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
879     layoutWrapper3->AdjustChildren(OffsetF(), false);
880 }
881 
882 /**
883  * @tc.name: LayoutWrapperTest021
884  * @tc.desc: Test AvoidKeyboard.
885  * @tc.type: FUNC
886  */
887 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest021, TestSize.Level1)
888 {
889     auto node = FrameNode::CreateFrameNode(V2::OVERLAY_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
890     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
891     RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
892     RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
893     focusHub->currentFocus_ = false;
894     node->focusHub_ = focusHub;
895     node->eventHub_ = eventHub;
896 
897     RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
898     safeAreamanager->keyboardOffset_ = -1.0f;
899 
900     auto pipeline = PipelineContext::GetCurrentContext();
901     CHECK_NULL_VOID(pipeline);
902     pipeline->overlayManager_ = nullptr;
903     safeAreamanager->SetIsAtomicService(true);
904     pipeline->safeAreaManager_ = safeAreamanager;
905 
906     node->SetActive(true);
907     EXPECT_TRUE(layoutWrapper->AvoidKeyboard());
908     EXPECT_FALSE(layoutWrapper->AvoidKeyboard(false));
909     EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
910 }
911 
912 }