• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "test/unittest/core/event/drag_event_test_ng.h"
17 #include "test/mock/base/mock_task_executor.h"
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS::Ace::NG {
SetUpTestSuite()22 void DragEventTestNg::SetUpTestSuite()
23 {
24     GTEST_LOG_(INFO) << "DragEventTestNg SetUpTestCase";
25     testing::FLAGS_gmock_verbose = "error";
26 }
27 
TearDownTestSuite()28 void DragEventTestNg::TearDownTestSuite()
29 {
30     GTEST_LOG_(INFO) << "DragEventTestNg TearDownTestCase";
31 }
32 
SetUp()33 void DragEventTestNg::SetUp()
34 {
35     MockPipelineContext::SetUp();
36 }
37 
TearDown()38 void DragEventTestNg::TearDown()
39 {
40     MockPipelineContext::TearDown();
41 }
42 
43 /**
44  * @tc.name: DragEventTest001
45  * @tc.desc: Create DragEvent and execute its callback functions.
46  * @tc.type: FUNC
47  */
48 HWTEST_F(DragEventTestNg, DragEventTest001, TestSize.Level1)
49 {
50     /**
51      * @tc.steps: step1. Create GestureEventFunc as the arguments of the construction of DragEvent.
52      */
53     double unknownPropertyValue = 0.0;
54     GestureEventFunc actionStart = [&unknownPropertyValue](
__anon6f3d34d10102( GestureEvent& info) 55                                        GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
56     GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anon6f3d34d10202( GestureEvent& info) 57                                         GestureEvent& info) { unknownPropertyValue = info.GetAngle(); };
58     GestureEventFunc actionEnd = [&unknownPropertyValue](
__anon6f3d34d10302( GestureEvent& info) 59                                      GestureEvent& info) { unknownPropertyValue = info.GetOffsetX(); };
__anon6f3d34d10402() 60     GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
61         unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
62     };
63 
64     /**
65      * @tc.steps: step2. Create DragEvent.
66      */
67     const DragEvent dragEvent =
68         DragEvent(std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
69 
70     /**
71      * @tc.steps: step3. Get and execute DragEvent ActionStartEvent.
72      * @tc.expected: Execute ActionStartEvent which unknownPropertyValue is assigned in.
73      */
74     GestureEvent info = GestureEvent();
75     info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
76     dragEvent.GetActionStartEventFunc()(info);
77     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
78 
79     /**
80      * @tc.steps: step4. Get and execute DragEvent ActionUpdateEvent.
81      * @tc.expected: Execute ActionUpdateEvent which unknownPropertyValue is assigned in.
82      */
83     unknownPropertyValue = 0.0;
84     info.SetAngle(GESTURE_EVENT_PROPERTY_VALUE);
85     dragEvent.GetActionUpdateEventFunc()(info);
86     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
87 
88     /**
89      * @tc.steps: step5. Get and execute DragEvent ActionEndEvent.
90      * @tc.expected: Execute ActionEndEvent which unknownPropertyValue is assigned in.
91      */
92     unknownPropertyValue = 0.0;
93     info.SetOffsetX(GESTURE_EVENT_PROPERTY_VALUE);
94     dragEvent.GetActionEndEventFunc()(info);
95     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
96 
97     /**
98      * @tc.steps: step6. Get and execute DragEvent ActionCancelEvent.
99      * @tc.expected: Execute ActionCancelEvent which unknownPropertyValue is assigned in.
100      */
101     unknownPropertyValue = 0.0;
102     dragEvent.GetActionCancelEventFunc()();
103     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
104 }
105 
106 /**
107  * @tc.name: DragEventActuatorPropertyTest002
108  * @tc.desc: Create DragEventActuator and test its property value.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(DragEventTestNg, DragEventActuatorPropertyTest002, TestSize.Level1)
112 {
113     /**
114      * @tc.steps: step1. Create DragEventActuator.
115      */
116     auto eventHub = AceType::MakeRefPtr<EventHub>();
117     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
118     DragEventActuator dragEventActuator = DragEventActuator(
119         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
120 
121     /**
122      * @tc.steps: step2. Create DragEventActuator when fingers number and distance are both greater than the default.
123      * @tc.expected: panEventActuator is initialized with the fingers_ and distance_ defined before.
124      */
125     auto dragEventActuator2 =
126         AceType::MakeRefPtr<DragEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION,
127             FINGERS_NUMBER_GREATER_THAN_DEFAULT, DISTANCE_GREATER_THAN_DEFAULT);
128     EXPECT_NE(dragEventActuator2, nullptr);
129     EXPECT_EQ(dragEventActuator2->fingers_, FINGERS_NUMBER_GREATER_THAN_DEFAULT);
130     EXPECT_EQ(dragEventActuator2->distance_, DISTANCE_GREATER_THAN_DEFAULT);
131 
132     /**
133      * @tc.steps: step3. Get DragEventActuator direction, fingers_ and distance_.
134      * @tc.expected:  DragEventActuator's direction, fingers_ and distance_ are equal with the parameters passed in the
135      * constructor.
136      */
137     EXPECT_EQ(dragEventActuator.GetDirection().type, DRAG_DIRECTION.type);
138     EXPECT_EQ(dragEventActuator.fingers_, FINGERS_NUMBER);
139     EXPECT_EQ(dragEventActuator.distance_, DISTANCE);
140     /**
141      * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent and CustomDragEvent.
142      * @tc.expected:  Get DragEventActuator's DragEvent and CustomDragEvent which are equal with the DragEvent create
143      * before.
144      */
__anon6f3d34d10502(GestureEvent& info) 145     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d10602(GestureEvent& info) 146     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d10702(GestureEvent& info) 147     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d10802() 148     GestureEventNoParameter actionCancel = []() {};
149 
150     auto dragEvent = AceType::MakeRefPtr<DragEvent>(
151         std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
152     dragEventActuator.ReplaceDragEvent(dragEvent);
153     EXPECT_EQ(dragEvent, dragEventActuator.userCallback_);
154     dragEventActuator.SetCustomDragEvent(dragEvent);
155     EXPECT_EQ(dragEvent, dragEventActuator.customCallback_);
156 }
157 
158 /**
159  * @tc.name: DragEventActuatorOnCollectTouchTargetTest003
160  * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
161  * @tc.type: FUNC
162  */
163 HWTEST_F(DragEventTestNg, DragEventActuatorOnCollectTouchTargetTest003, TestSize.Level1)
164 {
165     /**
166      * @tc.steps: step1. Create DragEventActuator.
167      */
168     auto eventHub = AceType::MakeRefPtr<EventHub>();
169     auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), false);
170     EXPECT_NE(frameNode, nullptr);
171     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
172     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
173     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
174         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
175 
176     /**
177      * @tc.steps: step2. Invoke OnCollectTouchTarget without setting userCallback_.
178      * @tc.expected:  userCallback_ is null and return directly.
179      */
180     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
181     EXPECT_NE(getEventTargetImpl, nullptr);
182     TouchTestResult finalResult;
183     ResponseLinkResult responseLinkResult;
184     frameNode->GetOrCreateFocusHub();
185     dragEventActuator->OnCollectTouchTarget(
186         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
187     EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
188     EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
189     EXPECT_EQ(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
190     EXPECT_EQ(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
191     EXPECT_EQ(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
192     EXPECT_TRUE(finalResult.empty());
193 
194     /**
195      * @tc.steps: step3. Create DragEvent and set as DragEventActuator's DragEvent.
196      * @tc.expected: DragEventActuator's userCallback_ is not null.
197      */
198     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
199     GestureEventFunc actionStart = [&unknownPropertyValue](
__anon6f3d34d10902( GestureEvent& info) 200                                        GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
201     GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anon6f3d34d10a02( GestureEvent& info) 202                                         GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
203     GestureEventFunc actionEnd = [&unknownPropertyValue](
__anon6f3d34d10b02( GestureEvent& info) 204                                      GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
__anon6f3d34d10c02() 205     GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
206         unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
207     };
208     auto dragEvent = AceType::MakeRefPtr<DragEvent>(
209         std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
210     dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anon6f3d34d10d02(GestureEvent& info) 211         [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE; });
212     dragEventActuator->ReplaceDragEvent(dragEvent);
213     dragEventActuator->SetCustomDragEvent(dragEvent);
214     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
215 
216     /**
217      * @tc.steps: step4. Invoke OnCollectTouchTarget when userCallback_ is not null.
218      * @tc.expected: panRecognizer_ action and finalResult will be assigned value.
219      */
220     dragEventActuator->OnCollectTouchTarget(
221         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
222 
223     EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
224     EXPECT_NE(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
225     EXPECT_NE(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
226     EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
227     EXPECT_FALSE(finalResult.size() == TOUCH_TEST_RESULT_SIZE);
228 
229     /**
230      * @tc.steps: step5. Invoke OnCollectTouchTarget when SequencedRecognizer_ is null.
231      * @tc.expected: Result size will be increased by one.
232      */
233     dragEventActuator->SequencedRecognizer_ = nullptr;
234     dragEventActuator->OnCollectTouchTarget(
235         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
236     EXPECT_TRUE(finalResult.size() != TOUCH_TEST_RESULT_SIZE_2);
237 
238     /**
239      * @tc.steps: Create prepareDragFrameNode for drag start.
240      * @tc.expected: Create prepareDragFrameNode success.
241      */
242     auto pipeline = PipelineContext::GetCurrentContext();
243     ASSERT_NE(pipeline, nullptr);
244     auto dragDropManager = pipeline->GetDragDropManager();
245     ASSERT_NE(dragDropManager, nullptr);
246     DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
247     /**
248      * @tc.steps: step6. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
249      * function exists.
250      * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
251      * value.
252      */
253     GestureEvent info = GestureEvent();
254     info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
255     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
256     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
257     (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
258     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
259     (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
260     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
261     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
262     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
263 
264     /**
265      * @tc.steps: step7. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
266      * function not exist.
267      * @tc.expected: The functions have not been executed.
268      */
269     SystemProperties::debugEnabled_ = true;
270     auto dragEventNullptr = AceType::MakeRefPtr<DragEvent>(nullptr, nullptr, nullptr, nullptr);
271     dragEventActuator->ReplaceDragEvent(dragEventNullptr);
272     dragEventActuator->SetCustomDragEvent(dragEventNullptr);
273     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
274     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
275     (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
276     (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
277     dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anon6f3d34d10e02(GestureEvent& info) 278         [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE; });
279     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
280     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_DEFAULT_VALUE);
281 }
282 
283 /**
284  * @tc.name: DragEventTestNg001
285  * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
286  * @tc.type: FUNC
287  */
288 HWTEST_F(DragEventTestNg, DragEventTestNg001, TestSize.Level1)
289 {
290     /**
291      * @tc.steps: step1. Create DragEventActuator.
292      */
293     auto eventHub = AceType::MakeRefPtr<EventHub>();
294     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
295     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
296         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, 0, 50.0f);
297     dragEventActuator->StartDragTaskForWeb(GestureEvent());
__anon6f3d34d10f02(GestureEvent&) 298     auto actionStart = [](GestureEvent&) {};
__anon6f3d34d11002(GestureEvent&) 299     auto longPressUpdate = [](GestureEvent&) {};
300     dragEventActuator->actionStart_ = actionStart;
301     dragEventActuator->StartDragTaskForWeb(GestureEvent());
302 
303     dragEventActuator->CancelDragForWeb();
__anon6f3d34d11102(GestureEvent&) 304     auto actionCancel = [](GestureEvent&) {};
305     dragEventActuator->actionCancel_ = actionCancel;
306     dragEventActuator->CancelDragForWeb();
307 
308     dragEventActuator->StartLongPressActionForWeb();
309     dragEventActuator->isReceivedLongPress_ = true;
310     dragEventActuator->StartLongPressActionForWeb();
311     dragEventActuator->isReceivedLongPress_ = true;
312     dragEventActuator->longPressUpdate_ = longPressUpdate;
313     dragEventActuator->StartLongPressActionForWeb();
314     ASSERT_FALSE(dragEventActuator->isReceivedLongPress_);
315 }
316 
317 /**
318  * @tc.name: DragEventTestNg002
319  * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
320  * @tc.type: FUNC
321  */
322 HWTEST_F(DragEventTestNg, DragEventTestNg002, TestSize.Level1)
323 {
324     /**
325      * @tc.steps: step1. Create FrameNode and set dragPreview.
326      */
327     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
328     frameNode->SetDraggable(true);
329     NG::DragDropInfo dragPreviewInfo;
330     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(static_cast<void*>(new char[0]));
331     dragPreviewInfo.pixelMap = pixelMap;
332     frameNode->SetDragPreview(dragPreviewInfo);
333 
334     /**
335      * @tc.steps: step2. Get eventHub and set onDragStart.
336      * @tc.expected: eventHub is not nullptr.
337      */
338     auto eventHub = frameNode->GetEventHub<EventHub>();
339     EXPECT_NE(eventHub, nullptr);
340     eventHub->AttachHost(frameNode);
__anon6f3d34d11202(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 341     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
342         DragDropInfo info;
343         void* voidPtr = static_cast<void*>(new char[0]);
344         info.pixelMap = PixelMap::CreatePixelMap(voidPtr);
345         return info;
346     };
347     eventHub->SetOnDragStart(std::move(onDragStart));
348 
349     /**
350      * @tc.steps: step3. Create gestureEventHub and dragEventActuator.
351      */
352     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
353     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
354         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
355 
356     /**
357      * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent.
358      * @tc.expected: dragEventActuator's userCallback_ is not null.
359      */
360     TouchTestResult finalResult;
361     ResponseLinkResult responseLinkResult;
362     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon6f3d34d11302(GestureEvent& info) 363     GestureEventFunc actionStart = [&unknownPropertyValue](GestureEvent& info) {
364         unknownPropertyValue = info.GetScale();
365     };
__anon6f3d34d11402(GestureEvent& info) 366     GestureEventFunc actionUpdate = [&unknownPropertyValue](GestureEvent& info) {
367         unknownPropertyValue = info.GetScale();
368     };
__anon6f3d34d11502(GestureEvent& info) 369     GestureEventFunc actionEnd = [&unknownPropertyValue](GestureEvent& info) {
370         unknownPropertyValue = info.GetScale();
371     };
__anon6f3d34d11602() 372     GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
373         unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
374     };
375     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
376         std::move(actionEnd), std::move(actionCancel));
377     dragEventActuator->ReplaceDragEvent(dragEvent);
378     dragEventActuator->SetCustomDragEvent(dragEvent);
379     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
380 
381     /**
382      * @tc.steps: step5. Invoke OnCollectTouchTarget when userCallback_ is not null.
383      * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's callback is not nullptr.
384      */
385     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
386     frameNode->GetOrCreateFocusHub();
387     EXPECT_NE(getEventTargetImpl, nullptr);
388     dragEventActuator->OnCollectTouchTarget(
389         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
390     EXPECT_NE(dragEventActuator->longPressRecognizer_, nullptr);
391     EXPECT_NE(dragEventActuator->longPressRecognizer_->callback_, nullptr);
392 
393     /**
394      * @tc.steps: step6. Invoke thumbnail callback.
395      * @tc.expected: GestureEventHub's pixelMap is not nullptr.
396      */
397     dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
398     EXPECT_NE(gestureEventHub->pixelMap_, nullptr);
399 }
400 
401 /**
402  * @tc.name: DragEventTestNg003
403  * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
404  * @tc.type: FUNC
405  */
406 HWTEST_F(DragEventTestNg, DragEventTestNg003, TestSize.Level1)
407 {
408     /**
409      * @tc.steps: step1. Create DragEventActuator.
410      */
411     SystemProperties::debugEnabled_ = true;
412     auto eventHub = AceType::MakeRefPtr<EventHub>();
413     auto frameNode = FrameNode::CreateFrameNode(
414         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
415     DragDropInfo dragDropInfo;
416     frameNode->SetDragPreview(dragDropInfo);
417     frameNode->SetDraggable(true);
418     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
419     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
420     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
421         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE_EQUAL_DEFAULT);
422     /**
423      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
424      * @tc.expected: dragEventActuator's userCallback_ is not null.
425      */
__anon6f3d34d11702(GestureEvent& info) 426     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d11802(GestureEvent& info) 427     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d11902(GestureEvent& info) 428     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d11a02() 429     GestureEventNoParameter actionCancel = []() {};
430     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
431         std::move(actionEnd), std::move(actionCancel));
432     dragEventActuator->ReplaceDragEvent(dragEvent);
433     dragEventActuator->SetCustomDragEvent(dragEvent);
434     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
435     /**
436      * @tc.steps: step3. Invoke OnCollectTouchTarget when callback_ is not null.
437      * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's HasThumbnailCallback() return true.
438      */
439     TouchTestResult finalResult;
440     ResponseLinkResult responseLinkResult;
441     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
442     EXPECT_NE(getEventTargetImpl, nullptr);
443     EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), false);
444     frameNode->GetOrCreateFocusHub();
445     dragEventActuator->OnCollectTouchTarget(
446         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
447     EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
448     dragEventActuator->OnCollectTouchTarget(
449         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
450     EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
451     /**
452      * @tc.steps: step4. Invoke thumbnail callback.
453      * @tc.expected: cover dragPreviewInfo.customNode == nullptr, dragPreviewInfo.pixelMap == nullptr.
454      */
455     EXPECT_EQ(frameNode->GetDragPreview().customNode, nullptr);
456     dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
457     EXPECT_EQ(gestureEventHub->GetPixelMap(), frameNode->GetRenderContext()->GetThumbnailPixelMap());
458     /**
459      * @tc.steps: step5. Invoke thumbnail callback.
460      * @tc.expected: cover dragPreviewInfo.customNode != nullptr, dragPreviewInfo.pixelMap == nullptr.
461      */
462     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
463     dragDropInfo.customNode = customNode;
464     frameNode->SetDragPreview(dragDropInfo);
465     dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
466     EXPECT_NE(frameNode->GetDragPreview().customNode, nullptr);
467 }
468 
469 /**
470  * @tc.name: DragEventTestNg004
471  * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget.
472  * @tc.type: FUNC
473  */
474 HWTEST_F(DragEventTestNg, DragEventTestNg004, TestSize.Level1)
475 {
476     /**
477      * @tc.steps: step1. Create DragEventActuator.
478      */
479     SystemProperties::debugEnabled_ = true;
480     auto eventHub = AceType::MakeRefPtr<EventHub>();
481     auto frameNode = FrameNode::CreateFrameNode(
482         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
483     DragDropInfo dragDropInfo;
484     frameNode->SetDragPreview(dragDropInfo);
485     frameNode->SetDraggable(true);
486     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
487     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
488     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
489         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
490     /**
491      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
492      * @tc.expected: dragEventActuator's userCallback_ is not null.
493      */
__anon6f3d34d11b02(GestureEvent& info) 494     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d11c02(GestureEvent& info) 495     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d11d02(GestureEvent& info) 496     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d11e02() 497     GestureEventNoParameter actionCancel = []() {};
498     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
499         std::move(actionEnd), std::move(actionCancel));
500     dragEventActuator->ReplaceDragEvent(dragEvent);
501     dragEventActuator->SetCustomDragEvent(dragEvent);
502     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
503     /**
504      * @tc.steps: step3. Call the function OnCollectTouchTarget when sourceType is SourceType::MOUSE.
505      * @tc.expected: cover touchRestrict.sourceType == SourceType::MOUSE.
506      */
507     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
508     EXPECT_NE(getEventTargetImpl, nullptr);
509     TouchTestResult finalResult;
510     ResponseLinkResult responseLinkResult;
511     frameNode->GetOrCreateFocusHub();
512     dragEventActuator->OnCollectTouchTarget(
513         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT_MOUSE, getEventTargetImpl, finalResult, responseLinkResult);
514     EXPECT_FALSE(finalResult.empty());
515 }
516 
517 /**
518  * @tc.name: DragEventTestNg005
519  * @tc.desc: Create DragEventActuator and invoke longPressUpdate callback.
520  * @tc.type: FUNC
521  */
522 HWTEST_F(DragEventTestNg, DragEventTestNg005, TestSize.Level1)
523 {
524     /**
525      * @tc.steps: step1. Create DragEventActuator.
526      */
527     auto eventHub = AceType::MakeRefPtr<EventHub>();
528     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
529     DragDropInfo dragDropInfo;
530     frameNode->SetDragPreview(dragDropInfo);
531     frameNode->SetDraggable(true);
532     frameNode->GetOrCreateFocusHub();
533     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
534     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
535     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
536         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
537     /**
538      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
539      * @tc.expected: dragEventActuator's userCallback_ is not null.
540      */
__anon6f3d34d11f02(GestureEvent& info) 541     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d12002(GestureEvent& info) 542     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d12102(GestureEvent& info) 543     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d12202() 544     GestureEventNoParameter actionCancel = []() {};
545     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
546         std::move(actionEnd), std::move(actionCancel));
547     dragEventActuator->ReplaceDragEvent(dragEvent);
548     dragEventActuator->SetCustomDragEvent(dragEvent);
549     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
550     /**
551      * @tc.steps: step3. Create callback and set as dragEventActuator's longPressUpdate_.
552      * @tc.expected: previewLongPressRecognizer_'s onAction_ is not null.
553      */
554     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
555     TouchTestResult finalResult;
556     ResponseLinkResult responseLinkResult;
557     frameNode->GetOrCreateFocusHub();
558     dragEventActuator->OnCollectTouchTarget(
559         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
560     EXPECT_NE(dragEventActuator->previewLongPressRecognizer_->onAction_, nullptr);
561     /**
562      * @tc.steps: step4. Invoke longPressUpdateValue callback.
563      * @tc.expected: cover longPressUpdateValue callback.
564      */
565     SystemProperties::debugEnabled_ = true;
566     GestureEvent info = GestureEvent();
567     (*(dragEventActuator->longPressRecognizer_->onAction_))(info);
568     EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
569     SystemProperties::debugEnabled_ = false;
570     (*(dragEventActuator->longPressRecognizer_->onAction_))(info);
571     EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
572     /**
573      * @tc.steps: step5. Invoke longPressUpdate callback.
574      * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == true.
575      */
576     SystemProperties::debugEnabled_ = true;
577     EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
578     EXPECT_EQ(dragEventActuator->IsAllowedDrag(), true);
579     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
580     EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
581     /**
582      * @tc.steps: step6. Invoke longPressUpdate callback.
583      * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == false.
584      */
585     SystemProperties::debugEnabled_ = false;
586     frameNode->SetDraggable(false);
587     EXPECT_EQ(dragEventActuator->IsAllowedDrag(), false);
588     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
589     EXPECT_EQ(dragEventActuator->isReceivedLongPress_, true);
590     /**
591      * @tc.steps: step7. Invoke longPressUpdate callback.
592      * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == false.
593      */
594     gestureEventHub->SetTextDraggable(true);
595     gestureEventHub->SetIsTextDraggable(false);
596     dragEventActuator->SetIsNotInPreviewState(true);
597     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
598     EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
599     /**
600      * @tc.steps: step8. Invoke longPressUpdate callback.
601      * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == true.
602      */
603     gestureEventHub->SetIsTextDraggable(true);
604     dragEventActuator->SetIsNotInPreviewState(true);
605     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
606     EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
607 }
608 
609 /**
610  * @tc.name: DragEventTestNg006
611  * @tc.desc: Create DragEventActuator and invoke onActionStart callback.
612  * @tc.type: FUNC
613  */
614 HWTEST_F(DragEventTestNg, DragEventTestNg006, TestSize.Level1)
615 {
616     /**
617      * @tc.steps: step1. Create DragEventActuator.
618      */
619     SystemProperties::debugEnabled_ = true;
620     auto eventHub = AceType::MakeRefPtr<EventHub>();
621     auto frameNode = FrameNode::CreateFrameNode(
622         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
623     frameNode->SetDraggable(true);
624     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
625     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
626     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
627         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
628     /**
629      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
630      * @tc.expected: dragEventActuator's userCallback_ is not null.
631      */
632     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon6f3d34d12302(GestureEvent& info) 633     auto actionStart = [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
__anon6f3d34d12402(GestureEvent& info) 634     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d12502(GestureEvent& info) 635     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d12602() 636     GestureEventNoParameter actionCancel = []() {};
637     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
638         std::move(actionEnd), std::move(actionCancel));
639     dragEventActuator->ReplaceDragEvent(dragEvent);
640     dragEventActuator->SetCustomDragEvent(dragEvent);
641     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
642     /**
643      * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
644      * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionStart is not nullptr.
645      */
646     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
647     EXPECT_NE(getEventTargetImpl, nullptr);
648     TouchTestResult finalResult;
649     ResponseLinkResult responseLinkResult;
650     frameNode->GetOrCreateFocusHub();
651     dragEventActuator->OnCollectTouchTarget(
652         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
653     EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
654 
655     /**
656      * @tc.steps: Create prepareDragFrameNode for drag start.
657      * @tc.expected: Create prepareDragFrameNode success.
658      */
659     auto pipeline = PipelineContext::GetCurrentContext();
660     auto dragDropManager = pipeline->GetDragDropManager();
661     ASSERT_NE(dragDropManager, nullptr);
662     DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
663 
664     /**
665      * @tc.steps: step4. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
666      * @tc.expected: cover pattern->IsSelected() == false or GetMouseStatus() == MouseStatus::MOVE
667      */
668     GestureEvent info = GestureEvent();
669     info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
670     info.SetSourceDevice(SourceType::MOUSE);
671     gestureEventHub->SetTextDraggable(true);
672     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
673     EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
674 
675     auto pattern = frameNode->GetPattern<TextPattern>();
676     pattern->mouseStatus_ = MouseStatus::MOVE;
677     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
678     EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
679     EXPECT_EQ(pattern->GetMouseStatus(), MouseStatus::MOVE);
680     /**
681      * @tc.steps: step5. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
682      * @tc.expected: cover GetTextDraggable() is false, Trigger drag start event set by user.
683      */
684     gestureEventHub->SetTextDraggable(false);
685     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
686     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
687     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
688     /**
689      * @tc.steps: step6. Invoke onActionStart callback, when info.GetSourceDevice() is not SourceType::MOUSE.
690      * @tc.expected: cover gestureHub->GetTextDraggable() is true
691      */
692     info.SetSourceDevice(SourceType::TOUCH);
693     gestureEventHub->SetTextDraggable(true);
694     EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
695     (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
696     EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
697 }
698 
699 /**
700  * @tc.name: DragEventTestNg007
701  * @tc.desc: Create DragEventActuator and invoke onActionCancel callback.
702  * @tc.type: FUNC
703  */
704 HWTEST_F(DragEventTestNg, DragEventTestNg007, TestSize.Level1)
705 {
706     /**
707      * @tc.steps: step1. Create DragEventActuator.
708      */
709     auto eventHub = AceType::MakeRefPtr<EventHub>();
710     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
711     frameNode->SetDraggable(true);
712     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
713     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
714     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
715         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
716     /**
717      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
718      * @tc.expected: dragEventActuator's userCallback_ is not null.
719      */
720     double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon6f3d34d12702(GestureEvent& info) 721     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d12802(GestureEvent& info) 722     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d12902(GestureEvent& info) 723     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d12a02() 724     GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
725         unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
726     };
727     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
728         std::move(actionEnd), std::move(actionCancel));
729     dragEventActuator->ReplaceDragEvent(dragEvent);
730     dragEventActuator->SetCustomDragEvent(dragEvent);
731     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
732     /**
733      * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
734      * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionCancel is not nullptr.
735      */
736     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
737     TouchTestResult finalResult;
738     ResponseLinkResult responseLinkResult;
739     frameNode->GetOrCreateFocusHub();
740     dragEventActuator->OnCollectTouchTarget(
741         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
742     dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anon6f3d34d12b02(GestureEvent& info) 743         [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE; });
744     EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
745     /**
746      * @tc.steps: step4. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
747      * @tc.expected: cover gestureHub->GetIsTextDraggable() is false.
748      */
749     SystemProperties::debugEnabled_ = true;
750     GestureEvent info = GestureEvent();
751     info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
752     gestureEventHub->SetTextDraggable(true);
753     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
754     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
755     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
756     /**
757      * @tc.steps: step5. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
758      * @tc.expected: cover gestureHub->GetIsTextDraggable() is true.
759      */
760     SystemProperties::debugEnabled_ = false;
761     gestureEventHub->SetIsTextDraggable(true);
762     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
763     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
764     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
765     /**
766      * @tc.steps: step6. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
767      * @tc.expected: cover getDeviceType() != SourceType::MOUSE.
768      */
769     eventHub->AttachHost(nullptr);
770     EXPECT_EQ(dragEventActuator->GetIsBindOverlayValue(dragEventActuator), true);
771     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
772     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
773     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
774     /**
775      * @tc.steps: step7. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
776      * @tc.expected: cover getDeviceType() == SourceType::MOUSE.
777      */
778     auto context = PipelineContext::GetCurrentContext();
779     ASSERT_NE(context, nullptr);
780     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
781     auto taskExecutor = context->GetTaskExecutor();
782     ASSERT_NE(taskExecutor, nullptr);
783     dragEventActuator->panRecognizer_->deviceType_ = SourceType::MOUSE;
784     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
785     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
786     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
787 
788     gestureEventHub->SetTextDraggable(false);
789     unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
790     (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
791     EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
792 }
793 
794 /**
795  * @tc.name: DragEventTestNg008
796  * @tc.desc: Create DragEventActuator and invoke HideTextAnimation function.
797  * @tc.type: FUNC
798  */
799 HWTEST_F(DragEventTestNg, DragEventTestNg008, TestSize.Level1)
800 {
801     /**
802      * @tc.steps: step1. Create DragEventActuator.
803      */
804     auto eventHub = AceType::MakeRefPtr<EventHub>();
805     auto frameNode = FrameNode::CreateFrameNode(
806         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
807     NG::DragDropInfo dragPreviewInfo;
808     void* voidPtr = static_cast<void*>(new char[0]);
809     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
810     dragPreviewInfo.pixelMap = pixelMap;
811     frameNode->SetDragPreview(dragPreviewInfo);
812     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
813     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
814     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
815         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
816     /**
817      * @tc.steps: step2. Invoke HideTextAnimation function, when isAllowedDrag is false.
818      * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
819      */
820     SystemProperties::debugEnabled_ = true;
821     frameNode->SetDraggable(false);
822     gestureEventHub->SetTextDraggable(false);
823     dragEventActuator->HideTextAnimation();
824     EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
825     gestureEventHub->SetTextDraggable(true);
826     dragEventActuator->HideTextAnimation();
827     EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
828     /**
829      * @tc.steps: step3. Invoke HideTextAnimation function, when isAllowedDrag is true.
830      * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
831      */
832     SystemProperties::debugEnabled_ = false;
833     frameNode->SetDraggable(true);
834     gestureEventHub->SetTextDraggable(false);
835     dragEventActuator->HideTextAnimation();
836     EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
837     gestureEventHub->SetTextDraggable(true);
838     dragEventActuator->HideTextAnimation();
839     EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
840 }
841 
842 /**
843  * @tc.name: DragEventTestNg009
844  * @tc.desc: Invoke GetPreviewPixelMap.
845  * @tc.type: FUNC
846  */
847 HWTEST_F(DragEventTestNg, DragEventTestNg009, TestSize.Level1)
848 {
849     EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(NO_COMPONENT_ID, nullptr), nullptr);
850     EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(COMPONENT_ID, nullptr), nullptr);
851 
852     auto frameNode = FrameNode::CreateFrameNode(
853         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
854 
855     EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(NO_COMPONENT_ID, frameNode), nullptr);
856     EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(COMPONENT_ID, frameNode), nullptr);
857 }
858 
859 /**
860  * @tc.name: DragEventExecutePreDragActionTest001
861  * @tc.desc: Create DragEventActuator and test ExecutePreDragAction function.
862  * @tc.type: FUNC
863  */
864 HWTEST_F(DragEventTestNg, DragEventExecutePreDragActionTest001, TestSize.Level1)
865 {
866     /**
867      * @tc.steps: step1. Create DragEventActuator.
868      */
869     auto eventHub = AceType::MakeRefPtr<EventHub>();
870     auto frameNode = FrameNode::CreateFrameNode(
871         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
872     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
873     frameNode->eventHub_ = eventHub;
874     frameNode->SetDraggable(true);
875     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
876     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
877         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
878     /**
879      * @tc.steps: step2. Create onPreDrag function and bind to eventHub.
880      * @tc.expected: Bind onPreDrag function successful.
881      */
882     MockFunction<void(const PreDragStatus&)> mockOnPreFunction;
883     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_DETECTING_STATUS)).WillOnce(Return());
884     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION)).WillOnce(Return());
885     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::PREVIEW_LIFT_STARTED)).WillOnce(Return());
886     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::PREVIEW_LANDING_STARTED)).WillOnce(Return());
887     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG)).WillOnce(Return());
888     std::function<void(const PreDragStatus&)> mockOnPreDragFunc = mockOnPreFunction.AsStdFunction();
889 
__anon6f3d34d12c02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 890     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
891         DragDropInfo info;
892         return info;
893     };
894     eventHub->SetOnDragStart(std::move(onDragStart));
895     eventHub->SetOnPreDrag(mockOnPreDragFunc);
896     EXPECT_NE(eventHub->GetOnPreDrag(), nullptr);
897 
898     /**
899      * @tc.steps: step3. Call ExecutePreDragAction Function.
900      * @tc.expected: Call function successful.
901      */
902     auto pipeline = PipelineContext::GetMainPipelineContext();
903     auto dragDropManager = pipeline->GetDragDropManager();
904     ASSERT_NE(dragDropManager, nullptr);
905     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_DETECTING_STATUS);
906     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS, frameNode);
907     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION);
908     DragEventActuator::ExecutePreDragAction(PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION, frameNode);
909     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LIFT_STARTED);
910     DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LIFT_STARTED, frameNode);
911     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LIFT_FINISHED);
912     DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LIFT_FINISHED, frameNode);
913     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LANDING_STARTED);
914     DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LANDING_STARTED, frameNode);
915     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LANDING_FINISHED);
916     DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LANDING_FINISHED, frameNode);
917     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_CANCELED_BEFORE_DRAG);
918     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG, frameNode);
919     EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_CANCELED_BEFORE_DRAG);
920 }
921 
922 /**
923  * @tc.name: DragEventExecutePreDragActionTest002
924  * @tc.desc: Create DragEventActuator and test ExecutePreDragAction function.
925  * @tc.type: FUNC
926  */
927 HWTEST_F(DragEventTestNg, DragEventExecutePreDragActionTest002, TestSize.Level1)
928 {
929     /**
930      * @tc.steps: step1. Create DragEventActuator.
931      */
932     auto eventHub = AceType::MakeRefPtr<EventHub>();
933     auto frameNode = FrameNode::CreateFrameNode(
934         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
935     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
936     frameNode->eventHub_ = eventHub;
937     frameNode->SetDraggable(true);
938     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
939     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
940         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
941     auto pipeline = PipelineContext::GetMainPipelineContext();
942     auto dragDropManager = pipeline->GetDragDropManager();
943     ASSERT_NE(dragDropManager, nullptr);
944     DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
945     DragDropGlobalController::GetInstance().SetPreDragStatus(PreDragStatus::ACTION_DETECTING_STATUS);
946     /**
947      * @tc.steps: step2. Create onPreDrag function and bind to eventHub.
948      * @tc.expected: Bind onPreDrag function successful.
949      */
950     MockFunction<void(const PreDragStatus&)> mockOnPreFunction;
951     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_DETECTING_STATUS)).WillOnce(Return());
952     EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG)).WillOnce(Return());
953     std::function<void(const PreDragStatus&)> mockOnPreDragFunc = mockOnPreFunction.AsStdFunction();
954 
__anon6f3d34d12d02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 955     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
956         DragDropInfo info;
957         return info;
958     };
959     eventHub->SetOnDragStart(std::move(onDragStart));
960     eventHub->SetOnPreDrag(mockOnPreDragFunc);
961     EXPECT_NE(eventHub->GetOnPreDrag(), nullptr);
962 
963     /**
964      * @tc.steps: step3. Call ExecutePreDragAction Function with same status.
965      * @tc.expected: first call function successful, second call canceled.
966      */
967     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
968     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
969 
970     /**
971      * @tc.steps: step4. Call ExecutePreDragAction Function with fail parameters.
972      * @tc.expected: not call any function.
973      */
974     gestureEventHub->SetTextDraggable(true);
975     frameNode->SetDraggable(false);
976     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
977     dragDropManager->ResetDragging(DragDropMgrState::DRAGGING);
978     DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
979 }
980 
981 /**
982  * @tc.name: DragEventShowBadgeTest01
983  * @tc.desc: Test the GetCustomerBadgeNumber function of setting different NumberBadge.
984  * @tc.type: FUNC
985  */
986 HWTEST_F(DragEventTestNg, DragEventShowBadgeTest01, TestSize.Level1)
987 {
988     /**
989      * @tc.steps: step1. Create frameNode.
990      */
991     auto frameNode = FrameNode::CreateFrameNode(
992         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
993     EXPECT_NE(frameNode, nullptr);
994 
995     /**
996      * @tc.steps: step2. Do not set NumberBadge.
997      * @tc.expected: badgeNumber has no value.
998      */
999     auto dragPreviewOptions = frameNode->GetDragPreviewOption();
1000     auto badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1001     EXPECT_EQ(badgeNumber.has_value(), false);
1002 
1003     /**
1004      * @tc.steps: step3. Set NumberBadge value is true.
1005      * @tc.expected: badgeNumber has no value.
1006      */
1007     NG::DragPreviewOption previewOptions;
1008     previewOptions.isNumber = false;
1009     previewOptions.badgeNumber = true;
1010     frameNode->SetDragPreviewOptions(previewOptions);
1011     dragPreviewOptions = frameNode->GetDragPreviewOption();
1012     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1013     EXPECT_EQ(badgeNumber.has_value(), false);
1014 
1015     /**
1016      * @tc.steps: step4. Set NumberBadge value is false.
1017      * @tc.expected: badgeNumber has value.
1018      */
1019     previewOptions.isNumber = false;
1020     previewOptions.badgeNumber = false;
1021     frameNode->SetDragPreviewOptions(previewOptions);
1022     dragPreviewOptions = frameNode->GetDragPreviewOption();
1023     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1024     EXPECT_EQ(badgeNumber.has_value(), true);
1025     EXPECT_EQ(badgeNumber.value(), 1);
1026 
1027     /**
1028      * @tc.steps: step5. Set the NumberBadge to a special value 3.
1029      * @tc.expected: badgeNumber is the set value.
1030      */
1031     previewOptions.isNumber = true;
1032     previewOptions.badgeNumber = NUMBER_BADGE_SIZE_3;
1033     frameNode->SetDragPreviewOptions(previewOptions);
1034     dragPreviewOptions = frameNode->GetDragPreviewOption();
1035     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1036     EXPECT_EQ(badgeNumber.has_value(), true);
1037     EXPECT_EQ(badgeNumber.value(), NUMBER_BADGE_SIZE_3);
1038 
1039     /**
1040      * @tc.steps: step6. Set the NumberBadge to a special value 0.
1041      * @tc.expected: badgeNumber is 1.
1042      */
1043     previewOptions.isNumber = true;
1044     previewOptions.badgeNumber = 0;
1045     frameNode->SetDragPreviewOptions(previewOptions);
1046     dragPreviewOptions = frameNode->GetDragPreviewOption();
1047     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1048     EXPECT_EQ(badgeNumber.has_value(), true);
1049     EXPECT_EQ(badgeNumber.value(), 1);
1050 
1051     /**
1052      * @tc.steps: step7. Set the NumberBadge to a special value -1.
1053      * @tc.expected: badgeNumber is 1.
1054      */
1055     previewOptions.isNumber = true;
1056     previewOptions.badgeNumber = -1;
1057     frameNode->SetDragPreviewOptions(previewOptions);
1058     dragPreviewOptions = frameNode->GetDragPreviewOption();
1059     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1060     EXPECT_EQ(badgeNumber.has_value(), true);
1061     EXPECT_EQ(badgeNumber.value(), 1);
1062 
1063     /**
1064      * @tc.steps: step8. Set the NumberBadge to a special value 100.
1065      * @tc.expected: badgeNumber is the set value.
1066      */
1067     previewOptions.isNumber = true;
1068     previewOptions.badgeNumber = NUMBER_BADGE_SIZE_100;
1069     frameNode->SetDragPreviewOptions(previewOptions);
1070     dragPreviewOptions = frameNode->GetDragPreviewOption();
1071     badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1072     EXPECT_EQ(badgeNumber.has_value(), true);
1073     EXPECT_EQ(badgeNumber.value(), NUMBER_BADGE_SIZE_100);
1074 }
1075 
1076 /**
1077  * @tc.name: TestCreateGatherNode001
1078  * @tc.desc: Create List GatherNode
1079  * @tc.type: FUNC
1080  */
1081 HWTEST_F(DragEventTestNg, TestCreateGatherNode001, TestSize.Level1)
1082 {
1083     /**
1084      * @tc.steps: step1. Create List Node.
1085      */
1086     auto listNode = FrameNode::CreateFrameNode(
1087         V2::LIST_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ListPattern>());
1088     ASSERT_NE(listNode, nullptr);
1089     /**
1090      * @tc.steps: step2. Create List Item Node.
1091      */
1092     auto listItemNode1 = FrameNode::CreateFrameNode(V2::LIST_ITEM_ETS_TAG,
1093         ElementRegister::GetInstance()->MakeUniqueId(),
1094         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1095     ASSERT_NE(listItemNode1, nullptr);
1096     auto listItemNode2 = FrameNode::CreateFrameNode(V2::LIST_ITEM_ETS_TAG,
1097         ElementRegister::GetInstance()->MakeUniqueId(),
1098         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1099     ASSERT_NE(listItemNode2, nullptr);
1100     auto itemPattern1 = listItemNode1->GetPattern<ListItemPattern>();
1101     ASSERT_NE(itemPattern1, nullptr);
1102     itemPattern1->SetSelected(true);
1103     auto itemPattern2 = listItemNode2->GetPattern<ListItemPattern>();
1104     ASSERT_NE(itemPattern2, nullptr);
1105     itemPattern2->SetSelected(true);
1106     NG::DragPreviewOption option { true, false, true };
1107     listItemNode1->SetDragPreviewOptions(option);
1108     listNode->AddChild(listItemNode1);
1109     listNode->AddChild(listItemNode2);
1110     /**
1111      * @tc.steps: step3. Create DragEventActuator.
1112      */
1113     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d12e02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1114     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1115         DragDropInfo info;
1116         return info;
1117     };
1118     eventHub->SetOnDragStart(std::move(onDragStart));
1119     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode1));
1120     listItemNode1->eventHub_ = eventHub;
1121     listItemNode1->SetDraggable(true);
1122     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1123     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1124         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1125     /**
1126      * @tc.steps: step4. Create GatherNode.
1127      */
1128     dragEventActuator->FindItemParentNode(listItemNode1);
1129     auto gatherNode = DragEventActuator::CreateGatherNode(dragEventActuator);
1130     EXPECT_EQ(gatherNode, nullptr);
1131 }
1132 
1133 /**
1134  * @tc.name: TestCreateGatherNode002
1135  * @tc.desc: Create Grid GatherNode
1136  * @tc.type: FUNC
1137  */
1138 HWTEST_F(DragEventTestNg, TestCreateGatherNode002, TestSize.Level1)
1139 {
1140     /**
1141      * @tc.steps: step1. Create Grid Node.
1142      */
1143     auto gridNode = FrameNode::CreateFrameNode(
1144         V2::GRID_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<GridPattern>());
1145     ASSERT_NE(gridNode, nullptr);
1146     /**
1147      * @tc.steps: step2. Create Grid Item Node.
1148      */
1149     auto gridItemNode1 = FrameNode::CreateFrameNode(
1150         V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1151         AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1152     ASSERT_NE(gridItemNode1, nullptr);
1153     auto gridItemNode2 = FrameNode::CreateFrameNode(
1154         V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1155         AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1156     ASSERT_NE(gridItemNode2, nullptr);
1157     auto itemPattern1 = gridItemNode1->GetPattern<GridItemPattern>();
1158     ASSERT_NE(itemPattern1, nullptr);
1159     itemPattern1->SetSelected(true);
1160     auto itemPattern2 = gridItemNode2->GetPattern<GridItemPattern>();
1161     ASSERT_NE(itemPattern2, nullptr);
1162     itemPattern2->SetSelected(true);
1163     NG::DragPreviewOption option { true, false, true };
1164     gridItemNode1->SetDragPreviewOptions(option);
1165     gridNode->AddChild(gridItemNode1);
1166     gridNode->AddChild(gridItemNode2);
1167     /**
1168      * @tc.steps: step3. Create DragEventActuator.
1169      */
1170     auto eventHub = AceType::MakeRefPtr<EventHub>();
1171     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode1));
__anon6f3d34d12f02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1172     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1173         DragDropInfo info;
1174         return info;
1175     };
1176     eventHub->SetOnDragStart(std::move(onDragStart));
1177     gridItemNode1->eventHub_ = eventHub;
1178     gridItemNode1->SetDraggable(true);
1179     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1180     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1181         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1182     /**
1183      * @tc.steps: step4. Create GatherNode.
1184      */
1185     dragEventActuator->FindItemParentNode(gridItemNode1);
1186     auto gatherNode = DragEventActuator::CreateGatherNode(dragEventActuator);
1187     EXPECT_EQ(gatherNode, nullptr);
1188 }
1189 
1190 /**
1191  * @tc.name: TestCreateImageNode001
1192  * @tc.desc: Create ImageNode of FrameNode
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(DragEventTestNg, TestCreateImageNode001, TestSize.Level1)
1196 {
1197     /**
1198      * @tc.steps: step1. Create FrameNode.
1199      */
1200     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1201     ASSERT_NE(frameNode, nullptr);
1202     /**
1203      * @tc.steps: step2. Create GatherNodeChildInfo.
1204      */
1205     NG::GatherNodeChildInfo gatherNodeChildInfo;
1206     /**
1207      * @tc.steps: step3. Create ImageNode.
1208      */
1209     auto imageNode = DragEventActuator::CreateImageNode(frameNode, gatherNodeChildInfo);
1210     EXPECT_NE(imageNode, nullptr);
1211 }
1212 
1213 /**
1214  * @tc.name: TestResetNode001
1215  * @tc.desc: Reset Node scale
1216  * @tc.type: FUNC
1217  */
1218 HWTEST_F(DragEventTestNg, TestResetNode001, TestSize.Level1)
1219 {
1220     /**
1221      * @tc.steps: step1. Create FrameNode.
1222      */
1223     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1224     ASSERT_NE(frameNode, nullptr);
1225     NG::DragPreviewOption option { true, true, false };
1226     frameNode->SetDragPreviewOptions(option);
1227     /**
1228      * @tc.steps: step2. Set Scale
1229      */
1230     auto renderContext = frameNode->GetRenderContext();
1231     ASSERT_NE(renderContext, nullptr);
1232     renderContext->UpdateTransformScale({0.9f, 0.9f});
1233     auto scale = renderContext->GetTransformScaleValue({ 1.0f, 1.0f });
1234     EXPECT_EQ(scale.x, 0.9f);
1235     EXPECT_EQ(scale.y, 0.9f);
1236     /**
1237      * @tc.steps: step3. Reset frameNode scale.
1238      */
1239     DragDropFuncWrapper::ResetNode(frameNode);
1240     auto resetScale = renderContext->GetTransformScaleValue({ 0.0f, 0.0f });
1241     EXPECT_EQ(resetScale.x, 1.0f);
1242     EXPECT_EQ(resetScale.y, 1.0f);
1243 }
1244 
1245 /**
1246  * @tc.name: TestGetFrameNodePreviewPixelMap001
1247  * @tc.desc: Create frameNode and get DragPreviewInfo.PixelMap.
1248  * @tc.type: FUNC
1249  */
1250 HWTEST_F(DragEventTestNg, TestGetFrameNodePreviewPixelMap002, TestSize.Level1)
1251 {
1252     /**
1253      * @tc.steps: step1. Create FrameNode.
1254      */
1255     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1256     ASSERT_NE(frameNode, nullptr);
1257     /**
1258      * @tc.steps: step2. Set DragPreviewInfo.
1259      */
1260     NG::DragDropInfo dragPreviewInfo;
1261     void* voidPtr = static_cast<void*>(new char[0]);
1262     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
1263     ASSERT_NE(pixelMap, nullptr);
1264     dragPreviewInfo.pixelMap = pixelMap;
1265     frameNode->SetDragPreview(dragPreviewInfo);
1266     /**
1267      * @tc.steps: step3. Get PixelMap.
1268      */
1269     DragEventActuator::GetFrameNodePreviewPixelMap(frameNode);
1270     /**
1271      * @tc.steps: step4. Get GestureEventHub.
1272      */
1273     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
1274     ASSERT_NE(gestureHub, nullptr);
1275     /**
1276      * @tc.steps: step5. Get DragPreviewPixelMap.
1277      */
1278     auto dragPreviewPixelMap = gestureHub->GetDragPreviewPixelMap();
1279     EXPECT_EQ(dragPreviewPixelMap, pixelMap);
1280 }
1281 
1282 /**
1283  * @tc.name: TestIsBelongToMultiItemNode001
1284  * @tc.desc: Test IsBelongToMultiItemNode
1285  * @tc.type: FUNC
1286  */
1287 HWTEST_F(DragEventTestNg, TestIsBelongToMultiItemNode001, TestSize.Level1)
1288 {
1289     /**
1290      * @tc.steps: step1. Create ListItemNode.
1291      */
1292     auto listItemNode = FrameNode::CreateFrameNode(
1293         V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1294         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1295     ASSERT_NE(listItemNode, nullptr);
1296     auto itemPattern = listItemNode->GetPattern<ListItemPattern>();
1297     ASSERT_NE(itemPattern, nullptr);
1298     itemPattern->SetSelected(true);
1299     NG::DragPreviewOption option { true, false, true };
1300     listItemNode->SetDragPreviewOptions(option);
1301     /**
1302      * @tc.steps: step2. Create frameNode.
1303      */
1304     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1305     ASSERT_NE(frameNode, nullptr);
1306     listItemNode->AddChild(frameNode);
1307     /**
1308      * @tc.steps: step3. Create frameNode's DragEventActuator.
1309      */
1310     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d13002(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1311     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1312         DragDropInfo info;
1313         return info;
1314     };
1315     eventHub->SetOnDragStart(std::move(onDragStart));
1316     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode));
1317     listItemNode->eventHub_ = eventHub;
1318     listItemNode->SetDraggable(true);
1319     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1320     ASSERT_NE(gestureEventHub, nullptr);
1321     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1322         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1323     ASSERT_NE(dragEventActuator, nullptr);
1324     /**
1325      * @tc.steps: step4. Run IsBelongToMultiItemNode.
1326      */
1327     auto isBelongToMultiItemNode = dragEventActuator->IsBelongToMultiItemNode(frameNode);
1328     EXPECT_EQ(isBelongToMultiItemNode, true);
1329 }
1330 
1331 /**
1332  * @tc.name: TestIsBelongToMultiItemNode002
1333  * @tc.desc: Test IsBelongToMultiItemNode
1334  * @tc.type: FUNC
1335  */
1336 HWTEST_F(DragEventTestNg, TestIsBelongToMultiItemNode002, TestSize.Level1)
1337 {
1338     /**
1339      * @tc.steps: step1. Create GridItemNode.
1340      */
1341     auto gridItemNode = FrameNode::CreateFrameNode(
1342         V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1343         AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1344     ASSERT_NE(gridItemNode, nullptr);
1345     auto itemPattern = gridItemNode->GetPattern<GridItemPattern>();
1346     ASSERT_NE(itemPattern, nullptr);
1347     itemPattern->SetSelected(true);
1348     NG::DragPreviewOption option { true, false, true };
1349     gridItemNode->SetDragPreviewOptions(option);
1350     /**
1351      * @tc.steps: step2. Create frameNode.
1352      */
1353     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1354     ASSERT_NE(frameNode, nullptr);
1355     gridItemNode->AddChild(frameNode);
1356     /**
1357      * @tc.steps: step3. Create frameNode's DragEventActuator.
1358      */
1359     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d13102(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1360     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1361         DragDropInfo info;
1362         return info;
1363     };
1364     eventHub->SetOnDragStart(std::move(onDragStart));
1365     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode));
1366     gridItemNode->eventHub_ = eventHub;
1367     gridItemNode->SetDraggable(true);
1368     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1369     ASSERT_NE(gestureEventHub, nullptr);
1370     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1371         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1372     ASSERT_NE(dragEventActuator, nullptr);
1373     /**
1374      * @tc.steps: step4. Run IsBelongToMultiItemNode.
1375      */
1376     auto isBelongToMultiItemNode = dragEventActuator->IsBelongToMultiItemNode(frameNode);
1377     EXPECT_EQ(isBelongToMultiItemNode, true);
1378 }
1379 
1380 /**
1381  * @tc.name: TestIsSelectedItemNode001
1382  * @tc.desc: Test IsSelectedItemNode
1383  * @tc.type: FUNC
1384  */
1385 HWTEST_F(DragEventTestNg, TestIsSelectedItemNode001, TestSize.Level1)
1386 {
1387     /**
1388      * @tc.steps: step1. Create GridItemNode.
1389      */
1390     auto gridItemNode = FrameNode::CreateFrameNode(
1391         V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1392         AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1393     ASSERT_NE(gridItemNode, nullptr);
1394     auto itemPattern = gridItemNode->GetPattern<GridItemPattern>();
1395     ASSERT_NE(itemPattern, nullptr);
1396     itemPattern->SetSelected(true);
1397     NG::DragPreviewOption option { true, false, true };
1398     gridItemNode->SetDragPreviewOptions(option);
1399     /**
1400      * @tc.steps: step2. Create GridItemNode's DragEventActuator.
1401      */
1402     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d13202(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1403     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1404         DragDropInfo info;
1405         return info;
1406     };
1407     eventHub->SetOnDragStart(std::move(onDragStart));
1408     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode));
1409     gridItemNode->eventHub_ = eventHub;
1410     gridItemNode->SetDraggable(true);
1411     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1412     ASSERT_NE(gestureEventHub, nullptr);
1413     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1414         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1415     ASSERT_NE(dragEventActuator, nullptr);
1416     /**
1417      * @tc.steps: step3. Run IsBelongToMultiItemNode.
1418      */
1419     auto isSelectedItemNode = dragEventActuator->IsSelectedItemNode(gridItemNode);
1420     EXPECT_EQ(isSelectedItemNode, true);
1421 }
1422 
1423 /**
1424  * @tc.name: TestIsSelectedItemNode002
1425  * @tc.desc: Test IsSelectedItemNode
1426  * @tc.type: FUNC
1427  */
1428 HWTEST_F(DragEventTestNg, TestIsSelectedItemNode002, TestSize.Level1)
1429 {
1430     /**
1431      * @tc.steps: step1. Create ListItemNode.
1432      */
1433     auto listItemNode = FrameNode::CreateFrameNode(
1434         V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1435         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1436     ASSERT_NE(listItemNode, nullptr);
1437     auto itemPattern = listItemNode->GetPattern<ListItemPattern>();
1438     ASSERT_NE(itemPattern, nullptr);
1439     itemPattern->SetSelected(true);
1440     NG::DragPreviewOption option { true, false, true };
1441     listItemNode->SetDragPreviewOptions(option);
1442     /**
1443      * @tc.steps: step2. Create ListItemNode's DragEventActuator.
1444      */
1445     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d13302(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1446     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1447         DragDropInfo info;
1448         return info;
1449     };
1450     eventHub->SetOnDragStart(std::move(onDragStart));
1451     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode));
1452     listItemNode->eventHub_ = eventHub;
1453     listItemNode->SetDraggable(true);
1454     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1455     ASSERT_NE(gestureEventHub, nullptr);
1456     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1457         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1458     ASSERT_NE(dragEventActuator, nullptr);
1459     /**
1460      * @tc.steps: step3. Run IsBelongToMultiItemNode.
1461      */
1462     auto isSelectedItemNode = dragEventActuator->IsSelectedItemNode(listItemNode);
1463     EXPECT_EQ(isSelectedItemNode, true);
1464 }
1465 
1466 /**
1467  * @tc.name: TestIsNeedGather001
1468  * @tc.desc: Test IsNeedGather
1469  * @tc.type: FUNC
1470  */
1471 HWTEST_F(DragEventTestNg, TestIsNeedGather001, TestSize.Level1)
1472 {
1473     /**
1474      * @tc.steps: step1. Create List Node.
1475      */
1476     auto listNode = FrameNode::CreateFrameNode(
1477         V2::LIST_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ListPattern>());
1478     ASSERT_NE(listNode, nullptr);
1479     /**
1480      * @tc.steps: step2. Create List Item Node.
1481      */
1482     auto listItemNode1 = FrameNode::CreateFrameNode(
1483         V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1484         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1485     ASSERT_NE(listItemNode1, nullptr);
1486     auto listItemNode2 = FrameNode::CreateFrameNode(
1487         V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1488         AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1489     ASSERT_NE(listItemNode2, nullptr);
1490     auto itemPattern1 = listItemNode1->GetPattern<ListItemPattern>();
1491     ASSERT_NE(itemPattern1, nullptr);
1492     itemPattern1->SetSelected(true);
1493     auto itemPattern2 = listItemNode2->GetPattern<ListItemPattern>();
1494     ASSERT_NE(itemPattern2, nullptr);
1495     itemPattern2->SetSelected(true);
1496     NG::DragPreviewOption option { true, false, true };
1497     listItemNode1->SetDragPreviewOptions(option);
1498     listNode->AddChild(listItemNode1);
1499     listNode->AddChild(listItemNode2);
1500     /**
1501      * @tc.steps: step3. Create DragEventActuator.
1502      */
1503     auto eventHub = AceType::MakeRefPtr<EventHub>();
__anon6f3d34d13402(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1504     auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1505         DragDropInfo info;
1506         return info;
1507     };
1508     eventHub->SetOnDragStart(std::move(onDragStart));
1509     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode1));
1510     listItemNode1->eventHub_ = eventHub;
1511     listItemNode1->SetDraggable(true);
1512     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1513     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1514         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1515     /**
1516      * @tc.steps: step4. Test IsNeedGather().
1517      */
1518     dragEventActuator->IsBelongToMultiItemNode(listItemNode1);
1519     EXPECT_EQ(dragEventActuator->isSelectedItemNode_, true);
1520     dragEventActuator->FindItemParentNode(listItemNode1);
1521     bool isNeedGather = dragEventActuator->IsNeedGather();
1522     EXPECT_EQ(isNeedGather, false);
1523 }
1524 
1525 /**
1526  * @tc.name: TestMountGatherNode001
1527  * @tc.desc: Test MountGatherNode.
1528  * @tc.type: FUNC
1529  */
1530 HWTEST_F(DragEventTestNg, TestMountGatherNode001, TestSize.Level1)
1531 {
1532     /**
1533      * @tc.steps: step1. Create DragEventActuator.
1534      */
1535     auto eventHub = AceType::MakeRefPtr<EventHub>();
1536     auto frameNode = FrameNode::CreateFrameNode(
1537         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1538     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1539     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1540     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1541         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1542     /**
1543      * @tc.steps: step2. Create a stackNode.
1544      */
1545     auto stackNode = FrameNode::GetOrCreateFrameNode(V2::STACK_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon6f3d34d13502() 1546         []() { return AceType::MakeRefPtr<StackPattern>(); });
1547     /**
1548      * @tc.steps: step3. Invoke MountGatherNode function.
1549      */
1550     auto pipeline = PipelineContext::GetCurrentContext();
1551     auto overlayManager = pipeline->GetOverlayManager();
1552     EXPECT_NE(overlayManager, nullptr);
1553     std::vector<NG::GatherNodeChildInfo> gatherNodeChildrenInfo;
1554     dragEventActuator->MountGatherNode(overlayManager, frameNode, stackNode, gatherNodeChildrenInfo);
1555     EXPECT_EQ(overlayManager->hasGatherNode_, true);
1556 }
1557 
1558 /**
1559  * @tc.name: TestUpdateDefaultShadow
1560  * @tc.desc: Test get default shadow attribute.
1561  * @tc.type: FUNC
1562  */
1563 HWTEST_F(DragEventTestNg, TestUpdateDefaultShadow, TestSize.Level1)
1564 {
1565     /**
1566      * @tc.steps: step1. Create FrameNode.
1567      */
1568     auto frameNode = FrameNode::CreateFrameNode(
1569         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1570     EXPECT_NE(frameNode, nullptr);
1571     auto eventHub = AceType::MakeRefPtr<EventHub>();
1572     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1573     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1574     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1575         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1576     /**
1577      * @tc.steps: step2. get DragPreviewOption.
1578      */
1579     auto dragPreviewOption = frameNode->GetDragPreviewOption();
1580     EXPECT_EQ(dragPreviewOption.options.shadow, std::nullopt);
1581     /**
1582      * @tc.steps: step3. set enableDefaultShadow.
1583      */
1584     dragPreviewOption.isDefaultShadowEnabled = true;
1585     frameNode->SetDragPreviewOptions(dragPreviewOption);
1586     /**
1587      * @tc.steps: step4. Invoke UpdatePreviewOptionDefaultAttr.
1588      */
1589     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1590     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1591     auto shadowTheme = AceType::MakeRefPtr<ShadowTheme>();
1592     auto themeStyle = AceType::MakeRefPtr<ThemeStyle>();
1593     shadowTheme->SetThemeStyle(themeStyle);
1594     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(shadowTheme));
1595 
1596     dragEventActuator->UpdatePreviewOptionDefaultAttr(frameNode);
1597     dragPreviewOption = frameNode->GetDragPreviewOption();
1598     EXPECT_NE(dragPreviewOption.options.shadow, std::nullopt);
1599 }
1600 
1601 /**
1602  * @tc.name: TestApplyShadow
1603  * @tc.desc: Test set default shadow attribute.
1604  * @tc.type: FUNC
1605  */
1606 HWTEST_F(DragEventTestNg, TestApplyShadow, TestSize.Level1)
1607 {
1608     /**
1609      * @tc.steps: step1. Create FrameNode.
1610      */
1611     auto frameNode = FrameNode::CreateFrameNode(
1612         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1613     EXPECT_NE(frameNode, nullptr);
1614     /**
1615      * @tc.steps: step2. get DragPreviewOption.
1616      */
1617     auto dragPreviewOption = frameNode->GetDragPreviewOption();
1618     EXPECT_EQ(dragPreviewOption.options.shadow, std::nullopt);
1619     /**
1620      * @tc.steps: step3. set defaultShadow.
1621      */
1622     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1623     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1624     auto shadowTheme = AceType::MakeRefPtr<ShadowTheme>();
1625     auto themeStyle = AceType::MakeRefPtr<ThemeStyle>();
1626     shadowTheme->SetThemeStyle(themeStyle);
1627     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(shadowTheme));
1628 
1629     dragPreviewOption.options.shadow = DragEventActuator::GetDefaultShadow();
1630     frameNode->SetDragPreviewOptions(dragPreviewOption);
1631     /**
1632      * @tc.steps: step4. Invoke ApplyNewestOptionExecutedFromModifierToNode
1633      */
1634     auto imageNode = FrameNode::CreateFrameNode(
1635         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1636     EXPECT_NE(imageNode, nullptr);
1637     imageNode->SetDragPreviewOptions(frameNode->GetDragPreviewOption());
1638     DragDropFuncWrapper::ApplyNewestOptionExecutedFromModifierToNode(frameNode, imageNode);
1639     auto imageContext = imageNode->GetRenderContext();
1640     EXPECT_NE(imageContext, nullptr);
1641     auto shadow = imageContext->GetBackShadow();
1642     EXPECT_NE(shadow, std::nullopt);
1643 }
1644 
1645 /**
1646  * @tc.name: TestBlurStyleToEffection001
1647  * @tc.desc: Test BlurStyleToEffection.
1648  * @tc.type: FUNC
1649  */
1650 HWTEST_F(DragEventTestNg, TestBlurStyleToEffection001, TestSize.Level1)
1651 {
1652     /**
1653      * @tc.steps: step1. Create DragEventActuator.
1654      */
1655     auto eventHub = AceType::MakeRefPtr<EventHub>();
1656     auto frameNode = FrameNode::CreateFrameNode(
1657         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1658     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1659     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1660     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1661         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1662     /**
1663      * @tc.steps: step2. Invoke BlurStyleToEffection function.
1664      */
1665     std::vector<float> vecGrayScale = {0.0f, 0.0f};
1666     BlurStyleOption blurStyleInfo = {BlurStyle::NO_MATERIAL, ThemeColorMode::SYSTEM,
1667      AdaptiveColor::DEFAULT, 1.0, {vecGrayScale}};
1668     std::optional<BlurStyleOption> optBlurStyleInfo(blurStyleInfo);
1669     auto optEffectOption = DragDropFuncWrapper::BlurStyleToEffection(optBlurStyleInfo);
1670     auto pipeline = PipelineContext::GetCurrentContext();
1671     ASSERT_NE(pipeline, nullptr);
1672     EXPECT_EQ(optEffectOption.has_value(), false);
1673     /**
1674      * @tc.steps: step3. Create themeManager.
1675      */
1676     auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1677     MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1678     EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<BlurStyleTheme>()));
1679     auto blurStyleTheme = pipeline->GetTheme<BlurStyleTheme>();
1680     EXPECT_NE(blurStyleTheme, nullptr);
1681     auto resAdapter = RefPtr<ResourceAdapter>();
1682     auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(resAdapter);
1683     std::unordered_map<std::string, ResValueWrapper> attributes;
1684     ResValueWrapper resValueWrapper;
1685     resValueWrapper.type = ThemeConstantsType::THEME;
1686     resValueWrapper.value = AceType::MakeRefPtr<ThemeStyle>();
1687     attributes.insert(std::pair<std::string, ResValueWrapper>(THEME_BLUR_STYLE_COMMON, resValueWrapper));
1688     themeConstants->currentThemeStyle_ = AceType::MakeRefPtr<ThemeStyle>();
1689     themeConstants->currentThemeStyle_->SetAttributes(attributes);
1690     auto blThemeInstance = BlurStyleTheme::Builder().Build(themeConstants);
1691     EXPECT_CALL(*themeManager, GetTheme(BlurStyleTheme::TypeId())).WillRepeatedly(Return(blThemeInstance));
1692     /**
1693      * @tc.steps: step4. Invoke BlurStyleToEffection function.
1694      */
1695     optEffectOption = DragDropFuncWrapper::BlurStyleToEffection(optBlurStyleInfo);
1696     ASSERT_NE(optEffectOption.has_value(), true);
1697 }
1698 
1699 /**
1700  * @tc.name: TestRadiusToSigma001
1701  * @tc.desc: Test RadiusToSigma.
1702  * @tc.type: FUNC
1703  */
1704 HWTEST_F(DragEventTestNg, TestRadiusToSigma001, TestSize.Level1)
1705 {
1706     /**
1707      * @tc.steps: step1. Create DragEventActuator.
1708      */
1709     auto eventHub = AceType::MakeRefPtr<EventHub>();
1710     auto frameNode = FrameNode::CreateFrameNode(
1711         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1712     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1713     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1714     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1715         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1716     /**
1717      * @tc.steps: step2. Invoke RadiusToSigma function invalid.
1718      */
1719     float radius = -1.0f;
1720     auto sigMa = DragDropFuncWrapper::RadiusToSigma(radius);
1721     EXPECT_EQ(sigMa, 0.0f);
1722      /**
1723      * @tc.steps: step3. Invoke RadiusToSigma function.
1724      */
1725     float scaleHalf = 0.5f;
1726     float blurSigmaScale = 0.57735f;
1727     radius = 2.0f;
1728     float retSigMa = blurSigmaScale * radius + scaleHalf;
1729     sigMa = DragDropFuncWrapper::RadiusToSigma(radius);
1730     EXPECT_EQ(sigMa, retSigMa);
1731 }
1732 
1733 /**
1734  * @tc.name: GetDefaultBorderRadiusTest001
1735  * @tc.desc: Create DragEventActuator and invoke GetDefaultBorderRadius function.
1736  * @tc.type: FUNC
1737  */
1738 HWTEST_F(DragEventTestNg, GetDefaultBorderRadiusTest001, TestSize.Level1)
1739 {
1740     /**
1741      * @tc.steps: step1. Create DragEventActuator.
1742      */
1743     auto eventHub = AceType::MakeRefPtr<EventHub>();
1744     auto frameNode = FrameNode::CreateFrameNode(
1745         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1746     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1747     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1748         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1749     /**
1750      * @tc.steps: step2. Test GetDefaultBorderRadius
1751      */
1752     NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
1753     dragPreviewOptions.options.borderRadius = dragEventActuator->GetDefaultBorderRadius();
1754     frameNode->SetDragPreviewOptions(dragPreviewOptions);
1755     auto dragPreviewOption = frameNode->GetDragPreviewOption();
1756     auto borderRadius = dragPreviewOption.options.borderRadius;
1757     EXPECT_EQ(borderRadius.value().radiusTopLeft.value().Value(), 12.0);
1758     EXPECT_EQ(borderRadius.value().radiusTopRight.value().Value(), 12.0);
1759     EXPECT_EQ(borderRadius.value().radiusBottomRight.value().Value(), 12.0);
1760     EXPECT_EQ(borderRadius.value().radiusBottomLeft.value().Value(), 12.0);
1761     /**
1762      * @tc.steps: step3. Test PrepareRadiusParametersForDragData
1763      */
1764     auto arkExtraInfoJson = JsonUtil::Create(true);
1765     dragEventActuator->PrepareRadiusParametersForDragData(frameNode, arkExtraInfoJson);
1766     auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
1767     auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
1768     auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
1769     auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
1770     EXPECT_EQ(radiusTopLeft, 12.0);
1771     EXPECT_EQ(radiusTopRight, 12.0);
1772     EXPECT_EQ(radiusBottomRight, 12.0);
1773     EXPECT_EQ(radiusBottomLeft, 12.0);
1774 }
1775 
1776 /**
1777  * @tc.name: GetSetPressedKeyCodesTest001
1778  * @tc.desc: Test GetPressedKeyCodes and SetPressedKeyCodes function.
1779  * @tc.type: FUNC
1780  */
1781 HWTEST_F(DragEventTestNg, GetSetPressedKeyCodesTest001, TestSize.Level1)
1782 {
__anon6f3d34d13602(GestureEvent& info) 1783     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d13702(GestureEvent& info) 1784     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d13802(GestureEvent& info) 1785     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d13902() 1786     GestureEventNoParameter actionCancel = []() {};
1787     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
1788         std::move(actionEnd), std::move(actionCancel));
1789     dragEvent->SetPressedKeyCodes({KeyCode::KEY_DPAD_LEFT, KeyCode::KEY_DPAD_RIGHT});
1790     auto pressedKeyCodes = dragEvent->GetPressedKeyCodes();
1791     EXPECT_EQ(pressedKeyCodes.size(), 2);
1792     EXPECT_EQ(pressedKeyCodes[1], KeyCode::KEY_DPAD_RIGHT);
1793 }
1794 
1795 /**
1796  * @tc.name: SetResponseRegionFullTest
1797  * @tc.desc: Test ResetResponseRegion function.
1798  * @tc.type: FUNC
1799  */
1800 HWTEST_F(DragEventTestNg, ReSetResponseRegion, TestSize.Level1)
1801 {
1802     /**
1803      * @tc.steps: step1. Create DragEventActuator.
1804      */
1805     auto frameNode = FrameNode::CreateFrameNode(
1806         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1807     auto eventHub = AceType::MakeRefPtr<EventHub>();
1808     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1809     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1810     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1811         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1812 
1813     /**
1814      * @tc.steps: step2. Set frameNode response region.
1815      */
1816     auto setRect = DimensionRect(Dimension(100.0f), Dimension(100.0f));
1817     auto originRect = DimensionRect(Dimension(1.0f), Dimension(1.0f));
1818     dragEventActuator->isResponseRegionFull_ = true;
1819     dragEventActuator->responseRegion_ = { originRect };
1820     gestureEventHub->responseRegion_ = { setRect };
1821     ASSERT_EQ(gestureEventHub->responseRegion_.size(), 1);
1822     EXPECT_EQ(gestureEventHub->responseRegion_[0].width_, setRect.width_);
1823     EXPECT_EQ(gestureEventHub->responseRegion_[0].height_, setRect.height_);
1824 
1825     /**
1826      * @tc.steps: step3. call ResetResponseRegion.
1827      */
1828     dragEventActuator->ResetResponseRegion();
1829     EXPECT_EQ(dragEventActuator->isResponseRegionFull_, false);
1830     ASSERT_EQ(gestureEventHub->responseRegion_.size(), 1);
1831     EXPECT_EQ(gestureEventHub->responseRegion_[0].width_, originRect.width_);
1832     EXPECT_EQ(gestureEventHub->responseRegion_[0].height_, originRect.height_);
1833 }
1834 
1835 /**
1836  * @tc.name: SetResponseRegionFullTest
1837  * @tc.desc: Test DragClog001 function.
1838  * @tc.type: FUNC
1839  */
1840 HWTEST_F(DragEventTestNg, DragClog001, TestSize.Level1)
1841 {
1842     auto pipeline = PipelineContext::GetCurrentContext();
1843     ASSERT_NE(pipeline, nullptr);
1844     auto dragDropManager = pipeline->GetDragDropManager();
1845     ASSERT_NE(dragDropManager, nullptr);
__anon6f3d34d13a02()1846     DragDropGlobalController::GetInstance().SetAsyncDragCallback([](){});
1847     dragDropManager->RemoveDeadlineTimer();
1848     EXPECT_EQ(DragDropGlobalController::GetInstance().GetAsyncDragCallback(), nullptr);
1849     auto frameNode = FrameNode::CreateFrameNode("MyButton", 102, AceType::MakeRefPtr<Pattern>());
1850     auto guestureEventHub = frameNode->GetOrCreateGestureEventHub();
1851     ASSERT_NE(guestureEventHub, nullptr);
1852     GestureEvent info;
1853     info.SetSourceDevice(SourceType::MOUSE);
1854     guestureEventHub->HandleOnDragStart(info);
1855     dragDropManager->HandleSyncOnDragStart(DragStartRequestStatus::READY);
1856     EXPECT_EQ(DragDropGlobalController::GetInstance().GetAsyncDragCallback(), nullptr);
1857 }
1858 
1859 /**
1860  * @tc.name: DragEventPreviewLongPressActionTestNG001
1861  * @tc.desc: Test DragEventPreviewLongPressActionTestNG001 function.
1862  * @tc.type: FUNC
1863  */
1864 HWTEST_F(DragEventTestNg, DragEventPreviewLongPressActionTestNG001, TestSize.Level1)
1865 {
1866     auto pipeline = PipelineContext::GetCurrentContext();
1867     ASSERT_NE(pipeline, nullptr);
1868     auto dragDropManager = pipeline->GetDragDropManager();
1869     ASSERT_NE(dragDropManager, nullptr);
1870     /**
1871      * @tc.steps: step1. Create DragEventActuator.
1872      */
1873     auto eventHub = AceType::MakeRefPtr<EventHub>();
1874     auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), false);
1875     EXPECT_NE(frameNode, nullptr);
1876     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1877     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1878     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1879         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1880 
__anon6f3d34d13b02(GestureEvent& info) 1881     GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon6f3d34d13c02(GestureEvent& info) 1882     GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon6f3d34d13d02(GestureEvent& info) 1883     GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon6f3d34d13e02() 1884     GestureEventNoParameter actionCancel = []() {};
1885     auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
1886         std::move(actionEnd), std::move(actionCancel));
1887     dragEventActuator->ReplaceDragEvent(dragEvent);
1888     dragEventActuator->SetCustomDragEvent(dragEvent);
1889     EXPECT_NE(dragEventActuator->userCallback_, nullptr);
1890     /**
1891      * @tc.steps: step2. Invoke OnCollectTouchTarget.
1892      * @tc.expected: call OnCollectTouchTarget and create previewLongPressRecognizer_ successful.
1893      */
1894     auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
1895     EXPECT_NE(getEventTargetImpl, nullptr);
1896     TouchTestResult finalResult;
1897     ResponseLinkResult responseLinkResult;
1898     frameNode->GetOrCreateFocusHub();
1899     dragEventActuator->OnCollectTouchTarget(
1900         COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
1901     EXPECT_NE(dragEventActuator->previewLongPressRecognizer_->onAction_, nullptr);
1902 
1903     /**
1904      * @tc.steps: step3. Test previewLongPressRecognizer_ onAction callback with pan success.
1905      * @tc.expected: onAction callback complete successful.
1906      */
1907     dragEventActuator->isOnBeforeLiftingAnimation_ = true;
1908     GestureEvent info = GestureEvent();
1909     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
1910     EXPECT_FALSE(dragEventActuator->isOnBeforeLiftingAnimation_);
1911 
1912     /**
1913      * @tc.steps: step4. Test previewLongPressRecognizer_ onAction callback with pan reject.
1914      * @tc.expected: onAction callback return.
1915      */
1916     dragEventActuator->isOnBeforeLiftingAnimation_ = true;
1917     auto panRecognizer = dragEventActuator->panRecognizer_;
1918     panRecognizer->disposal_ = GestureDisposal::REJECT;
1919     (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
1920     EXPECT_TRUE(dragEventActuator->isOnBeforeLiftingAnimation_);
1921 }
1922 
1923 /**
1924  * @tc.name: GetThumbnailPixelMap
1925  * @tc.desc: test GetThumbnailPixelMap.
1926  * @tc.type: FUNC
1927  */
1928 HWTEST_F(DragEventTestNg, GetThumbnailPixelMap, TestSize.Level1)
1929 {
1930     /**
1931      * @tc.steps: step1. Create DragEventActuator.
1932      */
1933     auto eventHub = AceType::MakeRefPtr<EventHub>();
1934     auto frameNode = FrameNode::CreateFrameNode(
1935         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1936     DragDropInfo dragDropInfo;
1937     frameNode->SetDragPreview(dragDropInfo);
1938     NG::DragPreviewOption previewOptions;
1939     previewOptions.isLiftingDisabled = true;
1940     frameNode->SetDragPreviewOptions(previewOptions);
1941 
1942     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1943     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1944     auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1945         AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE_EQUAL_DEFAULT);
1946     dragEventActuator->gestureEventHub_ = gestureEventHub;
1947     /**
1948      * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
1949      * @tc.expected: dragEventActuator's userCallback_ is not null.
1950      */
1951 
1952     dragEventActuator->GetThumbnailPixelMap(true);
1953     EXPECT_FALSE(dragEventActuator->isOnBeforeLiftingAnimation_);
1954 }
1955 } // namespace OHOS::Ace::NG
1956