• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test/unittest/core/manager/drag_drop_manager_test_ng.h"
17 
18 #include "test/mock/core/render/mock_render_context.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace::NG {
23 
TestFunction(const DragPointerEvent & event)24 void  TestFunction(const DragPointerEvent& event) {}
SetUpTestCase()25 void DragDropManagerTestNg::SetUpTestCase()
26 {
27     MockPipelineContext::SetUp();
28     MockContainer::SetUp();
29 }
30 
TearDownTestCase()31 void DragDropManagerTestNg::TearDownTestCase()
32 {
33     MockPipelineContext::TearDown();
34     MockContainer::TearDown();
35 }
36 
37 /**
38  * @tc.name: DragDropManagerTest001
39  * @tc.desc: CreateAndShowItemDragOverlay via pixelMap and gestureEvent
40  * @tc.type: FUNC
41  * @tc.author:
42  */
43 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest001, TestSize.Level1)
44 {
45     /**
46      * @tc.steps: step1. construct a DragDropManager
47      */
48     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
49 
50     /**
51      * @tc.steps: step2. call CreateAndShowItemDragOverlay
52      * @tc.expected: step2. return a dragDropProxy successfully
53      *                      DragWindow.DrawPixelMap() will be called
54      */
55     void* voidPtr = static_cast<void*>(new char[0]);
56     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
57     GestureEvent gestureEvent;
58     RefPtr<EventHub> eventhub;
59     auto dragDropProxy = dragDropManager->CreateAndShowItemDragOverlay(pixelMap, gestureEvent, eventhub);
60     EXPECT_TRUE(dragDropProxy);
61 
62     /**
63      * @tc.steps: step3. call CreateAndShowItemDragOverlay with null.
64      * @tc.expected: step3. return dragDropProxy to false.
65      */
66     pixelMap = nullptr;
67     dragDropProxy = dragDropManager->CreateAndShowItemDragOverlay(pixelMap, gestureEvent, eventhub);
68     EXPECT_FALSE(dragDropProxy);
69 }
70 
71 /**
72  * @tc.name: DragDropManagerTest002
73  * @tc.desc: CreateAndShowItemDragOverlay via customNode and gestureEvent
74  * @tc.type: FUNC
75  * @tc.author:
76  */
77 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest002, TestSize.Level1)
78 {
79     /**
80      * @tc.steps: step1. construct a DragDropManager
81      */
82     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
83 
84     /**
85      * @tc.steps: step2. call CreateAndShowItemDragOverlay
86      * @tc.expected: step2. return a dragDropProxy successfully
87      *                      DragWindow.DrawFrameNode() will be called
88      */
89     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
90     GestureEvent gestureEvent;
91     RefPtr<EventHub> eventhub;
92     auto dragDropProxy = dragDropManager->CreateAndShowItemDragOverlay(customNode, gestureEvent, eventhub);
93     EXPECT_TRUE(dragDropProxy);
94 
95     /**
96      * @tc.expected: step2. the customNode's parent is root
97      */
98     auto root = customNode->GetParent();
99     auto rootTag = root->GetTag();
100     EXPECT_EQ(rootTag, ROOT_ETS_TAG);
101 }
102 
103 /**
104  * @tc.name: DragDropManagerTest003
105  * @tc.desc: Test UpdateItemDragPosition
106  * @tc.type: FUNC
107  * @tc.author:
108  */
109 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest003, TestSize.Level1)
110 {
111     /**
112      * @tc.steps: step1. construct a DragDropManager
113      */
114     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
115 
116     /**
117      * @tc.steps: step2. call CreateAndShowItemDragOverlay
118      * @tc.expected: step2. return a dragDropProxy successfully
119      */
120     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
121     GestureEvent gestureEvent;
122     RefPtr<EventHub> eventhub;
123     auto dragDropProxy = dragDropManager->CreateAndShowItemDragOverlay(customNode, gestureEvent, eventhub);
124     EXPECT_TRUE(dragDropProxy);
125     auto pipelineContext = MockPipelineContext::GetCurrentContext();
126     ASSERT_NE(pipelineContext, nullptr);
127     pipelineContext->SetDisplayWindowRectInfo({ 0, 0, 800, 800 }); // 800: window width and height
128     /**
129      * @tc.steps: step3. call UpdateItemDragPosition
130      * @tc.expected: step3. itemDragOverlayNode_'s position is updated to (GLOBAL_X, GLOBAL_Y)
131      */
132     dragDropManager->UpdateItemDragPosition(GLOBAL_X, GLOBAL_Y);
133     auto renderContext = dragDropManager->itemDragOverlayNode_->GetRenderContext();
134     EXPECT_EQ(renderContext->GetPosition().value(), OffsetT<Dimension>(Dimension(GLOBAL_X), Dimension(GLOBAL_Y)));
135 }
136 
137 /**
138  * @tc.name: DragDropManagerTest004
139  * @tc.desc: Test Functions relevant to Clipboard
140              Call this functions in order (AddDataToClipboard->GetExtraInfoFromClipboard->RestoreClipboardData)
141  * @tc.type: FUNC
142  * @tc.author:
143  */
144 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest004, TestSize.Level1)
145 {
146     /**
147      * @tc.steps: step1. construct a DragDropManager
148      */
149     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
150 
151     /**
152      * @tc.steps: step2. call AddDataToClipboard
153      * @tc.expected: step2. ClipBoard.SetData() & ClipBoard.GetData() will be called with printing logs
154      *                      they're defined in "components_ng/test/mock/clipboard/mock_clipboard.cpp"
155      */
156     dragDropManager->AddDataToClipboard(EXTRA_INFO);
157 
158     /**
159      * @tc.steps: step3. call GetExtraInfoFromClipboard after calling AddDataToClipboard
160      * @tc.expected: step3. get the extraInfo successfully
161      *                      ClipBoard.GetData() will be called with printing a log
162      *                      it's defined in "components_ng/test/mock/clipboard/mock_clipboard.cpp"
163      */
164     std::string extraInfo;
165     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
166     EXPECT_EQ(extraInfo, EXTRA_INFO);
167 
168     /**
169      * @tc.steps: step4. call GetExtraInfoFromClipboard
170      * @tc.expected: step4. extraInfo is equal to EXTRA_INFO
171      */
172     dragDropManager->clipboard_ = nullptr;
173     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
174     EXPECT_EQ(extraInfo, EXTRA_INFO);
175 
176     /**
177      * @tc.steps: step5. call AddDataToClipboard with empty.
178      * @tc.expected: step5. extraInfo is equal to EXTRA_INFO
179      */
180     dragDropManager->AddDataToClipboard(extraInfo);
181     EXPECT_EQ(extraInfo, EXTRA_INFO);
182 }
183 
184 /**
185  * @tc.name: DragDropManagerTest005
186  * @tc.desc: Test Functions relevant to Clipboard
187              Call this functions not in order (to test boundary cases)
188  * @tc.type: FUNC
189  * @tc.author:
190  */
191 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest005, TestSize.Level1)
192 {
193     /**
194      * @tc.steps: step1. construct a DragDropManager
195      */
196     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
197 
198     /**
199      * @tc.steps: step3. call AddDataToClipboard twice
200      *                   case: clipboard_ & addDataCallback_ has exited,
201      * @tc.expected: step3. EXTRA_INFO_2 will be added
202      */
203     dragDropManager->AddDataToClipboard(EXTRA_INFO);
204     dragDropManager->AddDataToClipboard(EXTRA_INFO_2);
205     std::string extraInfo;
206     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
207     EXPECT_EQ(extraInfo, EXTRA_INFO_2);
208 
209     /**
210      * @tc.steps: step4. call GetExtraInfoFromClipboard twice
211      *                   case: clipboard_ & addDataCallback_ has exited
212      * @tc.expected: step4. get the extraInfo successfully
213      */
214     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
215     EXPECT_EQ(extraInfo, EXTRA_INFO_2);
216 }
217 
218 /**
219  * @tc.name: DragDropManagerTest006
220  * @tc.desc: Test DestroyDragWindow & CheckDragDropProxy
221  * @tc.type: FUNC
222  * @tc.author:
223  */
224 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest006, TestSize.Level1)
225 {
226     /**
227      * @tc.steps: step1. construct a DragDropManager
228      */
229     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
230 
231     /**
232      * @tc.steps: step2. call DestroyDragWindow without creating dragWindow
233      * @tc.expected: step2. no fatal error happens
234      */
235     dragDropManager->DestroyDragWindow();
236 
237     /**
238      * @tc.steps: step3. call CheckDragDropProxy without creating dragWindow
239      * @tc.expected: step3. currentId is -1 at first
240      */
241     auto flag = dragDropManager->CheckDragDropProxy(INVALID_CURRENT_ID);
242     EXPECT_TRUE(flag);
243 
244     /**
245      * @tc.steps: step4. call CreateFrameworkDragDropProxy
246      * @tc.expected: step4. return a dragDropProxy successfully
247      */
248     auto dragDropProxy = dragDropManager->CreateFrameworkDragDropProxy();
249     EXPECT_TRUE(dragDropProxy);
250 
251     /**
252      * @tc.steps: step5. call CheckDragDropProxy after creating dragWindow
253      * @tc.expected: step5. currentId recover to -1
254      *                      MockDragWindow.Destroy() will be called
255      */
256     dragDropManager->DestroyDragWindow();
257     flag = dragDropManager->CheckDragDropProxy(INVALID_CURRENT_ID);
258     EXPECT_TRUE(flag);
259 
260     /**
261      * @tc.steps: step6. call CheckDragDropProxy (use proxy to create drag window)
262      * @tc.expected: step6. currentId recover to -1
263      */
264     auto dragDropManager2 = AceType::MakeRefPtr<DragDropManager>();
265     auto dragDropProxy2 = dragDropManager2->CreateFrameworkDragDropProxy();
266     EXPECT_TRUE(dragDropProxy2);
267     dragDropManager2->DestroyDragWindow();
268     flag = dragDropManager2->CheckDragDropProxy(INVALID_CURRENT_ID);
269     EXPECT_TRUE(flag);
270 }
271 
272 /**
273  * @tc.name: DragDropManagerTest007
274  * @tc.desc: Test OnDragStart & onDragCancel & OnItemDragStart & onItemDragCancel
275  * @tc.type: FUNC
276  * @tc.author:
277  */
278 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest007, TestSize.Level1)
279 {
280     /**
281      * @tc.steps: step1. construct a DragDropManager
282      */
283     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
284 
285     /**
286      * @tc.steps: step2. call OnDragStart
287      * @tc.expected: step2. draggedFrameNode_ &  preTargetFrameNode_ are assigned to the frameNode created previously
288      */
289     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
290     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, frameNode);
291     auto draggedNode = dragDropManager->draggedFrameNode_;
292     auto preTargetNode = dragDropManager->preTargetFrameNode_;
293     ASSERT_TRUE(draggedNode);
294     ASSERT_TRUE(preTargetNode);
295     auto draggedNodeTag = draggedNode->GetTag();
296     auto preTargetNodeTag = preTargetNode->GetTag();
297     EXPECT_EQ(draggedNodeTag, NODE_TAG);
298     EXPECT_EQ(preTargetNodeTag, NODE_TAG);
299 
300     /**
301      * @tc.steps: step3. call onDragCancel
302      * @tc.expected: step3. draggedFrameNode_ &  preTargetFrameNode_ are assigned to nullptr
303      */
304     dragDropManager->onDragCancel();
305     draggedNode = dragDropManager->draggedFrameNode_;
306     preTargetNode = dragDropManager->preTargetFrameNode_;
307     EXPECT_FALSE(draggedNode);
308     EXPECT_FALSE(preTargetNode);
309 
310     /**
311      * @tc.steps: step4. call OnItemDragStart
312      * @tc.expected: step4. preGridTargetNodeTag is assigned to the gridFrameNode created previously
313      */
314     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<Pattern>());
315     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
316     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
317     ASSERT_TRUE(preGridTargetNode);
318     auto preGridTargetNodeTag = preGridTargetNode->GetTag();
319     EXPECT_EQ(preGridTargetNodeTag, GRID_TAG);
320 
321     /**
322      * @tc.steps: step5. call onItemDragCancel
323      * @tc.expected: step5. preGridTargetFrameNode_ is assigned to nullptr
324      */
325     dragDropManager->onItemDragCancel();
326     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
327     EXPECT_FALSE(preGridTargetNode);
328 }
329 
330 /**
331  * @tc.name: DragDropManagerTest009
332  * @tc.desc: Test OnItemDragMove DragType is Grid
333  * @tc.type: FUNC
334  * @tc.author:
335  */
336 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest008, TestSize.Level1)
337 {
338     /**
339      * @tc.steps: step1. construct a DragDropManager
340      */
341     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
342 
343     /**
344      * @tc.steps: step2. construct a frameNode whose tag is Grid set its ItemDragEvent and GeometryNode
345      */
346     auto frameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
347     auto eventHub = frameNode->GetOrCreateEventHub<GridEventHub>();
348     ASSERT_TRUE(eventHub);
349     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
350     GestureEvent gestureEvent;
351     auto dragDropProxy = dragDropManager->CreateAndShowItemDragOverlay(customNode, gestureEvent, eventHub);
352     EXPECT_TRUE(dragDropProxy);
353 
354     // Set OnItemDragLeave callback
355     std::string itemInfoLeave;
__anonb7fa81190102(const ItemDragInfo& , int32_t ) 356     auto onItemDragLeave = [&itemInfoLeave](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
357         itemInfoLeave = ITEM_INFO_LEAVE;
358     };
359     eventHub->SetOnItemDragLeave(std::move(onItemDragLeave));
360 
361     // Set OnItemDragMove callback
362     std::string itemInfoMove;
363     auto onItemDragMove = [&itemInfoMove](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190202(const ItemDragInfo& , int32_t , int32_t ) 364                               int32_t /* insertIndex */) { itemInfoMove = ITEM_INFO_MOVE; };
365     eventHub->SetOnItemDragMove(std::move(onItemDragMove));
366 
367     // Set OnItemDragEnter callback
368     std::string itemInfoEnter;
__anonb7fa81190302(const ItemDragInfo& ) 369     auto onItemDragEnter = [&itemInfoEnter](const ItemDragInfo& /* dragInfo */) { itemInfoEnter = ITEM_INFO_ENTER; };
370     eventHub->SetOnItemDragEnter(std::move(onItemDragEnter));
371 
372     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
373     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
374     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
375     geoNode->SetFrameSize(FRAME_SIZE);
376     frameNode->SetGeometryNode(geoNode);
377 
378     /**
379      * @tc.steps: step4. call OnItemDragMove
380      *                   case: gridDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
381      * @tc.expected: step4. frameNode's onItemDragLeave_ will be called
382      *                      itemInfoLeave will be assigned to ITEM_INFO_LEAVE
383      */
384     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
385     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
386     ASSERT_TRUE(preGridTargetNode);
387     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
388     EXPECT_EQ(itemInfoLeave, ITEM_INFO_LEAVE);
389     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
390     EXPECT_FALSE(preGridTargetNode);
391 
392     /**
393      * @tc.steps: step5. call AddGridDragFrameNode
394      *                   after that, gridDragFrameNodes_ is not empty
395      */
396     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
397 
398     /**
399      * @tc.steps: step6. call OnItemDragMove
400      *                   case: gridDragFrameNodes_ is not empty & preGridTargetFrameNode_ equals the frameNode
401      * @tc.expected: step6. frameNode's OnItemDragMove_ will be called
402      *                      itemInfoMove will be assigned to ITEM_INFO_MOVE
403      */
404     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
405     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
406     EXPECT_TRUE(preGridTargetNode);
407     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
408 
409     /**
410      * @tc.steps: step7. call OnItemDragMove
411      *                   case: gridDragFrameNodes_ is not empty & preGridTargetFrameNode_ not equals the frameNode
412      * @tc.expected: step7. frameNode's onDragItemEnter_ will be called
413      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
414      *                      preGridTargetFrameNode_'s onDragItemLeave will be called
415      *                      leaveExtraInfoNew will be assigned to ITEM_INFO_ENTER
416      *                      preGridTargetFrameNode_ is assigned to frameNode
417      */
418     auto newFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
419     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, newFrameNode);
420     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
421     EXPECT_TRUE(preGridTargetNode);
422     // Set newFrameNode's onDragLeave callback
423     auto eventHubNew = newFrameNode->GetOrCreateEventHub<GridEventHub>();
424     ASSERT_TRUE(eventHubNew);
425     std::string itemInfoLeaveNew;
__anonb7fa81190402(const ItemDragInfo& , int32_t ) 426     auto onItemDragLeaveNew = [&itemInfoLeaveNew](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
427         itemInfoLeaveNew = ITEM_INFO_ENTER;
428     };
429     eventHubNew->SetOnItemDragLeave(std::move(onItemDragLeaveNew));
430     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
431     EXPECT_EQ(itemInfoLeaveNew, ITEM_INFO_ENTER);
432     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
433     ASSERT_FALSE(preGridTargetNode);
434 }
435 
436 /**
437  * @tc.name: DragDropManagerTest010
438  * @tc.desc: Test OnItemDragMove DragType is List
439  * @tc.type: FUNC
440  * @tc.author:
441  */
442 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest009, TestSize.Level1)
443 {
444     /**
445      * @tc.steps: step1. construct a DragDropManager
446      */
447     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
448 
449     /**
450      * @tc.steps: step2. construct a frameNode whose tag is List set its ItemDragEvent and GeometryNode
451      */
452     auto frameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
453     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
454     ASSERT_TRUE(eventHub);
455 
456     // Set OnItemDragLeave callback
457     std::string itemInfoLeave;
__anonb7fa81190502(const ItemDragInfo& , int32_t ) 458     auto onItemDragLeave = [&itemInfoLeave](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
459         itemInfoLeave = ITEM_INFO_LEAVE;
460     };
461     eventHub->SetOnItemDragLeave(std::move(onItemDragLeave));
462 
463     // Set OnItemDragMove callback
464     std::string itemInfoMove;
465     auto onItemDragMove = [&itemInfoMove](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190602(const ItemDragInfo& , int32_t , int32_t ) 466                               int32_t /* insertIndex */) { itemInfoMove = ITEM_INFO_MOVE; };
467     eventHub->SetOnItemDragMove(std::move(onItemDragMove));
468 
469     // Set OnItemDragEnter callback
470     std::string itemInfoEnter;
__anonb7fa81190702(const ItemDragInfo& ) 471     auto onItemDragEnter = [&itemInfoEnter](const ItemDragInfo& /* dragInfo */) { itemInfoEnter = ITEM_INFO_ENTER; };
472     eventHub->SetOnItemDragEnter(std::move(onItemDragEnter));
473 
474     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
475     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
476     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
477     geoNode->SetFrameSize(FRAME_SIZE);
478     frameNode->SetGeometryNode(geoNode);
479 
480     /**
481      * @tc.steps: step3. call OnItemDragMove
482      *                   case: listDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
483      * @tc.expected: step3. frameNode's onItemDragLeave_ will be called
484      *                      itemInfoLeave will be assigned to ITEM_INFO_LEAVE
485      */
486     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
487     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
488     ASSERT_TRUE(preGridTargetNode);
489     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
490     EXPECT_EQ(itemInfoLeave, ITEM_INFO_LEAVE);
491     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
492     EXPECT_FALSE(preGridTargetNode);
493 
494     /**
495      * @tc.steps: step4. call AddGridDragFrameNode
496      *                   after that, listDragFrameNodes_ is not empty
497      *                   need adding grid maybe a bug
498      */
499     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
500 
501     /**
502      * @tc.steps: step5. call OnItemDragMove
503      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ equals the frameNode
504      * @tc.expected: step5. a gridEventHub is trying to get by the frameNode,
505      *                      but it's list type, so will return early(maybe that is a bug)
506      *                      itemInfoMove will not be assigned DragWindow.MoveTo() will be called
507      */
508     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
509     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
510     EXPECT_TRUE(preGridTargetNode);
511     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
512     EXPECT_EQ(itemInfoMove, "");
513     // to force call the FireOnItemDragEvent with DragType::LIST and DragEventType::MOVE
514     OHOS::Ace::ItemDragInfo itemDragInfo;
515     dragDropManager->FireOnItemDragEvent(frameNode, DragType::LIST, itemDragInfo, DragEventType::MOVE, DRAGGED_INDEX);
516     EXPECT_EQ(itemInfoMove, ITEM_INFO_MOVE);
517 
518     /**
519      * @tc.steps: step6. call OnItemDragMove
520      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ not equals the frameNode
521      * @tc.expected: step6. frameNode's onDragItemEnter_ will be called
522      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
523      *                      preGridTargetFrameNode_'s onDragItemLeave will be called
524      *                      leaveExtraInfoNew will be assigned to ITEM_INFO_ENTER
525      *                      preGridTargetFrameNode_ is assigned to frameNode
526      */
527     auto newFrameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
528     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, newFrameNode);
529     EXPECT_TRUE(dragDropManager->preGridTargetFrameNode_);
530     // Set newFrameNode's onDragLeave callback
531     auto eventHubNew = newFrameNode->GetOrCreateEventHub<ListEventHub>();
532     ASSERT_TRUE(eventHubNew);
533     std::string itemInfoLeaveNew;
__anonb7fa81190802(const ItemDragInfo& , int32_t ) 534     auto onItemDragLeaveNew = [&itemInfoLeaveNew](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
535         itemInfoLeaveNew = ITEM_INFO_ENTER;
536     };
537     eventHubNew->SetOnItemDragLeave(std::move(onItemDragLeaveNew));
538     EXPECT_EQ(itemInfoEnter, "");
539     EXPECT_EQ(itemInfoLeaveNew, "");
540     ASSERT_TRUE(dragDropManager->preGridTargetFrameNode_);
541     auto preGridTargetNodeTag = dragDropManager->preGridTargetFrameNode_->GetTag();
542     EXPECT_EQ(preGridTargetNodeTag, LIST_TAG);
543 
544     /**
545      * @tc.steps: step7. call OnItemDragMove
546      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ is null
547      * @tc.expected: step7. frameNode's onDragItemEnter_ will be called
548      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
549      */
550     dragDropManager->onItemDragCancel();
551     EXPECT_FALSE(dragDropManager->preGridTargetFrameNode_);
552     itemInfoEnter = "";
553     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
554     EXPECT_EQ(itemInfoEnter, "");
555 }
556 
557 /**
558  * @tc.name: DragDropManagerTest011
559  * @tc.desc: Test OnItemDragEnd type is grid
560  * @tc.type: FUNC
561  * @tc.author:
562  */
563 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest011, TestSize.Level1)
564 {
565     /**
566      * @tc.steps: step1. construct a DragDropManager
567      */
568     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
569 
570     /**
571      * @tc.steps: step2. construct a frameNode which type is grid and set its GeometryNode
572      */
573     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
574     auto eventHub = frameNode->GetOrCreateEventHub<GridEventHub>();
575     ASSERT_TRUE(eventHub);
576 
577     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
578     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
579     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
580     geoNode->SetFrameSize(FRAME_SIZE);
581     frameNode->SetGeometryNode(geoNode);
582 
583     /**
584      * @tc.steps: step3. call OnItemDragEnd
585      *                   case: gridDragFrameNodes_ is empty
586      * @tc.expected: step3. preGridTargetFrameNode_ is null
587      */
588     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
589     auto preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
590     EXPECT_FALSE(preGridTargetFrameNode);
591 
592     // case: gridDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
593     auto preGridTargetNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
594     auto preGridEvent = preGridTargetNode->GetOrCreateEventHub<GridEventHub>();
595     std::string preGridDropInfo;
596     auto onPreGridItemDrop = [&preGridDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190902(const ItemDragInfo& , int32_t , int32_t , bool ) 597                                  int32_t /* insertIndex */, bool /* isSuccess */) { preGridDropInfo = EXTRA_INFO; };
598     preGridEvent->SetOnItemDrop(std::move(onPreGridItemDrop));
599     dragDropManager->preGridTargetFrameNode_ = preGridTargetNode;
600     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
601     EXPECT_EQ(preGridDropInfo, "");
602 
603     /**
604      * @tc.steps: step4. call AddDragFrameNode
605      *                   after that, gridDragFrameNodes_ is not empty
606      */
607     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
608 
609     /**
610      * @tc.steps: step5. call OnItemDragEnd
611      *                   case: eventHub dose not have onDrop_
612      * @tc.expected: step5. preGridTargetFrameNode_ is null
613      */
614     dragDropManager->preGridTargetFrameNode_ = nullptr;
615     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
616     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
617     EXPECT_FALSE(preGridTargetFrameNode);
618 
619     /**
620      * @tc.steps: step6. call OnItemDragEnd
621      *                   case: eventHub dose have onDrop_
622      * @tc.expected: step6. frameNode's OnDrop_ will be called
623      *                      itemDropInfo will be assigned to EXTRA_INFO
624      *                      preGridTargetFrameNode_ be assigned to nullptr
625      */
626     std::string itemDropInfo;
627     auto onItemDrop = [&itemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190a02(const ItemDragInfo& , int32_t , int32_t , bool ) 628                           int32_t /* insertIndex */, bool /* isSuccess */) { itemDropInfo = EXTRA_INFO; };
629     eventHub->SetOnItemDrop(onItemDrop);
630     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
631     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
632     EXPECT_FALSE(preGridTargetFrameNode);
633 
634     // case: preGridTargetFrameNode_ == dragFrameNode
635     dragDropManager->preGridTargetFrameNode_ = frameNode;
636     itemDropInfo.clear();
637     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
638 
639     // case: preGridTargetFrameNode_ != dragFrameNode
640     dragDropManager->preGridTargetFrameNode_ = preGridTargetNode;
641     itemDropInfo.clear();
642     preGridDropInfo.clear();
643     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
644     EXPECT_EQ(preGridDropInfo, "");
645 }
646 
647 /**
648  * @tc.name: DragDropManagerTest012
649  * @tc.desc: Test OnItemDragEnd type is list
650  * @tc.type: FUNC
651  * @tc.author:
652  */
653 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest012, TestSize.Level1)
654 {
655     /**
656      * @tc.steps: step1. construct a DragDropManager
657      */
658     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
659 
660     /**
661      * @tc.steps: step2. construct a frameNode which type is list and set its GeometryNode
662      */
663     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
664     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
665     ASSERT_TRUE(eventHub);
666 
667     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
668     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
669     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
670     geoNode->SetFrameSize(FRAME_SIZE);
671     frameNode->SetGeometryNode(geoNode);
672 
673     /**
674      * @tc.steps: step3. call OnItemDragEnd
675      *                   case: listDragFrameNodes_ is empty
676      * @tc.expected: step3. preGridTargetFrameNode_ is null
677      */
678     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
679     auto preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
680     EXPECT_FALSE(preGridTargetFrameNode);
681 
682     /**
683      * @tc.steps: step4. call AddDragFrameNode
684      *                   after that, listDragFrameNodes_ is not empty
685      */
686     dragDropManager->AddListDragFrameNode(frameNode->GetId(), frameNode);
687 
688     /**
689      * @tc.steps: step5. call OnItemDragEnd
690      * @tc.expected: step5. frameNode's OnDrop_ will be called
691      *                      itemDropInfo will be assigned to EXTRA_INFO
692      *                      preGridTargetFrameNode_ be assigned to nullptr
693      */
694     std::string itemDropInfo;
695     auto onItemDrop = [&itemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190b02(const ItemDragInfo& , int32_t , int32_t , bool ) 696                           int32_t /* insertIndex */, bool /* isSuccess */) { itemDropInfo = EXTRA_INFO; };
697     eventHub->SetOnItemDrop(onItemDrop);
698     dragDropManager->preGridTargetFrameNode_ = frameNode;
699     EXPECT_TRUE(dragDropManager->preGridTargetFrameNode_);
700     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
701     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
702     EXPECT_FALSE(preGridTargetFrameNode);
703 }
704 
705 /**
706  * @tc.name: DragDropManagerTest013
707  * @tc.desc: Test corner case
708  * @tc.type: FUNC
709  * @tc.author:
710  */
711 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest013, TestSize.Level1)
712 {
713     /**
714      * @tc.steps: step1. construct a DragDropManager
715      */
716     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
717 
718     /**
719      * @tc.steps: step2. call FindDragFrameNodeByPosition with frameNodes contains nullptr
720      * @tc.expected: step2.
721      */
722     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
723     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
724     frameNodeNull.Reset();
725     auto frameNodeGeoNullId = ElementRegister::GetInstance()->MakeUniqueId();
726     auto frameNodeGeoNull =
727         AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeGeoNullId, AceType::MakeRefPtr<Pattern>());
728     frameNodeGeoNull->SetGeometryNode(nullptr);
729     auto targetFrameNode = dragDropManager->FindDragFrameNodeByPosition(GLOBAL_X, GLOBAL_Y);
730     EXPECT_FALSE(targetFrameNode);
731 
732     /**
733      * @tc.steps: step3. call FireOnDragEvent with type=DragEventType::DROP
734      * @tc.expected: step3. FireOnDrop will be called
735      */
736     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
737     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
738     std::string onDropInfo;
__anonb7fa81190c02(const RefPtr<OHOS::Ace::DragEvent>& , const std::string& ) 739     auto onDrop = [&onDropInfo](const RefPtr<OHOS::Ace::DragEvent>& /* dragEvent */, const std::string& /* info */) {
740         onDropInfo = EXTRA_INFO;
741     };
742     eventHub->SetOnDrop(std::move(onDrop));
743     DragPointerEvent point;
744     TouchEvent event;
745     event.x = 1.0f;
746     event.y = 2.0f;
747     dragDropManager->velocityTracker_.UpdateTouchPoint(event, false);
748     dragDropManager->FireOnDragEvent(frameNode, point, DragEventType::DROP, EXTRA_INFO);
749     EXPECT_EQ(onDropInfo, EXTRA_INFO);
750 
751     /**
752      * @tc.steps: step4. call FireOnItemDropEvent with type=DragEventType::DROP
753      * @tc.expected: step4. FireOnItemDrop will be called
754      */
755     ItemDragInfo itemDragInfo;
756     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
757     auto gridEvent = gridNode->GetOrCreateEventHub<GridEventHub>();
758     std::string onItemDropInfo;
759     ItemDropFunc onItemDrop = [&onItemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81190d02(const ItemDragInfo& , int32_t , int32_t , bool ) 760                                   int32_t /* insertIndex */, bool /* isSuccess */) { onItemDropInfo = EXTRA_INFO; };
761     gridEvent->SetOnItemDrop(std::move(onItemDrop));
762     dragDropManager->FireOnItemDropEvent(gridNode, DragType::GRID, itemDragInfo, 0, 0, true);
763     EXPECT_EQ(onItemDropInfo, EXTRA_INFO);
764 
765     auto listNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
766     auto listEvent = listNode->GetOrCreateEventHub<ListEventHub>();
767     std::string onItemDropInfoList;
768     ItemDropFunc onItemDropList = [&onItemDropInfoList](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
769                                       int32_t /* insertIndex */,
__anonb7fa81190e02(const ItemDragInfo& , int32_t , int32_t , bool ) 770                                       bool /* isSuccess */) { onItemDropInfoList = EXTRA_INFO; };
771     listEvent->SetOnItemDrop(std::move(onItemDropList));
772     dragDropManager->FireOnItemDropEvent(listNode, DragType::LIST, itemDragInfo, 0, 0, true);
773     EXPECT_EQ(onItemDropInfoList, EXTRA_INFO);
774 }
775 
776 /**
777  * @tc.name: DragDropManagerTest014
778  * @tc.desc: Test OnTextDragEnd
779  * @tc.type: FUNC
780  * @tc.author:
781  */
782 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest014, TestSize.Level1)
783 {
784     /**
785      * @tc.steps: step1. Create DragDropManager.
786      * @tc.expected: dragDropManager is not null.
787      */
788     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
789     ASSERT_NE(dragDropManager, nullptr);
790 
791     /**
792      * @tc.steps: step2. call OnTextDragEnd.
793      * @tc.expected: dragDropManager->currentId_ equals -1.
794      */
795     float globalX = 20.0f;
796     float globalY = 20.0f;
797     std::string extraInfo;
798     dragDropManager->OnTextDragEnd(globalX, globalY, extraInfo);
799     EXPECT_EQ(dragDropManager->currentId_, -1);
800 
801     /**
802      * @tc.steps: step3. construct TextFrameNode.
803      * @tc.expected: frameNode is not null.
804      */
805     auto frameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<TextPattern>());
806     ASSERT_NE(frameNode, nullptr);
807 
808     /**
809      * @tc.steps: step4. updat edragDropManager->textFieldDragFrameNodes_ .
810      */
811     dragDropManager->textFieldDragFrameNodes_.insert(std::make_pair(100, WeakPtr<NG::FrameNode>(frameNode)));
812 
813     /**
814      * @tc.steps: step5. call OnTextDragEnd.
815      * @tc.expected: dragDropManager->currentId_ equals -1.
816      */
817     dragDropManager->OnTextDragEnd(globalX, globalY, extraInfo);
818     auto dragFrameNode = dragDropManager->FindDragFrameNodeByPosition(globalX, globalY);
819     EXPECT_EQ(dragDropManager->currentId_, -1);
820 }
821 
822 /**
823  * @tc.name: DragDropManagerTest015
824  * @tc.desc: Test RestoreClipboardData
825  * @tc.type: FUNC
826  * @tc.author:
827  */
828 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest015, TestSize.Level1)
829 {
830     /**
831      * @tc.steps: step1. Create DragDropManager.
832      * @tc.expected: dragDropManager is not null.
833      */
834     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
835     ASSERT_NE(dragDropManager, nullptr);
836 
837     /**
838      * @tc.steps: step2. call CancelItemDrag.
839      * @tc.expected: dragDropManager->deleteDataCallback_ is not null.
840      */
841     dragDropManager->RestoreClipboardData();
842     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
843 
844     /**
845      * @tc.steps: step3. call CancelItemDrag(clipboard_ is null branch).
846      * @tc.expected: step3. dragDropManager->deleteDataCallback_ is not null.
847      */
848     dragDropManager->clipboard_ = nullptr;
849     dragDropManager->RestoreClipboardData();
850     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
851 
852     /**
853      * @tc.steps: step4. call CancelItemDrag(deleteDataCallback_ is not null branch).
854      * @tc.expected: step4. dragDropManager->deleteDataCallback_ is not null.
855      */
__anonb7fa81190f02(const std::string& data) 856     auto callback = [weakManager = AceType::WeakClaim(AceType::RawPtr(dragDropManager))](const std::string& data) {
857         auto dragDropManagerPtr = weakManager.Upgrade();
858         ASSERT_NE(dragDropManagerPtr, nullptr);
859         auto json = JsonUtil::ParseJsonString(data);
860         if (json->Contains("preData")) {
861             dragDropManagerPtr->clipboard_->SetData(json->GetString("preData"));
862         }
863     };
864     dragDropManager->deleteDataCallback_ = callback;
865     dragDropManager->RestoreClipboardData();
866     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
867 }
868 
869 /**
870  * @tc.name: DragDropManagerTest017
871  * @tc.desc: Test UpdateDragEvent
872  * @tc.type: FUNC
873  * @tc.author:
874  */
875 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest017, TestSize.Level1)
876 {
877     /**
878      * @tc.steps: step1. Create DragDropManager.
879      * @tc.expected: dragDropManager is not null.
880      */
881     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
882     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
883     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, frameNode);
884     ASSERT_NE(dragDropManager, nullptr);
885 
886     /**
887      * @tc.steps: step2. construct a OHOS::Ace::DragEvent.
888      * @tc.expected: event is not null.
889      */
890     auto event = AceType::MakeRefPtr<OHOS::Ace::DragEvent>();
891     ASSERT_NE(event, nullptr);
892 
893     /**
894      * @tc.steps: step3. call UpdateDragEvent.
895      * @tc.expected: pipeline is not null.
896      */
897     dragDropManager->UpdateDragEvent(event, DragPointerEvent(1, 1));
898     auto pipeline = PipelineContext::GetCurrentContext();
899     ASSERT_NE(pipeline, nullptr);
900 }
901 
902 /**
903  * @tc.name: DragDropManagerTest021
904  * @tc.desc: Test CreateTextDragDropProxy
905  * @tc.type: FUNC
906  * @tc.author:
907  */
908 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest021, TestSize.Level1)
909 {
910     /**
911      * @tc.steps: step1. construct a DragDropManager
912      * @tc.expected: dragDropManager is not null.
913      */
914     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
915     ASSERT_NE(dragDropManager, nullptr);
916 
917     /**
918      * @tc.steps: step2. Call CreateTextDragDropProxy.
919      * @tc.expected: CreateTextDragDropProxy the returns true value is not null.
920      */
921     auto textDragDropProxy = dragDropManager->CreateTextDragDropProxy();
922     ASSERT_NE(textDragDropProxy, nullptr);
923 }
924 
925 /**
926  * @tc.name: DragDropManagerTest022
927  * @tc.desc: Test FindDragFrameNodeByPosition in default branches
928  * @tc.type: FUNC
929  * @tc.author:
930  */
931 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest022, TestSize.Level1)
932 {
933     /**
934      * @tc.steps: step1. construct a DragDropManager
935      */
936     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
937 
938     /**
939      * @tc.steps: step2. call FindDragFrameNodeByPosition with frameNodes contains nullptr
940      * @tc.expected: step2.
941      */
942     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
943     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
944     frameNodeNull.Reset();
945     auto frameNodeGeoNullId = ElementRegister::GetInstance()->MakeUniqueId();
946     auto frameNodeGeoNull =
947         AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeGeoNullId, AceType::MakeRefPtr<Pattern>());
948     frameNodeGeoNull->SetGeometryNode(nullptr);
949     auto targetFrameNode = dragDropManager->FindDragFrameNodeByPosition(GLOBAL_X, GLOBAL_Y);
950     EXPECT_FALSE(targetFrameNode);
951 }
952 
953 /**
954  * @tc.name: DragDropManagerTest023
955  * @tc.desc: Test OnDragStart(Point)
956  * @tc.type: FUNC
957  * @tc.author:
958  */
959 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest023, TestSize.Level1)
960 {
961     /**
962      * @tc.steps: step1. construct a DragDropManager
963      * @tc.expected: dragDropManager is not null.
964      */
965     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
966     ASSERT_NE(dragDropManager, nullptr);
967 
968     /**
969      * @tc.steps: step2. Call OnDragStart with Point.
970      * @tc.expected: dragDropManager->dragDropState_ is equal to DragDropMgrState::DRAGGING.
971      */
972     dragDropManager->OnDragStart(Point(15.0f, 15.0f));
973     EXPECT_EQ(dragDropManager->dragDropState_, DragDropMgrState::DRAGGING);
974 
975     /**
976      * @tc.steps: step3. Call OnDragStart with Point and FrameNode.
977      * @tc.expected: dragDropManager->dragDropState_ is equal to DragDropMgrState::DRAGGING.
978      */
979     RefPtr<FrameNode> frameNode = nullptr;
980     dragDropManager->OnDragStart(Point(15.0f, 15.0f), frameNode);
981     EXPECT_EQ(dragDropManager->dragDropState_, DragDropMgrState::DRAGGING);
982 }
983 
984 /**
985  * @tc.name: DragDropManagerTest024
986  * @tc.desc: Test ClearVelocityInfo
987  * @tc.type: FUNC
988  * @tc.author:
989  */
990 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest024, TestSize.Level1)
991 {
992     /**
993      * @tc.steps: step1. construct a DragDropManager
994      * @tc.expected: dragDropManager is not null.
995      */
996     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
997     ASSERT_NE(dragDropManager, nullptr);
998 
999     /**
1000      * @tc.steps: step2. Call ClearVelocityInfo.
1001      * @tc.expected: dragDropManager->velocityTracker_.isFirstPoint_ is equal to true.
1002      */
1003     dragDropManager->UpdateVelocityTrackerPoint(Point(15.0f, 15.0f), true);
1004     dragDropManager->ClearVelocityInfo();
1005     EXPECT_EQ(dragDropManager->velocityTracker_.isFirstPoint_, true);
1006 }
1007 
1008 /**
1009  * @tc.name: DragDropManagerTest025
1010  * @tc.desc: Test OnItemDragEnd out of eventHub is not an empty branche
1011  * @tc.type: FUNC
1012  * @tc.author:
1013  */
1014 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest025, TestSize.Level1)
1015 {
1016     /**
1017      * @tc.steps: step1. construct a DragDropManager.
1018      * @tc.expected: dragDropManager is not null.
1019      */
1020     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1021     ASSERT_NE(dragDropManager, nullptr);
1022 
1023     /**
1024      * @tc.steps: step2. construct a GridFrameNode.
1025      * @tc.expected: frameNode is not null.
1026      */
1027     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1028     ASSERT_TRUE(gridFrameNode);
1029 
1030     /**
1031      * @tc.steps: step3. Call OnItemDragEnd with DRAG_TYPE_GRID.
1032      * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1033      */
1034     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
1035     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
1036     EXPECT_FALSE(dragDropManager->draggedFrameNode_);
1037 
1038     /**
1039      * @tc.steps: step4. construct a ListFrameNode.
1040      * @tc.expected: frameNode is not null.
1041      */
1042     auto listFrameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
1043     ASSERT_TRUE(listFrameNode);
1044 
1045     /**
1046      * @tc.steps: step5. Call OnItemDragEnd with DRAG_TYPE_LIST.
1047      * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1048      */
1049     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, listFrameNode);
1050     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
1051     EXPECT_FALSE(dragDropManager->draggedFrameNode_);
1052 }
1053 
1054 /**
1055  * @tc.name: DragDropManagerTest026
1056  * @tc.desc: Test GetExtraInfo
1057  * @tc.type: FUNC
1058  * @tc.author:
1059  */
1060 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest026, TestSize.Level1)
1061 {
1062     /**
1063      * @tc.steps: step1. construct a DragDropManager
1064      * @tc.expected: dragDropManager is not null.
1065      */
1066     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1067     ASSERT_NE(dragDropManager, nullptr);
1068 
1069     /**
1070      * @tc.steps: step2. Call GetExtraInfo.
1071      * @tc.expected: extraInfo is empty.
1072      */
1073     auto extraInfo = dragDropManager->GetExtraInfo();
1074     EXPECT_TRUE(extraInfo.empty());
1075 }
1076 
1077 /**
1078  * @tc.name: DragDropManagerTest027
1079  * @tc.desc: Test SetExtraInfo
1080  * @tc.type: FUNC
1081  * @tc.author:
1082  */
1083 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest027, TestSize.Level1)
1084 {
1085     /**
1086      * @tc.steps: step1. construct a DragDropManager
1087      * @tc.expected: dragDropManager is not null.
1088      */
1089     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1090     ASSERT_NE(dragDropManager, nullptr);
1091 
1092     /**
1093      * @tc.steps: step2. Call SetExtraInfo.
1094      * @tc.expected: dragDropManager->extraInfo_ is equal to "extraInfo".
1095      */
1096     dragDropManager->SetExtraInfo("extraInfo");
1097     EXPECT_EQ(dragDropManager->extraInfo_, "extraInfo");
1098 }
1099 
1100 /**
1101  * @tc.name: DragDropManagerTest028
1102  * @tc.desc: Test ClearExtraInfo
1103  * @tc.type: FUNC
1104  * @tc.author:
1105  */
1106 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest028, TestSize.Level1)
1107 {
1108     /**
1109      * @tc.steps: step1. construct a DragDropManager
1110      * @tc.expected: dragDropManager is not null.
1111      */
1112     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1113     ASSERT_NE(dragDropManager, nullptr);
1114 
1115     /**
1116      * @tc.steps: step2. Call ClearExtraInfo.
1117      * @tc.expected: dragDropManager->extraInfo_ is empty.
1118      */
1119     dragDropManager->SetExtraInfo("extraInfo");
1120     dragDropManager->ClearExtraInfo();
1121     EXPECT_TRUE(dragDropManager->extraInfo_.empty());
1122 }
1123 
1124 /**
1125  * @tc.name: DragDropManagerTest029
1126  * @tc.desc: Test CancelItemDrag in draggedGridFrameNode branches
1127  * @tc.type: FUNC
1128  * @tc.author:
1129  */
1130 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest029, TestSize.Level1)
1131 {
1132     /**
1133      * @tc.steps: step1. Create DragDropManager.
1134      * @tc.expected: dragDropManager is not null.
1135      */
1136     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1137     ASSERT_NE(dragDropManager, nullptr);
1138 
1139     /**
1140      * @tc.steps: step2. call CancelItemDrag.
1141      * @tc.expected: dragDropManager->draggedGridFrameNode_ is false.
1142      */
1143     dragDropManager->CancelItemDrag();
1144     EXPECT_FALSE(dragDropManager->draggedGridFrameNode_);
1145 
1146     /**
1147      * @tc.steps: step3. Create FrameNode.
1148      * @tc.expected: frameNode is not null.
1149      */
1150     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1151     ASSERT_NE(frameNode, nullptr);
1152 
1153     /**
1154      * @tc.steps: step4. call CancelItemDrag.
1155      * @tc.expected: dragDropManager->draggedGridFrameNode_ is true.
1156      */
1157     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
1158     dragDropManager->CancelItemDrag();
1159     EXPECT_TRUE(dragDropManager->draggedGridFrameNode_);
1160 }
1161 
1162 /**
1163  * @tc.name: DragDropManagerTest0291
1164  * @tc.desc: Test CancelItemDrag in listEventHub branches
1165  * @tc.type: FUNC
1166  * @tc.author:
1167  */
1168 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0291, TestSize.Level1)
1169 {
1170     /**
1171      * @tc.steps: step1. Create DragDropManager.
1172      * @tc.expected: dragDropManager is not null.
1173      */
1174     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1175     ASSERT_NE(dragDropManager, nullptr);
1176 
1177     /**
1178      * @tc.steps: step2. Create FrameNode.
1179      * @tc.expected: listFrameNode is not null.
1180      */
1181     auto listFrameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
1182     ASSERT_NE(listFrameNode, nullptr);
1183 
1184     /**
1185      * @tc.steps: step3. update draggedGridFrameNode_ with listFrameNode.
1186      */
1187     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, listFrameNode);
1188 
1189     /**
1190      * @tc.steps: step4. call CancelItemDrag.
1191      * * @tc.expected: listEventHub is TRUE.
1192      */
1193     dragDropManager->CancelItemDrag();
1194     auto listEventHub = dragDropManager->draggedGridFrameNode_->GetOrCreateEventHub<ListEventHub>();
1195     EXPECT_TRUE(listEventHub);
1196 }
1197 
1198 /**
1199  * @tc.name: DragDropManagerTest0292
1200  * @tc.desc: Test CancelItemDrag in gridEventHub branches
1201  * @tc.type: FUNC
1202  * @tc.author:
1203  */
1204 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0292, TestSize.Level1)
1205 {
1206     /**
1207      * @tc.steps: step1. Create DragDropManager.
1208      * @tc.expected: dragDropManager is not null.
1209      */
1210     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1211     ASSERT_NE(dragDropManager, nullptr);
1212 
1213     /**
1214      * @tc.steps: step2. Create FrameNode.
1215      * @tc.expected: gridFrameNode is not null.
1216      */
1217     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1218     ASSERT_NE(gridFrameNode, nullptr);
1219 
1220     /**
1221      * @tc.steps: step3. update draggedGridFrameNode_ with gridFrameNode.
1222      */
1223     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
1224 
1225     /**
1226      * @tc.steps: step4. call CancelItemDrag.
1227      * * @tc.expected: gridEventHub is TRUE.
1228      */
1229     dragDropManager->CancelItemDrag();
1230     auto gridEventHub = dragDropManager->draggedGridFrameNode_->GetOrCreateEventHub<GridEventHub>();
1231     EXPECT_TRUE(gridEventHub);
1232 }
1233 
1234 /**
1235  * @tc.name: DragDropManagerTest030
1236  * @tc.desc: Test FireOnItemDragEvent in DragType::GRID branches
1237  * @tc.type: FUNC
1238  * @tc.author:
1239  */
1240 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest030, TestSize.Level1)
1241 {
1242     /**
1243      * @tc.steps: step1. Create DragDropManager.
1244      * @tc.expected: dragDropManager is not null.
1245      */
1246     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1247     ASSERT_NE(dragDropManager, nullptr);
1248 
1249     /**
1250      * @tc.steps: step2. Create FrameNode.
1251      * @tc.expected: gridFrameNode is not null.
1252      */
1253     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1254     ASSERT_NE(gridFrameNode, nullptr);
1255 
1256     /**
1257      * @tc.steps: step3. call FireOnItemDragEvent with DragEventType::ENTER.
1258      * * @tc.expected: eventHub is TRUE.
1259      */
1260     OHOS::Ace::ItemDragInfo itemDragInfo;
1261     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType::ENTER, 0, 0);
1262     auto eventHub = gridFrameNode->GetOrCreateEventHub<GridEventHub>();
1263     EXPECT_TRUE(eventHub);
1264 
1265     /**
1266      * @tc.steps: step4. call FireOnItemDragEvent with DragEventType::MOVE.
1267      * * @tc.expected: eventHub is TRUE.
1268      */
1269     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType::MOVE, 0, 0);
1270     EXPECT_TRUE(eventHub);
1271 
1272     /**
1273      * @tc.steps: step5. call FireOnItemDragEvent with DragEventType::default.
1274      * * @tc.expected: eventHub is TRUE.
1275      */
1276     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType(10), 0, 0);
1277     EXPECT_TRUE(eventHub);
1278 }
1279 
1280 /**
1281  * @tc.name: DragDropManagerTest031
1282  * @tc.desc: Test FindTargetInChildNodes is an empty branch of parentNode
1283  * @tc.type: FUNC
1284  * @tc.author:
1285  */
1286 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest031, TestSize.Level1)
1287 {
1288     /**
1289      * @tc.steps: step1. Create DragDropManager.
1290      * @tc.expected: dragDropManager is not null.
1291      */
1292     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1293     ASSERT_NE(dragDropManager, nullptr);
1294 
1295     /**
1296      * @tc.steps: step2. call FindTargetInChildNodes(parentNode is empty).
1297      * @tc.expected: childFindResult is false.
1298      */
1299     RefPtr<UINode> customNode = nullptr;
1300     std::vector<RefPtr<FrameNode>> hitFrameNodes;
1301     auto childFindResult = dragDropManager->FindTargetInChildNodes(customNode, hitFrameNodes, true);
1302     EXPECT_FALSE(childFindResult);
1303 }
1304 
1305 /**
1306  * @tc.name: DragDropManagerTest033
1307  * @tc.desc: Test FindTargetInChildNodes
1308  * @tc.type: FUNC
1309  * @tc.author:
1310  */
1311 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest033, TestSize.Level1)
1312 {
1313     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1314     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1315     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1316     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1317     geometryNode->SetFrameSize(FRAME_SIZE);
1318     frameNodeNull->SetGeometryNode(geometryNode);
1319     auto pipelineTmp = NG::PipelineContext::GetCurrentContext();
1320     auto parentNodeTmp = pipelineTmp->GetRootElement();
1321     auto parentFrameNodeTmp = AceType::DynamicCast<FrameNode>(parentNodeTmp);
1322     parentFrameNodeTmp->frameChildren_.insert(WeakPtr<NG::FrameNode>(frameNodeNull));
1323     dragDropManager->AddGridDragFrameNode(frameNodeNull->GetId(), frameNodeNull);
1324     std::map<int32_t, WeakPtr<FrameNode>> frameNodes = dragDropManager->gridDragFrameNodes_;
1325     PointF point(GLOBAL_X, GLOBAL_Y);
1326     std::vector<RefPtr<FrameNode>> hitFrameNodes;
1327     for (auto iterOfFrameNode = frameNodes.begin(); iterOfFrameNode != frameNodes.end(); iterOfFrameNode++) {
1328         auto frameNode = iterOfFrameNode->second.Upgrade();
1329         auto geometryNode = frameNode->GetGeometryNode();
1330         if (!geometryNode) {
1331             continue;
1332         }
1333         auto globalFrameRect = geometryNode->GetFrameRect();
1334         globalFrameRect.SetOffset(frameNode->GetTransformRelativeOffset());
1335         if (globalFrameRect.IsInRegion(point)) {
1336             hitFrameNodes.push_back(frameNode);
1337         }
1338     }
1339     auto pipeline = NG::PipelineContext::GetCurrentContext();
1340     auto manager = pipeline->GetOverlayManager();
1341     auto parentNode = pipeline->GetRootElement();
1342     auto parentFrameNode = AceType::DynamicCast<FrameNode>(parentNode);
1343     auto children = parentFrameNode->GetFrameChildren();
1344     EXPECT_FALSE(children.empty());
1345     for (auto iter = children.rbegin(); iter != children.rend(); iter++) {
1346         auto child = iter->Upgrade();
1347         if (child == nullptr) {
1348             continue;
1349         }
1350         auto childNode = AceType::DynamicCast<UINode>(child);
1351         auto childFindResult = dragDropManager->FindTargetInChildNodes(childNode, hitFrameNodes, true);
1352         EXPECT_FALSE(childFindResult);
1353     }
1354     for (auto iter : hitFrameNodes) {
1355         EXPECT_NE(parentFrameNode, iter);
1356     }
1357     auto result = dragDropManager->FindTargetInChildNodes(parentNode, hitFrameNodes, true);
1358     EXPECT_FALSE(result);
1359 }
1360 
1361 /**
1362  * @tc.name: DragDropManagerTest034
1363  * @tc.desc: Test PrintDragFrameNode.
1364  * @tc.type: FUNC
1365  * @tc.author:
1366  */
1367 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest034, TestSize.Level1)
1368 {
1369     /**
1370      * @tc.steps: step1. construct a DragDropManager
1371      * @tc.expected: dragDropManager is not null.
1372      */
1373     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1374     ASSERT_NE(dragDropManager, nullptr);
1375 
1376     OHOS::Ace::DragPointerEvent point;
1377     RefPtr<FrameNode> dragFrameNode = nullptr;
1378     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, dragFrameNode);
1379 
1380     /**
1381      * @tc.steps: step2. call PrintDragFrameNode with dragFrameNode and point.
1382      * * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1383      */
1384     dragDropManager->PrintDragFrameNode(point, dragFrameNode);
1385     ASSERT_FALSE(dragDropManager->draggedFrameNode_);
1386 }
1387 
1388 /**
1389  * @tc.name: DragDropManagerTest035
1390  * @tc.desc: Test FireOnItemDropEvent is empty branchs.
1391  * @tc.type: FUNC
1392  * @tc.author:
1393  */
1394 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest035, TestSize.Level1)
1395 {
1396     /**
1397      * @tc.steps: step1. construct a DragDropManager.
1398      * @tc.expected: dragDropManager is not null.
1399      */
1400     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1401     ASSERT_NE(dragDropManager, nullptr);
1402 
1403     /**
1404      * @tc.steps: step1. construct a DragDropManager.
1405      * @tc.expected: step2. FireOnItemDropEvent.
1406      */
1407     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1408     auto draggedNode = dragDropManager->draggedFrameNode_;
1409     auto preTargetNode = dragDropManager->preTargetFrameNode_;
1410     OHOS::Ace::ItemDragInfo itemDragInfo;
1411 
1412     /**
1413      * @tc.steps: step2. call OnDragStart with DragType::GRID and frameNode.
1414      * @tc.expected: step2. draggedNode is false.
1415      */
1416     dragDropManager->FireOnItemDropEvent(frameNode, DragType::GRID, itemDragInfo, 0, 0, true);
1417     ASSERT_FALSE(draggedNode);
1418 
1419     /**
1420      * @tc.steps: step2. call OnDragStart with DragType::LIST and frameNode.
1421      * @tc.expected: step2. raggedNode is false.
1422      */
1423     dragDropManager->FireOnItemDropEvent(frameNode, DragType::LIST, itemDragInfo, 0, 0, true);
1424     ASSERT_FALSE(draggedNode);
1425 }
1426 
1427 /**
1428  * @tc.name: DragDropManagerTest037
1429  * @tc.desc: Test GetItemIndex out of eventHub->CheckPostionInGrid is a true branch.
1430  * @tc.type: FUNC
1431  * @tc.author:
1432  */
1433 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest037, TestSize.Level1)
1434 {
1435     /**
1436      * @tc.steps: step1. construct a DragDropManager.
1437      * @tc.expected: dragDropManager is not null.
1438      */
1439     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1440     ASSERT_NE(dragDropManager, nullptr);
1441 
1442     /**
1443      * @tc.steps: step2. construct a GeometryNode,updates MarginFrameOffset and FrameSize.
1444      * @tc.expected: geometryNode is not null.
1445      */
1446     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1447     ASSERT_NE(geometryNode, nullptr);
1448     geometryNode->SetMarginFrameOffset(FRAME_OFFSET);
1449     geometryNode->SetFrameSize(FRAME_SIZE);
1450 
1451     /**
1452      * @tc.steps: step3. construct a FrameNode with GeometryNode.
1453      * @tc.expected: gridNode is not null.
1454      */
1455     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1456     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1457     ASSERT_NE(dragDropManager, nullptr);
1458     gridNode->SetGeometryNode(geometryNode);
1459 
1460     /**
1461      * @tc.steps: step4. construct a GridEventHub and updates OnItemDrop and AttachHost.
1462      */
1463     ItemDragInfo itemDragInfo;
1464     auto gridEvent = gridNode->GetOrCreateEventHub<GridEventHub>();
1465     std::string onItemDropInfo;
1466     ItemDropFunc onItemDrop = [&onItemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anonb7fa81191002(const ItemDragInfo& , int32_t , int32_t , bool ) 1467                                   int32_t /* insertIndex */, bool /* isSuccess */) { onItemDropInfo = EXTRA_INFO; };
1468     gridEvent->SetOnItemDrop(std::move(onItemDrop));
1469     gridEvent->AttachHost(WeakPtr<NG::FrameNode>(gridNode));
1470 
1471     /**
1472      * @tc.steps: step5. call GetItemIndex with DragEventType::GRID and gridNode.
1473      * @tc.expected: retFlag is true.
1474      */
1475     dragDropManager->draggedGridFrameNode_ = gridNode;
1476     dragDropManager->GetItemIndex(gridNode, DragType::GRID, 0, 0);
1477     auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
1478     ASSERT_NE(mockRenderContext, nullptr);
1479     gridNode->renderContext_ = mockRenderContext;
1480     mockRenderContext->rect_ = { 0.0f, 0.0f, 1.0f, 1.0f };
1481     bool retFlag = gridEvent->CheckPostionInGrid(0, 0);
1482     EXPECT_TRUE(retFlag);
1483 }
1484 
1485 /**
1486  * @tc.name: DragDropManagerTest038
1487  * @tc.desc: Test GetItemIndex out of itemFrameNode is a true branch.
1488  * @tc.type: FUNC
1489  * @tc.author:
1490  */
1491 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest038, TestSize.Level1)
1492 {
1493     /**
1494      * @tc.steps: step1. construct a DragDropManager.
1495      * @tc.expected: dragDropManager is not null.
1496      */
1497     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1498     ASSERT_NE(dragDropManager, nullptr);
1499 
1500     /**
1501      * @tc.steps: step2. construct a GeometryNode,updates MarginFrameOffset and FrameSize.
1502      * @tc.expected: geometryNode is not null.
1503      */
1504     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1505     ASSERT_NE(geometryNode, nullptr);
1506     geometryNode->SetMarginFrameOffset(FRAME_OFFSET);
1507     geometryNode->SetFrameSize(FRAME_SIZE);
1508 
1509     /**
1510      * @tc.steps: step3. construct a FrameNode with GeometryNode.
1511      * @tc.expected: gridNode is not null.
1512      */
1513     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1514     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1515     ASSERT_NE(gridNode, nullptr);
1516     gridNode->SetGeometryNode(geometryNode);
1517 
1518     /**
1519      * @tc.steps: step4. construct a FrameNode.
1520      */
1521     auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1522     auto childNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, childId, AceType::MakeRefPtr<Pattern>());
1523     childNode->SetGeometryNode(geometryNode);
1524     childNode->isActive_ = true;
1525 
1526     /**
1527      * @tc.steps: step5. gridNode AddChild with childNode.
1528      */
1529     gridNode->AddChild(childNode);
1530 
1531     /**
1532      * @tc.steps: step6. call GetItemIndex with DragEventType::GRID and gridNode.
1533      * @tc.expected: retFlag is true.
1534      */
1535     dragDropManager->draggedGridFrameNode_ = gridNode;
1536     dragDropManager->GetItemIndex(gridNode, DragType::GRID, 0, 0);
1537     bool retFlag = gridNode->FindChildByPosition(0, 0);
1538     EXPECT_TRUE(retFlag);
1539 }
1540 
1541 /**
1542  * @tc.name: DragDropManagerTest039
1543  * @tc.desc: Test CheckParentVisible out of parent is a true branch.
1544  * @tc.type: FUNC
1545  * @tc.author:
1546  */
1547 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest039, TestSize.Level1)
1548 {
1549     /**
1550      * @tc.steps: step1. construct a DragDropManager.
1551      * @tc.expected: dragDropManager is not null.
1552      */
1553     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1554     ASSERT_NE(dragDropManager, nullptr);
1555 
1556     /**
1557      * @tc.steps: step2. construct a frameNode and update attributes.
1558      * IsVisible is false branch
1559      */
1560     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1561     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1562     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1563     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
1564     eventHub->SetEnabled(true);
1565 
1566     /**
1567      * @tc.steps: step3. update nodesForDragNotify_.
1568      * @tc.expected: nodesForDragNotify_ is not empty.
1569      */
1570     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1571     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1572 
1573     /**
1574      * @tc.steps: step4. update NotifyDragEvent.
1575      * @tc.expected: notifyEvent attributes to be the set value.
1576      */
1577     RefPtr<NotifyDragEvent> notifyEvent = AceType::MakeRefPtr<NotifyDragEvent>();
1578     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1579     EXPECT_DOUBLE_EQ(notifyEvent->GetX(), 1.0);
1580     EXPECT_DOUBLE_EQ(notifyEvent->GetY(), 1.0);
1581 
1582     /**
1583      * @tc.steps: step5. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of isVisible.
1584      * @tc.expected: isVisible is false.
1585      */
1586     dragDropManager->NotifyDragRegisterFrameNode(
1587         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1588     bool isVisible = frameNode->IsVisible();
1589     EXPECT_FALSE(isVisible);
1590 
1591     /**
1592      * @tc.steps: step6. update nodesForDragNotify_.
1593      * @tc.expected: nodesForDragNotify_ is not empty.
1594      */
1595     dragDropManager->UnRegisterDragStatusListener(frameNode->GetId());
1596     EXPECT_TRUE(dragDropManager->nodesForDragNotify_.empty());
1597     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1598     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1599 
1600     /**
1601      * @tc.steps: step7. update frameNode attribute.
1602      * @tc.expected: parent is not null.
1603      */
1604     auto customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1605     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::VISIBLE, true);
1606     frameNode->SetParent(WeakPtr<NG::UINode>(customNode));
1607     auto parent = frameNode->GetParent();
1608     EXPECT_TRUE(parent);
1609     parent->SetDepth(32);
1610     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1611 
1612     /**
1613      * @tc.steps: step8. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of parentFrameNode.
1614      * @tc.expected: parent->GetDepth() returns a value that is not equal to 1.
1615      */
1616     dragDropManager->NotifyDragRegisterFrameNode(
1617         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1618     EXPECT_NE(parent->GetDepth(), 1);
1619 }
1620 
1621 /**
1622  * @tc.name: DragDropManagerTest0391
1623  * @tc.desc: Test CheckParentVisible out of parentFrameNode  is a true branch.
1624  * @tc.type: FUNC
1625  * @tc.author:
1626  */
1627 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0391, TestSize.Level1)
1628 {
1629     /**
1630      * @tc.steps: step1. construct a DragDropManager.
1631      * @tc.expected: dragDropManager is not null.
1632      */
1633     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1634     ASSERT_NE(dragDropManager, nullptr);
1635 
1636     /**
1637      * @tc.steps: step2. construct a frameNode and update attributes.
1638      * IsVisible is false branch
1639      */
1640     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1641     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1642     auto customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1643     customNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1644     frameNode->SetParent(WeakPtr<NG::UINode>(customNode));
1645     auto parent = frameNode->GetParent();
1646     EXPECT_TRUE(parent);
1647     parent->SetDepth(32);
1648     EXPECT_NE(parent->GetDepth(), 1);
1649 
1650     /**
1651      * @tc.steps: step4. update nodesForDragNotify_ and NotifyDragEvent.
1652      * @tc.expected: nodesForDragNotify_ is not empty.
1653      */
1654     RefPtr<NotifyDragEvent> notifyEvent = AceType::MakeRefPtr<NotifyDragEvent>();
1655     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1656     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1657     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1658 
1659     /**
1660      * @tc.steps: step5. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of parentFrameNode(is
1661      * false).
1662      * @tc.expected: customNode->IsVisible() returns a value that is not equal to false.
1663      */
1664     dragDropManager->NotifyDragRegisterFrameNode(
1665         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1666     EXPECT_FALSE(customNode->IsVisible());
1667 }
1668 
1669 /**
1670  * @tc.name: DragDropManagerTest040
1671  * @tc.desc: Test FindHitFrameNodes in frameNode branchs
1672  * @tc.type: FUNC
1673  * @tc.author:
1674  */
1675 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest040, TestSize.Level1)
1676 {
1677     /**
1678      * @tc.steps: step1. construct a DragDropManager.
1679      * @tc.expected: dragDropManager is not null.
1680      */
1681     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1682     ASSERT_NE(dragDropManager, nullptr);
1683 
1684     /**
1685      * @tc.steps: step2. construct a frameNode and update attributes.
1686      * @tc.expected: geometryNode is null.
1687      */
1688     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1689     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1690     frameNode->SetActive(true);
1691     frameNode->geometryNode_ = nullptr;
1692     auto geometryNode = frameNode->GetGeometryNode();
1693     EXPECT_FALSE(geometryNode);
1694 
1695     /**
1696      * @tc.steps: step3. update nodesForDragNotify_.
1697      * @tc.expected: nodesForDragNotify_ is not empty.
1698      */
1699     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1700     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1701 
1702     /**
1703      * @tc.steps: step4. call FindHitFrameNodes out of geometryNode are false branches.
1704      * @tc.expected: frameNodeList is empty.
1705      */
1706     auto frameNodeList = dragDropManager->FindHitFrameNodes(Point(1.0f, 1.0f));
1707     EXPECT_TRUE(frameNodeList.empty());
1708 
1709     /**
1710      * @tc.steps: step5. clear nodesForDragNotify_.
1711      */
1712     dragDropManager->UnRegisterDragStatusListener(frameNode->GetId());
1713     EXPECT_TRUE(dragDropManager->nodesForDragNotify_.empty());
1714 
1715     /**
1716      * @tc.steps: step6. updates frameNode and nodesForDragNotify_.
1717      */
1718     frameNode->SetActive(false);
1719     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1720     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1721 
1722     /**
1723      * @tc.steps: step7. call FindHitFrameNodes out of IsVisible are false branches.
1724      * @tc.expected: frameNodeList is empty.
1725      */
1726     frameNodeList = dragDropManager->FindHitFrameNodes(Point(1.0f, 1.0f));
1727     EXPECT_TRUE(frameNodeList.empty());
1728 }
1729 
1730 /**
1731  * @tc.name: DragDropManagerTest041
1732  * @tc.desc: Test SetDragDampStartPoint and GetDragDampStartPoint
1733  * @tc.type: FUNC
1734  * @tc.author:
1735  */
1736 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest041, TestSize.Level1)
1737 {
1738     /**
1739      * @tc.steps: step1. construct a DragDropManager.
1740      * @tc.expected: dragDropManager is not null.
1741      */
1742     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1743     ASSERT_NE(dragDropManager, nullptr);
1744 
1745     /**
1746      * @tc.steps: step2. create a point, than call SetDragDampStartPoint.
1747      * @tc.expected: The values of dragDampStartPoint_ and point are equal
1748      */
1749     Point point(1.0f, 1.0f);
1750     dragDropManager->SetDragDampStartPoint(point);
1751     EXPECT_EQ(dragDropManager->dragDampStartPoint_, point);
1752 
1753     /**
1754      * @tc.steps: step3. create a point, than call GetDragDampStartPoint.
1755      * @tc.expected: The return values of dragDampStartPoint_ and point are equal
1756      */
1757     Point point2(2.0f, 2.0f);
1758     dragDropManager->dragDampStartPoint_ = point2;
1759     auto returnPoint = dragDropManager->GetDragDampStartPoint();
1760     EXPECT_EQ(returnPoint, point2);
1761 }
1762 
1763 /**
1764  * @tc.name: DragDropManagerTest042
1765  * @tc.desc: ResetPreTargetFrameNode
1766  * @tc.type: FUNC
1767  * @tc.author:
1768  */
1769 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest042, TestSize.Level1)
1770 {
1771     /**
1772      * @tc.steps: step1. construct a DragDropManager.
1773      * @tc.expected: dragDropManager is not null.
1774      */
1775     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1776     ASSERT_NE(dragDropManager, nullptr);
1777 
1778     /**
1779      * @tc.steps: step2. create a frameNode, then set preTargetFrameNode_.
1780      * @tc.expected: The values of preTargetFrameNode_ and frameNode are equal
1781      */
1782     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1783     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1784     ASSERT_NE(frameNode, nullptr);
1785 
1786     dragDropManager->preTargetFrameNode_ = frameNode;
1787     ASSERT_EQ(dragDropManager->preTargetFrameNode_, frameNode);
1788     auto container = MockContainer::Current();
1789     ASSERT_NE(container, nullptr);
1790     auto instanceId = container->GetInstanceId();
1791     /**
1792      * @tc.steps: step3. call ResetPreTargetFrameNode in SceneBoardWindow.
1793      * @tc.expected: The value of preTargetFrameNode_ is frameNode
1794      */
1795     container->isUIExtensionWindow_ = false;
1796     container->isSceneBoardWindow_ = true;
1797     dragDropManager->ResetPreTargetFrameNode(instanceId);
1798     EXPECT_EQ(dragDropManager->preTargetFrameNode_, frameNode);
1799 
1800     /**
1801      * @tc.steps: step4. call ResetPreTargetFrameNode in UIExtensionWindow.
1802      * @tc.expected: The value of preTargetFrameNode_ is frameNode
1803      */
1804     container->isUIExtensionWindow_ = true;
1805     container->isSceneBoardWindow_ = false;
1806     dragDropManager->ResetPreTargetFrameNode(instanceId);
1807     EXPECT_EQ(dragDropManager->preTargetFrameNode_, frameNode);
1808 
1809     /**
1810      * @tc.steps: step5. call ResetPreTargetFrameNode.
1811      * @tc.expected: The value of preTargetFrameNode_ is nullptr
1812      */
1813     container->isUIExtensionWindow_ = false;
1814     container->isSceneBoardWindow_ = false;
1815     dragDropManager->ResetPreTargetFrameNode(instanceId);
1816     EXPECT_EQ(dragDropManager->preTargetFrameNode_, nullptr);
1817 }
1818 
1819 /**
1820  * @tc.name: CheckIsFolderSubwindowBoundary001
1821  * @tc.desc: ResetPreTargetFrameNode
1822  * @tc.type: FUNC
1823  * @tc.author:
1824  */
1825 HWTEST_F(DragDropManagerTestNg, CheckIsFolderSubwindowBoundary001, TestSize.Level1)
1826 {
1827     /**
1828      * @tc.steps: step1. construct a DragDropManager.
1829      * @tc.expected: dragDropManager is not null.
1830      */
1831     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1832     ASSERT_NE(dragDropManager, nullptr);
1833     bool result = dragDropManager->CheckIsFolderSubwindowBoundary(0.0f, 0.0f, 0);
1834     EXPECT_EQ(result, false);
1835 }
1836 
1837 /**
1838  * @tc.name: HandleUIExtensionDragEvent001
1839  * @tc.desc: ResetPreTargetFrameNode
1840  * @tc.type: FUNC
1841  * @tc.author:
1842  */
1843 HWTEST_F(DragDropManagerTestNg, HandleUIExtensionDragEvent001, TestSize.Level1)
1844 {
1845     /**
1846      * @tc.steps: step1. construct a DragDropManager.
1847      * @tc.expected: dragDropManager is not null.
1848      */
1849     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1850     ASSERT_NE(dragDropManager, nullptr);
1851     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1852     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1853     DragPointerEvent pointerEvent;
1854     DragEventType type = DragEventType::ENTER;
1855     dragDropManager->HandleUIExtensionDragEvent(frameNode, pointerEvent, type);
1856     EXPECT_NE(pointerEvent.action, PointerAction::PULL_IN_WINDOW);
1857 }
1858 
1859 /**
1860  * @tc.name: HandleUIExtensionDragEvent002
1861  * @tc.desc: ResetPreTargetFrameNode
1862  * @tc.type: FUNC
1863  * @tc.author:
1864  */
1865 HWTEST_F(DragDropManagerTestNg, HandleUIExtensionDragEvent002, TestSize.Level1)
1866 {
1867     /**
1868      * @tc.steps: step1. construct a DragDropManager.
1869      * @tc.expected: dragDropManager is not null.
1870      */
1871     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1872     ASSERT_NE(dragDropManager, nullptr);
1873     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1874     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1875     DragPointerEvent pointerEvent;
1876     DragEventType type = DragEventType::LEAVE;
1877     dragDropManager->HandleUIExtensionDragEvent(frameNode, pointerEvent, type);
1878     EXPECT_NE(pointerEvent.action, PointerAction::PULL_OUT_WINDOW);
1879 }
1880 
1881 /**
1882  * @tc.name: HandleUIExtensionDragEvent003
1883  * @tc.desc: ResetPreTargetFrameNode
1884  * @tc.type: FUNC
1885  * @tc.author:
1886  */
1887 HWTEST_F(DragDropManagerTestNg, HandleUIExtensionDragEvent003, TestSize.Level1)
1888 {
1889     /**
1890      * @tc.steps: step1. construct a DragDropManager.
1891      * @tc.expected: dragDropManager is not null.
1892      */
1893     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1894     ASSERT_NE(dragDropManager, nullptr);
1895     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1896     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1897     DragPointerEvent pointerEvent;
1898     DragEventType type =  DragEventType::PULL_CANCEL;
1899     dragDropManager->HandleUIExtensionDragEvent(frameNode, pointerEvent, type);
1900     EXPECT_NE(pointerEvent.action, PointerAction::PULL_CANCEL);
1901 }
1902 
1903 /**
1904  * @tc.name: CalculateScale001
1905  * @tc.desc: ResetPreTargetFrameNode
1906  * @tc.type: FUNC
1907  * @tc.author:
1908  */
1909 HWTEST_F(DragDropManagerTestNg, CalculateScale001, TestSize.Level1)
1910 {
1911     /**
1912      * @tc.steps: step1. construct a DragDropManager.
1913      * @tc.expected: dragDropManager is not null.
1914      */
1915     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1916     ASSERT_NE(dragDropManager, nullptr);
1917     float with = 100.0f;
1918     float height = 100.0f;
1919     float widthLimit = 50.0f;
1920     float heightLimit = 50.0f;
1921     auto scaleDataInfo = dragDropManager->CalculateScale(with, height, widthLimit, heightLimit);
1922     EXPECT_EQ(scaleDataInfo->isNeedScale, true);
1923 
1924     with = 100.0f;
1925     height = 50.0f;
1926     widthLimit = 50.0f;
1927     heightLimit = 50.0f;
1928     scaleDataInfo = dragDropManager->CalculateScale(with, height, widthLimit, heightLimit);
1929     EXPECT_EQ(scaleDataInfo->isNeedScale, true);
1930 
1931     with = 0.0f;
1932     height = 50.0f;
1933     widthLimit = 50.0f;
1934     heightLimit = 50.0f;
1935     scaleDataInfo = dragDropManager->CalculateScale(with, height, widthLimit, heightLimit);
1936     EXPECT_EQ(scaleDataInfo->isNeedScale, false);
1937 
1938     with = 50.0f;
1939     height = 0.0f;
1940     widthLimit = 50.0f;
1941     heightLimit = 50.0f;
1942     scaleDataInfo = dragDropManager->CalculateScale(with, height, widthLimit, heightLimit);
1943     EXPECT_EQ(scaleDataInfo->isNeedScale, false);
1944 }
1945 
1946 /**
1947  * @tc.name: UnRegisterPullEventListener001
1948  * @tc.desc: ResetPreTargetFrameNode
1949  * @tc.type: FUNC
1950  */
1951 HWTEST_F(DragDropManagerTestNg, UnRegisterPullEventListener001, TestSize.Level1)
1952 {
1953     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1954     ASSERT_NE(dragDropManager, nullptr);
1955 
1956     const int32_t EXISTING_ID = 100;
__anonb7fa81191102(const DragPointerEvent&) 1957     auto testListener = [](const DragPointerEvent&) {};
1958     dragDropManager->pullEventListener_.emplace(EXISTING_ID, testListener);
1959     ASSERT_EQ(dragDropManager->pullEventListener_.size(), 1);
1960 
1961     dragDropManager->UnRegisterPullEventListener(EXISTING_ID);
1962     EXPECT_EQ(dragDropManager->pullEventListener_.size(), 0);
1963 }
1964 
1965 /**
1966  * @tc.name: IsAnyDraggableHit001
1967  * @tc.desc: ResetPreTargetFrameNode
1968  * @tc.type: FUNC
1969  */
1970 HWTEST_F(DragDropManagerTestNg, IsAnyDraggableHit001, TestSize.Level1)
1971 {
1972     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1973     ASSERT_NE(dragDropManager, nullptr);
1974     RefPtr<PipelineBase> pipeline = NG::MockPipelineContext::pipeline_;
1975     int32_t pointId = 100;
1976     dragDropManager->IsAnyDraggableHit(pipeline, pointId);
1977     EXPECT_EQ(dragDropManager->isAnyDraggableHit_, false);
1978 
1979     dragDropManager->isAnyDraggableHit_ = true;
1980     dragDropManager->IsAnyDraggableHit(pipeline, pointId);
1981     EXPECT_EQ(dragDropManager->isAnyDraggableHit_, true);
1982 }
1983 
1984 /**
1985  * @tc.name: IsAnyDraggableHit002
1986  * @tc.desc: ResetPreTargetFrameNode
1987  * @tc.type: FUNC 245
1988  */
1989 HWTEST_F(DragDropManagerTestNg, IsAnyDraggableHit002, TestSize.Level1)
1990 {
1991     auto clickRecognizer = AceType::MakeRefPtr<ClickRecognizer>();
1992     clickRecognizer->OnRejected();
1993     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1994     ASSERT_NE(dragDropManager, nullptr);
1995     TouchTestResult touchTestResults = { clickRecognizer };
1996     RefPtr<PipelineBase> pipeline = NG::MockPipelineContext::pipeline_;
1997     pipeline->SetEventManager(AceType::MakeRefPtr<EventManager>());
1998     pipeline->eventManager_->touchTestResults_[100] = touchTestResults;
1999     int32_t pointId = 100;
2000     dragDropManager->IsAnyDraggableHit(pipeline, pointId);
2001     EXPECT_EQ(dragDropManager->isAnyDraggableHit_, false);
2002 }
2003 
2004 /**
2005  * @tc.name: IsAnyDraggableHit003
2006  * @tc.desc: ResetPreTargetFrameNode
2007  * @tc.type: FUNC
2008  */
2009 HWTEST_F(DragDropManagerTestNg, IsAnyDraggableHit003, TestSize.Level1)
2010 {
2011     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2012     ASSERT_NE(dragDropManager, nullptr);
2013     TouchTestResult touchTestResults;
2014     RefPtr<PipelineBase> pipeline = NG::MockPipelineContext::pipeline_;
2015     pipeline->SetEventManager(AceType::MakeRefPtr<EventManager>());
2016     pipeline->eventManager_->touchTestResults_[100] = touchTestResults;
2017     int32_t pointId = 100;
2018     dragDropManager->IsAnyDraggableHit(pipeline, pointId);
2019     EXPECT_EQ(dragDropManager->isAnyDraggableHit_, false);
2020 }
2021 
2022 /**
2023  * @tc.name: RequireSummaryAndDragBundleInfoIfNecessary001
2024  * @tc.desc: ResetPreTargetFrameNode
2025  * @tc.type: FUNC
2026  */
2027 HWTEST_F(DragDropManagerTestNg, RequireSummaryAndDragBundleInfoIfNecessary001, TestSize.Level1)
2028 {
2029     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2030     ASSERT_NE(dragDropManager, nullptr);
2031 
2032     DragPointerEvent pointerEvent;
2033     pointerEvent.pullId = 1;
2034     dragDropManager->RequireSummaryAndDragBundleInfoIfNecessary(pointerEvent);
2035     EXPECT_EQ(dragDropManager->currentPullId_, 1);
2036 
2037     DragPointerEvent pointerEvent1;
2038     pointerEvent1.pullId = -1;
2039     dragDropManager->RequireSummaryAndDragBundleInfoIfNecessary(pointerEvent);
2040     EXPECT_EQ(dragDropManager->currentPullId_, 1);
2041 }
2042 
2043 /**
2044  * @tc.name: HandleSyncOnDragStart001
2045  * @tc.desc: ResetPreTargetFrameNode
2046  * @tc.type: FUNC
2047  */
2048 HWTEST_F(DragDropManagerTestNg, HandleSyncOnDragStart001, TestSize.Level1)
2049 {
2050     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2051     ASSERT_NE(dragDropManager, nullptr);
2052 
2053     DragStartRequestStatus dragStartRequestStatus = DragStartRequestStatus::WAITING;
2054     dragDropManager->HandleSyncOnDragStart(dragStartRequestStatus);
2055     EXPECT_EQ(dragStartRequestStatus, DragStartRequestStatus::WAITING);
2056 
2057     bool callbackCalled = false;
__anonb7fa81191202() 2058     auto callback = [&callbackCalled]() { callbackCalled = true; };
2059     DragDropGlobalController::GetInstance().SetAsyncDragCallback(callback);
2060 
2061     dragStartRequestStatus = DragStartRequestStatus::READY;
2062     dragDropManager->HandleSyncOnDragStart(dragStartRequestStatus);
2063     EXPECT_EQ(dragStartRequestStatus, DragStartRequestStatus::READY);
2064 }
2065 
2066 /**
2067  * @tc.name: HandleSyncOnDragStart002
2068  * @tc.desc: ResetPreTargetFrameNode
2069  * @tc.type: FUNC
2070  */
2071 HWTEST_F(DragDropManagerTestNg, HandleSyncOnDragStart002, TestSize.Level1)
2072 {
2073     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2074     ASSERT_NE(dragDropManager, nullptr);
2075 
2076     DragDropGlobalController::GetInstance().SetDragStartRequestStatus(DragStartRequestStatus::READY);
2077     dragDropManager->HandleSyncOnDragStart(DragStartRequestStatus::WAITING);
2078     EXPECT_EQ(
2079         DragDropGlobalController::GetInstance().GetDragStartRequestStatus(),
2080         DragStartRequestStatus::WAITING);
2081 
2082     bool callbackCalled = false;
__anonb7fa81191302() 2083     auto callback = [&callbackCalled]() { callbackCalled = true; };
2084     DragDropGlobalController::GetInstance().SetAsyncDragCallback(callback);
2085     dragDropManager->HandleSyncOnDragStart(DragStartRequestStatus::READY);
2086     EXPECT_TRUE(callbackCalled);
2087     EXPECT_EQ(
2088         DragDropGlobalController::GetInstance().GetDragStartRequestStatus(),
2089         DragStartRequestStatus::READY);
2090 
2091     DragDropGlobalController::GetInstance().SetAsyncDragCallback(nullptr);
2092     DragDropGlobalController::GetInstance().SetDragStartRequestStatus(DragStartRequestStatus::WAITING);
2093     dragDropManager->HandleSyncOnDragStart(DragStartRequestStatus::READY);
2094     EXPECT_EQ(
2095         DragDropGlobalController::GetInstance().GetDragStartRequestStatus(),
2096         DragStartRequestStatus::WAITING);
2097 
2098     auto invalidStatus = static_cast<DragStartRequestStatus>(99);
2099     dragDropManager->HandleSyncOnDragStart(invalidStatus);
2100     EXPECT_EQ(
2101         DragDropGlobalController::GetInstance().GetDragStartRequestStatus(),
2102         DragStartRequestStatus::WAITING);
2103 }
2104 
2105 /**
2106  * @tc.name: GetWindowId001
2107  * @tc.desc: ResetPreTargetFrameNode
2108  * @tc.type: FUNC
2109  */
2110 HWTEST_F(DragDropManagerTestNg, GetWindowId001, TestSize.Level1)
2111 {
2112     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2113     ASSERT_NE(dragDropManager, nullptr);
2114     int32_t result = dragDropManager->GetWindowId();
2115     EXPECT_EQ(result, -1);
2116 }
2117 
2118 /**
2119  * @tc.name: ResetDraggingStatus001
2120  * @tc.desc: ResetPreTargetFrameNode
2121  * @tc.type: FUNC
2122  */
2123 HWTEST_F(DragDropManagerTestNg, ResetDraggingStatus001, TestSize.Level1)
2124 {
2125     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2126     ASSERT_NE(dragDropManager, nullptr);
2127     TouchEvent touchPoint;
2128 
2129     touchPoint.id = 1;
2130     dragDropManager->currentPointerId_ = 1;
2131     dragDropManager->draggingPressedState_ = true;
2132     dragDropManager->ResetDraggingStatus(touchPoint);
2133 
2134     dragDropManager->dragDropState_ = DragDropMgrState::DRAGGING;
2135     auto draggedGridFrameNode_ = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
2136     dragDropManager->ResetDraggingStatus(touchPoint);
2137     EXPECT_EQ(dragDropManager->currentPointerId_, 1);
2138 }
2139 
2140 /**
2141  * @tc.name: ResetDraggingStatus002
2142  * @tc.desc: ResetPreTargetFrameNode
2143  * @tc.type: FUNC
2144  */
2145 HWTEST_F(DragDropManagerTestNg, ResetDraggingStatus002, TestSize.Level1)
2146 {
2147     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2148     ASSERT_NE(dragDropManager, nullptr);
2149     TouchEvent touchPoint;
2150     touchPoint.type = TouchType::CANCEL;
2151     dragDropManager->ResetDraggingStatus(touchPoint);
2152     EXPECT_EQ(dragDropManager->dragDropState_, DragDropMgrState::IDLE);
2153 }
2154 
2155 /**
2156  * @tc.name: HandleOnDragEnd001
2157  * @tc.desc: ResetPreTargetFrameNode
2158  * @tc.type: FUNC
2159  */
2160 HWTEST_F(DragDropManagerTestNg, HandleOnDragEnd001, TestSize.Level1)
2161 {
2162     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2163     ASSERT_NE(dragDropManager, nullptr);
2164     DragPointerEvent pointerEvent;
2165     string extraInfo = "Test";
2166     auto dragFrameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
2167     dragDropManager->HandleOnDragEnd(pointerEvent, extraInfo, dragFrameNode);
2168     EXPECT_FALSE(dragDropManager->IsDragging());
2169 }
2170 
2171 /**
2172  * @tc.name: HandleOnDragEnd002
2173  * @tc.desc: HandleOnDragEnd
2174  * @tc.type: FUNC
2175  */
2176 HWTEST_F(DragDropManagerTestNg, HandleOnDragEnd002, TestSize.Level1)
2177 {
2178     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2179     ASSERT_NE(dragDropManager, nullptr);
2180     DragDropGlobalController::GetInstance().SetDragStartRequestStatus(DragStartRequestStatus::READY);
2181 
2182     auto eventHub = AceType::MakeRefPtr<EventHub>();
2183     ASSERT_NE(eventHub, nullptr);
2184     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(eventHub);
2185     ASSERT_NE(gestureEventHub, nullptr);
2186 
2187     GestureEvent info;
2188     gestureEventHub->HandleOnDragStart(info);
2189     ASSERT_EQ(DragDropGlobalController::GetInstance().GetCallAnsyncEnd(), nullptr);
2190 }
2191 
2192 /**
2193  * @tc.name: SetEnableDisallowStatusShowing
2194  * @tc.desc: Test SetEnableDisallowStatusShowing
2195  * @tc.type: FUNC
2196  * @tc.author:
2197  */
2198 HWTEST_F(DragDropManagerTestNg, SetEnableDisallowStatusShowing, TestSize.Level1)
2199 {
2200     bool enableDropDisallowedBadgeDefalut = DragDropGlobalController::GetInstance().GetEnableDropDisallowedBadge();
2201     EXPECT_FALSE(enableDropDisallowedBadgeDefalut);
2202     DragDropGlobalController::GetInstance().SetEnableDropDisallowedBadge(true);
2203     bool enableDropDisallowedBadgeTrue = DragDropGlobalController::GetInstance().GetEnableDropDisallowedBadge();
2204     EXPECT_TRUE(enableDropDisallowedBadgeTrue);
2205     DragDropGlobalController::GetInstance().SetEnableDropDisallowedBadge(false);
2206     bool enableDropDisallowedBadgeFalse = DragDropGlobalController::GetInstance().GetEnableDropDisallowedBadge();
2207     EXPECT_FALSE(enableDropDisallowedBadgeFalse);
2208 }
2209 
2210 /**
2211  * @tc.name: HandleOnDragEnd003
2212  * @tc.desc: HandleOnDragEnd
2213  * @tc.type: FUNC
2214  */
2215 HWTEST_F(DragDropManagerTestNg, HandleOnDragEnd003, TestSize.Level1)
2216 {
2217     /**
2218      * @tc.steps: step1. construct a DragDropManager.
2219      * @tc.expected: dragDropManager is not null.
2220      */
2221     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2222     ASSERT_NE(dragDropManager, nullptr);
2223 
2224     /**
2225      * @tc.steps: step2. create a frameNode, then set preTargetFrameNode_.
2226      * @tc.expected: The values of preTargetFrameNode_ and frameNode are equal
2227      */
2228     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
2229     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
2230     ASSERT_NE(frameNode, nullptr);
2231 
2232     dragDropManager->preTargetFrameNode_ = frameNode;
2233     ASSERT_EQ(dragDropManager->preTargetFrameNode_, frameNode);
2234 
2235     dragDropManager->draggingPressedState_ = true;
2236     EXPECT_TRUE(dragDropManager->draggingPressedState_);
2237     DragNotifyMsgCore notifyMessage;
2238     auto dragEvent = AceType::MakeRefPtr<OHOS::Ace::DragEvent>();
2239     ASSERT_NE(dragEvent, nullptr);
2240     dragDropManager->ResetDragEndOption(notifyMessage, dragEvent, 0);
2241     EXPECT_FALSE(dragDropManager->draggingPressedState_);
2242 }
2243 
2244 /**
2245  * @tc.name: HandleOnDragEnd004
2246  * @tc.desc: HandleOnDragEnd
2247  * @tc.type: FUNC
2248  */
2249 HWTEST_F(DragDropManagerTestNg, HandleOnDragEnd004, TestSize.Level1)
2250 {
2251     /**
2252      * @tc.steps: step1. construct a DragDropManager.
2253      * @tc.expected: dragDropManager is not null.
2254      */
2255     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2256     ASSERT_NE(dragDropManager, nullptr);
2257 
2258     /**
2259      * @tc.steps: step2. create a frameNode, then set preTargetFrameNode_.
2260      * @tc.expected: The values of preTargetFrameNode_ and frameNode are equal
2261      */
2262     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
2263     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
2264     ASSERT_NE(frameNode, nullptr);
2265 
2266     dragDropManager->preTargetFrameNode_ = frameNode;
2267     ASSERT_EQ(dragDropManager->preTargetFrameNode_, frameNode);
2268 
2269     DragNotifyMsgCore notifyMessage;
2270     auto dragEvent = AceType::MakeRefPtr<OHOS::Ace::DragEvent>();
2271     ASSERT_NE(dragEvent, nullptr);
2272     dragEvent->isRemoteDev_ = true;
2273     EXPECT_TRUE(dragEvent->isRemoteDev_);
2274     dragDropManager->ResetDragEndOption(notifyMessage, dragEvent, 0);
2275     EXPECT_FALSE(dragEvent->isRemoteDev_);
2276 }
2277 
2278 /**
2279  * @tc.name: DragDropManagerCheckIsNewDragTest001
2280  * @tc.desc: Verify CheckIsNewDrag and RequireSummaryAndDragBundleInfoIfNecessary handle pullId correctly.
2281  * @tc.type: FUNC
2282  */
2283 HWTEST_F(DragDropManagerTestNg, DragDropManagerCheckIsNewDragTest001, TestSize.Level1)
2284 {
2285     /**
2286      * @tc.steps: step1. Create DragDropManager instance.
2287      */
2288     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2289     ASSERT_NE(dragDropManager, nullptr);
2290 
2291     /**
2292      * @tc.steps: step2. Check when pullId is -1 (invalid).
2293      * @tc.expected: Returns false.
2294      */
2295     DragPointerEvent pointerEvent;
2296     pointerEvent.pullId = INVALID_PULL_ID;
2297     EXPECT_FALSE(dragDropManager->CheckIsNewDrag(pointerEvent));
2298 
2299     /**
2300      * @tc.steps: step3. Check when pullId is equal to currentPullId_.
2301      * @tc.expected: Returns false.
2302      */
2303     dragDropManager->currentPullId_ = CURRENT_PULL_ID;
2304     pointerEvent.pullId = CURRENT_PULL_ID;
2305     EXPECT_FALSE(dragDropManager->CheckIsNewDrag(pointerEvent));
2306 
2307     /**
2308      * @tc.steps: step4. Check when pullId is different from currentPullId_.
2309      * @tc.expected: Returns true.
2310      */
2311     pointerEvent.pullId = NEW_PULL_ID;
2312     EXPECT_TRUE(dragDropManager->CheckIsNewDrag(pointerEvent));
2313 
2314     /**
2315      * @tc.steps: step5. Call RequireSummaryAndDragBundleInfoIfNecessary and verify currentPullId_ update.
2316      * @tc.expected: currentPullId_ should be updated to new value.
2317      */
2318     dragDropManager->RequireSummaryAndDragBundleInfoIfNecessary(pointerEvent);
2319     EXPECT_EQ(dragDropManager->currentPullId_, NEW_PULL_ID);
2320 }
2321 
2322 /**
2323  * @tc.name: DragDropManagerResetPullIdTest001
2324  * @tc.desc: Verify ResetPullId clears summaryMap, parentHitNodes and resets currentPullId_.
2325  * @tc.type: FUNC
2326  */
2327 HWTEST_F(DragDropManagerTestNg, DragDropManagerResetPullIdTest001, TestSize.Level1)
2328 {
2329     /**
2330      * @tc.steps: step1. Create DragDropManager and simulate internal state.
2331      */
2332     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2333     ASSERT_NE(dragDropManager, nullptr);
2334 
2335     dragDropManager->summaryMap_.insert({ "data", 1 });
2336     dragDropManager->parentHitNodes_.insert(PARENT_NODE_ID);
2337     dragDropManager->currentPullId_ = CURRENT_PULL_ID;
2338 
2339     /**
2340      * @tc.steps: step2. Call ResetPullId.
2341      * @tc.expected: All fields reset to default state.
2342      */
2343     dragDropManager->ResetPullId();
2344 
2345     EXPECT_TRUE(dragDropManager->summaryMap_.empty());
2346     EXPECT_TRUE(dragDropManager->parentHitNodes_.empty());
2347     EXPECT_EQ(dragDropManager->currentPullId_, INVALID_PULL_ID);
2348 }
2349 
2350 /**
2351  * @tc.name: ResetDragDropClearTest001
2352  * @tc.desc: Test ResetDragDrop should clear velocity info
2353  * @tc.type: FUNC
2354  */
2355 HWTEST_F(DragDropManagerTestNg, ResetDragDropClearTest001, TestSize.Level1)
2356 {
2357     /**
2358      * @tc.steps: step1. Create an instance of DragDropManager
2359      */
2360     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
2361     ASSERT_NE(dragDropManager, nullptr);
2362 
2363     /**
2364      * @tc.steps: step2. Manually add fake data to velocityTracker_
2365      * @tc.expected: The isFirstPoint_ of velocityTracker_ should become false (indicating data exists)
2366      */
2367     Point startPoint(POINT_X1, POINT_Y1);
2368     dragDropManager->UpdateVelocityTrackerPoint(startPoint, true);
2369     EXPECT_FALSE(dragDropManager->velocityTracker_.isFirstPoint_);
2370 
2371     /**
2372      * @tc.steps: step3. Call ResetDragDrop to simulate a drag failure
2373      */
2374     int32_t windowId = WINDOW_ID;
2375     Point dropPoint(POINT_X2, POINT_Y2);
2376     dragDropManager->ResetDragDrop(windowId, dropPoint);
2377 
2378     /**
2379      * @tc.steps: step4. Check if velocityTracker_ has been cleared
2380      * @tc.expected: velocityTracker_ is successfully reset
2381      */
2382     EXPECT_TRUE(dragDropManager->velocityTracker_.isFirstPoint_);
2383 }
2384 } // namespace OHOS::Ace::NG
2385