• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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/property/layout_constraint.h"
39 #include "core/components_ng/property/property.h"
40 #include "core/components_ng/property/safe_area_insets.h"
41 #include "core/components_ng/syntax/lazy_for_each_model.h"
42 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
43 #include "core/components_v2/inspector/inspector_constants.h"
44 #include "core/pipeline_ng/ui_task_scheduler.h"
45 
46 #undef private
47 #undef protected
48 
49 using namespace testing;
50 using namespace testing::ext;
51 
52 namespace OHOS::Ace::NG {
53 namespace {
54 constexpr int32_t INDEX_NUM_0 = 0;
55 constexpr int32_t INDEX_ERROR_NUM = -1;
56 constexpr int32_t NODE_ID_0 = 0;
57 constexpr int32_t CHILD_COUNT = 1;
58 constexpr int32_t NODE_ID_1 = 1;
59 constexpr int32_t NODE_ID_2 = 2;
60 constexpr int32_t NODE_ID_3 = 3;
61 constexpr int32_t CACHE_COUNT = 1;
62 constexpr int32_t ERROR_HOST_DEPTH = -1;
63 const std::pair<int32_t, int32_t> RANGE { -1, 0 };
64 const std::pair<int32_t, int32_t> RANGE_0 { 0, 0 };
65 
66 constexpr float RK356_WIDTH = 720.0f;
67 constexpr float RK356_HEIGHT = 1136.0f;
68 constexpr float ROW_HEIGHT = 120.0f;
69 
70 const SizeF CONTAINER_SIZE { RK356_WIDTH, RK356_HEIGHT };
71 SizeF SELF_IDEAL_SIZE { RK356_WIDTH, ROW_HEIGHT };
72 SizeF FRAME_SIZE { 0, 0 };
73 const SizeF TEST_FRAME_SIZE { 0, 0 };
74 OptionalSize IDEAL_SIZE { 0, 0 };
75 
76 const std::string TEST_TAG = "";
77 const std::string ROW_FRAME_NODE = "rowFrameNode";
78 const std::string FIRST_FRAME_NODE = "TabContent";
79 const std::string FIRST_CHILD_FRAME_NODE = "firstChildFrameNode";
80 const std::string SECOND_CHILD_FRAME_NODE = "secondChildFrameNode";
81 const std::string THIRD_CHILD_FRAME_NODE = "thirdChildFrameNode";
82 
83 constexpr bool TEST_TRUE = true;
84 constexpr bool TEST_FALSE = false;
85 
CreateNodeAndWrapper(const std::string & tag,int32_t nodeId)86 std::pair<RefPtr<FrameNode>, RefPtr<LayoutWrapperNode>> CreateNodeAndWrapper(const std::string& tag, int32_t nodeId)
87 {
88     auto node = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
89     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
90     RefPtr<LayoutWrapperNode> layoutWrapper =
91         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
92 
93     return std::make_pair(node, layoutWrapper);
94 }
95 
CreateLayoutWrapper(const std::string & tag,int32_t nodeId)96 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(const std::string& tag, int32_t nodeId)
97 {
98     auto rowFrameNode = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<LinearLayoutPattern>(false));
99     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
100     RefPtr<LayoutWrapperNode> layoutWrapper =
101         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
102 
103     return layoutWrapper;
104 }
105 
CreateChildLayoutWrapper(const std::string & tag,int32_t nodeId)106 RefPtr<LayoutWrapperNode> CreateChildLayoutWrapper(const std::string& tag, int32_t nodeId)
107 {
108     auto frameNode = FrameNode::CreateFrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>());
109     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
110     RefPtr<LayoutWrapperNode> layoutWrapper =
111         AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
112 
113     return layoutWrapper;
114 }
115 
CreateLayoutWrapperBuilder()116 RefPtr<LazyLayoutWrapperBuilder> CreateLayoutWrapperBuilder()
117 {
118     RefPtr<LazyForEachActuator> actuator = AceType::MakeRefPtr<LazyForEachActuator>();
119     auto builder = AceType::DynamicCast<LazyForEachBuilder>(actuator);
120     RefPtr<LazyForEachNode> host_ = AceType::MakeRefPtr<LazyForEachNode>(NODE_ID_1, builder);
121     WeakPtr<LazyForEachNode> host(host_);
122     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = AceType::MakeRefPtr<LazyLayoutWrapperBuilder>(builder, host);
123 
124     return wrapperBuilder;
125 }
126 
UpdateParentConstraint(RefPtr<LayoutWrapperNode> layoutWrapper,LayoutConstraintF & parentConstraint)127 void UpdateParentConstraint(RefPtr<LayoutWrapperNode> layoutWrapper, LayoutConstraintF& parentConstraint)
128 {
129     parentConstraint.maxSize = CONTAINER_SIZE;
130     parentConstraint.percentReference = CONTAINER_SIZE;
131     parentConstraint.selfIdealSize.SetSize(SizeF(RK356_WIDTH, ROW_HEIGHT));
132 
133     layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentConstraint);
134 }
135 } // namespace
136 
137 class LayoutWrapperTestNg : public testing::Test {
138 public:
139     static void SetUpTestSuite();
140     static void TearDownTestSuite();
141 };
142 
SetUpTestSuite()143 void LayoutWrapperTestNg::SetUpTestSuite()
144 {
145     MockPipelineContext::SetUp();
146 }
147 
TearDownTestSuite()148 void LayoutWrapperTestNg::TearDownTestSuite()
149 {
150     MockPipelineContext::TearDown();
151 }
152 
153 /**
154  * @tc.name: LayoutWrapperTest001
155  * @tc.desc: Test GetOrCreateChildByIndex.
156  * @tc.type: FUNC
157  */
158 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest001, TestSize.Level1)
159 {
160     /**
161      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
162      */
163     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
164 
165     /**
166      * @tc.steps: step2. call GetOrCreateChildByIndex and set input index is INDEX_NUM_0.
167      * @tc.expected: the return value is null.
168      */
169     RefPtr<LayoutWrapper> testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_FALSE);
170     EXPECT_EQ(testWrapper, nullptr);
171 
172     /**
173      * @tc.steps: step3. call GetOrCreateChildByIndex and set input index is INDEX_ERROR_NUM.
174      * @tc.expected: the return value is null.
175      */
176     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_ERROR_NUM, TEST_FALSE);
177     EXPECT_EQ(testWrapper, nullptr);
178 
179     /**
180      * @tc.steps: step4. create firstChildLayoutWrapper and append it to layoutWrapper.
181      */
182     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
183     layoutWrapper->AppendChild(firstChildLayoutWrapper);
184 
185     /**
186      * @tc.steps: step5. call GetOrCreateChildByIndex and set input index is INDEX_NUM_0.
187      * @tc.expected: the return value is the same as secondLayoutWrapper.
188      */
189     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_FALSE);
190     EXPECT_EQ(testWrapper, firstChildLayoutWrapper);
191 
192     /**
193      * @tc.steps: step6. call GetOrCreateChildByIndex and set input addToRenderTree is TEST_TRUE.
194      * @tc.expected: testWrapper->isActive_ is true.
195      */
196     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_TRUE);
197 
198     EXPECT_TRUE(AceType::DynamicCast<LayoutWrapperNode>(layoutWrapper->GetOrCreateChildByIndex(0))->isActive_);
199 }
200 
201 /**
202  * @tc.name: LayoutWrapperTest002
203  * @tc.desc: Test GetOrCreateChildByIndex.
204  * @tc.type: FUNC
205  */
206 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest002, TestSize.Level1)
207 {
208     /**
209      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
210      */
211     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
212 
213     /**
214      * @tc.steps: step2. call GetOrCreateChildByIndex and set layoutWrapper->currentChildCount_ is CHILD_COUNT.
215      * @tc.expected: the return value is null and layoutWrapper->layoutWrapperBuilder_ is null.
216      */
217     layoutWrapper->currentChildCount_ = CHILD_COUNT;
218     RefPtr<LayoutWrapper> testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_FALSE);
219     EXPECT_EQ(testWrapper, nullptr);
220     EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
221 
222     /**
223      * @tc.steps: step3. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
224      */
225     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
226     layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
227 
228     /**
229      * @tc.steps: step4. call GetOrCreateChildByIndex and set index is INDEX_NUM_0.
230      * @tc.expected: the return value is null.
231      */
232     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_FALSE);
233     EXPECT_EQ(testWrapper, nullptr);
234 
235     /**
236      * @tc.steps: step5. call GetOrCreateChildByIndex and set layoutWrapperBuilder_->wrapperMap_ is not null.
237      * @tc.expected: the return value is not null.
238      */
239     layoutWrapper->layoutWrapperBuilder_->startIndex_ = -1;
240     layoutWrapper->layoutWrapperBuilder_->wrapperMap_ = { { 1, layoutWrapper } };
241     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_FALSE);
242     ASSERT_NE(testWrapper, nullptr);
243 
244     /**
245      * @tc.steps: step6. call GetOrCreateChildByIndex and set input addToRenderTree is TEST_TRUE.
246      * @tc.expected: the return value is not null.
247      */
248     testWrapper = layoutWrapper->GetOrCreateChildByIndex(INDEX_NUM_0, TEST_TRUE);
249     EXPECT_TRUE(layoutWrapper->isActive_);
250 }
251 
252 /**
253  * @tc.name: LayoutWrapperTest003
254  * @tc.desc: Test SetCacheCount.
255  * @tc.type: FUNC
256  */
257 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest003, TestSize.Level1)
258 {
259     /**
260      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
261      */
262     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
263 
264     /**
265      * @tc.steps: step2. call SetCacheCount.
266      * @tc.expected: layoutWrapperBuilder_->cacheCount_ is 0.
267      */
268     layoutWrapper->SetCacheCount(CACHE_COUNT);
269     EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
270 
271     /**
272      * @tc.steps: step3. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
273      */
274     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
275     layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
276 
277     /**
278      * @tc.steps: step4. call SetCacheCount.
279      * @tc.expected: layoutWrapperBuilder_->cacheCount_ is equal to CACHE_COUNT.
280      */
281     layoutWrapper->SetCacheCount(CACHE_COUNT);
282     EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_->cacheCount_, CACHE_COUNT);
283 }
284 
285 /**
286  * @tc.name: LayoutWrapperTest004
287  * @tc.desc: Test GetAllChildrenWithBuild.
288  * @tc.type: FUNC
289  */
290 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest004, TestSize.Level1)
291 {
292     /**
293      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
294      */
295     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
296 
297     /**
298      * @tc.steps: step2. call GetAllChildrenWithBuild.
299      * @tc.expected: the return value is empty.
300      */
301     std::list<RefPtr<LayoutWrapper>> retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_TRUE);
302     EXPECT_TRUE(retCachedList.empty());
303 
304     /**
305      * @tc.steps: step3. create firstChildLayoutWrapper and append it to layoutWrapper.
306      */
307     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
308     layoutWrapper->AppendChild(firstChildLayoutWrapper);
309 
310     /**
311      * @tc.steps: step4. call GetAllChildrenWithBuild.
312      * @tc.expected: the return value is not empty.
313      */
314     retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_TRUE);
315     EXPECT_FALSE(retCachedList.empty());
316     EXPECT_TRUE(firstChildLayoutWrapper->isActive_);
317 
318     /**
319      * @tc.steps: step5. call GetAllChildrenWithBuild again.
320      * @tc.expected: the return value is not empty.
321      */
322     retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_TRUE);
323     EXPECT_FALSE(retCachedList.empty());
324 }
325 
326 /**
327  * @tc.name: LayoutWrapperTest005
328  * @tc.desc: Test GetAllChildrenWithBuild TEST_TRUE.
329  * @tc.type: FUNC
330  */
331 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest005, TestSize.Level1)
332 {
333     /**
334      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
335      */
336     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
337 
338     /**
339      * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
340      */
341     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
342     layoutWrapper->AppendChild(firstChildLayoutWrapper);
343 
344     /**
345      * @tc.steps: step3. call GetAllChildrenWithBuild and set child->isActive_ is TEST_TRUE.
346      * @tc.expected: the return value is not empty.
347      */
348     firstChildLayoutWrapper->isActive_ = TEST_TRUE;
349     std::list<RefPtr<LayoutWrapper>> retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_TRUE);
350     EXPECT_FALSE(retCachedList.empty());
351     EXPECT_TRUE(firstChildLayoutWrapper->isActive_);
352 }
353 
354 /**
355  * @tc.name: LayoutWrapperTest006
356  * @tc.desc: Test the operation of layout_wrapper.
357  * @tc.type: FUNC
358  */
359 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest006, TestSize.Level1)
360 {
361     /**
362      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
363      */
364     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
365 
366     /**
367      * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
368      */
369     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
370     layoutWrapper->AppendChild(firstChildLayoutWrapper);
371 
372     /**
373      * @tc.steps: step3. call GetAllChildrenWithBuild.
374      * @tc.expected: the return value is the same as layoutWrapper->children_.
375      */
376     std::list<RefPtr<LayoutWrapper>> retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_FALSE);
377     EXPECT_EQ(retCachedList, layoutWrapper->cachedList_);
378 }
379 
380 /**
381  * @tc.name: LayoutWrapperTest007
382  * @tc.desc: Test GetAllChildrenWithBuild TEST_FALSE.
383  * @tc.type: FUNC
384  */
385 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest007, TestSize.Level1)
386 {
387     /**
388      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
389      */
390     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
391 
392     /**
393      * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
394      */
395     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
396     layoutWrapper->AppendChild(firstChildLayoutWrapper);
397 
398     /**
399      * @tc.steps: step3. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
400      */
401     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
402     layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
403 
404     /**
405      * @tc.steps: step4. call GetAllChildrenWithBuild and set layoutWrapper->layoutWrapperBuilder_ is not null.
406      * @tc.expected: the return value is not empty.
407      */
408     std::list<RefPtr<LayoutWrapper>> retCachedList = layoutWrapper->GetAllChildrenWithBuild(TEST_FALSE);
409     EXPECT_FALSE(retCachedList.empty());
410     EXPECT_FALSE(firstChildLayoutWrapper->isActive_);
411 }
412 
413 /**
414  * @tc.name: LayoutWrapperTest008
415  * @tc.desc: Test RemoveChildInRenderTree.
416  * @tc.type: FUNC
417  */
418 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest008, TestSize.Level1)
419 {
420     /**
421      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
422      */
423     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
424     EXPECT_FALSE(layoutWrapper->isActive_);
425 
426     /**
427      * @tc.steps: step3. create firstChildLayoutWrapper and append it to layoutWrapper.
428      */
429     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
430     layoutWrapper->AppendChild(firstChildLayoutWrapper);
431 
432     /**
433      * @tc.steps: step4. call RemoveChildInRenderTree and set input wrapper is secondLayoutWrapper.
434      * @tc.expected: firstChildLayoutWrapper->isActive_ is false.
435      */
436     layoutWrapper->RemoveChildInRenderTree(firstChildLayoutWrapper);
437     EXPECT_FALSE(firstChildLayoutWrapper->isActive_);
438 }
439 
440 /**
441  * @tc.name: LayoutWrapperTest009
442  * @tc.desc: Test RemoveChildInRenderTree.
443  * @tc.type: FUNC
444  */
445 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest009, TestSize.Level1)
446 {
447     /**
448      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
449      */
450     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
451 
452     /**
453      * @tc.steps: step3. create firstChildLayoutWrapper and append it to layoutWrapper.
454      */
455     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
456     layoutWrapper->AppendChild(firstChildLayoutWrapper);
457 
458     /**
459      * @tc.steps: step3. call RemoveChildInRenderTree and set input index is NODE_ID_1.
460      * @tc.expected: layoutWrapper->isActive_ is false.
461      */
462     layoutWrapper->RemoveChildInRenderTree(NODE_ID_1);
463     EXPECT_FALSE(firstChildLayoutWrapper->isActive_);
464 
465     /**
466      * @tc.steps: step4. call RemoveChildInRenderTree and set input index is NODE_ID_0.
467      * @tc.expected: the return layoutWrapper->isActive_ is true.
468      */
469     layoutWrapper->isActive_ = TEST_TRUE;
470     layoutWrapper->RemoveChildInRenderTree(NODE_ID_0);
471     EXPECT_TRUE(layoutWrapper->isActive_);
472 }
473 
474 /**
475  * @tc.name: LayoutWrapperTest010
476  * @tc.desc: Test RemoveAllChildInRenderTree.
477  * @tc.type: FUNC
478  */
479 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest010, TestSize.Level1)
480 {
481     /**
482      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
483      */
484     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
485 
486     /**
487      * @tc.steps: step2. call RemoveChildInRenderTree.
488      * @tc.expected: layoutWrapper->isActive_ is false.
489      */
490     layoutWrapper->RemoveAllChildInRenderTree();
491     EXPECT_FALSE(layoutWrapper->isActive_);
492 
493     /**
494      * @tc.steps: step3. create two layoutWrapper and append them to layoutWrapper.
495      */
496     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
497     RefPtr<LayoutWrapperNode> secondChildLayoutWrapper = CreateChildLayoutWrapper(SECOND_CHILD_FRAME_NODE, NODE_ID_2);
498 
499     firstChildLayoutWrapper->isActive_ = TEST_TRUE;
500     secondChildLayoutWrapper->isActive_ = TEST_TRUE;
501 
502     layoutWrapper->AppendChild(firstChildLayoutWrapper);
503     layoutWrapper->AppendChild(secondChildLayoutWrapper);
504 
505     /**
506      * @tc.steps: step4. call RemoveAllChildInRenderTree.
507      * @tc.expected: the firstChildLayoutWrapper->isActive_ and  secondChildLayoutWrapper->isActive_ are false.
508      */
509     layoutWrapper->RemoveAllChildInRenderTree();
510     EXPECT_FALSE(firstChildLayoutWrapper->isActive_);
511     EXPECT_FALSE(secondChildLayoutWrapper->isActive_);
512 
513     /**
514      * @tc.steps: step5. create thirdChildLayoutWrapper and append it to layoutWrapper.
515      */
516     RefPtr<LayoutWrapperNode> thirdChildLayoutWrapper = CreateChildLayoutWrapper(THIRD_CHILD_FRAME_NODE, NODE_ID_3);
517     thirdChildLayoutWrapper->isActive_ = TEST_TRUE;
518     layoutWrapper->AppendChild(thirdChildLayoutWrapper);
519 
520     /**
521      * @tc.steps: step6. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
522      */
523     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
524     layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
525 
526     /**
527      * @tc.steps: step7. call RemoveChildInRenderTree.
528      * @tc.expected: thirdChildLayoutWrapper->isActive_ is false.
529      */
530     layoutWrapper->RemoveAllChildInRenderTree();
531     EXPECT_FALSE(thirdChildLayoutWrapper->isActive_);
532 }
533 
534 /**
535  * @tc.name: LayoutWrapperTest011
536  * @tc.desc: Test ResetHostNode.
537  * @tc.type: FUNC
538  */
539 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest011, TestSize.Level1)
540 {
541     /**
542      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
543      */
544     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
545 
546     /**
547      * @tc.steps: step2. call ResetHostNode.
548      * @tc.expected: layoutWrapper->hostNode_.refCounter_ is null.
549      */
550     layoutWrapper->ResetHostNode();
551     EXPECT_EQ(layoutWrapper->hostNode_.refCounter_, nullptr);
552 }
553 
554 /**
555  * @tc.name: LayoutWrapperTest012
556  * @tc.desc: Test GetHostNode.
557  * @tc.type: FUNC
558  */
559 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest012, TestSize.Level1)
560 {
561     /**
562      * @tc.steps: step1. create layoutwrapper.
563      */
564     auto rowFrameNode =
565         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
566     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
567     RefPtr<LayoutWrapperNode> layoutWrapper =
568         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
569 
570     /**
571      * @tc.steps: step2. call GetHostNode.
572      * @tc.expected: the return value is the same as rowFrameNode.
573      */
574     RefPtr<FrameNode> hostNode = layoutWrapper->GetHostNode();
575     EXPECT_EQ(hostNode, rowFrameNode);
576 }
577 
578 /**
579  * @tc.name: LayoutWrapperTest013
580  * @tc.desc: Test GetHostTag.
581  * @tc.type: FUNC
582  */
583 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest013, TestSize.Level1)
584 {
585     /**
586      * @tc.steps: step1. create layoutwrapper.
587      */
588     auto rowFrameNode =
589         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
590     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
591     RefPtr<LayoutWrapperNode> layoutWrapper =
592         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
593 
594     /**
595      * @tc.steps: step2. call GetHostTag.
596      * @tc.expected: the return retHostTag is the same as ROW_FRAME_NODE.
597      */
598     std::string hostTag = layoutWrapper->GetHostTag();
599     EXPECT_EQ(hostTag, ROW_FRAME_NODE);
600 
601     /**
602      * @tc.steps: step3. call GetHostTag and set hostNode_ is null.
603      * @tc.expected: the return value is the same as TEST_TAG.
604      */
605     layoutWrapper->hostNode_ = nullptr;
606     hostTag = layoutWrapper->GetHostTag();
607     EXPECT_EQ(hostTag, TEST_TAG);
608 }
609 
610 /**
611  * @tc.name: LayoutWrapperTest014
612  * @tc.desc: Test GetHostDepth.
613  * @tc.type: FUNC
614  */
615 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest014, TestSize.Level1)
616 {
617     /**
618      * @tc.steps: step1. create layoutwrapper.
619      */
620     auto rowFrameNode =
621         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
622     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
623     RefPtr<LayoutWrapperNode> layoutWrapper =
624         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
625 
626     /**
627      * @tc.steps: step2. call GetHostDepth and set hostNode_ is not null.
628      * @tc.expected: the return value is equal to HOST_DEPTH.
629      */
630     int32_t hostDepth = layoutWrapper->GetHostDepth();
631     EXPECT_EQ(hostDepth, Infinity<int32_t>());
632 
633     /**
634      * @tc.steps: step3. call GetHostDepth and set hostNode_ is null.
635      * @tc.expected: the return value is equal to ERROR_HOST_DEPTH.
636      */
637     layoutWrapper->hostNode_ = nullptr;
638     hostDepth = layoutWrapper->GetHostDepth();
639     EXPECT_EQ(hostDepth, ERROR_HOST_DEPTH);
640 }
641 
642 /**
643  * @tc.name: LayoutWrapperTest015
644  * @tc.desc: Test Measure.
645  * @tc.type: FUNC
646  */
647 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest015, TestSize.Level1)
648 {
649     /**
650      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
651      */
652     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
653 
654     /**
655      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
656      */
657     LayoutConstraintF parentLayoutConstraint;
658     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
659 
660     /**
661      * @tc.steps: step3. call Measure and set layoutWrapper->layoutProperty_ is null.
662      */
663     layoutWrapper->layoutProperty_ = nullptr;
664     layoutWrapper->Measure(parentLayoutConstraint);
665 
666     /**
667      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
668      */
669     FRAME_SIZE.width_ = layoutWrapper->geometryNode_->GetFrameSize().Width();
670     FRAME_SIZE.height_ = layoutWrapper->geometryNode_->GetFrameSize().Height();
671     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
672 }
673 
674 /**
675  * @tc.name: LayoutWrapperTest016
676  * @tc.desc: Test Measure.
677  * @tc.type: FUNC
678  */
679 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest016, TestSize.Level1)
680 {
681     /**
682      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
683      */
684     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
685 
686     /**
687      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
688      */
689     LayoutConstraintF parentLayoutConstraint;
690     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
691 
692     /**
693      * @tc.steps: step3. call Measure and set layoutWrapper->geometryNode_ is null.
694      * @tc.expected: layoutWrapper->geometryNode_ is null.
695      */
696     layoutWrapper->geometryNode_ = nullptr;
697     layoutWrapper->Measure(parentLayoutConstraint);
698     EXPECT_EQ(layoutWrapper->geometryNode_, nullptr);
699 }
700 
701 /**
702  * @tc.name: LayoutWrapperTest017
703  * @tc.desc: Test Measure.
704  * @tc.type: FUNC
705  */
706 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest017, TestSize.Level1)
707 {
708     /**
709      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
710      */
711     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
712 
713     /**
714      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
715      */
716     LayoutConstraintF parentLayoutConstraint;
717     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
718 
719     /**
720      * @tc.steps: step3. call Measure and set layoutWrapper->hostNode_ is null.
721      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
722      */
723     layoutWrapper->hostNode_ = nullptr;
724     layoutWrapper->Measure(parentLayoutConstraint);
725     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
726     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
727 }
728 
729 /**
730  * @tc.name: LayoutWrapperTest018
731  * @tc.desc: Test Measure.
732  * @tc.type: FUNC
733  */
734 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest018, TestSize.Level1)
735 {
736     /**
737      * @tc.steps: step1. create layoutwrapper.
738      */
739     auto rowFrameNode =
740         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
741     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
742     RefPtr<LayoutWrapperNode> layoutWrapper =
743         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
744 
745     /**
746      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
747      */
748     LayoutConstraintF parentLayoutConstraint;
749     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
750 
751     /**
752      * @tc.steps: step3. call Measure and set layoutWrapper->layoutAlgorithm_ is null.
753      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
754      */
755     layoutWrapper->Measure(parentLayoutConstraint);
756     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
757     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
758 }
759 
760 /**
761  * @tc.name: LayoutWrapperTest019
762  * @tc.desc: Test Measure.
763  * @tc.type: FUNC
764  */
765 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest019, TestSize.Level1)
766 {
767     /**
768      * @tc.steps: step1. create layoutwrapper.
769      */
770     auto rowFrameNode =
771         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
772     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
773     RefPtr<LayoutWrapperNode> layoutWrapper =
774         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
775 
776     /**
777      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
778      */
779     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
780     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
781     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
782 
783     /**
784      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
785      */
786     LayoutConstraintF parentLayoutConstraint;
787     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
788 
789     /**
790      * @tc.steps: step4. call Measure and set layoutProperty_->geometryTransition_ is not null.
791      * @tc.expected: FRAME_SIZE.width_ is RK356_WIDTH and FRAME_SIZE.height_ is ROW_HEIGHT.
792      */
793     layoutWrapper->GetLayoutProperty()->geometryTransition_ =
794         AceType::MakeRefPtr<GeometryTransition>("test", rowFrameNode);
795     layoutWrapper->Measure(parentLayoutConstraint);
796     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
797     EXPECT_EQ(FRAME_SIZE.width_, RK356_WIDTH);
798     EXPECT_EQ(FRAME_SIZE.height_, ROW_HEIGHT);
799 }
800 
801 /**
802  * @tc.name: LayoutWrapperTest020
803  * @tc.desc: Test Measure.
804  * @tc.type: FUNC
805  */
806 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest020, TestSize.Level1)
807 {
808     /**
809      * @tc.steps: step1. create layoutwrapper.
810      */
811     auto rowFrameNode =
812         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
813     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
814     RefPtr<LayoutWrapperNode> layoutWrapper =
815         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
816 
817     /**
818      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
819      */
820     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
821     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
822     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
823 
824     /**
825      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
826      */
827     LayoutConstraintF parentLayoutConstraint;
828     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
829 
830     /**
831      * @tc.steps: step3. call Measure and set layoutAlgorithm_->skipMeasure_ is TEST_TRUE.
832      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
833      */
834     layoutWrapper->layoutAlgorithm_->skipMeasure_ = TEST_TRUE;
835     layoutWrapper->Measure(parentLayoutConstraint);
836     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
837     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
838 }
839 
840 /**
841  * @tc.name: LayoutWrapperTest021
842  * @tc.desc: Test Measure.
843  * @tc.type: FUNC
844  */
845 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest021, TestSize.Level1)
846 {
847     /**
848      * @tc.steps: step1. create a layoutwrapper pointer.
849      */
850     auto rowFrameNode =
851         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
852     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
853     RefPtr<LayoutWrapperNode> layoutWrapper =
854         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
855 
856     /**
857      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
858      */
859     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
860     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
861     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
862 
863     /**
864      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
865      */
866     LayoutConstraintF parentLayoutConstraint;
867     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
868 
869     /**
870      * @tc.steps: step3. call Measure.
871      * @tc.expected: FRAME_SIZE.Width() is RK356_WIDTH and FRAME_SIZE.Height() is ROW_HEIGHT.
872      */
873     layoutWrapper->Measure(parentLayoutConstraint);
874     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
875     EXPECT_EQ(FRAME_SIZE.width_, RK356_WIDTH);
876     EXPECT_EQ(FRAME_SIZE.height_, ROW_HEIGHT);
877 
878     /**
879      * @tc.steps: step4. UpdateAspectRatio and UpdateLayoutWeight.
880      */
881 
882     layoutWrapper->layoutProperty_->magicItemProperty_.UpdateAspectRatio(0.5);
883     layoutWrapper->layoutProperty_->magicItemProperty_.UpdateLayoutWeight(0.5);
884     /**
885      * @tc.steps: step5. call Measure.
886      * @tc.expected: FRAME_SIZE.Height() is twice as much RK356_WIDTH.
887      */
888     layoutWrapper->Measure(parentLayoutConstraint);
889     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
890     EXPECT_EQ(FRAME_SIZE.width_, RK356_WIDTH);
891     EXPECT_EQ(FRAME_SIZE.height_, RK356_WIDTH * 2);
892 
893     /**
894      * @tc.steps: step6. call Measure and set layoutProperty_->calcLayoutConstraint_is not null.
895      * @tc.expected: SELF_IDEAL_SIZE.Height() is twice as much RK356_WIDTH.
896      */
897     layoutWrapper->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
898     layoutWrapper->Measure(parentLayoutConstraint);
899     IDEAL_SIZE.width_ = layoutWrapper->layoutProperty_->layoutConstraint_->selfIdealSize.Width();
900     IDEAL_SIZE.height_ = layoutWrapper->layoutProperty_->layoutConstraint_->selfIdealSize.Height();
901     EXPECT_EQ(IDEAL_SIZE.width_, RK356_WIDTH);
902     EXPECT_EQ(IDEAL_SIZE.height_, RK356_WIDTH * 2);
903 }
904 
905 /**
906  * @tc.name: LayoutWrapperTest022
907  * @tc.desc: Test Measure.
908  * @tc.type: FUNC
909  */
910 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest022, TestSize.Level1)
911 {
912     /**
913      * @tc.steps: step1. create a layoutwrapper pointer.
914      */
915     auto rowFrameNode =
916         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
917     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
918     RefPtr<LayoutWrapperNode> layoutWrapper =
919         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
920 
921     /**
922      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
923      */
924     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
925     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
926     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
927 
928     /**
929      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
930      */
931     LayoutConstraintF parentLayoutConstraint;
932     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
933 
934     /**
935      * @tc.steps: step4. call Measure and set layoutWrapper->needForceMeasureAndLayout_ is TEST_FALSE.
936      * @tc.expected: layoutWrapper->skipMeasureContent_ is true.
937      */
938     layoutWrapper->needForceMeasureAndLayout_ = std::make_optional(TEST_FALSE);
939     layoutWrapper->Measure(parentLayoutConstraint);
940     EXPECT_TRUE(layoutWrapper->skipMeasureContent_);
941 }
942 
943 /**
944  * @tc.name: LayoutWrapperTest023
945  * @tc.desc: Test the operation of layout_wrapper.
946  * @tc.type: FUNC
947  */
948 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest023, TestSize.Level1)
949 {
950     /**
951      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
952      */
953     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
954 
955     /**
956      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
957      */
958     LayoutConstraintF parentLayoutConstraint;
959     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
960 
961     /**
962      * @tc.steps: step3. call Layout and set layoutWrapper->layoutProperty_ is null.
963      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
964      */
965     layoutWrapper->layoutProperty_ = nullptr;
966     layoutWrapper->Layout();
967     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
968     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
969 }
970 
971 /**
972  * @tc.name: LayoutWrapperTest024
973  * @tc.desc: Test Layout.
974  * @tc.type: FUNC
975  */
976 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest024, TestSize.Level1)
977 {
978     /**
979      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
980      */
981     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
982 
983     /**
984      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
985      */
986     LayoutConstraintF parentLayoutConstraint;
987     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
988 
989     /**
990      * @tc.steps: step3. call Layout and set layoutWrapper->geometryNode_ is null.
991      * @tc.expected: FRAME_SIZE is the default value.
992      */
993     layoutWrapper->geometryNode_ = nullptr;
994     layoutWrapper->Layout();
995     EXPECT_EQ(layoutWrapper->geometryNode_, nullptr);
996 }
997 
998 /**
999  * @tc.name: LayoutWrapperTest025
1000  * @tc.desc: Test Layout.
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest025, TestSize.Level1)
1004 {
1005     /**
1006      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1007      */
1008     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1009 
1010     /**
1011      * @tc.steps: step2. call UpdateParentConstraint update parentLayoutConstraint.
1012      */
1013     LayoutConstraintF parentLayoutConstraint;
1014     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
1015 
1016     /**
1017      * @tc.steps: step3. call Layout and set layoutWrapper->hostNode_ is null.
1018      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1019      */
1020     layoutWrapper->hostNode_ = nullptr;
1021     layoutWrapper->Layout();
1022     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1023     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1024 }
1025 
1026 /**
1027  * @tc.name: LayoutWrapperTest026
1028  * @tc.desc: Test Layout.
1029  * @tc.type: FUNC
1030  */
1031 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest026, TestSize.Level1)
1032 {
1033     /**
1034      * @tc.steps: step1. create a layoutwrapper pointer.
1035      */
1036     auto rowFrameNode =
1037         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1038     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1039     RefPtr<LayoutWrapperNode> layoutWrapper =
1040         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1041 
1042     /**
1043      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
1044      */
1045     LayoutConstraintF parentLayoutConstraint;
1046     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
1047 
1048     /**
1049      * @tc.steps: step3. call Layout and set layoutWrapper->layoutAlgorithm_ is not null.
1050      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1051      */
1052     layoutWrapper->Layout();
1053     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1054     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1055 }
1056 
1057 /**
1058  * @tc.name: LayoutWrapperTest027
1059  * @tc.desc: Test Layout.
1060  * @tc.type: FUNC
1061  */
1062 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest027, TestSize.Level1)
1063 {
1064     /**
1065      * @tc.steps: step1. create a layoutwrapper pointer.
1066      */
1067     auto rowFrameNode =
1068         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1069     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1070     RefPtr<LayoutWrapperNode> layoutWrapper =
1071         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1072 
1073     /**
1074      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
1075      */
1076     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
1077     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
1078     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
1079 
1080     /**
1081      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
1082      */
1083     LayoutConstraintF parentLayoutConstraint;
1084     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
1085 
1086     /**
1087      * @tc.steps: step4. call Layout and set layoutWrapper->layoutAlgorithm_->skipLayout_ is TEST_TRUE.
1088      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1089      */
1090     layoutWrapper->layoutAlgorithm_->skipLayout_ = TEST_TRUE;
1091     layoutWrapper->Layout();
1092     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1093     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1094 }
1095 
1096 /**
1097  * @tc.name: LayoutWrapperTest028
1098  * @tc.desc: Test Layout.
1099  * @tc.type: FUNC
1100  */
1101 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest028, TestSize.Level1)
1102 {
1103     /**
1104      * @tc.steps: step1. create a layoutwrapper pointer.
1105      */
1106     auto rowFrameNode =
1107         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1108     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1109     RefPtr<LayoutWrapperNode> layoutWrapper =
1110         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1111 
1112     /**
1113      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
1114      */
1115     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
1116     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
1117     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
1118 
1119     /**
1120      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
1121      */
1122     LayoutConstraintF parentLayoutConstraint;
1123     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
1124 
1125     /**
1126      * @tc.steps: step4. call Layout and set layoutWrapper->skipMeasureContent_ is default value.
1127      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1128      */
1129     layoutWrapper->Layout();
1130     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1131     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1132 
1133     /**
1134      * @tc.steps: step5. call Layout and set layoutWrapper->skipMeasureContent_ is TEST_TRUE.
1135      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1136      */
1137     layoutWrapper->skipMeasureContent_ = TEST_TRUE;
1138     layoutWrapper->Layout();
1139     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1140     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1141 }
1142 
1143 /**
1144  * @tc.name: LayoutWrapperTest029
1145  * @tc.desc: Test Layout.
1146  * @tc.type: FUNC
1147  */
1148 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest029, TestSize.Level1)
1149 {
1150     /**
1151      * @tc.steps: step1. create a layoutwrapper pointer.
1152      */
1153     auto rowFrameNode =
1154         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1155     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1156     RefPtr<LayoutWrapperNode> layoutWrapper =
1157         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1158 
1159     /**
1160      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
1161      */
1162     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
1163     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
1164     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
1165 
1166     /**
1167      * @tc.steps: step3. call UpdateParentConstraint update parentLayoutConstraint.
1168      */
1169     LayoutConstraintF parentLayoutConstraint;
1170     UpdateParentConstraint(layoutWrapper, parentLayoutConstraint);
1171 
1172     /**
1173      * @tc.steps: step4. call Layout and set layoutWrapper->skipMeasureContent_ is default value.
1174      * @tc.expected: FRAME_SIZE is the same as TEST_FRAME_SIZE.
1175      */
1176     layoutWrapper->Layout();
1177     FRAME_SIZE = layoutWrapper->geometryNode_->GetFrameSize();
1178     EXPECT_EQ(FRAME_SIZE, TEST_FRAME_SIZE);
1179 }
1180 
1181 /**
1182  * @tc.name: LayoutWrapperTest030
1183  * @tc.desc: Test SkipMeasureContent.
1184  * @tc.type: FUNC
1185  */
1186 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest030, TestSize.Level1)
1187 {
1188     /**
1189      * @tc.steps: step1. create a layoutwrapper pointer.
1190      */
1191     auto rowFrameNode =
1192         FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1193     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1194     RefPtr<LayoutWrapperNode> layoutWrapper =
1195         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1196 
1197     /**
1198      * @tc.steps: step2. set layoutWrapper->layoutAlgorithm_ is not null.
1199      */
1200     auto rowLayoutPattern = rowFrameNode->GetPattern<LinearLayoutPattern>();
1201     auto rowLayoutAlgorithm = rowLayoutPattern->CreateLayoutAlgorithm();
1202     layoutWrapper->SetLayoutAlgorithm(AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(rowLayoutAlgorithm));
1203 
1204     /**
1205      * @tc.steps: step3. call SkipMeasureContent.
1206      * @tc.expected: the return value is false.
1207      */
1208     bool retSkipMeasureContent = layoutWrapper->SkipMeasureContent();
1209     EXPECT_FALSE(retSkipMeasureContent);
1210 
1211     /**
1212      * @tc.steps: step4. call SkipMeasureContent and set layoutWrapper->skipMeasureContent_ is true.
1213      * @tc.expected: the return value is true.
1214      */
1215     layoutWrapper->skipMeasureContent_ = std::make_optional(TEST_TRUE);
1216     retSkipMeasureContent = layoutWrapper->SkipMeasureContent();
1217     EXPECT_TRUE(retSkipMeasureContent);
1218 }
1219 
1220 /**
1221  * @tc.name: LayoutWrapperTest031
1222  * @tc.desc: Test CheckNeedForceMeasureAndLayout.
1223  * @tc.type: FUNC
1224  */
1225 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest031, TestSize.Level1)
1226 {
1227     /**
1228      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1229      */
1230     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1231 
1232     /**
1233      * @tc.steps: step2. call CheckNeedForceMeasureAndLayout.
1234      * @tc.expected: the return retCheck is true.
1235      */
1236     bool retCheck = layoutWrapper->CheckNeedForceMeasureAndLayout();
1237     EXPECT_TRUE(retCheck);
1238 
1239     /**
1240      * @tc.steps: step3. call CheckNeedForceMeasureAndLayout again.
1241      * @tc.expected: the return retCheck is true.
1242      */
1243     retCheck = layoutWrapper->CheckNeedForceMeasureAndLayout();
1244     EXPECT_TRUE(retCheck);
1245 }
1246 
1247 /**
1248  * @tc.name: LayoutWrapperTest032
1249  * @tc.desc: Test CheckNeedForceMeasureAndLayout.
1250  * @tc.type: FUNC
1251  */
1252 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest032, TestSize.Level1)
1253 {
1254     /**
1255      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1256      */
1257     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1258 
1259     /**
1260      * @tc.steps: step2. call CheckNeedForceMeasureAndLayout again.
1261      * @tc.expected: the return retCheck is false.
1262      */
1263     layoutWrapper->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_NORMAL;
1264     bool retCheck = layoutWrapper->CheckNeedForceMeasureAndLayout();
1265     EXPECT_FALSE(retCheck);
1266 }
1267 
1268 /**
1269  * @tc.name: LayoutWrapperTest033
1270  * @tc.desc: Test CheckNeedForceMeasureAndLayout.
1271  * @tc.type: FUNC
1272  */
1273 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest033, TestSize.Level1)
1274 {
1275     /**
1276      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1277      */
1278     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1279 
1280     /**
1281      * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
1282      */
1283     RefPtr<LayoutWrapperNode> firstChildLayoutWrapper = CreateChildLayoutWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
1284     layoutWrapper->AppendChild(firstChildLayoutWrapper);
1285 
1286     /**
1287      * @tc.steps: step3. call CheckChildNeedForceMeasureAndLayout.
1288      * @tc.expected: the return retCheck is true.
1289      */
1290     bool retCheck = layoutWrapper->CheckChildNeedForceMeasureAndLayout();
1291     EXPECT_TRUE(retCheck);
1292 }
1293 
1294 /**
1295  * @tc.name: LayoutWrapperTest034
1296  * @tc.desc: Test BuildLazyItem.
1297  * @tc.type: FUNC
1298  */
1299 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest034, TestSize.Level1)
1300 {
1301     /**
1302      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1303      */
1304     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1305 
1306     /**
1307      * @tc.steps: step2. set layoutWrapper->lazyBuildFunction_ is not null.
1308      */
__anon1d7da86e0202(RefPtr<LayoutWrapperNode> testLayoutWrapper) 1309     auto lazyBuildFunction = [](RefPtr<LayoutWrapperNode> testLayoutWrapper) { testLayoutWrapper = nullptr; };
1310     layoutWrapper->lazyBuildFunction_ = lazyBuildFunction;
1311 
1312     /**
1313      * @tc.steps: step3. call GetLazyBuildRange.
1314      * @tc.expected: the return retRange.first is -1 and retRange.second is 0.
1315      */
1316     layoutWrapper->BuildLazyItem();
1317     EXPECT_EQ(layoutWrapper->lazyBuildFunction_, nullptr);
1318 }
1319 
1320 /**
1321  * @tc.name: LayoutWrapperTest035
1322  * @tc.desc: Test GetLazyBuildRange.
1323  * @tc.type: FUNC
1324  */
1325 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest035, TestSize.Level1)
1326 {
1327     /**
1328      * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1329      */
1330     RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1331 
1332     /**
1333      * @tc.steps: step2. call GetLazyBuildRange.
1334      * @tc.expected: the return value is the same as RANGE.
1335      */
1336     std::pair<int32_t, int32_t> retRange = layoutWrapper->GetLazyBuildRange();
1337     EXPECT_EQ(retRange, RANGE);
1338 
1339     /**
1340      * @tc.steps: step3. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
1341      */
1342     RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
1343     layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
1344 
1345     /**
1346      * @tc.steps: step4. call GetLazyBuildRange.
1347      * @tc.expected: the return value is the same as RANGE_0.
1348      */
1349     retRange = layoutWrapper->GetLazyBuildRange();
1350     EXPECT_EQ(retRange, RANGE_0);
1351 }
1352 
1353 /**
1354  * @tc.name: LayoutWrapperTest036
1355  * @tc.desc: Test Apply SafeArea constraint for Popup nodes.
1356  * @tc.type: FUNC
1357  */
1358 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest036, TestSize.Level1)
1359 {
1360     auto [parentHost, parent] = CreateNodeAndWrapper(V2::ROOT_ETS_TAG, 0);
1361     auto [stageHost, stage] = CreateNodeAndWrapper(V2::STAGE_ETS_TAG, 1);
1362     auto [popupHost, popup] = CreateNodeAndWrapper(V2::MENU_WRAPPER_ETS_TAG, 2);
1363     parentHost->AddChild(stageHost);
1364     parentHost->AddChild(popupHost);
1365     popupHost->layoutProperty_->UpdateSafeAreaInsets(SafeAreaInsets({}, { 0, 1 }, {}, {}));
1366 
1367     LayoutConstraintF constraint;
1368     UpdateParentConstraint(parent, constraint);
1369     stage->ApplyConstraint(constraint);
1370     popup->ApplyConstraint(constraint);
1371 
1372     EXPECT_EQ(stage->layoutProperty_->layoutConstraint_, constraint);
1373     // popup is restricted by safeArea
1374     EXPECT_EQ(popup->geometryNode_->parentLayoutConstraint_, constraint);
1375     EXPECT_TRUE(popup->layoutProperty_->layoutConstraint_);
1376     EXPECT_NE(popup->layoutProperty_->layoutConstraint_, constraint);
1377 }
1378 
1379 /**
1380  * @tc.name: LayoutWrapperTest037
1381  * @tc.desc: Test OffsetNodeToSafeArea.
1382  * @tc.type: FUNC
1383  */
1384 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest037, TestSize.Level1)
1385 {
1386     auto layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1387     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1388         SafeAreaInsets({}, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
1389     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT - 2 });
1390 
1391     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 1 });
1392     layoutWrapper->OffsetNodeToSafeArea();
1393     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1394 
1395     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 5 });
1396     layoutWrapper->OffsetNodeToSafeArea();
1397     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1398 
1399     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
1400     layoutWrapper->OffsetNodeToSafeArea();
1401     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1402 
1403     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1404         SafeAreaInsets({ 0, 5 }, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
1405     layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
1406     layoutWrapper->OffsetNodeToSafeArea();
1407     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1408 
1409     // set right and bottom again
1410     layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
1411     layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1412         SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }));
1413     layoutWrapper->OffsetNodeToSafeArea();
1414     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 1);
1415     EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
1416 }
1417 
1418 /**
1419  * @tc.name: LayoutWrapperTest038
1420  * @tc.desc: Test ExpandIntoKeyboard.
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest038, TestSize.Level1)
1424 {
1425     auto [parent, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
1426     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
1427 
1428     auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
1429     child->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
1430     child->MountToParent(parent);
1431 
1432     auto safeAreaManager = PipelineContext::GetCurrentContext()->safeAreaManager_;
1433     // ExpandIntoKeyboard(): use page offset judge if expandIntoKeyboard
1434     // no page node, return OffsetF(0, 0)
1435     safeAreaManager->UpdateKeyboardOffset(50.0f);
1436     EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0, 0));
1437 
1438     // parent already expanded
1439     child->ExpandIntoKeyboard();
1440     EXPECT_EQ(child->ExpandIntoKeyboard(), OffsetF(0, 0));
1441 
1442     layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_NONE, SAFE_AREA_EDGE_ALL });
1443     child->ExpandIntoKeyboard();
1444     // no page node, return OffsetF(0, 0)
1445     EXPECT_EQ(child->ExpandIntoKeyboard(), OffsetF(0, 0));
1446 }
1447 
1448 /**
1449  * @tc.name: LayoutWrapperTest039
1450  * @tc.desc: Test CreateRootConstraint.
1451  * @tc.type: FUNC
1452  */
1453 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest039, TestSize.Level1)
1454 {
1455     auto context = PipelineContext::GetCurrentContext();
1456     context->rootHeight_ = RK356_HEIGHT;
1457     context->rootWidth_ = RK356_WIDTH;
1458 
1459     auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
1460     layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT });
1461     layoutWrapper->layoutProperty_->UpdateAspectRatio(2.0);
1462     layoutWrapper->CreateRootConstraint();
1463     EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT / 2);
1464 }
1465 
1466 /**
1467  * @tc.name: LayoutWrapperTest040
1468  * @tc.desc: Test AvoidKeyboard.
1469  * @tc.type: FUNC
1470  */
1471 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest040, TestSize.Level1)
1472 {
1473     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1474 
1475     /**
1476      * @tc.steps: step1. call AddNodeFlexLayouts on a frame with parent JS_VIEW_ETS_TAG.
1477      * @tc.expected:
1478      */
1479     auto [node1, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
1480     node1->MountToParent(parent);
1481 
1482     auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
1483     child->MountToParent(node1);
1484     childWrapper->AddNodeFlexLayouts();
1485     EXPECT_EQ(node1->GetFlexLayouts(), 0);
1486 
1487     /**
1488      * @tc.steps: step2. call AddNodeFlexLayouts on a frame with parent COMMON_VIEW_ETS_TAG.
1489      * @tc.expected:
1490      */
1491     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
1492     child2->MountToParent(child);
1493     node1->tag_ = OHOS::Ace::V2::COMMON_VIEW_ETS_TAG;
1494     childWrapper->AddNodeFlexLayouts();
1495     EXPECT_EQ(child2->GetFlexLayouts(), 0);
1496 
1497     /**
1498      * @tc.steps: step3. call AddNodeFlexLayouts on a frame with parent ROW_FRAME_NODE.
1499      * @tc.expected:
1500      */
1501     node1->tag_ = ROW_FRAME_NODE;
1502     childWrapper->AddNodeFlexLayouts();
1503     EXPECT_EQ(child->GetFlexLayouts(), 0);
1504 }
1505 
1506 /**
1507  * @tc.name: LayoutWrapperTest041
1508  * @tc.desc: Test AdjustChildren.
1509  * @tc.type: FUNC
1510  */
1511 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest041, TestSize.Level1)
1512 {
1513     /**
1514      * @tc.steps: step1. rowFrameNode addChildren .
1515      */
1516     auto rowFrameNode = FrameNode::CreateFrameNode(
1517         OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1518 
1519     auto rowFrameNode1 = FrameNode::CreateFrameNode(
1520         OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_1, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1521     RefPtr<CustomNode> cusNodeTemp = AceType::MakeRefPtr<CustomNode>(NODE_ID_2, OHOS::Ace::V2::FLEX_ETS_TAG);
1522     rowFrameNode->AddChild(cusNodeTemp);
1523     rowFrameNode->AddChild(rowFrameNode1);
1524 
1525     /**
1526      * @tc.steps: step2. create LayoutWrapper.
1527      */
1528     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1529     RefPtr<LayoutWrapperNode> layoutWrapper =
1530         AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1531 
1532     /**
1533      * @tc.steps: step3. Call AdjustChildren().
1534      */
1535     layoutWrapper->AdjustChildren(OffsetF(0, 10), false);
1536     EXPECT_FALSE(rowFrameNode1->GetLayoutProperty()->GetSafeAreaExpandOpts());
1537 }
1538 
1539 /**
1540  * @tc.name: LayoutWrapperTest042
1541  * @tc.desc: Test AvoidKeyboard.
1542  * @tc.type: FUNC
1543  */
1544 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest042, TestSize.Level1)
1545 {
1546     /**
1547      * @tc.steps: step1. create LayoutWrapper.
1548      */
1549     auto node = FrameNode::CreateFrameNode(V2::STAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
1550     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1551     RefPtr<LayoutWrapperNode> layoutWrapper =
1552         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
1553 
1554     /**
1555      * @tc.steps: step2. Call AvoidKeyboard.
1556      * @tc.expected: GetHostTag() != V2::PAGE_ETS_TAG.
1557      */
1558     layoutWrapper->AvoidKeyboard();
1559     EXPECT_NE(layoutWrapper->GetHostTag(), V2::PAGE_ETS_TAG);
1560 }
1561 
1562 /**
1563  * @tc.name: LayoutWrapperTest043
1564  * @tc.desc: Test AvoidKeyboard.
1565  * @tc.type: FUNC
1566  */
1567 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest043, TestSize.Level1)
1568 {
1569     /**
1570      * @tc.steps: step1. create LayoutWrapper.
1571      */
1572     auto node = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
1573     RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
1574     RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1575     focusHub->currentFocus_ = false;
1576     node->focusHub_ = focusHub;
1577     node->eventHub_ = eventHub;
1578 
1579     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1580     RefPtr<LayoutWrapperNode> layoutWrapper =
1581         AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
1582 
1583     /**
1584      * @tc.steps: step2. create safeAreaManager_.
1585      */
1586     RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
1587     safeAreamanager->keyboardOffset_ = -1.0f;
1588 
1589     auto pipeline = PipelineContext::GetCurrentContext();
1590     CHECK_NULL_VOID(pipeline);
1591     pipeline->safeAreaManager_ = safeAreamanager;
1592 
1593     /**
1594      * @tc.steps: step3. Call AvoidKeyboard.
1595      */
1596     layoutWrapper->AvoidKeyboard();
1597     EXPECT_TRUE(node->GetFocusHub());
1598     EXPECT_TRUE(!node->GetFocusHub()->IsCurrentFocus());
1599     EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
1600 }
1601 
1602 /**
1603  * @tc.name: LayoutWrapperTest044
1604  * @tc.desc: Test AddNodeFlexLayouts.
1605  * @tc.type: FUNC
1606  */
1607 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest044, TestSize.Level1)
1608 {
1609     auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1610 
1611     /**
1612      * @tc.steps: step1. call AddNodeFlexLayouts on a frame with parent JS_VIEW_ETS_TAG.
1613      * @tc.expected:
1614      */
1615     auto [node1, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
1616     node1->MountToParent(parent);
1617 
1618     auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
1619     child->MountToParent(node1);
1620     childWrapper->AddNodeFlexLayouts();
1621     EXPECT_EQ(node1->GetFlexLayouts(), 0);
1622 
1623     /**
1624      * @tc.steps: step2. call AddNodeFlexLayouts on a frame with parent COMMON_VIEW_ETS_TAG.
1625      * @tc.expected:
1626      */
1627     auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
1628     child2->MountToParent(child);
1629     node1->tag_ = OHOS::Ace::V2::COMMON_VIEW_ETS_TAG;
1630     childWrapper->AddNodeFlexLayouts();
1631     EXPECT_EQ(child2->GetFlexLayouts(), 0);
1632 
1633     /**
1634      * @tc.steps: step3. call AddNodeFlexLayouts on a frame with parent ROW_FRAME_NODE.
1635      * @tc.expected:
1636      */
1637     node1->tag_ = ROW_FRAME_NODE;
1638     childWrapper->AddNodeFlexLayouts();
1639     EXPECT_EQ(child->GetFlexLayouts(), 0);
1640 }
1641 } // namespace OHOS::Ace::NG
1642