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
17 using namespace testing;
18 using namespace testing::ext;
19
20 namespace OHOS::Ace::NG {
SetUpTestSuite()21 void FrameNodeTestNg::SetUpTestSuite()
22 {
23 MockPipelineContext::SetUp();
24 }
25
TearDownTestSuite()26 void FrameNodeTestNg::TearDownTestSuite()
27 {
28 MockPipelineContext::TearDown();
29 }
30
31 /**
32 * @tc.name: FrameNodeTestNg001
33 * @tc.desc: Test frame node method
34 * @tc.type: FUNC
35 */
36 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg001, TestSize.Level1)
37 {
__anond6e917530102() 38 auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
39 auto two = FrameNode::GetFrameNode("two", 1);
40 EXPECT_NE(one, nullptr);
41 EXPECT_EQ(two, nullptr);
42
43 /**
44 * @tc.steps: step2. create FrameNode and set a callback
45 * @tc.expect: call DestroyCallback while object is destroyed
46 */
47 bool flag = false;
48 auto three = FrameNode::GetOrCreateFrameNode("one", 1, nullptr);
49 ASSERT_NE(three, nullptr);
__anond6e917530202() 50 three->PushDestroyCallback([&flag]() { flag = !flag; });
51 three = nullptr;
52 EXPECT_TRUE(flag);
53 }
54
55 /**
56 * @tc.name: FrameNodeTestNg002
57 * @tc.desc: Test frame node method
58 * @tc.type: FUNC
59 */
60 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg002, TestSize.Level1)
61 {
__anond6e917530302() 62 auto one = FrameNode::GetOrCreateFrameNode("one", 1, []() { return AceType::MakeRefPtr<Pattern>(); });
63 one->SetParent(FRAME_NODE_PARENT);
64 auto two = FrameNode::GetFrameNode("two", 1);
65 EXPECT_NE(one, nullptr);
66 EXPECT_EQ(two, nullptr);
67 ElementRegister::GetInstance()->Clear();
68 }
69
70 /**
71 * @tc.name: FrameNodeTestNg004
72 * @tc.desc: Test frame node method
73 * @tc.type: FUNC
74 */
75 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg004, TestSize.Level1)
76 {
77 /**
78 * @tc.steps: step1. create framenode and initialize the params used in Test.
79 */
80 auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
81 node->AttachToMainTree();
82 node->GetRenderContext()->RequestNextFrame();
83 EXPECT_TRUE(node->IsOnMainTree());
84
85 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
86 const RefPtr<FrameNode> parentNode =
87 FrameNode::CreateFrameNode("RelativeContainer", nodeId, AceType::MakeRefPtr<Pattern>(), true);
88 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
89
90 /**
91 * @tc.steps: step2. call OnInspectorIdUpdate .
92 * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
93 * this parentNode is not MarkDirtyNode
94 */
95 node->OnInspectorIdUpdate("RelativeContainer");
96 EXPECT_EQ(parentNode->GetTag(), "RelativeContainer");
97 }
98
99 /**
100 * @tc.name: FrameNodeTestNg007
101 * @tc.desc: Test frame node method
102 * @tc.type: FUNC
103 */
104 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg007, TestSize.Level1)
105 {
106 /**
107 * @tc.steps: step 1. create framenode and initialize the params used in Test.
108 */
109 auto node = FrameNode::CreateFrameNode("childNode", 10, AceType::MakeRefPtr<Pattern>(), true);
110
111 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
112 const RefPtr<FrameNode> parentNode =
113 FrameNode::CreateFrameNode("parent", nodeId, AceType::MakeRefPtr<Pattern>(), true);
114 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
115
116 const RefPtr<FrameNode> overlayNode =
117 FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
118
119 /**
120 * @tc.steps: step 2. call OnInspectorIdUpdate .
121 * @tc.expect: this parentNode is MarkDirtyNode, but this Tag() != "RelativeContainer"
122 * this parentNode is not MarkDirtyNode
123 */
124
125 node->SetParent(AceType::WeakClaim(AceType::RawPtr(parentNode)));
126 node->OnInspectorIdUpdate("RelativeContainer");
127 EXPECT_EQ(parentNode->GetTag(), "parent");
128
129 /**
130 * @tc.steps: step 3. call LayoutOverlay .
131 * @tc.expect: FrameRect of overlayNode is 0.
132 */
133 node->SetOverlayNode(overlayNode);
134 node->LayoutOverlay();
135
136 auto layoutProperty = overlayNode->GetLayoutProperty();
137 layoutProperty->positionProperty_ = std::make_unique<PositionProperty>();
138 node->LayoutOverlay();
139 EXPECT_EQ(overlayNode->GetGeometryNode()->GetFrameRect().GetX(), 0);
140
141 /**
142 * @tc.steps: step 4. call GetFrameChildByIndex .
143 * @tc.expect: index == 0 return uiNode, index != 0 return null
144 */
145 EXPECT_TRUE(node->GetFrameChildByIndex(0, false));
146 EXPECT_FALSE(node->GetFrameChildByIndex(1, false));
147
148 /**
149 * @tc.steps: step 5. call GetBaselineDistance .
150 * @tc.expect: node has not child return 0. if node has child return childBaseline of child
151 */
152 EXPECT_EQ(node->GetBaselineDistance(), 0);
153 node->AddChild(FRAME_NODE);
154 EXPECT_EQ(node->GetBaselineDistance(), 0);
155 auto nodeLayoutProperty = node->GetLayoutProperty();
156 nodeLayoutProperty->geometryTransition_ =
157 ElementRegister::GetInstance()->GetOrCreateGeometryTransition("test", false, true);
158 node->Layout();
159 EXPECT_FALSE(node->IsRootMeasureNode());
160 node->SetRootMeasureNode();
161 node->Layout();
162 EXPECT_TRUE(node->IsRootMeasureNode());
163 }
164
165 /**
166 * @tc.name: FrameNodeTestNg008
167 * @tc.desc: Test frame node method
168 * @tc.type: FUNC
169 */
170 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg008, TestSize.Level1)
171 {
172 /**
173 * @tc.steps: step 1. create framenode and initialize the params used in Test.
174 */
175 RefPtr<NG::DrawModifier> drawModifier = AceType::MakeRefPtr<NG::DrawModifier>();
176 ASSERT_NE(drawModifier, nullptr);
177
178 /**
179 * @tc.steps: step 2. call get function .
180 * @tc.expect: expect the return value to be correct.
181 */
182 EXPECT_TRUE(FRAME_NODE->IsSupportDrawModifier());
183
184 /**
185 * @tc.steps: step 3. call GetContentModifier when drawModifier is null.
186 * @tc.expect: expect the return value to be correct.
187 */
188 EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
189
190 /**
191 * @tc.steps: step 4. Nodes created by virtual classes, call GetContentModifier when drawModifier is null.
192 * @tc.expect: expect the return value to be correct.
193 */
194 FRAME_NODE->SetDrawModifier(drawModifier);
195 EXPECT_EQ(FRAME_NODE->GetContentModifier(), nullptr);
196
197 /**
198 * @tc.steps: step 5. Nodes created by virtual classes, call SetRemoveCustomProperties.
199 * @tc.expect: expect call successfully.
200 */
__anond6e917530402() 201 FRAME_NODE->SetRemoveCustomProperties([]() -> void {});
202 }
203
204 /**
205 * @tc.name: FrameNodeTouchTest001
206 * @tc.desc: Test frame node method
207 * @tc.type: FUNC
208 */
209 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest, TestSize.Level1)
210 {
211 /**
212 * @tc.steps: step1. create framenode and initialize the params used in Test.
213 */
214 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
215 node->AttachToMainTree();
216 node->GetOrCreateGestureEventHub();
217 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
218 node->renderContext_ = mockRenderContext;
219 node->SetActive(true);
220 auto localPoint = PointF(10, 10);
221 auto parentLocalPoint = PointF(10, 10);
222 const NG::PointF point { 10, 10 };
223 const PointF parentLocalPointOne = { 10, 10 };
224 TouchRestrict touchRestrict = { TouchRestrict::NONE };
225 auto globalPoint = PointF(10, 10);
226 auto touchTestResult = std::list<RefPtr<TouchEventTarget>>();
227 ResponseLinkResult responseLinkResult;
228
229 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
230 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
231
232 /**
233 * @tc.steps: step2. create childnode
234 */
235 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true);
236 childNode->SetExclusiveEventForChild(true);
237 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>();
238 childNode->renderContext_ = mockRenderContextforChild;
239 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
240 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
241 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
242 childNode->GetOrCreateGestureEventHub();
243 childNode->SetActive(true);
244 auto childEventHub = childNode->GetOrCreateGestureEventHub();
245
246 /**
247 * @tc.steps: step3. add childnode to the framenode
248 */
249 std::list<RefPtr<FrameNode>> children;
250 children.push_back(childNode);
251 node->frameChildren_ = { children.begin(), children.end() };
252
253 /**
254 * @tc.steps: step4. create grandChildNode
255 */
256
257 auto grandChildNode = FrameNode::CreateFrameNode("main", 3, AceType::MakeRefPtr<Pattern>(), true);
258 grandChildNode->SetExclusiveEventForChild(true);
259 grandChildNode->renderContext_ = mockRenderContextforChild;
260 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
261 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_))
262 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint)));
263 grandChildNode->GetOrCreateGestureEventHub();
264 grandChildNode->SetActive(true);
265 auto grandChildEventHub = grandChildNode->GetOrCreateGestureEventHub();
266
267 /**
268 * @tc.steps: step5. add grandChildNode to the childnode
269 */
270 std::list<RefPtr<FrameNode>> grandChild;
271 grandChild.push_back(grandChildNode);
272 childNode->frameChildren_ = { grandChild.begin(), grandChild.end() };
273
274 /**
275 * @tc.steps: step6. compare hitTestResult which is retured in function TouchTest whith expected value.
276 * @tc.expected: step6. hitTestResult is STOP_BUBBLING when hitTestModeofGrandChilds or hitTestModeofChild is
277 * HTMBLOCK;
278 */
279 HitTestMode hitTestModeofGrandChilds[] = { HitTestMode::HTMBLOCK, HitTestMode::HTMDEFAULT };
280 HitTestMode hitTestModeofChilds[] = { HitTestMode::HTMDEFAULT, HitTestMode::HTMBLOCK, HitTestMode::HTMTRANSPARENT,
281 HitTestMode::HTMNONE, HitTestMode::HTMTRANSPARENT_SELF };
282 bool isStacks[] = { true, false };
283
284 for (auto hitTestModeofGrandChild : hitTestModeofGrandChilds) {
285 grandChildEventHub->SetHitTestMode(hitTestModeofGrandChild);
286 for (auto isStack : isStacks) {
287 for (auto hitTestModeofChild : hitTestModeofChilds) {
288 childNode->SetExclusiveEventForChild(isStack);
289 childEventHub->SetHitTestMode(hitTestModeofChild);
290 auto result = childNode->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
291 touchTestResult, 0, responseLinkResult, true);
292 result = node->TouchTest(globalPoint, parentLocalPointOne, parentLocalPointOne, touchRestrict,
293 touchTestResult, 0, responseLinkResult, true);
294 }
295 }
296 }
297 }
298
299 /**
300 * @tc.name: FrameNodeTestNg005
301 * @tc.desc: Test frame node method
302 * @tc.type: FUNC
303 */
304 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg005, TestSize.Level1)
305 {
306 /**
307 * @tc.steps: step1. callback function.
308 * @tc.expected: expect The function is run ok.
309 */
310 auto one = FrameNode::CreateFrameNodeWithTree("main", 10, AceType::MakeRefPtr<Pattern>());
311 EXPECT_NE(one, nullptr);
312
313 MeasureProperty calcLayoutConstraint;
314 FRAME_NODE->UpdateLayoutConstraint(std::move(calcLayoutConstraint));
315 EXPECT_EQ(FRAME_NODE2->layoutProperty_->propertyChangeFlag_, 1);
316
317 FRAME_NODE2->needSyncRenderTree_ = true;
318 FRAME_NODE2->RebuildRenderContextTree();
319 EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
320
321 /**
322 * @tc.steps: step 2. create and set overlayNode.
323 * @tc.expect:cover branch overlayNode is not null and function is run ok.
324 */
325 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
326 const RefPtr<FrameNode> overlayNode =
327 FrameNode::CreateFrameNode("overlayNode", nodeId, AceType::MakeRefPtr<Pattern>(), true);
328 FRAME_NODE2->SetOverlayNode(overlayNode);
329 FRAME_NODE2->RebuildRenderContextTree();
330 EXPECT_FALSE(FRAME_NODE2->needSyncRenderTree_);
331
332 FRAME_NODE2->OnMountToParentDone();
333
334 FRAME_NODE2->FlushUpdateAndMarkDirty();
335
336 std::list<RefPtr<FrameNode>> visibleList;
337 FRAME_NODE2->isActive_ = true;
338 FRAME_NODE2->OnGenerateOneDepthVisibleFrame(visibleList);
339 EXPECT_TRUE(FRAME_NODE2->IsVisible());
340
341 FRAME_NODE2->OnGenerateOneDepthAllFrame(visibleList);
342 EXPECT_EQ(visibleList.size(), 2);
343
344 auto pattern = FRAME_NODE2->GetPattern();
345 EXPECT_EQ(pattern, 1);
346
347 auto atomicNode = FRAME_NODE2->IsAtomicNode();
348 EXPECT_TRUE(atomicNode);
349
350 auto hitTestMode = FRAME_NODE2->GetHitTestMode();
351 EXPECT_EQ(hitTestMode, HitTestMode::HTMDEFAULT);
352
353 auto touchable = FRAME_NODE2->GetTouchable();
354 EXPECT_TRUE(touchable);
355
356 const PointF globalPoint;
357 const PointF parentLocalPoint;
358 MouseTestResult onMouseResult;
359 MouseTestResult onHoverResult;
360 RefPtr<FrameNode> hoverNode;
361 auto mouse = FRAME_NODE2->MouseTest(globalPoint, parentLocalPoint, onMouseResult, onHoverResult, hoverNode);
362 EXPECT_EQ(mouse, HitTestResult::BUBBLING);
363 }
364
365 /**
366 * @tc.name: FrameNodeTestNg006
367 * @tc.desc: Test frame node method
368 * @tc.type: FUNC
369 */
370 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg006, TestSize.Level1)
371 {
372 /**
373 * @tc.steps: step1. callback function.
374 * @tc.expected: expect The function is run ok.
375 */
376 FRAME_NODE2->OnWindowShow();
377 FRAME_NODE2->OnWindowHide();
378 FRAME_NODE2->OnWindowFocused();
379 FRAME_NODE2->OnWindowUnfocused();
380 FRAME_NODE2->OnWindowSizeChanged(1, 1, WindowSizeChangeReason::CUSTOM_ANIMATION);
381
382 OffsetF Offset = { 0, 0 };
383 FRAME_NODE2->SetParent(FRAME_NODE3);
384 auto relativeOffset = FRAME_NODE2->GetTransformRelativeOffset();
385 EXPECT_EQ(relativeOffset, Offset);
386
387 FRAME_NODE2->SetParent(FRAME_NODE3);
388 auto rectOffset = FRAME_NODE2->GetPaintRectOffset(true);
389 EXPECT_EQ(rectOffset, Offset);
390
391 FRAME_NODE2->OnNotifyMemoryLevel(true);
392
393 auto childrenCount = FRAME_NODE2->GetAllDepthChildrenCount();
394 EXPECT_EQ(childrenCount, 1);
395
396 DimensionRect dimensionRect;
397 FRAME_NODE2->AddHotZoneRect(dimensionRect);
398 FRAME_NODE2->RemoveLastHotZoneRect();
399 EXPECT_NE(FRAME_NODE2->eventHub_, nullptr);
400
401 FRAME_NODE->ProcessOffscreenNode(FRAME_NODE3);
402 FRAME_NODE->GetTransformRectRelativeToWindow();
403 FRAME_NODE->GetPaintRectOffsetToPage();
404
405 float x = 1.0;
406 float y = 1.0;
407 auto Position = FRAME_NODE->FindChildByPosition(x, y);
408 EXPECT_EQ(Position, nullptr);
409
410 FRAME_NODE->ProvideRestoreInfo();
411 auto immediately = FRAME_NODE->RemoveImmediately();
412 EXPECT_TRUE(immediately);
413 }
414
415 /**
416 * @tc.name: FrameNodeTestNg_DumpInfo006
417 * @tc.desc: Test frame node method
418 * @tc.type: FUNC
419 */
420 HWTEST_F(FrameNodeTestNg, FrameNodeDumpInfo006, TestSize.Level1)
421 {
422 /**
423 * @tc.steps: step1. callback DumpInfo
424 * @tc.expected: expect The function is run ok.
425 */
426 LayoutProperty layoutProperty;
427 FRAME_NODE->DumpInfo();
428
429 FRAME_NODE->layoutProperty_->UpdatePadding(PaddingPropertyT<CalcLength>());
430 FRAME_NODE->layoutProperty_->GetPaddingProperty();
431 FRAME_NODE->DumpInfo();
432 EXPECT_EQ(layoutProperty.padding_, nullptr);
433
434 FRAME_NODE->layoutProperty_->UpdateMargin(PaddingProperty());
435 FRAME_NODE->layoutProperty_->GetMarginProperty();
436 FRAME_NODE->DumpInfo();
437 EXPECT_EQ(layoutProperty.margin_, nullptr);
438
439 FRAME_NODE->layoutProperty_->UpdateBorderWidth(BorderWidthPropertyT<Dimension>());
440 FRAME_NODE->layoutProperty_->GetBorderWidthProperty();
441 FRAME_NODE->DumpInfo();
442 EXPECT_EQ(layoutProperty.borderWidth_, nullptr);
443
444 /**
445 * @tc.steps: step2. set layoutConstraintF_ an geometryNode_'sParentLayoutConstraint
446 and call DumpInfo
447 * @tc.expected: expect The function is run ok.
448 */
449 FRAME_NODE->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
450 auto layoutConstraintF_ = LayoutConstraintF();
451 FRAME_NODE->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
452 FRAME_NODE->DumpInfo();
453 EXPECT_EQ(layoutProperty.calcLayoutConstraint_, nullptr);
454 }
455
456 /**
457 * @tc.name: FrameNodeTestNg_ToJsonValue007
458 * @tc.desc: Test frame node method
459 * @tc.type: FUNC
460 */
461 HWTEST_F(FrameNodeTestNg, FrameNodeToJsonValue007, TestSize.Level1)
462 {
463 /**
464 * @tc.steps: step1. build a object to jsonValue
465 * @tc.expected: expect The function is run ok.
466 */
467 auto gestureEventHub = FRAME_NODE->GetOrCreateGestureEventHub();
468
469 std::vector<DimensionRect> responseRegion;
470 responseRegion.push_back(DimensionRect());
471 gestureEventHub->SetResponseRegion(responseRegion);
472
473 auto jsonValue = JsonUtil::Create(true);
474 FRAME_NODE->ToJsonValue(jsonValue, filter);
475 EXPECT_TRUE(jsonValue);
476
477 /**
478 * @tc.steps: step2. build a object to jsonValue and call FromJson
479 * @tc.expected: expect The function is run ok.
480 */
481 FRAME_NODE->FromJson(jsonValue);
482 FRAME_NODE->renderContext_ = nullptr;
483 FRAME_NODE->eventHub_->focusHub_ = nullptr;
484 auto jsonValue2 = JsonUtil::Create(true);
485 FRAME_NODE->ToJsonValue(jsonValue2, filter);
486 FRAME_NODE->FromJson(jsonValue2);
487 EXPECT_TRUE(jsonValue2);
488 }
489
490 /**
491 * @tc.name: FrameNodeTestNg_OnAttachToMainTree008
492 * @tc.desc: Test frame node method
493 * @tc.type: FUNC
494 */
495 HWTEST_F(FrameNodeTestNg, FrameNodeOnAttachToMainTree008, TestSize.Level1)
496 {
497 /**
498 * @tc.steps: step1. build a object to OnAttachToMainTree
499 * @tc.expected: expect The function is run ok.
500 */
501 FRAME_NODE2->OnAttachToMainTree(true);
502
503 auto request = FRAME_NODE2->hasPendingRequest_ = true;
504 FRAME_NODE2->OnAttachToMainTree(true);
505 EXPECT_TRUE(request);
506
507 /**
508 * @tc.steps: step2 set PositionProperty of FRAME_NODE2 and call OnAttachToMainTree
509 * @tc.expected: expect The function is run ok.
510 */
511 auto& posProperty = FRAME_NODE2->renderContext_->GetOrCreatePositionProperty();
512 posProperty->UpdateOffset(OffsetT<Dimension>()); // OffsetT<Dimension>
513 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
514 auto testNode_ = TestNode::CreateTestNode(100);
515 FRAME_NODE_PARENT->SetParent(testNode_);
516 FRAME_NODE2->OnAttachToMainTree(true);
517 EXPECT_TRUE(request);
518 }
519
520 /**
521 * @tc.name: FrameNodeTestNg_NotifyVisibleChange009
522 * @tc.desc: Test frame node method
523 * @tc.type: FUNC
524 */
525 HWTEST_F(FrameNodeTestNg, FrameNodeNotifyVisibleChange009, TestSize.Level1)
526 {
527 /**
528 * @tc.steps: step1. build a object to NotifyVisibleChange
529 * @tc.expected: expect The FRAME_NODE2 is not nullptr.
530 */
531 FRAME_NODE2->AddChild(FRAME_NODE3);
532 FRAME_NODE2->NotifyVisibleChange(VisibleType::VISIBLE, VisibleType::INVISIBLE);
533 FRAME_NODE2->Clean();
534 EXPECT_NE(FRAME_NODE2, nullptr);
535 }
536
537 /**
538 * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread0010
539 * @tc.desc: Test frame node method
540 * @tc.type: FUNC
541 */
542 HWTEST_F(FrameNodeTestNg, FrameNodeSwapDirtyLayoutWrapperOnMainThread0010, TestSize.Level1)
543 {
544 /**
545 * @tc.steps: step1. build a object to SwapDirtyLayoutWrapperOnMainThread
546 */
547 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
548
549 /**
550 * @tc.steps: step2. callback SwapDirtyLayoutWrapperOnMainThread
551 * @tc.expected: expect layoutWrapper is not nullptr.
552 */
553 FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
554 EXPECT_NE(layoutWrapper, nullptr);
555 layoutWrapper->SetActive(true);
556 auto test = FRAME_NODE2->IsActive();
557
558 /**
559 * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
560 * @tc.expected: expect isActive_ is false.
561 */
562 FRAME_NODE2->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
563 EXPECT_TRUE(test);
564 }
565
566 /**
567 * @tc.name: FrameNodeTestNg_AdjustGridOffset0011
568 * @tc.desc: Test frame node method
569 * @tc.type: FUNC
570 */
571 HWTEST_F(FrameNodeTestNg, FrameNodeAdjustGridOffset0011, TestSize.Level1)
572 {
573 /**
574 * @tc.steps: step1. build a object to AdjustGridOffset
575 * @tc.expected: expect active is true.
576 */
577 FRAME_NODE2->SetActive(true);
578 bool active = FRAME_NODE2->IsActive();
579 FRAME_NODE2->AdjustGridOffset();
580 EXPECT_TRUE(active);
581
582 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
583 FRAME_NODE2->GetAncestorNodeOfFrame();
584
585 FRAME_NODE2->SetActive(false);
586
587 /**
588 * @tc.steps: step2. build a object to AdjustGridOffset
589 * @tc.expected: expect active1 is false.
590 */
591 bool active1 = FRAME_NODE2->IsActive();
592 FRAME_NODE2->AdjustGridOffset();
593 EXPECT_FALSE(active1);
594 }
595
596 /**
597 * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback0012
598 * @tc.desc: Test frame node method
599 * @tc.type: FUNC
600 */
601 HWTEST_F(FrameNodeTestNg, FrameNodeSetOnAreaChangeCallback0012, TestSize.Level1)
602 {
603 /**
604 * @tc.steps: step1. build a object to SetOnAreaChangeCallback
605 * @tc.expected: expect The function is run ok.
606 */
607 OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anond6e917530502(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 608 const OffsetF& origin) {};
609 FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
610 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
611 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
612
613 /**
614 * @tc.steps: step2.test while callback is nullptr
615 * @tc.expected:expect The function is run ok.
616 */
617 FRAME_NODE2->lastFrameRect_ = nullptr;
618 FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
619 FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
620 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
621 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
622 }
623
624 /**
625 * @tc.name: FrameNodeTestNg_TriggerOnAreaChangeCallback0013
626 * @tc.desc: Test frame node method
627 * @tc.type: FUNC
628 */
629 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerOnAreaChangeCallback0013, TestSize.Level1)
630 {
631 /**
632 * @tc.steps: step1. set a flag and init a callback(onAreaChanged)
633 */
634 bool flag = false;
635 OnAreaChangedFunc onAreaChanged = [&flag](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anond6e917530602(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 636 const OffsetF& origin) { flag = !flag; };
637
638 /**
639 * @tc.steps: step2. call TriggerOnAreaChangeCallback before set callback
640 * @tc.expected: expect flag is still false
641 */
642 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_1);
643 EXPECT_FALSE(flag);
644
645 /**
646 * @tc.steps: step3.set callback and release lastParentOffsetToWindow_
647 * @tc.expected: expect flag is still false
648 */
649 FRAME_NODE2->eventHub_->SetOnAreaChanged(std::move(onAreaChanged));
650 FRAME_NODE2->lastParentOffsetToWindow_ = nullptr;
651 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_2);
652 EXPECT_FALSE(flag);
653
654 /**
655 * @tc.steps: step4. release lastFrameRect_
656 * @tc.expected: expect flag is still false
657 */
658 FRAME_NODE2->lastFrameRect_ = nullptr;
659 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_3);
660 EXPECT_FALSE(flag);
661
662 /**
663 * @tc.steps: step5.set lastParentOffsetToWindow_ and lastFrameRect_
664 * @tc.expected: expect flag is still false
665 */
666 FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
667 FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
668 FRAME_NODE2->TriggerOnAreaChangeCallback(TIMESTAMP_4);
669 EXPECT_FALSE(flag);
670 }
671
672 /**
673 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback0014
674 * @tc.desc: Test frame node method
675 * @tc.type: FUNC
676 */
677 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback0014, TestSize.Level1)
678 {
679 /**
680 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
681 * @tc.expected: expect The function is run ok.
682 */
683 VisibleCallbackInfo callbackInfo;
684 FRAME_NODE2->SetVisibleAreaUserCallback({ 0.0f }, callbackInfo);
685 FRAME_NODE2->TriggerVisibleAreaChangeCallback(1);
686
687 /**
688 * @tc.steps: step2. callback SetParent
689 * @tc.expected: expect parent is same with parentNode.
690 */
691 auto parentNode = AceType::MakeRefPtr<FrameNode>("test", -1, AceType::MakeRefPtr<Pattern>(), false);
692 FRAME_NODE2->SetParent(FRAME_NODE3);
693 FRAME_NODE2->TriggerVisibleAreaChangeCallback(2);
694 auto parent = FRAME_NODE2->GetParent();
695 EXPECT_EQ(parent, 1);
696
697 auto parentNode1 = FrameNode::CreateFrameNode("parent", 2, AceType::MakeRefPtr<Pattern>());
698 RefPtr<FrameNode> frameNodes[3] = { parentNode1, nullptr, nullptr };
699 FRAME_NODE2->TriggerVisibleAreaChangeCallback(3);
700 auto parent1 = FRAME_NODE2->GetParent();
701 EXPECT_EQ(parent1, 1);
702
703 FRAME_NODE2->lastVisibleRatio_ = 1.0;
704 FRAME_NODE2->TriggerVisibleAreaChangeCallback(4);
705
706 /**
707 * @tc.steps: step3. set onShow_ and call TriggerVisibleAreaChangeCallback
708 * @tc.expected: expect GetOnShow is true and lastVisibleRatio_ is zero.
709 */
710 auto context = PipelineContext::GetCurrentContext();
711 context->onShow_ = true;
712 FRAME_NODE2->TriggerVisibleAreaChangeCallback(5);
713 auto testNode_ = TestNode::CreateTestNode(101);
714 FRAME_NODE3->SetParent(testNode_);
715 FRAME_NODE3->isActive_ = true;
716 FRAME_NODE2->TriggerVisibleAreaChangeCallback(6);
717 FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::INVISIBLE);
718 FRAME_NODE2->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
719 FRAME_NODE2->isActive_ = true;
720 FRAME_NODE2->TriggerVisibleAreaChangeCallback(7);
721 FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE);
722 FRAME_NODE2->TriggerVisibleAreaChangeCallback(8);
723 EXPECT_TRUE(context->GetOnShow());
724 }
725
726 /**
727 * @tc.name: FrameNodeTestNg_CreateLayoutTask0015
728 * @tc.desc: Test frame node method
729 * @tc.type: FUNC
730 */
731 HWTEST_F(FrameNodeTestNg, FrameNodeCreateLayoutTask0015, TestSize.Level1)
732 {
733 /**
734 * @tc.steps: step1. build a object to CreateLayoutTask
735 * @tc.expected: expect The function is run ok.
736 */
737 FRAME_NODE2->isLayoutDirtyMarked_ = true;
738 FRAME_NODE2->CreateLayoutTask(true);
739 EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
740
741 FRAME_NODE2->CreateLayoutTask(true);
742
743 FRAME_NODE2->isLayoutDirtyMarked_ = true;
744 FRAME_NODE2->CreateLayoutTask(false);
745 EXPECT_FALSE(FRAME_NODE2->isLayoutDirtyMarked_);
746 }
747
748 /**
749 * @tc.name: FrameNodeTestNg_CreateRenderTask0016
750 * @tc.desc: Test frame node method
751 * @tc.type: FUNC
752 */
753 HWTEST_F(FrameNodeTestNg, FrameNodeCreateRenderTask0016, TestSize.Level1)
754 {
755 /**
756 * @tc.steps: step1. build a object to CreateRenderTask
757 * @tc.expected: expect The isRenderDirtyMarked_ is false.
758 */
759 FRAME_NODE2->isRenderDirtyMarked_ = true;
760 FRAME_NODE2->CreateRenderTask(true);
761 EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
762
763 FRAME_NODE2->isRenderDirtyMarked_ = true;
764 FRAME_NODE2->CreateRenderTask(false);
765
766 FRAME_NODE2->CreateRenderTask(true);
767 EXPECT_FALSE(FRAME_NODE2->isRenderDirtyMarked_);
768 }
769
770 /**
771 * @tc.name: FrameNodeTestNg_GetParentGlobalOffset0017
772 * @tc.desc: Test frame node method
773 * @tc.type: FUNC
774 */
775 HWTEST_F(FrameNodeTestNg, FrameNodeGetParentGlobalOffset0017, TestSize.Level1)
776 {
777 /**
778 * @tc.steps: step1. SetParent for FRAME_NODE2 and callback GetParentGlobalOffset.
779 * @tc.expected: expect The parent is same with 1.
780 */
781 FRAME_NODE2->GetParentGlobalOffset();
782 FRAME_NODE2->SetParent(FRAME_NODE_PARENT);
783 auto parent = FRAME_NODE2->GetAncestorNodeOfFrame();
784 FRAME_NODE2->GetParentGlobalOffset();
785 EXPECT_EQ(parent, 1);
786 }
787
788 /**
789 * @tc.name: FrameNodeTestNg_UpdateLayoutPropertyFlag0018
790 * @tc.desc: Test frame node method
791 * @tc.type: FUNC
792 */
793 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateLayoutPropertyFlag0018, TestSize.Level1)
794 {
795 /**
796 * @tc.steps: step1.call back UpdateLayoutPropertyFlag.
797 * @tc.expected: expect selfFlag is same with PROPERTY_UPDATE_BY_CHILD_REQUEST.
798 */
799 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
800 auto selfFlag = FRAME_NODE2->layoutProperty_->GetPropertyChangeFlag();
801 FRAME_NODE2->UpdateLayoutPropertyFlag();
802 EXPECT_EQ(selfFlag, PROPERTY_UPDATE_BY_CHILD_REQUEST);
803
804 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
805 FRAME_NODE2->AddChild(FRAME_NODE3);
806 FRAME_NODE2->UpdateLayoutPropertyFlag();
807 FRAME_NODE2->Clean();
808 }
809
810 /**
811 * @tc.name: FrameNodeTestNg_UpdateChildrenLayoutWrapper0019
812 * @tc.desc: Test frame node method
813 * @tc.type: FUNC
814 */
815 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateChildrenLayoutWrapper0019, TestSize.Level1)
816 {
817 /**
818 * @tc.steps: step1. AddChild for FRAME_NODE2 and callback UpdateChildrenLayoutWrapper.
819 * @tc.expected: expect The UpdateLayoutWrapper is true.
820 */
821 FRAME_NODE2->AddChild(FRAME_NODE3);
822 FRAME_NODE2->UpdateChildrenLayoutWrapper(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true), true, true);
823 FRAME_NODE2->Clean();
824 EXPECT_TRUE(FRAME_NODE2->UpdateLayoutWrapper(nullptr, true, true));
825 }
826
827 /**
828 * @tc.name: FrameNodeTestNg_MarkModifyDone0021
829 * @tc.desc: Test frame node method
830 * @tc.type: FUNC
831 */
832 HWTEST_F(FrameNodeTestNg, FrameNodeMarkModifyDone0021, TestSize.Level1)
833 {
834 /**
835 * @tc.steps: step1. build a object to MarkModifyDone.
836 * @tc.expected:expect The function is run ok.
837 */
838 FRAME_NODE2->MarkModifyDone();
839 EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
840 FRAME_NODE2->isRestoreInfoUsed_ = true;
841 FRAME_NODE2->MarkModifyDone();
842 EXPECT_TRUE(FRAME_NODE2->isRestoreInfoUsed_);
843 }
844
845 /**
846 * @tc.name: FrameNodeTestNg_MarkNeedRender0022
847 * @tc.desc: Test frame node method
848 * @tc.type: FUNC
849 */
850 HWTEST_F(FrameNodeTestNg, FrameNodeMarkNeedRender0022, TestSize.Level1)
851 {
852 /**
853 * @tc.steps: step1. callback MarkNeedRenderOnly.
854 * @tc.expected: expect The function is run ok.
855 */
856 FRAME_NODE2->MarkNeedRenderOnly();
857 auto test = FRAME_NODE2->isRenderDirtyMarked_ = false;
858 auto test1 = FRAME_NODE2->isLayoutDirtyMarked_ = false;
859 FRAME_NODE2->MarkNeedRender(false);
860 FRAME_NODE2->MarkNeedRender(true);
861 EXPECT_FALSE(test);
862 EXPECT_FALSE(test1);
863 }
864
865 /**
866 * @tc.name: FrameNodeTestNg_IsNeedRequestParentMeasure0023
867 * @tc.desc: Test frame node method
868 * @tc.type: FUNC
869 */
870 HWTEST_F(FrameNodeTestNg, FrameNodeIsNeedRequestParentMeasure0023, TestSize.Level1)
871 {
872 /**
873 * @tc.steps: step1. callback IsNeedRequestParentMeasure.
874 * @tc.expected: expect The function return value is true.
875 */
876 auto test = FRAME_NODE2->IsNeedRequestParentMeasure();
877 EXPECT_TRUE(test);
878
879 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
880 FRAME_NODE2->IsNeedRequestParentMeasure();
881
882 FRAME_NODE2->layoutProperty_->propertyChangeFlag_ = PROPERTY_UPDATE_BY_CHILD_REQUEST;
883 FRAME_NODE2->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
884 auto test1 = FRAME_NODE2->IsNeedRequestParentMeasure();
885 EXPECT_TRUE(test1);
886 }
887
888 /**
889 * @tc.name: FrameNodeTestNg_OnGenerateOneDepthVisibleFrameWithTransition0024
890 * @tc.desc: Test frame node method
891 * @tc.type: FUNC
892 */
893 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithTransition0024, TestSize.Level1)
894 {
895 /**
896 * @tc.steps: step1. callback OnGenerateOneDepthVisibleFrameWithTransition.
897 * @tc.expected: expect The function is run ok.
898 */
899 std::list<RefPtr<FrameNode>> visibleList;
900 FRAME_NODE2->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
901
902 /**
903 * @tc.steps: step2.push the framenode to visibleList and callback OnGenerateOneDepthVisibleFrameWithTransition
904 * @tc.expected: expect visibleList.size is 3.
905 */
906 visibleList.push_back(FRAME_NODE);
907 FRAME_NODE3->OnGenerateOneDepthVisibleFrameWithTransition(visibleList);
908 EXPECT_EQ(visibleList.size(), 3);
909 }
910
911 /**
912 * @tc.name: FrameNodeTestNg_IsOutOfTouchTestRegion0025
913 * @tc.desc: Test frame node method
914 * @tc.type: FUNC
915 */
916 HWTEST_F(FrameNodeTestNg, FrameNodeIsOutOfTouchTestRegion0025, TestSize.Level1)
917 {
918 /**
919 * @tc.steps: step1. callback IsOutOfTouchTestRegion.
920 * @tc.expected: expect The function return value is true.
921 */
922 PointF pointF;
923 std::vector<RectF> rectF;
924 TouchEvent touchEvent;
925 auto test = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
926 EXPECT_TRUE(test);
927
928 auto test1 = FRAME_NODE2->InResponseRegionList(pointF, rectF);
929 auto test2 = FRAME_NODE2->IsOutOfTouchTestRegion(std::move(pointF), touchEvent);
930 EXPECT_FALSE(test1);
931 EXPECT_TRUE(test2);
932 }
933
934 /**
935 * @tc.name: FrameNodeTestNg_TouchTest0026
936 * @tc.desc: Test frame node method
937 * @tc.type: FUNC
938 */
939 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest0026, TestSize.Level1)
940 {
941 /**
942 * @tc.steps: step1. callback TouchTest.
943 * @tc.expected: expect The function return value is true.
944 */
945 PointF globalPoint;
946 PointF parentLocalPoint;
947 TouchRestrict touchRestrict;
948 TouchTestResult result;
949 ResponseLinkResult responseLinkResult;
950 SystemProperties::debugEnabled_ = true;
951 FRAME_NODE2->TouchTest(
952 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
953
954 SystemProperties::debugEnabled_ = false;
955 FRAME_NODE2->TouchTest(
956 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
957
958 /**
959 * @tc.steps: step2. set isActive_ and IsEnabled is false.
960 * @tc.expected: expect The function return value is OUT_OF_REGION.
961 */
962 FRAME_NODE2->isActive_ = false;
963 FRAME_NODE2->eventHub_->SetEnabled(false);
964 auto test = FRAME_NODE2->TouchTest(
965 globalPoint, parentLocalPoint, parentLocalPoint, touchRestrict, result, 1, responseLinkResult);
966 EXPECT_EQ(test, HitTestResult::OUT_OF_REGION);
967 }
968
969 /**
970 * @tc.name: FrameNodeTestNg_AxisTest0027
971 * @tc.desc: Test frame node method
972 * @tc.type: FUNC
973 */
974 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest0027, TestSize.Level1)
975 {
976 /**
977 * @tc.steps: step1. callback AxisTest.
978 * @tc.expected: expect inputEventHub_ is run not null.
979 */
980 const PointF globalPoint;
981 const PointF parentLocalPoint;
982 const PointF parentRevertPoint;
983 TouchRestrict touchRestrict;
984 AxisTestResult onAxisResult;
985 FRAME_NODE2->eventHub_->GetOrCreateInputEventHub();
986 FRAME_NODE2->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult);
987 EXPECT_NE(FRAME_NODE2->eventHub_->inputEventHub_, nullptr);
988 }
989
990 /**
991 * @tc.name: FrameNodeTestNg0028
992 * @tc.desc: Test frame node method
993 * @tc.type: FUNC
994 */
995 HWTEST_F(FrameNodeTestNg, FrameNodeOnAccessibilityEvent0028, TestSize.Level1)
996 {
997 /**
998 * @tc.steps: step1. callback OnAccessibilityEvent.
999 * @tc.expected: expect The function is true.
1000 */
1001 auto test = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = true;
1002 FRAME_NODE2->OnAccessibilityEvent(
1003 AccessibilityEventType::CHANGE, WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_SUBTREE);
1004 FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, "", "");
1005 EXPECT_TRUE(test);
1006
1007 /**
1008 * @tc.steps: step2. callback OnAccessibilityEvent.
1009 * @tc.expected: expect The function is false.
1010 */
1011 auto test1 = AceApplicationInfo::GetInstance().isAccessibilityEnabled_ = false;
1012 FRAME_NODE2->OnAccessibilityEvent(AccessibilityEventType::ACCESSIBILITY_FOCUSED);
1013 EXPECT_FALSE(test1);
1014 }
1015
1016 /**
1017 * @tc.name: FrameNodeTestNg_MarkRemoving0029
1018 * @tc.desc: Test frame node method
1019 * @tc.type: FUNC
1020 */
1021 HWTEST_F(FrameNodeTestNg, FrameNodeMarkRemoving0029, TestSize.Level1)
1022 {
1023 /**
1024 * @tc.steps: step1. callback MarkRemoving.
1025 * @tc.expected: expect The function return value is true.
1026 */
1027 FRAME_NODE2->AddChild(FRAME_NODE3);
1028 FRAME_NODE2->layoutProperty_->UpdateGeometryTransition("id");
1029 auto mark = FRAME_NODE2->MarkRemoving();
1030 FRAME_NODE2->Clean();
1031 EXPECT_TRUE(mark);
1032
1033 FRAME_NODE2->layoutProperty_ = nullptr;
1034 auto mark1 = FRAME_NODE2->MarkRemoving();
1035 EXPECT_FALSE(mark1);
1036 }
1037
1038 /**
1039 * @tc.name: FrameNodeTestNg_CalculateCurrentVisibleRatio0030
1040 * @tc.desc: Test frame node method
1041 * @tc.type: FUNC
1042 */
1043 HWTEST_F(FrameNodeTestNg, FrameNodeCalculateCurrentVisibleRatio0030, TestSize.Level1)
1044 {
1045 /**
1046 * @tc.steps: step1. callback RemoveLastHotZoneRect.
1047 * @tc.expected: step1. expect The function is run ok.
1048 */
1049 RectF visibleRect;
1050 RectF renderRect;
1051 FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect);
1052 EXPECT_EQ(visibleRect.Width(), 0);
1053 EXPECT_EQ(renderRect.Width(), 0);
1054
1055 /**
1056 * @tc.steps: step2. set wrong value and call CalculateCurrentVisibleRatio
1057 * @tc.expected: expect The function returns 0.
1058 */
1059 renderRect.SetWidth(-1);
1060 EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1061 visibleRect.SetWidth(-1);
1062 EXPECT_EQ(FRAME_NODE2->CalculateCurrentVisibleRatio(visibleRect, renderRect), 0);
1063 }
1064
1065 /**
1066 * @tc.name: FrameNodeTestNg_InitializePatternAndContext0032
1067 * @tc.desc: Test InitializePatternAndContext
1068 * @tc.type: FUNC
1069 */
1070 HWTEST_F(FrameNodeTestNg, FrameNodeInitializePatternAndContext0032, TestSize.Level1)
1071 {
1072 /**
1073 * @tc.steps: step1. create a node and set onMainTree_=false, then call InitializePatternAndContext
1074 and trigger the callback
1075 * @tc.expected: hasPendingRequest_ is true
1076 */
__anond6e917530702() 1077 auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1078 one->onMainTree_ = false;
1079 one->InitializePatternAndContext();
1080 auto renderContext_ = one->renderContext_;
1081 renderContext_->RequestNextFrame();
1082 EXPECT_TRUE(one->hasPendingRequest_);
1083 }
1084
1085 /**
1086 * @tc.name: FrameNodeTestNg_ProcessAllVisibleCallback0033
1087 * @tc.desc: Test ProcessAllVisibleCallback
1088 * @tc.type: FUNC
1089 */
1090 HWTEST_F(FrameNodeTestNg, FrameNodeProcessAllVisibleCallback0033, TestSize.Level1)
1091 {
1092 /**
1093 * @tc.steps: step1. create a node and init a vector for preparing for args, then set a flag
1094 */
__anond6e917530802() 1095 auto one = FrameNode::GetOrCreateFrameNode("one", 11, []() { return AceType::MakeRefPtr<Pattern>(); });
1096 std::vector<double> visibleAreaRatios { 0.2, 0.8, 0.21, 0.79, 0.5 };
1097 int flag = 0;
__anond6e917530902(bool input1, double input2) 1098 auto defaultCallback = [&flag](bool input1, double input2) { flag += 1; };
1099 VisibleCallbackInfo callbackInfo { defaultCallback, 1.0, false };
1100
1101 /**
1102 * @tc.steps: step2. call ProcessAllVisibleCallback with 0.5 from 0
1103 * @tc.expected: flag is 1
1104 */
1105 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0.5, 0);
1106 EXPECT_EQ(flag, 1);
1107
1108 /**
1109 * @tc.steps: step3. call ProcessAllVisibleCallback with 0 from 0.5
1110 * @tc.expected: flag is 2
1111 */
1112 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0.5);
1113 EXPECT_EQ(flag, 2);
1114
1115 /**
1116 * @tc.steps: step4. call ProcessAllVisibleCallback with 0 from 0
1117 * @tc.expected: flag is 2
1118 */
1119 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 0, 0);
1120 EXPECT_EQ(flag, 2);
1121
1122 /**
1123 * @tc.steps: step5. call ProcessAllVisibleCallback with 1 from 0
1124 * @tc.expected: flag is 3
1125 */
1126 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 0);
1127 EXPECT_EQ(flag, 3);
1128
1129 /**
1130 * @tc.steps: step6. call ProcessAllVisibleCallback with 1 from 1
1131 * @tc.expected: flag is 3
1132 */
1133 one->ProcessAllVisibleCallback(visibleAreaRatios, callbackInfo, 1, 1);
1134 EXPECT_EQ(flag, 3);
1135 }
1136
1137 /**
1138 * @tc.name: FrameNodeTestNg_AnimateHoverEffect0034
1139 * @tc.desc: Test AnimateHoverEffect
1140 * @tc.type: FUNC
1141 */
1142 HWTEST_F(FrameNodeTestNg, FrameNodeAnimateHoverEffect0034, TestSize.Level1)
1143 {
1144 /**
1145 * @tc.steps: step1. create a frame node and release inputEventHub_, then
1146 change hoverEffectType_ and call AnimateHoverEffect
1147 * @tc.expected: AnimateHoverEffectScale has been called
1148 */
__anond6e917530a02() 1149 auto one = FrameNode::GetOrCreateFrameNode("one", 12, []() { return AceType::MakeRefPtr<Pattern>(); });
1150 one->eventHub_->inputEventHub_ = nullptr;
1151 auto renderContext = AceType::DynamicCast<MockRenderContext>(one->renderContext_);
1152 EXPECT_CALL(*renderContext, AnimateHoverEffectScale(_));
1153 one->AnimateHoverEffect(false);
1154 auto inputEventHub = one->eventHub_->GetOrCreateInputEventHub();
1155 inputEventHub->hoverEffectType_ = HoverEffectType::UNKNOWN;
1156 one->AnimateHoverEffect(false);
1157 inputEventHub->hoverEffectType_ = HoverEffectType::AUTO;
1158 one->AnimateHoverEffect(false);
1159 inputEventHub->hoverEffectType_ = HoverEffectType::SCALE;
1160 one->AnimateHoverEffect(false);
1161 inputEventHub->hoverEffectType_ = HoverEffectType::BOARD;
1162 one->AnimateHoverEffect(false);
1163 inputEventHub->hoverEffectType_ = HoverEffectType::OPACITY;
1164 one->AnimateHoverEffect(false);
1165 inputEventHub->hoverEffectType_ = HoverEffectType::NONE;
1166 one->AnimateHoverEffect(false);
1167 }
1168
1169 /**
1170 * @tc.name: FrameNodeTestNg_CreateAnimatablePropertyFloat0035
1171 * @tc.desc: Test AnimateHoverEffect
1172 * @tc.type: FUNC
1173 */
1174 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatablePropertyFloat0035, TestSize.Level1)
1175 {
1176 /**
1177 * @tc.steps: step1. call CreateAnimatablePropertyFloat.
1178 * @tc.expected: expect GetRenderContext is not null.
1179 */
1180 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1181
1182 FRAME_NODE->renderContext_ = AceType::MakeRefPtr<MockRenderContext>();
1183 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1184
1185 /**
1186 * @tc.steps: step2. put value to map and call CreateAnimatablePropertyFloat.
1187 * @tc.expected: expect iter is not equal map.
1188 */
1189 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1190 FRAME_NODE->CreateAnimatablePropertyFloat(NAME, value, onCallbackEvent);
1191 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1192 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1193 EXPECT_NE(iter, map);
1194 }
1195
1196 /**
1197 * @tc.name: FrameNodeTestNg_UpdateAnimatablePropertyFloat0036
1198 * @tc.desc: Test AnimateHoverEffect
1199 * @tc.type: FUNC
1200 */
1201 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatablePropertyFloat0036, TestSize.Level1)
1202 {
1203 /**
1204 * @tc.steps: step1. call UpdateAnimatablePropertyFloat.
1205 * @tc.expected: expect iter is not equal map.
1206 */
1207 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1208 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1209 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1210 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1211 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1212 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1213 EXPECT_NE(iter, map);
1214
1215 /**
1216 * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1217 * @tc.expected: expect property is nullptr.
1218 */
1219 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1220 FRAME_NODE->UpdateAnimatablePropertyFloat(NAME, value);
1221 auto property = AceType::DynamicCast<NodeAnimatablePropertyFloat>(iter->second);
1222 EXPECT_EQ(property, nullptr);
1223 }
1224
1225 /**
1226 * @tc.name: FrameNodeTestNg_CreateAnimatableArithmeticProperty0037
1227 * @tc.desc: Test AnimateHoverEffect
1228 * @tc.type: FUNC
1229 */
1230 HWTEST_F(FrameNodeTestNg, FrameNodeCreateAnimatableArithmeticProperty0037, TestSize.Level1)
1231 {
1232 /**
1233 * @tc.steps: step1. call CreateAnimatableArithmeticProperty.
1234 * @tc.expected: expect iter is not equal map.
1235 */
1236 RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1237 std::function<void(const RefPtr<NG::CustomAnimatableArithmetic>&)> onCallbackEvent;
1238 FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1239 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("test", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1240 FRAME_NODE->CreateAnimatableArithmeticProperty(NAME, value, onCallbackEvent);
1241 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1242 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1243 EXPECT_NE(iter, map);
1244 }
1245
1246 /**
1247 * @tc.name: FrameNodeTestNg_UpdateAnimatableArithmeticProperty0038
1248 * @tc.desc: Test AnimateHoverEffect
1249 * @tc.type: FUNC
1250 */
1251 HWTEST_F(FrameNodeTestNg, FrameNodeUpdateAnimatableArithmeticProperty0038, TestSize.Level1)
1252 {
1253 /**
1254 * @tc.steps: step1. call UpdateAnimatableArithmeticProperty.
1255 * @tc.expected: expect iter is not equal map.
1256 */
1257 RefPtr<CustomAnimatableArithmetic> value = AceType::MakeRefPtr<CustomAnimatableArithmetic>();
1258 FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1259 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1260
1261 FRAME_NODE->nodeAnimatablePropertyMap_.emplace("propertyName", AceType::MakeRefPtr<NodeAnimatablePropertyBase>());
1262 FRAME_NODE->UpdateAnimatableArithmeticProperty(NAME, value);
1263 auto iter = FRAME_NODE->nodeAnimatablePropertyMap_.find(NAME);
1264 auto map = FRAME_NODE->nodeAnimatablePropertyMap_.end();
1265 EXPECT_NE(iter, map);
1266
1267 /**
1268 * @tc.steps: step2. call UpdateAnimatablePropertyFloat and clear nodeAnimatablePropertyMap_.
1269 * @tc.expected: expect property is nullptr.
1270 */
1271 FRAME_NODE->nodeAnimatablePropertyMap_.clear();
1272 FRAME_NODE->UpdateAnimatableArithmeticProperty("", value);
1273 auto property = AceType::DynamicCast<NodeAnimatableArithmeticProperty>(iter->second);
1274 EXPECT_EQ(property, nullptr);
1275 }
1276
1277 /**
1278 * @tc.name: FrameNodeTestNg0039
1279 * @tc.desc: Test of FrameProxy
1280 * @tc.type: FUNC
1281 */
1282 HWTEST_F(FrameNodeTestNg, FrameNodeTestNg0039, TestSize.Level1)
1283 {
1284 /**
1285 * @tc.steps: step1. creat childNode、create LazyForEachNode
1286 * @tc.expected: childNode is not null
1287 */
1288 auto childNode = FrameNode::CreateFrameNode(
1289 "child", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1290 auto itemNode = FrameNode::CreateFrameNode(
1291 "itemNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1292 childNode->AddChild(itemNode);
1293 /**
1294 * @tc.steps: step2. call SetIsOverlayNode.
1295 * @tc.expected: change IsOverlayNode().
1296 */
1297 ConfigurationChange configurationChange;
1298 childNode->OnConfigurationUpdate(configurationChange);
1299 configurationChange.languageUpdate = true;
1300 childNode->OnConfigurationUpdate(configurationChange);
1301 configurationChange.colorModeUpdate = true;
1302 childNode->OnConfigurationUpdate(configurationChange);
1303 configurationChange.directionUpdate = true;
1304 childNode->OnConfigurationUpdate(configurationChange);
1305 configurationChange.dpiUpdate = true;
1306 childNode->OnConfigurationUpdate(configurationChange);
1307 configurationChange.fontUpdate = true;
1308 configurationChange.iconUpdate = true;
1309 configurationChange.skinUpdate = true;
1310 configurationChange.fontWeightScaleUpdate = true;
1311 childNode->OnConfigurationUpdate(configurationChange);
1312 configurationChange.fontScaleUpdate = true;
1313 childNode->OnConfigurationUpdate(configurationChange);
1314
1315 childNode->SetBackgroundLayoutConstraint(itemNode);
1316 childNode->ForceUpdateLayoutPropertyFlag(PROPERTY_UPDATE_MEASURE_SELF);
1317 childNode->GetPaintRectWithTransform();
1318 childNode->GetTransformScale();
1319 childNode->SetJSViewActive(true);
1320 auto layoutProperty = childNode->GetLayoutProperty();
1321 EXPECT_FALSE(layoutProperty->IsOverlayNode());
1322 layoutProperty->SetIsOverlayNode(true);
1323 childNode->DumpOverlayInfo();
1324 EXPECT_TRUE(layoutProperty->IsOverlayNode());
1325 }
1326
1327 /**
1328 * @tc.name: FrameNodeTestNg_SetOnAreaChangeCallback040
1329 * @tc.desc: Test frame node method
1330 * @tc.type: FUNC
1331 */
1332 HWTEST_F(FrameNodeTestNg, SetOnAreaChangeCallback040, TestSize.Level1)
1333 {
1334 /**
1335 * @tc.steps: step1. build a object to SetOnAreaChangeCallback
1336 * @tc.expected: expect cover branch lastFrameRect_ non null and function is run ok.
1337 */
1338 OnAreaChangedFunc callback = [](const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect,
__anond6e917530b02(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin) 1339 const OffsetF& origin) {};
1340 FRAME_NODE2->lastFrameRect_ = std::make_unique<RectF>();
1341 FRAME_NODE2->SetOnAreaChangeCallback(std::move(callback));
1342 EXPECT_NE(FRAME_NODE2->lastFrameRect_, nullptr);
1343
1344 /**
1345 * @tc.steps: step2.test while callback is nullptr
1346 * @tc.expected:expect cover branch lastParentOffsetToWindow_ non null and function is run ok.
1347 */
1348
1349 FRAME_NODE2->lastParentOffsetToWindow_ = std::make_unique<OffsetF>();
1350 FRAME_NODE2->SetOnAreaChangeCallback(nullptr);
1351 EXPECT_NE(FRAME_NODE2->lastParentOffsetToWindow_, nullptr);
1352 }
1353
1354 /**
1355 * @tc.name: FrameNodeTestNg_SwapDirtyLayoutWrapperOnMainThread040
1356 * @tc.desc: Test frame node method
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(FrameNodeTestNg, SwapDirtyLayoutWrapperOnMainThread040, TestSize.Level1)
1360 {
1361 /**
1362 * @tc.steps: step1. creat frameNode and layoutProperty
1363 */
1364 RefPtr<LayoutWrapper> layoutWrapper = FRAME_NODE2->CreateLayoutWrapper(true, true);
1365 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1366 auto layoutProperty = frameNode->GetLayoutProperty<LayoutProperty>();
1367 ASSERT_NE(layoutProperty, nullptr);
1368
1369 /**
1370 * @tc.steps: step2. setBorderWidth and updateBorderWidth.
1371 * @tc.expected: expect borderWidth property is not nullptr.
1372 */
1373 BorderWidthProperty overCountBorderWidth;
1374 overCountBorderWidth.SetBorderWidth(Dimension(10, DimensionUnit::VP));
1375 layoutProperty->UpdateBorderWidth(overCountBorderWidth);
1376 frameNode->SetLayoutProperty(layoutProperty);
1377
1378 /**
1379 * @tc.steps: step3. callback SwapDirtyLayoutWrapperOnMainThread
1380 * @tc.expected: expect GetBorderWidthProperty is not nullptr.
1381 */
1382 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1383 EXPECT_NE(layoutProperty->GetBorderWidthProperty(), nullptr);
1384
1385 /**
1386 * @tc.steps: step4. updatae layoutConstraint and set eventHub_.
1387 * @tc.expected: expect cover branch eventHub_ non null and function is run ok .
1388 */
1389 auto layoutConstraintF_ = LayoutConstraintF();
1390 layoutConstraintF_.maxSize = CONTAINER_SIZE;
1391 layoutConstraintF_.percentReference = CONTAINER_SIZE;
1392 frameNode->geometryNode_->SetParentLayoutConstraint(layoutConstraintF_);
1393 layoutProperty->UpdateLayoutConstraint(layoutConstraintF_);
1394
1395 frameNode->eventHub_->GetOrCreateFocusHub();
1396 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1397 EXPECT_NE(frameNode->eventHub_, nullptr);
1398
1399 /**
1400 * @tc.steps: step5. set currentFocus_ is true and call SwapDirtyLayoutWrapperOnMainThread.
1401 * @tc.expected: expect cover branch IsCurrentFocus() is true and function is run ok .
1402 */
1403 frameNode->eventHub_->GetOrCreateFocusHub()->currentFocus_ = true;
1404 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper);
1405 EXPECT_TRUE(frameNode->eventHub_->GetOrCreateFocusHub()->IsCurrentFocus());
1406 }
1407
1408 /**
1409 * @tc.name: FrameNodeTouchTest047
1410 * @tc.desc: Test method GeometryNodeToJsonValue
1411 * @tc.type: FUNC
1412 */
1413 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest047, TestSize.Level1)
1414 {
1415 /**
1416 * @tc.steps: step1. construct parameters.
1417 */
1418 std::unique_ptr<JsonValue> value = JsonUtil::Create(true);
1419
1420 /**
1421 * @tc.steps: step2. construct parameters.
1422 * @tc.expected: expect cover branch layoutProperty_ is nullptr.
1423 */
1424 FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1425 EXPECT_EQ(FRAME_NODE2->layoutProperty_, nullptr);
1426
1427 /**
1428 * @tc.steps: step3. set layoutProperty_ and call GeometryNodeToJsonValue.
1429 * @tc.expected: expect cover branch layoutProperty_ is not nullptr.
1430 */
1431 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>();
1432 FRAME_NODE2->layoutProperty_ = layoutProperty;
1433 FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1434 EXPECT_NE(FRAME_NODE2->layoutProperty_, nullptr);
1435
1436 /**
1437 * @tc.steps: step4. set calcLayoutConstraint_ and call GeometryNodeToJsonValue.
1438 * @tc.expected: expect cover branch calcLayoutConstraint_ is not nullptr.
1439 */
1440 FRAME_NODE2->layoutProperty_->calcLayoutConstraint_ = std::make_unique<MeasureProperty>();
1441
1442 FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1443 EXPECT_NE(FRAME_NODE2->layoutProperty_->calcLayoutConstraint_, nullptr);
1444
1445 /**
1446 * @tc.steps: step5. set selfIdealSize and call GeometryNodeToJsonValue.
1447 * @tc.expected: expect cover branch selfIdealSize has value.
1448 */
1449 std::optional<CalcLength> len = CalcLength("auto");
1450 FRAME_NODE2->layoutProperty_->calcLayoutConstraint_->selfIdealSize = CalcSize(len, len);
1451 FRAME_NODE2->GeometryNodeToJsonValue(value, filter);
1452 EXPECT_NE(FRAME_NODE2->renderContext_, nullptr);
1453
1454 FRAME_NODE2->layoutProperty_ = nullptr;
1455 }
1456
1457 /**
1458 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback048
1459 * @tc.desc: Test frame node method
1460 * @tc.type: FUNC
1461 */
1462 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback048, TestSize.Level1)
1463 {
1464 /**
1465 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1466 * @tc.expected: expect The function is run ok.
1467 */
1468 VisibleCallbackInfo callbackInfo;
1469 constexpr uint32_t minInterval = 100; // 100ms
1470 int flag = 0;
__anond6e917530c02(bool input1, double input2) 1471 callbackInfo.callback = [&flag](bool input1, double input2) { flag += 1; };
1472 callbackInfo.period = minInterval;
1473 FRAME_NODE2->SetVisibleAreaUserCallback({ 0.2, 0.8, 0.21, 0.79, 0.5 }, callbackInfo);
1474 FRAME_NODE2->ProcessThrottledVisibleCallback();
1475 EXPECT_EQ(FRAME_NODE2->throttledCallbackOnTheWay_, false);
1476 }
1477
1478 /**
1479 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback049
1480 * @tc.desc: Test the function GetValidLeafChildNumber
1481 * @tc.type: FUNC
1482 */
1483 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback049, TestSize.Level1)
1484 {
1485 /**
1486 * @tc.steps: step1. build a object to TriggerVisibleAreaChangeCallback
1487 * @tc.expected: expect The function is run ok.
1488 */
1489 int32_t nodeId = ElementRegister::GetInstance()->MakeUniqueId();
1490 const RefPtr<FrameNode> node =
1491 FrameNode::CreateFrameNode("TriggerVisibleAreaChangeCallback001", nodeId, AceType::MakeRefPtr<Pattern>(), true);
1492
1493 /**
1494 * @tc.steps2: Call the function GetValidLeafChildNumber.
1495 * @tc.expected: Value returned as expected.
1496 */
1497 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1498 const RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>(), true);
1499 GET_CHILD1->UpdateInspectorId("child1");
1500 node->AddChild(GET_CHILD1);
1501 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 1), 1);
1502
1503 const RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>(), true);
1504 GET_CHILD2->UpdateInspectorId("child2");
1505 node->AddChild(GET_CHILD2);
1506 EXPECT_EQ(FRAME_NODE2->GetValidLeafChildNumber(node, 3), 2);
1507 }
1508
1509 /**
1510 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback050
1511 * @tc.desc: Test the function MarkAndCheckNewOpIncNode
1512 * @tc.type: FUNC
1513 */
1514 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback050, TestSize.Level1)
1515 {
1516 /**
1517 * @tc.steps: step1. creat node and generate a node tree.
1518 */
1519 RefPtr<FrameNode> GET_PARENT = FrameNode::CreateFrameNode("parent", 4, AceType::MakeRefPtr<Pattern>());
1520 RefPtr<FrameNode> GET_CHILD1 = FrameNode::CreateFrameNode("child1", 5, AceType::MakeRefPtr<Pattern>());
1521 RefPtr<FrameNode> GET_CHILD2 = FrameNode::CreateFrameNode("child2", 6, AceType::MakeRefPtr<Pattern>());
1522 GET_PARENT->AddChild(GET_CHILD1);
1523 GET_PARENT->AddChild(GET_CHILD2);
1524 GET_CHILD1->MarkAndCheckNewOpIncNode();
1525 EXPECT_FALSE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1526
1527 /**
1528 * @tc.steps2: set suggestOpIncByte_ and call the function MarkAndCheckNewOpIncNode.
1529 * @tc.expected: Value returned as expected.
1530 */
1531 GET_PARENT->suggestOpIncByte_ = 7;
1532 GET_CHILD1->SetSuggestOpIncActivatedOnce();
1533 GET_PARENT->SetSuggestOpIncActivatedOnce();
1534 GET_CHILD1->MarkAndCheckNewOpIncNode();
1535 EXPECT_TRUE(GET_PARENT->GetSuggestOpIncActivatedOnce());
1536 GET_CHILD1->suggestOpIncByte_ = 1;
1537 GET_CHILD1->MarkAndCheckNewOpIncNode();
1538 }
1539
1540 /**
1541 * @tc.name: FrameNodeTouchTest051
1542 * @tc.desc: Test frameNode FindSuggestOpIncNode
1543 * @tc.type: FUNC
1544 */
1545 HWTEST_F(FrameNodeTestNg, FrameNodeTouchTest051, TestSize.Level1)
1546 {
1547 /**
1548 * @tc.steps: step1. initialize parameters.
1549 */
1550 std::string tag = "test";
1551 auto frameNode = FrameNode::CreateFrameNode(tag, 1, AceType::MakeRefPtr<Pattern>(), true);
1552 auto frameNode1 = FrameNode::CreateFrameNode("test1", 2, AceType::MakeRefPtr<Pattern>(), true);
1553 frameNode->AddChild(frameNode1);
1554 frameNode->GetBaselineDistance();
1555
1556 /**
1557 * @tc.steps: step2. set frame size and call FindSuggestOpIncNode
1558 * @tc.expected: expect result value.
1559 */
1560 frameNode->geometryNode_->SetFrameSize(SizeF(20, 20));
1561 auto result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1562 EXPECT_EQ(result, 3);
1563 result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1564 EXPECT_EQ(result, 2);
1565 SystemProperties::debugEnabled_ = true;
1566 frameNode->suggestOpIncByte_ = 0;
1567 result = frameNode->FindSuggestOpIncNode(tag, SizeF(0, 0), 1);
1568 EXPECT_EQ(result, 3);
1569 }
1570
1571 /**
1572 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback052
1573 * @tc.desc: Test the function IsOpIncValidNode
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback052, TestSize.Level1)
1577 {
1578 /**
1579 * @tc.steps: step1. initialize parameters.
1580 */
1581
1582 SizeF boundary(1, 1);
1583 int32_t childNumber = 2;
1584
1585 /**
1586 * @tc.steps2: call the function IsOpIncValidNode.
1587 * @tc.expected: Value returned as expected.
1588 */
1589 auto result = FRAME_NODE2->IsOpIncValidNode(boundary, childNumber);
1590 EXPECT_EQ(result, 2);
1591
1592 FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1593 result = FRAME_NODE2->IsOpIncValidNode(boundary, childNumber);
1594 EXPECT_EQ(result, 3);
1595
1596 SizeF boundary1(40, 40);
1597 FRAME_NODE2->geometryNode_->SetFrameSize(SizeF(20, 20));
1598 result = FRAME_NODE2->IsOpIncValidNode(boundary1, childNumber);
1599 EXPECT_EQ(result, 2);
1600 }
1601
1602 /**
1603 * @tc.name: FrameNodeTestNg_TriggerVisibleAreaChangeCallback053
1604 * @tc.desc: Test the function MarkSuggestOpIncGroup
1605 * @tc.type: FUNC
1606 */
1607 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback053, TestSize.Level1)
1608 {
1609 /**
1610 * @tc.steps1: call the function MarkSuggestOpIncGroup.
1611 * @tc.expected: Value returned as expected.
1612 */
1613 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1614
1615 FRAME_NODE2->SetCanSuggestOpInc(true);
1616 FRAME_NODE2->SetSuggestOpIncMarked(true);
1617 FRAME_NODE2->SetOpIncGroupCheckedThrough(true);
1618 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1619
1620 FRAME_NODE2->SetSuggestOpIncMarked(false);
1621 FRAME_NODE2->SetCanSuggestOpInc(false);
1622 FRAME_NODE2->SetOpIncGroupCheckedThrough(false);
1623 EXPECT_TRUE(FRAME_NODE2->MarkSuggestOpIncGroup(true, true));
1624 }
1625
1626 /**
1627 * @tc.name: FrameNodeTestNg_IsPaintRectWithTransformValid054
1628 * @tc.desc: Test frame node method IsPaintRectWithTransformValid
1629 * @tc.type: FUNC
1630 */
1631 HWTEST_F(FrameNodeTestNg, FrameNodeIsPaintRectWithTransformValid054, TestSize.Level1)
1632 {
1633 /**
1634 * @tc.steps: step1. callback IsPaintRectWithTransformValid.
1635 * @tc.expected: expect The function return value is true when width or height is nearZero.
1636 */
1637 auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1638 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
1639 node->renderContext_ = mockRenderContext;
1640
1641 mockRenderContext->rect_ = RectF(0, 0, 0, 10);
1642 auto test1 = node->IsPaintRectWithTransformValid();
1643 EXPECT_TRUE(test1);
1644
1645 mockRenderContext->rect_ = RectF(0, 0, 10, 0);
1646 auto test2 = node->IsPaintRectWithTransformValid();
1647 EXPECT_TRUE(test2);
1648
1649 mockRenderContext->rect_ = RectF(0, 0, 10, 10);
1650 auto test3 = node->IsPaintRectWithTransformValid();
1651 EXPECT_FALSE(test3);
1652
1653 mockRenderContext->rect_ = RectF(0, 0, 0, 0);
1654 auto test4 = node->IsPaintRectWithTransformValid();
1655 EXPECT_TRUE(test4);
1656 }
1657
1658 /**
1659 * @tc.name: FrameNodeSetJSCustomProperty055
1660 * @tc.desc: Test SetJSCustomProperty isCNode true, expect result updateFlag is false.
1661 * @tc.type: FUNC
1662 */
1663 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty055, TestSize.Level1)
1664 {
1665 /**
1666 * @tc.steps: step1. initialize parameters.
1667 */
1668 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1669
1670 /**
1671 * @tc.steps: step2. set isCNode true
1672 * @tc.expected: expect result updateFlag is false.
1673 */
1674 frameNode->setIsCNode(true);
__anond6e917530d02() 1675 std::function<bool()> func = []() -> bool { return true; };
__anond6e917530e02(const std::string& key) 1676 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1677 return "getFuncA";
1678 };
1679 frameNode->SetJSCustomProperty(func, getFuncA);
1680 std::string value;
1681 bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", value);
1682 EXPECT_EQ(updateFlagValue, false);
1683 }
1684
1685 /**
1686 * @tc.name: FrameNodeSetJSCustomProperty056
1687 * @tc.desc: Test SetJSCustomProperty isCNode false and func true, expect result updateFlag is true.
1688 * @tc.type: FUNC
1689 */
1690 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty056, TestSize.Level1)
1691 {
1692 /**
1693 * @tc.steps: step1. initialize parameters.
1694 */
1695 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1696
1697 /**
1698 * @tc.steps: step2. set isCNode false and func true.
1699 * @tc.expected: expect result updateFlag is true.
1700 */
1701 frameNode->setIsCNode(false);
__anond6e917530f02() 1702 std::function<bool()> func = []() -> bool { return true; };
__anond6e917531002(const std::string& key) 1703 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1704 return "getFuncA";
1705 };
1706 frameNode->SetJSCustomProperty(func, getFuncA);
1707 frameNode->setIsCNode(true);
1708 std::string flagValue;
1709 bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", flagValue);
1710 EXPECT_EQ(updateFlagValue, true);
1711 EXPECT_EQ(flagValue, "1");
1712 }
1713
1714 /**
1715 * @tc.name: FrameNodeSetJSCustomProperty057
1716 * @tc.desc: Test SetJSCustomProperty isCNode false and func false, expect result updateFlag is false.
1717 * @tc.type: FUNC
1718 */
1719 HWTEST_F(FrameNodeTestNg, FrameNodeSetJSCustomProperty057, TestSize.Level1)
1720 {
1721 /**
1722 * @tc.steps: step1. initialize parameters.
1723 */
1724 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1725
1726 /**
1727 * @tc.steps: step2. set isCNode false and func false.
1728 * @tc.expected: expect result updateFlag is false.
1729 */
1730 frameNode->setIsCNode(false);
__anond6e917531102() 1731 std::function<bool()> func = []() -> bool { return false; };
__anond6e917531202(const std::string& key) 1732 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1733 return "getFuncA";
1734 };
1735 frameNode->SetJSCustomProperty(func, getFuncA);
1736 frameNode->setIsCNode(true);
1737 std::string flagValue;
1738 bool updateFlagValue = frameNode->GetCapiCustomProperty("updateFlag", flagValue);
1739 EXPECT_EQ(updateFlagValue, false);
1740 }
1741
1742 /**
1743 * @tc.name: FrameNodeGetJSCustomProperty058
1744 * @tc.desc: Test GetJSCustomProperty getCustomProperty_ value getFuncA, expect result value getFuncA.
1745 * @tc.type: FUNC
1746 */
1747 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty058, TestSize.Level1)
1748 {
1749 /**
1750 * @tc.steps: step1. initialize parameters.
1751 */
1752 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1753
1754 /**
1755 * @tc.steps: step2. set getCustomProperty_ value getFuncA.
1756 * @tc.expected: expect result value getFuncA.
1757 */
__anond6e917531302() 1758 std::function<bool()> func = []() -> bool { return true; };
__anond6e917531402(const std::string& key) 1759 std::function<std::string(const std::string&)> getFuncA = [](const std::string& key) -> std::string {
1760 return "getFuncA";
1761 };
1762 frameNode->SetJSCustomProperty(func, getFuncA);
1763 std::string getValue;
1764 bool result = frameNode->GetJSCustomProperty("key", getValue);
1765 EXPECT_EQ(result, true);
1766 EXPECT_EQ(getValue, "getFuncA");
1767 }
1768
1769 /**
1770 * @tc.name: FrameNodeGetJSCustomProperty059
1771 * @tc.desc: Test GetJSCustomProperty getCustomProperty_ nullptr
1772 * @tc.type: FUNC
1773 */
1774 HWTEST_F(FrameNodeTestNg, FrameNodeGetJSCustomProperty059, TestSize.Level1)
1775 {
1776 /**
1777 * @tc.steps: step1. initialize parameters.
1778 */
1779 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1780
1781 /**
1782 * @tc.steps: step2. set getCustomProperty_ nullptr
1783 * @tc.expected: expect result GetJSCustomProperty false.
1784 */
__anond6e917531502() 1785 std::function<bool()> func = []() -> bool { return true; };
1786 frameNode->SetJSCustomProperty(func, nullptr);
1787 std::string getValue;
1788 bool result = frameNode->GetJSCustomProperty("key", getValue);
1789 EXPECT_EQ(result, false);
1790 }
1791
1792 /**
1793 * @tc.name: FrameNodeGetCapiCustomProperty060
1794 * @tc.desc: Test GetCapiCustomProperty no key value value value added.
1795 * @tc.type: FUNC
1796 */
1797 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty060, TestSize.Level1)
1798 {
1799 /**
1800 * @tc.steps: step1. initialize parameters.
1801 */
1802 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1803
1804 /**
1805 * @tc.steps: step2. GetCapiCustomProperty
1806 * @tc.expected: expect result value false.
1807 */
1808 frameNode->setIsCNode(false);
1809 std::string value;
1810 bool result = frameNode->GetCapiCustomProperty("key", value);
1811 EXPECT_EQ(result, false);
1812 }
1813
1814 /**
1815 * @tc.name: FrameNodeGetCapiCustomProperty061
1816 * @tc.desc: Test GetCapiCustomProperty the key value value value exists.
1817 * @tc.type: FUNC
1818 */
1819 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty061, TestSize.Level1)
1820 {
1821 /**
1822 * @tc.steps: step1. initialize parameters.
1823 */
1824 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1825
1826 /**
1827 * @tc.steps: step2. add the key value as value1.
1828 * @tc.expected: expect result value1.
1829 */
1830 frameNode->setIsCNode(true);
1831 frameNode->AddCustomProperty("key", "value1");
1832 std::string value;
1833 bool result = frameNode->GetCapiCustomProperty("key", value);
1834 EXPECT_EQ(result, true);
1835 EXPECT_EQ(value, "value1");
1836 }
1837
1838 /**
1839 * @tc.name: FrameNodeGetCapiCustomProperty062
1840 * @tc.desc: Test GetCapiCustomProperty the key value does not exist.
1841 * @tc.type: FUNC
1842 */
1843 HWTEST_F(FrameNodeTestNg, FrameNodeGetCapiCustomProperty062, TestSize.Level1)
1844 {
1845 /**
1846 * @tc.steps: step1. initialize parameters.
1847 */
1848 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1849
1850 /**
1851 * @tc.steps: step2. set key is value1
1852 * @tc.expected: expect result value.
1853 */
1854 frameNode->setIsCNode(true);
1855 frameNode->AddCustomProperty("key", "value1");
1856 std::string value;
1857 bool result = frameNode->GetCapiCustomProperty("key1", value);
1858 EXPECT_EQ(result, false);
1859 }
1860
1861 /**
1862 * @tc.name: FrameNodeRemoveCustomProperty063
1863 * @tc.desc: Test RemoveCustomProperty.
1864 * @tc.type: FUNC
1865 */
1866 HWTEST_F(FrameNodeTestNg, FrameNodeRemoveCustomProperty063, TestSize.Level1)
1867 {
1868 /**
1869 * @tc.steps: step1. initialize parameters.
1870 */
1871 auto frameNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr<Pattern>(), true);
1872
1873 /**
1874 * @tc.steps: step2. set key is value1, remove key.
1875 * @tc.expected: expect result false.
1876 */
1877 frameNode->setIsCNode(true);
1878 frameNode->AddCustomProperty("key", "value1");
1879 frameNode->RemoveCustomProperty("key");
1880 std::string value;
1881 bool result = frameNode->GetCapiCustomProperty("key", value);
1882 EXPECT_EQ(result, false);
1883 }
1884 } // namespace OHOS::Ace::NG
1885