1 /*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "test/unittest/core/base/frame_node_test_ng.h"
16 #include "gtest/gtest.h"
17 #include "core/components_ng/pattern/marquee/marquee_paint_property.h"
18 #include "core/components_ng/pattern/text/text_pattern.h"
19 #include "core/components_ng/pattern/stack/stack_pattern.h"
20 #include "interfaces/inner_api/ace_kit/src/view/frame_node_impl.h"
21 #include "core/components_ng/pattern/linear_layout/column_model_ng.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS::Ace::NG {
SetUpTestSuite()27 void FrameNodeTestNg::SetUpTestSuite()
28 {
29 MockPipelineContext::SetUp();
30 }
31
TearDownTestSuite()32 void FrameNodeTestNg::TearDownTestSuite()
33 {
34 MockPipelineContext::TearDown();
35 }
36
37 class TestAICaller : public AICallerHelper {
38 public:
39 TestAICaller() = default;
40 ~TestAICaller() override = default;
onAIFunctionCaller(const std::string & funcName,const std::string & params)41 bool onAIFunctionCaller(const std::string& funcName, const std::string& params) override
42 {
43 if (funcName.compare("Success") == 0) {
44 return true;
45 }
46 return false;
47 }
48 };
49
50 /**
51 * @tc.name: FrameNodeTestNg001
52 * @tc.desc: Test frame node method
53 * @tc.type: FUNC
54 */
55 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg001, TestSize.Level1)
56 {
__anon943640bd0102() 57 auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
58 auto two = FrameNode::GetFrameNode("two", 1);
59 EXPECT_NE(one, nullptr);
60 EXPECT_EQ(two, nullptr);
61
62 /**
63 * @tc.steps: step2. create FrameNode and set a callback
64 * @tc.expect: call DestroyCallback while object is destroyed
65 */
66 bool flag = false;
67 auto three = FrameNode::GetOrCreateFrameNode("one", 1, nullptr);
68 ASSERT_NE(three, nullptr);
__anon943640bd0202() 69 three->PushDestroyCallbackWithTag([&flag]() { flag = !flag; }, "");
70 three = nullptr;
71 EXPECT_TRUE(flag);
72 }
73
74 /**
75 * @tc.name: FrameNodeTestNg002
76 * @tc.desc: Test frame node method
77 * @tc.type: FUNC
78 */
79 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg002, TestSize.Level1)
80 {
__anon943640bd0302() 81 auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
82 one->SetParent(FRAME_NODE_PARENT);
83 auto two = FrameNode::GetFrameNode("two", 1);
84 EXPECT_NE(one, nullptr);
85 EXPECT_EQ(two, nullptr);
86 ElementRegister::GetInstance()->Clear();
87 }
88
89 /**
90 * @tc.name: FrameNodeTestNg004
91 * @tc.desc: Test frame node method
92 * @tc.type: FUNC
93 */
94 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg004, TestSize.Level1)
95 {
96 /**
97 * @tc.steps: step1. create framenode and initialize the params used in Test.
98 */
99 auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
100 node->AttachToMainTree();
101 node->GetRenderContext()->RequestNextFrame();
102 EXPECT_TRUE(node->IsOnMainTree());
103
104 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
105 const RefPtr<FrameNode> parentNode =
106 FrameNode::CreateFrameNode("RelativeContainer", nodeId, AceType::MakeRefPtr<Pattern>(), true);
107 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
108
109 /**
110 * @tc.steps: step2. call OnInspectorIdUpdate .
111 * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
112 * this parentNode is not MarkDirtyNode
113 */
114 node->OnInspectorIdUpdate("RelativeContainer");
115 EXPECT_EQ(parentNode->GetTag(), "RelativeContainer");
116 }
117
118 /**
119 * @tc.name: FrameNodeTestNg007
120 * @tc.desc: Test frame node method
121 * @tc.type: FUNC
122 */
123 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg007, TestSize.Level1)
124 {
125 /**
126 * @tc.steps: step 1. create framenode and initialize the params used in Test.
127 */
128 auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
129
130 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
131 const RefPtr<FrameNode> parentNode =
132 FrameNode::CreateFrameNode("parent", nodeId, AceType::MakeRefPtr<Pattern>(), true);
133 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
134
135 const RefPtr<FrameNode> overlayNode =
136 FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
137
138 /**
139 * @tc.steps: step 2. call OnInspectorIdUpdate .
140 * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
141 * this parentNode is not MarkDirtyNode
142 */
143
144 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
145 node->OnInspectorIdUpdate("RelativeContainer");
146 EXPECT_EQ(parentNode->GetTag(), "parent");
147
148 /**
149 * @tc.steps: step 3. call LayoutOverlay .
150 * @tc.expect: FrameRect of overlayNode is 0.
151 */
152 node->SetOverlayNode(overlayNode);
153 node->LayoutOverlay();
154
155 auto layoutProperty = overlayNode->GetLayoutProperty();
156 layoutProperty->positionProperty_ = std::make_unique<PositionProperty>();
157 node->LayoutOverlay();
158 EXPECT_EQ(overlayNode->GetGeometryNode()->GetFrameRect().GetX(), 0);
159
160 /**
161 * @tc.steps: step 4. call GetFrameChildByIndex .
162 * @tc.expect: index == 0 return uiNode, index != 0 return null
163 */
164 EXPECT_TRUE(node->GetFrameChildByIndex(0, false));
165 EXPECT_FALSE(node->GetFrameChildByIndex(1, false));
166
167 /**
168 * @tc.steps: step 5. call GetBaselineDistance .
169 * @tc.expect: node has not child return 0. if node has child return childBaseline of child
170 */
171 EXPECT_EQ(node->GetBaselineDistance(), 0);
172 node->AddChild(FRAME_NODE);
173 EXPECT_EQ(node->GetBaselineDistance(), 0);
174 auto nodeLayoutProperty = node->GetLayoutProperty();
175 nodeLayoutProperty->geometryTransition_ =
176 ElementRegister::GetInstance()->GetOrCreateGeometryTransition("test", false, true);
177 node->Layout();
178 EXPECT_FALSE(node->IsRootMeasureNode());
179 node->SetRootMeasureNode();
180 node->Layout();
181 EXPECT_TRUE(node->IsRootMeasureNode());
182 }
183
184 /**
185 * @tc.name: FrameNodeTestNg008
186 * @tc.desc: Test frame node method
187 * @tc.type: FUNC
188 */
189 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg008, TestSize.Level1)
190 {
191 /**
192 * @tc.steps: step 1. create framenode and initialize the params used in Test.
193 */
194 RefPtr<NG::DrawModifier> drawModifier = AceType::MakeRefPtr<NG::DrawModifier>();
195 ASSERT_NE(drawModifier, nullptr);
196
197 /**
198 * @tc.steps: step 2. call get function .
199 * @tc.expect: expect the return value to be correct.
200 */
201 EXPECT_TRUE(FRAME_NODE->IsSupportDrawModifier());
202
203 /**
204 * @tc.steps: step 3. call GetContentModifier when drawModifier is null.
205 * @tc.expect: expect the return value to be correct.
206 */
207 EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
208
209 /**
210 * @tc.steps: step 4. Nodes created by virtual classes, call GetContentModifier when drawModifier is null.
211 * @tc.expect: expect the return value to be correct.
212 */
213 FRAME_NODE->SetDrawModifier(drawModifier);
214 EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
215
216 /**
217 * @tc.steps: step 5. Nodes created by virtual classes, call SetRemoveCustomProperties.
218 * @tc.expect: expect call successfully.
219 */
__anon943640bd0402() 220 FRAME_NODE->SetRemoveCustomProperties([]() -> void {});
221 }
222
223 /**
224 * @tc.name: FrameNodeTouchTest001
225 * @tc.desc: Test frame node method
226 * @tc.type: FUNC
227 */
228 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest, TestSize.Level1)
229 {
230 /**
231 * @tc.steps: step1. create framenode and initialize the params used in Test.
232 */
233 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
234 node->AttachToMainTree();
235 node->GetOrCreateGestureEventHub();
236 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
237 node->renderContext_ = mockRenderContext;
238 node->SetActive(true);
239 auto localPoint = PointF(10, 10);
240 auto parentLocalPoint = PointF(10, 10);
241 const NG::PointF point { 10, 10 };
242 const PointF parentLocalPointOne = { 10, 10 };
243 TouchRestrict touchRestrict = { TouchRestrict::NONE };
244 auto globalPoint = PointF(10, 10);
245 auto touchTestResult = std::list<RefPtr<TouchEventTarget>>();
246 ResponseLinkResult responseLinkResult;
247
248 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
249 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
250
251 /**
252 * @tc.steps: step2. create childnode
253 */
254 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true);
255 childNode->SetExclusiveEventForChild(true);
256 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>();
257 childNode->renderContext_ = mockRenderContextforChild;
258 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
259 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
260 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
261 childNode->GetOrCreateGestureEventHub();
262 childNode->SetActive(true);
263 auto childEventHub = childNode->GetOrCreateGestureEventHub();
264
265 /**
266 * @tc.steps: step3. add childnode to the framenode
267 */
268 std::list<RefPtr<FrameNode>> children;
269 children.push_back(childNode);
270 node->frameChildren_ = { children.begin(), children.end() };
271
272 /**
273 * @tc.steps: step4. create grandChildNode
274 */
275
276 auto grandChildNode = FrameNode::CreateFrameNode("main", 3, AceType::MakeRefPtr<Pattern>(), true);
277 grandChildNode->SetExclusiveEventForChild(true);
278 grandChildNode->renderContext_ = mockRenderContextforChild;
279 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
280 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
281 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
282 grandChildNode->GetOrCreateGestureEventHub();
283 grandChildNode->SetActive(true);
284 auto grandChildEventHub = grandChildNode->GetOrCreateGestureEventHub();
285
286 /**
287 * @tc.steps: step5. add grandChildNode to the childnode
288 */
289 std::list<RefPtr<FrameNode>> grandChild;
290 grandChild.push_back(grandChildNode);
291 childNode->frameChildren_ = { grandChild.begin(), grandChild.end() };
292
293 /**
294 * @tc.steps: step6. compare hitTestResult which is retured in function TouchTest whith expected value.
295 * @tc.expected: step6. hitTestResult is STOP_BUBBLING when hitTestModeofGrandChilds or hitTestModeofChild is
296 * HTMBLOCK;
297 */
298 HitTestMode hitTestModeofGrandChilds[] = { HitTestMode::HTMBLOCK, HitTestMode::HTMDEFAULT };
299 HitTestMode hitTestModeofChilds[] = { HitTestMode::HTMDEFAULT, HitTestMode::HTMBLOCK, HitTestMode::HTMTRANSPARENT,
300 HitTestMode::HTMNONE, HitTestMode::HTMTRANSPARENT_SELF };
301 bool isStacks[] = { true, false };
302
303 for (auto hitTestModeofGrandChild : hitTestModeofGrandChilds) {
304 grandChildEventHub->SetHitTestMode(hitTestModeofGrandChild);
305 for (auto isStack : isStacks) {
306 for (auto hitTestModeofChild : hitTestModeofChilds) {
307 childNode->SetExclusiveEventForChild(isStack);
308 childEventHub->SetHitTestMode(hitTestModeofChild);
309 auto result = childNode->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
310 touchTestResult, 0, responseLinkResult, true);
311 result = node->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
312 touchTestResult, 0, responseLinkResult, true);
313 }
314 }
315 }
316 }
317
318 /**
319 * @tc.name: FrameNodeTestNg005
320 * @tc.desc: Test frame node method
321 * @tc.type: FUNC
322 */
323 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg005, TestSize.Level1)
324 {
325 /**
326 * @tc.steps: step1. callback function.
327 * @tc.expected: expect The function is run ok.
328 */
329 auto one = FrameNode::CreateFrameNodeWithTree("main", 10, AceType::MakeRefPtr<Pattern>());
330 EXPECT_NE(one, nullptr);
331
332 MeasureProperty calcLayoutConstraint;
333 FRAME_NODE->UpdateLayoutConstraint(std::move(calcLayoutConstraint));
334 EXPECT_EQ(FRAME_NODE2->layoutProperty_->propertyChangeFlag_, 1);
335
336 FRAME_NODE2->needSyncRenderTree_ = true;
337 FRAME_NODE2->RebuildRenderContextTree();
338 EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
339
340 /**
341 * @tc.steps: step 2. create and set overlayNode.
342 * @tc.expect:cover branch overlayNode is not null and function is run ok.
343 */
344 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
345 const RefPtr<FrameNode> overlayNode =
346 FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
347 FRAME_NODE2->SetOverlayNode(overlayNode);
348 FRAME_NODE2->RebuildRenderContextTree();
349 EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
350
351 FRAME_NODE2->OnMountToParentDone();
352
353 FRAME_NODE2->FlushUpdateAndMarkDirty();
354
355 std::list<RefPtr<FrameNode>> visibleList;
356 FRAME_NODE2->isActive_ = true;
357 FRAME_NODE2->OnGenerateOneDepthVisibleFrame(visibleList);
358 EXPECT_TRUE(FRAME_NODE2->IsVisible());
359
360 FRAME_NODE2->OnGenerateOneDepthAllFrame(visibleList);
361 EXPECT_EQ(visibleList.size(), 2);
362
363 auto pattern = FRAME_NODE2->GetPattern();
364 EXPECT_EQ(pattern, 1);
365
366 auto atomicNode = FRAME_NODE2->IsAtomicNode();
367 EXPECT_TRUE(atomicNode);
368
369 auto hitTestMode = FRAME_NODE2->GetHitTestMode();
370 EXPECT_EQ(hitTestMode, HitTestMode::HTMDEFAULT);
371
372 auto touchable = FRAME_NODE2->GetTouchable();
373 EXPECT_TRUE(touchable);
374
375 const PointF globalPoint;
376 const PointF parentLocalPoint;
377 MouseTestResult onMouseResult;
378 MouseTestResult onHoverResult;
379 RefPtr<FrameNode> hoverNode;
380 auto mouse = FRAME_NODE2->MouseTest(globalPoint, parentLocalPoint, onMouseResult, onHoverResult, hoverNode);
381 EXPECT_EQ(mouse, HitTestResult::BUBBLING);
382 }
383
384 /**
385 * @tc.name: FrameNodeTestNg006
386 * @tc.desc: Test frame node method
387 * @tc.type: FUNC
388 */
389 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg006, TestSize.Level1)
390 {
391 /**
392 * @tc.steps: step1. callback function.
393 * @tc.expected: expect The function is run ok.
394 */
395 FRAME_NODE2->OnWindowShow();
396 FRAME_NODE2->OnWindowHide();
397 FRAME_NODE2->OnWindowFocused();
398 FRAME_NODE2->OnWindowUnfocused();
399 FRAME_NODE2->OnWindowSizeChanged(1, 1, WindowSizeChangeReason::CUSTOM_ANIMATION);
400
401 OffsetF Offset = { 0, 0 };
402 FRAME_NODE2->SetParent(FRAME_NODE3);
403 auto relativeOffset = FRAME_NODE2->GetTransformRelativeOffset();
404 EXPECT_EQ(relativeOffset, Offset);
405
406 FRAME_NODE2->SetParent(FRAME_NODE3);
407 auto rectOffset = FRAME_NODE2->GetPaintRectOffset(true);
408 EXPECT_EQ(rectOffset, Offset);
409
410 FRAME_NODE2->OnNotifyMemoryLevel(true);
411
412 auto childrenCount = FRAME_NODE2->GetAllDepthChildrenCount();
413 EXPECT_EQ(childrenCount, 1);
414
415 DimensionRect dimensionRect;
416 FRAME_NODE2->AddHotZoneRect(dimensionRect);
417 FRAME_NODE2->RemoveLastHotZoneRect();
418 EXPECT_NE(FRAME_NODE2->GetOrCreateEventHub<EventHub>(), nullptr);
419
420 FRAME_NODE->ProcessOffscreenNode(FRAME_NODE3);
421 FRAME_NODE->GetTransformRectRelativeToWindow();
422 FRAME_NODE->GetPaintRectOffsetToPage();
423
424 float x = 1.0;
425 float y = 1.0;
426 auto Position = FRAME_NODE->FindChildByPosition(x, y);
427 EXPECT_EQ(Position, nullptr);
428
429 FRAME_NODE->ProvideRestoreInfo();
430 auto immediately = FRAME_NODE->RemoveImmediately();
431 EXPECT_TRUE(immediately);
432 }
433
434 /**
435 * @tc.name: FrameNodeTestNg_DumpInfo006
436 * @tc.desc: Test frame node method
437 * @tc.type: FUNC
438 */
439 HWTEST_F(FrameNodeTestNg, FrameNodeDumpInfo006, TestSize.Level1)
440 {
441 /**
442 * @tc.steps: step1. callback DumpInfo
443 * @tc.expected: expect The function is run ok.
444 */
445 LayoutProperty layoutProperty;
446 FRAME_NODE->DumpInfo();
447
448 FRAME_NODE->layoutProperty_->UpdatePadding(PaddingPropertyT<CalcLength>());
449 FRAME_NODE->layoutProperty_->GetPaddingProperty();
450 FRAME_NODE->DumpInfo();
451 EXPECT_EQ(layoutProperty.padding_, nullptr);
452
453 FRAME_NODE->layoutProperty_->UpdateMargin(PaddingProperty());
454 FRAME_NODE->layoutProperty_->GetMarginProperty();
455 FRAME_NODE->DumpInfo();
456 EXPECT_EQ(layoutProperty.margin_, nullptr);
457
458 FRAME_NODE->layoutProperty_->UpdateBorderWidth(BorderWidthPropertyT<Dimension>());
459 FRAME_NODE->layoutProperty_->GetBorderWidthProperty();
460 FRAME_NODE->DumpInfo();
461 EXPECT_EQ(layoutProperty.borderWidth_, nullptr);
462
463 /**
464 * @tc.steps: step2. set layoutConstraintF_ an geometryNode_'sParentLayoutConstraint
465 and call DumpInfo
466 * @tc.expected: expect The function is run ok.
467 */
468 FRAME_NODE->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
469 auto layoutConstraintF_ = LayoutConstraintF();
470 FRAME_NODE->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
471 FRAME_NODE->DumpInfo();
472 EXPECT_EQ(layoutProperty.calcLayoutConstraint_, nullptr);
473 }
474
475 /**
476 * @tc.name: FrameNodeTestNg_ToJsonValue007
477 * @tc.desc: Test frame node method
478 * @tc.type: FUNC
479 */
480 HWTEST_F(FrameNodeTestNg, FrameNodeToJsonValue007, TestSize.Level1)
481 {
482 /**
483 * @tc.steps: step1. build a object to jsonValue
484 * @tc.expected: expect The function is run ok.
485 */
486 auto gestureEventHub = FRAME_NODE->GetOrCreateGestureEventHub();
487
488 std::vector<DimensionRect> responseRegion;
489 responseRegion.push_back(DimensionRect());
490 gestureEventHub->SetResponseRegion(responseRegion);
491
492 auto jsonValue = JsonUtil::Create(true);
493 FRAME_NODE->ToJsonValue(jsonValue, filter);
494 EXPECT_TRUE(jsonValue);
495
496 /**
497 * @tc.steps: step2. build a object to jsonValue and call FromJson
498 * @tc.expected: expect The function is run ok.
499 */
500 FRAME_NODE->FromJson(jsonValue);
501 FRAME_NODE->renderContext_ = nullptr;
502 FRAME_NODE->focusHub_ = nullptr;
503 auto jsonValue2 = JsonUtil::Create(true);
504 FRAME_NODE->ToJsonValue(jsonValue2, filter);
505 FRAME_NODE->FromJson(jsonValue2);
506 EXPECT_TRUE(jsonValue2);
507 }
508
509 /**
510 * @tc.name: FrameNodeTestNg_OnAttachToMainTree008
511 * @tc.desc: Test frame node method
512 * @tc.type: FUNC
513 */
514 HWTEST_F(FrameNodeTestNg, FrameNodeOnAttachToMainTree008, TestSize.Level1)
515 {
516 /**
517 * @tc.steps: step1. build a object to OnAttachToMainTree
518 * @tc.expected: expect The function is run ok.
519 */
520 FRAME_NODE2->OnAttachToMainTree(true);
521
522 auto request = FRAME_NODE2->hasPendingRequest_ = true;
523 FRAME_NODE2->OnAttachToMainTree(true);
524 EXPECT_TRUE(request);
525
526 /**
527 * @tc.steps: step2 set PositionProperty of FRAME_NODE2 and call OnAttachToMainTree
528 * @tc.expected: expect The function is run ok.
529 */
530 auto& posProperty = FRAME_NODE2->renderContext_->GetOrCreatePositionProperty();
531 posProperty->UpdateOffset(OffsetT<Dimension>()); // OffsetT<Dimension>
532 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
533 auto testNode_ = TestNode::CreateTestNode(100);
534 FRAME_NODE_PARENT->SetParent(testNode_);
535 FRAME_NODE2->OnAttachToMainTree(true);
536 EXPECT_TRUE(request);
537 }
538
539 /**
540 * @tc.name: FrameNodeTestNg_NotifyVisibleChange009
541 * @tc.desc: Test frame node method
542 * @tc.type: FUNC
543 */
544 HWTEST_F(FrameNodeTestNg, FrameNodeNotifyVisibleChange009, TestSize.Level1)
545 {
546 /**
547 * @tc.steps: step1. build a object to NotifyVisibleChange
548 * @tc.expected: expect The FRAME_NODE2 is not nullptr.
549 */
550 FRAME_NODE2->AddChild(FRAME_NODE3);
551 FRAME_NODE2->NotifyVisibleChange(VisibleType::VISIBLE, VisibleType::INVISIBLE);
552 FRAME_NODE2->Clean();
553 EXPECT_NE(FRAME_NODE2, nullptr);
554 }
555
556 /**
557 * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread0010
558 * @tc.desc: Test frame node method
559 * @tc.type: FUNC
560 */
561 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirtyLayoutWrapperOnMainThread0010, TestSize.Level1)
562 {
563 /**
564 * @tc.steps: step1. build a object to SwapDirtyLayoutWrapperOnMainThread
565 */
566 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
567
568 /**
569 * @tc.steps: step2. callback SwapDirtyLayoutWrapperOnMainThread
570 * @tc.expected: expect layoutWrapper is not nullptr.
571 */
572 FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
573 EXPECT_NE(layoutWrapper, nullptr);
574 layoutWrapper->SetActive(true);
575 auto test = FRAME_NODE2->IsActive();
576
577 /**
578 * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
579 * @tc.expected: expect isActive_ is false.
580 */
581 FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
582 EXPECT_TRUE(test);
583 }
584
585 /**
586 * @tc.name: FrameNodeTestNg_AdjustGridOffset0011
587 * @tc.desc: Test frame node method
588 * @tc.type: FUNC
589 */
590 HWTEST_F(FrameNodeTestNg, FrameNodeAdjustGridOffset0011, TestSize.Level1)
591 {
592 /**
593 * @tc.steps: step1. build a object to AdjustGridOffset
594 * @tc.expected: expect active is true.
595 */
596 FRAME_NODE2->SetActive(true);
597 bool active = FRAME_NODE2->IsActive();
598 FRAME_NODE2->AdjustGridOffset();
599 EXPECT_TRUE(active);
600
601 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
602 FRAME_NODE2->GetAncestorNodeOfFrame(false);
603
604 FRAME_NODE2->SetActive(false);
605
606 /**
607 * @tc.steps: step2. build a object to AdjustGridOffset
608 * @tc.expected: expect active1 is false.
609 */
610 bool active1 = FRAME_NODE2->IsActive();
611 FRAME_NODE2->AdjustGridOffset();
612 EXPECT_FALSE(active1);
613 }
614
615 /**
616 * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback0012
617 * @tc.desc: Test frame node method
618 * @tc.type: FUNC
619 */
620 HWTEST_F(FrameNodeTestNg, FrameNodeSetOnAreaChangeCallback0012, TestSize.Level1)
621 {
622 /**
623 * @tc.steps: step1. build a object to SetOnAreaChangeCallback
624 * @tc.expected: expect The function is run ok.
625 */
626 OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon943640bd0502(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 627 const OffsetF& origin) {};
628 FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
629 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
630 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
631
632 /**
633 * @tc.steps: step2.test while callback is nullptr
634 * @tc.expected:expect The function is run ok.
635 */
636 FRAME_NODE2->lastFrameRect_ = nullptr;
637 FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
638 FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
639 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
640 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
641 }
642
643 /**
644 * @tc.name: FrameNodeTestNg_TriggerOnAreaChangeCallback0013
645 * @tc.desc: Test frame node method
646 * @tc.type: FUNC
647 */
648 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerOnAreaChangeCallback0013, TestSize.Level1)
649 {
650 /**
651 * @tc.steps: step1. set a flag and init a callback(onAreaChanged)
652 */
653 bool flag = false;
654 OnAreaChangedFunc onAreaChanged = [&flag](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon943640bd0602(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 655 const OffsetF& origin) { flag = !flag; };
656
657 /**
658 * @tc.steps: step2. call TriggerOnAreaChangeCallback before set callback
659 * @tc.expected: expect flag is still false
660 */
661 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_1);
662 EXPECT_FALSE(flag);
663
664 /**
665 * @tc.steps: step3.set callback and release lastParentOffsetToWindow_
666 * @tc.expected: expect flag is still false
667 */
668 FRAME_NODE2->GetOrCreateEventHub<EventHub>()->SetOnAreaChanged(std::move(onAreaChanged));
669 FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
670 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_2);
671 EXPECT_FALSE(flag);
672
673 /**
674 * @tc.steps: step4. release lastFrameRect_
675 * @tc.expected: expect flag is still false
676 */
677 FRAME_NODE2->lastFrameRect_ = nullptr;
678 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_3);
679 EXPECT_FALSE(flag);
680
681 /**
682 * @tc.steps: step5.set lastParentOffsetToWindow_ and lastFrameRect_
683 * @tc.expected: expect flag is still false
684 */
685 FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
686 FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
687 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_4);
688 EXPECT_FALSE(flag);
689 }
690
691 /**
692 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback0014
693 * @tc.desc: Test frame node method
694 * @tc.type: FUNC
695 */
696 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback0014, TestSize.Level1)
697 {
698 /**
699 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
700 * @tc.expected: expect The function is run ok.
701 */
702 VisibleCallbackInfo callbackInfo;
703 FRAME_NODE2->SetVisibleAreaUserCallback({ 0.0f }, callbackInfo);
704 FRAME_NODE2->TriggerVisibleAreaChangeCallback(1);
705
706 /**
707 * @tc.steps: step2. callback SetParent
708 * @tc.expected: expect parent is same with parentNode.
709 */
710 auto parentNode = AceType::MakeRefPtr<FrameNode>("test", -1, AceType::MakeRefPtr<Pattern>(), false);
711 FRAME_NODE2->SetParent(FRAME_NODE3);
712 FRAME_NODE2->TriggerVisibleAreaChangeCallback(2);
713 auto parent = FRAME_NODE2->GetParent();
714 EXPECT_EQ(parent, 1);
715
716 auto parentNode1 = FrameNode::CreateFrameNode("parent", 2, AceType::MakeRefPtr<Pattern>());
717 RefPtr<FrameNode> frameNodes[3] = { parentNode1, nullptr, nullptr };
718 FRAME_NODE2->TriggerVisibleAreaChangeCallback(3);
719 auto parent1 = FRAME_NODE2->GetParent();
720 EXPECT_EQ(parent1, 1);
721
722 FRAME_NODE2->lastVisibleRatio_ = 1.0;
723 FRAME_NODE2->TriggerVisibleAreaChangeCallback(4);
724
725 /**
726 * @tc.steps: step3. set onShow_ and call TriggerVisibleAreaChangeCallback
727 * @tc.expected: expect GetOnShow is true and lastVisibleRatio_ is zero.
728 */
729 auto context = PipelineContext::GetCurrentContext();
730 context->onShow_ = true;
731 FRAME_NODE2->TriggerVisibleAreaChangeCallback(5);
732 auto testNode_ = TestNode::CreateTestNode(101);
733 FRAME_NODE3->SetParent(testNode_);
734 FRAME_NODE3->isActive_ = true;
735 FRAME_NODE2->TriggerVisibleAreaChangeCallback(6);
736 FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::INVISIBLE);
737 FRAME_NODE2->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
738 FRAME_NODE2->isActive_ = true;
739 FRAME_NODE2->TriggerVisibleAreaChangeCallback(7);
740 FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
741 FRAME_NODE2->TriggerVisibleAreaChangeCallback(8);
742 EXPECT_TRUE(context->GetOnShow());
743 EXPECT_EQ(FRAME_NODE2->lastVisibleRatio_, 1);
744 }
745
746 /**
747 * @tc.name: FrameNodeTestNg_CreateLayoutTask0015
748 * @tc.desc: Test frame node method
749 * @tc.type: FUNC
750 */
751 HWTEST_F(FrameNodeTestNg, FrameNodeCreateLayoutTask0015, TestSize.Level1)
752 {
753 /**
754 * @tc.steps: step1. build a object to CreateLayoutTask
755 * @tc.expected: expect The function is run ok.
756 */
757 FRAME_NODE2->isLayoutDirtyMarked_ = true;
758 FRAME_NODE2->CreateLayoutTask(true);
759 EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
760
761 FRAME_NODE2->CreateLayoutTask(true);
762
763 FRAME_NODE2->isLayoutDirtyMarked_ = true;
764 FRAME_NODE2->CreateLayoutTask(false);
765 EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
766 }
767
768 /**
769 * @tc.name: FrameNodeTestNg_CreateRenderTask0016
770 * @tc.desc: Test frame node method
771 * @tc.type: FUNC
772 */
773 HWTEST_F(FrameNodeTestNg, FrameNodeCreateRenderTask0016, TestSize.Level1)
774 {
775 /**
776 * @tc.steps: step1. build a object to CreateRenderTask
777 * @tc.expected: expect The isRenderDirtyMarked_ is false.
778 */
779 FRAME_NODE2->isRenderDirtyMarked_ = true;
780 FRAME_NODE2->CreateRenderTask(true);
781 EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
782
783 FRAME_NODE2->isRenderDirtyMarked_ = true;
784 FRAME_NODE2->CreateRenderTask(false);
785
786 FRAME_NODE2->CreateRenderTask(true);
787 EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
788 }
789
790 /**
791 * @tc.name: FrameNodeTestNg_CreateRenderTask0017
792 * @tc.desc: Test frame node method
793 * @tc.type: FUNC
794 */
795 HWTEST_F(FrameNodeTestNg, FrameNodeCreateRenderTask0017, TestSize.Level1)
796 {
797 /**
798 * @tc.steps: step1. build a object to CreateRenderTask
799 * @tc.expected: expect The isRenderDirtyMarked_ is false.
800 */
801 auto frameNode = FrameNode::CreateFrameNode("frameNode", 1, AceType::MakeRefPtr<Pattern>(), true);
802 frameNode->isRenderDirtyMarked_ = true;
803 frameNode->isObservedByDrawChildren_ = true;
804 frameNode->renderContext_->UpdateAccessibilityFocus(true);
805 /**
806 * @tc.steps: step2. create layoutProperty.
807 */
808 NG::RectF testRect = { 10.0f, 10.0f, 10.0f, 10.0f }; // 10.0f is the x, y, width and height of rect
809 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
810 layoutProperty->SetLayoutRect(testRect);
811 layoutProperty->propVisibility_ = VisibleType::VISIBLE;
812
813 /**
814 * @tc.steps: step3. call the function CreateRenderTask.
815 */
816 frameNode->SetLayoutProperty(layoutProperty);
817 frameNode->CreateRenderTask(true).value()();
818 EXPECT_NE(frameNode, nullptr);
819 }
820
821 /**
822 * @tc.name: FrameNodeTestNg_UpdateLayoutPropertyFlag0018
823 * @tc.desc: Test frame node method
824 * @tc.type: FUNC
825 */
826 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateLayoutPropertyFlag0018, TestSize.Level1)
827 {
828 /**
829 * @tc.steps: step1.call back UpdateLayoutPropertyFlag.
830 * @tc.expected: expect selfFlag is same with PROPERTY_UPDATE_BY_CHILD_REQUEST.
831 */
832 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
833 auto selfFlag = FRAME_NODE2->layoutProperty_->GetPropertyChangeFlag();
834 FRAME_NODE2->UpdateLayoutPropertyFlag();
835 EXPECT_EQ(selfFlag, PROPERTY_UPDATE_BY_CHILD_REQUEST);
836
837 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
838 FRAME_NODE2->AddChild(FRAME_NODE3);
839 FRAME_NODE2->UpdateLayoutPropertyFlag();
840 FRAME_NODE2->Clean();
841 }
842
843 /**
844 * @tc.name: FrameNodeTestNg_UpdateChildrenLayoutWrapper0019
845 * @tc.desc: Test frame node method
846 * @tc.type: FUNC
847 */
848 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateChildrenLayoutWrapper0019, TestSize.Level1)
849 {
850 /**
851 * @tc.steps: step1. AddChild for FRAME_NODE2 and callback UpdateChildrenLayoutWrapper.
852 * @tc.expected: expect The UpdateLayoutWrapper is true.
853 */
854 FRAME_NODE2->AddChild(FRAME_NODE3);
855 FRAME_NODE2->UpdateChildrenLayoutWrapper(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true), true, true);
856 FRAME_NODE2->Clean();
857 EXPECT_TRUE(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true));
858 }
859
860 /**
861 * @tc.name: FrameNodeTestNg_MarkModifyDone0021
862 * @tc.desc: Test frame node method
863 * @tc.type: FUNC
864 */
865 HWTEST_F(FrameNodeTestNg, FrameNodeMarkModifyDone0021, TestSize.Level1)
866 {
867 /**
868 * @tc.steps: step1. build a object to MarkModifyDone.
869 * @tc.expected:expect The function is run ok.
870 */
871 FRAME_NODE2->MarkModifyDone();
872 EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
873 FRAME_NODE2->isRestoreInfoUsed_ = true;
874 FRAME_NODE2->MarkModifyDone();
875 EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
876 }
877
878 /**
879 * @tc.name: FrameNodeTestNg_MarkNeedRender0022
880 * @tc.desc: Test frame node method
881 * @tc.type: FUNC
882 */
883 HWTEST_F(FrameNodeTestNg, FrameNodeMarkNeedRender0022, TestSize.Level1)
884 {
885 /**
886 * @tc.steps: step1. callback MarkNeedRenderOnly.
887 * @tc.expected: expect The function is run ok.
888 */
889 FRAME_NODE2->MarkNeedRenderOnly();
890 auto test = FRAME_NODE2->isRenderDirtyMarked_ = false;
891 auto test1 = FRAME_NODE2->isLayoutDirtyMarked_ = false;
892 FRAME_NODE2->MarkNeedRender(false);
893 FRAME_NODE2->MarkNeedRender(true);
894 EXPECT_FALSE(test);
895 EXPECT_FALSE(test1);
896 }
897
898 /**
899 * @tc.name: FrameNodeTestNg_IsNeedRequestParentMeasure0023
900 * @tc.desc: Test frame node method
901 * @tc.type: FUNC
902 */
903 HWTEST_F(FrameNodeTestNg, FrameNodeIsNeedRequestParentMeasure0023, TestSize.Level1)
904 {
905 /**
906 * @tc.steps: step1. callback IsNeedRequestParentMeasure.
907 * @tc.expected: expect The function return value is true.
908 */
909 auto test = FRAME_NODE2->IsNeedRequestParentMeasure();
910 EXPECT_TRUE(test);
911
912 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
913 FRAME_NODE2->IsNeedRequestParentMeasure();
914
915 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
916 FRAME_NODE2->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
917 auto test1 = FRAME_NODE2->IsNeedRequestParentMeasure();
918 EXPECT_TRUE(test1);
919 }
920
921 /**
922 * @tc.name: FrameNodeTestNg_OnGenerateOneDepthVisibleFrameWithTransition0024
923 * @tc.desc: Test frame node method
924 * @tc.type: FUNC
925 */
926 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithTransition0024, TestSize.Level1)
927 {
928 /**
929 * @tc.steps: step1. callback OnGenerateOneDepthVisibleFrameWithTransition.
930 * @tc.expected: expect The function is run ok.
931 */
932 std::list<RefPtr<FrameNode>> visibleList;
933 FRAME_NODE2->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
934
935 /**
936 * @tc.steps: step2.push the framenode to visibleList and callback OnGenerateOneDepthVisibleFrameWithTransition
937 * @tc.expected: expect visibleList.size is 3.
938 */
939 visibleList.push_back(FRAME_NODE);
940 FRAME_NODE3->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
941 EXPECT_EQ(visibleList.size(), 3);
942 }
943
944 /**
945 * @tc.name: FrameNodeTestNg_IsOutOfTouchTestRegion0025
946 * @tc.desc: Test frame node method
947 * @tc.type: FUNC
948 */
949 HWTEST_F(FrameNodeTestNg, FrameNodeIsOutOfTouchTestRegion0025, TestSize.Level1)
950 {
951 /**
952 * @tc.steps: step1. callback IsOutOfTouchTestRegion.
953 * @tc.expected: expect The function return value is true.
954 */
955 PointF pointF;
956 std::vector<RectF> rectF;
957 TouchEvent touchEvent;
958 auto test = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
959 EXPECT_TRUE(test);
960
961 auto test1 = FRAME_NODE2->InResponseRegionList(pointF, rectF);
962 auto test2 = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
963 EXPECT_FALSE(test1);
964 EXPECT_TRUE(test2);
965 }
966
967 /**
968 * @tc.name: FrameNodeTestNg_TouchTest0026
969 * @tc.desc: Test frame node method
970 * @tc.type: FUNC
971 */
972 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest0026, TestSize.Level1)
973 {
974 /**
975 * @tc.steps: step1. callback TouchTest.
976 * @tc.expected: expect The function return value is true.
977 */
978 PointF globalPoint;
979 PointF parentLocalPoint;
980 TouchRestrict touchRestrict;
981 TouchTestResult result;
982 ResponseLinkResult responseLinkResult;
983 SystemProperties::debugEnabled_ = true;
984 FRAME_NODE2->TouchTest(
985 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
986
987 SystemProperties::debugEnabled_ = false;
988 FRAME_NODE2->TouchTest(
989 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
990
991 /**
992 * @tc.steps: step2. set isActive_ and IsEnabled is false.
993 * @tc.expected: expect The function return value is OUT_OF_REGION.
994 */
995 FRAME_NODE2->isActive_ = false;
996 FRAME_NODE2->GetOrCreateEventHub<EventHub>()->SetEnabled(false);
997 auto test = FRAME_NODE2->TouchTest(
998 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
999 EXPECT_EQ(test, HitTestResult::OUT_OF_REGION);
1000 }
1001
1002 class MockFrameNode : public FrameNode {
1003 DECLARE_ACE_TYPE(MockFrameNode, FrameNode);
1004
1005 public:
CreateMockFrameNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)1006 static RefPtr<MockFrameNode> CreateMockFrameNode(
1007 const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
1008 {
1009 auto frameNode = AceType::MakeRefPtr<MockFrameNode>(tag, nodeId, pattern);
1010 ElementRegister::GetInstance()->AddUINode(frameNode);
1011 frameNode->InitializePatternAndContext();
1012 return frameNode;
1013 }
1014
MockFrameNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)1015 MockFrameNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
1016 : FrameNode(tag, nodeId, pattern)
1017 {}
1018 ~MockFrameNode() override = default;
1019
1020 MOCK_METHOD(bool, IsOutOfTouchTestRegion, (const PointF&, const TouchEvent&, std::vector<RectF>*));
1021 MOCK_METHOD(void, CollectSelfAxisResult,
1022 (const PointF&, const PointF&, bool&, const PointF&, AxisTestResult&, bool&, HitTestResult&, TouchRestrict&,
1023 bool));
1024 };
1025
1026 using NiceMockFrameNode = NiceMock<MockFrameNode>;
1027
1028 /**
1029 * @tc.name: FrameNodeTestNg_AxisTest0027
1030 * @tc.desc: Test AxisTest
1031 * @tc.type: FUNC
1032 */
1033 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest0027, TestSize.Level1)
1034 {
1035 /**
1036 * @tc.steps: step1. construct tree
1037 */
1038 auto stackNode = NiceMockFrameNode::CreateMockFrameNode(
1039 "stackNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StackPattern>());
1040 auto node1 = NiceMockFrameNode::CreateMockFrameNode(
1041 "node1", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StackPattern>());
1042 auto node2 = NiceMockFrameNode::CreateMockFrameNode(
1043 "node2", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StackPattern>());
1044 stackNode->frameChildren_.emplace(node1);
1045 stackNode->frameChildren_.emplace(node2);
1046
1047 std::vector<RefPtr<MockFrameNode>> nodes = { stackNode, node1, node2 };
1048 for (auto& item : nodes) {
1049 item->isActive_ = true;
1050 const auto& inputEventHub = item->GetOrCreateEventHub<EventHub>()->GetOrCreateInputEventHub();
__anon943640bd0702(AxisInfo& info) 1051 inputEventHub->SetAxisEvent([&item](AxisInfo& info) {});
1052 ON_CALL((*item), CollectSelfAxisResult(testing::_, testing::_, testing::_, testing::_, testing::_, testing::_,
1053 testing::_, testing::_, testing::_))
1054 .WillByDefault(
1055 testing::Invoke([&inputEventHub](const PointF&, const PointF&, bool&, const PointF&,
__anon943640bd0802(const PointF&, const PointF&, bool&, const PointF&, AxisTestResult& axisResult, bool&, HitTestResult&, TouchRestrict&, bool) 1056 AxisTestResult& axisResult, bool&, HitTestResult&, TouchRestrict&, bool) {
1057 axisResult.emplace_back(inputEventHub->axisEventActuator_->axisEventTarget_);
1058 }));
1059 ON_CALL((*item), IsOutOfTouchTestRegion(testing::_, testing::_, testing::_))
1060 .WillByDefault(
__anon943640bd0902(const PointF&, const TouchEvent&, std::vector<RectF>*) 1061 testing::Invoke([](const PointF&, const TouchEvent&, std::vector<RectF>*) { return false; }));
1062 }
1063 node2->SetHitTestMode(HitTestMode::HTMTRANSPARENT);
1064 const PointF globalPoint, parentLocalPoint, parentRevertPoint;
1065 TouchRestrict touchRestrict;
1066 AxisTestResult onAxisResult;
1067
1068 /**
1069 * @tc.steps: step2. Trigger AxisTest.
1070 * @tc.expected: expect the order of axis test sequence is correct.
1071 */
1072 stackNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult);
1073 std::string expectSeq = node2->GetHostTag() + node1->GetHostTag() + stackNode->GetHostTag();
1074 std::string triggerSeq;
1075 for (auto& item : onAxisResult) {
1076 triggerSeq.append(item->GetFrameName());
1077 }
1078 EXPECT_EQ(triggerSeq, expectSeq);
1079 }
1080
1081 /**
1082 * @tc.name: FrameNodeTestNg0028
1083 * @tc.desc: Test frame node method
1084 * @tc.type: FUNC
1085 */
1086 HWTEST_F(FrameNodeTestNg, FrameNodeOnAccessibilityEvent0028, TestSize.Level1)
1087 {
1088 /**
1089 * @tc.steps: step1. callback OnAccessibilityEvent.
1090 * @tc.expected: expect The function is true.
1091 */
1092 auto test = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = true;
1093 FRAME_NODE2->OnAccessibilityEvent(
1094 AccessibilityEventType::CHANGE, WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_SUBTREE);
1095 FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, "", "");
1096 EXPECT_TRUE(test);
1097
1098 /**
1099 * @tc.steps: step2. callback OnAccessibilityEvent.
1100 * @tc.expected: expect The function is false.
1101 */
1102 auto test1 = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = false;
1103 FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::ACCESSIBILITY_FOCUSED);
1104 EXPECT_FALSE(test1);
1105 }
1106
1107 /**
1108 * @tc.name: FrameNodeTestNg0029
1109 * @tc.desc: Test frame node method
1110 * @tc.type: FUNC
1111 */
1112 HWTEST_F(FrameNodeTestNg, FrameNodeOnAccessibilityEventForVirtualNode0029, TestSize.Level1)
1113 {
1114 /**
1115 * @tc.steps: step1. callback OnAccessibilityEventForVirtualNode.
1116 * @tc.expected: expect The function is true.
1117 */
1118 AccessibilityEvent event;
1119 auto accessibilityId = 1;
1120 auto test = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = true;
1121 FRAME_NODE2->OnAccessibilityEventForVirtualNode(AccessibilityEventType::CHANGE, accessibilityId);
1122 EXPECT_TRUE(test);
1123
1124 /**
1125 * @tc.steps: step2. callback OnAccessibilityEventForVirtualNode.
1126 * @tc.expected: expect The function is false.
1127 */
1128 auto test1 = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = false;
1129 FRAME_NODE2->OnAccessibilityEventForVirtualNode(AccessibilityEventType::FOCUS, accessibilityId);
1130 EXPECT_FALSE(test1);
1131 }
1132
1133 /**
1134 * @tc.name: FrameNodeTestNg_MarkRemoving0029
1135 * @tc.desc: Test frame node method
1136 * @tc.type: FUNC
1137 */
1138 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving0029, TestSize.Level1)
1139 {
1140 /**
1141 * @tc.steps: step1. callback MarkRemoving.
1142 * @tc.expected: expect The function return value is true.
1143 */
1144 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
1145 FRAME_NODE2->AddChild(FRAME_NODE3);
1146 FRAME_NODE2->layoutProperty_->UpdateGeometryTransition("id");
1147 auto mark = FRAME_NODE2->MarkRemoving();
1148 FRAME_NODE2->Clean();
1149 EXPECT_TRUE(mark);
1150
1151 FRAME_NODE2->layoutProperty_ = nullptr;
1152 auto mark1 = FRAME_NODE2->MarkRemoving();
1153 EXPECT_FALSE(mark1);
1154 }
1155
1156 /**
1157 * @tc.name: FrameNodeTestNg_CalculateCurrentVisibleRatio0030
1158 * @tc.desc: Test frame node method
1159 * @tc.type: FUNC
1160 */
1161 HWTEST_F(FrameNodeTestNg, FrameNodeCalculateCurrentVisibleRatio0030, TestSize.Level1)
1162 {
1163 /**
1164 * @tc.steps: step1. callback RemoveLastHotZoneRect.
1165 * @tc.expected: step1. expect The function is run ok.
1166 */
1167 RectF visibleRect;
1168 RectF renderRect;
1169 FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect);
1170 EXPECT_EQ(visibleRect.Width(), 0);
1171 EXPECT_EQ(renderRect.Width(), 0);
1172
1173 /**
1174 * @tc.steps: step2. set wrong value and call CalculateCurrentVisibleRatio
1175 * @tc.expected: expect The function returns 0.
1176 */
1177 renderRect.SetWidth(-1);
1178 EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1179 visibleRect.SetWidth(-1);
1180 EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1181 }
1182
1183 /**
1184 * @tc.name: FrameNodeTestNg_InitializePatternAndContext0032
1185 * @tc.desc: Test InitializePatternAndContext
1186 * @tc.type: FUNC
1187 */
1188 HWTEST_F(FrameNodeTestNg, FrameNodeInitializePatternAndContext0032, TestSize.Level1)
1189 {
1190 /**
1191 * @tc.steps: step1. create a node and set onMainTree_=false, then call InitializePatternAndContext
1192 and trigger the callback
1193 * @tc.expected: hasPendingRequest_ is true
1194 */
__anon943640bd0a02() 1195 auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1196 one->onMainTree_ = false;
1197 one->InitializePatternAndContext();
1198 auto renderContext_ = one->renderContext_;
1199 renderContext_->RequestNextFrame();
1200 EXPECT_TRUE(one->hasPendingRequest_);
1201 }
1202
1203 /**
1204 * @tc.name: FrameNodeTestNg_ProcessAllVisibleCallback0033
1205 * @tc.desc: Test ProcessAllVisibleCallback
1206 * @tc.type: FUNC
1207 */
1208 HWTEST_F(FrameNodeTestNg, FrameNodeProcessAllVisibleCallback0033, TestSize.Level1)
1209 {
1210 /**
1211 * @tc.steps: step1. create a node and init a vector for preparing for args, then set a flag
1212 */
__anon943640bd0b02() 1213 auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1214 std::vector<double> visibleAreaRatios { 0.2, 0.8, 0.21, 0.79, 0.5 };
1215 int flag = 0;
__anon943640bd0c02(bool input1, double input2) 1216 auto defaultCallback = [&flag](bool input1, double input2) { flag += 1; };
1217 VisibleCallbackInfo callbackInfo { defaultCallback, 1.0, false };
1218
1219 /**
1220 * @tc.steps: step2. call ProcessAllVisibleCallback with 0.5 from 0
1221 * @tc.expected: flag is 1
1222 */
1223 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0.5, 0);
1224 EXPECT_EQ(flag, 1);
1225
1226 /**
1227 * @tc.steps: step3. call ProcessAllVisibleCallback with 0 from 0.5
1228 * @tc.expected: flag is 2
1229 */
1230 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0.5);
1231 EXPECT_EQ(flag, 2);
1232
1233 /**
1234 * @tc.steps: step4. call ProcessAllVisibleCallback with 0 from 0
1235 * @tc.expected: flag is 2
1236 */
1237 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0);
1238 EXPECT_EQ(flag, 2);
1239
1240 /**
1241 * @tc.steps: step5. call ProcessAllVisibleCallback with 1 from 0
1242 * @tc.expected: flag is 3
1243 */
1244 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 0);
1245 EXPECT_EQ(flag, 3);
1246
1247 /**
1248 * @tc.steps: step6. call ProcessAllVisibleCallback with 1 from 1
1249 * @tc.expected: flag is 3
1250 */
1251 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 1);
1252 EXPECT_EQ(flag, 3);
1253 }
1254
1255 /**
1256 * @tc.name: FrameNodeTestNg_AnimateHoverEffect0034
1257 * @tc.desc: Test AnimateHoverEffect
1258 * @tc.type: FUNC
1259 */
1260 HWTEST_F(FrameNodeTestNg, FrameNodeAnimateHoverEffect0034, TestSize.Level1)
1261 {
1262 /**
1263 * @tc.steps: step1. create a frame node and release inputEventHub_, then
1264 change hoverEffectType_ and call AnimateHoverEffect
1265 * @tc.expected: AnimateHoverEffectScale has been called
1266 */
__anon943640bd0d02() 1267 auto one = FrameNode::GetOrCreateFrameNode("one", 12, []() { return AceType::MakeRefPtr<Pattern>(); });
1268 one->GetOrCreateEventHub<EventHub>()->inputEventHub_ = nullptr;
1269 auto renderContext = AceType::DynamicCast<MockRenderContext>(one->renderContext_);
1270 EXPECT_CALL(*renderContext, AnimateHoverEffectScale(_));
1271 one->AnimateHoverEffect(false);
1272 auto inputEventHub = one->GetOrCreateEventHub<EventHub>()->GetOrCreateInputEventHub();
1273 inputEventHub->hoverEffectType_ = HoverEffectType::UNKNOWN;
1274 one->AnimateHoverEffect(false);
1275 inputEventHub->hoverEffectType_ = HoverEffectType::AUTO;
1276 one->AnimateHoverEffect(false);
1277 inputEventHub->hoverEffectType_ = HoverEffectType::SCALE;
1278 one->AnimateHoverEffect(false);
1279 inputEventHub->hoverEffectType_ = HoverEffectType::BOARD;
1280 one->AnimateHoverEffect(false);
1281 inputEventHub->hoverEffectType_ = HoverEffectType::OPACITY;
1282 one->AnimateHoverEffect(false);
1283 inputEventHub->hoverEffectType_ = HoverEffectType::NONE;
1284 one->AnimateHoverEffect(false);
1285 }
1286
1287 /**
1288 * @tc.name: FrameNodeTestNg_CreateAnimatablePropertyFloat0035
1289 * @tc.desc: Test AnimateHoverEffect
1290 * @tc.type: FUNC
1291 */
1292 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatablePropertyFloat0035, TestSize.Level1)
1293 {
1294 /**
1295 * @tc.steps: step1. call CreateAnimatablePropertyFloat.
1296 * @tc.expected: expect GetRenderContext is not null.
1297 */
1298 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1299
1300 FRAME_NODE->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1301 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1302
1303 /**
1304 * @tc.steps: step2. put value to map and call CreateAnimatablePropertyFloat.
1305 * @tc.expected: expect iter is not equal map.
1306 */
1307 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1308 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1309 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1310 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1311 EXPECT_NE(iter, map);
1312 }
1313
1314 /**
1315 * @tc.name: FrameNodeTestNg_UpdateAnimatablePropertyFloat0036
1316 * @tc.desc: Test AnimateHoverEffect
1317 * @tc.type: FUNC
1318 */
1319 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatablePropertyFloat0036, TestSize.Level1)
1320 {
1321 /**
1322 * @tc.steps: step1. call UpdateAnimatablePropertyFloat.
1323 * @tc.expected: expect iter is not equal map.
1324 */
1325 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1326 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1327 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1328 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1329 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1330 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1331 EXPECT_NE(iter, map);
1332
1333 /**
1334 * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1335 * @tc.expected: expect property is nullptr.
1336 */
1337 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1338 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1339 auto property = AceType::DynamicCast<NodeAnimatablePropertyFloat>(iter->second);
1340 EXPECT_EQ(property, nullptr);
1341 }
1342
1343 /**
1344 * @tc.name: FrameNodeTestNg_CreateAnimatableArithmeticProperty0037
1345 * @tc.desc: Test AnimateHoverEffect
1346 * @tc.type: FUNC
1347 */
1348 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatableArithmeticProperty0037, TestSize.Level1)
1349 {
1350 /**
1351 * @tc.steps: step1. call CreateAnimatableArithmeticProperty.
1352 * @tc.expected: expect iter is not equal map.
1353 */
1354 RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1355 std::function<void(const RefPtr<NG::CustomAnimatableArithmetic>&)> onCallbackEvent;
1356 FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1357 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1358 FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1359 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1360 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1361 EXPECT_NE(iter, map);
1362 }
1363
1364 /**
1365 * @tc.name: FrameNodeTestNg_UpdateAnimatableArithmeticProperty0038
1366 * @tc.desc: Test AnimateHoverEffect
1367 * @tc.type: FUNC
1368 */
1369 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatableArithmeticProperty0038, TestSize.Level1)
1370 {
1371 /**
1372 * @tc.steps: step1. call UpdateAnimatableArithmeticProperty.
1373 * @tc.expected: expect iter is not equal map.
1374 */
1375 RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1376 FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1377 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1378
1379 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1380 FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1381 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1382 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1383 EXPECT_NE(iter, map);
1384
1385 /**
1386 * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1387 * @tc.expected: expect property is nullptr.
1388 */
1389 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1390 FRAME_NODE->UpdateAnimatableArithmeticProperty("", value);
1391 auto property = AceType::DynamicCast<NodeAnimatableArithmeticProperty>(iter->second);
1392 EXPECT_EQ(property, nullptr);
1393 }
1394
1395 /**
1396 * @tc.name: FrameNodeTestNg0039
1397 * @tc.desc: Test of FrameProxy
1398 * @tc.type: FUNC
1399 */
1400 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg0039, TestSize.Level1)
1401 {
1402 /**
1403 * @tc.steps: step1. creat childNode、create LazyForEachNode
1404 * @tc.expected: childNode is not null
1405 */
1406 auto childNode = FrameNode::CreateFrameNode(
1407 "child", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1408 auto itemNode = FrameNode::CreateFrameNode(
1409 "itemNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1410 childNode->AddChild(itemNode);
1411 /**
1412 * @tc.steps: step2. call SetIsOverlayNode.
1413 * @tc.expected: change IsOverlayNode().
1414 */
1415 ConfigurationChange configurationChange;
1416 childNode->OnConfigurationUpdate(configurationChange);
1417 configurationChange.languageUpdate = true;
1418 childNode->OnConfigurationUpdate(configurationChange);
1419 configurationChange.colorModeUpdate = true;
1420 childNode->OnConfigurationUpdate(configurationChange);
1421 configurationChange.directionUpdate = true;
1422 childNode->OnConfigurationUpdate(configurationChange);
1423 configurationChange.dpiUpdate = true;
1424 childNode->OnConfigurationUpdate(configurationChange);
1425 configurationChange.fontUpdate = true;
1426 configurationChange.iconUpdate = true;
1427 configurationChange.skinUpdate = true;
1428 configurationChange.fontWeightScaleUpdate = true;
1429 childNode->OnConfigurationUpdate(configurationChange);
1430 configurationChange.fontScaleUpdate = true;
1431 childNode->OnConfigurationUpdate(configurationChange);
1432
1433 childNode->SetBackgroundLayoutConstraint(itemNode);
1434 childNode->ForceUpdateLayoutPropertyFlag(PROPERTY_UPDATE_MEASURE_SELF);
1435 childNode->GetPaintRectWithTransform();
1436 childNode->GetTransformScale();
1437 childNode->SetJSViewActive(true);
1438 auto layoutProperty = childNode->GetLayoutProperty();
1439 EXPECT_FALSE(layoutProperty->IsOverlayNode());
1440 layoutProperty->SetIsOverlayNode(true);
1441 childNode->DumpOverlayInfo();
1442 EXPECT_TRUE(layoutProperty->IsOverlayNode());
1443 }
1444
1445 /**
1446 * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback040
1447 * @tc.desc: Test frame node method
1448 * @tc.type: FUNC
1449 */
1450 HWTEST_F(FrameNodeTestNg, SetOnAreaChangeCallback040, TestSize.Level1)
1451 {
1452 /**
1453 * @tc.steps: step1. build a object to SetOnAreaChangeCallback
1454 * @tc.expected: expect cover branch lastFrameRect_ non null and function is run ok.
1455 */
1456 OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anon943640bd0e02(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 1457 const OffsetF& origin) {};
1458 FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
1459 FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
1460 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
1461
1462 /**
1463 * @tc.steps: step2.test while callback is nullptr
1464 * @tc.expected:expect cover branch lastParentOffsetToWindow_ non null and function is run ok.
1465 */
1466
1467 FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
1468 FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
1469 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
1470 }
1471
1472 /**
1473 * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread040
1474 * @tc.desc: Test frame node method
1475 * @tc.type: FUNC
1476 */
1477 HWTEST_F(FrameNodeTestNg, SwapDirtyLayoutWrapperOnMainThread040, TestSize.Level1)
1478 {
1479 /**
1480 * @tc.steps: step1. creat frameNode and layoutProperty
1481 */
1482 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
1483 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1484 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>();
1485 ASSERT_NE(layoutProperty, nullptr);
1486
1487 /**
1488 * @tc.steps: step2. setBorderWidth and updateBorderWidth.
1489 * @tc.expected: expect borderWidth property is not nullptr.
1490 */
1491 BorderWidthProperty overCountBorderWidth;
1492 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP));
1493 layoutProperty->UpdateBorderWidth(overCountBorderWidth);
1494 frameNode->SetLayoutProperty(layoutProperty);
1495
1496 /**
1497 * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
1498 * @tc.expected: expect GetBorderWidthProperty is not nullptr.
1499 */
1500 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1501 EXPECT_NE(layoutProperty->GetBorderWidthProperty(), nullptr);
1502
1503 /**
1504 * @tc.steps: step4. updatae layoutConstraint and set eventHub_.
1505 * @tc.expected: expect cover branch eventHub_ non null and function is run ok .
1506 */
1507 auto layoutConstraintF_ = LayoutConstraintF();
1508 layoutConstraintF_.maxSize = CONTAINER_SIZE;
1509 layoutConstraintF_.percentReference = CONTAINER_SIZE;
1510 frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
1511 layoutProperty->UpdateLayoutConstraint(layoutConstraintF_);
1512
1513 frameNode->GetOrCreateEventHub<EventHub>()->GetOrCreateFocusHub();
1514 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1515 EXPECT_NE(frameNode->eventHub_, nullptr);
1516
1517 /**
1518 * @tc.steps: step5. set currentFocus_ is true and call SwapDirtyLayoutWrapperOnMainThread.
1519 * @tc.expected: expect cover branch IsCurrentFocus() is true and function is run ok .
1520 */
1521 frameNode->GetOrCreateEventHub<EventHub>()->GetOrCreateFocusHub()->currentFocus_ = true;
1522 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1523 EXPECT_TRUE(frameNode->GetOrCreateEventHub<EventHub>()->GetOrCreateFocusHub()->IsCurrentFocus());
1524 }
1525
1526 /**
1527 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback048
1528 * @tc.desc: Test frame node method
1529 * @tc.type: FUNC
1530 */
1531 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback048, TestSize.Level1)
1532 {
1533 /**
1534 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1535 * @tc.expected: expect The function is run ok.
1536 */
1537 VisibleCallbackInfo callbackInfo;
1538 constexpr uint32_t minInterval = 100; // 100ms
1539 int flag = 0;
__anon943640bd0f02(bool input1, double input2) 1540 callbackInfo.callback = [&flag](bool input1, double input2) { flag += 1; };
1541 callbackInfo.period = minInterval;
1542 FRAME_NODE2->SetVisibleAreaUserCallback({ 0.2, 0.8, 0.21, 0.79, 0.5 }, callbackInfo);
1543 FRAME_NODE2->ProcessThrottledVisibleCallback(false);
1544 EXPECT_EQ(FRAME_NODE2->throttledCallbackOnTheWay_, false);
1545 }
1546
1547 /**
1548 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback049
1549 * @tc.desc: Test the function GetValidLeafChildNumber
1550 * @tc.type: FUNC
1551 */
1552 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback049, TestSize.Level1)
1553 {
1554 /**
1555 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1556 * @tc.expected: expect The function is run ok.
1557 */
1558 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1559 const RefPtr<FrameNode> node =
1560 FrameNode::CreateFrameNode("TriggerVisibleAreaChangeCallback001", nodeId, AceType::MakeRefPtr<Pattern>(), true);
1561
1562 /**
1563 * @tc.steps2: Call the function GetValidLeafChildNumber.
1564 * @tc.expected: Value returned as expected.
1565 */
1566 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1567 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>(), true);
1568 GET_CHILD1->UpdateInspectorId("child1");
1569 node->AddChild(GET_CHILD1);
1570 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1571
1572 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>(), true);
1573 GET_CHILD2->UpdateInspectorId("child2");
1574 node->AddChild(GET_CHILD2);
1575 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 3), 2);
1576 }
1577
1578 /**
1579 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback050
1580 * @tc.desc: Test the function MarkAndCheckNewOpIncNode
1581 * @tc.type: FUNC
1582 */
1583 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback050, TestSize.Level1)
1584 {
1585 /**
1586 * @tc.steps: step1. creat node and generate a node tree.
1587 */
1588 RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>());
1589 RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>());
1590 RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>());
1591 GET_PARENT->AddChild(GET_CHILD1);
1592 GET_PARENT->AddChild(GET_CHILD2);
1593 GET_CHILD1->MarkAndCheckNewOpIncNode(Axis::VERTICAL);
1594 EXPECT_FALSE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1595
1596 /**
1597 * @tc.steps2: set suggestOpIncByte_ and call the function MarkAndCheckNewOpIncNode.
1598 * @tc.expected: Value returned as expected.
1599 */
1600 GET_PARENT->suggestOpIncByte_ = 7;
1601 GET_CHILD1->SetSuggestOpIncActivatedOnce();
1602 GET_PARENT->SetSuggestOpIncActivatedOnce();
1603 GET_CHILD1->MarkAndCheckNewOpIncNode(Axis::VERTICAL);
1604 EXPECT_TRUE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1605 GET_CHILD1->suggestOpIncByte_ = 1;
1606 GET_CHILD1->MarkAndCheckNewOpIncNode(Axis::VERTICAL);
1607 }
1608
1609 /**
1610 * @tc.name: FrameNodeTouchTest051
1611 * @tc.desc: Test frameNode FindSuggestOpIncNode
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest051, TestSize.Level1)
1615 {
1616 /**
1617 * @tc.steps: step1. initialize parameters.
1618 */
1619 std::string tag = "test";
1620 auto frameNode = FrameNode::CreateFrameNode(tag, 1, AceType::MakeRefPtr<Pattern>(), true);
1621 auto frameNode1 = FrameNode::CreateFrameNode("test1", 2, AceType::MakeRefPtr<Pattern>(), true);
1622 frameNode->AddChild(frameNode1);
1623 frameNode->GetBaselineDistance();
1624
1625 /**
1626 * @tc.steps: step2. set frame size and call FindSuggestOpIncNode
1627 * @tc.expected: expect result value.
1628 */
1629 frameNode->geometryNode_->SetFrameSize(SizeF(20, 20));
1630 auto result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1, Axis::VERTICAL);
1631 EXPECT_EQ(result, 0);
1632 result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1, Axis::VERTICAL);
1633 EXPECT_EQ(result, 2);
1634 SystemProperties::debugEnabled_ = true;
1635 frameNode->suggestOpIncByte_ = 0;
1636 result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1, Axis::VERTICAL);
1637 EXPECT_EQ(result, 0);
1638 }
1639
1640 /**
1641 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback052
1642 * @tc.desc: Test the function IsOpIncValidNode
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback052, TestSize.Level1)
1646 {
1647 /**
1648 * @tc.steps: step1. initialize parameters.
1649 */
1650
1651 SizeF boundary(1, 1);
1652 int32_t childNumber = 2;
1653
1654 /**
1655 * @tc.steps2: call the function IsOpIncValidNode.
1656 * @tc.expected: Value returned as expected.
1657 */
1658 auto result = FRAME_NODE2->IsOpIncValidNode(boundary, Axis::VERTICAL, childNumber);
1659 EXPECT_EQ(result, 0);
1660
1661 FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1662 result = FRAME_NODE2->IsOpIncValidNode(boundary, Axis::VERTICAL, childNumber);
1663 EXPECT_EQ(result, 0);
1664
1665 SizeF boundary1(40, 40);
1666 FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1667 result = FRAME_NODE2->IsOpIncValidNode(boundary1, Axis::VERTICAL, childNumber);
1668 EXPECT_EQ(result, 0);
1669 }
1670
1671 /**
1672 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback053
1673 * @tc.desc: Test the function MarkSuggestOpIncGroup
1674 * @tc.type: FUNC
1675 */
1676 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback053, TestSize.Level1)
1677 {
1678 /**
1679 * @tc.steps1: call the function MarkSuggestOpIncGroup.
1680 * @tc.expected: Value returned as expected.
1681 */
1682 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1683
1684 FRAME_NODE2->SetCanSuggestOpInc(true);
1685 FRAME_NODE2->SetSuggestOpIncMarked(true);
1686 FRAME_NODE2->SetOpIncGroupCheckedThrough(true);
1687 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1688
1689 FRAME_NODE2->SetSuggestOpIncMarked(false);
1690 FRAME_NODE2->SetCanSuggestOpInc(false);
1691 FRAME_NODE2->SetOpIncGroupCheckedThrough(false);
1692 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1693 }
1694
1695 /**
1696 * @tc.name: FrameNodeTestNg_IsPaintRectWithTransformValid054
1697 * @tc.desc: Test frame node method IsPaintRectWithTransformValid
1698 * @tc.type: FUNC
1699 */
1700 HWTEST_F(FrameNodeTestNg, FrameNodeIsPaintRectWithTransformValid054, TestSize.Level1)
1701 {
1702 /**
1703 * @tc.steps: step1. callback IsPaintRectWithTransformValid.
1704 * @tc.expected: expect The function return value is true when width or height is nearZero.
1705 */
1706 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1707 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
1708 node->renderContext_ = mockRenderContext;
1709
1710 mockRenderContext->rect_ = RectF(0, 0, 0, 10);
1711 mockRenderContext->paintRect_ = RectF(0, 0, 0, 10);
1712 auto test1 = node->IsPaintRectWithTransformValid();
1713 EXPECT_TRUE(test1);
1714
1715 mockRenderContext->rect_ = RectF(0, 0, 10, 0);
1716 mockRenderContext->paintRect_ = RectF(0, 0, 10, 0);
1717 auto test2 = node->IsPaintRectWithTransformValid();
1718 EXPECT_TRUE(test2);
1719
1720 mockRenderContext->rect_ = RectF(0, 0, 10, 10);
1721 mockRenderContext->paintRect_ = RectF(0, 0, 10, 10);
1722 auto test3 = node->IsPaintRectWithTransformValid();
1723 EXPECT_FALSE(test3);
1724
1725 mockRenderContext->rect_ = RectF(0, 0, 0, 0);
1726 mockRenderContext->paintRect_ = RectF(0, 0, 0, 0);
1727 auto test4 = node->IsPaintRectWithTransformValid();
1728 EXPECT_TRUE(test4);
1729 }
1730
1731 /**
1732 * @tc.name: FrameNodeTestNg_Predict001
1733 * @tc.desc: Test frame node method ResetPredictNodes
1734 * @tc.type: FUNC
1735 */
1736 HWTEST_F(FrameNodeTestNg, FrameNodePredict001, TestSize.Level1)
1737 {
1738 /**
1739 * @tc.steps: step1. add predictNode to main node and delete main node.
1740 * @tc.expected: expect the predictNode is not layout dirty marked after main node desconstructed.
1741 */
1742 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1743 auto predictNode = FrameNode::CreateFrameNode("predict", 1, AceType::MakeRefPtr<Pattern>(), false);
1744 predictNode->SetLayoutDirtyMarked(true);
1745 node->AddPredictLayoutNode(predictNode);
1746 node.Reset();
1747 EXPECT_FALSE(predictNode->IsLayoutDirtyMarked());
1748 }
1749
1750 /**
1751 * @tc.name: FrameNodeSetJSCustomProperty055
1752 * @tc.desc: Test SetJSCustomProperty isCNode true, expect result is false.
1753 * @tc.type: FUNC
1754 */
1755 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty055, TestSize.Level1)
1756 {
1757 /**
1758 * @tc.steps: step1. initialize parameters.
1759 */
1760 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1761
1762 /**
1763 * @tc.steps: step2. set isCNode true.
1764 * @tc.expected: expect result is false.
1765 */
1766 frameNode->setIsCNode(true);
__anon943640bd1002() 1767 std::function<bool()> func = []() -> bool { return true; };
__anon943640bd1102(const std::string& key) 1768 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1769 return "getFuncA";
1770 };
1771 frameNode->SetJSCustomProperty(func, getFuncA);
1772 std::string getValue;
1773 bool result = frameNode->GetCapiCustomProperty("key", getValue);
1774 EXPECT_EQ(result, false);
1775 }
1776
1777 /**
1778 * @tc.name: FrameNodeSetJSCustomProperty056
1779 * @tc.desc: Test SetJSCustomProperty isCNode false, expect result is false.
1780 * @tc.type: FUNC
1781 */
1782 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty056, TestSize.Level1)
1783 {
1784 /**
1785 * @tc.steps: step1. initialize parameters.
1786 */
1787 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1788
1789 /**
1790 * @tc.steps: step2. set isCNode false.
1791 * @tc.expected: expect result is false.
1792 */
1793 frameNode->setIsCNode(false);
__anon943640bd1202() 1794 std::function<bool()> func = []() -> bool { return true; };
__anon943640bd1302(const std::string& key) 1795 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1796 return "getFuncA";
1797 };
1798 frameNode->SetJSCustomProperty(func, getFuncA);
1799 frameNode->setIsCNode(true);
1800 std::string getValue;
1801 bool result = frameNode->GetCapiCustomProperty("key", getValue);
1802 EXPECT_EQ(result, false);
1803 }
1804
1805 /**
1806 * @tc.name: FrameNodeGetJSCustomProperty058
1807 * @tc.desc: Test GetJSCustomProperty getCustomProperty_ value getFuncA, expect result value getFuncA.
1808 * @tc.type: FUNC
1809 */
1810 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty058, TestSize.Level1)
1811 {
1812 /**
1813 * @tc.steps: step1. initialize parameters.
1814 */
1815 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1816
1817 /**
1818 * @tc.steps: step2. set getCustomProperty_ value getFuncA.
1819 * @tc.expected: expect result value getFuncA.
1820 */
__anon943640bd1402() 1821 std::function<bool()> func = []() -> bool { return true; };
__anon943640bd1502(const std::string& key) 1822 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1823 return "getFuncA";
1824 };
1825 frameNode->SetJSCustomProperty(func, getFuncA);
1826 frameNode->SetCustomPropertyMapFlagByKey("key");
1827 std::string getValue;
1828 bool result = frameNode->GetJSCustomProperty("key", getValue);
1829 EXPECT_EQ(result, true);
1830 EXPECT_EQ(getValue, "getFuncA");
1831 }
1832
1833 /**
1834 * @tc.name: FrameNodeGetJSCustomProperty059
1835 * @tc.desc: Test GetJSCustomProperty getCustomProperty_ nullptr
1836 * @tc.type: FUNC
1837 */
1838 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty059, TestSize.Level1)
1839 {
1840 /**
1841 * @tc.steps: step1. initialize parameters.
1842 */
1843 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1844
1845 /**
1846 * @tc.steps: step2. set getCustomProperty_ nullptr
1847 * @tc.expected: expect result GetJSCustomProperty false.
1848 */
__anon943640bd1602() 1849 std::function<bool()> func = []() -> bool { return true; };
1850 frameNode->SetJSCustomProperty(func, nullptr);
1851 frameNode->SetCustomPropertyMapFlagByKey("key");
1852 std::string getValue;
1853 bool result = frameNode->GetJSCustomProperty("key", getValue);
1854 EXPECT_EQ(result, false);
1855 }
1856
1857 /**
1858 * @tc.name: FrameNodeGetCapiCustomProperty060
1859 * @tc.desc: Test GetCapiCustomProperty no key value value value added.
1860 * @tc.type: FUNC
1861 */
1862 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty060, TestSize.Level1)
1863 {
1864 /**
1865 * @tc.steps: step1. initialize parameters.
1866 */
1867 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1868
1869 /**
1870 * @tc.steps: step2. GetCapiCustomProperty
1871 * @tc.expected: expect result value false.
1872 */
1873 frameNode->setIsCNode(false);
1874 std::string value;
1875 bool result = frameNode->GetCapiCustomProperty("key", value);
1876 EXPECT_EQ(result, false);
1877 }
1878
1879 /**
1880 * @tc.name: FrameNodeGetCapiCustomProperty061
1881 * @tc.desc: Test GetCapiCustomProperty the key value value value exists.
1882 * @tc.type: FUNC
1883 */
1884 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty061, TestSize.Level1)
1885 {
1886 /**
1887 * @tc.steps: step1. initialize parameters.
1888 */
1889 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1890
1891 /**
1892 * @tc.steps: step2. add the key value as value1.
1893 * @tc.expected: expect result value1.
1894 */
1895 frameNode->setIsCNode(true);
1896 frameNode->AddCustomProperty("key", "value1");
1897 std::string value;
1898 bool result = frameNode->GetCapiCustomProperty("key", value);
1899 EXPECT_EQ(result, true);
1900 EXPECT_EQ(value, "value1");
1901 }
1902
1903 /**
1904 * @tc.name: FrameNodeGetCapiCustomProperty062
1905 * @tc.desc: Test GetCapiCustomProperty the key value does not exist.
1906 * @tc.type: FUNC
1907 */
1908 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty062, TestSize.Level1)
1909 {
1910 /**
1911 * @tc.steps: step1. initialize parameters.
1912 */
1913 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1914
1915 /**
1916 * @tc.steps: step2. set key is value1
1917 * @tc.expected: expect result value.
1918 */
1919 frameNode->setIsCNode(true);
1920 frameNode->AddCustomProperty("key", "value1");
1921 std::string value;
1922 bool result = frameNode->GetCapiCustomProperty("key1", value);
1923 EXPECT_EQ(result, false);
1924 }
1925
1926 /**
1927 * @tc.name: FrameNodeRemoveCustomProperty063
1928 * @tc.desc: Test RemoveCustomProperty.
1929 * @tc.type: FUNC
1930 */
1931 HWTEST_F(FrameNodeTestNg, FrameNodeRemoveCustomProperty063, TestSize.Level1)
1932 {
1933 /**
1934 * @tc.steps: step1. initialize parameters.
1935 */
1936 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1937
1938 /**
1939 * @tc.steps: step2. set key is value1, remove key.
1940 * @tc.expected: expect result false.
1941 */
1942 frameNode->setIsCNode(true);
1943 frameNode->AddCustomProperty("key", "value1");
1944 frameNode->RemoveCustomProperty("key");
1945 std::string value;
1946 bool result = frameNode->GetCapiCustomProperty("key", value);
1947 EXPECT_EQ(result, false);
1948 }
1949
1950 /**
1951 * @tc.name: FrameNodeTestNg_OnAutoEventParamUpdate
1952 * @tc.desc: Test frame node method
1953 * @tc.type: FUNC
1954 */
1955 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg_OnAutoEventParamUpdate, TestSize.Level1)
1956 {
1957 /**
1958 * @tc.steps: step1. create framenode and initialize the params used in Test.
1959 */
1960 auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
1961 node->AttachToMainTree();
1962 node->GetRenderContext()->RequestNextFrame();
1963 EXPECT_TRUE(node->IsOnMainTree());
1964
1965 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1966 const RefPtr<FrameNode> parentNode =
1967 FrameNode::CreateFrameNode("RelativeContainer", nodeId, AceType::MakeRefPtr<Pattern>(), true);
1968 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
1969
1970 /**
1971 * @tc.steps: step2. call OnAutoEventParamUpdate.
1972 * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
1973 * this parentNode is not MarkDirtyNode
1974 */
1975 node->OnAutoEventParamUpdate("{\"$origin\":\"Tom\",\"$exposureCfg\":{\"ratio\":0.8,\"duration\":3000}}");
1976 EXPECT_EQ(parentNode->GetTag(), "RelativeContainer");
1977 }
1978
1979 /**
1980 * @tc.name: FrameNodeTestNg065
1981 * @tc.desc: Test GetIsLayoutNode.
1982 * @tc.type: FUNC
1983 */
1984 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg065, TestSize.Level1)
1985 {
1986 auto frameNode =
1987 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1988 bool isLayoutNode = false;
1989 frameNode->isLayoutNode_ = isLayoutNode;
1990 bool result = frameNode->GetIsLayoutNode();
1991 EXPECT_EQ(result, isLayoutNode);
1992
1993 isLayoutNode = false;
1994 frameNode->isLayoutNode_ = isLayoutNode;
1995 result = frameNode->GetIsLayoutNode();
1996 EXPECT_EQ(result, isLayoutNode);
1997 }
1998
1999 /**
2000 * @tc.name: FrameNodeTestNg066
2001 * @tc.desc: Test GetIsFind.
2002 * @tc.type: FUNC
2003 */
2004 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg066, TestSize.Level1)
2005 {
2006 auto frameNode =
2007 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2008 bool isFind = true;
2009 frameNode->isFind_ = isFind;
2010 bool result = frameNode->GetIsFind();
2011 EXPECT_EQ(result, isFind);
2012
2013 isFind = false;
2014 frameNode->isFind_ = isFind;
2015 result = frameNode->GetIsFind();
2016 EXPECT_EQ(result, isFind);
2017 }
2018
2019 /**
2020 * @tc.name: FrameNodeTestNg067
2021 * @tc.desc: Test SetIsFind.
2022 * @tc.type: FUNC
2023 */
2024 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg067, TestSize.Level1)
2025 {
2026 auto frameNode =
2027 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2028 bool isFind = true;
2029 frameNode->SetIsFind(isFind);
2030 bool result = frameNode->GetIsFind();
2031 EXPECT_EQ(result, isFind);
2032
2033 isFind = false;
2034 frameNode->SetIsFind(isFind);
2035 result = frameNode->GetIsFind();
2036 EXPECT_EQ(result, isFind);
2037 }
2038
2039 /**
2040 * @tc.name: FrameNodeTestNg069
2041 * @tc.desc: Test CheckAutoSave.
2042 * @tc.type: FUNC
2043 */
2044 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg069, TestSize.Level1)
2045 {
2046 auto frameNode =
2047 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2048
2049 auto pattern_ = frameNode->GetPattern();
2050 EXPECT_NE(pattern_, nullptr);
2051 bool result = frameNode->CheckAutoSave();
2052 EXPECT_EQ(result, pattern_->CheckAutoSave());
2053
2054 pattern_ = nullptr;
2055 result = frameNode->CheckAutoSave();
2056 EXPECT_FALSE(result);
2057 }
2058
2059 /**
2060 * @tc.name: FrameNodeTestNg070
2061 * @tc.desc: Test RenderCustomChild.
2062 * @tc.type: FUNC
2063 */
2064 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg070, TestSize.Level1)
2065 {
2066 auto frameNode =
2067 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2068
2069 int64_t deadline = 1;
2070 bool result = frameNode->RenderCustomChild(deadline);
2071 bool res = frameNode->UINode::RenderCustomChild(deadline);
2072 EXPECT_EQ(result, res);
2073 }
2074
2075 /**
2076 * @tc.name: FrameNodeTestNg081
2077 * @tc.desc: Test GetOrCreateCommonNode.
2078 * @tc.type: FUNC
2079 */
2080 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg081, TestSize.Level1)
2081 {
2082 bool isLayoutNode = true;
2083 auto commonOne =
__anon943640bd1702() 2084 FrameNode::GetOrCreateCommonNode("commonOne", 1, isLayoutNode, []() { return AceType::MakeRefPtr<Pattern>(); });
2085 auto commonTwo = FrameNode::GetFrameNode("commonTwo", 1);
2086 EXPECT_NE(commonOne, nullptr);
2087 EXPECT_EQ(commonTwo, nullptr);
2088
2089 /**
2090 * @tc.steps: step2. create FrameNode and set a callback
2091 * @tc.expect: call DestroyCallback while object is destroyed
2092 */
2093 bool flag = true;
2094 auto commonThree = FrameNode::GetOrCreateFrameNode("commonOne", 1, nullptr);
2095 ASSERT_NE(commonThree, nullptr);
__anon943640bd1802() 2096 commonThree->PushDestroyCallbackWithTag([&flag]() { flag = !flag; }, "");
2097 commonThree = nullptr;
2098 EXPECT_FALSE(flag);
2099 }
2100
2101 /**
2102 * @tc.name: FrameNodeTestNg082
2103 * @tc.desc: Test CreateCommonNode.
2104 * @tc.type: FUNC
2105 */
2106 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg082, TestSize.Level1)
2107 {
2108 /* @tc.steps: step1. create commonNode and initialize the params used in Test.
2109 */
2110 bool isLayoutNode = false;
2111 auto commonNode =
2112 FrameNode::CreateCommonNode("CommonChildNode", 20, isLayoutNode, AceType::MakeRefPtr<Pattern>(), true);
2113 commonNode->AttachToMainTree();
2114 commonNode->GetRenderContext()->RequestNextFrame();
2115 EXPECT_TRUE(commonNode->IsOnMainTree());
2116
2117 int32_t commonNodeId = ElementRegister::GetInstance()->MakeUniqueId();
2118 const RefPtr<FrameNode> commonParentNode =
2119 FrameNode::CreateCommonNode("CommonRelativeContainer", commonNodeId, isLayoutNode,
2120 AceType::MakeRefPtr<Pattern>(), true);
2121 commonNode->SetParent(AceType::WeakClaim(AceType::RawPtr(commonParentNode)));
2122
2123 /**
2124 * @tc.steps: step2. call OnInspectorIdUpdate .
2125 * @tc.expect: this commonParentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
2126 * this commonParentNode is not MarkDirtyNode
2127 */
2128 commonNode->OnInspectorIdUpdate("CommonRelativeContainer");
2129 EXPECT_EQ(commonParentNode->GetTag(), "CommonRelativeContainer");
2130 }
2131
2132 /**
2133 * @tc.name: FrameNodeTestNg083
2134 * @tc.desc: Test RequestParentDirty.
2135 * @tc.type: FUNC
2136 */
2137 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg083, TestSize.Level1)
2138 {
2139 /* @tc.steps: step1. create frameNodeTemp and initialize the params used in Test.
2140 */
2141 auto frameNodeTemp =
2142 FrameNode::CreateFrameNode("root", 2, AceType::MakeRefPtr<Pattern>(), true);
2143
2144 /**
2145 * @tc.steps: step2. frameNodeTemp is a root node
2146 * @tc.expect: frameNodeTemp call RequestParentDirty
2147 */
2148 bool result = frameNodeTemp->FrameNode::RequestParentDirty();
2149 EXPECT_FALSE(result);
2150
2151 /**
2152 * @tc.steps: step3. create childNode and added to frameNodeTemp
2153 * @tc.expect: childNode call RequestParentDirty
2154 */
2155 auto childNode =
2156 FrameNode::CreateFrameNode("main", 3, AceType::MakeRefPtr<Pattern>(), false);
2157 frameNodeTemp->AddChild(childNode);
2158 result = childNode->FrameNode::RequestParentDirty();
2159 EXPECT_TRUE(result);
2160 }
2161
2162 /**
2163 * @tc.name: FrameNodeTestNg084
2164 * @tc.desc: Test AddCustomProperty.
2165 * @tc.type: FUNC
2166 */
2167 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg084, TestSize.Level1)
2168 {
2169 /* @tc.steps: step1. create frameNode and initialize the params used in Test.
2170 */
2171 auto frameNode =
2172 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2173 /**
2174 * @tc.steps: step2. setIsCNode true
2175 * @tc.expect: frameNode call AddCustomProperty
2176 */
2177 frameNode->setIsCNode(true);
2178 frameNode->AddCustomProperty("key1", "value1");
2179 std::string value;
2180 bool result = frameNode->GetCapiCustomProperty("key1", value);
2181 EXPECT_EQ(result, true);
2182 EXPECT_EQ(value, "value1");
2183 }
2184
2185 /**
2186 * @tc.name: FrameNodeTestNg085
2187 * @tc.desc: Test GetActiveChildren.
2188 * @tc.type: FUNC
2189 */
2190 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg085, TestSize.Level1)
2191 {
2192 /* @tc.steps: step1. create frameNode and initialize the params used in Test.
2193 */
2194 auto frameNode =
2195 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2196 /**
2197 * @tc.steps: step2. create childNode1 and added to frameNode
2198 * @tc.expect: childNode1 setActive true
2199 */
2200 auto childNode1 =
2201 FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), false);
2202 frameNode->AddChild(childNode1);
2203 childNode1->SetActive(true);
2204 /**
2205 * @tc.steps: step3. create childNode2 and added to frameNode
2206 * @tc.expect: childNode2 setActive false
2207 */
2208 auto childNode2 =
2209 FrameNode::CreateFrameNode("main", 3, AceType::MakeRefPtr<Pattern>(), false);
2210 frameNode->AddChild(childNode2);
2211 childNode2->SetActive(false);
2212
2213 std::list<RefPtr<FrameNode>> list = frameNode->FrameNode::GetActiveChildren();
2214 EXPECT_EQ(list.size(), 1);
2215 }
2216
2217 /**
2218 * @tc.name: FrameNodeTestNg086
2219 * @tc.desc: Test ChildrenUpdatedFrom.
2220 * @tc.type: FUNC
2221 */
2222 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg086, TestSize.Level1)
2223 {
2224 /* @tc.steps: step1. create frameNode and initialize the params used in Test.
2225 */
2226 auto frameNode =
2227 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2228 /**
2229 * @tc.steps: step2. childrenUpdatedFrom_ >= 0 and index > childrenUpdatedFrom_
2230 * @tc.expect: childrenUpdatedFrom_ do not change
2231 */
2232 frameNode->childrenUpdatedFrom_ = 0;
2233 int32_t index = 2;
2234 frameNode->FrameNode::ChildrenUpdatedFrom(index);
2235 int32_t currentIndex = frameNode->childrenUpdatedFrom_;
2236 EXPECT_EQ(currentIndex, 0);
2237
2238 /**
2239 * @tc.steps: step3. childrenUpdatedFrom_ >= 0 and index < childrenUpdatedFrom_
2240 * @tc.expect: childrenUpdatedFrom_ is set to index
2241 */
2242 frameNode->childrenUpdatedFrom_ = 3;
2243 frameNode->FrameNode::ChildrenUpdatedFrom(index);
2244 currentIndex = frameNode->childrenUpdatedFrom_;
2245 EXPECT_EQ(currentIndex, 2);
2246
2247 /**
2248 * @tc.steps: step3. childrenUpdatedFrom_ < 0
2249 * @tc.expect: childrenUpdatedFrom_ is set to index
2250 */
2251 frameNode->childrenUpdatedFrom_ = -1;
2252 frameNode->FrameNode::ChildrenUpdatedFrom(index);
2253 currentIndex = frameNode->childrenUpdatedFrom_;
2254 EXPECT_EQ(currentIndex, 2);
2255 }
2256
2257 /**
2258 * @tc.name: FrameNodeTestNg091
2259 * @tc.desc: Test AddFrameNodeChangeInfoFlag
2260 * @tc.type: FUNC
2261 */
2262 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg091, TestSize.Level1)
2263 {
2264 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2265 frameNode->AddFrameNodeChangeInfoFlag(1 << 5);
2266 EXPECT_EQ(frameNode->GetChangeInfoFlag(), 1 << 5);
2267 }
2268
2269 /**
2270 * @tc.name: FrameNodeTestNg092
2271 * @tc.desc: Test AddFrameNodeChangeInfoFlag
2272 * @tc.type: FUNC
2273 */
2274 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg092, TestSize.Level1)
2275 {
2276 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2277 frameNode->AddFrameNodeChangeInfoFlag(0);
2278 EXPECT_EQ(frameNode->GetChangeInfoFlag(), 0);
2279 }
2280
2281 /**
2282 * @tc.name: FrameNodeTestNg093
2283 * @tc.desc: Test SetPaintNode
2284 * @tc.type: FUNC
2285 */
2286 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg093, TestSize.Level1)
2287 {
2288 auto paintNode = FrameNode::CreateFrameNode("paintNodeTag", 2, AceType::MakeRefPtr<Pattern>(), true);
2289 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2290 frameNode->SetPaintNode(paintNode);
2291 EXPECT_EQ(frameNode->GetPaintNode(), paintNode);
2292 }
2293
2294 /**
2295 * @tc.name: FrameNodeTestNg094
2296 * @tc.desc: Test GetPaintNode
2297 * @tc.type: FUNC
2298 */
2299 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg094, TestSize.Level1)
2300 {
2301 RefPtr<Pattern> pattern = AceType::MakeRefPtr<Pattern>();
2302 FrameNode frameNode("testTag", 1, pattern);
2303 RefPtr<FrameNode> paintNode = AceType::MakeRefPtr<FrameNode>("paintNodeTag", 2, pattern);
2304 frameNode.SetPaintNode(paintNode);
2305 const RefPtr<FrameNode>& result = frameNode.GetPaintNode();
2306 ASSERT_EQ(result, paintNode);
2307 }
2308
2309 /**
2310 * @tc.name: FrameNodeTestNg095
2311 * @tc.desc: Test SetFocusPaintNode
2312 * @tc.type: FUNC
2313 */
2314 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg095, TestSize.Level1)
2315 {
2316 auto focusPaintNode = FrameNode::CreateFrameNode("focusTag", 2, AceType::MakeRefPtr<Pattern>(), true);
2317 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2318 frameNode->SetFocusPaintNode(focusPaintNode);
2319 EXPECT_EQ(frameNode->GetFocusPaintNode(), focusPaintNode);
2320 }
2321
2322 /**
2323 * @tc.name: FrameNodeTestNg096
2324 * @tc.desc: Test GetFocusPaintNode
2325 * @tc.type: FUNC
2326 */
2327 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg096, TestSize.Level1)
2328 {
2329 auto focusPaintNode = FrameNode::CreateFrameNode("focusPaintNode", 2, AceType::MakeRefPtr<Pattern>(), true);
2330 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2331 frameNode->SetFocusPaintNode(focusPaintNode);
2332 EXPECT_EQ(frameNode->GetFocusPaintNode(), focusPaintNode);
2333 }
2334
2335 /**
2336 * @tc.name: FrameNodeTestNg097
2337 * @tc.desc: Test IsDrawFocusOnTop
2338 * @tc.type: FUNC
2339 */
2340 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg097, TestSize.Level1)
2341 {
2342 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2343 EXPECT_FALSE(frameNode->IsDrawFocusOnTop());
2344 }
2345
2346 /**
2347 * @tc.name: FrameNodeTestNg098
2348 * @tc.desc: Test IsDrawFocusOnTop true value
2349 * @tc.type: FUNC
2350 */
2351 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg098, TestSize.Level1)
2352 {
2353 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2354 auto accessibilityProperty = frameNode->GetAccessibilityProperty<NG::AccessibilityProperty>();
2355 ASSERT_NE(accessibilityProperty, nullptr);
2356 accessibilityProperty->SetFocusDrawLevel(static_cast<int32_t>(FocusDrawLevel::TOP));
2357 EXPECT_TRUE(frameNode->IsDrawFocusOnTop());
2358 }
2359
2360 /**
2361 * @tc.name: FrameNodeGetOrCreate001
2362 * @tc.desc: Test FrameNodeGetOrCreate001.
2363 * @tc.type: FUNC
2364 */
2365 HWTEST_F(FrameNodeTestNg, FrameNodeGetOrCreate001, TestSize.Level1)
2366 {
2367 /**
2368 * @tc.steps: step1. create root node.
2369 * @tc.expected: expect is not nullptr.
2370 */
2371 auto frameNode1 = FrameNode::CreateFrameNodeWithTree("Column", 1, AceType::MakeRefPtr<Pattern>());
2372 EXPECT_NE(frameNode1, nullptr);
2373 EXPECT_EQ(frameNode1->GetId(), 1);
2374
2375 /**
2376 * @tc.steps: step2. attach node to main tree.
2377 * @tc.expected: expect IsOnMainTree is true.
2378 */
2379 EXPECT_EQ(frameNode1->IsOnMainTree(), false);
2380 frameNode1->AttachToMainTree();
2381 EXPECT_EQ(frameNode1->IsOnMainTree(), true);
__anon943640bd1902null2382 auto pattern = [] {return AceType::MakeRefPtr<Pattern>();};
2383 /**
2384 * @tc.steps: step3. create child node.
2385 * @tc.expected: expect is not nullptr.
2386 */
2387 auto frameNode2 = FrameNode::GetOrCreateFrameNode("Column", 2, pattern);
2388 EXPECT_NE(frameNode2, nullptr);
2389 EXPECT_EQ(frameNode2->GetId(), 2);
2390 /**
2391 * @tc.steps: step4. create same node.
2392 * @tc.expected: node2 == node 3.
2393 */
2394 auto frameNode3 = FrameNode::GetOrCreateFrameNode("Column", 2, pattern);
2395 EXPECT_EQ(frameNode3, frameNode2);
2396 /**
2397 * @tc.steps: step5. create child node.
2398 * @tc.expected: expect is not nullptr.
2399 */
2400 frameNode1->AddChild(frameNode2, 1, true);
2401 auto children = frameNode1->GetChildren();
2402 EXPECT_EQ(children.size(), 1);
2403 }
2404
2405 /**
2406 * @tc.name: FrameNodeGetOrCreate002
2407 * @tc.desc: Test FrameNodeGetOrCreate002.
2408 * @tc.type: FUNC
2409 */
2410 HWTEST_F(FrameNodeTestNg, FrameNodeGetOrCreate002, TestSize.Level1)
2411 {
2412 /**
2413 * @tc.steps: step1. create root node.
2414 * @tc.expected: expect is not nullptr.
2415 */
2416 auto frameNode1 = FrameNode::CreateFrameNodeWithTree("Row", 1, AceType::MakeRefPtr<Pattern>());
2417 EXPECT_NE(frameNode1, nullptr);
2418 EXPECT_EQ(frameNode1->GetId(), 1);
2419 /**
2420 * @tc.steps: step2. create child node.
2421 * @tc.expected: expect is not nullptr.
2422 */
__anon943640bd1a02() 2423 auto frameNode2 = FrameNode::GetOrCreateFrameNode("Row", 2, []() { return AceType::MakeRefPtr<Pattern>(); });
2424
2425 EXPECT_NE(frameNode2, nullptr);
2426 EXPECT_EQ(frameNode2->GetId(), 2);
2427 frameNode1->AddChild(frameNode2, 1, true);
2428 /**
2429 * @tc.steps: step3. create child node.
2430 * @tc.expected: expect is not nullptr.
2431 */
__anon943640bd1b02() 2432 auto frameNode3 = FrameNode::GetOrCreateFrameNode("Row", 3, []() { return AceType::MakeRefPtr<Pattern>(); });
2433 EXPECT_NE(frameNode2, nullptr);
2434 EXPECT_EQ(frameNode2->GetId(), 2);
2435 frameNode2->AddChild(frameNode2, 1, true);
2436
2437 /**
2438 * @tc.steps: step4. test GetFrameNodeOnly
2439 * @tc.expected: expect is not nullptr.
2440 */
2441 auto frameNode4 = FrameNode::GetFrameNodeOnly("Row", 3);
2442 EXPECT_NE(frameNode4, nullptr);
2443 /**
2444 * @tc.steps: step5. test GetFrameNodeChildByIndex
2445 * @tc.expected: expect is not nullptr.
2446 */
2447 auto frameNode5 = frameNode1->GetFrameNodeChildByIndex(0);
2448 EXPECT_NE(frameNode5, nullptr);
2449 auto frameNode6 = frameNode2->GetFrameNodeChildByIndex(0);
2450 EXPECT_EQ(frameNode6, nullptr);
2451 /**
2452 * @tc.steps: step6. test FrameCount
2453 * @tc.expected: expect is not nullptr.
2454 */
2455 auto frameCount = frameNode1->FrameCount();
2456 EXPECT_EQ(frameCount, 1);
2457 }
2458
2459 /**
2460 * @tc.name: FrameNodeTestNG089
2461 * @tc.desc: Test DumpSimplifyCommonInfo.
2462 * @tc.type: FUNC
2463 */
2464 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG089, TestSize.Level1)
2465 {
2466 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2467 const NG::RectF rect = { 10.0f, 20.0f, 30.0f, 40.0f };
2468 frameNode->GetGeometryNode()->frame_.rect_ = rect;
2469 frameNode->GetRenderContext()->UpdateBackgroundColor(Color::BLUE);
2470 frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE);
2471 frameNode->GetLayoutProperty()->SetLayoutRect(rect);
2472 frameNode->GetLayoutProperty()->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
2473 frameNode->GetLayoutProperty()->padding_ = std::make_unique<PaddingProperty>();
2474 LayoutConstraintF constraint;
2475 constraint.selfIdealSize.SetHeight(30.0f);
2476 constraint.selfIdealSize.SetWidth(20.0f);
2477 frameNode->GetLayoutProperty()->contentConstraint_ = constraint;
2478 LayoutConstraintF layoutConstraint;
2479 layoutConstraint.percentReference.SetWidth(10.0f);
2480 frameNode->GetGeometryNode()->SetParentLayoutConstraint(layoutConstraint);
2481 std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
2482 frameNode->DumpInfo(json);
2483 std::string res = json->ToString();
2484
2485 EXPECT_EQ(res.length() < 9000, true);
2486 }
2487
2488 /**
2489 * @tc.name: FrameNodeTestNG300
2490 * @tc.desc: Test GetPatternTypeName.
2491 * @tc.type: FUNC
2492 */
2493 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG300, TestSize.Level1)
2494 {
2495 /**
2496 * @tc.steps: step1. create frameNode.
2497 * @tc.expected: expect is not nullptr.
2498 */
2499 auto frameNode =
__anon943640bd1c02() 2500 FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
2501 EXPECT_NE(frameNode, nullptr);
2502 /**
2503 * @tc.steps: step2. create pattern_.
2504 * @tc.expected: make sure pattern_ is not nullptr.
2505 */
2506 auto textPattern = AceType::MakeRefPtr<TextPattern>();
2507 frameNode->pattern_ = textPattern;
2508 auto res = frameNode->GetPatternTypeName();
2509 EXPECT_NE(res, nullptr);
2510 }
2511
2512 /**
2513 * @tc.name: FrameNodeTestNG301
2514 * @tc.desc: Test GetLayoutPropertyTypeName.
2515 * @tc.type: FUNC
2516 */
2517 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG301, TestSize.Level1)
2518 {
2519 /**
2520 * @tc.steps: step1. create frameNode.
2521 * @tc.expected: expect is not nullptr.
2522 */
2523 auto frameNode =
2524 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2525 EXPECT_NE(frameNode, nullptr);
2526 /**
2527 * @tc.steps: step2. create layoutProperty_ is nullptr.
2528 * @tc.expected: expect is not nullptr.
2529 */
2530 frameNode->layoutProperty_ = nullptr;
2531 auto res = frameNode->GetLayoutPropertyTypeName();
2532 EXPECT_EQ(res, nullptr);
2533 }
2534
2535 /**
2536 * @tc.name: FrameNodeTestNG302
2537 * @tc.desc: Test GetLayoutPropertyTypeName.
2538 * @tc.type: FUNC
2539 */
2540 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG302, TestSize.Level1)
2541 {
2542 /**
2543 * @tc.steps: step1. create frameNode.
2544 * @tc.expected: expect is not nullptr.
2545 */
2546 auto frameNode =
2547 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2548 EXPECT_NE(frameNode, nullptr);
2549 /**
2550 * @tc.steps: step2. create layoutProperty_ is nullptr.
2551 * @tc.expected: expect is not nullptr.
2552 */
2553 frameNode->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
2554 auto res = frameNode->GetLayoutPropertyTypeName();
2555 EXPECT_NE(res, nullptr);
2556 }
2557
2558 /**
2559 * @tc.name: FrameNodeTestNG303
2560 * @tc.desc: Test GetLayoutPropertyTypeName.
2561 * @tc.type: FUNC
2562 */
2563 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG303, TestSize.Level1)
2564 {
2565 /**
2566 * @tc.steps: step1. create frameNode.
2567 * @tc.expected: expect is not nullptr.
2568 */
2569 auto frameNode =
2570 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2571 EXPECT_NE(frameNode, nullptr);
2572 /**
2573 * @tc.steps: step2. create layoutProperty_ is nullptr.
2574 * @tc.expected: expect is not nullptr.
2575 */
2576 BorderWidthProperty overCountBorderWidth;
2577 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP));
2578 frameNode->layoutProperty_->UpdateBorderWidth(overCountBorderWidth);
2579 auto res = frameNode->GetLayoutPropertyTypeName();
2580 EXPECT_NE(res, nullptr);
2581 }
2582
2583 /**
2584 * @tc.name: FrameNodeTestNG304
2585 * @tc.desc: Test GetPaintPropertyTypeName.
2586 * @tc.type: FUNC
2587 */
2588 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG304, TestSize.Level1)
2589 {
2590 /**
2591 * @tc.steps: step1. create frameNode.
2592 * @tc.expected: expect is not nullptr.
2593 */
2594 auto frameNode =
2595 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2596 EXPECT_NE(frameNode, nullptr);
2597 /**
2598 * @tc.steps: step2. create paintProperty_ is nullptr.
2599 * @tc.expected: expect is not nullptr.
2600 */
2601 frameNode->paintProperty_ = nullptr;
2602 auto res = frameNode->GetPaintPropertyTypeName();
2603 EXPECT_EQ(res, nullptr);
2604 }
2605
2606 /**
2607 * @tc.name: FrameNodeTestNG305
2608 * @tc.desc: Test GetPaintPropertyTypeName.
2609 * @tc.type: FUNC
2610 */
2611 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG305, TestSize.Level1)
2612 {
2613 /**
2614 * @tc.steps: step1. create frameNode.
2615 * @tc.expected: expect is not nullptr.
2616 */
2617 auto frameNode =
2618 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2619 EXPECT_NE(frameNode, nullptr);
2620 /**
2621 * @tc.steps: step2. create paintProperty_ is nullptr.
2622 * @tc.expected: expect is not nullptr.
2623 */
2624 RefPtr<MarqueePaintProperty> marqueePaintProperty = AceType::MakeRefPtr<MarqueePaintProperty>();
2625 frameNode->paintProperty_ = marqueePaintProperty;
2626 auto res = frameNode->GetPaintPropertyTypeName();
2627 EXPECT_NE(res, nullptr);
2628 }
2629
2630 /**
2631 * @tc.name: FrameNodeTestNG306
2632 * @tc.desc: Test GetKitNode.
2633 * @tc.type: FUNC
2634 */
2635 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG306, TestSize.Level1)
2636 {
2637 /**
2638 * @tc.steps: step1. create frameNode.
2639 * @tc.expected: expect is not nullptr.
2640 */
2641 auto frameNode =
2642 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2643 EXPECT_NE(frameNode, nullptr);
2644 /**
2645 * @tc.steps: step2. create kitNode_ is nullptr.
2646 * @tc.expected: expect is nullptr.
2647 */
2648 frameNode->kitNode_ = nullptr;
2649 auto res = frameNode->GetKitNode();
2650 EXPECT_EQ(res, nullptr);
2651 }
2652
2653 /**
2654 * @tc.name: FrameNodeTestNG307
2655 * @tc.desc: Test GetKitNode.
2656 * @tc.type: FUNC
2657 */
2658 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG307, TestSize.Level1)
2659 {
2660 /**
2661 * @tc.steps: step1. create frameNode.
2662 * @tc.expected: expect is not nullptr.
2663 */
2664 auto frameNode =
2665 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2666 EXPECT_NE(frameNode, nullptr);
2667 /**
2668 * @tc.steps: step2. create kitNode_ is nullptr.
2669 * @tc.expected: expect is nullptr.
2670 */
2671 auto kitNode = frameNode->GetKitNode();
2672 auto kitNodeToFrameNode = AceType::DynamicCast<Kit::FrameNodeImpl>(kitNode);
2673 frameNode->SetKitNode(kitNodeToFrameNode);
2674 auto res = frameNode->GetKitNode();
2675 EXPECT_EQ(res, kitNodeToFrameNode);
2676 }
2677
2678 /**
2679 * @tc.name: FrameNodeTestNG308
2680 * @tc.desc: Test GetKitNode.
2681 * @tc.type: FUNC
2682 */
2683 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG308, TestSize.Level1)
2684 {
2685 /**
2686 * @tc.steps: step1. create frameNode.
2687 * @tc.expected: expect is not nullptr.
2688 */
2689 auto frameNode =
2690 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2691 EXPECT_NE(frameNode, nullptr);
2692 /**
2693 * @tc.steps: step2. create kitNode_ is not nullptr.
2694 * @tc.expected: expect is not nullptr.
2695 */
2696 auto pattern = AceType::MakeRefPtr<Pattern>();
2697 int32_t nodeId = 1;
2698 auto kitNode = NG::ColumnModelNG::CreateFrameNode(nodeId);
2699 auto kitNodeToFrameNode = AceType::DynamicCast<Kit::FrameNodeImpl>(kitNode);
2700 frameNode->SetKitNode(kitNodeToFrameNode);
2701 auto res = frameNode->GetKitNode();
2702 EXPECT_EQ(res, kitNodeToFrameNode);
2703 }
2704
2705 /**
2706 * @tc.name: FrameNodeTestNG309
2707 * @tc.desc: Test GetKitNode.
2708 * @tc.type: FUNC
2709 */
2710 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG309, TestSize.Level1)
2711 {
2712 /**
2713 * @tc.steps: step1. create frameNode.
2714 * @tc.expected: expect is not nullptr.
2715 */
2716 auto frameNode =
2717 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2718 EXPECT_NE(frameNode, nullptr);
2719 /**
2720 * @tc.steps: step2. create geometryNode_ is nullptr.
2721 * @tc.expected: expect is nullptr.
2722 */
2723 auto geometryNode= nullptr;
2724 frameNode->SetGeometryNode(geometryNode);
2725 auto res = frameNode->GetGeometryNode();
2726 EXPECT_EQ(res, nullptr);
2727 }
2728
2729 /**
2730 * @tc.name: FrameNodeTestNG310
2731 * @tc.desc: Test GetKitNode.
2732 * @tc.type: FUNC
2733 */
2734 HWTEST_F(FrameNodeTestNg, FrameNodeTestNG310, TestSize.Level1)
2735 {
2736 /**
2737 * @tc.steps: step1. create frameNode.
2738 * @tc.expected: expect is not nullptr.
2739 */
2740 auto frameNode =
2741 FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2742 EXPECT_NE(frameNode, nullptr);
2743 /**
2744 * @tc.steps: step2. create geometryNode_ is nullptr.
2745 * @tc.expected: expect is nullptr.
2746 */
2747 auto geometryNode= AceType::MakeRefPtr<GeometryNode>();
2748 frameNode->SetGeometryNode(geometryNode);
2749 auto res = frameNode->GetGeometryNode();
2750 EXPECT_NE(res, nullptr);
2751 EXPECT_EQ(res, geometryNode);
2752 }
2753
2754 /**
2755 * @tc.name: FrameNodeTestNg311
2756 * @tc.desc: Test OnAttachAdapter.
2757 * @tc.type: FUNC
2758 */
2759 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg311, TestSize.Level1)
2760 {
2761 auto frameNode =
2762 FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
2763 auto childNode1 =
2764 FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), false);
2765 auto pattern_ = frameNode->GetPattern();
2766 EXPECT_NE(pattern_, nullptr);
2767 bool result = pattern_->OnAttachAdapter(frameNode, childNode1);
2768 EXPECT_EQ(result, false);
2769 pattern_ = nullptr;
2770 }
2771
2772 /**
2773 * @tc.name: FrameNodeTestNg312
2774 * @tc.desc: Test CallAIFunction.
2775 * @tc.type: FUNC
2776 */
2777 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg312, TestSize.Level1)
2778 {
2779 /**
2780 * @tc.steps1: initialize parameters.
2781 */
2782 static constexpr uint32_t AI_CALL_SUCCESS = 0;
2783 static constexpr uint32_t AI_CALLER_INVALID = 1;
2784 static constexpr uint32_t AI_CALL_FUNCNAME_INVALID = 2;
2785 auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<Pattern>(), true);
2786
2787 /**
2788 * @tc.steps2: create AI helper
2789 */
2790 auto myAICaller = std::make_shared<TestAICaller>();
2791
2792 /**
2793 * @tc.steps3: call ai function without set
2794 * @tc.excepted: step3 return AI_CALLER_INVALID means AI helper not setted.
2795 */
2796 EXPECT_EQ(frameNode->CallAIFunction("Success", ""), AI_CALLER_INVALID);
2797
2798 /**
2799 * @tc.steps4: set ai helper instance.
2800 * @tc.excepted: step4 AI helper not null and setted success.
2801 */
2802 frameNode->SetAICallerHelper(myAICaller);
2803 EXPECT_EQ(frameNode->aiCallerHelper_, myAICaller);
2804
2805 /**
2806 * @tc.steps5: call ai function success after set.
2807 * @tc.excepted: step5 ai function called success.
2808 */
2809 EXPECT_EQ(frameNode->CallAIFunction("Success", "params1: 1"), AI_CALL_SUCCESS);
2810
2811 /**
2812 * @tc.steps6: call invalid function after set.
2813 * @tc.excepted: step6 ai function not found and return AI_CALL_FUNCNAME_INVALID.
2814 */
2815 EXPECT_EQ(frameNode->CallAIFunction("OTHERFunction", "params1: 1"), AI_CALL_FUNCNAME_INVALID);
2816 }
2817 } // namespace OHOS::Ace::NG
2818