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