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/core/common/mock_container.h"
21 #include "test/mock/core/common/mock_interaction_interface.h"
22 #include "test/mock/core/pipeline/mock_pipeline_context.h"
23
24 #include "base/subwindow/subwindow_manager.h"
25 #include "core/common/ace_engine.h"
26 #include "core/components_ng/manager/drag_drop/drag_drop_controller_func_wrapper.h"
27 #include "core/components_ng/manager/drag_drop/drag_drop_func_wrapper.h"
28 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h"
29 #include "core/components_ng/manager/drag_drop/utils/drag_animation_helper.h"
30
31 using namespace testing;
32 using namespace testing::ext;
33 namespace OHOS::Ace::NG {
34 namespace {
35 RefPtr<DragWindow> MOCK_DRAG_WINDOW;
36 constexpr float WIDTH = 400.0f;
37 constexpr float HEIGHT = 400.0f;
38 constexpr int32_t RESERVED_DEVICEID = 0xAAAAAAFF;
39 const OffsetF COORDINATE_OFFSET(WIDTH, HEIGHT);
40 } // namespace
41
42 class DragControllerFuncWrapperTestNg : public testing::Test {
43 public:
44 static void SetUpTestCase();
45 static void TearDownTestCase();
46 };
47
SetUpTestCase()48 void DragControllerFuncWrapperTestNg::SetUpTestCase()
49 {
50 MockPipelineContext::SetUp();
51 MockContainer::SetUp();
52 MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
53 }
54
TearDownTestCase()55 void DragControllerFuncWrapperTestNg::TearDownTestCase()
56 {
57 MockPipelineContext::TearDown();
58 MockContainer::TearDown();
59 MOCK_DRAG_WINDOW = nullptr;
60 }
61
62 /**
63 * @tc.name: DragDropControllerFuncWrapperTest001
64 * @tc.desc: Test GetUpdateDragMovePosition afther UpdateDragMovePosition. Position is equal to OffsetF() because
65 * lastDragMovePosition_ is equal to OffsetF().
66 * @tc.type: FUNC
67 * @tc.author:
68 */
69 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest001, TestSize.Level1)
70 {
71 /**
72 * @tc.steps: step1. Set the update drag move position
73 */
74 int32_t containerId = 100;
75
76 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
77 ASSERT_NE(pipelineContext, nullptr);
78 auto manager = pipelineContext->GetDragDropManager();
79 OffsetF position(10.0f, 20.0f);
80 manager->UpdateDragMovePosition(position, false);
81
82 /**
83 * @tc.steps: step2. call GetUpdateDragMovePosition
84 * @tc.expected: step2. drag move position is equal to OffsetF().
85 */
86 auto offset = NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId);
87 EXPECT_EQ(offset, NG::OffsetF());
88 }
89
90 /**
91 * @tc.name: DragDropControllerFuncWrapperTest002
92 * @tc.desc: Test ResetContextMenuDragPosition. Position is equal to OffsetF().
93 * @tc.type: FUNC
94 * @tc.author:
95 */
96 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest002, TestSize.Level1)
97 {
98 /**
99 * @tc.steps: step1. Set the update drag move position
100 */
101 int32_t containerId = 100;
102
103 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
104 ASSERT_NE(pipelineContext, nullptr);
105 auto manager = pipelineContext->GetDragDropManager();
106 ASSERT_NE(manager, nullptr);
107 OffsetF position(10.0f, 20.0f);
108 manager->UpdateDragMovePosition(position, false);
109
110 /**
111 * @tc.steps: step2. call ResetContextMenuDragPosition
112 * @tc.expected: step2. drag move position is equal to OffsetF().
113 */
114 NG::DragControllerFuncWrapper::ResetContextMenuDragPosition(containerId);
115 auto offset = manager->GetUpdateDragMovePosition();
116 EXPECT_EQ(offset, NG::OffsetF());
117 }
118
119 /**
120 * @tc.name: DragDropControllerFuncWrapperTest003
121 * @tc.desc: Test GetOriginNodeOffset when hasTouchPoint is true or false.
122 * @tc.type: FUNC
123 * @tc.author:
124 */
125 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest003, TestSize.Level1)
126 {
127 /**
128 * @tc.steps: step1. Prepare darg data and asyncCtxData.
129 */
130 int32_t containerId = 100;
131 bool hasTouchPoint = true;
132 DragPointerEvent dragPointerEvent(100, 100);
133 NG::DragPreviewOption previewOption;
134 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
135 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
136 void* voidPtr = static_cast<void*>(new char[0]);
137 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
138
139 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
140 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
141 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
142 touchPoint, pixelMapList };
143
144 /**
145 * @tc.steps: step2. call GetOriginNodeOffset when hasTouchPoint is true.
146 * @tc.expected: step2. originNodeOffset is equal to NG::OffsetF(90, 90).
147 */
148 auto pointPosition =
149 NG::DragDropFuncWrapper::GetPointRelativeToMainWindow(asyncCtxData.dragPointerEvent.GetPoint());
150 auto touchPointOffset = NG::DragControllerFuncWrapper::GetTouchPointOffset(data, asyncCtxData);
151 EXPECT_EQ(touchPointOffset, NG::OffsetF(10, 10));
152 auto pixelMapScaledOffset =
153 NG::DragControllerFuncWrapper::GetPixelMapScaledOffset(pointPosition, data, asyncCtxData);
154 EXPECT_EQ(pixelMapScaledOffset, NG::OffsetF(90, 90));
155 auto originNodeOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
156 EXPECT_EQ(originNodeOffset, NG::OffsetF(90, 90));
157
158 /**
159 * @tc.steps: step3. call GetOriginNodeOffset when hasTouchPoint is false.
160 * @tc.expected: step3. originNodeOffset is equal to NG::OffsetF(100, 100).
161 */
162 hasTouchPoint = false;
163 asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption, touchPoint, pixelMapList };
164 touchPointOffset = NG::DragControllerFuncWrapper::GetTouchPointOffset(data, asyncCtxData);
165 EXPECT_EQ(touchPointOffset, NG::OffsetF(-0, -0));
166 pixelMapScaledOffset = NG::DragControllerFuncWrapper::GetPixelMapScaledOffset(pointPosition, data, asyncCtxData);
167 EXPECT_EQ(pixelMapScaledOffset, NG::OffsetF(100, 100));
168 originNodeOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
169 EXPECT_EQ(originNodeOffset, NG::OffsetF(100, 100));
170 }
171
172 /**
173 * @tc.name: DragDropControllerFuncWrapperTest004
174 * @tc.desc: Test UpdatePreviewPositionAndScale. ImageContext's ClickEffectLevelValue can be updated to LIGHT.
175 * @tc.type: FUNC
176 * @tc.author:
177 */
178 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest004, TestSize.Level1)
179 {
180 /**
181 * @tc.steps: step1. Prepare darg data, asyncCtxData and Invoke CreatePreviewNode function.
182 * @tc.expected: step1. ImageNode is not null.
183 */
184 int32_t containerId = 100;
185 bool hasTouchPoint = true;
186 DragPointerEvent dragPointerEvent(100, 100);
187 NG::DragPreviewOption previewOption;
188 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
189 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
190 void* voidPtr = static_cast<void*>(new char[0]);
191 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
192
193 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
194 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
195 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
196 touchPoint, pixelMapList };
197 RefPtr<FrameNode> imageNode = nullptr;
198 NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
199 ASSERT_NE(imageNode, nullptr);
200
201 /**
202 * @tc.steps: step2. Call UpdatePreviewPositionAndScale function.
203 * @tc.expected: step2. GetClickEffectLevelValue is correct.
204 */
205 auto frameOffset = NG::DragControllerFuncWrapper::GetOriginNodeOffset(data, asyncCtxData);
206 NG::DragControllerFuncWrapper::UpdatePreviewPositionAndScale(imageNode, frameOffset, data.previewScale);
207 auto imageContext = imageNode->GetRenderContext();
208 auto clickEffectInfo = imageContext->GetClickEffectLevelValue();
209 EXPECT_EQ(clickEffectInfo.level, ClickEffectLevel::LIGHT);
210 }
211
212 /**
213 * @tc.name: DragDropControllerFuncWrapperTest005
214 * @tc.desc: Test GetOrCreateGatherNode. GatherNode can be created when pixelMapList size > 1.
215 * @tc.type: FUNC
216 * @tc.author:
217 */
218 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest005, TestSize.Level1)
219 {
220 /**
221 * @tc.steps: step1. Create OverlayManager.
222 * @tc.expected: step1. OverlayManager is not null.
223 */
224 int32_t containerId = 100;
225 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
226 ASSERT_NE(pipelineContext, nullptr);
227 auto overlayManager = pipelineContext->GetOverlayManager();
228 ASSERT_NE(overlayManager, nullptr);
229
230 /**
231 * @tc.steps: step2. Prepare darg data and asyncCtxData.
232 */
233 bool hasTouchPoint = true;
234 DragPointerEvent dragPointerEvent(100, 100);
235 NG::DragPreviewOption previewOption;
236 previewOption.options.opacity = 0.3f;
237 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
238 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
239 void* voidPtr = static_cast<void*>(new char[1]);
240 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
241
242 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
243 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
244 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
245 touchPoint, pixelMapList };
246
247 /**
248 * @tc.steps: step3. Call GetOrCreateGatherNode function when pixelMapList size <= 1.
249 * @tc.expected: step3. gatherNode is equal to nullptr and childrenInfo size is equal to 0.
250 */
251 std::vector<GatherNodeChildInfo> childrenInfo;
252 auto gatherNode =
253 NG::DragControllerFuncWrapper::GetOrCreateGatherNode(overlayManager, childrenInfo, data, asyncCtxData);
254 EXPECT_EQ(gatherNode, nullptr);
255 EXPECT_EQ(childrenInfo.size(), 0);
256 }
257
258 /**
259 * @tc.name: DragDropControllerFuncWrapperTest006
260 * @tc.desc: Test UpdatePreviewAttr. ImageContext's opacity can be updated when has opacity value.
261 * @tc.type: FUNC
262 * @tc.author:
263 */
264 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest006, TestSize.Level1)
265 {
266 /**
267 * @tc.steps: step1. Prepare darg data and asyncCtxData and Invoke CreatePreviewNode function.
268 * @tc.expected: step1. ImageNode is not null.
269 */
270 int32_t containerId = 100;
271 bool hasTouchPoint = true;
272 DragPointerEvent dragPointerEvent(100, 100);
273 NG::DragPreviewOption previewOption;
274 previewOption.options.opacity = 0.3f;
275 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
276 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
277 void* voidPtr = static_cast<void*>(new char[0]);
278 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
279
280 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
281 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
282 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
283 touchPoint, pixelMapList };
284 RefPtr<FrameNode> imageNode = nullptr;
285 NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
286 ASSERT_NE(imageNode, nullptr);
287
288 /**
289 * @tc.steps: step2. Call UpdatePreviewAttr function when has opacity value.
290 * @tc.expected: step2. opacityValue is equal to 0.3f.
291 */
292 NG::DragControllerFuncWrapper::UpdatePreviewAttr(imageNode, asyncCtxData.dragPreviewOption);
293 auto imageContext = imageNode->GetRenderContext();
294 auto opacityValue = imageContext->GetOpacityValue();
295 EXPECT_EQ(opacityValue, 0.3f);
296 }
297
298 /**
299 * @tc.name: DragDropControllerFuncWrapperTest007
300 * @tc.desc: Test UpdateGatherAnimatePosition function. GatherNodeChildInfo's imageNode can be updated.
301 * @tc.type: FUNC
302 */
303 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest007, TestSize.Level1)
304 {
305 /**
306 * @tc.steps: step1. Create imageNode.
307 * @tc.expected: step1. imageNode is not null.
308 */
309 void* voidPtr = static_cast<void*>(new char[0]);
310 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
311 auto imageNode = DragAnimationHelper::CreateImageNode(refPixelMap);
312 ASSERT_NE(imageNode, nullptr);
313 auto renderContext = imageNode->GetRenderContext();
314 ASSERT_NE(renderContext, nullptr);
315
316 /**
317 * @tc.steps: step1. Call UpdateGatherAnimatePosition with gatherNodeChildInfo.
318 * @tc.expected: step1. renderContext's position value is equal to targetOffset.
319 */
320 std::vector<GatherNodeChildInfo> gatherNodeChildInfo(1);
321 gatherNodeChildInfo[0].imageNode = imageNode;
322 auto tempOffset = OffsetT<Dimension>(Dimension(0.0f), Dimension(0.0f));
323 auto targetOffset = OffsetT<Dimension>(Dimension(COORDINATE_OFFSET.GetX()), Dimension(COORDINATE_OFFSET.GetY()));
324 EXPECT_EQ(renderContext->GetPositionValue(tempOffset), tempOffset);
325 NG::DragControllerFuncWrapper::UpdateGatherAnimatePosition(
326 gatherNodeChildInfo, { COORDINATE_OFFSET.GetX(), COORDINATE_OFFSET.GetY() });
327 EXPECT_EQ(renderContext->GetPositionValue(tempOffset), targetOffset);
328 }
329
330 /**
331 * @tc.name: DragDropControllerFuncWrapperTest008
332 * @tc.desc: Test MountPixelMap function. PixelMap can be mount to root node success.
333 * @tc.type: FUNC
334 */
335 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest008, TestSize.Level1)
336 {
337 /**
338 * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
339 * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
340 */
341 int32_t containerId = 100;
342 bool hasTouchPoint = true;
343 DragPointerEvent dragPointerEvent(100, 100);
344 NG::DragPreviewOption previewOption;
345 previewOption.options.opacity = 0.3f;
346 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
347 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
348 void* voidPtr = static_cast<void*>(new char[0]);
349 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
350
351 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
352 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
353 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
354 touchPoint, pixelMapList };
355 RefPtr<FrameNode> imageNode = nullptr;
356 NG::DragControllerFuncWrapper::CreatePreviewNode(imageNode, data, asyncCtxData);
357 ASSERT_NE(imageNode, nullptr);
358 auto textNode = NG::DragAnimationHelper::CreateBadgeTextNode(data.badgeNumber);
359 ASSERT_NE(textNode, nullptr);
360 auto pipeline = PipelineContext::GetCurrentContext();
361 ASSERT_NE(pipeline, nullptr);
362 auto overlayManager = pipeline->GetOverlayManager();
363 ASSERT_NE(overlayManager, nullptr);
364
365 /**
366 * @tc.steps: step2. Call MountPixelMap function.
367 * @tc.expected: step2. MountPixelMapToRootNode success, overlayManager's hasPixelMap is true.
368 */
369 NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, textNode, true);
370 EXPECT_EQ(overlayManager->GetHasDragPixelMap(), true);
371
372 /**
373 * @tc.steps: step3. Call MountPixelMap function when imageNode isPreviewNeedScale is true.
374 * @tc.expected: step3. imageNode's IsPreviewNeedScale is true, and TranslateOptions x value is 0.0f.
375 */
376 imageNode->GetGeometryNode()->SetFrameWidth(WIDTH);
377 EXPECT_EQ(imageNode->IsPreviewNeedScale(), true);
378 NG::DragControllerFuncWrapper::MountPixelMap(overlayManager, data, imageNode, textNode, true);
379 auto imageContext = imageNode->GetRenderContext();
380 EXPECT_TRUE(imageContext->GetTransformTranslate().has_value());
381 TranslateOptions result = imageContext->GetTransformTranslate().value();
382 TranslateOptions expectValue { 0.0f, 0.0f, 0.0f };
383 EXPECT_EQ(result.x.CalcValue(), expectValue.x.CalcValue());
384 }
385
386 /**
387 * @tc.name: DragDropControllerFuncWrapperTest009
388 * @tc.desc: Test UpdateBadgeTextNodePosition function.
389 * @tc.type: FUNC
390 */
391 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest009, TestSize.Level1)
392 {
393 /**
394 * @tc.steps: step1. Prepare darg data, imageNode, textNode, pipeline and overlayManager.
395 * @tc.expected: step1. imageNode, textNode, pipeline and overlayManager is not null.
396 */
397 int32_t containerId = 100;
398 bool hasTouchPoint = true;
399 DragPointerEvent dragPointerEvent(100, 100);
400 NG::DragPreviewOption previewOption;
401 previewOption.options.opacity = 0.3f;
402 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
403 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
404 void* voidPtr = static_cast<void*>(new char[0]);
405 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
406
407 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
408 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
409 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
410 touchPoint, pixelMapList };
411 auto textNode = NG::DragAnimationHelper::CreateBadgeTextNode(data.badgeNumber);
412 ASSERT_NE(textNode, nullptr);
413 auto pipeline = PipelineContext::GetCurrentContext();
414 ASSERT_NE(pipeline, nullptr);
415 auto overlayManager = pipeline->GetOverlayManager();
416 ASSERT_NE(overlayManager, nullptr);
417
418 /**
419 * @tc.steps: step2. Call UpdateBadgeTextNodePosition function.
420 * @tc.expected: step2. TranslateOptions x value is 0.0f.
421 */
422 NG::DragControllerFuncWrapper::UpdateBadgeTextNodePosition(
423 textNode, data, asyncCtxData, data.dragPreviewOffsetToScreen);
424 auto imageContext = textNode->GetRenderContext();
425 TranslateOptions result = imageContext->GetTransformTranslate().value();
426 TranslateOptions expectValue { 0.0f, 0.0f, 0.0f };
427 EXPECT_EQ(result.x.CalcValue(), expectValue.x.CalcValue());
428 }
429
430 /**
431 * @tc.name: DragDropControllerFuncWrapperTest010
432 * @tc.desc: Test TransDragWindowToDragFwk function. DragDropManager's isDragFwkShow_ will be true afther
433 * TransDragWindowToDragFwk.
434 * @tc.type: FUNC
435 */
436 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest010, TestSize.Level1)
437 {
438 /**
439 * @tc.steps: step1. Create dragDropManager.
440 * @tc.expected: step1. dragDropManager is not null.
441 */
442 int32_t containerId = 100;
443 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
444 ASSERT_NE(pipelineContext, nullptr);
445 auto dragDropManager = pipelineContext->GetDragDropManager();
446 ASSERT_NE(dragDropManager, nullptr);
447
448 /**
449 * @tc.steps: step2. Call TransDragWindowToDragFwk function.
450 * @tc.expected: step2. dragDropManager->isDragFwkShow_ is true
451 */
452 dragDropManager->SetDragFwkShow(false);
453 NG::DragControllerFuncWrapper::TransDragWindowToDragFwk(containerId);
454 EXPECT_TRUE(dragDropManager->IsDragFwkShow());
455 }
456
457 /**
458 * @tc.name: DragDropControllerFuncWrapperTest011
459 * @tc.desc: Test CalcDragMoveOffset function. DragMoveOffset can be calculated correctly.
460 * @tc.type: FUNC
461 */
462 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest011, TestSize.Level1)
463 {
464 /**
465 * @tc.steps: step1. Create dragDropManager.
466 * @tc.expected: step1. dragDropManager is not null.
467 */
468 int32_t containerId = 100;
469 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
470 ASSERT_NE(pipelineContext, nullptr);
471 auto dragDropManager = pipelineContext->GetDragDropManager();
472 ASSERT_NE(dragDropManager, nullptr);
473
474 /**
475 * @tc.steps: step2. Call CalcDragMoveOffset when dragPreviewInfo's originOffset is OffsetF(20, 20).
476 * @tc.expected: step2. CalcDragMoveOffset offset is equal to Offset(10, 10).
477 */
478 DragDropManager::DragPreviewInfo dragPreviewInfo;
479 dragPreviewInfo.originOffset = OffsetF(20, 20);
480 dragDropManager->SetDragPreviewInfo(dragPreviewInfo);
481 auto offset = NG::DragControllerFuncWrapper::CalcDragMoveOffset(30, 30);
482 EXPECT_EQ(offset, Offset(10, 10));
483 }
484
485 /**
486 * @tc.name: DragDropControllerFuncWrapperTest0012
487 * @tc.desc: Test TryDoDragStartAnimation.
488 * @tc.type: FUNC
489 * @tc.author:
490 */
491 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0012, TestSize.Level1)
492 {
493 /**
494 * @tc.steps: step1. Create pipelineContext.
495 * @tc.expected: step1. pipelineContext is not null.
496 */
497 int32_t containerId = 100;
498 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
499 ASSERT_NE(pipelineContext, nullptr);
500 auto pipeline = PipelineBase::GetCurrentContextSafelyWithCheck();
501 ASSERT_NE(pipeline, nullptr);
502
503 /**
504 * @tc.steps: step2. Prepare darg data and asyncCtxData.
505 */
506 bool hasTouchPoint = true;
507 DragPointerEvent dragPointerEvent(100, 100);
508 NG::DragPreviewOption previewOption;
509 previewOption.options.opacity = 0.3f;
510 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
511 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
512 void* voidPtr = static_cast<void*>(new char[0]);
513 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
514
515 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
516 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
517 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
518 touchPoint, pixelMapList };
519
520 /**
521 * @tc.steps: step2. Invoke SubWindowShow function.
522 * @tc.expected: step2. subWindow is null.
523 */
524 pipelineContext = AceType::DynamicCast<NG::PipelineContext>(pipeline);
525 ASSERT_NE(pipelineContext, nullptr);
526 RefPtr<Subwindow> subWindow = nullptr;
527 {
528 auto mainPipeline = PipelineContext::GetMainPipelineContext();
529 subWindow = SubwindowManager::GetInstance()->ShowPreviewNG((pipelineContext != mainPipeline));
530 }
531 EXPECT_EQ(subWindow, nullptr);
532
533 /**
534 * @tc.steps: step3. Call TryDoDragStartAnimation function.
535 * @tc.expected: step3. returnValue is equal to false.
536 */
537 auto returnValue = NG::DragControllerFuncWrapper::TryDoDragStartAnimation(subWindow, data, asyncCtxData);
538 EXPECT_EQ(returnValue, false);
539 }
540
541 /**
542 * @tc.name: DragDropControllerFuncWrapperTest0013
543 * @tc.desc: Test DoDragStartAnimation.
544 * @tc.type: FUNC
545 * @tc.author:
546 */
547 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0013, TestSize.Level1)
548 {
549 /**
550 * @tc.steps: step1. Create overlayManager.
551 * @tc.expected: step1. overlayManager is not null.
552 */
553 int32_t containerId = 100;
554 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
555 ASSERT_NE(pipelineContext, nullptr);
556 auto overlayManager = pipelineContext->GetOverlayManager();
557 ASSERT_NE(overlayManager, nullptr);
558 auto dragDropManager = pipelineContext->GetDragDropManager();
559 ASSERT_NE(dragDropManager, nullptr);
560
561 /**
562 * @tc.steps: step2. Prepare darg data and asyncCtxData.
563 */
564 bool hasTouchPoint = true;
565 DragPointerEvent dragPointerEvent(100, 100);
566 NG::DragPreviewOption previewOption;
567 previewOption.options.opacity = 0.3f;
568 DimensionOffset touchPoint = DimensionOffset(10.0_vp, 10.0_vp);
569 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
570 void* voidPtr = static_cast<void*>(new char[0]);
571 RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
572
573 NG::PreparedInfoForDrag data = { false, 10, 0.5f, false, NG::OffsetF(),
574 NG::DragControllerFuncWrapper::GetUpdateDragMovePosition(containerId), refPixelMap };
575 NG::PreparedAsyncCtxForAnimate asyncCtxData = { containerId, hasTouchPoint, dragPointerEvent, previewOption,
576 touchPoint, pixelMapList };
577 asyncCtxData.dragPointerEvent.deviceId = RESERVED_DEVICEID;
578
579 /**
580 * @tc.steps: step3. Call DoDragStartAnimation function deviceId == RESERVED_DEVICEID.
581 * @tc.expected: step3. dragDropManager->isDragFwkShow_ is true.
582 */
583 NG::DragControllerFuncWrapper::DoDragStartAnimation(overlayManager, data, asyncCtxData);
584 EXPECT_TRUE(dragDropManager->IsDragFwkShow());
585
586 /**
587 * @tc.steps: step4. Call DoDragStartAnimation function deviceId != RESERVED_DEVICEID.
588 * @tc.expected: step4. dragDropManager->isStartAnimationFinished_ is false
589 */
590 asyncCtxData.dragPointerEvent.deviceId = 0;
591 NG::DragControllerFuncWrapper::DoDragStartAnimation(overlayManager, data, asyncCtxData);
592 EXPECT_FALSE(dragDropManager->IsPullMoveReceivedForCurrentDrag());
593 EXPECT_EQ(dragDropManager->GetCurrentAnimationCnt(), 0);
594 EXPECT_EQ(dragDropManager->GetAllAnimationCnt(), 0);
595 EXPECT_FALSE(dragDropManager->IsStartAnimationFInished());
596 }
597
598 /**
599 * @tc.name: DragDropControllerFuncWrapperTest0014
600 * @tc.desc: Test GetDragPreviewInfo.
601 * @tc.type: FUNC
602 * @tc.author:
603 */
604 HWTEST_F(DragControllerFuncWrapperTestNg, DragControllerFuncWrapperTest0014, TestSize.Level1)
605 {
606 /**
607 * @tc.steps: step1. Create overlayManager.
608 * @tc.expected: step1. overlayManager is not null.
609 */
610 int32_t containerId = 100;
611 auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
612 ASSERT_NE(pipelineContext, nullptr);
613 auto overlayManager = pipelineContext->GetOverlayManager();
614 ASSERT_NE(overlayManager, nullptr);
615 auto dragDropManager = pipelineContext->GetDragDropManager();
616 ASSERT_NE(dragDropManager, nullptr);
617
618 /**
619 * @tc.steps: step2. Call GetDragPreviewInfo function.
620 * @tc.expected: step2. DragDropManager->dragPreviewInfo.imageNode is nullptr.
621 */
622 AceEngine& aceEngine = AceEngine::Get();
623 aceEngine.AddContainer(containerId, MockContainer::container_);
624 overlayManager->SetHasPixelMap(true);
625 NG::DragControllerFuncWrapper::GetDragPreviewInfo(overlayManager, containerId);
626 auto imageNode = overlayManager->GetDragPixelMapContentNode();
627 EXPECT_NE(imageNode, nullptr);
628 EXPECT_EQ(dragDropManager->GetDragPreviewInfo().imageNode, nullptr);
629 }
630
631 } // namespace OHOS::Ace::NG