• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <optional>
17 
18 #include "gtest/gtest.h"
19 #include "test/mock/base/mock_drag_window.h"
20 #include "test/mock/base/mock_pixel_map.h"
21 #include "test/mock/core/common/mock_container.h"
22 #include "test/mock/core/common/mock_interaction_interface.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24 
25 #include "base/subwindow/subwindow_manager.h"
26 #include "core/common/ace_engine.h"
27 #include "core/components_ng/manager/drag_drop/drag_drop_controller_func_wrapper.h"
28 #include "core/components_ng/manager/drag_drop/drag_drop_func_wrapper.h"
29 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h"
30 #include "core/components_ng/manager/drag_drop/utils/drag_animation_helper.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 namespace OHOS::Ace::NG {
35 namespace {
36 RefPtr<DragWindow> MOCK_DRAG_WINDOW;
37 constexpr float WIDTH = 400.0f;
38 constexpr float HEIGHT = 400.0f;
39 constexpr int32_t RESERVED_DEVICEID = 0xAAAAAAFF;
40 const OffsetF COORDINATE_OFFSET(WIDTH, HEIGHT);
41 } // namespace
42 
43 class DragControllerFuncWrapperTestNg : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47 };
48 
SetUpTestCase()49 void DragControllerFuncWrapperTestNg::SetUpTestCase()
50 {
51     MockPipelineContext::SetUp();
52     MockContainer::SetUp(NG::PipelineContext::GetCurrentContext());
53     MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
54 }
55 
TearDownTestCase()56 void DragControllerFuncWrapperTestNg::TearDownTestCase()
57 {
58     MockPipelineContext::TearDown();
59     MockContainer::TearDown();
60     MOCK_DRAG_WINDOW = nullptr;
61 }
62 
63 /**
64  * @tc.name: DragDropControllerFuncWrapperTest001
65  * @tc.desc: Test GetUpdateDragMovePosition afther UpdateDragMovePosition. Position is equal to OffsetF() because
66  * lastDragMovePosition_ is equal to OffsetF().
67  * @tc.type: FUNC
68  * @tc.author:
69  */
70 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest001, TestSize.Level1)
71 {
72     /**
73      * @tc.steps: step1. Set the update drag move position
74      */
75     int32_t containerId = 100;
76 
77     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
78     ASSERT_NE(pipelineContext, nullptr);
79     auto manager = pipelineContext->GetDragDropManager();
80     OffsetF position(10.0f, 20.0f);
81     manager->UpdateDragMovePosition(position, false);
82 
83     /**
84      * @tc.steps: step2. call GetUpdateDragMovePosition
85      * @tc.expected: step2. drag move position is equal to OffsetF().
86      */
87     auto offset = NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId);
88     EXPECT_EQ(offset, NG::OffsetF());
89 }
90 
91 /**
92  * @tc.name: DragDropControllerFuncWrapperTest002
93  * @tc.desc: Test ResetContextMenuDragPosition. Position is equal to OffsetF().
94  * @tc.type: FUNC
95  * @tc.author:
96  */
97 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest002, TestSize.Level1)
98 {
99     /**
100      * @tc.steps: step1. Set the update drag move position
101      */
102     int32_t containerId = 100;
103 
104     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
105     ASSERT_NE(pipelineContext, nullptr);
106     auto manager = pipelineContext->GetDragDropManager();
107     ASSERT_NE(manager, nullptr);
108     OffsetF position(10.0f, 20.0f);
109     manager->UpdateDragMovePosition(position, false);
110 
111     /**
112      * @tc.steps: step2. call ResetContextMenuDragPosition
113      * @tc.expected: step2. drag move position is equal to OffsetF().
114      */
115     NG::DragControllerFuncWrapper::ResetContextMenuDragPosition(containerId);
116     auto offset = manager->GetUpdateDragMovePosition();
117     EXPECT_EQ(offset, NG::OffsetF());
118 }
119 
120 /**
121  * @tc.name: DragDropControllerFuncWrapperTest003
122  * @tc.desc: Test GetOriginNodeOffset when hasTouchPoint is true or false.
123  * @tc.type: FUNC
124  * @tc.author:
125  */
126 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest003, TestSize.Level1)
127 {
128     /**
129      * @tc.steps: step1. Prepare darg data and asyncCtxData.
130      */
131     int32_t containerId = 100;
132     bool hasTouchPoint = true;
133     DragPointerEvent dragPointerEvent(100, 100);
134     NG::DragPreviewOption previewOption;
135     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
136     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
137     void* voidPtr = static_cast<void*>(new char[0]);
138     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
139 
140     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
141         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
142     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
143         touchPoint, pixelMapList };
144 
145     /**
146      * @tc.steps: step2. call GetOriginNodeOffset when hasTouchPoint is true.
147      * @tc.expected: step2. originNodeOffset is equal to NG::OffsetF(90, 90).
148      */
149     auto pointPosition =
150         NG::DragDropFuncWrapper::GetPointRelativeToMainWindow(asyncCtxData.dragPointerEvent.GetPoint());
151     auto touchPointOffset = NG::DragControllerFuncWrapper::GetTouchPointOffset(data, asyncCtxData);
152     EXPECT_EQ(touchPointOffset, NG::OffsetF(10, 10));
153     auto pixelMapScaledOffset =
154         NG::DragControllerFuncWrapper::GetPixelMapScaledOffset(pointPosition, data, asyncCtxData);
155     EXPECT_EQ(pixelMapScaledOffset, NG::OffsetF(90, 90));
156     auto originNodeOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
157     EXPECT_EQ(originNodeOffset, NG::OffsetF(0, 0));
158 
159     /**
160      * @tc.steps: step3. call GetOriginNodeOffset when hasTouchPoint is false.
161      * @tc.expected: step3. originNodeOffset is equal to NG::OffsetF(100, 100).
162      */
163     hasTouchPoint = false;
164     asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption, touchPoint, pixelMapList };
165     touchPointOffset = NG::DragControllerFuncWrapper::GetTouchPointOffset(data, asyncCtxData);
166     EXPECT_EQ(touchPointOffset, NG::OffsetF(-0, -0));
167     pixelMapScaledOffset = NG::DragControllerFuncWrapper::GetPixelMapScaledOffset(pointPosition, data, asyncCtxData);
168     EXPECT_EQ(pixelMapScaledOffset, NG::OffsetF(100, 100));
169     originNodeOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
170     EXPECT_EQ(originNodeOffset, NG::OffsetF(0, 0));
171 }
172 
173 /**
174  * @tc.name: DragDropControllerFuncWrapperTest004
175  * @tc.desc: Test UpdatePreviewPositionAndScale. ImageContext's ClickEffectLevelValue can be updated to LIGHT.
176  * @tc.type: FUNC
177  * @tc.author:
178  */
179 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest004, TestSize.Level1)
180 {
181     /**
182      * @tc.steps: step1. Prepare darg data, asyncCtxData and Invoke CreatePreviewNode function.
183      * @tc.expected: step1. ImageNode is not null.
184      */
185     int32_t containerId = 100;
186     bool hasTouchPoint = true;
187     DragPointerEvent dragPointerEvent(100, 100);
188     NG::DragPreviewOption previewOption;
189     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
190     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
191     void* voidPtr = static_cast<void*>(new char[0]);
192     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
193 
194     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
195         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
196     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
197         touchPoint, pixelMapList };
198     RefPtr<FrameNode> imageNode = nullptr;
199     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
200     ASSERT_NE(imageNode, nullptr);
201 
202     /**
203      * @tc.steps: step2. Call UpdatePreviewPositionAndScale function.
204      * @tc.expected: step2. GetClickEffectLevelValue is correct.
205      */
206     auto frameOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
207     NG::DragControllerFuncWrapper::UpdatePreviewPositionAndScale(imageNode, frameOffset, data.previewScale);
208     auto imageContext = imageNode->GetRenderContext();
209     auto clickEffectInfo = imageContext->GetClickEffectLevelValue();
210     EXPECT_EQ(clickEffectInfo.level, ClickEffectLevel::LIGHT);
211 }
212 
213 /**
214  * @tc.name: DragDropControllerFuncWrapperTest005
215  * @tc.desc: Test GetOrCreateGatherNode. GatherNode can be created when pixelMapList size > 1.
216  * @tc.type: FUNC
217  * @tc.author:
218  */
219 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest005, TestSize.Level1)
220 {
221     /**
222      * @tc.steps: step1. Create OverlayManager.
223      * @tc.expected: step1. OverlayManager is not null.
224      */
225     int32_t containerId = 100;
226     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
227     ASSERT_NE(pipelineContext, nullptr);
228     auto overlayManager = pipelineContext->GetOverlayManager();
229     ASSERT_NE(overlayManager, nullptr);
230 
231     /**
232      * @tc.steps: step2. Prepare darg data and asyncCtxData.
233      */
234     bool hasTouchPoint = true;
235     DragPointerEvent dragPointerEvent(100, 100);
236     NG::DragPreviewOption previewOption;
237     previewOption.options.opacity = 0.3f;
238     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
239     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
240     void* voidPtr = static_cast<void*>(new char[1]);
241     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
242 
243     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
244         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
245     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
246         touchPoint, pixelMapList };
247 
248     /**
249      * @tc.steps: step3. Call GetOrCreateGatherNode function when pixelMapList size <= 1.
250      * @tc.expected: step3. gatherNode is equal to nullptr and childrenInfo size is equal to 0.
251      */
252     std::vector<GatherNodeChildInfo> childrenInfo;
253     auto gatherNode =
254         NG::DragControllerFuncWrapper::GetOrCreateGatherNode(overlayManager, childrenInfo, data, asyncCtxData);
255     EXPECT_EQ(gatherNode, nullptr);
256     EXPECT_EQ(childrenInfo.size(), 0);
257 }
258 
259 /**
260  * @tc.name: DragDropControllerFuncWrapperTest006
261  * @tc.desc: Test UpdatePreviewAttr. ImageContext's opacity can be updated when has opacity value.
262  * @tc.type: FUNC
263  * @tc.author:
264  */
265 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest006, TestSize.Level1)
266 {
267     /**
268      * @tc.steps: step1. Prepare darg data and asyncCtxData and Invoke CreatePreviewNode function.
269      * @tc.expected: step1. ImageNode is not null.
270      */
271     int32_t containerId = 100;
272     bool hasTouchPoint = true;
273     DragPointerEvent dragPointerEvent(100, 100);
274     NG::DragPreviewOption previewOption;
275     previewOption.options.opacity = 0.3f;
276     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
277     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
278     void* voidPtr = static_cast<void*>(new char[0]);
279     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
280 
281     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
282         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
283     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
284         touchPoint, pixelMapList };
285     RefPtr<FrameNode> imageNode = nullptr;
286     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
287     ASSERT_NE(imageNode, nullptr);
288 
289     /**
290      * @tc.steps: step2. Call UpdatePreviewAttr function when has opacity value.
291      * @tc.expected: step2. opacityValue is equal to 0.3f.
292      */
293     NG::DragControllerFuncWrapper::UpdatePreviewAttr(imageNode, asyncCtxData.dragPreviewOption);
294     auto imageContext = imageNode->GetRenderContext();
295     auto opacityValue = imageContext->GetOpacityValue();
296     EXPECT_EQ(opacityValue, 0.3f);
297 }
298 
299 /**
300  * @tc.name: DragDropControllerFuncWrapperTest007
301  * @tc.desc: Test UpdateGatherAnimatePosition function. GatherNodeChildInfo's imageNode can be updated.
302  * @tc.type: FUNC
303  */
304 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest007, TestSize.Level1)
305 {
306     /**
307      * @tc.steps: step1. Create imageNode.
308      * @tc.expected: step1. imageNode is not null.
309      */
310     void* voidPtr = static_cast<void*>(new char[0]);
311     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
312     auto imageNode = DragAnimationHelper::CreateImageNode(refPixelMap);
313     ASSERT_NE(imageNode, nullptr);
314     auto renderContext = imageNode->GetRenderContext();
315     ASSERT_NE(renderContext, nullptr);
316 
317     /**
318      * @tc.steps: step1. Call UpdateGatherAnimatePosition with gatherNodeChildInfo.
319      * @tc.expected: step1. renderContext's position value is equal to targetOffset.
320      */
321     std::vector<GatherNodeChildInfo> gatherNodeChildInfo(1);
322     gatherNodeChildInfo[0].imageNode = imageNode;
323     auto tempOffset = OffsetT<Dimension>(Dimension(0.0f), Dimension(0.0f));
324     auto targetOffset = OffsetT<Dimension>(Dimension(COORDINATE_OFFSET.GetX()), Dimension(COORDINATE_OFFSET.GetY()));
325     EXPECT_EQ(renderContext->GetPositionValue(tempOffset), tempOffset);
326     NG::DragControllerFuncWrapper::UpdateGatherAnimatePosition(
327         gatherNodeChildInfo, { COORDINATE_OFFSET.GetX(), COORDINATE_OFFSET.GetY() });
328     EXPECT_EQ(renderContext->GetPositionValue(tempOffset), targetOffset);
329 }
330 
331 /**
332  * @tc.name: DragDropControllerFuncWrapperTest008
333  * @tc.desc: Test MountPixelMap function. PixelMap can be mount to root node success.
334  * @tc.type: FUNC
335  */
336 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest008, TestSize.Level1)
337 {
338     /**
339      * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
340      * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
341      */
342     int32_t containerId = 100;
343     bool hasTouchPoint = true;
344     DragPointerEvent dragPointerEvent(100, 100);
345     NG::DragPreviewOption previewOption;
346     previewOption.options.opacity = 0.3f;
347     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
348     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
349     void* voidPtr = static_cast<void*>(new char[0]);
350     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
351 
352     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
353         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
354     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
355         touchPoint, pixelMapList };
356     RefPtr<FrameNode> imageNode = nullptr;
357     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
358     ASSERT_NE(imageNode, nullptr);
359     auto textNode = NG::DragAnimationHelper::CreateBadgeTextNode(data.badgeNumber);
360     ASSERT_NE(textNode, nullptr);
361     auto pipeline = PipelineContext::GetCurrentContext();
362     ASSERT_NE(pipeline, nullptr);
363     auto overlayManager = pipeline->GetOverlayManager();
364     ASSERT_NE(overlayManager, nullptr);
365 
366     /**
367      * @tc.steps: step2. Call MountPixelMap function.
368      * @tc.expected: step2. MountPixelMapToRootNode success, overlayManager's hasPixelMap is true.
369      */
370     NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, textNode, true);
371     EXPECT_EQ(overlayManager->GetHasDragPixelMap(), true);
372 
373     /**
374      * @tc.steps: step3. Call MountPixelMap function when imageNode isPreviewNeedScale is true.
375      * @tc.expected: step3. imageNode's IsPreviewNeedScale is true, and TranslateOptions x value is 0.0f.
376      */
377     imageNode->GetGeometryNode()->SetFrameWidth(WIDTH);
378     EXPECT_EQ(imageNode->IsPreviewNeedScale(), true);
379     NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, textNode, true);
380     auto imageContext = imageNode->GetRenderContext();
381     EXPECT_TRUE(imageContext->GetTransformTranslate().has_value());
382     TranslateOptions result = imageContext->GetTransformTranslate().value();
383     TranslateOptions expectValue { 0.0f, 0.0f, 0.0f };
384     EXPECT_EQ(result.x.CalcValue(), expectValue.x.CalcValue());
385 }
386 
387 /**
388  * @tc.name: DragDropControllerFuncWrapperTest009
389  * @tc.desc: Test UpdateBadgeTextNodePosition function.
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest009, TestSize.Level1)
393 {
394     /**
395      * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
396      * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
397      */
398     int32_t containerId = 100;
399     bool hasTouchPoint = true;
400     DragPointerEvent dragPointerEvent(100, 100);
401     AceEngine& aceEngine = AceEngine::Get();
402     aceEngine.AddContainer(containerId, MockContainer::container_);
403     NG::DragPreviewOption previewOption;
404     previewOption.options.opacity = 0.3f;
405     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
406     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
407     void* voidPtr = static_cast<void*>(new char[0]);
408     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
409 
410     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
411         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
412     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
413         touchPoint, pixelMapList };
414     auto textNode = NG::DragAnimationHelper::CreateBadgeTextNode(data.badgeNumber);
415     ASSERT_NE(textNode, nullptr);
416     auto pipeline = PipelineContext::GetCurrentContext();
417     ASSERT_NE(pipeline, nullptr);
418     auto overlayManager = pipeline->GetOverlayManager();
419     ASSERT_NE(overlayManager, nullptr);
420 
421     /**
422      * @tc.steps: step2. Call UpdateBadgeTextNodePosition function.
423      * @tc.expected: step2. TranslateOptions x value is 0.0f.
424      */
425     NG::DragControllerFuncWrapper::UpdateBadgeTextNodePosition(
426         textNode, data, asyncCtxData, data.dragPreviewOffsetToScreen);
427     auto imageContext = textNode->GetRenderContext();
428     TranslateOptions result = imageContext->GetTransformTranslate().value();
429     TranslateOptions expectValue { 0.0f, 0.0f, 0.0f };
430     EXPECT_EQ(result.x.CalcValue(), expectValue.x.CalcValue());
431 }
432 
433 /**
434  * @tc.name: DragDropControllerFuncWrapperTest010
435  * @tc.desc: Test TransDragWindowToDragFwk function. DragDropManager's isDragFwkShow_ will be true afther
436  * TransDragWindowToDragFwk.
437  * @tc.type: FUNC
438  */
439 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest010, TestSize.Level1)
440 {
441     /**
442      * @tc.steps: step1. Create dragDropManager.
443      * @tc.expected: step1. dragDropManager is not null.
444      */
445     int32_t containerId = 100;
446     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
447     ASSERT_NE(pipelineContext, nullptr);
448     auto dragDropManager = pipelineContext->GetDragDropManager();
449     ASSERT_NE(dragDropManager, nullptr);
450 
451     /**
452      * @tc.steps: step2. Call TransDragWindowToDragFwk function.
453      * @tc.expected: step2. dragDropManager->isDragFwkShow_ is true
454      */
455     dragDropManager->SetDragFwkShow(false);
456     NG::DragControllerFuncWrapper::TransDragWindowToDragFwk(containerId);
457     EXPECT_TRUE(dragDropManager->IsDragFwkShow());
458 }
459 
460 /**
461  * @tc.name: DragDropControllerFuncWrapperTest011
462  * @tc.desc: Test CalcDragMoveOffset function. DragMoveOffset can be calculated correctly.
463  * @tc.type: FUNC
464  */
465 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest011, TestSize.Level1)
466 {
467     /**
468      * @tc.steps: step1. Create dragDropManager.
469      * @tc.expected: step1. dragDropManager is not null.
470      */
471     int32_t containerId = 100;
472     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
473     ASSERT_NE(pipelineContext, nullptr);
474     auto dragDropManager = pipelineContext->GetDragDropManager();
475     ASSERT_NE(dragDropManager, nullptr);
476 
477     /**
478      * @tc.steps: step2. Call CalcDragMoveOffset when dragPreviewInfo's originOffset is OffsetF(20, 20).
479      * @tc.expected: step2. CalcDragMoveOffset offset is equal to Offset(10, 10).
480      */
481     DragDropManager::DragPreviewInfo dragPreviewInfo;
482     dragPreviewInfo.originOffset = OffsetF(20, 20);
483     dragDropManager->SetDragPreviewInfo(dragPreviewInfo);
484     auto offset = NG::DragControllerFuncWrapper::CalcDragMoveOffset(30, 30);
485     EXPECT_EQ(offset, Offset(10, 10));
486 }
487 
488 /**
489  * @tc.name: DragDropControllerFuncWrapperTest0012
490  * @tc.desc: Test TryDoDragStartAnimation.
491  * @tc.type: FUNC
492  * @tc.author:
493  */
494 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0012, TestSize.Level1)
495 {
496     /**
497      * @tc.steps: step1. Create pipelineContext.
498      * @tc.expected: step1. pipelineContext is not null.
499      */
500     int32_t containerId = 100;
501     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
502     ASSERT_NE(pipelineContext, nullptr);
503     auto pipeline = PipelineBase::GetCurrentContextSafelyWithCheck();
504     ASSERT_NE(pipeline, nullptr);
505 
506     /**
507      * @tc.steps: step2. Prepare darg data and asyncCtxData.
508      */
509     bool hasTouchPoint = true;
510     DragPointerEvent dragPointerEvent(100, 100);
511     NG::DragPreviewOption previewOption;
512     previewOption.options.opacity = 0.3f;
513     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
514     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
515     void* voidPtr = static_cast<void*>(new char[0]);
516     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
517 
518     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
519         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
520     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
521         touchPoint, pixelMapList };
522 
523     /**
524      * @tc.steps: step2. Invoke SubWindowShow function.
525      * @tc.expected: step2. subWindow is null.
526      */
527     pipelineContext = AceType::DynamicCast<NG::PipelineContext>(pipeline);
528     ASSERT_NE(pipelineContext, nullptr);
529     auto dragDropManager = pipelineContext->GetDragDropManager();
530     dragDropManager->SetIsShowBadgeAnimation(true);
531     EXPECT_EQ(dragDropManager->IsShowBadgeAnimation(), true);
532     RefPtr<Subwindow> subWindow = nullptr;
533     {
534         auto mainPipeline = PipelineContext::GetMainPipelineContext();
535         subWindow = SubwindowManager::GetInstance()->ShowPreviewNG((pipelineContext != mainPipeline));
536     }
537     EXPECT_EQ(subWindow, nullptr);
538 
539     /**
540      * @tc.steps: step3. Call TryDoDragStartAnimation function.
541      * @tc.expected: step3. returnValue is equal to false.
542      */
543     auto returnValue = NG::DragControllerFuncWrapper::TryDoDragStartAnimation(subWindow, data, asyncCtxData);
544     EXPECT_EQ(returnValue, false);
545 }
546 
547 /**
548  * @tc.name: DragDropControllerFuncWrapperTest0013
549  * @tc.desc: Test DoDragStartAnimation.
550  * @tc.type: FUNC
551  * @tc.author:
552  */
553 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0013, TestSize.Level1)
554 {
555     /**
556      * @tc.steps: step1. Create overlayManager.
557      * @tc.expected: step1. overlayManager is not null.
558      */
559     int32_t containerId = 100;
560     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
561     ASSERT_NE(pipelineContext, nullptr);
562     auto overlayManager = pipelineContext->GetOverlayManager();
563     ASSERT_NE(overlayManager, nullptr);
564     auto dragDropManager = pipelineContext->GetDragDropManager();
565     ASSERT_NE(dragDropManager, nullptr);
566 
567     /**
568      * @tc.steps: step2. Prepare darg data and asyncCtxData.
569      */
570     bool hasTouchPoint = true;
571     DragPointerEvent dragPointerEvent(100, 100, 100, 100, 100, 100);
572     NG::DragPreviewOption previewOption;
573     previewOption.options.opacity = 0.3f;
574     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
575     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
576     void* voidPtr = static_cast<void*>(new char[0]);
577     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
578 
579     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
580         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
581     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
582         touchPoint, pixelMapList };
583     asyncCtxData.dragPointerEvent.deviceId = RESERVED_DEVICEID;
584 
585     /**
586      * @tc.steps: step3. Call DoDragStartAnimation function deviceId == RESERVED_DEVICEID.
587      * @tc.expected: step3. dragDropManager->isDragFwkShow_ is true.
588      */
589     NG::DragControllerFuncWrapper::DoDragStartAnimation(overlayManager, data, asyncCtxData);
590     EXPECT_TRUE(dragDropManager->IsDragFwkShow());
591 
592     /**
593      * @tc.steps: step4. Call DoDragStartAnimation function deviceId != RESERVED_DEVICEID.
594      * @tc.expected: step4. dragDropManager->isStartAnimationFinished_ is true
595      */
596     asyncCtxData.dragPointerEvent.deviceId = 0;
597     NG::DragControllerFuncWrapper::DoDragStartAnimation(overlayManager, data, asyncCtxData);
598     EXPECT_FALSE(dragDropManager->IsPullMoveReceivedForCurrentDrag());
599     EXPECT_EQ(dragDropManager->GetCurrentAnimationCnt(), 0);
600     EXPECT_EQ(dragDropManager->GetAllAnimationCnt(), 0);
601     EXPECT_EQ(dragDropManager->GetDragAnimationPointerEvent().windowX, 100);
602     EXPECT_TRUE(dragDropManager->IsStartAnimationFInished());
603 }
604 
605 /**
606  * @tc.name: DragDropControllerFuncWrapperTest0014
607  * @tc.desc: Test GetDragPreviewInfo.
608  * @tc.type: FUNC
609  * @tc.author:
610  */
611 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0014, TestSize.Level1)
612 {
613     /**
614      * @tc.steps: step1. Create overlayManager.
615      * @tc.expected: step1. overlayManager is not null.
616      */
617     int32_t containerId = 100;
618     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
619     ASSERT_NE(pipelineContext, nullptr);
620     auto overlayManager = pipelineContext->GetOverlayManager();
621     ASSERT_NE(overlayManager, nullptr);
622     auto dragDropManager = pipelineContext->GetDragDropManager();
623     ASSERT_NE(dragDropManager, nullptr);
624 
625     /**
626      * @tc.steps: step2. Call GetDragPreviewInfo function.
627      * @tc.expected: step2. DragDropManager->dragPreviewInfo.imageNode is nullptr.
628      */
629     AceEngine& aceEngine = AceEngine::Get();
630     aceEngine.AddContainer(containerId, MockContainer::container_);
631     overlayManager->SetHasPixelMap(true);
632     NG::DragControllerFuncWrapper::GetDragPreviewInfo(overlayManager, containerId);
633     auto imageNode = overlayManager->GetDragPixelMapContentNode();
634     EXPECT_NE(imageNode, nullptr);
635     EXPECT_NE(dragDropManager->GetDragPreviewInfo().imageNode, nullptr);
636 }
637 
638 /**
639  * @tc.name: DragDropControllerFuncWrapperTest0015
640  * @tc.desc: Test GetScaleInfo.
641  * @tc.type: FUNC
642  * @tc.author:
643  */
644 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0015, TestSize.Level1)
645 {
646     /**
647      * @tc.steps: step1. Call GetScaleInfo function.
648      * @tc.expected: step1. isNeedScale is true and sacle is not 1.0f.
649      */
650     int32_t containerId = 100;
651     AceEngine& aceEngine = AceEngine::Get();
652     aceEngine.AddContainer(containerId, MockContainer::container_);
653     auto scaleData = NG::DragControllerFuncWrapper::GetScaleInfo(containerId, WIDTH, HEIGHT);
654     EXPECT_NE(scaleData, nullptr);
655     EXPECT_NE(scaleData->isNeedScale, false);
656     EXPECT_NE(scaleData->scale, 1.0f);
657 }
658 
659 /**
660  * @tc.name: DragDropControllerFuncWrapperTest016
661  * @tc.desc: Test GetTouchPointOffset when DimensionUnit is PERCENT.
662  * @tc.type: FUNC
663  * @tc.author:
664  */
665 HWTEST_F(DragControllerFuncWrapperTestNg, DragDropControllerFuncWrapperTest016, TestSize.Level1)
666 {
667     /**
668      * @tc.steps: step1. Prepare darg data and asyncCtxData.
669      */
670     int32_t containerId = 100;
671     bool hasTouchPoint = true;
672     DragPointerEvent dragPointerEvent(100, 100);
673     NG::DragPreviewOption previewOption;
674     auto touchPointX = Dimension(0.1, DimensionUnit::PERCENT);
675     auto touchPointY = Dimension(0.1, DimensionUnit::PERCENT);
676     DimensionOffset touchPoint = DimensionOffset(touchPointX, touchPointY);
677     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
678     void* voidPtr = static_cast<void*>(new char[0]);
679     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
680 
681     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
682         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
683     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
684         touchPoint, pixelMapList };
685 
686     /**
687      * @tc.steps: step2. call GetTouchPointOffset.
688      * @tc.expected: step2. touchPointOffset is equal to NG::OffsetF(0, 0).
689      */
690     auto touchPointOffset = NG::DragControllerFuncWrapper::GetTouchPointOffset(data, asyncCtxData);
691     EXPECT_EQ(touchPointOffset, NG::OffsetF(0, 0));
692 }
693 
694 /**
695  * @tc.name: DragDropControllerFuncWrapperTest017
696  * @tc.desc: Test UpdatePreviewAttr. ImageContext's opacity can be updated when has opacity value.
697  * @tc.type: FUNC
698  * @tc.author:
699  */
700 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest017, TestSize.Level1)
701 {
702     /**
703      * @tc.steps: step1. Prepare darg data and asyncCtxData and Invoke CreatePreviewNode function.
704      * @tc.expected: step1. ImageNode is not null.
705      */
706     int32_t containerId = 100;
707     bool hasTouchPoint = true;
708     DragPointerEvent dragPointerEvent(100, 100);
709     NG::DragPreviewOption previewOption;
710     previewOption.options.opacity = 0.3f;
711     previewOption.options.shadow = DragDropFuncWrapper::GetDefaultShadow();
712     previewOption.options.borderRadius = DragDropFuncWrapper::GetDefaultBorderRadius();
713     previewOption.options.blurbgEffect.backGroundEffect = EffectOption();
714     previewOption.options.blurbgEffect.backGroundEffect.radius.SetValue(1.0F);
715     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
716     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
717     void* voidPtr = static_cast<void*>(new char[0]);
718     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
719 
720     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
721         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
722     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
723         touchPoint, pixelMapList };
724     RefPtr<FrameNode> imageNode = nullptr;
725     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
726     ASSERT_NE(imageNode, nullptr);
727 
728     /**
729      * @tc.steps: step2. Call UpdatePreviewAttr function when has opacity value.
730      * @tc.expected: step2. opacityValue is equal to 0.3f.
731      */
732     NG::DragControllerFuncWrapper::UpdatePreviewAttr(imageNode, asyncCtxData.dragPreviewOption);
733     auto imageContext = imageNode->GetRenderContext();
734     ASSERT_NE(imageContext, nullptr);
735     auto opacityValue = imageContext->GetOpacityValue();
736     EXPECT_EQ(opacityValue, 0.3f);
737 }
738 
739 /**
740  * @tc.name: DragDropControllerFuncWrapperTest018
741  * @tc.desc: Test UpdatePreviewPositionAndScale when scale is 0.
742  * @tc.type: FUNC
743  * @tc.author:
744  */
745 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest018, TestSize.Level1)
746 {
747     /**
748      * @tc.steps: step1. Prepare darg data, asyncCtxData and Invoke CreatePreviewNode function.
749      * @tc.expected: step1. ImageNode is not null.
750      */
751     int32_t containerId = 100;
752     bool hasTouchPoint = true;
753     DragPointerEvent dragPointerEvent(100, 100);
754     NG::DragPreviewOption previewOption;
755     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
756     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
757     void* voidPtr = static_cast<void*>(new char[0]);
758     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
759 
760     NG::PreparedInfoForDrag data = { false, 10, 0.0f, false, NG::OffsetF(),
761         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
762     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
763         touchPoint, pixelMapList };
764     RefPtr<FrameNode> imageNode = nullptr;
765     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
766     ASSERT_NE(imageNode, nullptr);
767 
768     /**
769      * @tc.steps: step2. Call UpdatePreviewPositionAndScale function.
770      * @tc.expected: step2. GetClickEffectLevelValue is correct.
771      */
772     auto frameOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
773     NG::DragControllerFuncWrapper::UpdatePreviewPositionAndScale(imageNode, frameOffset, data.previewScale);
774     auto imageContext = imageNode->GetRenderContext();
775     ASSERT_NE(imageContext, nullptr);
776     auto clickEffectInfo = imageContext->GetClickEffectLevelValue();
777     EXPECT_EQ(clickEffectInfo.level, ClickEffectLevel::LIGHT);
778 }
779 
780 /**
781  * @tc.name: DragDropControllerFuncWrapperTest020
782  * @tc.desc: Test MountPixelMap function. isDragPixelMap is false.
783  * @tc.type: FUNC
784  */
785 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest020, TestSize.Level1)
786 {
787     /**
788      * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
789      * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
790      */
791     int32_t containerId = 100;
792     bool hasTouchPoint = true;
793     DragPointerEvent dragPointerEvent(100, 100);
794     NG::DragPreviewOption previewOption;
795     previewOption.options.opacity = 0.3f;
796     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
797     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
798     void* voidPtr = static_cast<void*>(new char[0]);
799     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
800 
801     NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
802         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
803     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
804         touchPoint, pixelMapList };
805     RefPtr<FrameNode> imageNode = nullptr;
806     NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
807     ASSERT_NE(imageNode, nullptr);
808     auto textNode = NG::DragAnimationHelper::CreateBadgeTextNode(data.badgeNumber);
809     ASSERT_NE(textNode, nullptr);
810     auto pipeline = PipelineContext::GetCurrentContext();
811     ASSERT_NE(pipeline, nullptr);
812     auto overlayManager = pipeline->GetOverlayManager();
813     ASSERT_NE(overlayManager, nullptr);
814 
815     /**
816      * @tc.steps: step2. Call MountPixelMap function.
817      * @tc.expected: step2. MountPixelMapToRootNode success, overlayManager's hasPixelMap is true.
818      */
819     NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, textNode, false);
820     EXPECT_EQ(overlayManager->GetHasPixelMap(), true);
821 
822     /**
823      * @tc.steps: step3. Call MountPixelMap function when textNode is nullptr.
824      * @tc.expected: step3. MountPixelMapToRootNode success, overlayManager's GetHasDragPixelMap is true
825      */
826     NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, nullptr, true);
827     EXPECT_EQ(overlayManager->GetHasDragPixelMap(), true);
828 }
829 
830 /**
831  * @tc.name: DragDropControllerFuncWrapperTest021
832  * @tc.desc: Test UpdateBadgeTextNodePosition function.
833  * @tc.type: FUNC
834  */
835 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest021, TestSize.Level1)
836 {
837     /**
838      * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
839      * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
840      */
841     int32_t containerId = 100;
842     bool hasTouchPoint = true;
843     DragPointerEvent dragPointerEvent(100, 100);
844     NG::DragPreviewOption previewOption;
845     previewOption.options.opacity = 0.3f;
846     DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
847     std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
848     void* voidPtr = static_cast<void*>(new char[0]);
849     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
850 
851     NG::PreparedInfoForDrag data = { false, 1, 0.5f, false, NG::OffsetF(),
852         NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
853     NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
854         touchPoint, pixelMapList };
855 
856     /**
857      * @tc.steps: step2. Call UpdateBadgeTextNodePosition function when badgeNumber is 1.
858      * @tc.expected: step2. TranslateOptions x value is 0.0f.
859      */
860     NG::DragControllerFuncWrapper::UpdateBadgeTextNodePosition(
861         nullptr, data, asyncCtxData, data.dragPreviewOffsetToScreen);
862     EXPECT_EQ(data.badgeNumber, 1);
863 }
864 } // namespace OHOS::Ace::NG