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, INT32_MAX);
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 MountToHostOnMainThread.
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. call MountToHostOnMainThread.
1309 * @tc.expected: layoutWrapper->layoutWrapperBuilder_ is null.
1310 */
1311 layoutWrapper->MountToHostOnMainThread();
1312 EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
1313
1314 /**
1315 * @tc.steps: step3. call MountToHostOnMainThread and set layoutWrapper->isActive_ is TEST_TRUE.
1316 * @tc.expected: layoutWrapper->layoutWrapperBuilder_ is null.
1317 */
1318 layoutWrapper->isActive_ = TEST_TRUE;
1319 layoutWrapper->MountToHostOnMainThread();
1320 EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
1321
1322 /**
1323 * @tc.steps: step4. create a testLayoutWrapper pointer and set tag is FIRST_CHILD_FRAME_NODE.
1324 */
1325 auto frameNode = FrameNode::CreateFrameNode(FIRST_CHILD_FRAME_NODE, NODE_ID_1, AceType::MakeRefPtr<Pattern>());
1326 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1327 RefPtr<LayoutWrapperNode> testLayoutWrapper =
1328 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1329
1330 /**
1331 * @tc.steps: step5. call MountToHostOnMainThread.
1332 * @tc.expected: testLayoutWrapper->layoutWrapperBuilder is null.
1333 */
1334 testLayoutWrapper->MountToHostOnMainThread();
1335 EXPECT_EQ(testLayoutWrapper->layoutWrapperBuilder_, nullptr);
1336 }
1337
1338 /**
1339 * @tc.name: LayoutWrapperTest035
1340 * @tc.desc: Test MountToHostOnMainThread.
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest035, TestSize.Level1)
1344 {
1345 /**
1346 * @tc.steps: step1. create a layoutwrapper pointer.
1347 */
1348 auto rowFrameNode =
1349 FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1350 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1351 RefPtr<LayoutWrapperNode> layoutWrapper =
1352 AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1353
1354 /**
1355 * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
1356 */
1357 auto frameNode = FrameNode::CreateFrameNode(FIRST_CHILD_FRAME_NODE, NODE_ID_1, AceType::MakeRefPtr<Pattern>());
1358 RefPtr<LayoutWrapperNode> firstChildLayoutWrapper =
1359 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1360
1361 layoutWrapper->AppendChild(firstChildLayoutWrapper);
1362
1363 /**
1364 * @tc.steps: step3. call MountToHostOnMainThread.
1365 * @tc.expected: layoutWrapper->layoutWrapperBuilder_ is null.
1366 */
1367 layoutWrapper->isActive_ = TEST_TRUE;
1368 layoutWrapper->MountToHostOnMainThread();
1369 EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
1370 }
1371
1372 /**
1373 * @tc.name: LayoutWrapperTest036
1374 * @tc.desc: Test MountToHostOnMainThread.
1375 * @tc.type: FUNC
1376 */
1377 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest036, TestSize.Level1)
1378 {
1379 /**
1380 * @tc.steps: step1. create a layoutwrapper pointer.
1381 */
1382 auto rowFrameNode =
1383 FrameNode::CreateFrameNode(ROW_FRAME_NODE, NODE_ID_0, AceType::MakeRefPtr<LinearLayoutPattern>(false));
1384 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1385 RefPtr<LayoutWrapperNode> layoutWrapper =
1386 AceType::MakeRefPtr<LayoutWrapperNode>(rowFrameNode, geometryNode, rowFrameNode->GetLayoutProperty());
1387
1388 /**
1389 * @tc.steps: step2. create firstChildLayoutWrapper and append it to layoutWrapper.
1390 */
1391 auto frameNode = FrameNode::CreateFrameNode(FIRST_CHILD_FRAME_NODE, NODE_ID_1, AceType::MakeRefPtr<Pattern>());
1392 RefPtr<LayoutWrapperNode> firstChildLayoutWrapper =
1393 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty());
1394
1395 firstChildLayoutWrapper->hostNode_ = nullptr;
1396 layoutWrapper->AppendChild(firstChildLayoutWrapper);
1397
1398 /**
1399 * @tc.steps: step3. call MountToHostOnMainThread.
1400 * @tc.expected: layoutWrapper->layoutWrapperBuilder_ is null.
1401 */
1402 layoutWrapper->MountToHostOnMainThread();
1403 EXPECT_EQ(layoutWrapper->layoutWrapperBuilder_, nullptr);
1404
1405 /**
1406 * @tc.steps: step4. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
1407 */
1408 RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
1409 layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
1410
1411 /**
1412 * @tc.steps: step5. call MountToHostOnMainThread.
1413 * @tc.expected: layoutWrapper->layoutWrapperBuilder_ is not null.
1414 */
1415 layoutWrapper->isActive_ = TEST_TRUE;
1416
1417 layoutWrapper->MountToHostOnMainThread();
1418 ASSERT_NE(layoutWrapper->layoutWrapperBuilder_, nullptr);
1419 }
1420
1421 /**
1422 * @tc.name: LayoutWrapperTest037
1423 * @tc.desc: Test BuildLazyItem.
1424 * @tc.type: FUNC
1425 */
1426 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest037, TestSize.Level1)
1427 {
1428 /**
1429 * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1430 */
1431 RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1432
1433 /**
1434 * @tc.steps: step2. set layoutWrapper->lazyBuildFunction_ is not null.
1435 */
__anon1d37e74c0202(RefPtr<LayoutWrapperNode> testLayoutWrapper) 1436 auto lazyBuildFunction = [](RefPtr<LayoutWrapperNode> testLayoutWrapper) { testLayoutWrapper = nullptr; };
1437 layoutWrapper->lazyBuildFunction_ = lazyBuildFunction;
1438
1439 /**
1440 * @tc.steps: step3. call GetLazyBuildRange.
1441 * @tc.expected: the return retRange.first is -1 and retRange.second is 0.
1442 */
1443 layoutWrapper->BuildLazyItem();
1444 EXPECT_EQ(layoutWrapper->lazyBuildFunction_, nullptr);
1445 }
1446
1447 /**
1448 * @tc.name: LayoutWrapperTest038
1449 * @tc.desc: Test GetLazyBuildRange.
1450 * @tc.type: FUNC
1451 */
1452 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest038, TestSize.Level1)
1453 {
1454 /**
1455 * @tc.steps: step1. call CreateLayoutWrapper create a layoutwrapper pointer.
1456 */
1457 RefPtr<LayoutWrapperNode> layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1458
1459 /**
1460 * @tc.steps: step2. call GetLazyBuildRange.
1461 * @tc.expected: the return value is the same as RANGE.
1462 */
1463 std::pair<int32_t, int32_t> retRange = layoutWrapper->GetLazyBuildRange();
1464 EXPECT_EQ(retRange, RANGE);
1465
1466 /**
1467 * @tc.steps: step3. create wrapperBuilder and set it to layoutWrapper->layoutWrapperBuilder_.
1468 */
1469 RefPtr<LazyLayoutWrapperBuilder> wrapperBuilder = CreateLayoutWrapperBuilder();
1470 layoutWrapper->layoutWrapperBuilder_ = wrapperBuilder;
1471
1472 /**
1473 * @tc.steps: step4. call GetLazyBuildRange.
1474 * @tc.expected: the return value is the same as RANGE_0.
1475 */
1476 retRange = layoutWrapper->GetLazyBuildRange();
1477 EXPECT_EQ(retRange, RANGE_0);
1478 }
1479
1480 /**
1481 * @tc.name: LayoutWrapperTest039
1482 * @tc.desc: Test Apply SafeArea constraint for Popup nodes.
1483 * @tc.type: FUNC
1484 */
1485 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest039, TestSize.Level1)
1486 {
1487 auto [parentHost, parent] = CreateNodeAndWrapper(V2::ROOT_ETS_TAG, 0);
1488 auto [stageHost, stage] = CreateNodeAndWrapper(V2::STAGE_ETS_TAG, 1);
1489 auto [popupHost, popup] = CreateNodeAndWrapper(V2::MENU_WRAPPER_ETS_TAG, 2);
1490 parentHost->AddChild(stageHost);
1491 parentHost->AddChild(popupHost);
1492 popupHost->layoutProperty_->UpdateSafeAreaInsets(SafeAreaInsets({}, { 0, 1 }, {}, {}));
1493
1494 LayoutConstraintF constraint;
1495 UpdateParentConstraint(parent, constraint);
1496 stage->ApplyConstraint(constraint);
1497 popup->ApplyConstraint(constraint);
1498
1499 EXPECT_EQ(stage->layoutProperty_->layoutConstraint_, constraint);
1500 // popup is restricted by safeArea
1501 EXPECT_EQ(popup->geometryNode_->parentLayoutConstraint_, constraint);
1502 EXPECT_TRUE(popup->layoutProperty_->layoutConstraint_);
1503 EXPECT_NE(popup->layoutProperty_->layoutConstraint_, constraint);
1504 }
1505
1506 /**
1507 * @tc.name: LayoutWrapperTest042
1508 * @tc.desc: Test OffsetNodeToSafeArea.
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest042, TestSize.Level1)
1512 {
1513 auto layoutWrapper = CreateLayoutWrapper(ROW_FRAME_NODE, NODE_ID_0);
1514 layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1515 SafeAreaInsets({}, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
1516 layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT - 2 });
1517
1518 layoutWrapper->geometryNode_->SetFrameOffset({ 0, 1 });
1519 layoutWrapper->OffsetNodeToSafeArea();
1520 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1521
1522 layoutWrapper->geometryNode_->SetFrameOffset({ 0, 5 });
1523 layoutWrapper->OffsetNodeToSafeArea();
1524 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1525
1526 layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
1527 layoutWrapper->OffsetNodeToSafeArea();
1528 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1529
1530 layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1531 SafeAreaInsets({ 0, 5 }, { 0, 1 }, {}, { RK356_HEIGHT - 1, RK356_HEIGHT }));
1532 layoutWrapper->geometryNode_->SetFrameOffset({ 0, 0 });
1533 layoutWrapper->OffsetNodeToSafeArea();
1534 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset(), OffsetF(0, 1));
1535
1536 // set right and bottom again
1537 layoutWrapper->geometryNode_->SetFrameOffset({ 1, 1 });
1538 layoutWrapper->layoutProperty_->UpdateSafeAreaInsets(
1539 SafeAreaInsets({ 0, 0 }, { 0, 0 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }, { RK356_HEIGHT, RK356_HEIGHT + 1 }));
1540 layoutWrapper->OffsetNodeToSafeArea();
1541 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().x_, 1);
1542 EXPECT_EQ(layoutWrapper->geometryNode_->GetFrameOffset().y_, 1);
1543 }
1544
1545 /**
1546 * @tc.name: LayoutWrapperTest043
1547 * @tc.desc: Test ExpandIntoKeyboard.
1548 * @tc.type: FUNC
1549 */
1550 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest043, TestSize.Level1)
1551 {
1552 auto [parent, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
1553 layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
1554
1555 auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_1);
1556 child->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_ALL, SAFE_AREA_EDGE_ALL });
1557 child->MountToParent(parent);
1558
1559 auto safeAreaManager = PipelineContext::GetCurrentContext()->safeAreaManager_;
1560 // ExpandIntoKeyboard(): use page offset judge if expandIntoKeyboard
1561 // no page node, return OffsetF(0, 0)
1562 safeAreaManager->UpdateKeyboardOffset(50.0f);
1563 EXPECT_EQ(parent->ExpandIntoKeyboard(), OffsetF(0, 0));
1564
1565 // parent already expanded
1566 child->ExpandIntoKeyboard();
1567 EXPECT_EQ(child->ExpandIntoKeyboard(), OffsetF(0, 0));
1568
1569 layoutWrapper->layoutProperty_->UpdateSafeAreaExpandOpts({ SAFE_AREA_TYPE_NONE, SAFE_AREA_EDGE_ALL });
1570 child->ExpandIntoKeyboard();
1571 // no page node, return OffsetF(0, 0)
1572 EXPECT_EQ(child->ExpandIntoKeyboard(), OffsetF(0, 0));
1573 }
1574
1575 /**
1576 * @tc.name: LayoutWrapperTest044
1577 * @tc.desc: Test AvoidKeyboard.
1578 * @tc.type: FUNC
1579 */
1580 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest044, TestSize.Level1)
1581 {
1582 auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::PAGE_ETS_TAG, NODE_ID_0);
1583 layoutWrapper->AvoidKeyboard();
1584 string ret = "";
1585 EXPECT_EQ(ret, "");
1586 }
1587
1588 /**
1589 * @tc.name: LayoutWrapperTest045
1590 * @tc.desc: Test CreateRootConstraint.
1591 * @tc.type: FUNC
1592 */
1593 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest045, TestSize.Level1)
1594 {
1595 auto context = PipelineContext::GetCurrentContext();
1596 context->rootHeight_ = RK356_HEIGHT;
1597 context->rootWidth_ = RK356_WIDTH;
1598
1599 auto [node, layoutWrapper] = CreateNodeAndWrapper(ROW_FRAME_NODE, NODE_ID_0);
1600 layoutWrapper->geometryNode_->SetFrameSize({ RK356_WIDTH, RK356_HEIGHT });
1601 layoutWrapper->layoutProperty_->UpdateAspectRatio(2.0);
1602 layoutWrapper->CreateRootConstraint();
1603 EXPECT_EQ(layoutWrapper->layoutProperty_->layoutConstraint_->percentReference.Height(), RK356_HEIGHT / 2);
1604 }
1605
1606 /**
1607 * @tc.name: LayoutWrapperTest046
1608 * @tc.desc: Test AvoidKeyboard.
1609 * @tc.type: FUNC
1610 */
1611 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest046, TestSize.Level1)
1612 {
1613 auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1614
1615 /**
1616 * @tc.steps: step1. call AddNodeFlexLayouts on a frame with parent JS_VIEW_ETS_TAG.
1617 * @tc.expected:
1618 */
1619 auto [node1, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
1620 node1->MountToParent(parent);
1621
1622 auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
1623 child->MountToParent(node1);
1624 childWrapper->AddNodeFlexLayouts();
1625 EXPECT_EQ(node1->GetFlexLayouts(), 0);
1626
1627 /**
1628 * @tc.steps: step2. call AddNodeFlexLayouts on a frame with parent COMMON_VIEW_ETS_TAG.
1629 * @tc.expected:
1630 */
1631 auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
1632 child2->MountToParent(child);
1633 node1->tag_ = OHOS::Ace::V2::COMMON_VIEW_ETS_TAG;
1634 childWrapper->AddNodeFlexLayouts();
1635 EXPECT_EQ(child2->GetFlexLayouts(), 0);
1636
1637 /**
1638 * @tc.steps: step3. call AddNodeFlexLayouts on a frame with parent ROW_FRAME_NODE.
1639 * @tc.expected:
1640 */
1641 node1->tag_ = ROW_FRAME_NODE;
1642 childWrapper->AddNodeFlexLayouts();
1643 EXPECT_EQ(child->GetFlexLayouts(), 0);
1644 }
1645
1646 /**
1647 * @tc.name: LayoutWrapperTest049
1648 * @tc.desc: Test AvoidKeyboard.
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest049, TestSize.Level1)
1652 {
1653 /**
1654 * @tc.steps: step1. create LayoutWrapper.
1655 */
1656 auto node = FrameNode::CreateFrameNode(V2::STAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
1657 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1658 RefPtr<LayoutWrapperNode> layoutWrapper =
1659 AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
1660
1661 /**
1662 * @tc.steps: step2. Call AvoidKeyboard.
1663 * @tc.expected: GetHostTag() != V2::PAGE_ETS_TAG.
1664 */
1665 layoutWrapper->AvoidKeyboard();
1666 EXPECT_NE(layoutWrapper->GetHostTag(), V2::PAGE_ETS_TAG);
1667 }
1668
1669 /**
1670 * @tc.name: LayoutWrapperTest050
1671 * @tc.desc: Test AvoidKeyboard.
1672 * @tc.type: FUNC
1673 */
1674 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest050, TestSize.Level1)
1675 {
1676 /**
1677 * @tc.steps: step1. create LayoutWrapper.
1678 */
1679 auto node = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, NODE_ID_0, AceType::MakeRefPtr<Pattern>());
1680 RefPtr<EventHub> eventHub = AceType::MakeRefPtr<EventHub>();
1681 RefPtr<FocusHub> focusHub = AceType::MakeRefPtr<FocusHub>(eventHub);
1682 focusHub->currentFocus_ = false;
1683 eventHub->focusHub_ = focusHub;
1684 node->eventHub_ = eventHub;
1685
1686 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1687 RefPtr<LayoutWrapperNode> layoutWrapper =
1688 AceType::MakeRefPtr<LayoutWrapperNode>(node, geometryNode, node->GetLayoutProperty());
1689
1690 /**
1691 * @tc.steps: step2. create safeAreaManager_.
1692 */
1693 RefPtr<SafeAreaManager> safeAreamanager = AceType::MakeRefPtr<SafeAreaManager>();
1694 safeAreamanager->keyboardOffset_ = -1.0f;
1695
1696 auto pipeline = PipelineContext::GetCurrentContext();
1697 CHECK_NULL_VOID(pipeline);
1698 pipeline->safeAreaManager_ = safeAreamanager;
1699
1700 /**
1701 * @tc.steps: step3. Call AvoidKeyboard.
1702 */
1703 layoutWrapper->AvoidKeyboard();
1704 EXPECT_TRUE(node->GetFocusHub());
1705 EXPECT_TRUE(!node->GetFocusHub()->IsCurrentFocus());
1706 EXPECT_TRUE(LessNotEqual(safeAreamanager->GetKeyboardOffset(), 0.0));
1707 }
1708
1709 /**
1710 * @tc.name: LayoutWrapperTest051
1711 * @tc.desc: Test AddNodeFlexLayouts.
1712 * @tc.type: FUNC
1713 */
1714 HWTEST_F(LayoutWrapperTestNg, LayoutWrapperTest051, TestSize.Level1)
1715 {
1716 auto [parent, layoutWrapper] = CreateNodeAndWrapper(OHOS::Ace::V2::FLEX_ETS_TAG, NODE_ID_0);
1717
1718 /**
1719 * @tc.steps: step1. call AddNodeFlexLayouts on a frame with parent JS_VIEW_ETS_TAG.
1720 * @tc.expected:
1721 */
1722 auto [node1, nodeLayoutWrapper1] = CreateNodeAndWrapper(OHOS::Ace::V2::JS_VIEW_ETS_TAG, NODE_ID_1);
1723 node1->MountToParent(parent);
1724
1725 auto [child, childWrapper] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_2);
1726 child->MountToParent(node1);
1727 childWrapper->AddNodeFlexLayouts();
1728 EXPECT_EQ(node1->GetFlexLayouts(), 0);
1729
1730 /**
1731 * @tc.steps: step2. call AddNodeFlexLayouts on a frame with parent COMMON_VIEW_ETS_TAG.
1732 * @tc.expected:
1733 */
1734 auto [child2, childWrapper2] = CreateNodeAndWrapper(FIRST_CHILD_FRAME_NODE, NODE_ID_3);
1735 child2->MountToParent(child);
1736 node1->tag_ = OHOS::Ace::V2::COMMON_VIEW_ETS_TAG;
1737 childWrapper->AddNodeFlexLayouts();
1738 EXPECT_EQ(child2->GetFlexLayouts(), 0);
1739
1740 /**
1741 * @tc.steps: step3. call AddNodeFlexLayouts on a frame with parent ROW_FRAME_NODE.
1742 * @tc.expected:
1743 */
1744 node1->tag_ = ROW_FRAME_NODE;
1745 childWrapper->AddNodeFlexLayouts();
1746 EXPECT_EQ(child->GetFlexLayouts(), 0);
1747 }
1748 } // namespace OHOS::Ace::NG
1749