1 /* 2 * Copyright (c) 2024-2025 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 #include "core/event/touch_event.h" 18 #include "frameworks/core/components_ng/pattern/text_field/text_field_pattern.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS::Ace::NG { 24 namespace {} // namespace 25 26 /** 27 * @tc.name: FrameNodeOnGenerateOneDepthVisibleFrameWithOffset01 28 * @tc.desc: Test the function OnGenerateOneDepthVisibleFrameWithOffset 29 * @tc.type: FUNC 30 */ 31 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithOffset01, TestSize.Level1) 32 { 33 /** 34 * @tc.steps: step1. create frameNode. 35 */ 36 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 37 auto childNode = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>(), true); 38 frameNode->isLayoutNode_ = true; 39 frameNode->isActive_ = true; 40 frameNode->overlayNode_ = nullptr; 41 EXPECT_EQ(frameNode->overlayNode_, nullptr); 42 /** 43 * @tc.steps: step2. call the function OnGenerateOneDepthVisibleFrameWithOffset. 44 */ 45 OffsetF Offset = { 0.0, 0.0 }; 46 std::list<RefPtr<FrameNode>> children; 47 children.push_back(childNode); 48 frameNode->OnGenerateOneDepthVisibleFrameWithOffset(children, Offset); 49 frameNode->overlayNode_ = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); 50 frameNode->OnGenerateOneDepthVisibleFrameWithOffset(children, Offset); 51 EXPECT_NE(frameNode->overlayNode_, nullptr); 52 EXPECT_EQ(frameNode->overlayNode_->GetNodeName(), ""); 53 } 54 55 /** 56 * @tc.name: FrameNodeOnGenerateOneDepthVisibleFrameWithOffset02 57 * @tc.desc: Test the function OnGenerateOneDepthVisibleFrameWithOffset 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithOffset02, TestSize.Level1) 61 { 62 /** 63 * @tc.steps: step1. create frameNode. 64 */ 65 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 66 auto childNode = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>(), true); 67 frameNode->isLayoutNode_ = false; 68 frameNode->isActive_ = true; 69 frameNode->overlayNode_ = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); 70 EXPECT_NE(frameNode->overlayNode_, nullptr); 71 EXPECT_EQ(frameNode->overlayNode_->GetNodeName(), ""); 72 /** 73 * @tc.steps: step2. call the function OnGenerateOneDepthVisibleFrameWithOffset. 74 */ 75 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 76 layoutProperty->propVisibility_ = VisibleType::INVISIBLE; 77 OffsetF Offset = { 0.0, 0.0 }; 78 std::list<RefPtr<FrameNode>> children; 79 children.push_back(childNode); 80 frameNode->SetLayoutProperty(layoutProperty); 81 frameNode->OnGenerateOneDepthVisibleFrameWithOffset(children, Offset); 82 EXPECT_EQ(frameNode->GetLayoutProperty(), layoutProperty); 83 } 84 85 /** 86 * @tc.name: FrameNodeOnGenerateOneDepthVisibleFrameWithOffset03 87 * @tc.desc: Test the function OnGenerateOneDepthVisibleFrameWithOffset 88 * @tc.type: FUNC 89 */ 90 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithOffset03, TestSize.Level1) 91 { 92 /** 93 * @tc.steps: step1. create frameNode. 94 */ 95 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 96 auto childNode = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>(), true); 97 frameNode->isLayoutNode_ = false; 98 frameNode->isActive_ = true; 99 frameNode->overlayNode_ = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); 100 EXPECT_NE(frameNode->overlayNode_, nullptr); 101 EXPECT_EQ(frameNode->overlayNode_->GetNodeName(), ""); 102 /** 103 * @tc.steps: step2. call the function OnGenerateOneDepthVisibleFrameWithOffset. 104 */ 105 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 106 layoutProperty->propVisibility_ = VisibleType::VISIBLE; 107 OffsetF Offset = { 0.0, 0.0 }; 108 std::list<RefPtr<FrameNode>> children; 109 children.push_back(childNode); 110 frameNode->SetLayoutProperty(layoutProperty); 111 frameNode->OnGenerateOneDepthVisibleFrameWithOffset(children, Offset); 112 EXPECT_EQ(frameNode->layoutProperty_->propVisibility_, layoutProperty->propVisibility_); 113 } 114 115 /** 116 * @tc.name: FrameNodeOnGenerateOneDepthVisibleFrameWithOffset04 117 * @tc.desc: Test the function OnGenerateOneDepthVisibleFrameWithOffset 118 * @tc.type: FUNC 119 */ 120 HWTEST_F(FrameNodeTestNg, FrameNodeOnGenerateOneDepthVisibleFrameWithOffset04, TestSize.Level1) 121 { 122 /** 123 * @tc.steps: step1. create frameNode. 124 */ 125 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 126 auto childNode = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>(), true); 127 frameNode->isLayoutNode_ = false; 128 frameNode->isActive_ = false; 129 frameNode->overlayNode_ = AceType::MakeRefPtr<FrameNode>("test", 1, AceType::MakeRefPtr<Pattern>()); 130 EXPECT_NE(frameNode->overlayNode_, nullptr); 131 EXPECT_EQ(frameNode->overlayNode_->GetNodeName(), ""); 132 /** 133 * @tc.steps: step2. call the function OnGenerateOneDepthVisibleFrameWithOffset. 134 */ 135 auto layoutProperty = AceType::MakeRefPtr<LayoutProperty>(); 136 layoutProperty->propVisibility_ = VisibleType::VISIBLE; 137 OffsetF Offset = { 0.0, 0.0 }; 138 std::list<RefPtr<FrameNode>> children; 139 children.push_back(childNode); 140 frameNode->SetLayoutProperty(layoutProperty); 141 frameNode->OnGenerateOneDepthVisibleFrameWithOffset(children, Offset); 142 EXPECT_EQ(frameNode->GetLayoutProperty(), layoutProperty); 143 } 144 145 /** 146 * @tc.name: FrameNodeIsOutOfTouchTestRegion01 147 * @tc.desc: Test the function IsOutOfTouchTestRegion 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(FrameNodeTestNg, FrameNodeIsOutOfTouchTestRegion01, TestSize.Level1) 151 { 152 /** 153 * @tc.steps: step1. create frameNode. 154 */ 155 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 156 auto testNode = FrameNode::CreateFrameNode("testNode", 1, AceType::MakeRefPtr<Pattern>(), true); 157 158 /** 159 * @tc.steps: step2. call the function IsOutOfTouchTestRegion. 160 */ 161 NG::PointF point { 1.0, 1.0 }; 162 frameNode->renderContext_->UpdateClipEdge(true); 163 TouchEvent touchEvent; 164 touchEvent.sourceType = static_cast<SourceType>(1); 165 EXPECT_TRUE(frameNode->IsOutOfTouchTestRegion(point, touchEvent)); 166 testNode->renderContext_->UpdateClipEdge(false); 167 EXPECT_TRUE(testNode->IsOutOfTouchTestRegion(point, touchEvent)); 168 } 169 170 /** 171 * @tc.name: FrameNodeAddJudgeToTargetComponent01 172 * @tc.desc: Test the function AddJudgeToTargetComponent 173 * @tc.type: FUNC 174 */ 175 HWTEST_F(FrameNodeTestNg, FrameNodeAddJudgeToTargetComponent01, TestSize.Level1) 176 { 177 /** 178 * @tc.steps: step1. create frameNode. 179 */ 180 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 181 182 /** 183 * @tc.steps: step2. call the function AddJudgeToTargetComponent. 184 */ 185 auto gestureHub = frameNode->GetOrCreateGestureEventHub(); 186 auto gestureJudgeFunc = [](const RefPtr<GestureInfo>& gestureInfo, __anond32069d10202(const RefPtr<GestureInfo>& gestureInfo, const std::shared_ptr<BaseGestureEvent>&) 187 const std::shared_ptr<BaseGestureEvent>&) -> GestureJudgeResult { 188 return GestureJudgeResult(1); 189 }; 190 gestureHub->SetOnGestureJudgeNativeBegin(gestureJudgeFunc); 191 RefPtr<TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>(); 192 frameNode->AddJudgeToTargetComponent(targetComponent); 193 EXPECT_NE(frameNode, nullptr); 194 } 195 196 /** 197 * @tc.name: FrameNodeAddJudgeToTargetComponent02 198 * @tc.desc: Test the function AddJudgeToTargetComponent 199 * @tc.type: FUNC 200 */ 201 HWTEST_F(FrameNodeTestNg, FrameNodeAddJudgeToTargetComponent02, TestSize.Level1) 202 { 203 /** 204 * @tc.steps: step1. create frameNode. 205 */ 206 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 207 208 /** 209 * @tc.steps: step2. call the function AddJudgeToTargetComponent. 210 */ 211 frameNode->GetOrCreateEventHub<EventHub>()->gestureEventHub_ = nullptr; 212 RefPtr<TargetComponent> targetComponent = AceType::MakeRefPtr<TargetComponent>(); 213 frameNode->AddJudgeToTargetComponent(targetComponent); 214 EXPECT_NE(frameNode, nullptr); 215 EXPECT_EQ(frameNode->GetOrCreateEventHub<EventHub>()->gestureEventHub_, nullptr); 216 } 217 218 /** 219 * @tc.name: TriggerShouldParallelInnerWithTest01 220 * @tc.desc: Test the function TriggerShouldParallelInnerWith 221 * @tc.type: FUNC 222 */ 223 HWTEST_F(FrameNodeTestNg, TriggerShouldParallelInnerWithTest01, TestSize.Level1) 224 { 225 /** 226 * @tc.steps: step1. create frameNode. 227 */ 228 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 229 auto gestureHub = frameNode->GetOrCreateEventHub<EventHub>()->GetOrCreateGestureEventHub(); 230 ShouldBuiltInRecognizerParallelWithFunc shouldBuiltInRecognizerParallelWithFunc = __anond32069d10302(RefPtr<NGGestureRecognizer> target, std::vector<RefPtr<NGGestureRecognizer>> targets) 231 [](RefPtr<NGGestureRecognizer> target, std::vector<RefPtr<NGGestureRecognizer>> targets) { 232 return RefPtr<NGGestureRecognizer>(); 233 }; 234 gestureHub->SetShouldBuildinRecognizerParallelWithFunc(std::move(shouldBuiltInRecognizerParallelWithFunc)); 235 ResponseLinkResult currentRecognizers; 236 ResponseLinkResult responseLinkRecognizers; 237 auto recognizer = AceType::MakeRefPtr<ClickRecognizer>(); 238 recognizer->SetRecognizerType(GestureTypeName::PAN_GESTURE); 239 recognizer->GetGestureInfo()->SetIsSystemGesture(true); 240 currentRecognizers.emplace_back(recognizer); 241 responseLinkRecognizers.emplace_back(recognizer); 242 currentRecognizers.emplace_back(AceType::MakeRefPtr<ClickRecognizer>()); 243 244 auto recognizer1 = AceType::MakeRefPtr<ClickRecognizer>(); 245 recognizer1->SetRecognizerType(GestureTypeName::UNKNOWN); 246 recognizer1->GetGestureInfo()->SetIsSystemGesture(true); 247 currentRecognizers.emplace_back(recognizer1); 248 249 auto recognizer2 = AceType::MakeRefPtr<ClickRecognizer>(); 250 recognizer2->SetRecognizerType(GestureTypeName::PAN_GESTURE); 251 recognizer2->GetGestureInfo()->SetIsSystemGesture(true); 252 TouchEvent touchEvent; 253 TouchEvent touchEvent1; 254 recognizer2->touchPoints_[touchEvent.id] = touchEvent; 255 recognizer2->touchPoints_[touchEvent1.id] = touchEvent1; 256 currentRecognizers.emplace_back(recognizer2); 257 /** 258 * @tc.steps: step2. call the function TriggerShouldParallelInnerWith. 259 */ 260 frameNode->TriggerShouldParallelInnerWith(currentRecognizers, responseLinkRecognizers); 261 EXPECT_FALSE(recognizer->IsBridgeMode()); 262 } 263 264 /** 265 * @tc.name: OnSyncGeometryFrameFinishTest 266 * @tc.desc: Test the function OnSyncGeometryFrameFinish 267 * @tc.type: FUNC 268 */ 269 HWTEST_F(FrameNodeTestNg, OnSyncGeometryFrameFinishTest, TestSize.Level1) 270 { 271 /** 272 * @tc.steps: step1. create frameNode. 273 */ 274 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 275 RectF paintRect = { 10.0f, 10.0f, 10.0f, 10.0f }; 276 /** 277 * @tc.steps: step2. call the function TriggerShouldParallelInnerWith. 278 */ 279 frameNode->OnSyncGeometryFrameFinish(paintRect); 280 EXPECT_TRUE(frameNode->syncedFramePaintRect_.has_value()); 281 frameNode->OnSyncGeometryFrameFinish(paintRect); 282 RectF paintRect1 = { 20.0f, 20.0f, 20.0f, 20.0f }; 283 frameNode->OnSyncGeometryFrameFinish(paintRect1); 284 EXPECT_EQ(frameNode->syncedFramePaintRect_, paintRect1); 285 } 286 287 /** 288 * @tc.name: IsContextTransparentTest001 289 * @tc.desc: Test the function IsContextTransparent 290 * @tc.type: FUNC 291 */ 292 HWTEST_F(FrameNodeTestNg, IsContextTransparentTest001, TestSize.Level1) 293 { 294 /** 295 * @tc.steps: step1. create frameNode. 296 */ 297 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 298 299 /** 300 * @tc.steps: step2. call the function IsContextTransparent. 301 */ 302 EXPECT_TRUE(frameNode->IsContextTransparent()); 303 frameNode->GetRenderContext()->UpdateOpacity(0.0); 304 EXPECT_TRUE(frameNode->IsContextTransparent()); 305 frameNode->GetRenderContext()->UpdateOpacity(10.0); 306 EXPECT_TRUE(frameNode->IsContextTransparent()); 307 auto mockRenderContext = AceType::DynamicCast<MockRenderContext>(frameNode->GetRenderContext()); 308 mockRenderContext->SetPaintRectWithTransform(RectF(10.0f, 10.0f, 10.0f, 0.0f)); 309 EXPECT_TRUE(frameNode->IsContextTransparent()); 310 mockRenderContext->SetPaintRectWithTransform(RectF(10.0f, 10.0f, 10.0f, 10.0f)); 311 EXPECT_FALSE(frameNode->IsContextTransparent()); 312 frameNode->layoutProperty_->propVisibility_ = VisibleType::INVISIBLE; 313 EXPECT_TRUE(frameNode->IsContextTransparent()); 314 } 315 316 /** 317 * @tc.name: IsContextTransparentTest002 318 * @tc.desc: Test the function IsContextTransparent 319 * @tc.type: FUNC 320 */ 321 HWTEST_F(FrameNodeTestNg, IsContextTransparentTest002, TestSize.Level1) 322 { 323 /** 324 * @tc.steps: step1. create frameNode. 325 */ 326 auto frameNode = FrameNode::CreateFrameNode("Flex", 1, AceType::MakeRefPtr<Pattern>(), true); 327 auto frameNode1 = FrameNode::CreateFrameNode("framenode", 2, AceType::MakeRefPtr<Pattern>(), true); 328 frameNode->AddChild(frameNode1); 329 /** 330 * @tc.steps: step2. call the function IsContextTransparent. 331 */ 332 EXPECT_TRUE(frameNode->IsContextTransparent()); 333 auto mockRenderContext = AceType::DynamicCast<MockRenderContext>(frameNode->GetRenderContext()); 334 mockRenderContext->SetPaintRectWithTransform(RectF(10.0f, 10.0f, 10.0f, 0.0f)); 335 auto mockRenderContext1 = AceType::DynamicCast<MockRenderContext>(frameNode1->GetRenderContext()); 336 mockRenderContext1->SetPaintRectWithTransform(RectF(10.0f, 10.0f, 10.0f, 10.0f)); 337 EXPECT_FALSE(frameNode->IsContextTransparent()); 338 mockRenderContext->SetPaintRectWithTransform(RectF(10.0f, 10.0f, 10.0f, 10.0f)); 339 EXPECT_FALSE(frameNode->IsContextTransparent()); 340 frameNode->layoutProperty_->propVisibility_ = VisibleType::INVISIBLE; 341 EXPECT_FALSE(frameNode->IsContextTransparent()); 342 frameNode->layoutProperty_->propVisibility_ = VisibleType::VISIBLE; 343 frameNode->GetRenderContext()->UpdateBackgroundColor(Color::BLUE); 344 EXPECT_FALSE(frameNode->IsContextTransparent()); 345 } 346 347 /** 348 * @tc.name: AddTouchEventAllFingersInfoTest 349 * @tc.desc: Test the function AddTouchEventAllFingersInfo 350 * @tc.type: FUNC 351 */ 352 HWTEST_F(FrameNodeTestNg, AddTouchEventAllFingersInfoTest, TestSize.Level1) 353 { 354 /** 355 * @tc.steps: step1. create frameNode. 356 */ 357 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 358 /** 359 * @tc.steps: step2. call the function AddTouchEventAllFingersInfoTest. 360 */ 361 TouchEventInfo touchEventInfo("touch"); 362 TouchEvent touchEvent; 363 TouchPoint touchPoint; 364 touchEvent.pointers.emplace_back(touchPoint); 365 TouchPoint touchPoint1; 366 touchPoint1.tiltX = 10.0; 367 touchPoint1.tiltY = 10.0; 368 touchEvent.pointers.emplace_back(touchPoint1); 369 frameNode->AddTouchEventAllFingersInfo(touchEventInfo, touchEvent); 370 EXPECT_EQ(touchEventInfo.touches_.size(), 2); 371 } 372 373 /** 374 * @tc.name: TriggerOnTouchInterceptTest 375 * @tc.desc: Test the function TriggerOnTouchIntercept 376 * @tc.type: FUNC 377 */ 378 HWTEST_F(FrameNodeTestNg, TriggerOnTouchInterceptTest, TestSize.Level1) 379 { 380 /** 381 * @tc.steps: step1. create frameNode. 382 */ 383 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 384 /** 385 * @tc.steps: step2. call the function AddTouchEventAllFingersInfoTest. 386 */ 387 auto gestureHub = frameNode->GetOrCreateEventHub<EventHub>()->GetOrCreateGestureEventHub(); __anond32069d10402(TouchEventInfo& touchEventInfo) 388 TouchInterceptFunc touchInterceptFunc = [](TouchEventInfo& touchEventInfo) { return HitTestMode::HTMBLOCK; }; 389 gestureHub->SetOnTouchIntercept(std::move(touchInterceptFunc)); 390 TouchEventInfo touchEventInfo("touch"); 391 TouchEvent touchEvent; 392 EXPECT_EQ(frameNode->TriggerOnTouchIntercept(touchEvent), HitTestMode::HTMBLOCK); 393 touchEvent.tiltX = 10.0; 394 touchEvent.tiltY = 10.0; 395 EXPECT_EQ(frameNode->TriggerOnTouchIntercept(touchEvent), HitTestMode::HTMBLOCK); 396 } 397 398 /** 399 * @tc.name: CalculateCachedTransformRelativeOffsetTest 400 * @tc.desc: Test the function CalculateCachedTransformRelativeOffset 401 * @tc.type: FUNC 402 */ 403 HWTEST_F(FrameNodeTestNg, CalculateCachedTransformRelativeOffsetTest, TestSize.Level1) 404 { 405 /** 406 * @tc.steps: step1. create frameNode. 407 */ 408 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 409 /** 410 * @tc.steps: step2. call the function CalculateCachedTransformRelativeOffset. 411 */ 412 frameNode->CalculateCachedTransformRelativeOffset(0); 413 auto child = FrameNode::CreateFrameNode("child", 2, AceType::MakeRefPtr<Pattern>(), true); 414 frameNode->AddChild(child); 415 child->CalculateCachedTransformRelativeOffset(0); 416 frameNode->exposureProcessor_ = AceType::MakeRefPtr<Recorder::ExposureProcessor>("test", "0"); 417 frameNode->RecordExposureInner(); 418 EXPECT_EQ(child->CalculateCachedTransformRelativeOffset(0), OffsetF(0, 0)); 419 EXPECT_EQ(child->CalculateCachedTransformRelativeOffset(10), OffsetF(0, 0)); 420 } 421 422 /** 423 * @tc.name: ProcessVisibleAreaChangeEventTest 424 * @tc.desc: Test the function ProcessVisibleAreaChangeEvent 425 * @tc.type: FUNC 426 */ 427 HWTEST_F(FrameNodeTestNg, ProcessVisibleAreaChangeEventTest, TestSize.Level1) 428 { 429 /** 430 * @tc.steps: step1. create frameNode. 431 */ 432 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 433 RectF visibleRect = { 10.0, 10.0, 10.0, 10.0 }; 434 RectF frameRect = { 10.0, 10.0, 10.0, 10.0 }; 435 std::vector<double> visibleAreaRatios = { 0.0, 0.0 }; 436 VisibleCallbackInfo visibleAreaCallback; 437 438 /** 439 * @tc.steps: step2. call the function ProcessVisibleAreaChangeEvent. 440 */ 441 // !NearEqual 442 frameNode->ProcessVisibleAreaChangeEvent(visibleRect, frameRect, visibleAreaRatios, visibleAreaCallback, true); 443 // NearEqual 444 frameNode->ProcessVisibleAreaChangeEvent(visibleRect, frameRect, visibleAreaRatios, visibleAreaCallback, true); 445 EXPECT_EQ(frameNode->lastVisibleRatio_, 1.0); 446 // !NearEqual 447 frameNode->ProcessVisibleAreaChangeEvent(visibleRect, frameRect, visibleAreaRatios, visibleAreaCallback, false); 448 // NearEqual 449 frameNode->ProcessVisibleAreaChangeEvent(visibleRect, frameRect, visibleAreaRatios, visibleAreaCallback, false); 450 EXPECT_EQ(frameNode->lastInnerVisibleRatio_, 1.0); 451 } 452 453 /** 454 * @tc.name: FrameNodeTestNg_AxisTest001 455 * @tc.desc: Test frame node method 456 * @tc.type: FUNC 457 */ 458 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest001, TestSize.Level1) 459 { 460 /** 461 * @tc.steps: step1. callback AxisTest. 462 * @tc.expected: expect isActive_ is flase and. 463 */ 464 PointF globalPoint; 465 PointF parentLocalPoint; 466 PointF parentRevertPoint; 467 TouchRestrict touchRestrict; 468 AxisTestResult onAxisResult; 469 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 470 ASSERT_NE(frameNode, nullptr); 471 frameNode->isActive_ = false; 472 /** 473 * @tc.steps: step2. callback AxisTest. 474 * @tc.expected: expect eventHub_ is nullptr. 475 */ 476 ASSERT_EQ(frameNode->eventHub_, nullptr); 477 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 478 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 479 /** 480 * @tc.steps: step3. callback AxisTest. 481 * @tc.expected: expect eventHub_ is not nullptr and enabled_ is false. 482 */ 483 frameNode->eventHub_ = AceType::MakeRefPtr<EventHub>(); 484 ASSERT_NE(frameNode->eventHub_, nullptr); 485 auto eventHub_ = frameNode->eventHub_; 486 eventHub_->enabled_ = false; 487 result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 488 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 489 /** 490 * @tc.steps: step4. callback AxisTest. 491 * @tc.expected: expect eventHub_ is not nullptr and enabled_ is true. 492 */ 493 eventHub_->enabled_ = true; 494 result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 495 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 496 } 497 498 /** 499 * @tc.name: FrameNodeTestNg_AxisTest002 500 * @tc.desc: Test frame node method 501 * @tc.type: FUNC 502 */ 503 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest002, TestSize.Level1) 504 { 505 /** 506 * @tc.steps: step1. callback AxisTest. 507 * @tc.expected: expect isActive_ is true and. 508 */ 509 PointF globalPoint; 510 PointF parentLocalPoint; 511 PointF parentRevertPoint; 512 TouchRestrict touchRestrict; 513 AxisTestResult onAxisResult; 514 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 515 ASSERT_NE(frameNode, nullptr); 516 EXPECT_TRUE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 517 frameNode->isActive_ = true; 518 /** 519 * @tc.steps: step2. callback AxisTest. 520 * @tc.expected: expect eventHub_ is nullptr. 521 */ 522 ASSERT_EQ(frameNode->eventHub_, nullptr); 523 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 524 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 525 /** 526 * @tc.steps: step3. callback AxisTest. 527 * @tc.expected: expect eventHub_ is not nullptr and enabled_ is false. 528 */ 529 frameNode->eventHub_ = AceType::MakeRefPtr<EventHub>(); 530 ASSERT_NE(frameNode->eventHub_, nullptr); 531 auto eventHub_ = frameNode->eventHub_; 532 eventHub_->enabled_ = false; 533 result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 534 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 535 /** 536 * @tc.steps: step4. callback AxisTest. 537 * @tc.expected: expect eventHub_ is not nullptr and enabled_ is true. 538 */ 539 eventHub_->enabled_ = true; 540 result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 541 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 542 } 543 544 /** 545 * @tc.name: FrameNodeTestNg_AxisTest003 546 * @tc.desc: Test frame node method 547 * @tc.type: FUNC 548 */ 549 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest003, TestSize.Level1) 550 { 551 /** 552 * @tc.steps: step1. callback AxisTest. 553 * @tc.expected: expect isActive_ is true and. 554 */ 555 PointF globalPoint; 556 PointF parentLocalPoint = { 1.0f, 1.0f }; 557 PointF parentRevertPoint = { 1.0f, 1.0f }; 558 TouchRestrict touchRestrict; 559 AxisTestResult onAxisResult; 560 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 561 ASSERT_NE(frameNode, nullptr); 562 frameNode->isActive_ = true; 563 auto eventHub_ = AceType::MakeRefPtr<EventHub>(); 564 ASSERT_NE(eventHub_, nullptr); 565 frameNode->eventHub_ = eventHub_; 566 eventHub_->enabled_ = true; 567 /** 568 * @tc.steps: step2. callback AxisTest. 569 * @tc.expected: expect IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent) is false. 570 */ 571 auto renderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 572 ASSERT_NE(renderContext_, nullptr); 573 frameNode->renderContext_ = renderContext_; 574 renderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 575 frameNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 576 EXPECT_FALSE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 577 /** 578 * @tc.steps: step3. callback AxisTest. 579 * @tc.expected: expect consumed is false. 580 */ 581 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 582 EXPECT_EQ(result, HitTestResult::BUBBLING); 583 } 584 585 /** 586 * @tc.name: FrameNodeTestNg_AxisTest004 587 * @tc.desc: Test frame node method 588 * @tc.type: FUNC 589 */ 590 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest004, TestSize.Level1) 591 { 592 /** 593 * @tc.steps: step1. callback AxisTest. 594 * @tc.expected: expect isActive_ is true and. 595 */ 596 PointF globalPoint; 597 PointF parentLocalPoint = { 1.0f, 1.0f }; 598 PointF parentRevertPoint = { 1.0f, 1.0f }; 599 TouchRestrict touchRestrict; 600 AxisTestResult onAxisResult; 601 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 602 ASSERT_NE(frameNode, nullptr); 603 frameNode->isActive_ = true; 604 auto eventHub_ = AceType::MakeRefPtr<EventHub>(); 605 ASSERT_NE(eventHub_, nullptr); 606 frameNode->eventHub_ = eventHub_; 607 eventHub_->enabled_ = true; 608 /** 609 * @tc.steps: step2. callback AxisTest. 610 * @tc.expected: expect IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent) is false. 611 */ 612 auto renderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 613 ASSERT_NE(renderContext_, nullptr); 614 frameNode->renderContext_ = renderContext_; 615 renderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 616 frameNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 617 auto childNode = FrameNode::CreateFrameNode("childNode", 2, AceType::MakeRefPtr<Pattern>(), true); 618 /** 619 * @tc.steps: step3. callback AxisTest. 620 * @tc.expected: expect GetHitTestMode() == HitTestMode::HTMBLOCK is false. 621 */ 622 std::list<RefPtr<FrameNode>> children; 623 children.push_back(childNode); 624 frameNode->frameChildren_ = { children.begin(), children.end() }; 625 EXPECT_FALSE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 626 /** 627 * @tc.steps: step5. callback AxisTest. 628 * @tc.expected: expect consumed is true. 629 */ 630 auto gestureHub = eventHub_->GetOrCreateGestureEventHub(); 631 ASSERT_NE(gestureHub, nullptr); 632 gestureHub->hitTestMode_ = HitTestMode::HTMNONE; 633 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 634 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 635 } 636 637 /** 638 * @tc.name: FrameNodeTestNg_AxisTest005 639 * @tc.desc: Test frame node method 640 * @tc.type: FUNC 641 */ 642 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest005, TestSize.Level1) 643 { 644 /** 645 * @tc.steps: step1. callback AxisTest. 646 * @tc.expected: expect isActive_ is true and. 647 */ 648 PointF globalPoint; 649 PointF parentLocalPoint = { 1.0f, 1.0f }; 650 PointF parentRevertPoint = { 1.0f, 1.0f }; 651 TouchRestrict touchRestrict; 652 AxisTestResult onAxisResult; 653 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 654 ASSERT_NE(frameNode, nullptr); 655 frameNode->isActive_ = true; 656 auto eventHub_ = AceType::MakeRefPtr<EventHub>(); 657 ASSERT_NE(eventHub_, nullptr); 658 frameNode->eventHub_ = eventHub_; 659 eventHub_->enabled_ = true; 660 /** 661 * @tc.steps: step2. callback AxisTest. 662 * @tc.expected: expect IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent) is false. 663 */ 664 auto renderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 665 ASSERT_NE(renderContext_, nullptr); 666 frameNode->renderContext_ = renderContext_; 667 renderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 668 frameNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 669 auto childNode = FrameNode::CreateFrameNode("childNode", 2, AceType::MakeRefPtr<Pattern>(), true); 670 /** 671 * @tc.steps: step3. callback AxisTest. 672 * @tc.expected: expect GetHitTestMode() == HitTestMode::HTMBLOCK is true. 673 */ 674 std::list<RefPtr<FrameNode>> children; 675 children.push_back(childNode); 676 frameNode->frameChildren_ = { children.begin(), children.end() }; 677 EXPECT_FALSE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 678 auto gestureHub = eventHub_->GetOrCreateGestureEventHub(); 679 ASSERT_NE(gestureHub, nullptr); 680 gestureHub->hitTestMode_ = HitTestMode::HTMBLOCK; 681 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 682 EXPECT_EQ(result, HitTestResult::STOP_BUBBLING); 683 } 684 685 /** 686 * @tc.name: FrameNodeTestNg_AxisTest006 687 * @tc.desc: Test frame node method 688 * @tc.type: FUNC 689 */ 690 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest006, TestSize.Level1) 691 { 692 /** 693 * @tc.steps: step1. callback AxisTest. 694 * @tc.expected: expect isActive_ is true and. 695 */ 696 PointF globalPoint; 697 PointF parentLocalPoint = { 1.0f, 1.0f }; 698 PointF parentRevertPoint = { 1.0f, 1.0f }; 699 TouchRestrict touchRestrict; 700 AxisTestResult onAxisResult; 701 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 702 ASSERT_NE(frameNode, nullptr); 703 frameNode->isActive_ = true; 704 auto eventHub_ = AceType::MakeRefPtr<EventHub>(); 705 ASSERT_NE(eventHub_, nullptr); 706 frameNode->eventHub_ = eventHub_; 707 eventHub_->enabled_ = true; 708 /** 709 * @tc.steps: step2. callback AxisTest. 710 * @tc.expected: expect IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent) is false. 711 */ 712 auto renderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 713 ASSERT_NE(renderContext_, nullptr); 714 frameNode->renderContext_ = renderContext_; 715 renderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 716 frameNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 717 /** 718 * @tc.steps: step3. callback AxisTest. 719 * @tc.expected: expect !child is true. 720 */ 721 auto childNode = nullptr; 722 std::list<RefPtr<FrameNode>> children; 723 children.push_back(childNode); 724 frameNode->frameChildren_ = { children.begin(), children.end() }; 725 EXPECT_FALSE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 726 auto gestureHub = eventHub_->GetOrCreateGestureEventHub(); 727 ASSERT_NE(gestureHub, nullptr); 728 gestureHub->hitTestMode_ = HitTestMode::HTMNONE; 729 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 730 EXPECT_EQ(result, HitTestResult::OUT_OF_REGION); 731 } 732 733 /** 734 * @tc.name: FrameNodeTestNg_AxisTest007 735 * @tc.desc: Test frame node method 736 * @tc.type: FUNC 737 */ 738 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest007, TestSize.Level1) 739 { 740 /** 741 * @tc.steps: step1. callback AxisTest. 742 * @tc.expected: expect isActive_ is true and. 743 */ 744 PointF globalPoint; 745 PointF parentLocalPoint = { 3.0f, 3.0f }; 746 PointF parentRevertPoint = { 2.0f, 2.0f }; 747 TouchRestrict touchRestrict; 748 AxisTestResult onAxisResult; 749 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 750 ASSERT_NE(frameNode, nullptr); 751 frameNode->isActive_ = true; 752 auto eventHub_ = AceType::MakeRefPtr<EventHub>(); 753 ASSERT_NE(eventHub_, nullptr); 754 frameNode->eventHub_ = eventHub_; 755 eventHub_->enabled_ = true; 756 /** 757 * @tc.steps: step2. callback AxisTest. 758 * @tc.expected: expect IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent) is false. 759 */ 760 auto renderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 761 ASSERT_NE(renderContext_, nullptr); 762 frameNode->renderContext_ = renderContext_; 763 renderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 764 frameNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 765 auto childNode = FrameNode::CreateFrameNode("childNode", 2, AceType::MakeRefPtr<Pattern>(), true); 766 ASSERT_NE(childNode, nullptr); 767 /** 768 * @tc.steps: step3. callback AxisTest. 769 * @tc.expected: expect CheckChildHitTestResult is true. 770 */ 771 childNode->isActive_ = true; 772 auto childEventHub_ = AceType::MakeRefPtr<EventHub>(); 773 ASSERT_NE(childEventHub_, nullptr); 774 childNode->eventHub_ = childEventHub_; 775 childEventHub_->enabled_ = true; 776 auto childRenderContext_ = AceType::MakeRefPtr<MockRenderContext>(); 777 ASSERT_NE(childRenderContext_, nullptr); 778 childNode->renderContext_ = childRenderContext_; 779 childRenderContext_->paintRect_ = { 1.0f, 1.0f, 1.0f, 1.0f }; 780 childNode->GetOrRefreshMatrixFromCache().paintRectWithTransform = { 1.0f, 1.0f, 1.0f, 1.0f }; 781 auto childGestureHub = childEventHub_->GetOrCreateGestureEventHub(); 782 childGestureHub->hitTestMode_ = HitTestMode::HTMDEFAULT; 783 std::list<RefPtr<FrameNode>> children; 784 children.push_back(childNode); 785 frameNode->frameChildren_ = { children.begin(), children.end() }; 786 EXPECT_FALSE(frameNode->IsOutOfTouchTestRegion(parentRevertPoint, touchRestrict.touchEvent)); 787 auto gestureHub = eventHub_->GetOrCreateGestureEventHub(); 788 ASSERT_NE(gestureHub, nullptr); 789 gestureHub->hitTestMode_ = HitTestMode::HTMNONE; 790 auto result = frameNode->AxisTest(globalPoint, parentLocalPoint, parentRevertPoint, touchRestrict, onAxisResult); 791 EXPECT_EQ(result, HitTestResult::BUBBLING); 792 } 793 794 /** 795 * @tc.name: FrameNodeAxisTest008 796 * @tc.desc: Test frameNode AxisTest & hitTestBehavior when parent is HTMBLOCK_HIERARCHY and child is default and 797 * consumed event 798 * @tc.type: FUNC 799 */ 800 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest008, TestSize.Level1) 801 { 802 /** 803 * @tc.steps: step1. construct AxisTest parameters. 804 */ 805 TouchRestrict touchRestrict; 806 AxisTestResult result; 807 808 /** 809 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 810 */ 811 FRAME_NODE_PARENT->isActive_ = true; 812 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 813 parentEventHub->SetEnabled(true); 814 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 815 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); 816 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 817 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 818 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 819 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 820 auto localPoint = PointF(10, 10); 821 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 822 823 /** 824 * @tc.steps: step3. create childnode. 825 */ 826 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 827 childNode->SetExclusiveEventForChild(true); 828 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 829 mockRenderContextforChild->rect_ = RectF(50, 50, 50, 50); 830 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 831 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 832 childNode->renderContext_ = mockRenderContextforChild; 833 childNode->SetActive(true); 834 835 /** 836 * @tc.steps: step4. add childnode to the framenode. 837 * @tc.expected: expect The function return value is BLOCK_HIERARCHY. 838 */ 839 std::list<RefPtr<FrameNode>> children; 840 children.push_back(childNode); 841 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 842 auto test = FRAME_NODE_PARENT->AxisTest(localPoint, localPoint, localPoint, touchRestrict, result); 843 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 844 } 845 846 /** 847 * @tc.name: FrameNodeAxisTest009 848 * @tc.desc: Test frameNode AxisTest & hitTestBehavior when parent is HTMBLOCK_HIERARCHY and child is default and 849 * not consumed event 850 * @tc.type: FUNC 851 */ 852 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest009, TestSize.Level1) 853 { 854 /** 855 * @tc.steps: step1. construct AxisTest parameters. 856 */ 857 TouchRestrict touchRestrict; 858 AxisTestResult result; 859 860 /** 861 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 862 */ 863 FRAME_NODE_PARENT->isActive_ = true; 864 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 865 parentEventHub->SetEnabled(true); 866 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 867 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); 868 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 869 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 870 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 871 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 872 auto localPoint = PointF(10, 10); 873 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 874 875 /** 876 * @tc.steps: step3. create childnode. 877 */ 878 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 879 childNode->SetExclusiveEventForChild(true); 880 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 881 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 882 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 883 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 884 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 885 childNode->renderContext_ = mockRenderContextforChild; 886 childNode->SetActive(true); 887 888 /** 889 * @tc.steps: step4. add childnode to the framenode. 890 * @tc.expected: expect The function return value is BLOCK_HIERARCHY. 891 */ 892 std::list<RefPtr<FrameNode>> children; 893 children.push_back(childNode); 894 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 895 auto test = FRAME_NODE_PARENT->AxisTest(localPoint, localPoint, localPoint, touchRestrict, result); 896 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 897 } 898 899 /** 900 * @tc.name: FrameNodeAxisTest010 901 * @tc.desc: Test frameNode AxisTest & hitTestBehavior when parent is HTMBLOCK_DESCENDANTS and child is default and 902 * not consumed event 903 * @tc.type: FUNC 904 */ 905 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest010, TestSize.Level1) 906 { 907 /** 908 * @tc.steps: step1. construct AxisTest parameters. 909 */ 910 TouchRestrict touchRestrict; 911 AxisTestResult result; 912 913 /** 914 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 915 */ 916 FRAME_NODE_PARENT->isActive_ = true; 917 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 918 parentEventHub->SetEnabled(true); 919 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 920 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_DESCENDANTS); 921 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 922 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 923 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 924 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 925 auto localPoint = PointF(10, 10); 926 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); __anond32069d10502(TouchEventInfo& info) 927 TouchEventFunc touchEventFunc = [](TouchEventInfo& info) {}; 928 parentGestureEventHub->SetOnTouchEvent(std::move(touchEventFunc)); 929 EXPECT_NE(parentGestureEventHub->touchEventActuator_, nullptr); 930 931 /** 932 * @tc.steps: step3. create childnode. 933 */ 934 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 935 childNode->SetExclusiveEventForChild(true); 936 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 937 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 938 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 939 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 940 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 941 childNode->renderContext_ = mockRenderContextforChild; 942 childNode->SetActive(true); 943 944 /** 945 * @tc.steps: step4. add childnode to the framenode. 946 * @tc.expected: expect The function return value is STOP_BUBBLING. 947 */ 948 std::list<RefPtr<FrameNode>> children; 949 children.push_back(childNode); 950 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 951 auto test = FRAME_NODE_PARENT->AxisTest(localPoint, localPoint, localPoint, touchRestrict, result); 952 EXPECT_EQ(test, HitTestResult::BUBBLING); 953 EXPECT_TRUE(result.empty()); 954 } 955 956 /** 957 * @tc.name: FrameNodeAxisTest011 958 * @tc.desc: Test frameNode AxisTest & hitTestBehavior when parent is default and child is HTMBLOCK_HIERARCHY 959 * @tc.type: FUNC 960 */ 961 HWTEST_F(FrameNodeTestNg, FrameNodeAxisTest011, TestSize.Level1) 962 { 963 /** 964 * @tc.steps: step1. construct AxisTest parameters. 965 */ 966 TouchRestrict touchRestrict; 967 AxisTestResult result; 968 969 /** 970 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 971 */ 972 FRAME_NODE_PARENT->isActive_ = true; 973 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 974 parentEventHub->SetEnabled(true); 975 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 976 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 977 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 978 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 979 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 980 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 981 auto localPoint = PointF(10, 10); 982 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 983 const auto& inputEventHub = parentEventHub->GetOrCreateInputEventHub(); __anond32069d10602(AxisInfo& info) 984 inputEventHub->SetAxisEvent([](AxisInfo& info) {}); 985 986 /** 987 * @tc.steps: step3. create childnode. 988 */ 989 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 990 childNode->SetExclusiveEventForChild(true); 991 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 992 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 993 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 994 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 995 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 996 childNode->renderContext_ = mockRenderContextforChild; 997 childNode->SetActive(true); 998 auto childGestureEventHub = childNode->GetOrCreateGestureEventHub(); 999 childGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); 1000 const auto& childInputEventHub = childNode->GetOrCreateEventHub<EventHub>()->GetOrCreateInputEventHub(); __anond32069d10702(AxisInfo& info) 1001 childInputEventHub->SetAxisEvent([](AxisInfo& info) {}); 1002 1003 /** 1004 * @tc.steps: step4. add childnode to the framenode. 1005 * @tc.expected: expect The function return value is BLOCK_HIERARCHY. 1006 */ 1007 std::list<RefPtr<FrameNode>> children; 1008 children.push_back(childNode); 1009 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1010 auto test = FRAME_NODE_PARENT->AxisTest(localPoint, localPoint, localPoint, touchRestrict, result); 1011 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 1012 EXPECT_EQ(result.size(), 1); 1013 } 1014 1015 /** 1016 * @tc.name: FrameNodeTestNg_CheckResponseRegionForStylus001 1017 * @tc.desc: Test frame node method 1018 * @tc.type: FUNC 1019 */ 1020 HWTEST_F(FrameNodeTestNg, CheckResponseRegionForStylus001, TestSize.Level1) 1021 { 1022 auto frameNode = FrameNode::CreateFrameNode("frameNode", 1, AceType::MakeRefPtr<TextFieldPattern>()); 1023 ASSERT_NE(frameNode, nullptr); 1024 TouchEvent touchEvent; 1025 RectF paintRect = { 100.0f, 100.0f, 100.0f, 100.0f }; 1026 touchEvent.sourceTool = SourceTool::FINGER; 1027 touchEvent.type = TouchType::MOVE; 1028 EXPECT_EQ(frameNode->CheckResponseRegionForStylus(paintRect, touchEvent), paintRect); 1029 RectF expectPaintRect = { 100.0f, 80.0f, 100.0f, 140.0f }; 1030 touchEvent.sourceTool = SourceTool::PEN; 1031 touchEvent.type = TouchType::DOWN; 1032 EXPECT_EQ(frameNode->CheckResponseRegionForStylus(paintRect, touchEvent), expectPaintRect); 1033 } 1034 1035 /** 1036 * @tc.name: FrameNodeTriggerOnSizeChangeCallback04 1037 * @tc.desc: Test the function TriggerOnSizeChangeCallback 1038 * @tc.type: FUNC 1039 */ 1040 HWTEST_F(FrameNodeTestNg, FrameNodeTriggerOnSizeChangeCallback04, TestSize.Level1) 1041 { 1042 NG::RectF testLastFrameRect = { 10.0f, 10.0f, 10.0f, 10.0f }; // 10.0f is the x, y, width and height of rect 1043 NG::RectF testCurrFrameRect = { 10.0f, 10.0f, 10.0f, 10.0f }; // 10.0f is the x, y, width and height of rect 1044 FrameNode::onSizeChangeDumpInfo dumpInfoOne { 1, testLastFrameRect, testCurrFrameRect }; 1045 /** 1046 * @tc.steps: step1. create frameNode. 1047 */ 1048 auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<PagePattern>(nullptr), true); 1049 EXPECT_NE(frameNode->pattern_, nullptr); 1050 frameNode->isActive_ = true; 1051 auto pattern = frameNode->GetPattern<PagePattern>(); 1052 pattern->isOnShow_ = true; __anond32069d10802(const RectF& oldRect, const RectF& rect) 1053 OnSizeChangedFunc onSizeChanged = [](const RectF& oldRect, const RectF& rect) {}; 1054 auto eventHub = frameNode->GetOrCreateEventHub<EventHub>(); 1055 eventHub->AddInnerOnSizeChanged(1, std::move(onSizeChanged)); 1056 // auto 1057 frameNode->lastFrameNodeRect_ = 1058 std::make_unique<RectF>(RectF(OffsetF(50.0f, 50.0f), SizeF(50.0f, 50.0f))); // 50.0f is ths offset and size 1059 frameNode->onSizeChangeDumpInfos.push_back(dumpInfoOne); __anond32069d10902(const RectF& oldRect, const RectF& rect) 1060 OnSizeChangedFunc onJsFrameNodeSizeChanged = [node = frameNode](const RectF& oldRect, const RectF& rect) { 1061 node->lastFrameNodeRect_ = nullptr; 1062 }; 1063 eventHub->SetJSFrameNodeOnSizeChangeCallback(std::move(onJsFrameNodeSizeChanged)); 1064 /** 1065 * @tc.steps: step3. call the function TriggerOnSizeChangeCallback. 1066 */ 1067 frameNode->TriggerOnSizeChangeCallback(); 1068 EXPECT_EQ(frameNode->lastFrameNodeRect_, nullptr); 1069 } 1070 1071 /** 1072 * @tc.name: FrameNodeNotifyColorModeChange01 1073 * @tc.desc: Test the function NotifyColorModeChange 1074 * @tc.type: FUNC 1075 */ 1076 HWTEST_F(FrameNodeTestNg, FrameNodeNotifyColorModeChange01, TestSize.Level1) 1077 { 1078 /** 1079 * @tc.steps: step1. create frameNode. 1080 */ 1081 auto frameNode = FrameNode::CreateFrameNode("page", 1, AceType::MakeRefPtr<PagePattern>(nullptr), true); 1082 auto childNode = FrameNode::CreateFrameNode("child", 2, AceType::MakeRefPtr<PagePattern>(nullptr), true); 1083 frameNode->AddChild(childNode); 1084 frameNode->SetRerenderable(true); 1085 childNode->SetMeasureAnyway(true); 1086 /** 1087 * @tc.steps: step2. call the function NotifyColorModeChange. 1088 * @tc.expected: expect childNode Rerenderable is true. 1089 */ 1090 childNode->NotifyColorModeChange(1); 1091 EXPECT_TRUE(childNode->GetRerenderable()); 1092 } 1093 1094 /** 1095 * @tc.name: FrameNodeHitTestMode001 1096 * @tc.desc: Test frameNode TouchTest & hitTestBehavior when parent is HTMBLOCK_HIERARCHY and child is default and 1097 * consumed event 1098 * @tc.type: FUNC 1099 */ 1100 HWTEST_F(FrameNodeTestNg, FrameNodeHitTestMode001, TestSize.Level1) 1101 { 1102 /** 1103 * @tc.steps: step1. construct TouchTest parameters. 1104 */ 1105 TouchRestrict touchRestrict; 1106 TouchTestResult result; 1107 ResponseLinkResult responseLinkResult; 1108 1109 /** 1110 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 1111 */ 1112 FRAME_NODE_PARENT->isActive_ = true; 1113 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 1114 parentEventHub->SetEnabled(true); 1115 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 1116 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); 1117 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1118 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 1119 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 1120 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 1121 auto localPoint = PointF(10, 10); 1122 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1123 1124 /** 1125 * @tc.steps: step3. create childnode. 1126 */ 1127 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1128 childNode->SetExclusiveEventForChild(true); 1129 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1130 mockRenderContextforChild->rect_ = RectF(50, 50, 50, 50); 1131 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1132 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1133 childNode->renderContext_ = mockRenderContextforChild; 1134 childNode->SetActive(true); 1135 1136 /** 1137 * @tc.steps: step4. add childnode to the framenode. 1138 * @tc.expected: expect The function return value is STOP_BUBBLING. 1139 */ 1140 std::list<RefPtr<FrameNode>> children; 1141 children.push_back(childNode); 1142 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1143 auto test = 1144 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1145 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 1146 } 1147 1148 /** 1149 * @tc.name: FrameNodeHitTestMode002 1150 * @tc.desc: Test frameNode TouchTest & hitTestBehavior when parent is HTMBLOCK_HIERARCHY and child is default and 1151 * not consumed event 1152 * @tc.type: FUNC 1153 */ 1154 HWTEST_F(FrameNodeTestNg, FrameNodeHitTestMode002, TestSize.Level1) 1155 { 1156 /** 1157 * @tc.steps: step1. construct TouchTest parameters. 1158 */ 1159 TouchRestrict touchRestrict; 1160 TouchTestResult result; 1161 ResponseLinkResult responseLinkResult; 1162 1163 /** 1164 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 1165 */ 1166 FRAME_NODE_PARENT->isActive_ = true; 1167 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 1168 parentEventHub->SetEnabled(true); 1169 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 1170 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); 1171 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1172 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 1173 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 1174 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 1175 auto localPoint = PointF(10, 10); 1176 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1177 1178 /** 1179 * @tc.steps: step3. create childnode. 1180 */ 1181 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1182 childNode->SetExclusiveEventForChild(true); 1183 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1184 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 1185 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 1186 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1187 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1188 childNode->renderContext_ = mockRenderContextforChild; 1189 childNode->SetActive(true); 1190 1191 /** 1192 * @tc.steps: step4. add childnode to the framenode. 1193 * @tc.expected: expect The function return value is STOP_BUBBLING. 1194 */ 1195 std::list<RefPtr<FrameNode>> children; 1196 children.push_back(childNode); 1197 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1198 auto test = 1199 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1200 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 1201 } 1202 1203 /** 1204 * @tc.name: FrameNodeHitTestMode003 1205 * @tc.desc: Test frameNode TouchTest & hitTestBehavior when parent is HTMBLOCK_DESCENDANTS and child is default and 1206 * not consumed event 1207 * @tc.type: FUNC 1208 */ 1209 HWTEST_F(FrameNodeTestNg, FrameNodeHitTestMode003, TestSize.Level1) 1210 { 1211 /** 1212 * @tc.steps: step1. construct TouchTest parameters. 1213 */ 1214 TouchRestrict touchRestrict; 1215 TouchTestResult result; 1216 ResponseLinkResult responseLinkResult; 1217 1218 /** 1219 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 1220 */ 1221 FRAME_NODE_PARENT->isActive_ = true; 1222 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 1223 parentEventHub->SetEnabled(true); 1224 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 1225 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_DESCENDANTS); 1226 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1227 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 1228 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 1229 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 1230 auto localPoint = PointF(10, 10); 1231 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); __anond32069d10a02(TouchEventInfo& info) 1232 TouchEventFunc touchEventFunc = [](TouchEventInfo& info) {}; 1233 parentGestureEventHub->SetOnTouchEvent(std::move(touchEventFunc)); 1234 EXPECT_NE(parentGestureEventHub->touchEventActuator_, nullptr); 1235 1236 /** 1237 * @tc.steps: step3. create childnode. 1238 */ 1239 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1240 childNode->SetExclusiveEventForChild(true); 1241 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1242 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 1243 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 1244 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1245 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1246 childNode->renderContext_ = mockRenderContextforChild; 1247 childNode->SetActive(true); 1248 1249 /** 1250 * @tc.steps: step4. add childnode to the framenode. 1251 * @tc.expected: expect The function return value is STOP_BUBBLING. 1252 */ 1253 std::list<RefPtr<FrameNode>> children; 1254 children.push_back(childNode); 1255 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1256 auto test = 1257 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1258 EXPECT_EQ(test, HitTestResult::BUBBLING); 1259 EXPECT_TRUE(result.empty()); 1260 } 1261 1262 /** 1263 * @tc.name: FrameNodeHitTestMode004 1264 * @tc.desc: Test frameNode TouchTest & hitTestBehavior when parent is default and child is HTMBLOCK_HIERARCHY 1265 * @tc.type: FUNC 1266 */ 1267 HWTEST_F(FrameNodeTestNg, FrameNodeHitTestMode004, TestSize.Level1) 1268 { 1269 /** 1270 * @tc.steps: step1. construct TouchTest parameters. 1271 */ 1272 TouchRestrict touchRestrict; 1273 TouchTestResult result; 1274 ResponseLinkResult responseLinkResult; 1275 1276 /** 1277 * @tc.steps: step2. create parent node and set HTMBLOCK_HIERARCHY. 1278 */ 1279 FRAME_NODE_PARENT->isActive_ = true; 1280 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 1281 parentEventHub->SetEnabled(true); 1282 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 1283 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 1284 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1285 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 1286 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 1287 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 1288 auto localPoint = PointF(10, 10); 1289 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); __anond32069d10b02(TouchEventInfo& info) 1290 TouchEventFunc touchEventFunc = [](TouchEventInfo& info) {}; 1291 parentGestureEventHub->SetOnTouchEvent(std::move(touchEventFunc)); 1292 EXPECT_NE(parentGestureEventHub->touchEventActuator_, nullptr); 1293 1294 /** 1295 * @tc.steps: step3. create childnode. 1296 */ 1297 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1298 childNode->SetExclusiveEventForChild(true); 1299 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1300 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 1301 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 1302 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1303 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1304 childNode->renderContext_ = mockRenderContextforChild; 1305 childNode->SetActive(true); 1306 auto childGestureEventHub = childNode->GetOrCreateGestureEventHub(); 1307 childGestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK_HIERARCHY); __anond32069d10c02(TouchEventInfo& info) 1308 TouchEventFunc childTouchEventFunc = [](TouchEventInfo& info) {}; 1309 childGestureEventHub->SetOnTouchEvent(std::move(childTouchEventFunc)); 1310 EXPECT_NE(childGestureEventHub->touchEventActuator_, nullptr); 1311 1312 /** 1313 * @tc.steps: step4. add childnode to the framenode. 1314 * @tc.expected: expect The function return value is STOP_BUBBLING. 1315 */ 1316 std::list<RefPtr<FrameNode>> children; 1317 children.push_back(childNode); 1318 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1319 auto test = 1320 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1321 EXPECT_EQ(test, HitTestResult::BLOCK_HIERARCHY); 1322 EXPECT_EQ(result.size(), 1); 1323 } 1324 1325 /** 1326 * @tc.name: FrameNodeHitTestMode005 1327 * @tc.desc: Test frameNode TouchTest & hitTestBehavior when parent is default and child is HTMBLOCK_HIERARCHY 1328 * @tc.type: FUNC 1329 */ 1330 HWTEST_F(FrameNodeTestNg, FrameNodeHitTestMode005, TestSize.Level1) 1331 { 1332 /** 1333 * @tc.steps: step1. construct TouchTest parameters. 1334 */ 1335 TouchRestrict touchRestrict; 1336 TouchTestResult result; 1337 ResponseLinkResult responseLinkResult; 1338 1339 /** 1340 * @tc.steps: step2. create parent node and set onTouchIntercept and onChildTouchTestFunc. 1341 */ 1342 FRAME_NODE_PARENT->isActive_ = true; 1343 auto parentEventHub = FRAME_NODE_PARENT->GetOrCreateEventHub<EventHub>(); 1344 parentEventHub->SetEnabled(true); 1345 auto parentGestureEventHub = FRAME_NODE_PARENT->GetOrCreateGestureEventHub(); 1346 parentGestureEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); 1347 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>(); 1348 mockRenderContext->rect_ = RectF(0, 0, 100, 100); 1349 mockRenderContext->paintRect_ = RectF(0, 0, 100, 100); 1350 FRAME_NODE_PARENT->renderContext_ = mockRenderContext; 1351 auto localPoint = PointF(10, 10); 1352 EXPECT_CALL(*mockRenderContext, GetPointWithTransform(_)).WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); __anond32069d10d02(TouchEventInfo& info) 1353 TouchEventFunc touchEventFunc = [](TouchEventInfo& info) {}; 1354 parentGestureEventHub->SetOnTouchEvent(std::move(touchEventFunc)); 1355 EXPECT_NE(parentGestureEventHub->touchEventActuator_, nullptr); __anond32069d10e02(TouchEventInfo& touchEventInfo) 1356 TouchInterceptFunc touchInterceptFunc = [](TouchEventInfo& touchEventInfo) { 1357 return HitTestMode::HTMBLOCK_DESCENDANTS; 1358 }; 1359 parentGestureEventHub->SetOnTouchIntercept(std::move(touchInterceptFunc)); 1360 bool onChildTouchTestTriggerd = false; __anond32069d10f02(const std::vector<TouchTestInfo>& touchInfo) 1361 OnChildTouchTestFunc callback = [&onChildTouchTestTriggerd](const std::vector<TouchTestInfo>& touchInfo) { 1362 TouchResult res; 1363 res.strategy = TouchTestStrategy::DEFAULT; 1364 onChildTouchTestTriggerd = true; 1365 return res; 1366 }; 1367 parentGestureEventHub->SetOnTouchTestFunc(std::move(callback)); 1368 1369 /** 1370 * @tc.steps: step3. create childnode. 1371 */ 1372 auto childNode = FrameNode::CreateFrameNode("main", 2, AceType::MakeRefPtr<Pattern>(), true); 1373 childNode->SetExclusiveEventForChild(true); 1374 auto mockRenderContextforChild = AceType::MakeRefPtr<MockRenderContext>(); 1375 mockRenderContextforChild->rect_ = RectF(0, 0, 50, 50); 1376 mockRenderContextforChild->paintRect_ = RectF(0, 0, 50, 50); 1377 EXPECT_CALL(*mockRenderContextforChild, GetPointWithTransform(_)) 1378 .WillRepeatedly(DoAll(SetArgReferee<0>(localPoint))); 1379 childNode->renderContext_ = mockRenderContextforChild; 1380 childNode->SetActive(true); 1381 auto childGestureEventHub = childNode->GetOrCreateGestureEventHub(); 1382 childGestureEventHub->SetHitTestMode(HitTestMode::HTMDEFAULT); __anond32069d11002(TouchEventInfo& info) 1383 TouchEventFunc childTouchEventFunc = [](TouchEventInfo& info) {}; 1384 childGestureEventHub->SetOnTouchEvent(std::move(childTouchEventFunc)); 1385 EXPECT_NE(childGestureEventHub->touchEventActuator_, nullptr); 1386 1387 /** 1388 * @tc.steps: step4. add childnode to the framenode. 1389 * @tc.expected: expect The function return value is STOP_BUBBLING and onChildTouchTestTriggerd is false. 1390 */ 1391 std::list<RefPtr<FrameNode>> children; 1392 children.push_back(childNode); 1393 FRAME_NODE_PARENT->frameChildren_ = { children.begin(), children.end() }; 1394 auto test = 1395 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1396 EXPECT_EQ(test, HitTestResult::BUBBLING); 1397 EXPECT_EQ(result.size(), 0); 1398 EXPECT_FALSE(onChildTouchTestTriggerd); 1399 result.clear(); 1400 /** 1401 * @tc.steps: step4. change onTouchIntercept func. 1402 * @tc.expected: expect The function return value is BUBBLING and onChildTouchTestTriggerd is true. 1403 */ __anond32069d11102(TouchEventInfo& touchEventInfo) 1404 TouchInterceptFunc touchInterceptFuncNew = [](TouchEventInfo& touchEventInfo) { return HitTestMode::HTMDEFAULT; }; 1405 parentGestureEventHub->SetOnTouchIntercept(std::move(touchInterceptFuncNew)); 1406 test = 1407 FRAME_NODE_PARENT->TouchTest(localPoint, localPoint, localPoint, touchRestrict, result, 1, responseLinkResult); 1408 EXPECT_EQ(test, HitTestResult::BUBBLING); 1409 EXPECT_EQ(result.size(), 2); 1410 EXPECT_TRUE(onChildTouchTestTriggerd); 1411 FRAME_NODE_PARENT->renderContext_ = nullptr; 1412 } 1413 1414 /** 1415 * @tc.name: FrameNodeSetFocusDependenceTestMode001 1416 * @tc.desc: Test the function SetFocusDependence 1417 * @tc.type: FUNC 1418 */ 1419 HWTEST_F(FrameNodeTestNg, FrameNodeSetFocusDependenceTestMode001, TestSize.Level1) 1420 { 1421 /** 1422 * @tc.steps: step1. create frameNode. 1423 */ 1424 auto frameNode = FrameNode::CreateFrameNode("framenode", 1, AceType::MakeRefPtr<Pattern>(), true); 1425 auto childNode = FrameNode::CreateFrameNode("childNode", 1, AceType::MakeRefPtr<Pattern>(), true); 1426 /** 1427 * @tc.steps: step2. call the function SetFocusDependence. 1428 */ 1429 auto focusHub = frameNode->GetOrCreateFocusHub(); 1430 CHECK_NULL_VOID(focusHub); 1431 focusHub->SetFocusDependence(FocusDependence::SELF); 1432 /** 1433 * @tc.steps: step3. getFocusDependence. 1434 * @tc.expected: expect The function return value is SELF. 1435 */ 1436 EXPECT_EQ(focusHub->GetFocusDependence(), FocusDependence::SELF); 1437 } 1438 } // namespace OHOS::Ace::NG