• 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/log/ace_trace.h"
26 #include "base/memory/ace_type.h"
27 #include "base/utils/utils.h"
28 #include "core/components/common/layout/constants.h"
29 #include "core/components_ng/base/frame_node.h"
30 #include "core/components_ng/base/ui_node.h"
31 #include "core/components_ng/layout/layout_wrapper_builder.h"
32 #include "core/components_ng/layout/layout_wrapper_node.h"
33 #include "core/components_ng/pattern/custom/custom_node.h"
34 #include "core/components_ng/pattern/flex/flex_layout_algorithm.h"
35 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
36 #include "core/components_ng/pattern/list/list_pattern.h"
37 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
38 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
39 #include "core/components_ng/property/layout_constraint.h"
40 #include "core/components_ng/property/property.h"
41 #include "core/components_ng/property/safe_area_insets.h"
42 #include "core/components_ng/syntax/lazy_for_each_model.h"
43 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
44 #include "core/components_v2/inspector/inspector_constants.h"
45 #include "core/pipeline_ng/ui_task_scheduler.h"
46 
47 #undef private
48 #undef protected
49 
50 using namespace testing;
51 using namespace testing::ext;
52 
53 namespace OHOS::Ace::NG {
54 
55 class SyntaxNode : public UINode {
56     DECLARE_ACE_TYPE(SyntaxNode, UINode);
57 public:
CreateNode(const std::string & tag,int32_t nodeId)58     static RefPtr<SyntaxNode> CreateNode(const std::string& tag, int32_t nodeId)
59     {
60         auto spanNode = MakeRefPtr<SyntaxNode>(tag, nodeId);
61         return spanNode;
62     }
63 
IsAtomicNode() const64     bool IsAtomicNode() const override
65     {
66         return true;
67     }
68 
SyntaxNode(const std::string & tag,int32_t nodeId)69     explicit SyntaxNode(const std::string& tag, int32_t nodeId) : UINode(tag, nodeId) {}
70     ~SyntaxNode() override = default;
71 };
72 
73 class TestPattern : public Pattern {
74     DECLARE_ACE_TYPE(TestPattern, Pattern);
75 public:
76     TestPattern() = default;
77     ~TestPattern() override = default;
ConsumeChildrenAdjustment(const OffsetF &)78     bool ConsumeChildrenAdjustment(const OffsetF& /* offset */) override
79     {
80         return true;
81     }
82 };
83 
84 namespace {
85 constexpr int32_t NODE_ID_0 = 0;
86 constexpr int32_t NODE_ID_1 = 1;
87 constexpr int32_t NODE_ID_2 = 2;
88 constexpr int32_t NODE_ID_3 = 3;
89 
90 constexpr float RK356_WIDTH = 720.0f;
91 constexpr float RK356_HEIGHT = 1136.0f;
92 constexpr float ROW_HEIGHT = 120.0f;
93 
94 const SizeF CONTAINER_SIZE { RK356_WIDTH, RK356_HEIGHT };
95 SizeF SELF_IDEAL_SIZE { RK356_WIDTH, ROW_HEIGHT };
96 SizeF FRAME_SIZE { 0, 0 };
97 const SizeF TEST_FRAME_SIZE { 0, 0 };
98 OptionalSize IDEAL_SIZE { 0, 0 };
99 
100 const std::string TEST_TAG = "";
101 const std::string ROW_FRAME_NODE = "rowFrameNode";
102 const std::string FIRST_FRAME_NODE = "TabContent";
103 const std::string FIRST_CHILD_FRAME_NODE = "firstChildFrameNode";
104 const std::string SECOND_CHILD_FRAME_NODE = "secondChildFrameNode";
105 const std::string THIRD_CHILD_FRAME_NODE = "thirdChildFrameNode";
106 
CreateNodeAndWrapper(const std::string & tag,int32_t nodeId,RectF rf=RectF ())107 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateNodeAndWrapper(
108     const std::string& tag,
109     int32_t nodeId,
110     RectF rf = RectF())
111 {
112     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
113     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
114     geometryNode->frame_.rect_ = rf;
115     RefPtr<LayoutWrapperNode> layoutWrapper =
116         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
117 
118     return std::make_pair(node, layoutWrapper);
119 }
120 
CreateNodeAndWrapper2(const std::string & tag,int32_t nodeId,RectF rf=RectF ())121 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapper>> CreateNodeAndWrapper2(
122     const std::string& tag,
123     int32_t nodeId,
124     RectF rf = RectF())
125 {
126     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
127     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
128     auto geometryNode = node->GetGeometryNode();
129     geometryNode->frame_.rect_ = rf;
130 
131     return std::make_pair(node, layoutWrapper);
132 }
133 
CreateNodeAndWrapperTestPattern(const std::string & tag,int32_t nodeId,RectF rf=RectF ())134 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateNodeAndWrapperTestPattern(
135     const std::string& tag,
136     int32_t nodeId,
137     RectF rf = RectF())
138 {
139     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<TestPattern>());
140     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
141     geometryNode->frame_.rect_ = rf;
142     RefPtr<LayoutWrapperNode> layoutWrapper =
143         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
144 
145     return std::make_pair(node, layoutWrapper);
146 }
147 
CreateLayoutWrapper(const std::string & tag,int32_t nodeId)148 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(const std::string& tag, int32_t nodeId)
149 {
150     auto rowFrameNode = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<LinearLayoutPattern>(false));
151     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
152     RefPtr<LayoutWrapperNode> layoutWrapper =
153         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
154 
155     return layoutWrapper;
156 }
157 
CreateScrollableWrapper(int32_t nodeId,RectF rf=RectF ())158 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateScrollableWrapper(int32_t nodeId, RectF rf = RectF())
159 {
160     auto frameNode = FrameNode::GetOrCreateFrameNode(
161         V2::SCROLL_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ScrollPattern>(); });
162     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
163     geometryNode->frame_.rect_ = rf;
164     RefPtr<LayoutWrapperNode> layoutWrapper =
165         AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
166 
167     return std::make_pair(frameNode, layoutWrapper);
168 }
169 
MakeLayoutConstraintF()170 std::optional<LayoutConstraintF> MakeLayoutConstraintF()
171 {
172     std::optional<LayoutConstraintF> constraint;
173     constraint = std::make_optional<LayoutConstraintF>();
174     constraint->minSize = SizeF{1.0f, 2.0f};
175     constraint->maxSize = SizeF{100.0f, 200.0f};
176     constraint->percentReference = SizeF{10.0f, 20.0f};
177     constraint->parentIdealSize = OptionalSize<float>{10.0f, 20.0f};
178     constraint->selfIdealSize = OptionalSize<float>{10.0f, 20.0f};
179     return constraint;
180 }
181 
PresetAttributesForStrategyTest(PaddingProperty & safeAreaPadding0,PaddingProperty & safeAreaPadding1,PaddingProperty & margin1,MarginPropertyF & margin1_)182 void PresetAttributesForStrategyTest(PaddingProperty& safeAreaPadding0, PaddingProperty& safeAreaPadding1,
183     PaddingProperty& margin1, MarginPropertyF& margin1_)
184 {
185     safeAreaPadding0 = {
186         .left = CalcLength(10.0f),
187         .right = CalcLength(15.0f),
188         .top = CalcLength(20.0f),
189         .bottom = CalcLength(25.0f)
190     };
191     safeAreaPadding1 = {
192         .left = CalcLength(10.0f),
193         .right = CalcLength(15.0f),
194         .top = CalcLength(10.0f),
195         .bottom = CalcLength(15.0f)
196     };
197     margin1 = {
198         .left = CalcLength(0.0f),
199         .right = CalcLength(10.0f),
200         .top = CalcLength(0.0f),
201         .bottom = CalcLength(10.0f)
202     };
203     margin1_ = {
204         .left = 0.0f,
205         .right = 10.0f,
206         .top = 0.0f,
207         .bottom = 10.0f
208     };
209 }
210 
PresetSceneForStrategyTest(RefPtr<LayoutWrapper> layoutWrapper0,RefPtr<LayoutWrapper> layoutWrapper1)211 void PresetSceneForStrategyTest(RefPtr<LayoutWrapper> layoutWrapper0, RefPtr<LayoutWrapper> layoutWrapper1)
212 {
213     PaddingProperty safeAreaPadding0;
214     PaddingProperty safeAreaPadding1;
215     PaddingProperty margin1;
216     MarginPropertyF margin1_;
217     PresetAttributesForStrategyTest(safeAreaPadding0, safeAreaPadding1, margin1, margin1_);
218     layoutWrapper0->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding0);
219     layoutWrapper1->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding1);
220     layoutWrapper1->GetLayoutProperty()->UpdateMargin(margin1);
221     layoutWrapper1->GetGeometryNode()->UpdateMargin(margin1_);
222 }
223 } // namespace
224 
225 class LayoutWrapperTestTwoNg : public testing::Test {
226 public:
227     static void SetUpTestSuite();
228     static void TearDownTestSuite();
229 };
230 
SetUpTestSuite()231 void LayoutWrapperTestTwoNg::SetUpTestSuite()
232 {
233     MockPipelineContext::SetUp();
234 }
235 
TearDownTestSuite()236 void LayoutWrapperTestTwoNg::TearDownTestSuite()
237 {
238     MockPipelineContext::TearDown();
239 }
240 
241 /**
242  * @tc.name: LayoutWrapperTest001
243  * @tc.desc: Test GetParentGlobalOffsetWithSafeArea.
244  * @tc.type: FUNC
245  */
246 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest001, TestSize.Level1)
247 {
248     auto pipeline = PipelineContext::GetCurrentContext();
249     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
250     auto [child0, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
251     child0->MountToParent(parent);
252     auto [child1, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
253     child1->MountToParent(child0);
254     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
255     child2->MountToParent(child1);
256 
257     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
258     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
259     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
260     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
261 
262     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
263     auto pageRenderContext = child1->GetRenderContext();
264 
265     child1->renderContext_ = nullptr;
266     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
267     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
268     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
269     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
270 
271     child1->renderContext_ = pageRenderContext;
272     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
273     pageRenderContext->GetOrCreatePositionProperty();
274 
275     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
276     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
277     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
278     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
279 
280     pageRenderContext->GetPositionProperty()->UpdatePosition(OffsetT<Dimension>(Dimension(10.0), Dimension(10.0)));
281 
282     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
283     EXPECT_EQ(child1->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
284     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
285     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(0, 0));
286 
287     child1->layoutProperty_->layoutConstraint_ = MakeLayoutConstraintF();
288     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, false), OffsetF(0, 0));
289     EXPECT_EQ(child2->GetParentGlobalOffsetWithSafeArea(false, true), OffsetF(10.0f, 10.0f));
290 }
291 
292 /**
293  * @tc.name: LayoutWrapperTest002
294  * @tc.desc: Test GetFrameRectWithoutSafeArea.
295  * @tc.type: FUNC
296  */
297 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest002, TestSize.Level1)
298 {
299     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
300     RefPtr<LayoutWrapperNode> layoutWrapper =
301         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
302     EXPECT_EQ(layoutWrapper->GetFrameRectWithoutSafeArea(), RectF());
303     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
304     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
305     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
306     EXPECT_EQ(layoutWrapper->GetFrameRectWithoutSafeArea(), gn->frame_.rect_);
307 }
308 
309 /**
310  * @tc.name: LayoutWrapperTest003
311  * @tc.desc: Test OffsetNodeToSafeArea.
312  * @tc.type: FUNC
313  */
314 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest003, TestSize.Level1)
315 {
316     auto layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
317     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
318         SafeAreaInsets({}, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
319     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT - 2 });
320 
321     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 1 });
322     layoutWrapper->OffsetNodeToSafeArea();
323     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
324 
325     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 5 });
326     layoutWrapper->OffsetNodeToSafeArea();
327     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
328 
329     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
330     layoutWrapper->OffsetNodeToSafeArea();
331     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
332 
333     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
334         SafeAreaInsets({ 0, 5 }, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
335     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
336     layoutWrapper->OffsetNodeToSafeArea();
337     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
338 
339     // set right and bottom again
340     layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
341     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
342         SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }));
343     layoutWrapper->OffsetNodeToSafeArea();
344     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 1);
345     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
346 
347     layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
348     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
349         SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT + 1, RK356_HEIGHT }, { RK356_HEIGHT + 1, RK356_HEIGHT }));
350     layoutWrapper->OffsetNodeToSafeArea();
351     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 0);
352     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
353 }
354 
355 /**
356  * @tc.name: LayoutWrapperTest004
357  * @tc.desc: Test CreateRootConstraint.
358  * @tc.type: FUNC
359  */
360 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest004, TestSize.Level1)
361 {
362     auto context = PipelineContext::GetCurrentContext();
363     context->rootHeight_ = RK356_HEIGHT;
364     context->rootWidth_ = RK356_WIDTH;
365 
366     auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
367     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT });
368     layoutWrapper->CreateRootConstraint();
369     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT);
370     layoutWrapper->layoutProperty_->UpdateAspectRatio(0.0001);
371     layoutWrapper->CreateRootConstraint();
372     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), 0);
373     layoutWrapper->layoutProperty_->UpdateAspectRatio(2.0);
374     layoutWrapper->CreateRootConstraint();
375     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT / 2);
376 }
377 
378 /**
379  * @tc.name: LayoutWrapperTest005
380  * @tc.desc: Test ApplyConstraintWithoutMeasure.
381  * @tc.type: FUNC
382  */
383 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest005, TestSize.Level1)
384 {
385     auto context = PipelineContext::GetCurrentContext();
386     context->rootHeight_ = RK356_HEIGHT;
387     context->rootWidth_ = RK356_WIDTH;
388 
389     auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
390     std::optional<LayoutConstraintF> constraint;
391     layoutWrapper->ApplyConstraintWithoutMeasure(constraint);
392     constraint = MakeLayoutConstraintF();
393     layoutWrapper->ApplyConstraintWithoutMeasure(constraint);
394 }
395 
396 /**
397  * @tc.name: LayoutWrapperTest006
398  * @tc.desc: Test GetPageCurrentOffset.
399  * @tc.type: FUNC
400  */
401 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest006, TestSize.Level1)
402 {
403     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::PAGE_ETS_TAG, NODE_ID_0);
404     auto pipeline = PipelineContext::GetCurrentContext();
405     CHECK_NULL_VOID(pipeline);
406     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
407 
408     auto [pageNode, layoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
409     EXPECT_FALSE(layoutWrapper1 == nullptr);
410     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(pageNode);
411     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
412     auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
413     child->MountToParent(pageNode);
414     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
415 
416     pipeline->safeAreaManager_->SetIsFullScreen(true);
417     pipeline->safeAreaManager_->SetIsAtomicService(true);
418     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), 0.0f);
419     EXPECT_EQ(layoutWrapper1->GetPageCurrentOffset(), 0.0f);
420     pipeline->safeAreaManager_->SetIsAtomicService(false);
421     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
422         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
423     pipeline->safeAreaManager_->UpdateSystemSafeArea(
424         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
425     pipeline->safeAreaManager_->UpdateNavSafeArea(
426         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
427     EXPECT_EQ(layoutWrapper->GetPageCurrentOffset(), -70.0f);
428     EXPECT_EQ(layoutWrapper1->GetPageCurrentOffset(), -70.0f);
429 }
430 
431 /**
432  * @tc.name: LayoutWrapperTest007
433  * @tc.desc: Test ExpandIntoKeyboard.
434  * @tc.type: FUNC
435  */
436 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest007, TestSize.Level1)
437 {
438     auto pipeline = PipelineContext::GetCurrentContext();
439     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
440     auto [child0, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
441     child0->MountToParent(parent);
442     auto [child1, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
443     child1->MountToParent(child0);
444     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
445     child2->MountToParent(child1);
446     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
447     auto pageRenderContext = child1->GetRenderContext();
448     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
449 
450     pipeline->safeAreaManager_->SetIsAtomicService(true);
451     pipeline->safeAreaManager_->SetIsFullScreen(true);
452     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
453         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
454     pipeline->safeAreaManager_->UpdateSystemSafeArea(
455         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
456     pipeline->safeAreaManager_->UpdateNavSafeArea(
457         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
458     pipeline->safeAreaManager_->UpdateKeyboardOffset(50.0f);
459 
460     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
461     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
462     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
463     EXPECT_EQ(child2->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
464 
465     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
466     pageRenderContext->GetOrCreatePositionProperty();
467     pipeline->safeAreaManager_->SetIsAtomicService(false);
468 
469     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
470     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
471     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
472     EXPECT_EQ(child2->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
473     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
474     child0->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
475     child1->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
476     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0.0f, -50.0f));
477     EXPECT_EQ(child0->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
478     EXPECT_EQ(child1->ExpandIntoKeyboard(), OffsetF(0.0f, 0.0f));
479 }
480 
481 /**
482  * @tc.name: LayoutWrapperTest008
483  * @tc.desc: Test CheckValidSafeArea.
484  * @tc.type: FUNC
485  */
486 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest008, TestSize.Level1)
487 {
488     auto pipeline = PipelineContext::GetCurrentContext();
489     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
490     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
491     child0->MountToParent(parent);
492 
493     auto [child1, childWrapper1] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
494     child1->MountToParent(child0);
495 
496     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
497     child2->MountToParent(child1);
498 
499     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
500         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
501     pipeline->safeAreaManager_->UpdateSystemSafeArea(
502         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
503     pipeline->safeAreaManager_->UpdateNavSafeArea(
504         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
505 
506     EXPECT_FALSE(layoutWrapper->CheckValidSafeArea());
507     EXPECT_FALSE(childWrapper0->CheckValidSafeArea());
508     EXPECT_FALSE(childWrapper1->CheckValidSafeArea());
509     EXPECT_FALSE(childWrapper2->CheckValidSafeArea());
510     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
511     childWrapper0->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
512     childWrapper1->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
513     childWrapper2->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
514     EXPECT_TRUE(layoutWrapper->CheckValidSafeArea());
515     EXPECT_TRUE(childWrapper0->CheckValidSafeArea());
516     EXPECT_TRUE(childWrapper1->CheckValidSafeArea());
517     EXPECT_TRUE(childWrapper2->CheckValidSafeArea());
518 
519     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
520     auto pageRenderContext = child1->GetRenderContext();
521     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
522     pageRenderContext->GetOrCreatePositionProperty();
523 
524     pipeline->safeAreaManager_->SetIsAtomicService(true);
525     pipeline->safeAreaManager_->SetIsFullScreen(true);
526     EXPECT_TRUE(layoutWrapper->CheckValidSafeArea());
527     EXPECT_TRUE(childWrapper0->CheckValidSafeArea());
528     EXPECT_TRUE(childWrapper1->CheckValidSafeArea());
529     EXPECT_TRUE(childWrapper2->CheckValidSafeArea());
530 }
531 
532 /**
533  * @tc.name: LayoutWrapperTest009
534  * @tc.desc: Test AdjustNotExpandNode.
535  * @tc.type: FUNC
536  */
537 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest009, TestSize.Level1)
538 {
539     auto pipeline = PipelineContext::GetCurrentContext();
540     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
541 
542     layoutWrapper->AdjustNotExpandNode();
543 
544     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
545         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
546     pipeline->safeAreaManager_->UpdateSystemSafeArea(
547         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
548     pipeline->safeAreaManager_->UpdateNavSafeArea(
549         NG::SafeAreaInsets({20.0f, 50.0f}, {40.0f, 70.0f}, {670.0f, 700.0f}, {1210.0f, 1240.0f}));
550     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
551     layoutWrapper->AdjustNotExpandNode();
552     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
553     layoutWrapper->AdjustNotExpandNode();
554     pipeline->safeAreaManager_->UpdateCutoutSafeArea(
555         NG::SafeAreaInsets({40.0f, 10.0f}, {50.0f, 20.0f}, {710.0f, 680.0f}, {1260.0f, 1230.0f}));
556     pipeline->safeAreaManager_->UpdateSystemSafeArea(
557         NG::SafeAreaInsets({30.0f, 0.0f}, {30.0f, 0.0f}, {720.0f, 690.0f}, {1280.0f, 1250.0f}));
558     pipeline->safeAreaManager_->UpdateNavSafeArea(
559         NG::SafeAreaInsets({50.0f, 20.0f}, {70.0f, 40.0f}, {700.0f, 670.0f}, {1240.0f, 1210.0f}));
560     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
561     layoutWrapper->AdjustNotExpandNode();
562     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
563     layoutWrapper->AdjustNotExpandNode();
564 }
565 
566 /**
567  * @tc.name: LayoutWrapperTest010
568  * @tc.desc: Test ExpandSafeArea.
569  * @tc.type: FUNC
570  */
571 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest010, TestSize.Level1)
572 {
573     auto pipeline = PipelineContext::GetCurrentContext();
574     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
575     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
576     childWrapper0->geometryNode_->frame_.rect_ = RectF(0.0f, 0.0f, 100.0f, 100.0f);
577     child0->MountToParent(parent);
578     auto render0 = child0->GetRenderContext();
579 
580     auto [child1, childWrapper1] = CreateScrollableWrapper(NODE_ID_2, RectF(30.0f, 40.0f, 40.0f, 50.0f));
581     child1->MountToParent(child0);
582     auto render1 = child1->GetRenderContext();
583 
584     auto [child2, childWrapper2] = CreateScrollableWrapper(NODE_ID_3, RectF(40.0f, 40.0f, 20.0f, 10.0f));
585     child2->MountToParent(child1);
586 
587     childWrapper0->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
588     childWrapper1->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
589     childWrapper0->layoutProperty_->safeAreaExpandOpts_->switchToNone = true;
590     childWrapper1->layoutProperty_->safeAreaExpandOpts_->switchToNone = true;
591     childWrapper0->ExpandSafeArea();
592     childWrapper1->ExpandSafeArea();
593     childWrapper0->layoutProperty_->safeAreaExpandOpts_->edges |= SAFE_AREA_EDGE_BOTTOM;
594     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
595     childWrapper0->ExpandSafeArea();
596     childWrapper1->ExpandSafeArea();
597     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
598     childWrapper0->ExpandSafeArea();
599     childWrapper1->ExpandSafeArea();
600 
601     childWrapper0->layoutProperty_->safeAreaExpandOpts_->type |= SAFE_AREA_TYPE_KEYBOARD;
602     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
603     childWrapper0->ExpandSafeArea();
604     childWrapper1->ExpandSafeArea();
605     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
606     childWrapper0->ExpandSafeArea();
607     childWrapper1->ExpandSafeArea();
608 
609     childWrapper0->layoutProperty_->safeAreaExpandOpts_ = std::make_unique<SafeAreaExpandOpts>();
610     childWrapper1->layoutProperty_->safeAreaExpandOpts_->type |= SAFE_AREA_TYPE_KEYBOARD;
611     pipeline->safeAreaManager_->SetIgnoreSafeArea(true);
612     childWrapper0->ExpandSafeArea();
613     childWrapper1->ExpandSafeArea();
614     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
615     childWrapper0->ExpandSafeArea();
616     childWrapper1->ExpandSafeArea();
617 }
618 
619 /**
620  * @tc.name: LayoutWrapperTest011
621  * @tc.desc: Test AdjustFixedSizeNode.
622  * @tc.type: FUNC
623  */
624 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest011, TestSize.Level1)
625 {
626     RectF frame;
627     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
628     RefPtr<LayoutWrapperNode> layoutWrapper =
629         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, nullptr);
630     layoutWrapper->AdjustFixedSizeNode(frame);
631     EXPECT_EQ(frame, RectF());
632 
633     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
634     layoutWrapper->AdjustFixedSizeNode(frame);
635     EXPECT_EQ(frame, RectF());
636 
637     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
638     gn->frame_.rect_ = RectF{10.0f, 20.0f, 1200.0f, 1200.0f};
639     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
640     layoutWrapper->AdjustFixedSizeNode(frame);
641     EXPECT_EQ(frame, RectF());
642 
643     node->GetLayoutProperty()->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
644     node->GetLayoutProperty()->calcLayoutConstraint_->selfIdealSize =
645                 std::make_optional<CalcSize>(CalcLength(10.0), CalcLength(20.0));
646 
647     node->GetLayoutProperty()->magicItemProperty_.UpdateAspectRatio(20.0f);
648     layoutWrapper->AdjustFixedSizeNode(frame);
649     EXPECT_EQ(frame, RectF(0.0f, 0.0f, 1200.0f, 60.0f));
650 }
651 
652 /**
653  * @tc.name: LayoutWrapperTest012
654  * @tc.desc: Test AccumulateExpandCacheHit.
655  * @tc.type: FUNC
656  */
657 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest012, TestSize.Level1)
658 {
659     ExpandEdges totalExpand;
660     PaddingPropertyF innerSpace;
661     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
662 
663     RefPtr<LayoutWrapperNode> layoutWrapper =
664             AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
665     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
666     EXPECT_EQ(totalExpand, ExpandEdges());
667 
668     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
669     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
670     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
671     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
672     EXPECT_EQ(totalExpand, ExpandEdges());
673 
674     ExpandEdges safeAreaPadding;
675     safeAreaPadding.left = std::make_optional<float>(10.0f);
676     safeAreaPadding.right = std::make_optional<float>(20.0f);
677     safeAreaPadding.top = std::make_optional<float>(30.0f);
678     safeAreaPadding.bottom = std::make_optional<float>(40.0f);
679     EXPECT_FALSE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
680     EXPECT_EQ(totalExpand, ExpandEdges());
681     layoutWrapper->geometryNode_->SetAccumulatedSafeAreaEdges(safeAreaPadding);
682     EXPECT_TRUE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
683     EXPECT_EQ(totalExpand, ExpandEdges());
684     totalExpand.left = std::make_optional<float>(100.0f);
685     totalExpand.right = std::make_optional<float>(200.0f);
686     totalExpand.top = std::make_optional<float>(300.0f);
687     totalExpand.bottom = std::make_optional<float>(400.0f);
688 
689     EXPECT_TRUE(layoutWrapper->AccumulateExpandCacheHit(totalExpand, innerSpace));
690     ExpandEdges safeAreaPadding1;
691     safeAreaPadding1.left = std::make_optional<float>(110.0f);
692     safeAreaPadding1.right = std::make_optional<float>(220.0f);
693     safeAreaPadding1.top = std::make_optional<float>(330.0f);
694     safeAreaPadding1.bottom = std::make_optional<float>(440.0f);
695     EXPECT_EQ(totalExpand, safeAreaPadding1);
696 }
697 
698 /**
699  * @tc.name: LayoutWrapperTest014
700  * @tc.desc: Test GetAccumulatedSafeAreaExpandHelper.
701  * @tc.type: FUNC
702  */
703 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest014, TestSize.Level1)
704 {
705     RectF adjustingRect;
706     ExpandEdges totalExpand;
707     auto pipeline = PipelineContext::GetCurrentContext();
708     auto [parent, layoutWrapper] =
709             CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 100.0f, 100.0f));
710     auto [child0, nodeLayoutWrapper1] =
711             CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 50.0f, 40.0f));
712     child0->MountToParent(parent);
713     auto [child1, childWrapper] =
714             CreateNodeAndWrapper(V2::STAGE_ETS_TAG, NODE_ID_2, RectF(20.0f, 30.0f, 30.0f, 25.0f));
715     child1->MountToParent(child0);
716     auto [child2, childWrapper2] =
717             CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3, RectF(25.0f, 32.0f, 10.0f, 10.0f));
718     child2->MountToParent(child1);
719 
720     child1->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
721     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
722     child2->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
723     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
724 
725     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
726     auto pageRenderContext = child1->GetRenderContext();
727     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
728     pageRenderContext->GetOrCreatePositionProperty();
729 
730     pipeline->safeAreaManager_->SetIsAtomicService(true);
731     pipeline->safeAreaManager_->SetIsFullScreen(true);
732     pipeline->safeAreaManager_->UpdateSystemSafeArea(
733         NG::SafeAreaInsets({0.0f, 30.0f}, {0.0f, 30.0f}, {690.0f, 720.0f}, {1250.0f, 1280.0f}));
734 
735     child1->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
736     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
737     child2->GetAccumulatedSafeAreaExpandHelper(adjustingRect, totalExpand);
738     EXPECT_EQ(adjustingRect, RectF(0.0f, 0.0f, 0.0f, 0.0f));
739 }
740 
741 /**
742  * @tc.name: LayoutWrapperTest015
743  * @tc.desc: Test AvoidKeyboard.
744  * @tc.type: FUNC
745  */
746 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest015, TestSize.Level1)
747 {
748     auto node = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
749     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
750     RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
751     RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
752     focusHub->currentFocus_ = false;
753     node->focusHub_ = focusHub;
754     node->eventHub_ = eventHub;
755 
756     RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
757     safeAreamanager->keyboardOffset_ = -1.0f;
758 
759     auto pipeline = PipelineContext::GetCurrentContext();
760     CHECK_NULL_VOID(pipeline);
761     safeAreamanager->SetIsAtomicService(true);
762     pipeline->safeAreaManager_ = safeAreamanager;
763 
764     node->SetActive(true);
765     EXPECT_TRUE(layoutWrapper->AvoidKeyboard());
766     EXPECT_FALSE(layoutWrapper->AvoidKeyboard(false));
767     EXPECT_TRUE(node->GetFocusHub());
768     EXPECT_TRUE(!node->GetFocusHub()->IsCurrentFocus());
769     EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
770 }
771 
772 /**
773  * @tc.name: LayoutWrapperTest016
774  * @tc.desc: Test GetFrameRectWithSafeArea.
775  * @tc.type: FUNC
776  */
777 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest016, TestSize.Level1)
778 {
779     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
780     RefPtr<LayoutWrapperNode> tmoWrapper =
781         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
782     EXPECT_EQ(tmoWrapper->GetFrameRectWithSafeArea(), RectF());
783     auto pipeline = PipelineContext::GetCurrentContext();
784     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
785     auto [child0, childWrapper0] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
786     childWrapper0->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
787     childWrapper0->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
788     child0->MountToParent(parent);
789     auto [child1, childWrapper1] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
790     childWrapper1->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
791     childWrapper1->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
792     child1->MountToParent(child0);
793     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
794     childWrapper2->geometryNode_ = AceType::MakeRefPtr<GeometryNode>();
795     childWrapper2->geometryNode_->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
796     child2->MountToParent(child1);
797 
798     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
799     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
800     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
801     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
802     auto pageRenderContext = child1->GetRenderContext();
803     child1->renderContext_ = nullptr;
804     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
805     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
806     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
807     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
808     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
809     child1->renderContext_ = pageRenderContext;
810     pageRenderContext->UpdatePaintRect(RectF{40.0f, 40.0f, 500.0f, 1100.0f});
811     pageRenderContext->GetOrCreatePositionProperty();
812     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
813     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
814     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
815     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
816     pageRenderContext->GetPositionProperty()->UpdatePosition(OffsetT<Dimension>(Dimension(10.0), Dimension(10.0)));
817     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
818     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF());
819     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
820     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
821     child1->layoutProperty_->layoutConstraint_ = MakeLayoutConstraintF();
822     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
823     EXPECT_EQ(childWrapper1->GetFrameRectWithSafeArea(true), RectF(10.0f, 10.0f, 30.0f, 40.0f));
824     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(false), RectF(10.0f, 20.0f, 30.0f, 40.0f));
825     EXPECT_EQ(childWrapper2->GetFrameRectWithSafeArea(true), RectF(10.0f, 20.0f, 30.0f, 40.0f));
826 }
827 
828 /**
829  * @tc.name: LayoutWrapperTest017
830  * @tc.desc: Test ResetSafeAreaPadding.
831  * @tc.type: FUNC
832  */
833 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest017, TestSize.Level1)
834 {
835     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
836     RefPtr<LayoutWrapperNode> layoutWrapper =
837         AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, nullptr);
838     layoutWrapper->ResetSafeAreaPadding();
839 
840     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, nullptr, node->GetLayoutProperty());
841     layoutWrapper->ResetSafeAreaPadding();
842 
843     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
844     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
845     layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
846     layoutWrapper->ResetSafeAreaPadding();
847 }
848 
849 /**
850  * @tc.name: LayoutWrapperTest018
851  * @tc.desc: Test ExpandHelper.
852  * @tc.type: FUNC
853  */
854 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest018, TestSize.Level1)
855 {
856     std::unique_ptr<SafeAreaExpandOpts> opts = nullptr;
857     RectF tmpFrame = RectF{20.0f, 30.0f, 670.0f, 1220.0f};
858     auto pipeline = PipelineContext::GetCurrentContext();
859     auto node = FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
860     RefPtr<GeometryNode> gn = AceType::MakeRefPtr<GeometryNode>();
861     gn->frame_.rect_ = RectF{10.0f, 20.0f, 30.0f, 40.0f};
862     RefPtr<LayoutWrapperNode> layoutWrapper =
863             AceType::MakeRefPtr<LayoutWrapperNode>(node, gn, node->GetLayoutProperty());
864     RectF frame = tmpFrame;
865     layoutWrapper->ExpandHelper(opts, frame);
866     EXPECT_EQ(frame, tmpFrame);
867     frame = tmpFrame;
868 
869     opts = std::make_unique<SafeAreaExpandOpts>();
870     layoutWrapper->ExpandHelper(opts, frame);
871     EXPECT_EQ(frame, tmpFrame);
872     frame = tmpFrame;
873     opts->edges |= SAFE_AREA_EDGE_START;
874     opts->edges |= SAFE_AREA_EDGE_TOP;
875     opts->edges |= SAFE_AREA_EDGE_END;
876     opts->edges |= SAFE_AREA_EDGE_BOTTOM;
877     layoutWrapper->ExpandHelper(opts, frame);
878     EXPECT_EQ(frame, tmpFrame);
879 
880     opts->type |= SAFE_AREA_TYPE_SYSTEM;
881     pipeline->safeAreaManager_->SetIsFullScreen(true);
882     pipeline->safeAreaManager_->UpdateSystemSafeArea(
883         NG::SafeAreaInsets({10.0f, 40.0f}, {20.0f, 50.0f}, {680.0f, 710.0f}, {1230.0f, 1260.0f}));
884     layoutWrapper->ExpandHelper(opts, frame);
885     EXPECT_EQ(frame, RectF(10.0f, 20.0f, 700.0f, 1240.0f));
886 }
887 
888 /**
889  * @tc.name: LayoutWrapperTest019
890  * @tc.desc: Test IsSyntaxNode
891  * @tc.type: FUNC
892  */
893 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest019, TestSize.Level1)
894 {
895     auto [parent, layoutWrapper] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
896 
897     auto node = SyntaxNode::CreateNode(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
898     parent->MountToParent(node);
899     layoutWrapper->AdjustChild(node, OffsetF(), false);
900     node = SyntaxNode::CreateNode(V2::JS_FOR_EACH_ETS_TAG, NODE_ID_0);
901     layoutWrapper->AdjustChild(node, OffsetF(), false);
902     node = SyntaxNode::CreateNode(V2::JS_IF_ELSE_ETS_TAG, NODE_ID_0);
903     layoutWrapper->AdjustChild(node, OffsetF(), false);
904     node = SyntaxNode::CreateNode(V2::JS_LAZY_FOR_EACH_ETS_TAG, NODE_ID_0);
905     layoutWrapper->AdjustChild(node, OffsetF(), false);
906     node = SyntaxNode::CreateNode(V2::JS_SYNTAX_ITEM_ETS_TAG, NODE_ID_0);
907     layoutWrapper->AdjustChild(node, OffsetF(), false);
908     node = SyntaxNode::CreateNode(V2::JS_NODE_SLOT_ETS_TAG, NODE_ID_0);
909     layoutWrapper->AdjustChild(node, OffsetF(), false);
910     node = SyntaxNode::CreateNode(V2::TOAST_ETS_TAG, NODE_ID_0);
911     layoutWrapper->AdjustChild(node, OffsetF(), false);
912 
913     layoutWrapper->AdjustChild(parent, OffsetF(), false);
914     layoutWrapper->AdjustChild(parent, OffsetF(), true);
915 }
916 
917 /**
918  * @tc.name: LayoutWrapperTest020
919  * @tc.desc: Test AdjustChildren
920  * @tc.type: FUNC
921  */
922 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest020, TestSize.Level1)
923 {
924     auto [parent0, layoutWrapper0] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
925     layoutWrapper0->hostNode_ = nullptr;
926     layoutWrapper0->AdjustChildren(OffsetF(), false);
927     auto [parent1, layoutWrapper1] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
928     layoutWrapper1->AdjustChildren(OffsetF(), false);
929     auto [parent2, layoutWrapper2] = CreateNodeAndWrapper(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
930     layoutWrapper2->AdjustChildren(OffsetF(), false);
931     auto [parent3, layoutWrapper3] = CreateNodeAndWrapperTestPattern(V2::JS_VIEW_ETS_TAG, NODE_ID_0);
932     layoutWrapper3->AdjustChildren(OffsetF(), false);
933 }
934 
935 /**
936  * @tc.name: LayoutWrapperTest021
937  * @tc.desc: Test AvoidKeyboard.
938  * @tc.type: FUNC
939  */
940 HWTEST_F(LayoutWrapperTestTwoNg, LayoutWrapperTest021, TestSize.Level1)
941 {
942     auto node = FrameNode::CreateFrameNode(V2::OVERLAY_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
943     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
944     RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
945     RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
946     focusHub->currentFocus_ = false;
947     node->focusHub_ = focusHub;
948     node->eventHub_ = eventHub;
949 
950     RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
951     safeAreamanager->keyboardOffset_ = -1.0f;
952 
953     auto pipeline = PipelineContext::GetCurrentContext();
954     CHECK_NULL_VOID(pipeline);
955     pipeline->overlayManager_ = nullptr;
956     safeAreamanager->SetIsAtomicService(true);
957     pipeline->safeAreaManager_ = safeAreamanager;
958 
959     node->SetActive(true);
960     EXPECT_TRUE(layoutWrapper->AvoidKeyboard());
961     EXPECT_FALSE(layoutWrapper->AvoidKeyboard(false));
962     EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
963 }
964 /**
965  * @tc.name: IgnoreLayoutProcessTagFuncs
966  * @tc.desc: Test Get,Set,ResetIgnoreLayoutProcess.
967  * @tc.type: FUNC
968  */
969 HWTEST_F(LayoutWrapperTestTwoNg, IgnoreLayoutProcessTagFuncs, TestSize.Level0)
970 {
971     auto node = FrameNode::CreateFrameNode(V2::OVERLAY_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
972     auto layoutWrapper = AceType::DynamicCast<LayoutWrapper>(node);
973     EXPECT_EQ(layoutWrapper->GetIgnoreLayoutProcess(), false);
974     layoutWrapper->SetIgnoreLayoutProcess(true);
975     EXPECT_EQ(layoutWrapper->GetIgnoreLayoutProcess(), true);
976     layoutWrapper->ResetIgnoreLayoutProcess();
977     EXPECT_EQ(layoutWrapper->GetIgnoreLayoutProcess(), false);
978 }
979 
980 /**
981  * @tc.name: HasPreMeasuredTest
982  * @tc.desc: Test SetHasPreMeasured, GetHasPreMeasured and CheckHasPreMeasured
983  * @tc.type: FUNC
984  */
985 HWTEST_F(LayoutWrapperTestTwoNg, HasPreMeasuredTest, TestSize.Level1)
986 {
987     auto pipeline = PipelineContext::GetCurrentContext();
988     auto [node, layoutWrapper] = CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
989     EXPECT_EQ(layoutWrapper->CheckHasPreMeasured(), false);
990     EXPECT_EQ(layoutWrapper->GetHasPreMeasured(), false);
991     layoutWrapper->SetHasPreMeasured();
992     EXPECT_EQ(layoutWrapper->CheckHasPreMeasured(), true);
993     EXPECT_EQ(layoutWrapper->GetHasPreMeasured(), true);
994     EXPECT_EQ(layoutWrapper->CheckHasPreMeasured(), false);
995     EXPECT_EQ(layoutWrapper->GetHasPreMeasured(), false);
996 }
997 
998 /**
999  * @tc.name: DelaySelfLayoutForIgnoreTest
1000  * @tc.desc: Test SetDelaySelfLayoutForIgnore and GetDelaySelfLayoutForIgnore
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(LayoutWrapperTestTwoNg, DelaySelfLayoutForIgnoreTest, TestSize.Level1)
1004 {
1005     auto pipeline = PipelineContext::GetCurrentContext();
1006     auto [node, layoutWrapper] = CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1007     EXPECT_EQ(layoutWrapper->GetDelaySelfLayoutForIgnore(), false);
1008     layoutWrapper->SetDelaySelfLayoutForIgnore();
1009     EXPECT_EQ(layoutWrapper->GetDelaySelfLayoutForIgnore(), true);
1010     EXPECT_EQ(layoutWrapper->GetDelaySelfLayoutForIgnore(), false);
1011 }
1012 
1013 /**
1014  * @tc.name: EscapeDelayForIgnoreTest
1015  * @tc.desc: Test SetEscapeDelayForIgnore and GetEscapeDelayForIgnore
1016  * @tc.type: FUNC
1017  */
1018 HWTEST_F(LayoutWrapperTestTwoNg, EscapeDelayForIgnoreTest, TestSize.Level1)
1019 {
1020     auto pipeline = PipelineContext::GetCurrentContext();
1021     auto [node, layoutWrapper] = CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1022     EXPECT_EQ(layoutWrapper->GetEscapeDelayForIgnore(), false);
1023     layoutWrapper->SetEscapeDelayForIgnore(true);
1024     EXPECT_EQ(layoutWrapper->GetEscapeDelayForIgnore(), true);
1025     layoutWrapper->SetEscapeDelayForIgnore(false);
1026     EXPECT_EQ(layoutWrapper->GetEscapeDelayForIgnore(), false);
1027 }
1028 
1029 /**
1030  * @tc.name: EdgeControlOnGetAccumulatedSafeAreaExpand
1031  * @tc.desc: Test GetAccumulatedSafeAreaExpand with edges options
1032  * @tc.type: FUNC
1033  */
1034 HWTEST_F(LayoutWrapperTestTwoNg, EdgeControlOnGetAccumulatedSafeAreaExpand, TestSize.Level1)
1035 {
1036     auto pipeline = PipelineContext::GetCurrentContext();
1037     auto [node0, layoutWrapper0] =
1038         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 100.0f, 100.0f));
1039     auto [child, layoutWrapper1] =
1040         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 75.0f, 55.0f));
1041     child->MountToParent(node0);
1042 
1043     PaddingProperty safeAreaPadding = {
1044         .left = CalcLength(10.0f),
1045         .right = CalcLength(15.0f),
1046         .top = CalcLength(20.0f),
1047         .bottom = CalcLength(25.0f)
1048     };
1049     layoutWrapper0->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding);
1050 
1051     ExpandEdges expectedRes = {
1052         .left = std::make_optional<float>(10.0f),
1053         .right = std::nullopt,
1054         .top = std::make_optional<float>(20.0f),
1055         .bottom = std::nullopt
1056     };
1057 
1058     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1059         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1060         .edges = NG::LAYOUT_SAFE_AREA_EDGE_START | NG::LAYOUT_SAFE_AREA_EDGE_TOP
1061     }), expectedRes);
1062 }
1063 
1064 /**
1065  * @tc.name: TypeControlOnGetAccumulatedSafeAreaExpand
1066  * @tc.desc: Test GetAccumulatedSafeAreaExpand with Types options
1067  * @tc.type: FUNC
1068  */
1069 HWTEST_F(LayoutWrapperTestTwoNg, TypeControlOnGetAccumulatedSafeAreaExpand, TestSize.Level1)
1070 {
1071     auto pipeline = PipelineContext::GetCurrentContext();
1072     auto [parent, parentWrapper] =
1073         CreateNodeAndWrapper2(V2::STAGE_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 200.0f, 200.0f));
1074     auto [node0, layoutWrapper0] =
1075         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(0.0f, 30.0f, 100.0f, 140.0f));
1076     node0->MountToParent(parent);
1077     auto [child, layoutWrapper1] =
1078         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_2, RectF(10.0f, 20.0f, 75.0f, 95.0f));
1079     child->MountToParent(node0);
1080 
1081     pipeline->stageManager_ = AceType::MakeRefPtr<StageManager>(parent);
1082     pipeline->safeAreaManager_->SetIgnoreSafeArea(false);
1083     pipeline->safeAreaManager_->SetIsFullScreen(false);
1084     pipeline->safeAreaManager_->SetIsNeedAvoidWindow(true);
1085     pipeline->safeAreaManager_->UpdateSystemSafeArea(
1086         NG::SafeAreaInsets({0.0f, 0.0f}, {0.0f, 30.0f}, {0.0f, 0.0f}, {170.0f, 200.0f}));
1087 
1088     PaddingProperty safeAreaPadding = {
1089         .left = CalcLength(10.0f),
1090         .right = CalcLength(15.0f),
1091         .top = CalcLength(20.0f),
1092         .bottom = CalcLength(25.0f)
1093     };
1094     layoutWrapper0->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding);
1095 
1096     ExpandEdges expectedRes = {
1097         .top = std::make_optional<float>(50.0f),
1098         .bottom = std::make_optional<float>(55.0f),
1099         .left = std::make_optional<float>(10.0f),
1100         .right = std::make_optional<float>(15.0f)
1101     };
1102 
1103     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1104         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1105         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1106     }), expectedRes);
1107 
1108     expectedRes.top = std::make_optional<float>(20.0f);
1109     expectedRes.bottom = std::make_optional<float>(25.0f);
1110     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1111         .type = NG::LAYOUT_SAFE_AREA_TYPE_KEYBOARD,
1112         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1113     }), expectedRes);
1114 }
1115 
1116 /**
1117  * @tc.name: StrategyControlOnGetAccumulatedSafeAreaExpand001
1118  * @tc.desc: Test GetAccumulatedSafeAreaExpand with Strategy options
1119  * @tc.type: FUNC
1120  */
1121 HWTEST_F(LayoutWrapperTestTwoNg, StrategyControlOnGetAccumulatedSafeAreaExpand001, TestSize.Level1)
1122 {
1123     auto pipeline = PipelineContext::GetCurrentContext();
1124     auto [node0, layoutWrapper0] =
1125         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 200.0f, 200.0f));
1126     auto [child, layoutWrapper1] =
1127         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 165.0f, 145.0f));
1128     child->MountToParent(node0);
1129     PresetSceneForStrategyTest(layoutWrapper0, layoutWrapper1);
1130 
1131     ExpandEdges expectedRes;
1132     /**
1133      * @tc.steps: step1. base scene
1134      */
1135     expectedRes = {
1136         .left = std::make_optional<float>(10.0f),
1137         .right = std::nullopt,
1138         .top = std::make_optional<float>(20.0f),
1139         .bottom = std::nullopt
1140     };
1141     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1142         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1143         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1144     }), expectedRes);
1145 
1146     /**
1147      * @tc.steps: step2. from self
1148      */
1149     expectedRes = {
1150         .left = std::make_optional<float>(20.0f),
1151         .right = std::make_optional<float>(15.0f),
1152         .top = std::make_optional<float>(30.0f),
1153         .bottom = std::make_optional<float>(15.0f)
1154     };
1155     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(true, {
1156         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1157         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1158     }), expectedRes);
1159 }
1160 
1161 /**
1162  * @tc.name: StrategyControlOnGetAccumulatedSafeAreaExpand002
1163  * @tc.desc: Test GetAccumulatedSafeAreaExpand with Strategy options
1164  * @tc.type: FUNC
1165  */
1166 HWTEST_F(LayoutWrapperTestTwoNg, StrategyControlOnGetAccumulatedSafeAreaExpand002, TestSize.Level1)
1167 {
1168     auto pipeline = PipelineContext::GetCurrentContext();
1169     auto [node0, layoutWrapper0] =
1170         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 200.0f, 200.0f));
1171     auto [child, layoutWrapper1] =
1172         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 165.0f, 145.0f));
1173     child->MountToParent(node0);
1174     PresetSceneForStrategyTest(layoutWrapper0, layoutWrapper1);
1175 
1176     ExpandEdges expectedRes = {
1177         .left = std::make_optional<float>(10.0f),
1178         .right = std::make_optional<float>(15.0f),
1179         .top = std::make_optional<float>(20.0f),
1180         .bottom = std::make_optional<float>(25.0f)
1181     };
1182     /**
1183      * @tc.steps: step3. from margin
1184      */
1185     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1186         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1187         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1188     }, IgnoreStrategy::FROM_MARGIN), expectedRes);
1189 
1190     /**
1191      * @tc.steps: step4. from margin, with invalid fromSelf
1192      */
1193     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(true, {
1194         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1195         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1196     }, IgnoreStrategy::FROM_MARGIN), expectedRes);
1197 }
1198 
1199 /**
1200  * @tc.name: StrategyControlOnGetAccumulatedSafeAreaExpand003
1201  * @tc.desc: Test GetAccumulatedSafeAreaExpand with Strategy options
1202  * @tc.type: FUNC
1203  */
1204 HWTEST_F(LayoutWrapperTestTwoNg, StrategyControlOnGetAccumulatedSafeAreaExpand003, TestSize.Level1)
1205 {
1206     auto pipeline = PipelineContext::GetCurrentContext();
1207     auto [node0, layoutWrapper0] =
1208         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 200.0f, 200.0f));
1209     auto [child, layoutWrapper1] =
1210         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(10.0f, 20.0f, 165.0f, 145.0f));
1211     child->MountToParent(node0);
1212     PresetSceneForStrategyTest(layoutWrapper0, layoutWrapper1);
1213     PaddingProperty margin1 = {
1214         .left = CalcLength(10.0f),
1215         .right = CalcLength(10.0f),
1216         .top = CalcLength(10.0f),
1217         .bottom = CalcLength(10.0f)
1218     };
1219     layoutWrapper1->GetLayoutProperty()->UpdateMargin(margin1);
1220     MarginPropertyF margin1_ = {
1221         .left = 10.0f,
1222         .right = 10.0f,
1223         .top = 10.0f,
1224         .bottom = 10.0f
1225     };
1226     layoutWrapper1->GetGeometryNode()->UpdateMargin(margin1_);
1227     layoutWrapper1->GetLayoutProperty()->marginResult_ = margin1_;
1228 
1229     ExpandEdges expectedRes = {
1230         .left = std::nullopt,
1231         .right = std::nullopt,
1232         .top = std::nullopt,
1233         .bottom = std::nullopt
1234     };
1235     /**
1236      * @tc.steps: step5. overlay whole margin
1237      */
1238     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1239         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1240         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1241     }), expectedRes);
1242 
1243     /**
1244      * @tc.steps: step6. overlay whole margin, with fromMargin
1245      */
1246     expectedRes.left = 0.0f;
1247     expectedRes.right = 15.0f;
1248     expectedRes.bottom = 25.0f;
1249     expectedRes.top = 10.0f;
1250     auto res = layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1251         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1252         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1253     }, IgnoreStrategy::FROM_MARGIN);
1254     EXPECT_EQ(res, expectedRes) << res.ToString().c_str();
1255 }
1256 /**
1257  * @tc.name: OverBorderPaddingOnGetAccumulatedSafeAreaExpand
1258  * @tc.desc: Test GetAccumulatedSafeAreaExpand over borderPadding
1259  * @tc.type: FUNC
1260  */
1261 HWTEST_F(LayoutWrapperTestTwoNg, OverBorderPaddingOnGetAccumulatedSafeAreaExpand, TestSize.Level1)
1262 {
1263     auto pipeline = PipelineContext::GetCurrentContext();
1264     auto [parent, parentWrapper] =
1265         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, RectF(0.0f, 0.0f, 200.0f, 200.0f));
1266     auto [node0, layoutWrapper0] =
1267         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, RectF(25.0f, 25.0f, 150.0f, 150.0f));
1268     node0->MountToParent(parent);
1269     auto [child, layoutWrapper1] =
1270         CreateNodeAndWrapper2(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_2, RectF(25.0f, 25.0f, 100.0f, 100.0f));
1271     child->MountToParent(node0);
1272 
1273     PaddingProperty safeAreaPadding = {
1274         .left = CalcLength(30.0f),
1275         .right = CalcLength(30.0f),
1276         .top = CalcLength(30.0f),
1277         .bottom = CalcLength(30.0f)
1278     };
1279     parentWrapper->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding);
1280     layoutWrapper0->GetLayoutProperty()->UpdateSafeAreaPadding(safeAreaPadding);
1281 
1282     PaddingProperty padding0 = {
1283         .left = CalcLength(1.0f),
1284         .right = CalcLength(1.0f),
1285         .top = CalcLength(1.0f),
1286         .bottom = CalcLength(1.0f)
1287     };
1288     layoutWrapper0->GetLayoutProperty()->UpdatePadding(padding0);
1289 
1290     ExpandEdges expectedRes;
1291     /**
1292      * @tc.steps: step1. overlay with whole borderPadding
1293      */
1294     expectedRes = {
1295         .left = std::make_optional<float>(24.0f),
1296         .right = std::make_optional<float>(24.0f),
1297         .top = std::make_optional<float>(24.0f),
1298         .bottom = std::make_optional<float>(24.0f)
1299     };
1300     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1301         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1302         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1303     }), expectedRes);
1304 
1305     /**
1306      * @tc.steps: step2. overlay without whole borderPadding
1307      */
1308     padding0.left = CalcLength(0.0f);
1309     layoutWrapper0->GetLayoutProperty()->UpdatePadding(padding0);
1310     expectedRes = {
1311         .left = std::make_optional<float>(50.0f),
1312         .right = std::make_optional<float>(50.0f),
1313         .top = std::make_optional<float>(50.0f),
1314         .bottom = std::make_optional<float>(50.0f)
1315     };
1316     EXPECT_EQ(layoutWrapper1->GetAccumulatedSafeAreaExpand(false, {
1317         .type = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM,
1318         .edges = NG::LAYOUT_SAFE_AREA_EDGE_ALL
1319     }), expectedRes);
1320 }
1321 }