• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test/unittest/core/event/drag_event/drag_event_common_test_ng.h"
17 
18 #define private public
19 #include "core/components_ng/manager/drag_drop/drag_drop_initiating/drag_drop_initiating_handler.h"
20 #include "core/components_ng/manager/drag_drop/drag_drop_proxy.h"
21 #undef private
22 #include "core/gestures/drag_event.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS::Ace::NG {
28 struct DragDropStartTestCase {
29     GlobalDraggingInfo globalDraggingInfo;
30     DragInfo dragInfo;
31     MultiDragInfo multiDragInfo;
32     InputEventType inputEventType;
33 
34     // calculate drag status
35     DragDropInitiatingStatus expectStatus = DragDropInitiatingStatus::IDLE;
DragDropStartTestCaseOHOS::Ace::NG::DragDropStartTestCase36     DragDropStartTestCase(GlobalDraggingInfo globalDraggingInfo, DragInfo dragInfo, MultiDragInfo multiDragInfo,
37         InputEventType inputEventType, DragDropInitiatingStatus expectStatus)
38         : globalDraggingInfo(globalDraggingInfo), dragInfo(dragInfo), multiDragInfo(multiDragInfo),
39           inputEventType(inputEventType), expectStatus(expectStatus)
40     {}
41 };
42 
43 class DragDropEventTestNgIssue : public DragEventCommonTestNg {
44 public:
45     static void SetUpTestSuite();
46     static void TearDownTestSuite();
47 
48 protected:
49     bool CheckDragDropInitiatingStatus(
50         int32_t caseNum, DragDropInitiatingStatus dragStatus, DragDropInitiatingStatus status);
51 };
52 
SetUpTestSuite()53 void DragDropEventTestNgIssue::SetUpTestSuite()
54 {
55     MockPipelineContext::SetUp();
56     MockContainer::SetUp();
57     SystemProperties::dragDropFrameworkStatus_ = 1;
58 }
59 
TearDownTestSuite()60 void DragDropEventTestNgIssue::TearDownTestSuite()
61 {
62     MockPipelineContext::TearDown();
63     MockContainer::TearDown();
64     SystemProperties::dragDropFrameworkStatus_ = 0;
65 }
66 
CheckDragDropInitiatingStatus(int32_t caseNum,DragDropInitiatingStatus dragStatus,DragDropInitiatingStatus expectStatus)67 bool DragDropEventTestNgIssue::CheckDragDropInitiatingStatus(
68     int32_t caseNum, DragDropInitiatingStatus dragStatus, DragDropInitiatingStatus expectStatus)
69 {
70     if (dragStatus == expectStatus) {
71         return testing::AssertionSuccess();
72     }
73     return testing::AssertionFailure() << "TestCaseNum: " << caseNum
74                                        << ", actual state: " << static_cast<int32_t>(dragStatus)
75                                        << ", expect state: " << static_cast<int32_t>(expectStatus);
76 }
77 
78 const std::vector<DragDropStartTestCase> DRAG_DROP_STATUS_DRAG_INFO_IMAGE_TEST_CASES = {
79     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(false, false, false, false),
80         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 0
81     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(false, false, true, false),
82         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::IDLE), // case 1
83     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(false, true, false, false),
84         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 2
85     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(false, true, true, false),
86         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 3
87     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(true, false, false, false),
88         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 4
89     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(true, false, true, false),
90         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::IDLE), // case 5
91     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(true, true, false, false),
92         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 6
93     DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(true, true, true, false),
94         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY), // case 7
95 };
96 
97 /**
98  * @tc.name: DragDropEventTestNGIssue001
99  * @tc.desc: Test CollectTouchTarget function when frameNode is image.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNGIssue001, TestSize.Level1)
103 {
104     int32_t caseNum = 0;
105     for (const auto& testCase : DRAG_DROP_STATUS_DRAG_INFO_IMAGE_TEST_CASES) {
106         /**
107          * @tc.steps: step1. create DragDropEventActuator.
108          */
109         auto eventHub = AceType::MakeRefPtr<EventHub>();
110         ASSERT_NE(eventHub, nullptr);
111         auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
112         ASSERT_NE(gestureEventHub, nullptr);
113         gestureEventHub->SetDragForbiddenForcely(testCase.dragInfo.isDragForbidden);
114         auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG,
__anon1548b6d50102() 115             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ImagePattern>(); });
116         ASSERT_NE(frameNode, nullptr);
117         eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
118         auto dragDropEventActuator =
119             AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
120         ASSERT_NE(dragDropEventActuator, nullptr);
121         /**
122          * @tc.steps: step2. call OnCollectTouchTarget function.
123          * @tc.expected: step2. DragDropInitiatingStatus equals.
124          */
125         frameNode->draggable_ = testCase.dragInfo.isDraggable;
126         frameNode->customerSet_ = testCase.dragInfo.isCustomerSet;
127         TouchRestrict dragTouchRestrict = { TouchRestrict::NONE };
128         dragTouchRestrict.inputEventType = testCase.inputEventType;
129         auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
130         EXPECT_NE(getEventTargetImpl, nullptr);
131         TouchTestResult finalResult;
132         ResponseLinkResult responseLinkResult;
133         dragDropEventActuator->OnCollectTouchTarget(
134             COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
135         auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
136         ASSERT_NE(handler, nullptr);
137         EXPECT_TRUE(
138             CheckDragDropInitiatingStatus(caseNum, handler->GetDragDropInitiatingStatus(), testCase.expectStatus));
139         caseNum++;
140     }
141 }
142 
143 /**
144  * @tc.name: DragDropEventTestNgIssue002
145  * @tc.desc: Test CopyEvent function when originDragDropInitiatingHandler is true.
146  * @tc.type: FUNC
147  */
148 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue002, TestSize.Level1)
149 {
150     auto eventHub = AceType::MakeRefPtr<EventHub>();
151     ASSERT_NE(eventHub, nullptr);
152     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
153     ASSERT_NE(gestureEventHub, nullptr);
154     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50202() 155         []() { return AceType::MakeRefPtr<ImagePattern>(); });
156     ASSERT_NE(frameNode, nullptr);
157     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
158     auto dragDropEventActuator =
159         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
160     ASSERT_NE(dragDropEventActuator, nullptr);
161     dragDropEventActuator->CopyEvent(dragDropEventActuator);
162     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
163 }
164 
165 /**
166  * @tc.name: DragDropEventTestNgIssue003
167  * @tc.desc: Test CopyEvent function when originDragDropInitiatingHandler is false.
168  * @tc.type: FUNC
169  */
170 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue003, TestSize.Level1)
171 {
172     auto eventHub = AceType::MakeRefPtr<EventHub>();
173     ASSERT_NE(eventHub, nullptr);
174     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
175     ASSERT_NE(gestureEventHub, nullptr);
176     auto dragDropEventActuator =
177         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
178     ASSERT_NE(dragDropEventActuator, nullptr);
179     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
180     dragDropEventActuator->CopyEvent(dragDropEventActuator);
181     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
182 }
183 
184 /**
185  * @tc.name: DragDropEventTestNgIssue004
186  * @tc.desc: Test GetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is nullptr and ture .
187  * @tc.type: FUNC
188  */
189 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue004, TestSize.Level1)
190 {
191     auto eventHub = AceType::MakeRefPtr<EventHub>();
192     ASSERT_NE(eventHub, nullptr);
193     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
194     ASSERT_NE(gestureEventHub, nullptr);
195     auto dragDropEventActuator =
196         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
197     ASSERT_NE(dragDropEventActuator, nullptr);
198     float preScale = 1.0f;
199     auto gestureHub = dragDropEventActuator->gestureEventHub_.Upgrade();
200     EXPECT_TRUE(!gestureHub->GetTextDraggable());
201     EXPECT_EQ(dragDropEventActuator->GetPreScaledPixelMapForDragThroughTouch(preScale), nullptr);
202 }
203 
204 /**
205  * @tc.name: DragDropEventTestNgIssue005
206  * @tc.desc: Test GetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is nullptr and false
207  * .
208  * @tc.type: FUNC
209  */
210 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue005, TestSize.Level1)
211 {
212     auto eventHub = AceType::MakeRefPtr<EventHub>();
213     ASSERT_NE(eventHub, nullptr);
214     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
215     ASSERT_NE(gestureEventHub, nullptr);
216     auto dragDropEventActuator =
217         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
218     ASSERT_NE(dragDropEventActuator, nullptr);
219     float preScale = 1.0f;
220     auto gestureHub = dragDropEventActuator->gestureEventHub_.Upgrade();
221     gestureHub->textDraggable_ = true;
222     EXPECT_TRUE(gestureHub->GetTextDraggable());
223     EXPECT_EQ(dragDropEventActuator->GetPreScaledPixelMapForDragThroughTouch(preScale), nullptr);
224 }
225 
226 /**
227  * @tc.name: DragDropEventTestNgIssue006
228  * @tc.desc: Test GetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is not nullptr and
229  * false .
230  * @tc.type: FUNC
231  */
232 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue006, TestSize.Level1)
233 {
234     auto eventHub = AceType::MakeRefPtr<EventHub>();
235     ASSERT_NE(eventHub, nullptr);
236     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
237     ASSERT_NE(gestureEventHub, nullptr);
238     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50302() 239         []() { return AceType::MakeRefPtr<ImagePattern>(); });
240     ASSERT_NE(frameNode, nullptr);
241     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
242     auto dragDropEventActuator =
243         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
244     ASSERT_NE(dragDropEventActuator, nullptr);
245     float preScale = 1.0f;
246     auto gestureHub = dragDropEventActuator->gestureEventHub_.Upgrade();
247     gestureHub->textDraggable_ = true;
248     EXPECT_TRUE(gestureHub->GetTextDraggable());
249     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
250     EXPECT_EQ(dragDropEventActuator->GetPreScaledPixelMapForDragThroughTouch(preScale), nullptr);
251 }
252 
253 /**
254  * @tc.name: DragDropEventTestNgIssue007
255  * @tc.desc: Test GetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is not nullptr and
256  * true .
257  * @tc.type: FUNC
258  */
259 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue007, TestSize.Level1)
260 {
261     auto eventHub = AceType::MakeRefPtr<EventHub>();
262     ASSERT_NE(eventHub, nullptr);
263     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
264     ASSERT_NE(gestureEventHub, nullptr);
265     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50402() 266         []() { return AceType::MakeRefPtr<ImagePattern>(); });
267     ASSERT_NE(frameNode, nullptr);
268     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
269     auto dragDropEventActuator =
270         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
271     ASSERT_NE(dragDropEventActuator, nullptr);
272     float preScale = 2.0f;
273     auto gestureHub = dragDropEventActuator->gestureEventHub_.Upgrade();
274     EXPECT_TRUE(!gestureHub->GetTextDraggable());
275     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
276     dragDropEventActuator->GetPreScaledPixelMapForDragThroughTouch(preScale);
277     EXPECT_EQ(preScale, 1.0f);
278 }
279 
280 /**
281  * @tc.name: DragDropEventTestNgIssue008
282  * @tc.desc: Test ResetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is  true .
283  * @tc.type: FUNC
284  */
285 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue008, TestSize.Level1)
286 {
287     auto eventHub = AceType::MakeRefPtr<EventHub>();
288     ASSERT_NE(eventHub, nullptr);
289     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
290     ASSERT_NE(gestureEventHub, nullptr);
291     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50502() 292         []() { return AceType::MakeRefPtr<ImagePattern>(); });
293     ASSERT_NE(frameNode, nullptr);
294     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
295     auto dragDropEventActuator =
296         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
297     ASSERT_NE(dragDropEventActuator, nullptr);
298     auto& params = dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->GetDragDropInitiatingParams();
299     params.preScaleValue = 2.0f;
300     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
301     dragDropEventActuator->ResetPreScaledPixelMapForDragThroughTouch();
302     EXPECT_EQ(params.preScaleValue, 1.0f);
303 }
304 
305 /**
306  * @tc.name: DragDropEventTestNGIssue009
307  * @tc.desc: Test NotifyTransDragWindowToFwk function when dragDropInitiatingHandler_ is  true .
308  * @tc.type: FUNC
309  */
310 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue009, TestSize.Level1)
311 {
312     auto eventHub = AceType::MakeRefPtr<EventHub>();
313     ASSERT_NE(eventHub, nullptr);
314     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
315     ASSERT_NE(gestureEventHub, nullptr);
316     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50602() 317         []() { return AceType::MakeRefPtr<ImagePattern>(); });
318     ASSERT_NE(frameNode, nullptr);
319     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
320     auto dragDropEventActuator =
321         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
322     ASSERT_NE(dragDropEventActuator, nullptr);
323     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
324     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->InitializeState();
325     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_ = 1;
326     dragDropEventActuator->NotifyTransDragWindowToFwk();
327     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_, 1);
328 }
329 
330 /**
331  * @tc.name: DragDropEventTestNgIssue010
332  * @tc.desc: Test NotifyDragStartTest function when dragDropInitiatingHandler_ is  true .
333  * @tc.type: FUNC
334  */
335 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue010, TestSize.Level1)
336 {
337     auto eventHub = AceType::MakeRefPtr<EventHub>();
338     ASSERT_NE(eventHub, nullptr);
339     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
340     ASSERT_NE(gestureEventHub, nullptr);
341     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50702() 342         []() { return AceType::MakeRefPtr<ImagePattern>(); });
343     ASSERT_NE(frameNode, nullptr);
344     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
345     auto dragDropEventActuator =
346         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
347     ASSERT_NE(dragDropEventActuator, nullptr);
348     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
349     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_, nullptr);
350     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->InitializeState();
351     auto currentState_ = dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_;
352     dragDropEventActuator->NotifyDragStart();
353     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_, currentState_);
354 }
355 
356 /**
357  * @tc.name: DragDropEventTestNgIssue012
358  * @tc.desc: Test IsNeedGatherTest function
359  * @tc.type: FUNC
360  */
361 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue012, TestSize.Level1)
362 {
363     auto eventHub = AceType::MakeRefPtr<EventHub>();
364     ASSERT_NE(eventHub, nullptr);
365     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
366     ASSERT_NE(gestureEventHub, nullptr);
367     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50802() 368         []() { return AceType::MakeRefPtr<ImagePattern>(); });
369     ASSERT_NE(frameNode, nullptr);
370     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
371     /**
372      * @tc.steps: step1. dragDropInitiatingHandler_ is not nullptr
373      */
374     auto dragDropEventActuator =
375         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
376     ASSERT_NE(dragDropEventActuator, nullptr);
377     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->GetDragDropInitiatingParams().isNeedGather =
378         true;
379     EXPECT_TRUE(dragDropEventActuator->IsNeedGather());
380     /**
381      * @tc.steps: step2. dragDropInitiatingHandler_ is  nullptr
382      */
383     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
384     EXPECT_FALSE(dragDropEventActuator->IsNeedGather());
385 }
386 
387 /**
388  * @tc.name: DragDropEventTestNgIssue013
389  * @tc.desc: Test GetIsNotInPreviewState function when dragDropInitiatingHandler_ is nullptr.
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue013, TestSize.Level1)
393 {
394     auto eventHub = AceType::MakeRefPtr<EventHub>();
395     ASSERT_NE(eventHub, nullptr);
396     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(eventHub);
397     ASSERT_NE(gestureEventHub, nullptr);
398     RefPtr<DragDropEventActuator> actuator = AceType::MakeRefPtr<DragDropEventActuator>(gestureEventHub);
399     ASSERT_NE(actuator, nullptr);
400     actuator->dragDropInitiatingHandler_ = nullptr;
401     EXPECT_TRUE(actuator->GetIsNotInPreviewState());
402 }
403 
404 /**
405  * @tc.name: DragDropEventTestNgIssue014
406  * @tc.desc: Test GetIsNotInPreviewState function when dragDropInitiatingHandler_ is not nullptr.
407  * @tc.type: FUNC
408  */
409 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue014, TestSize.Level1)
410 {
411     auto eventHub = AceType::MakeRefPtr<EventHub>();
412     ASSERT_NE(eventHub, nullptr);
413     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
414     ASSERT_NE(gestureEventHub, nullptr);
415     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50902() 416         []() { return AceType::MakeRefPtr<ImagePattern>(); });
417     ASSERT_NE(frameNode, nullptr);
418     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
419     auto dragDropEventActuator =
420         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
421     ASSERT_NE(dragDropEventActuator, nullptr);
422     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
423     bool result = dragDropEventActuator->GetIsNotInPreviewState();
424     EXPECT_TRUE(result);
425 }
426 
427 /**
428  * @tc.name: DragDropEventTestNgIssue015
429  * @tc.desc: Test NotifyMenuShow function when dragDropInitiatingHandler_ is not nullptr.
430  * @tc.type: FUNC
431  */
432 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue015, TestSize.Level1)
433 {
434     auto eventHub = AceType::MakeRefPtr<EventHub>();
435     ASSERT_NE(eventHub, nullptr);
436     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
437     ASSERT_NE(gestureEventHub, nullptr);
438     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50a02() 439         []() { return AceType::MakeRefPtr<ImagePattern>(); });
440     ASSERT_NE(frameNode, nullptr);
441     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
442     auto dragDropEventActuator =
443         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
444     ASSERT_NE(dragDropEventActuator, nullptr);
445     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
446     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->InitializeState();
447     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_ = 1;
448     bool isMenuShow = false;
449     dragDropEventActuator->NotifyMenuShow(isMenuShow);
450     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_, 1);
451 }
452 
453 /**
454  * @tc.name: DragDropEventTestNgIssue016
455  * @tc.desc: Test NotifyDragEnd function when dragDropInitiatingHandler_ is not nullptr.
456  * @tc.type: FUNC
457  */
458 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue016, TestSize.Level1)
459 {
460     auto eventHub = AceType::MakeRefPtr<EventHub>();
461     ASSERT_NE(eventHub, nullptr);
462     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
463     ASSERT_NE(gestureEventHub, nullptr);
464     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50b02() 465         []() { return AceType::MakeRefPtr<ImagePattern>(); });
466     ASSERT_NE(frameNode, nullptr);
467     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
468     auto dragDropEventActuator =
469         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
470     ASSERT_NE(dragDropEventActuator, nullptr);
471     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
472     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_, nullptr);
473     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->InitializeState();
474     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_ = 1;
475     dragDropEventActuator->NotifyDragEnd();
476     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->currentState_, 1);
477 }
478 
479 /**
480  * @tc.name: DragDropEventTestNgIssue017
481  * @tc.desc: Test SetThumbnailCallback function when dragDropInitiatingHandler_ is not nullptr.
482  * @tc.type: FUNC
483  */
484 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue017, TestSize.Level1)
485 {
486     auto eventHub = AceType::MakeRefPtr<EventHub>();
487     ASSERT_NE(eventHub, nullptr);
488     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
489     ASSERT_NE(gestureEventHub, nullptr);
490     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50c02() 491         []() { return AceType::MakeRefPtr<ImagePattern>(); });
492     ASSERT_NE(frameNode, nullptr);
493     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
494     auto dragDropEventActuator =
495         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
496     ASSERT_NE(dragDropEventActuator, nullptr);
497     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
498     auto dragDropInitiatingStateMachine = AceType::MakeRefPtr<DragDropInitiatingStateMachine>(frameNode);
499     ASSERT_NE(dragDropInitiatingStateMachine, nullptr);
500     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->dragDropInitiatingParams_
501         .getTextThumbnailPixelMapCallback = nullptr;
502     Offset offset(10.0, 20.0);
__anon1548b6d50d02(Offset offset) 503     auto callBack = [](Offset offset) {};
504     dragDropEventActuator->SetThumbnailCallback(std::move(callBack));
505     auto initiatingFlow_ = dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_;
506     EXPECT_NE(initiatingFlow_->dragDropInitiatingParams_.getTextThumbnailPixelMapCallback, nullptr);
507 }
508 
509 /**
510  * @tc.name: DragDropEventTestNgIssue018
511  * @tc.desc: Test RestartDragTask function when dragDropInitiatingHandler_ is not nullptr.
512  * @tc.type: FUNC
513  */
514 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue018, TestSize.Level1)
515 {
516     auto eventHub = AceType::MakeRefPtr<EventHub>();
517     ASSERT_NE(eventHub, nullptr);
518     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
519     ASSERT_NE(gestureEventHub, nullptr);
520     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50e02() 521         []() { return AceType::MakeRefPtr<ImagePattern>(); });
522     ASSERT_NE(frameNode, nullptr);
523     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
524     auto dragDropEventActuator =
525         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
526     ASSERT_NE(dragDropEventActuator, nullptr);
527     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
528     dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->InitializeState();
529     GestureEvent gestureEvent;
530     dragDropEventActuator->RestartDragTask(gestureEvent);
531     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->dragDropInitiatingState_[0], nullptr);
532 }
533 
534 /**
535  * @tc.name: DragDropEventTestNgIssue019
536  * @tc.desc: Test SequenceOnActionCancel callback when dragDropInitiatingHandler_ is nullptr.
537  * @tc.type: FUNC
538  */
539 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue019, TestSize.Level1)
540 {
541     auto eventHub = AceType::MakeRefPtr<EventHub>();
542     ASSERT_NE(eventHub, nullptr);
543     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
544     ASSERT_NE(gestureEventHub, nullptr);
545     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d50f02() 546         []() { return AceType::MakeRefPtr<ImagePattern>(); });
547     ASSERT_NE(frameNode, nullptr);
548     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
549     auto dragDropEventActuator =
550         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
551     ASSERT_NE(dragDropEventActuator, nullptr);
552     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
553     auto callback = dragDropEventActuator->GetSequenceOnActionCancel();
554     ASSERT_NE(callback, nullptr);
555     GestureEvent gestureEvent;
556     callback(gestureEvent);
557     ASSERT_EQ(dragDropEventActuator->dragDropInitiatingHandler_->GetDragDropInitiatingStatus(),
558         DragDropInitiatingStatus::IDLE);
559 }
560 /**
561  * @tc.name: DragDropEventTestNgIssue020
562  * @tc.desc: Test SequenceOnActionCancel callback when dragDropInitiatingHandler_ is not nullptr.
563  * @tc.type: FUNC
564  */
565 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue020, TestSize.Level1)
566 {
567     auto eventHub = AceType::MakeRefPtr<EventHub>();
568     ASSERT_NE(eventHub, nullptr);
569     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
570     ASSERT_NE(gestureEventHub, nullptr);
571     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51002() 572         []() { return AceType::MakeRefPtr<ImagePattern>(); });
573     ASSERT_NE(frameNode, nullptr);
574     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
575     auto dragDropEventActuator =
576         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
577     ASSERT_NE(dragDropEventActuator, nullptr);
578     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
579     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
580     auto pipeline = NG::PipelineContext::GetCurrentContext();
581     ASSERT_NE(pipeline, nullptr);
582     auto overlayManager = pipeline->GetOverlayManager();
583     ASSERT_NE(overlayManager, nullptr);
584     auto columnNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
585         AceType::MakeRefPtr<LinearLayoutPattern>(true));
586     overlayManager->MountPixelMapToRootNode(columnNode);
587     overlayManager->hasPixelMap_ = true;
588     auto callback = dragDropEventActuator->GetSequenceOnActionCancel();
589     ASSERT_NE(callback, nullptr);
590     GestureEvent gestureEvent;
591     callback(gestureEvent);
592     EXPECT_FALSE(overlayManager->hasPixelMap_);
593 }
594 /**
595  * @tc.name: DragDropEventTestNGIssue021
596  * @tc.desc: Test CollectTouchTarget function when sourceType is mouse.
597  * @tc.type: FUNC
598  */
599 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNGIssue021, TestSize.Level1)
600 {
601     int32_t caseNum = 0;
602     for (const auto& testCase : DRAG_DROP_STATUS_DRAG_INFO_IMAGE_TEST_CASES) {
603         /**
604          * @tc.steps: step1. create DragDropEventActuator.
605          */
606         auto eventHub = AceType::MakeRefPtr<EventHub>();
607         ASSERT_NE(eventHub, nullptr);
608         auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
609         ASSERT_NE(gestureEventHub, nullptr);
610         gestureEventHub->SetDragForbiddenForcely(testCase.dragInfo.isDragForbidden);
611         auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG,
__anon1548b6d51102() 612             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ImagePattern>(); });
613         ASSERT_NE(frameNode, nullptr);
614         eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
615         auto dragDropEventActuator =
616             AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
617         ASSERT_NE(dragDropEventActuator, nullptr);
618         /**
619          * @tc.steps: step2. call OnCollectTouchTarget function.
620          * @tc.expected: step2. DragDropInitiatingStatus equals.
621          */
622         frameNode->draggable_ = testCase.dragInfo.isDraggable;
623         frameNode->customerSet_ = testCase.dragInfo.isCustomerSet;
624         TouchRestrict dragTouchRestrict = { TouchRestrict::NONE };
625         dragTouchRestrict.inputEventType = testCase.inputEventType;
626         auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
627         EXPECT_NE(getEventTargetImpl, nullptr);
628         TouchTestResult finalResult;
629         ResponseLinkResult responseLinkResult;
630         dragDropEventActuator->OnCollectTouchTarget(
631             COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT_MOUSE, getEventTargetImpl, finalResult, responseLinkResult);
632         auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
633         ASSERT_NE(handler, nullptr);
634         EXPECT_TRUE(
635             CheckDragDropInitiatingStatus(caseNum, handler->GetDragDropInitiatingStatus(), testCase.expectStatus));
636         caseNum++;
637     }
638 }
639 
640 /**
641  * @tc.name: DragDropEventTestNgIssue022
642  * @tc.desc: Test onActionStart_ function
643  * @tc.type: FUNC
644  */
645 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue022, TestSize.Level1)
646 {
647     auto testCase = DragDropStartTestCase(GlobalDraggingInfo(false, false), DragInfo(false, false, false, false),
648         MultiDragInfo(false, false, false), InputEventType::TOUCH_SCREEN, DragDropInitiatingStatus::READY);
649     /**
650      * @tc.steps: step1. create DragDropEventActuator.
651      */
652     auto eventHub = AceType::MakeRefPtr<EventHub>();
653     ASSERT_NE(eventHub, nullptr);
654     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
655     ASSERT_NE(gestureEventHub, nullptr);
656     gestureEventHub->SetDragForbiddenForcely(testCase.dragInfo.isDragForbidden);
657     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51202() 658         []() { return AceType::MakeRefPtr<ImagePattern>(); });
659     ASSERT_NE(frameNode, nullptr);
660     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
661     auto dragDropEventActuator =
662         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
663     ASSERT_NE(dragDropEventActuator, nullptr);
664     /**
665      * @tc.steps: step2. call onActionStart_ function.
666      * @tc.expected: step2. onActionStart_ exit.
667      */
668     dragDropEventActuator->InitPanAction();
669     GestureEvent gestureEvent;
670     gestureEvent.SetPassThrough(false);
671     auto callback = *(dragDropEventActuator->panRecognizer_->onActionStart_);
672     if (callback) {
673         callback(gestureEvent);
674     }
675     gestureEvent.SetPassThrough(true);
676     callback = *(dragDropEventActuator->panRecognizer_->onActionStart_);
677     if (callback) {
678         callback(gestureEvent);
679     }
680     EXPECT_NE(callback, nullptr);
681 }
682 
683 /**
684  * @tc.name: DragDropProxyTest001
685  * @tc.desc: Test onDragStart
686  * @tc.type: FUNC
687  */
688 HWTEST_F(DragDropEventTestNgIssue, DragDropProxyTest001, TestSize.Level1)
689 {
690     /**
691      * @tc.steps: step1. construct a DragDropManager
692      */
693     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
694     GestureEvent gestureEvent;
695 
696     /**
697      * @tc.steps: step2. call onDragEnd
698      * @tc.expected: step2. drag extraInfo equals.
699      */
700     auto pipeline = MockPipelineContext::GetCurrentContextSafelyWithCheck();
701     ASSERT_NE(pipeline, nullptr);
702     auto manager = pipeline->GetDragDropManager();
703     manager->dragDropState_ = DragDropMgrState::DRAGGING;
704     auto dragDropProxy = dragDropManager->CreateFrameworkDragDropProxy();
705     dragDropProxy->id_ = manager->currentId_;
706     dragDropProxy->OnDragEnd(gestureEvent, false);
707     EXPECT_EQ(manager->dragDropState_, DragDropMgrState::IDLE);
708 }
709 
710 /**
711  * @tc.name: DragDropProxyTest002
712  * @tc.desc: Test onDragStart
713  * @tc.type: FUNC
714  */
715 HWTEST_F(DragDropEventTestNgIssue, DragDropProxyTest002, TestSize.Level1)
716 {
717     /**
718      * @tc.steps: step1. construct a DragDropManager
719      */
720     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
721     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51302() 722         []() { return AceType::MakeRefPtr<TextPattern>(); });
723     ASSERT_NE(frameNode, nullptr);
724 
725     /**
726      * @tc.steps: step2. call onDragStart
727      * @tc.expected: step2. drag extraInfo equals.
728      */
729     GestureEvent gestureEvent;
730     auto pipeline = MockPipelineContext::GetCurrentContextSafelyWithCheck();
731     ASSERT_NE(pipeline, nullptr);
732     auto manager = pipeline->GetDragDropManager();
733     auto dragDropProxy = dragDropManager->CreateFrameworkDragDropProxy();
734     dragDropProxy->id_ = manager->currentId_;
735     MockContainer::Current()->SetIsUIExtensionWindow(true);
736     dragDropProxy->OnDragStart(gestureEvent, "dragDropProxyTest", frameNode);
737     EXPECT_EQ(manager->extraInfo_, "dragDropProxyTest");
738 }
739 
740 /**
741  * @tc.name: DragDropEventTestNgIssue023
742  * @tc.desc: Test NotifyDragStart function when dragDropInitiatingHandler_ is nullptr.
743  * @tc.type: FUNC
744  */
745 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue023, TestSize.Level1)
746 {
747     auto eventHub = AceType::MakeRefPtr<EventHub>();
748     ASSERT_NE(eventHub, nullptr);
749     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
750     ASSERT_NE(gestureEventHub, nullptr);
751     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51402() 752         []() { return AceType::MakeRefPtr<ImagePattern>(); });
753     ASSERT_NE(frameNode, nullptr);
754     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
755     auto dragDropEventActuator =
756         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
757     ASSERT_NE(dragDropEventActuator, nullptr);
758     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
759     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
760     dragDropEventActuator->NotifyDragStart();
761     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
762 }
763 
764 /**
765  * @tc.name: DragDropEventTestNgIssue024
766  * @tc.desc: Test ResetPreScaledPixelMapForDragThroughTouch function when dragDropInitiatingHandler_ is nullptr.
767  * @tc.type: FUNC
768  */
769 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue024, TestSize.Level1)
770 {
771     auto eventHub = AceType::MakeRefPtr<EventHub>();
772     ASSERT_NE(eventHub, nullptr);
773     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
774     ASSERT_NE(gestureEventHub, nullptr);
775     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51502() 776         []() { return AceType::MakeRefPtr<ImagePattern>(); });
777     ASSERT_NE(frameNode, nullptr);
778     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
779     auto dragDropEventActuator =
780         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
781     ASSERT_NE(dragDropEventActuator, nullptr);
782     auto& params = dragDropEventActuator->dragDropInitiatingHandler_->initiatingFlow_->GetDragDropInitiatingParams();
783     params.preScaleValue = 2.0f;
784     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
785     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
786     dragDropEventActuator->ResetPreScaledPixelMapForDragThroughTouch();
787     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
788 }
789 
790 /**
791  * @tc.name: DragDropEventTestNGIssue025
792  * @tc.desc: Test NotifyTransDragWindowToFwk function when dragDropInitiatingHandler_ is nullptr.
793  * @tc.type: FUNC
794  */
795 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue025, TestSize.Level1)
796 {
797     auto eventHub = AceType::MakeRefPtr<EventHub>();
798     ASSERT_NE(eventHub, nullptr);
799     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
800     ASSERT_NE(gestureEventHub, nullptr);
801     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51602() 802         []() { return AceType::MakeRefPtr<ImagePattern>(); });
803     ASSERT_NE(frameNode, nullptr);
804     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
805     auto dragDropEventActuator =
806         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
807     ASSERT_NE(dragDropEventActuator, nullptr);
808     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
809     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
810     dragDropEventActuator->NotifyTransDragWindowToFwk();
811     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
812 }
813 
814 /**
815  * @tc.name: DragDropEventTestNgIssue026
816  * @tc.desc: Test NotifyMenuShow function when dragDropInitiatingHandler_ is nullptr.
817  * @tc.type: FUNC
818  */
819 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue026, TestSize.Level1)
820 {
821     auto eventHub = AceType::MakeRefPtr<EventHub>();
822     ASSERT_NE(eventHub, nullptr);
823     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
824     ASSERT_NE(gestureEventHub, nullptr);
825     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51702() 826         []() { return AceType::MakeRefPtr<ImagePattern>(); });
827     ASSERT_NE(frameNode, nullptr);
828     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
829     auto dragDropEventActuator =
830         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
831     ASSERT_NE(dragDropEventActuator, nullptr);
832     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
833     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
834     bool isMenuShow = false;
835     dragDropEventActuator->NotifyMenuShow(isMenuShow);
836     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
837 }
838 
839 /**
840  * @tc.name: DragDropEventTestNgIssue027
841  * @tc.desc: Test SetThumbnailCallback function when dragDropInitiatingHandler_ is nullptr.
842  * @tc.type: FUNC
843  */
844 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue027, TestSize.Level1)
845 {
846     auto eventHub = AceType::MakeRefPtr<EventHub>();
847     ASSERT_NE(eventHub, nullptr);
848     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
849     ASSERT_NE(gestureEventHub, nullptr);
850     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51802() 851         []() { return AceType::MakeRefPtr<ImagePattern>(); });
852     ASSERT_NE(frameNode, nullptr);
853     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
854     auto dragDropEventActuator =
855         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
856     ASSERT_NE(dragDropEventActuator, nullptr);
857     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
858     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
859     Offset offset(10.0, 20.0);
__anon1548b6d51902(Offset offset) 860     auto callBack = [](Offset offset) {};
861     dragDropEventActuator->SetThumbnailCallback(std::move(callBack));
862     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
863 }
864 
865 /**
866  * @tc.name: DragDropEventTestNgIssue028
867  * @tc.desc: Test HandleTouchEvent function when touches is empty.
868  * @tc.type: FUNC
869  */
870 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue028, TestSize.Level1)
871 {
872     auto eventHub = AceType::MakeRefPtr<EventHub>();
873     ASSERT_NE(eventHub, nullptr);
874     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
875     ASSERT_NE(gestureEventHub, nullptr);
876     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51a02() 877         []() { return AceType::MakeRefPtr<ImagePattern>(); });
878     ASSERT_NE(frameNode, nullptr);
879     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
880     auto dragDropEventActuator =
881         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
882     ASSERT_NE(dragDropEventActuator, nullptr);
883     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
884 
885     TouchEventInfo info("onTouch");
886     dragDropEventActuator->HandleTouchEvent(info, false);
887     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
888 
889     TouchLocationInfo touchInfo1(1);
890     touchInfo1.SetTouchType(TouchType::CANCEL);
891     info.AddTouchLocationInfo(std::move(touchInfo1));
892     dragDropEventActuator->HandleTouchEvent(info, false);
893     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
894 
895     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
896     dragDropEventActuator->HandleTouchEvent(info, false);
897     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
898 }
899 
900 /**
901  * @tc.name: DragDropEventTestNgIssue029
902  * @tc.desc: Test NotifyDragEnd  function when dragDropInitiatingHandler_ is nullptr.
903  * @tc.type: FUNC
904  */
905 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue029, TestSize.Level1)
906 {
907     auto eventHub = AceType::MakeRefPtr<EventHub>();
908     ASSERT_NE(eventHub, nullptr);
909     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
910     ASSERT_NE(gestureEventHub, nullptr);
911     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51b02() 912         []() { return AceType::MakeRefPtr<ImagePattern>(); });
913     ASSERT_NE(frameNode, nullptr);
914     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
915     auto dragDropEventActuator =
916         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
917     ASSERT_NE(dragDropEventActuator, nullptr);
918     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
919     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
920     dragDropEventActuator->NotifyDragEnd();
921     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
922 }
923 
924 /**
925  * @tc.name: DragDropEventTestNgIssue030
926  * @tc.desc: Test NotifyPreDragStatus function when dragDropInitiatingHandler_ is not nullptr.
927  * @tc.type: FUNC
928  */
929 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue030, TestSize.Level1)
930 {
931     auto eventHub = AceType::MakeRefPtr<EventHub>();
932     ASSERT_NE(eventHub, nullptr);
933     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
934     ASSERT_NE(gestureEventHub, nullptr);
935     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51c02() 936         []() { return AceType::MakeRefPtr<ImagePattern>(); });
937     ASSERT_NE(frameNode, nullptr);
938     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
939     auto dragDropEventActuator =
940         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
941     ASSERT_NE(dragDropEventActuator, nullptr);
942     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
943 
944     dragDropEventActuator->NotifyPreDragStatus(PreDragStatus::ACTION_DETECTING_STATUS);
945     EXPECT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
946 }
947 
948 /**
949  * @tc.name: DragDropEventTestNgIssue031
950  * @tc.desc: Test NotifyPreDragStatus function when dragDropInitiatingHandler_ is nullptr.
951  * @tc.type: FUNC
952  */
953 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue031, TestSize.Level1)
954 {
955     auto eventHub = AceType::MakeRefPtr<EventHub>();
956     ASSERT_NE(eventHub, nullptr);
957     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
958     ASSERT_NE(gestureEventHub, nullptr);
959     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51d02() 960         []() { return AceType::MakeRefPtr<ImagePattern>(); });
961     ASSERT_NE(frameNode, nullptr);
962     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
963     auto dragDropEventActuator =
964         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
965     ASSERT_NE(dragDropEventActuator, nullptr);
966     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
967 
968     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
969     dragDropEventActuator->NotifyPreDragStatus(PreDragStatus::ACTION_DETECTING_STATUS);
970     EXPECT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
971 }
972 
973 /**
974  * @tc.name: DragDropEventTestNgIssue032
975  * @tc.desc: Test RestartDragTask when dragDropInitiatingHandler_ is nullptr.
976  * @tc.type: FUNC
977  */
978 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue032, TestSize.Level1)
979 {
980     auto eventHub = AceType::MakeRefPtr<EventHub>();
981     ASSERT_NE(eventHub, nullptr);
982     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
983     ASSERT_NE(gestureEventHub, nullptr);
984     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51e02() 985         []() { return AceType::MakeRefPtr<ImagePattern>(); });
986     ASSERT_NE(frameNode, nullptr);
987     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
988     auto dragDropEventActuator =
989         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
990     ASSERT_NE(dragDropEventActuator, nullptr);
991     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
992     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
993     GestureEvent gestureEvent;
994     dragDropEventActuator->RestartDragTask(gestureEvent);
995     ASSERT_EQ(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
996 }
997 
998 /**
999  * @tc.name: DragDropEventTestNgIssue033
1000  * @tc.desc: Test onActionEnd_ callback when dragDropInitiatingHandler_ is not nullptr.
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue033, TestSize.Level1)
1004 {
1005     /**
1006      * @tc.steps: step1. create dragDropEventActuator.
1007      * @tc.expected: step1. dragDropEventActuator exit.
1008      */
1009     auto pipelineContext = MockPipelineContext::GetCurrentContext();
1010     ASSERT_NE(pipelineContext, nullptr);
1011     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1012     ASSERT_NE(dragDropManager, nullptr);
1013     pipelineContext->dragDropManager_ = dragDropManager;
1014     RefPtr<UINode> rootNode = AceType::MakeRefPtr<FrameNode>("root_node", -1, AceType::MakeRefPtr<Pattern>());
1015     ASSERT_NE(rootNode, nullptr);
1016     auto overlayManager = AceType::MakeRefPtr<OverlayManager>(AceType::DynamicCast<FrameNode>(rootNode));
1017     ASSERT_NE(overlayManager, nullptr);
1018     pipelineContext->overlayManager_ = overlayManager;
1019 
1020     auto eventHub = AceType::MakeRefPtr<EventHub>();
1021     ASSERT_NE(eventHub, nullptr);
1022     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1023     ASSERT_NE(gestureEventHub, nullptr);
1024     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d51f02() 1025         []() { return AceType::MakeRefPtr<ImagePattern>(); });
1026     ASSERT_NE(frameNode, nullptr);
1027     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1028     auto dragDropEventActuator =
1029         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
1030     ASSERT_NE(dragDropEventActuator, nullptr);
1031     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
1032     ASSERT_NE(handler, nullptr);
1033     auto machine = handler->initiatingFlow_;
1034     ASSERT_NE(machine, nullptr);
1035     machine->InitializeState();
1036     dragDropManager->ResetDragging(DragDropMgrState::IDLE);
1037     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::READY);
1038     /**
1039      * @tc.steps: step2. call onActionEnd_ function.
1040      * @tc.expected: step2. onActionEnd_ exit.
1041      */
1042     dragDropEventActuator->InitPanAction();
1043     GestureEvent gestureEvent;
1044     auto callback = *(dragDropEventActuator->panRecognizer_->onActionEnd_);
1045     if (callback) {
1046         callback(gestureEvent);
1047     }
1048     ASSERT_EQ(dragDropEventActuator->dragDropInitiatingHandler_->GetDragDropInitiatingStatus(),
1049         DragDropInitiatingStatus::IDLE);
1050 }
1051 
1052 /**
1053  * @tc.name: DragDropEventTestNgIssue034
1054  * @tc.desc: Test onActionEnd_ callback when dragDropInitiatingHandler_ is nullptr.
1055  * @tc.type: FUNC
1056  */
1057 HWTEST_F(DragDropEventTestNgIssue, DragDropEventTestNgIssue034, TestSize.Level1)
1058 {
1059     /**
1060      * @tc.steps: step1. create dragDropEventActuator.
1061      * @tc.expected: step1. dragDropEventActuator exit.
1062      */
1063     auto eventHub = AceType::MakeRefPtr<EventHub>();
1064     ASSERT_NE(eventHub, nullptr);
1065     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1066     ASSERT_NE(gestureEventHub, nullptr);
1067     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anon1548b6d52002() 1068         []() { return AceType::MakeRefPtr<ImagePattern>(); });
1069     ASSERT_NE(frameNode, nullptr);
1070     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1071     auto dragDropEventActuator =
1072         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
1073     ASSERT_NE(dragDropEventActuator, nullptr);
1074     ASSERT_NE(dragDropEventActuator->dragDropInitiatingHandler_, nullptr);
1075     dragDropEventActuator->dragDropInitiatingHandler_ = nullptr;
1076     auto pipeline = NG::PipelineContext::GetCurrentContext();
1077     ASSERT_NE(pipeline, nullptr);
1078     auto overlayManager = pipeline->GetOverlayManager();
1079     ASSERT_NE(overlayManager, nullptr);
1080     auto columnNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1081         AceType::MakeRefPtr<LinearLayoutPattern>(true));
1082     ASSERT_NE(columnNode, nullptr);
1083     overlayManager->MountPixelMapToRootNode(columnNode);
1084     overlayManager->hasPixelMap_ = true;
1085     /**
1086      * @tc.steps: step2. call onActionEnd_ function.
1087      * @tc.expected: step2. onActionEnd_ exit.
1088      */
1089     dragDropEventActuator->InitPanAction();
1090     GestureEvent gestureEvent;
1091     auto callback = *(dragDropEventActuator->panRecognizer_->onActionEnd_);
1092     if (callback) {
1093         callback(gestureEvent);
1094     }
1095     EXPECT_FALSE(overlayManager->hasPixelMap_);
1096 }
1097 } // namespace OHOS::Ace::NG