1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test/unittest/core/manager/drag_drop_manager_test_ng.h"
17 #include "test/mock/core/render/mock_render_context.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 namespace OHOS::Ace::NG {
SetUpTestCase()22 void DragDropManagerTestNg::SetUpTestCase()
23 {
24     MockPipelineContext::SetUp();
25     MockContainer::SetUp();
26 }
27 
TearDownTestCase()28 void DragDropManagerTestNg::TearDownTestCase()
29 {
30     MockPipelineContext::TearDown();
31     MockContainer::TearDown();
32 }
33 
34 /**
35  * @tc.name: DragDropManagerTest001
36  * @tc.desc: CreateAndShowDragWindow via pixelMap and gestureEvent
37  * @tc.type: FUNC
38  * @tc.author:
39  */
40 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest001, TestSize.Level1)
41 {
42     /**
43      * @tc.steps: step1. construct a DragDropManager
44      */
45     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
46 
47     /**
48      * @tc.steps: step2. call CreateAndShowDragWindow
49      * @tc.expected: step2. return a dragDropProxy successfully
50      *                      DragWindow.DrawPixelMap() will be called
51      */
52     void* voidPtr = static_cast<void*>(new char[0]);
53     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
54     GestureEvent gestureEvent;
55     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(pixelMap, gestureEvent);
56     EXPECT_TRUE(dragDropProxy);
57 
58     /**
59      * @tc.steps: step3. call CreateAndShowDragWindow with null.
60      * @tc.expected: step3. return dragDropProxy to false.
61      */
62     pixelMap = nullptr;
63     dragDropProxy = dragDropManager->CreateAndShowDragWindow(pixelMap, gestureEvent);
64     EXPECT_FALSE(dragDropProxy);
65 }
66 
67 /**
68  * @tc.name: DragDropManagerTest002
69  * @tc.desc: CreateAndShowDragWindow via customNode and gestureEvent
70  * @tc.type: FUNC
71  * @tc.author:
72  */
73 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest002, TestSize.Level1)
74 {
75     /**
76      * @tc.steps: step1. construct a DragDropManager
77      */
78     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
79 
80     /**
81      * @tc.steps: step2. call CreateAndShowDragWindow
82      * @tc.expected: step2. return a dragDropProxy successfully
83      *                      DragWindow.DrawFrameNode() will be called
84      */
85     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
86     GestureEvent gestureEvent;
87     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
88     EXPECT_TRUE(dragDropProxy);
89 
90     /**
91      * @tc.expected: step2. the customNode's parent is root
92      */
93     auto root = customNode->GetParent();
94     auto rootTag = root->GetTag();
95     EXPECT_EQ(rootTag, ROOT_ETS_TAG);
96 
97     /**
98      * @tc.steps: step3. call CreateAndShowDragWindow again
99      * @tc.expected: step3. return nullptr because dragWindow_ has existed
100      */
101     RefPtr<UINode> customNode2 = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
102     GestureEvent gestureEvent2;
103     auto dragDropProxyNull = dragDropManager->CreateAndShowDragWindow(customNode2, gestureEvent2);
104     EXPECT_FALSE(dragDropProxyNull);
105 }
106 
107 /**
108  * @tc.name: DragDropManagerTest003
109  * @tc.desc: Test UpdateDragWindowPosition
110  * @tc.type: FUNC
111  * @tc.author:
112  */
113 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest003, TestSize.Level1)
114 {
115     /**
116      * @tc.steps: step1. construct a DragDropManager
117      */
118     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
119 
120     /**
121      * @tc.steps: step2. call CreateAndShowDragWindow
122      * @tc.expected: step2. return a dragDropProxy successfully
123      */
124     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
125     GestureEvent gestureEvent;
126     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
127     EXPECT_TRUE(dragDropProxy);
128 
129     /**
130      * @tc.steps: step3. call UpdateDragWindowPosition
131      * @tc.expected: step3. DragWindow.MoveTo() will be called
132      */
133     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
134         .Times(1);
135     dragDropManager->UpdateDragWindowPosition(GLOBAL_X, GLOBAL_Y);
136 }
137 
138 /**
139  * @tc.name: DragDropManagerTest004
140  * @tc.desc: Test Functions relevant to Clipboard
141              Call this functions in order (AddDataToClipboard->GetExtraInfoFromClipboard->RestoreClipboardData)
142  * @tc.type: FUNC
143  * @tc.author:
144  */
145 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest004, TestSize.Level1)
146 {
147     /**
148      * @tc.steps: step1. construct a DragDropManager
149      */
150     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
151 
152     /**
153      * @tc.steps: step2. call CreateAndShowDragWindow
154      * @tc.expected: step2. return a dragDropProxy successfully
155      */
156     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
157     GestureEvent gestureEvent;
158     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
159     EXPECT_TRUE(dragDropProxy);
160 
161     /**
162      * @tc.steps: step3. call AddDataToClipboard
163      * @tc.expected: step3. ClipBoard.SetData() & ClipBoard.GetData() will be called with printing logs
164      *                      they're defined in "components_ng/test/mock/clipboard/mock_clipboard.cpp"
165      */
166     dragDropManager->AddDataToClipboard(EXTRA_INFO);
167 
168     /**
169      * @tc.steps: step4. call GetExtraInfoFromClipboard after calling AddDataToClipboard
170      * @tc.expected: step4. get the extraInfo successfully
171      *                      ClipBoard.GetData() will be called with printing a log
172      *                      it's defined in "components_ng/test/mock/clipboard/mock_clipboard.cpp"
173      */
174     std::string extraInfo;
175     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
176     EXPECT_EQ(extraInfo, EXTRA_INFO);
177 
178     /**
179      * @tc.steps: step5. call GetExtraInfoFromClipboard
180      * @tc.expected: step5. extraInfo is equal to EXTRA_INFO
181      */
182     dragDropManager->clipboard_ = nullptr;
183     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
184     EXPECT_EQ(extraInfo, EXTRA_INFO);
185 
186     /**
187      * @tc.steps: step6. call AddDataToClipboard with empty.
188      * @tc.expected: step6. extraInfo is equal to EXTRA_INFO
189      */
190     dragDropManager->AddDataToClipboard(extraInfo);
191     EXPECT_EQ(extraInfo, EXTRA_INFO);
192 }
193 
194 /**
195  * @tc.name: DragDropManagerTest005
196  * @tc.desc: Test Functions relevant to Clipboard
197              Call this functions not in order (to test boundary cases)
198  * @tc.type: FUNC
199  * @tc.author:
200  */
201 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest005, TestSize.Level1)
202 {
203     /**
204      * @tc.steps: step1. construct a DragDropManager
205      */
206     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
207 
208     /**
209      * @tc.steps: step2. call CreateAndShowDragWindow
210      * @tc.expected: step2. return a dragDropProxy successfully
211      */
212     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
213     GestureEvent gestureEvent;
214     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
215     EXPECT_TRUE(dragDropProxy);
216 
217     /**
218      * @tc.steps: step3. call AddDataToClipboard twice
219      *                   case: clipboard_ & addDataCallback_ has exited,
220      * @tc.expected: step3. EXTRA_INFO_2 will be added
221      */
222     dragDropManager->AddDataToClipboard(EXTRA_INFO);
223     dragDropManager->AddDataToClipboard(EXTRA_INFO_2);
224     std::string extraInfo;
225     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
226     EXPECT_EQ(extraInfo, EXTRA_INFO_2);
227 
228     /**
229      * @tc.steps: step4. call GetExtraInfoFromClipboard twice
230      *                   case: clipboard_ & addDataCallback_ has exited
231      * @tc.expected: step4. get the extraInfo successfully
232      */
233     dragDropManager->GetExtraInfoFromClipboard(extraInfo);
234     EXPECT_EQ(extraInfo, EXTRA_INFO_2);
235 }
236 
237 /**
238  * @tc.name: DragDropManagerTest006
239  * @tc.desc: Test DestroyDragWindow & CheckDragDropProxy
240  * @tc.type: FUNC
241  * @tc.author:
242  */
243 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest006, TestSize.Level1)
244 {
245     /**
246      * @tc.steps: step1. construct a DragDropManager
247      */
248     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
249 
250     /**
251      * @tc.steps: step2. call DestroyDragWindow without creating dragWindow
252      * @tc.expected: step2. no fatal error happens
253      */
254     dragDropManager->DestroyDragWindow();
255 
256     /**
257      * @tc.steps: step3. call CheckDragDropProxy without creating dragWindow
258      * @tc.expected: step3. currentId is -1 at first
259      */
260     auto flag = dragDropManager->CheckDragDropProxy(INVALID_CURRENT_ID);
261     EXPECT_TRUE(flag);
262 
263     /**
264      * @tc.steps: step4. call CreateAndShowDragWindow
265      * @tc.expected: step4. return a dragDropProxy successfully
266      *                      currentId has incremented by 1 to 1
267      */
268     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
269     GestureEvent gestureEvent;
270     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
271     EXPECT_TRUE(dragDropProxy);
272     flag = dragDropManager->CheckDragDropProxy(VALID_CURRENT_ID);
273     EXPECT_TRUE(flag);
274 
275     /**
276      * @tc.steps: step5. call CheckDragDropProxy after creating dragWindow
277      * @tc.expected: step5. currentId recover to -1
278      *                      MockDragWindow.Destroy() will be called
279      */
280     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), Destroy()).Times(1);
281     dragDropManager->DestroyDragWindow();
282     flag = dragDropManager->CheckDragDropProxy(INVALID_CURRENT_ID);
283     EXPECT_TRUE(flag);
284 
285     /**
286      * @tc.steps: step6. call CheckDragDropProxy when dragWindowRootNode_ is null (use proxy to create drag window)
287      * @tc.expected: step6. currentId recover to -1
288      *                      MockDragWindow.Destroy() will be called
289      */
290     auto dragDropManager2 = AceType::MakeRefPtr<DragDropManager>();
291     void* voidPtr = static_cast<void*>(new char[0]);
292     RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
293     GestureEvent gestureEvent2;
294     auto dragDropProxy2 = dragDropManager2->CreateAndShowDragWindow(pixelMap, gestureEvent2);
295     EXPECT_TRUE(dragDropProxy2);
296     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager2->dragWindow_)), Destroy()).Times(1);
297     dragDropManager2->DestroyDragWindow();
298     flag = dragDropManager2->CheckDragDropProxy(INVALID_CURRENT_ID);
299     EXPECT_TRUE(flag);
300 }
301 
302 /**
303  * @tc.name: DragDropManagerTest007
304  * @tc.desc: Test OnDragStart & onDragCancel & OnItemDragStart & onItemDragCancel
305  * @tc.type: FUNC
306  * @tc.author:
307  */
308 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest007, TestSize.Level1)
309 {
310     /**
311      * @tc.steps: step1. construct a DragDropManager
312      */
313     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
314 
315     /**
316      * @tc.steps: step2. call OnDragStart
317      * @tc.expected: step2. draggedFrameNode_ &  preTargetFrameNode_ are assigned to the frameNode created previously
318      */
319     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
320     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, frameNode);
321     auto draggedNode = dragDropManager->draggedFrameNode_;
322     auto preTargetNode = dragDropManager->preTargetFrameNode_;
323     ASSERT_TRUE(draggedNode);
324     ASSERT_TRUE(preTargetNode);
325     auto draggedNodeTag = draggedNode->GetTag();
326     auto preTargetNodeTag = preTargetNode->GetTag();
327     EXPECT_EQ(draggedNodeTag, NODE_TAG);
328     EXPECT_EQ(preTargetNodeTag, NODE_TAG);
329 
330     /**
331      * @tc.steps: step3. call onDragCancel
332      * @tc.expected: step3. draggedFrameNode_ &  preTargetFrameNode_ are assigned to nullptr
333      */
334     dragDropManager->onDragCancel();
335     draggedNode = dragDropManager->draggedFrameNode_;
336     preTargetNode = dragDropManager->preTargetFrameNode_;
337     EXPECT_FALSE(draggedNode);
338     EXPECT_FALSE(preTargetNode);
339 
340     /**
341      * @tc.steps: step4. call OnItemDragStart
342      * @tc.expected: step4. preGridTargetNodeTag is assigned to the gridFrameNode created previously
343      */
344     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<Pattern>());
345     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
346     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
347     ASSERT_TRUE(preGridTargetNode);
348     auto preGridTargetNodeTag = preGridTargetNode->GetTag();
349     EXPECT_EQ(preGridTargetNodeTag, GRID_TAG);
350 
351     /**
352      * @tc.steps: step5. call onItemDragCancel
353      * @tc.expected: step5. preGridTargetFrameNode_ is assigned to nullptr
354      */
355     dragDropManager->onItemDragCancel();
356     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
357     EXPECT_FALSE(preGridTargetNode);
358 }
359 
360 /**
361  * @tc.name: DragDropManagerTest009
362  * @tc.desc: Test OnItemDragMove DragType is Grid
363  * @tc.type: FUNC
364  * @tc.author:
365  */
366 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest008, TestSize.Level1)
367 {
368     /**
369      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
370      */
371     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
372     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
373     GestureEvent gestureEvent;
374     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
375     EXPECT_TRUE(dragDropProxy);
376 
377     /**
378      * @tc.steps: step2. call OnItemDragMove
379      *                   case: gridDragFrameNodes_ is empty & preTargetFrameNode_ is null
380      * @tc.expected: step2. DragWindow.MoveTo() will be called
381      */
382     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
383         .Times(1);
384     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
385 
386     /**
387      * @tc.steps: step3. construct a frameNode whose tag is Grid set its ItemDragEvent and GeometryNode
388      */
389     auto frameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
390     auto eventHub = frameNode->GetEventHub<GridEventHub>();
391     ASSERT_TRUE(eventHub);
392 
393     // Set OnItemDragLeave callback
394     std::string itemInfoLeave;
__anon25030b2f0102(const ItemDragInfo& , int32_t ) 395     auto onItemDragLeave = [&itemInfoLeave](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
396         itemInfoLeave = ITEM_INFO_LEAVE;
397     };
398     eventHub->SetOnItemDragLeave(std::move(onItemDragLeave));
399 
400     // Set OnItemDragMove callback
401     std::string itemInfoMove;
402     auto onItemDragMove = [&itemInfoMove](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0202(const ItemDragInfo& , int32_t , int32_t ) 403                               int32_t /* insertIndex */) { itemInfoMove = ITEM_INFO_MOVE; };
404     eventHub->SetOnItemDragMove(std::move(onItemDragMove));
405 
406     // Set OnItemDragEnter callback
407     std::string itemInfoEnter;
__anon25030b2f0302(const ItemDragInfo& ) 408     auto onItemDragEnter = [&itemInfoEnter](const ItemDragInfo& /* dragInfo */) { itemInfoEnter = ITEM_INFO_ENTER; };
409     eventHub->SetOnItemDragEnter(std::move(onItemDragEnter));
410 
411     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
412     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
413     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
414     geoNode->SetFrameSize(FRAME_SIZE);
415     frameNode->SetGeometryNode(geoNode);
416 
417     /**
418      * @tc.steps: step4. call OnItemDragMove
419      *                   case: gridDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
420      * @tc.expected: step4. frameNode's onItemDragLeave_ will be called
421      *                      itemInfoLeave will be assigned to ITEM_INFO_LEAVE
422      */
423     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
424     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
425     ASSERT_TRUE(preGridTargetNode);
426     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
427         .Times(1);
428     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
429     EXPECT_EQ(itemInfoLeave, ITEM_INFO_LEAVE);
430     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
431     EXPECT_FALSE(preGridTargetNode);
432 
433     /**
434      * @tc.steps: step5. call AddGridDragFrameNode
435      *                   after that, gridDragFrameNodes_ is not empty
436      */
437     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
438 
439     /**
440      * @tc.steps: step6. call OnItemDragMove
441      *                   case: gridDragFrameNodes_ is not empty & preGridTargetFrameNode_ equals the frameNode
442      * @tc.expected: step6. frameNode's OnItemDragMove_ will be called
443      *                      itemInfoMove will be assigned to ITEM_INFO_MOVE
444      *                      DragWindow.MoveTo() will be called
445      */
446     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
447     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
448     EXPECT_TRUE(preGridTargetNode);
449     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
450         .Times(1);
451     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
452 
453     /**
454      * @tc.steps: step7. call OnItemDragMove
455      *                   case: gridDragFrameNodes_ is not empty & preGridTargetFrameNode_ not equals the frameNode
456      * @tc.expected: step7. frameNode's onDragItemEnter_ will be called
457      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
458      *                      preGridTargetFrameNode_'s onDragItemLeave will be called
459      *                      leaveExtraInfoNew will be assigned to ITEM_INFO_ENTER
460      *                      preGridTargetFrameNode_ is assigned to frameNode
461      *                      DragWindow.MoveTo() will be called
462      */
463     auto newFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
464     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, newFrameNode);
465     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
466     EXPECT_TRUE(preGridTargetNode);
467     // Set newFrameNode's onDragLeave callback
468     auto eventHubNew = newFrameNode->GetEventHub<GridEventHub>();
469     ASSERT_TRUE(eventHubNew);
470     std::string itemInfoLeaveNew;
__anon25030b2f0402(const ItemDragInfo& , int32_t ) 471     auto onItemDragLeaveNew = [&itemInfoLeaveNew](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
472         itemInfoLeaveNew = ITEM_INFO_ENTER;
473     };
474     eventHubNew->SetOnItemDragLeave(std::move(onItemDragLeaveNew));
475     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
476         .Times(1);
477     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
478     EXPECT_EQ(itemInfoLeaveNew, ITEM_INFO_ENTER);
479     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
480     ASSERT_FALSE(preGridTargetNode);
481 }
482 
483 /**
484  * @tc.name: DragDropManagerTest010
485  * @tc.desc: Test OnItemDragMove DragType is List
486  * @tc.type: FUNC
487  * @tc.author:
488  */
489 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest009, TestSize.Level1)
490 {
491     /**
492      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
493      */
494     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
495     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
496     GestureEvent gestureEvent;
497     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
498     EXPECT_TRUE(dragDropProxy);
499 
500     /**
501      * @tc.steps: step2. call OnItemDragMove
502      *                   case: listDragFrameNodes_ is empty & preTargetFrameNode_ is null
503      * @tc.expected: step2. DragWindow.MoveTo() will be called
504      */
505     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
506         .Times(1);
507     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
508 
509     /**
510      * @tc.steps: step3. construct a frameNode whose tag is List set its ItemDragEvent and GeometryNode
511      */
512     auto frameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
513     auto eventHub = frameNode->GetEventHub<ListEventHub>();
514     ASSERT_TRUE(eventHub);
515 
516     // Set OnItemDragLeave callback
517     std::string itemInfoLeave;
__anon25030b2f0502(const ItemDragInfo& , int32_t ) 518     auto onItemDragLeave = [&itemInfoLeave](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
519         itemInfoLeave = ITEM_INFO_LEAVE;
520     };
521     eventHub->SetOnItemDragLeave(std::move(onItemDragLeave));
522 
523     // Set OnItemDragMove callback
524     std::string itemInfoMove;
525     auto onItemDragMove = [&itemInfoMove](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0602(const ItemDragInfo& , int32_t , int32_t ) 526                               int32_t /* insertIndex */) { itemInfoMove = ITEM_INFO_MOVE; };
527     eventHub->SetOnItemDragMove(std::move(onItemDragMove));
528 
529     // Set OnItemDragEnter callback
530     std::string itemInfoEnter;
__anon25030b2f0702(const ItemDragInfo& ) 531     auto onItemDragEnter = [&itemInfoEnter](const ItemDragInfo& /* dragInfo */) { itemInfoEnter = ITEM_INFO_ENTER; };
532     eventHub->SetOnItemDragEnter(std::move(onItemDragEnter));
533 
534     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
535     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
536     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
537     geoNode->SetFrameSize(FRAME_SIZE);
538     frameNode->SetGeometryNode(geoNode);
539 
540     /**
541      * @tc.steps: step4. call OnItemDragMove
542      *                   case: listDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
543      * @tc.expected: step4. frameNode's onItemDragLeave_ will be called
544      *                      itemInfoLeave will be assigned to ITEM_INFO_LEAVE
545      *                      DragWindow.MoveTo() will be called
546      */
547     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
548     auto preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
549     ASSERT_TRUE(preGridTargetNode);
550     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
551         .Times(2);
552     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
553     EXPECT_EQ(itemInfoLeave, ITEM_INFO_LEAVE);
554     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
555     EXPECT_FALSE(preGridTargetNode);
556 
557     /**
558      * @tc.steps: step5. call AddGridDragFrameNode
559      *                   after that, listDragFrameNodes_ is not empty
560      *                   need adding grid maybe a bug
561      */
562     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
563 
564     /**
565      * @tc.steps: step6. call OnItemDragMove
566      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ equals the frameNode
567      * @tc.expected: step6. a gridEventHub is trying to get by the frameNode,
568      *                      but it's list type, so will return early(maybe that is a bug)
569      *                      itemInfoMove will not be assigned DragWindow.MoveTo() will be called
570      */
571     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
572     preGridTargetNode = dragDropManager->preGridTargetFrameNode_;
573     EXPECT_TRUE(preGridTargetNode);
574     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
575     EXPECT_EQ(itemInfoMove, "");
576     // to force call the FireOnItemDragEvent with DragType::LIST and DragEventType::MOVE
577     OHOS::Ace::ItemDragInfo itemDragInfo;
578     dragDropManager->FireOnItemDragEvent(frameNode, DragType::LIST, itemDragInfo, DragEventType::MOVE, DRAGGED_INDEX);
579     EXPECT_EQ(itemInfoMove, ITEM_INFO_MOVE);
580 
581     /**
582      * @tc.steps: step7. call OnItemDragMove
583      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ not equals the frameNode
584      * @tc.expected: step7. frameNode's onDragItemEnter_ will be called
585      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
586      *                      preGridTargetFrameNode_'s onDragItemLeave will be called
587      *                      leaveExtraInfoNew will be assigned to ITEM_INFO_ENTER
588      *                      preGridTargetFrameNode_ is assigned to frameNode
589      *                      DragWindow.MoveTo() will be called
590      */
591     auto newFrameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
592     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, newFrameNode);
593     EXPECT_TRUE(dragDropManager->preGridTargetFrameNode_);
594     // Set newFrameNode's onDragLeave callback
595     auto eventHubNew = newFrameNode->GetEventHub<ListEventHub>();
596     ASSERT_TRUE(eventHubNew);
597     std::string itemInfoLeaveNew;
__anon25030b2f0802(const ItemDragInfo& , int32_t ) 598     auto onItemDragLeaveNew = [&itemInfoLeaveNew](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */) {
599         itemInfoLeaveNew = ITEM_INFO_ENTER;
600     };
601     eventHubNew->SetOnItemDragLeave(std::move(onItemDragLeaveNew));
602     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
603         .Times(0);
604     EXPECT_EQ(itemInfoEnter, "");
605     EXPECT_EQ(itemInfoLeaveNew, "");
606     ASSERT_TRUE(dragDropManager->preGridTargetFrameNode_);
607     auto preGridTargetNodeTag = dragDropManager->preGridTargetFrameNode_->GetTag();
608     EXPECT_EQ(preGridTargetNodeTag, LIST_TAG);
609 
610     /**
611      * @tc.steps: step8. call OnItemDragMove
612      *                   case: listDragFrameNodes_ is not empty & preGridTargetFrameNode_ is null
613      * @tc.expected: step8. frameNode's onDragItemEnter_ will be called
614      *                      itemInfoEnter will be assigned to ITEM_INFO_ENTER
615      *                      DragWindow.MoveTo() will be called
616      */
617     dragDropManager->onItemDragCancel();
618     EXPECT_FALSE(dragDropManager->preGridTargetFrameNode_);
619     itemInfoEnter = "";
620     EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragDropManager->dragWindow_)), MoveTo(GLOBAL_X, GLOBAL_Y))
621         .Times(1);
622     dragDropManager->OnItemDragMove(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
623     EXPECT_EQ(itemInfoEnter, "");
624 }
625 
626 /**
627  * @tc.name: DragDropManagerTest011
628  * @tc.desc: Test OnItemDragEnd type is grid
629  * @tc.type: FUNC
630  * @tc.author:
631  */
632 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest011, TestSize.Level1)
633 {
634     /**
635      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
636      */
637     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
638     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
639     GestureEvent gestureEvent;
640     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
641     EXPECT_TRUE(dragDropProxy);
642 
643     /**
644      * @tc.steps: step2. construct a frameNode which type is grid and set its GeometryNode
645      */
646     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
647     auto eventHub = frameNode->GetEventHub<GridEventHub>();
648     ASSERT_TRUE(eventHub);
649 
650     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
651     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
652     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
653     geoNode->SetFrameSize(FRAME_SIZE);
654     frameNode->SetGeometryNode(geoNode);
655 
656     /**
657      * @tc.steps: step3. call OnItemDragEnd
658      *                   case: gridDragFrameNodes_ is empty
659      * @tc.expected: step3. preGridTargetFrameNode_ is null
660      */
661     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
662     auto preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
663     EXPECT_FALSE(preGridTargetFrameNode);
664 
665     // case: gridDragFrameNodes_ is empty & preGridTargetFrameNode_ is not null
666     auto preGridTargetNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
667     auto preGridEvent = preGridTargetNode->GetEventHub<GridEventHub>();
668     std::string preGridDropInfo;
669     auto onPreGridItemDrop = [&preGridDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0902(const ItemDragInfo& , int32_t , int32_t , bool ) 670                                  int32_t /* insertIndex */, bool /* isSuccess */) { preGridDropInfo = EXTRA_INFO; };
671     preGridEvent->SetOnItemDrop(std::move(onPreGridItemDrop));
672     dragDropManager->preGridTargetFrameNode_ = preGridTargetNode;
673     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
674     EXPECT_EQ(preGridDropInfo, "");
675 
676     /**
677      * @tc.steps: step4. call AddDragFrameNode
678      *                   after that, gridDragFrameNodes_ is not empty
679      */
680     dragDropManager->AddGridDragFrameNode(frameNode->GetId(), frameNode);
681 
682     /**
683      * @tc.steps: step5. call OnItemDragEnd
684      *                   case: eventHub dose not have onDrop_
685      * @tc.expected: step5. preGridTargetFrameNode_ is null
686      */
687     dragDropManager->preGridTargetFrameNode_ = nullptr;
688     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
689     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
690     EXPECT_FALSE(preGridTargetFrameNode);
691 
692     /**
693      * @tc.steps: step6. call OnItemDragEnd
694      *                   case: eventHub dose have onDrop_
695      * @tc.expected: step6. frameNode's OnDrop_ will be called
696      *                      itemDropInfo will be assigned to EXTRA_INFO
697      *                      preGridTargetFrameNode_ be assigned to nullptr
698      */
699     std::string itemDropInfo;
700     auto onItemDrop = [&itemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0a02(const ItemDragInfo& , int32_t , int32_t , bool ) 701                           int32_t /* insertIndex */, bool /* isSuccess */) { itemDropInfo = EXTRA_INFO; };
702     eventHub->SetOnItemDrop(onItemDrop);
703     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
704     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
705     EXPECT_FALSE(preGridTargetFrameNode);
706 
707     // case: preGridTargetFrameNode_ == dragFrameNode
708     dragDropManager->preGridTargetFrameNode_ = frameNode;
709     itemDropInfo.clear();
710     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
711 
712     // case: preGridTargetFrameNode_ != dragFrameNode
713     dragDropManager->preGridTargetFrameNode_ = preGridTargetNode;
714     itemDropInfo.clear();
715     preGridDropInfo.clear();
716     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
717     EXPECT_EQ(preGridDropInfo, "");
718 }
719 
720 /**
721  * @tc.name: DragDropManagerTest012
722  * @tc.desc: Test OnItemDragEnd type is list
723  * @tc.type: FUNC
724  * @tc.author:
725  */
726 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest012, TestSize.Level1)
727 {
728     /**
729      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
730      */
731     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
732     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
733     GestureEvent gestureEvent;
734     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
735     EXPECT_TRUE(dragDropProxy);
736 
737     /**
738      * @tc.steps: step2. construct a frameNode which type is list and set its GeometryNode
739      */
740     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
741     auto eventHub = frameNode->GetEventHub<ListEventHub>();
742     ASSERT_TRUE(eventHub);
743 
744     // Set geometry node to make sure (GLOBAL_X, GLOBAL_Y) in geoNode.frameRect_
745     auto geoNode = AceType::MakeRefPtr<GeometryNode>();
746     geoNode->SetMarginFrameOffset(FRAME_OFFSET);
747     geoNode->SetFrameSize(FRAME_SIZE);
748     frameNode->SetGeometryNode(geoNode);
749 
750     /**
751      * @tc.steps: step3. call OnItemDragEnd
752      *                   case: listDragFrameNodes_ is empty
753      * @tc.expected: step3. preGridTargetFrameNode_ is null
754      */
755     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
756     auto preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
757     EXPECT_FALSE(preGridTargetFrameNode);
758 
759     /**
760      * @tc.steps: step4. call AddDragFrameNode
761      *                   after that, listDragFrameNodes_ is not empty
762      */
763     dragDropManager->AddListDragFrameNode(frameNode->GetId(), frameNode);
764 
765     /**
766      * @tc.steps: step5. call OnItemDragEnd
767      * @tc.expected: step5. frameNode's OnDrop_ will be called
768      *                      itemDropInfo will be assigned to EXTRA_INFO
769      *                      preGridTargetFrameNode_ be assigned to nullptr
770      */
771     std::string itemDropInfo;
772     auto onItemDrop = [&itemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0b02(const ItemDragInfo& , int32_t , int32_t , bool ) 773                           int32_t /* insertIndex */, bool /* isSuccess */) { itemDropInfo = EXTRA_INFO; };
774     eventHub->SetOnItemDrop(onItemDrop);
775     dragDropManager->preGridTargetFrameNode_ = frameNode;
776     EXPECT_TRUE(dragDropManager->preGridTargetFrameNode_);
777     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
778     preGridTargetFrameNode = dragDropManager->preGridTargetFrameNode_;
779     EXPECT_FALSE(preGridTargetFrameNode);
780 }
781 
782 /**
783  * @tc.name: DragDropManagerTest013
784  * @tc.desc: Test corner case
785  * @tc.type: FUNC
786  * @tc.author:
787  */
788 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest013, TestSize.Level1)
789 {
790     /**
791      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
792      */
793     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
794     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
795     GestureEvent gestureEvent;
796     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
797     EXPECT_TRUE(dragDropProxy);
798 
799     /**
800      * @tc.steps: step2. call FindDragFrameNodeByPosition with frameNodes contains nullptr
801      * @tc.expected: step2.
802      */
803     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
804     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
805     dragDropManager->AddDragFrameNode(frameNodeNull->GetId(), frameNodeNull);
806     frameNodeNull.Reset();
807     auto frameNodeGeoNullId = ElementRegister::GetInstance()->MakeUniqueId();
808     auto frameNodeGeoNull =
809         AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeGeoNullId, AceType::MakeRefPtr<Pattern>());
810     frameNodeGeoNull->SetGeometryNode(nullptr);
811     dragDropManager->AddDragFrameNode(frameNodeGeoNull->GetId(), frameNodeGeoNull);
812     EXPECT_EQ(static_cast<int32_t>(dragDropManager->dragFrameNodes_.size()), 2);
813     auto targetFrameNode = dragDropManager->FindDragFrameNodeByPosition(GLOBAL_X, GLOBAL_Y);
814     EXPECT_FALSE(targetFrameNode);
815 
816     /**
817      * @tc.steps: step3. call FireOnDragEvent with type=DragEventType::DROP
818      * @tc.expected: step3. FireOnDrop will be called
819      */
820     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
821     auto eventHub = frameNode->GetEventHub<EventHub>();
822     std::string onDropInfo;
__anon25030b2f0c02(const RefPtr<OHOS::Ace::DragEvent>& , const std::string& ) 823     auto onDrop = [&onDropInfo](const RefPtr<OHOS::Ace::DragEvent>& /* dragEvent */, const std::string& /* info */) {
824         onDropInfo = EXTRA_INFO;
825     };
826     eventHub->SetOnDrop(std::move(onDrop));
827     PointerEvent point;
828     TouchEvent event;
829     event.x = 1.0f;
830     event.y = 2.0f;
831     dragDropManager->velocityTracker_.UpdateTouchPoint(event, false);
832     dragDropManager->FireOnDragEvent(frameNode, point, DragEventType::DROP, EXTRA_INFO);
833     EXPECT_EQ(onDropInfo, EXTRA_INFO);
834 
835     /**
836      * @tc.steps: step4. call FireOnItemDropEvent with type=DragEventType::DROP
837      * @tc.expected: step4. FireOnItemDrop will be called
838      */
839     ItemDragInfo itemDragInfo;
840     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
841     auto gridEvent = gridNode->GetEventHub<GridEventHub>();
842     std::string onItemDropInfo;
843     ItemDropFunc onItemDrop = [&onItemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f0d02(const ItemDragInfo& , int32_t , int32_t , bool ) 844                                   int32_t /* insertIndex */, bool /* isSuccess */) { onItemDropInfo = EXTRA_INFO; };
845     gridEvent->SetOnItemDrop(std::move(onItemDrop));
846     dragDropManager->FireOnItemDropEvent(gridNode, DragType::GRID, itemDragInfo, 0, 0, true);
847     EXPECT_EQ(onItemDropInfo, "");
848 
849     auto listNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
850     auto listEvent = listNode->GetEventHub<ListEventHub>();
851     std::string onItemDropInfoList;
852     ItemDropFunc onItemDropList = [&onItemDropInfoList](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
853                                       int32_t /* insertIndex */,
__anon25030b2f0e02(const ItemDragInfo& , int32_t , int32_t , bool ) 854                                       bool /* isSuccess */) { onItemDropInfoList = EXTRA_INFO; };
855     listEvent->SetOnItemDrop(std::move(onItemDropList));
856     dragDropManager->FireOnItemDropEvent(listNode, DragType::LIST, itemDragInfo, 0, 0, true);
857     EXPECT_EQ(onItemDropInfoList, EXTRA_INFO);
858 }
859 
860 /**
861  * @tc.name: DragDropManagerTest014
862  * @tc.desc: Test OnTextDragEnd
863  * @tc.type: FUNC
864  * @tc.author:
865  */
866 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest014, TestSize.Level1)
867 {
868     /**
869      * @tc.steps: step1. Create DragDropManager.
870      * @tc.expected: dragDropManager is not null.
871      */
872     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
873     ASSERT_NE(dragDropManager, nullptr);
874 
875     /**
876      * @tc.steps: step2. call OnTextDragEnd.
877      * @tc.expected: dragDropManager->currentId_ equals -1.
878      */
879     float globalX = 20.0f;
880     float globalY = 20.0f;
881     std::string extraInfo;
882     dragDropManager->OnTextDragEnd(globalX, globalY, extraInfo);
883     EXPECT_EQ(dragDropManager->currentId_, -1);
884 
885     /**
886      * @tc.steps: step3. construct TextFrameNode.
887      * @tc.expected: frameNode is not null.
888      */
889     auto frameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<TextPattern>());
890     ASSERT_NE(frameNode, nullptr);
891 
892     /**
893      * @tc.steps: step4. updat edragDropManager->textFieldDragFrameNodes_ .
894      */
895     dragDropManager->textFieldDragFrameNodes_.insert(std::make_pair(100, WeakPtr<NG::FrameNode>(frameNode)));
896 
897     /**
898      * @tc.steps: step5. call OnTextDragEnd.
899      * @tc.expected: dragDropManager->currentId_ equals -1.
900      */
901     dragDropManager->OnTextDragEnd(globalX, globalY, extraInfo);
902     auto dragFrameNode = dragDropManager->FindDragFrameNodeByPosition(globalX, globalY);
903     EXPECT_EQ(dragDropManager->currentId_, -1);
904 }
905 
906 /**
907  * @tc.name: DragDropManagerTest015
908  * @tc.desc: Test RestoreClipboardData
909  * @tc.type: FUNC
910  * @tc.author:
911  */
912 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest015, TestSize.Level1)
913 {
914     /**
915      * @tc.steps: step1. Create DragDropManager.
916      * @tc.expected: dragDropManager is not null.
917      */
918     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
919     ASSERT_NE(dragDropManager, nullptr);
920 
921     /**
922      * @tc.steps: step2. call CancelItemDrag.
923      * @tc.expected: dragDropManager->deleteDataCallback_ is not null.
924      */
925     dragDropManager->RestoreClipboardData();
926     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
927 
928     /**
929      * @tc.steps: step3. call CancelItemDrag(clipboard_ is null branch).
930      * @tc.expected: step3. dragDropManager->deleteDataCallback_ is not null.
931      */
932     dragDropManager->clipboard_ = nullptr;
933     dragDropManager->RestoreClipboardData();
934     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
935 
936     /**
937      * @tc.steps: step4. call CancelItemDrag(deleteDataCallback_ is not null branch).
938      * @tc.expected: step4. dragDropManager->deleteDataCallback_ is not null.
939      */
__anon25030b2f0f02(const std::string& data) 940     auto callback = [weakManager = AceType::WeakClaim(AceType::RawPtr(dragDropManager))](const std::string& data) {
941         auto dragDropManagerPtr = weakManager.Upgrade();
942         ASSERT_NE(dragDropManagerPtr, nullptr);
943         auto json = JsonUtil::ParseJsonString(data);
944         if (json->Contains("preData")) {
945             dragDropManagerPtr->clipboard_->SetData(json->GetString("preData"));
946         }
947     };
948     dragDropManager->deleteDataCallback_ = callback;
949     dragDropManager->RestoreClipboardData();
950     ASSERT_NE(dragDropManager->deleteDataCallback_, nullptr);
951 }
952 
953 /**
954  * @tc.name: DragDropManagerTest017
955  * @tc.desc: Test UpdateDragEvent
956  * @tc.type: FUNC
957  * @tc.author:
958  */
959 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest017, TestSize.Level1)
960 {
961     /**
962      * @tc.steps: step1. Create DragDropManager.
963      * @tc.expected: dragDropManager is not null.
964      */
965     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
966     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
967     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, frameNode);
968     ASSERT_NE(dragDropManager, nullptr);
969 
970     /**
971      * @tc.steps: step2. construct a OHOS::Ace::DragEvent.
972      * @tc.expected: event is not null.
973      */
974     auto event = AceType::MakeRefPtr<OHOS::Ace::DragEvent>();
975     ASSERT_NE(event, nullptr);
976 
977     /**
978      * @tc.steps: step3. call UpdateDragEvent.
979      * @tc.expected: pipeline is not null.
980      */
981     dragDropManager->UpdateDragEvent(event, PointerEvent(1, 1));
982     auto pipeline = PipelineContext::GetCurrentContext();
983     ASSERT_NE(pipeline, nullptr);
984 }
985 
986 /**
987  * @tc.name: DragDropManagerTest021
988  * @tc.desc: Test CreateTextDragDropProxy
989  * @tc.type: FUNC
990  * @tc.author:
991  */
992 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest021, TestSize.Level1)
993 {
994     /**
995      * @tc.steps: step1. construct a DragDropManager
996      * @tc.expected: dragDropManager is not null.
997      */
998     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
999     ASSERT_NE(dragDropManager, nullptr);
1000 
1001     /**
1002      * @tc.steps: step2. Call CreateTextDragDropProxy.
1003      * @tc.expected: CreateTextDragDropProxy the returns true value is not null.
1004      */
1005     auto textDragDropProxy = dragDropManager->CreateTextDragDropProxy();
1006     ASSERT_NE(textDragDropProxy, nullptr);
1007 }
1008 
1009 /**
1010  * @tc.name: DragDropManagerTest022
1011  * @tc.desc: Test FindDragFrameNodeByPosition in default branches
1012  * @tc.type: FUNC
1013  * @tc.author:
1014  */
1015 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest022, TestSize.Level1)
1016 {
1017     /**
1018      * @tc.steps: step1. construct a DragDropManager and create a DragWindow
1019      */
1020     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1021     RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1022     GestureEvent gestureEvent;
1023     auto dragDropProxy = dragDropManager->CreateAndShowDragWindow(customNode, gestureEvent);
1024     EXPECT_TRUE(dragDropProxy);
1025 
1026     /**
1027      * @tc.steps: step2. call FindDragFrameNodeByPosition with frameNodes contains nullptr
1028      * @tc.expected: step2.
1029      */
1030     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1031     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1032     dragDropManager->AddDragFrameNode(frameNodeNull->GetId(), frameNodeNull);
1033     frameNodeNull.Reset();
1034     auto frameNodeGeoNullId = ElementRegister::GetInstance()->MakeUniqueId();
1035     auto frameNodeGeoNull =
1036         AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeGeoNullId, AceType::MakeRefPtr<Pattern>());
1037     frameNodeGeoNull->SetGeometryNode(nullptr);
1038     dragDropManager->AddDragFrameNode(frameNodeGeoNull->GetId(), frameNodeGeoNull);
1039     EXPECT_EQ(static_cast<int32_t>(dragDropManager->dragFrameNodes_.size()), 2);
1040     auto targetFrameNode = dragDropManager->FindDragFrameNodeByPosition(GLOBAL_X, GLOBAL_Y);
1041     EXPECT_FALSE(targetFrameNode);
1042 }
1043 
1044 /**
1045  * @tc.name: DragDropManagerTest023
1046  * @tc.desc: Test OnDragStart(Point)
1047  * @tc.type: FUNC
1048  * @tc.author:
1049  */
1050 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest023, TestSize.Level1)
1051 {
1052     /**
1053      * @tc.steps: step1. construct a DragDropManager
1054      * @tc.expected: dragDropManager is not null.
1055      */
1056     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1057     ASSERT_NE(dragDropManager, nullptr);
1058 
1059     /**
1060      * @tc.steps: step2. Call OnDragStart with Point.
1061      * @tc.expected: dragDropManager->dragDropState_ is equal to DragDropMgrState::DRAGGING.
1062      */
1063     dragDropManager->OnDragStart(Point(15.0f, 15.0f));
1064     EXPECT_EQ(dragDropManager->dragDropState_, DragDropMgrState::DRAGGING);
1065 
1066     /**
1067      * @tc.steps: step3. Call OnDragStart with Point and FrameNode.
1068      * @tc.expected: dragDropManager->dragDropState_ is equal to DragDropMgrState::DRAGGING.
1069      */
1070     RefPtr<FrameNode> frameNode = nullptr;
1071     dragDropManager->OnDragStart(Point(15.0f, 15.0f), frameNode);
1072     EXPECT_EQ(dragDropManager->dragDropState_, DragDropMgrState::DRAGGING);
1073 }
1074 
1075 /**
1076  * @tc.name: DragDropManagerTest024
1077  * @tc.desc: Test ClearVelocityInfo
1078  * @tc.type: FUNC
1079  * @tc.author:
1080  */
1081 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest024, TestSize.Level1)
1082 {
1083     /**
1084      * @tc.steps: step1. construct a DragDropManager
1085      * @tc.expected: dragDropManager is not null.
1086      */
1087     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1088     ASSERT_NE(dragDropManager, nullptr);
1089 
1090     /**
1091      * @tc.steps: step2. Call ClearVelocityInfo.
1092      * @tc.expected: dragDropManager->velocityTracker_.isFirstPoint_ is equal to true.
1093      */
1094     dragDropManager->UpdateVelocityTrackerPoint(Point(15.0f, 15.0f), true);
1095     dragDropManager->ClearVelocityInfo();
1096     EXPECT_EQ(dragDropManager->velocityTracker_.isFirstPoint_, true);
1097 }
1098 
1099 /**
1100  * @tc.name: DragDropManagerTest025
1101  * @tc.desc: Test OnItemDragEnd out of eventHub is not an empty branche
1102  * @tc.type: FUNC
1103  * @tc.author:
1104  */
1105 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest025, TestSize.Level1)
1106 {
1107     /**
1108      * @tc.steps: step1. construct a DragDropManager.
1109      * @tc.expected: dragDropManager is not null.
1110      */
1111     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1112     ASSERT_NE(dragDropManager, nullptr);
1113 
1114     /**
1115      * @tc.steps: step2. construct a GridFrameNode.
1116      * @tc.expected: frameNode is not null.
1117      */
1118     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1119     ASSERT_TRUE(gridFrameNode);
1120 
1121     /**
1122      * @tc.steps: step3. Call OnItemDragEnd with DRAG_TYPE_GRID.
1123      * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1124      */
1125     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
1126     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_GRID);
1127     EXPECT_FALSE(dragDropManager->draggedFrameNode_);
1128 
1129     /**
1130      * @tc.steps: step4. construct a ListFrameNode.
1131      * @tc.expected: frameNode is not null.
1132      */
1133     auto listFrameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<ListPattern>());
1134     ASSERT_TRUE(listFrameNode);
1135 
1136     /**
1137      * @tc.steps: step5. Call OnItemDragEnd with DRAG_TYPE_LIST.
1138      * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1139      */
1140     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, listFrameNode);
1141     dragDropManager->OnItemDragEnd(GLOBAL_X, GLOBAL_Y, DRAGGED_INDEX, DRAG_TYPE_LIST);
1142     EXPECT_FALSE(dragDropManager->draggedFrameNode_);
1143 }
1144 
1145 /**
1146  * @tc.name: DragDropManagerTest026
1147  * @tc.desc: Test GetExtraInfo
1148  * @tc.type: FUNC
1149  * @tc.author:
1150  */
1151 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest026, TestSize.Level1)
1152 {
1153     /**
1154      * @tc.steps: step1. construct a DragDropManager
1155      * @tc.expected: dragDropManager is not null.
1156      */
1157     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1158     ASSERT_NE(dragDropManager, nullptr);
1159 
1160     /**
1161      * @tc.steps: step2. Call GetExtraInfo.
1162      * @tc.expected: extraInfo is empty.
1163      */
1164     auto extraInfo = dragDropManager->GetExtraInfo();
1165     EXPECT_TRUE(extraInfo.empty());
1166 }
1167 
1168 /**
1169  * @tc.name: DragDropManagerTest027
1170  * @tc.desc: Test SetExtraInfo
1171  * @tc.type: FUNC
1172  * @tc.author:
1173  */
1174 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest027, TestSize.Level1)
1175 {
1176     /**
1177      * @tc.steps: step1. construct a DragDropManager
1178      * @tc.expected: dragDropManager is not null.
1179      */
1180     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1181     ASSERT_NE(dragDropManager, nullptr);
1182 
1183     /**
1184      * @tc.steps: step2. Call SetExtraInfo.
1185      * @tc.expected: dragDropManager->extraInfo_ is equal to "extraInfo".
1186      */
1187     dragDropManager->SetExtraInfo("extraInfo");
1188     EXPECT_EQ(dragDropManager->extraInfo_, "extraInfo");
1189 }
1190 
1191 /**
1192  * @tc.name: DragDropManagerTest028
1193  * @tc.desc: Test ClearExtraInfo
1194  * @tc.type: FUNC
1195  * @tc.author:
1196  */
1197 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest028, TestSize.Level1)
1198 {
1199     /**
1200      * @tc.steps: step1. construct a DragDropManager
1201      * @tc.expected: dragDropManager is not null.
1202      */
1203     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1204     ASSERT_NE(dragDropManager, nullptr);
1205 
1206     /**
1207      * @tc.steps: step2. Call ClearExtraInfo.
1208      * @tc.expected: dragDropManager->extraInfo_ is empty.
1209      */
1210     dragDropManager->SetExtraInfo("extraInfo");
1211     dragDropManager->ClearExtraInfo();
1212     EXPECT_TRUE(dragDropManager->extraInfo_.empty());
1213 }
1214 
1215 /**
1216  * @tc.name: DragDropManagerTest029
1217  * @tc.desc: Test CancelItemDrag in draggedGridFrameNode branches
1218  * @tc.type: FUNC
1219  * @tc.author:
1220  */
1221 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest029, TestSize.Level1)
1222 {
1223     /**
1224      * @tc.steps: step1. Create DragDropManager.
1225      * @tc.expected: dragDropManager is not null.
1226      */
1227     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1228     ASSERT_NE(dragDropManager, nullptr);
1229 
1230     /**
1231      * @tc.steps: step2. call CancelItemDrag.
1232      * @tc.expected: dragDropManager->draggedGridFrameNode_ is false.
1233      */
1234     dragDropManager->CancelItemDrag();
1235     EXPECT_FALSE(dragDropManager->draggedGridFrameNode_);
1236 
1237     /**
1238      * @tc.steps: step3. Create FrameNode.
1239      * @tc.expected: frameNode is not null.
1240      */
1241     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1242     ASSERT_NE(frameNode, nullptr);
1243 
1244     /**
1245      * @tc.steps: step4. call CancelItemDrag.
1246      * @tc.expected: dragDropManager->draggedGridFrameNode_ is true.
1247      */
1248     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, frameNode);
1249     dragDropManager->CancelItemDrag();
1250     EXPECT_TRUE(dragDropManager->draggedGridFrameNode_);
1251 }
1252 
1253 /**
1254  * @tc.name: DragDropManagerTest0291
1255  * @tc.desc: Test CancelItemDrag in listEventHub branches
1256  * @tc.type: FUNC
1257  * @tc.author:
1258  */
1259 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0291, TestSize.Level1)
1260 {
1261     /**
1262      * @tc.steps: step1. Create DragDropManager.
1263      * @tc.expected: dragDropManager is not null.
1264      */
1265     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1266     ASSERT_NE(dragDropManager, nullptr);
1267 
1268     /**
1269      * @tc.steps: step2. Create FrameNode.
1270      * @tc.expected: listFrameNode is not null.
1271      */
1272     auto listFrameNode = AceType::MakeRefPtr<FrameNode>(LIST_TAG, -1, AceType::MakeRefPtr<ListPattern>());
1273     ASSERT_NE(listFrameNode, nullptr);
1274 
1275     /**
1276      * @tc.steps: step3. update draggedGridFrameNode_ with listFrameNode.
1277      */
1278     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, listFrameNode);
1279 
1280     /**
1281      * @tc.steps: step4. call CancelItemDrag.
1282      * * @tc.expected: listEventHub is TRUE.
1283      */
1284     dragDropManager->CancelItemDrag();
1285     auto listEventHub = dragDropManager->draggedGridFrameNode_->GetEventHub<ListEventHub>();
1286     EXPECT_TRUE(listEventHub);
1287 }
1288 
1289 /**
1290  * @tc.name: DragDropManagerTest0292
1291  * @tc.desc: Test CancelItemDrag in gridEventHub branches
1292  * @tc.type: FUNC
1293  * @tc.author:
1294  */
1295 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0292, TestSize.Level1)
1296 {
1297     /**
1298      * @tc.steps: step1. Create DragDropManager.
1299      * @tc.expected: dragDropManager is not null.
1300      */
1301     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1302     ASSERT_NE(dragDropManager, nullptr);
1303 
1304     /**
1305      * @tc.steps: step2. Create FrameNode.
1306      * @tc.expected: gridFrameNode is not null.
1307      */
1308     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1309     ASSERT_NE(gridFrameNode, nullptr);
1310 
1311     /**
1312      * @tc.steps: step3. update draggedGridFrameNode_ with gridFrameNode.
1313      */
1314     dragDropManager->OnItemDragStart(GLOBAL_X, GLOBAL_Y, gridFrameNode);
1315 
1316     /**
1317      * @tc.steps: step4. call CancelItemDrag.
1318      * * @tc.expected: gridEventHub is TRUE.
1319      */
1320     dragDropManager->CancelItemDrag();
1321     auto gridEventHub = dragDropManager->draggedGridFrameNode_->GetEventHub<GridEventHub>();
1322     EXPECT_TRUE(gridEventHub);
1323 }
1324 
1325 /**
1326  * @tc.name: DragDropManagerTest030
1327  * @tc.desc: Test FireOnItemDragEvent in DragType::GRID branches
1328  * @tc.type: FUNC
1329  * @tc.author:
1330  */
1331 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest030, TestSize.Level1)
1332 {
1333     /**
1334      * @tc.steps: step1. Create DragDropManager.
1335      * @tc.expected: dragDropManager is not null.
1336      */
1337     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1338     ASSERT_NE(dragDropManager, nullptr);
1339 
1340     /**
1341      * @tc.steps: step2. Create FrameNode.
1342      * @tc.expected: gridFrameNode is not null.
1343      */
1344     auto gridFrameNode = AceType::MakeRefPtr<FrameNode>(GRID_TAG, -1, AceType::MakeRefPtr<GridPattern>());
1345     ASSERT_NE(gridFrameNode, nullptr);
1346 
1347     /**
1348      * @tc.steps: step3. call FireOnItemDragEvent with DragEventType::ENTER.
1349      * * @tc.expected: eventHub is TRUE.
1350      */
1351     OHOS::Ace::ItemDragInfo itemDragInfo;
1352     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType::ENTER, 0, 0);
1353     auto eventHub = gridFrameNode->GetEventHub<GridEventHub>();
1354     EXPECT_TRUE(eventHub);
1355 
1356     /**
1357      * @tc.steps: step4. call FireOnItemDragEvent with DragEventType::MOVE.
1358      * * @tc.expected: eventHub is TRUE.
1359      */
1360     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType::MOVE, 0, 0);
1361     EXPECT_TRUE(eventHub);
1362 
1363     /**
1364      * @tc.steps: step5. call FireOnItemDragEvent with DragEventType::default.
1365      * * @tc.expected: eventHub is TRUE.
1366      */
1367     dragDropManager->FireOnItemDragEvent(gridFrameNode, DragType::GRID, itemDragInfo, DragEventType(10), 0, 0);
1368     EXPECT_TRUE(eventHub);
1369 }
1370 
1371 /**
1372  * @tc.name: DragDropManagerTest031
1373  * @tc.desc: Test FindTargetInChildNodes is an empty branch of parentNode
1374  * @tc.type: FUNC
1375  * @tc.author:
1376  */
1377 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest031, TestSize.Level1)
1378 {
1379     /**
1380      * @tc.steps: step1. Create DragDropManager.
1381      * @tc.expected: dragDropManager is not null.
1382      */
1383     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1384     ASSERT_NE(dragDropManager, nullptr);
1385 
1386     /**
1387      * @tc.steps: step2. call FindTargetInChildNodes(parentNode is empty).
1388      * @tc.expected: childFindResult is false.
1389      */
1390     RefPtr<UINode> customNode = nullptr;
1391     std::vector<RefPtr<FrameNode>> hitFrameNodes;
1392     auto childFindResult = dragDropManager->FindTargetInChildNodes(customNode, hitFrameNodes, true);
1393     EXPECT_FALSE(childFindResult);
1394 }
1395 
1396 /**
1397  * @tc.name: DragDropManagerTest033
1398  * @tc.desc: Test FindTargetInChildNodes
1399  * @tc.type: FUNC
1400  * @tc.author:
1401  */
1402 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest033, TestSize.Level1)
1403 {
1404     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1405     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1406     auto frameNodeNull = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1407     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1408     geometryNode->SetFrameSize(FRAME_SIZE);
1409     frameNodeNull->SetGeometryNode(geometryNode);
1410     auto pipelineTmp = NG::PipelineContext::GetCurrentContext();
1411     auto parentNodeTmp = pipelineTmp->GetRootElement();
1412     auto parentFrameNodeTmp = AceType::DynamicCast<FrameNode>(parentNodeTmp);
1413     parentFrameNodeTmp->frameChildren_.insert(WeakPtr<NG::FrameNode>(frameNodeNull));
1414     dragDropManager->AddGridDragFrameNode(frameNodeNull->GetId(), frameNodeNull);
1415     std::map<int32_t, WeakPtr<FrameNode>> frameNodes = dragDropManager->gridDragFrameNodes_;
1416     PointF point(GLOBAL_X, GLOBAL_Y);
1417     std::vector<RefPtr<FrameNode>> hitFrameNodes;
1418     for (auto iterOfFrameNode = frameNodes.begin(); iterOfFrameNode != frameNodes.end(); iterOfFrameNode++) {
1419         auto frameNode = iterOfFrameNode->second.Upgrade();
1420         auto geometryNode = frameNode->GetGeometryNode();
1421         if (!geometryNode) {
1422             continue;
1423         }
1424         auto globalFrameRect = geometryNode->GetFrameRect();
1425         globalFrameRect.SetOffset(frameNode->GetTransformRelativeOffset());
1426         if (globalFrameRect.IsInRegion(point)) {
1427             hitFrameNodes.push_back(frameNode);
1428         }
1429     }
1430     auto pipeline = NG::PipelineContext::GetCurrentContext();
1431     auto manager = pipeline->GetOverlayManager();
1432     auto parentNode = pipeline->GetRootElement();
1433     auto parentFrameNode = AceType::DynamicCast<FrameNode>(parentNode);
1434     auto children = parentFrameNode->GetFrameChildren();
1435     EXPECT_FALSE(children.empty());
1436     for (auto iter = children.rbegin(); iter != children.rend(); iter++) {
1437         auto child = iter->Upgrade();
1438         if (child == nullptr) {
1439             continue;
1440         }
1441         auto childNode = AceType::DynamicCast<UINode>(child);
1442         auto childFindResult = dragDropManager->FindTargetInChildNodes(childNode, hitFrameNodes, true);
1443         EXPECT_FALSE(childFindResult);
1444     }
1445     for (auto iter : hitFrameNodes) {
1446         EXPECT_NE(parentFrameNode, iter);
1447     }
1448     auto result = dragDropManager->FindTargetInChildNodes(parentNode, hitFrameNodes, true);
1449     EXPECT_FALSE(result);
1450 }
1451 
1452 /**
1453  * @tc.name: DragDropManagerTest034
1454  * @tc.desc: Test PrintDragFrameNode.
1455  * @tc.type: FUNC
1456  * @tc.author:
1457  */
1458 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest034, TestSize.Level1)
1459 {
1460     /**
1461      * @tc.steps: step1. construct a DragDropManager
1462      * @tc.expected: dragDropManager is not null.
1463      */
1464     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1465     ASSERT_NE(dragDropManager, nullptr);
1466 
1467     OHOS::Ace::PointerEvent point;
1468     RefPtr<FrameNode> dragFrameNode = nullptr;
1469     dragDropManager->OnDragStart({ GLOBAL_X, GLOBAL_Y }, dragFrameNode);
1470 
1471     /**
1472      * @tc.steps: step2. call PrintDragFrameNode with dragFrameNode and point.
1473      * * @tc.expected: dragDropManager->draggedFrameNode_ is false.
1474      */
1475     dragDropManager->PrintDragFrameNode(point, dragFrameNode);
1476     ASSERT_FALSE(dragDropManager->draggedFrameNode_);
1477 }
1478 
1479 /**
1480  * @tc.name: DragDropManagerTest035
1481  * @tc.desc: Test FireOnItemDropEvent is empty branchs.
1482  * @tc.type: FUNC
1483  * @tc.author:
1484  */
1485 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest035, TestSize.Level1)
1486 {
1487     /**
1488      * @tc.steps: step1. construct a DragDropManager.
1489      * @tc.expected: dragDropManager is not null.
1490      */
1491     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1492     ASSERT_NE(dragDropManager, nullptr);
1493 
1494     /**
1495      * @tc.steps: step1. construct a DragDropManager.
1496      * @tc.expected: step2. FireOnItemDropEvent.
1497      */
1498     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1499     auto draggedNode = dragDropManager->draggedFrameNode_;
1500     auto preTargetNode = dragDropManager->preTargetFrameNode_;
1501     OHOS::Ace::ItemDragInfo itemDragInfo;
1502 
1503     /**
1504      * @tc.steps: step2. call OnDragStart with DragType::GRID and frameNode.
1505      * @tc.expected: step2. draggedNode is false.
1506      */
1507     dragDropManager->FireOnItemDropEvent(frameNode, DragType::GRID, itemDragInfo, 0, 0, true);
1508     ASSERT_FALSE(draggedNode);
1509 
1510     /**
1511      * @tc.steps: step2. call OnDragStart with DragType::LIST and frameNode.
1512      * @tc.expected: step2. raggedNode is false.
1513      */
1514     dragDropManager->FireOnItemDropEvent(frameNode, DragType::LIST, itemDragInfo, 0, 0, true);
1515     ASSERT_FALSE(draggedNode);
1516 }
1517 
1518 /**
1519  * @tc.name: DragDropManagerTest037
1520  * @tc.desc: Test GetItemIndex out of eventHub->CheckPostionInGrid is a true branch.
1521  * @tc.type: FUNC
1522  * @tc.author:
1523  */
1524 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest037, TestSize.Level1)
1525 {
1526     /**
1527      * @tc.steps: step1. construct a DragDropManager.
1528      * @tc.expected: dragDropManager is not null.
1529      */
1530     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1531     ASSERT_NE(dragDropManager, nullptr);
1532 
1533     /**
1534      * @tc.steps: step2. construct a GeometryNode,updates MarginFrameOffset and FrameSize.
1535      * @tc.expected: geometryNode is not null.
1536      */
1537     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1538     ASSERT_NE(geometryNode, nullptr);
1539     geometryNode->SetMarginFrameOffset(FRAME_OFFSET);
1540     geometryNode->SetFrameSize(FRAME_SIZE);
1541 
1542     /**
1543      * @tc.steps: step3. construct a FrameNode with GeometryNode.
1544      * @tc.expected: gridNode is not null.
1545      */
1546     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1547     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1548     ASSERT_NE(dragDropManager, nullptr);
1549     gridNode->SetGeometryNode(geometryNode);
1550 
1551     /**
1552      * @tc.steps: step4. construct a GridEventHub and updates OnItemDrop and AttachHost.
1553      */
1554     ItemDragInfo itemDragInfo;
1555     auto gridEvent = gridNode->GetEventHub<GridEventHub>();
1556     std::string onItemDropInfo;
1557     ItemDropFunc onItemDrop = [&onItemDropInfo](const ItemDragInfo& /* dragInfo */, int32_t /* itemIndex */,
__anon25030b2f1002(const ItemDragInfo& , int32_t , int32_t , bool ) 1558                                   int32_t /* insertIndex */, bool /* isSuccess */) { onItemDropInfo = EXTRA_INFO; };
1559     gridEvent->SetOnItemDrop(std::move(onItemDrop));
1560     gridEvent->AttachHost(WeakPtr<NG::FrameNode>(gridNode));
1561 
1562     /**
1563      * @tc.steps: step5. call GetItemIndex with DragEventType::GRID and gridNode.
1564      * @tc.expected: retFlag is true.
1565      */
1566     dragDropManager->draggedGridFrameNode_ = gridNode;
1567     dragDropManager->GetItemIndex(gridNode, DragType::GRID, 0, 0);
1568     auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
1569     ASSERT_NE(mockRenderContext, nullptr);
1570     gridNode->renderContext_ = mockRenderContext;
1571     mockRenderContext->rect_ = { 0.0f, 0.0f, 1.0f, 1.0f };
1572     bool retFlag = gridEvent->CheckPostionInGrid(0, 0);
1573     EXPECT_TRUE(retFlag);
1574 }
1575 
1576 /**
1577  * @tc.name: DragDropManagerTest038
1578  * @tc.desc: Test GetItemIndex out of itemFrameNode is a true branch.
1579  * @tc.type: FUNC
1580  * @tc.author:
1581  */
1582 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest038, TestSize.Level1)
1583 {
1584     /**
1585      * @tc.steps: step1. construct a DragDropManager.
1586      * @tc.expected: dragDropManager is not null.
1587      */
1588     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1589     ASSERT_NE(dragDropManager, nullptr);
1590 
1591     /**
1592      * @tc.steps: step2. construct a GeometryNode,updates MarginFrameOffset and FrameSize.
1593      * @tc.expected: geometryNode is not null.
1594      */
1595     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
1596     ASSERT_NE(geometryNode, nullptr);
1597     geometryNode->SetMarginFrameOffset(FRAME_OFFSET);
1598     geometryNode->SetFrameSize(FRAME_SIZE);
1599 
1600     /**
1601      * @tc.steps: step3. construct a FrameNode with GeometryNode.
1602      * @tc.expected: gridNode is not null.
1603      */
1604     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1605     auto gridNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<GridPattern>());
1606     ASSERT_NE(gridNode, nullptr);
1607     gridNode->SetGeometryNode(geometryNode);
1608 
1609     /**
1610      * @tc.steps: step4. construct a FrameNode.
1611      */
1612     auto childId = ElementRegister::GetInstance()->MakeUniqueId();
1613     auto childNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, childId, AceType::MakeRefPtr<Pattern>());
1614     childNode->SetGeometryNode(geometryNode);
1615     childNode->isActive_ = true;
1616 
1617     /**
1618      * @tc.steps: step5. gridNode AddChild with childNode.
1619      */
1620     gridNode->AddChild(childNode);
1621 
1622     /**
1623      * @tc.steps: step6. call GetItemIndex with DragEventType::GRID and gridNode.
1624      * @tc.expected: retFlag is true.
1625      */
1626     dragDropManager->draggedGridFrameNode_ = gridNode;
1627     dragDropManager->GetItemIndex(gridNode, DragType::GRID, 0, 0);
1628     bool retFlag = gridNode->FindChildByPosition(0, 0);
1629     EXPECT_TRUE(retFlag);
1630 }
1631 
1632 /**
1633  * @tc.name: DragDropManagerTest039
1634  * @tc.desc: Test CheckParentVisible out of parent is a true branch.
1635  * @tc.type: FUNC
1636  * @tc.author:
1637  */
1638 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest039, TestSize.Level1)
1639 {
1640     /**
1641      * @tc.steps: step1. construct a DragDropManager.
1642      * @tc.expected: dragDropManager is not null.
1643      */
1644     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1645     ASSERT_NE(dragDropManager, nullptr);
1646 
1647     /**
1648      * @tc.steps: step2. construct a frameNode and update attributes.
1649      * IsVisible is false branch
1650      */
1651     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1652     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1653     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1654     auto eventHub = frameNode->GetEventHub<EventHub>();
1655     eventHub->SetEnabled(true);
1656 
1657     /**
1658      * @tc.steps: step3. update nodesForDragNotify_.
1659      * @tc.expected: nodesForDragNotify_ is not empty.
1660      */
1661     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1662     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1663 
1664     /**
1665      * @tc.steps: step4. update NotifyDragEvent.
1666      * @tc.expected: notifyEvent attributes to be the set value.
1667      */
1668     RefPtr<NotifyDragEvent> notifyEvent = AceType::MakeRefPtr<NotifyDragEvent>();
1669     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1670     EXPECT_DOUBLE_EQ(notifyEvent->GetX(), 1.0);
1671     EXPECT_DOUBLE_EQ(notifyEvent->GetY(), 1.0);
1672 
1673     /**
1674      * @tc.steps: step5. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of isVisible.
1675      * @tc.expected: isVisible is false.
1676      */
1677     dragDropManager->NotifyDragRegisterFrameNode(
1678         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1679     bool isVisible = frameNode->IsVisible();
1680     EXPECT_FALSE(isVisible);
1681 
1682     /**
1683      * @tc.steps: step6. update nodesForDragNotify_.
1684      * @tc.expected: nodesForDragNotify_ is not empty.
1685      */
1686     dragDropManager->UnRegisterDragStatusListener(frameNode->GetId());
1687     EXPECT_TRUE(dragDropManager->nodesForDragNotify_.empty());
1688     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1689     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1690 
1691     /**
1692      * @tc.steps: step7. update frameNode attribute.
1693      * @tc.expected: parent is not null.
1694      */
1695     auto customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1696     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::VISIBLE, true);
1697     frameNode->SetParent(WeakPtr<NG::UINode>(customNode));
1698     auto parent = frameNode->GetParent();
1699     EXPECT_TRUE(parent);
1700     parent->SetDepth(32);
1701     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1702 
1703     /**
1704      * @tc.steps: step8. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of parentFrameNode.
1705      * @tc.expected: parent->GetDepth() returns a value that is not equal to 1.
1706      */
1707     dragDropManager->NotifyDragRegisterFrameNode(
1708         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1709     EXPECT_NE(parent->GetDepth(), 1);
1710 }
1711 
1712 /**
1713  * @tc.name: DragDropManagerTest0391
1714  * @tc.desc: Test CheckParentVisible out of parentFrameNode  is a true branch.
1715  * @tc.type: FUNC
1716  * @tc.author:
1717  */
1718 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest0391, TestSize.Level1)
1719 {
1720     /**
1721      * @tc.steps: step1. construct a DragDropManager.
1722      * @tc.expected: dragDropManager is not null.
1723      */
1724     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1725     ASSERT_NE(dragDropManager, nullptr);
1726 
1727     /**
1728      * @tc.steps: step2. construct a frameNode and update attributes.
1729      * IsVisible is false branch
1730      */
1731     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1732     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1733     auto customNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, -1, AceType::MakeRefPtr<Pattern>());
1734     customNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1735     frameNode->SetParent(WeakPtr<NG::UINode>(customNode));
1736     auto parent = frameNode->GetParent();
1737     EXPECT_TRUE(parent);
1738     parent->SetDepth(32);
1739     EXPECT_NE(parent->GetDepth(), 1);
1740 
1741     /**
1742      * @tc.steps: step4. update nodesForDragNotify_ and NotifyDragEvent.
1743      * @tc.expected: nodesForDragNotify_ is not empty.
1744      */
1745     RefPtr<NotifyDragEvent> notifyEvent = AceType::MakeRefPtr<NotifyDragEvent>();
1746     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1747     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1748     dragDropManager->UpdateNotifyDragEvent(notifyEvent, Point(1.0f, 1.0f), DragEventType::START);
1749 
1750     /**
1751      * @tc.steps: step5. call NotifyDragRegisterFrameNode branches of CheckParentVisible out of parentFrameNode(is
1752      * false).
1753      * @tc.expected: customNode->IsVisible() returns a value that is not equal to false.
1754      */
1755     dragDropManager->NotifyDragRegisterFrameNode(
1756         dragDropManager->nodesForDragNotify_, DragEventType::START, notifyEvent);
1757     EXPECT_FALSE(customNode->IsVisible());
1758 }
1759 
1760 /**
1761  * @tc.name: DragDropManagerTest040
1762  * @tc.desc: Test FindHitFrameNodes in frameNode branchs
1763  * @tc.type: FUNC
1764  * @tc.author:
1765  */
1766 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest040, TestSize.Level1)
1767 {
1768     /**
1769      * @tc.steps: step1. construct a DragDropManager.
1770      * @tc.expected: dragDropManager is not null.
1771      */
1772     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1773     ASSERT_NE(dragDropManager, nullptr);
1774 
1775     /**
1776      * @tc.steps: step2. construct a frameNode and update attributes.
1777      * @tc.expected: geometryNode is null.
1778      */
1779     auto frameNodeNullId = ElementRegister::GetInstance()->MakeUniqueId();
1780     auto frameNode = AceType::MakeRefPtr<FrameNode>(NODE_TAG, frameNodeNullId, AceType::MakeRefPtr<Pattern>());
1781     frameNode->SetActive(true);
1782     frameNode->geometryNode_ = nullptr;
1783     auto geometryNode = frameNode->GetGeometryNode();
1784     EXPECT_FALSE(geometryNode);
1785 
1786     /**
1787      * @tc.steps: step3. update nodesForDragNotify_.
1788      * @tc.expected: nodesForDragNotify_ is not empty.
1789      */
1790     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1791     EXPECT_FALSE(dragDropManager->nodesForDragNotify_.empty());
1792 
1793     /**
1794      * @tc.steps: step4. call FindHitFrameNodes out of geometryNode are false branches.
1795      * @tc.expected: frameNodeList is empty.
1796      */
1797     auto frameNodeList = dragDropManager->FindHitFrameNodes(Point(1.0f, 1.0f));
1798     EXPECT_TRUE(frameNodeList.empty());
1799 
1800     /**
1801      * @tc.steps: step5. clear nodesForDragNotify_.
1802      */
1803     dragDropManager->UnRegisterDragStatusListener(frameNode->GetId());
1804     EXPECT_TRUE(dragDropManager->nodesForDragNotify_.empty());
1805 
1806     /**
1807      * @tc.steps: step6. updates frameNode and nodesForDragNotify_.
1808      */
1809     frameNode->SetActive(false);
1810     frameNode->GetLayoutProperty()->UpdateVisibility(VisibleType::INVISIBLE, true);
1811     dragDropManager->RegisterDragStatusListener(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
1812 
1813     /**
1814      * @tc.steps: step7. call FindHitFrameNodes out of IsVisible are false branches.
1815      * @tc.expected: frameNodeList is empty.
1816      */
1817     frameNodeList = dragDropManager->FindHitFrameNodes(Point(1.0f, 1.0f));
1818     EXPECT_TRUE(frameNodeList.empty());
1819 }
1820 
1821 /**
1822  * @tc.name: DragDropManagerTest041
1823  * @tc.desc: Test SetDragDampStartPoint and GetDragDampStartPoint
1824  * @tc.type: FUNC
1825  * @tc.author:
1826  */
1827 HWTEST_F(DragDropManagerTestNg, DragDropManagerTest041, TestSize.Level1)
1828 {
1829     /**
1830      * @tc.steps: step1. construct a DragDropManager.
1831      * @tc.expected: dragDropManager is not null.
1832      */
1833     auto dragDropManager = AceType::MakeRefPtr<DragDropManager>();
1834     ASSERT_NE(dragDropManager, nullptr);
1835 
1836     /**
1837      * @tc.steps: step2. create a point, than call SetDragDampStartPoint.
1838      * @tc.expected: The values of dragDampStartPoint_ and point are equal
1839      */
1840     Point point(1.0f, 1.0f);
1841     dragDropManager->SetDragDampStartPoint(point);
1842     EXPECT_EQ(dragDropManager->dragDampStartPoint_, point);
1843 
1844     /**
1845      * @tc.steps: step3. create a point, than call GetDragDampStartPoint.
1846      * @tc.expected: The return values of dragDampStartPoint_ and point are equal
1847      */
1848     Point point2(2.0f, 2.0f);
1849     dragDropManager->dragDampStartPoint_ = point2;
1850     auto returnPoint = dragDropManager->GetDragDampStartPoint();
1851     EXPECT_EQ(returnPoint, point2);
1852 }
1853 } // namespace OHOS::Ace::NG
1854