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/event/drag_event_test_ng.h"
17 #include "test/mock/base/mock_task_executor.h"
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS::Ace::NG {
SetUpTestSuite()22 void DragEventTestNg::SetUpTestSuite()
23 {
24 GTEST_LOG_(INFO) << "DragEventTestNg SetUpTestCase";
25 testing::FLAGS_gmock_verbose = "error";
26 }
27
TearDownTestSuite()28 void DragEventTestNg::TearDownTestSuite()
29 {
30 GTEST_LOG_(INFO) << "DragEventTestNg TearDownTestCase";
31 }
32
SetUp()33 void DragEventTestNg::SetUp()
34 {
35 MockPipelineContext::SetUp();
36 }
37
TearDown()38 void DragEventTestNg::TearDown()
39 {
40 MockPipelineContext::TearDown();
41 }
42
43 /**
44 * @tc.name: DragEventTest001
45 * @tc.desc: Create DragEvent and execute its callback functions.
46 * @tc.type: FUNC
47 */
48 HWTEST_F(DragEventTestNg, DragEventTest001, TestSize.Level1)
49 {
50 /**
51 * @tc.steps: step1. Create GestureEventFunc as the arguments of the construction of DragEvent.
52 */
53 double unknownPropertyValue = 0.0;
54 GestureEventFunc actionStart = [&unknownPropertyValue](
__anondbf094730102( GestureEvent& info) 55 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
56 GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anondbf094730202( GestureEvent& info) 57 GestureEvent& info) { unknownPropertyValue = info.GetAngle(); };
58 GestureEventFunc actionEnd = [&unknownPropertyValue](
__anondbf094730302( GestureEvent& info) 59 GestureEvent& info) { unknownPropertyValue = info.GetOffsetX(); };
__anondbf094730402() 60 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
61 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
62 };
63
64 /**
65 * @tc.steps: step2. Create DragEvent.
66 */
67 const DragEvent dragEvent =
68 DragEvent(std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
69
70 /**
71 * @tc.steps: step3. Get and execute DragEvent ActionStartEvent.
72 * @tc.expected: Execute ActionStartEvent which unknownPropertyValue is assigned in.
73 */
74 GestureEvent info = GestureEvent();
75 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
76 dragEvent.GetActionStartEventFunc()(info);
77 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
78
79 /**
80 * @tc.steps: step4. Get and execute DragEvent ActionUpdateEvent.
81 * @tc.expected: Execute ActionUpdateEvent which unknownPropertyValue is assigned in.
82 */
83 unknownPropertyValue = 0.0;
84 info.SetAngle(GESTURE_EVENT_PROPERTY_VALUE);
85 dragEvent.GetActionUpdateEventFunc()(info);
86 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
87
88 /**
89 * @tc.steps: step5. Get and execute DragEvent ActionEndEvent.
90 * @tc.expected: Execute ActionEndEvent which unknownPropertyValue is assigned in.
91 */
92 unknownPropertyValue = 0.0;
93 info.SetOffsetX(GESTURE_EVENT_PROPERTY_VALUE);
94 dragEvent.GetActionEndEventFunc()(info);
95 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
96
97 /**
98 * @tc.steps: step6. Get and execute DragEvent ActionCancelEvent.
99 * @tc.expected: Execute ActionCancelEvent which unknownPropertyValue is assigned in.
100 */
101 unknownPropertyValue = 0.0;
102 dragEvent.GetActionCancelEventFunc()();
103 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
104 }
105
106 /**
107 * @tc.name: DragEventActuatorPropertyTest002
108 * @tc.desc: Create DragEventActuator and test its property value.
109 * @tc.type: FUNC
110 */
111 HWTEST_F(DragEventTestNg, DragEventActuatorPropertyTest002, TestSize.Level1)
112 {
113 /**
114 * @tc.steps: step1. Create DragEventActuator.
115 */
116 auto eventHub = AceType::MakeRefPtr<EventHub>();
117 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
118 DragEventActuator dragEventActuator = DragEventActuator(
119 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
120
121 /**
122 * @tc.steps: step2. Create DragEventActuator when fingers number and distance are both greater than the default.
123 * @tc.expected: panEventActuator is initialized with the fingers_ and distance_ defined before.
124 */
125 auto dragEventActuator2 =
126 AceType::MakeRefPtr<DragEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION,
127 FINGERS_NUMBER_GREATER_THAN_DEFAULT, DISTANCE_GREATER_THAN_DEFAULT);
128 EXPECT_NE(dragEventActuator2, nullptr);
129 EXPECT_EQ(dragEventActuator2->fingers_, FINGERS_NUMBER_GREATER_THAN_DEFAULT);
130 EXPECT_EQ(dragEventActuator2->distance_, DISTANCE_GREATER_THAN_DEFAULT);
131
132 /**
133 * @tc.steps: step3. Get DragEventActuator direction, fingers_ and distance_.
134 * @tc.expected: DragEventActuator's direction, fingers_ and distance_ are equal with the parameters passed in the
135 * constructor.
136 */
137 EXPECT_EQ(dragEventActuator.GetDirection().type, DRAG_DIRECTION.type);
138 EXPECT_EQ(dragEventActuator.fingers_, FINGERS_NUMBER);
139 EXPECT_EQ(dragEventActuator.distance_, DISTANCE);
140 /**
141 * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent and CustomDragEvent.
142 * @tc.expected: Get DragEventActuator's DragEvent and CustomDragEvent which are equal with the DragEvent create
143 * before.
144 */
__anondbf094730502(GestureEvent& info) 145 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094730602(GestureEvent& info) 146 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094730702(GestureEvent& info) 147 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094730802() 148 GestureEventNoParameter actionCancel = []() {};
149
150 auto dragEvent = AceType::MakeRefPtr<DragEvent>(
151 std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
152 dragEventActuator.ReplaceDragEvent(dragEvent);
153 EXPECT_EQ(dragEvent, dragEventActuator.userCallback_);
154 dragEventActuator.SetCustomDragEvent(dragEvent);
155 EXPECT_EQ(dragEvent, dragEventActuator.customCallback_);
156 }
157
158 /**
159 * @tc.name: DragEventActuatorOnCollectTouchTargetTest003
160 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
161 * @tc.type: FUNC
162 */
163 HWTEST_F(DragEventTestNg, DragEventActuatorOnCollectTouchTargetTest003, TestSize.Level1)
164 {
165 /**
166 * @tc.steps: step1. Create DragEventActuator.
167 */
168 auto eventHub = AceType::MakeRefPtr<EventHub>();
169 auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), false);
170 EXPECT_NE(frameNode, nullptr);
171 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
172 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
173 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
174 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
175
176 /**
177 * @tc.steps: step2. Invoke OnCollectTouchTarget without setting userCallback_.
178 * @tc.expected: userCallback_ is null and return directly.
179 */
180 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
181 EXPECT_NE(getEventTargetImpl, nullptr);
182 TouchTestResult finalResult;
183 ResponseLinkResult responseLinkResult;
184 frameNode->GetOrCreateFocusHub();
185 dragEventActuator->OnCollectTouchTarget(
186 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
187 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
188 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
189 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
190 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
191 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
192 EXPECT_TRUE(finalResult.empty());
193
194 /**
195 * @tc.steps: step3. Create DragEvent and set as DragEventActuator's DragEvent.
196 * @tc.expected: DragEventActuator's userCallback_ is not null.
197 */
198 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
199 GestureEventFunc actionStart = [&unknownPropertyValue](
__anondbf094730902( GestureEvent& info) 200 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
201 GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anondbf094730a02( GestureEvent& info) 202 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
203 GestureEventFunc actionEnd = [&unknownPropertyValue](
__anondbf094730b02( GestureEvent& info) 204 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
__anondbf094730c02() 205 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
206 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
207 };
208 auto dragEvent = AceType::MakeRefPtr<DragEvent>(
209 std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
210 dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anondbf094730d02(GestureEvent& info) 211 [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE; });
212 dragEventActuator->ReplaceDragEvent(dragEvent);
213 dragEventActuator->SetCustomDragEvent(dragEvent);
214 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
215
216 /**
217 * @tc.steps: step4. Invoke OnCollectTouchTarget when userCallback_ is not null.
218 * @tc.expected: panRecognizer_ action and finalResult will be assigned value.
219 */
220 dragEventActuator->OnCollectTouchTarget(
221 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
222
223 EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
224 EXPECT_NE(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
225 EXPECT_NE(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
226 EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
227 EXPECT_FALSE(finalResult.size() == TOUCH_TEST_RESULT_SIZE);
228
229 /**
230 * @tc.steps: step5. Invoke OnCollectTouchTarget when SequencedRecognizer_ is null.
231 * @tc.expected: Result size will be increased by one.
232 */
233 dragEventActuator->SequencedRecognizer_ = nullptr;
234 dragEventActuator->OnCollectTouchTarget(
235 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
236 EXPECT_TRUE(finalResult.size() != TOUCH_TEST_RESULT_SIZE_2);
237
238 /**
239 * @tc.steps: Create prepareDragFrameNode for drag start.
240 * @tc.expected: Create prepareDragFrameNode success.
241 */
242 auto pipeline = PipelineContext::GetCurrentContext();
243 ASSERT_NE(pipeline, nullptr);
244 auto dragDropManager = pipeline->GetDragDropManager();
245 ASSERT_NE(dragDropManager, nullptr);
246 DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
247 /**
248 * @tc.steps: step6. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
249 * function exists.
250 * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
251 * value.
252 */
253 GestureEvent info = GestureEvent();
254 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
255 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
256 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
257 (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
258 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
259 (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
260 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
261 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
262 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
263
264 /**
265 * @tc.steps: step7. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
266 * function not exist.
267 * @tc.expected: The functions have not been executed.
268 */
269 SystemProperties::debugEnabled_ = true;
270 auto dragEventNullptr = AceType::MakeRefPtr<DragEvent>(nullptr, nullptr, nullptr, nullptr);
271 dragEventActuator->ReplaceDragEvent(dragEventNullptr);
272 dragEventActuator->SetCustomDragEvent(dragEventNullptr);
273 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
274 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
275 (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
276 (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
277 dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anondbf094730e02(GestureEvent& info) 278 [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE; });
279 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
280 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_DEFAULT_VALUE);
281 }
282
283 /**
284 * @tc.name: DragEventTestNg001
285 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
286 * @tc.type: FUNC
287 */
288 HWTEST_F(DragEventTestNg, DragEventTestNg001, TestSize.Level1)
289 {
290 /**
291 * @tc.steps: step1. Create DragEventActuator.
292 */
293 auto eventHub = AceType::MakeRefPtr<EventHub>();
294 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
295 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
296 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, 0, 50.0f);
297 dragEventActuator->StartDragTaskForWeb(GestureEvent());
__anondbf094730f02(GestureEvent&) 298 auto actionStart = [](GestureEvent&) {};
__anondbf094731002(GestureEvent&) 299 auto longPressUpdate = [](GestureEvent&) {};
300 dragEventActuator->actionStart_ = actionStart;
301 dragEventActuator->StartDragTaskForWeb(GestureEvent());
302
303 dragEventActuator->CancelDragForWeb();
__anondbf094731102(GestureEvent&) 304 auto actionCancel = [](GestureEvent&) {};
305 dragEventActuator->actionCancel_ = actionCancel;
306 dragEventActuator->CancelDragForWeb();
307
308 dragEventActuator->StartLongPressActionForWeb();
309 dragEventActuator->isReceivedLongPress_ = true;
310 dragEventActuator->StartLongPressActionForWeb();
311 dragEventActuator->isReceivedLongPress_ = true;
312 dragEventActuator->longPressUpdate_ = longPressUpdate;
313 dragEventActuator->StartLongPressActionForWeb();
314 ASSERT_FALSE(dragEventActuator->isReceivedLongPress_);
315 }
316
317 /**
318 * @tc.name: DragEventTestNg002
319 * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
320 * @tc.type: FUNC
321 */
322 HWTEST_F(DragEventTestNg, DragEventTestNg002, TestSize.Level1)
323 {
324 /**
325 * @tc.steps: step1. Create FrameNode and set dragPreview.
326 */
327 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
328 frameNode->SetDraggable(true);
329 NG::DragDropInfo dragPreviewInfo;
330 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(static_cast<void*>(new char[0]));
331 dragPreviewInfo.pixelMap = pixelMap;
332 frameNode->SetDragPreview(dragPreviewInfo);
333
334 /**
335 * @tc.steps: step2. Get eventHub and set onDragStart.
336 * @tc.expected: eventHub is not nullptr.
337 */
338 auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
339 EXPECT_NE(eventHub, nullptr);
340 eventHub->AttachHost(frameNode);
__anondbf094731202(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 341 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
342 DragDropInfo info;
343 void* voidPtr = static_cast<void*>(new char[0]);
344 info.pixelMap = PixelMap::CreatePixelMap(voidPtr);
345 return info;
346 };
347 eventHub->SetOnDragStart(std::move(onDragStart));
348
349 /**
350 * @tc.steps: step3. Create gestureEventHub and dragEventActuator.
351 */
352 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
353 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
354 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
355
356 /**
357 * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent.
358 * @tc.expected: dragEventActuator's userCallback_ is not null.
359 */
360 TouchTestResult finalResult;
361 ResponseLinkResult responseLinkResult;
362 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anondbf094731302(GestureEvent& info) 363 GestureEventFunc actionStart = [&unknownPropertyValue](GestureEvent& info) {
364 unknownPropertyValue = info.GetScale();
365 };
__anondbf094731402(GestureEvent& info) 366 GestureEventFunc actionUpdate = [&unknownPropertyValue](GestureEvent& info) {
367 unknownPropertyValue = info.GetScale();
368 };
__anondbf094731502(GestureEvent& info) 369 GestureEventFunc actionEnd = [&unknownPropertyValue](GestureEvent& info) {
370 unknownPropertyValue = info.GetScale();
371 };
__anondbf094731602() 372 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
373 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
374 };
375 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
376 std::move(actionEnd), std::move(actionCancel));
377 dragEventActuator->ReplaceDragEvent(dragEvent);
378 dragEventActuator->SetCustomDragEvent(dragEvent);
379 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
380
381 /**
382 * @tc.steps: step5. Invoke OnCollectTouchTarget when userCallback_ is not null.
383 * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's callback is not nullptr.
384 */
385 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
386 frameNode->GetOrCreateFocusHub();
387 EXPECT_NE(getEventTargetImpl, nullptr);
388 dragEventActuator->OnCollectTouchTarget(
389 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
390 EXPECT_NE(dragEventActuator->longPressRecognizer_, nullptr);
391 EXPECT_NE(dragEventActuator->longPressRecognizer_->callback_, nullptr);
392
393 /**
394 * @tc.steps: step6. Invoke thumbnail callback.
395 * @tc.expected: GestureEventHub's pixelMap is not nullptr.
396 */
397 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
398 EXPECT_NE(gestureEventHub->pixelMap_, nullptr);
399 }
400
401 /**
402 * @tc.name: DragEventTestNg003
403 * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
404 * @tc.type: FUNC
405 */
406 HWTEST_F(DragEventTestNg, DragEventTestNg003, TestSize.Level1)
407 {
408 /**
409 * @tc.steps: step1. Create DragEventActuator.
410 */
411 SystemProperties::debugEnabled_ = true;
412 auto eventHub = AceType::MakeRefPtr<EventHub>();
413 auto frameNode = FrameNode::CreateFrameNode(
414 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
415 DragDropInfo dragDropInfo;
416 frameNode->SetDragPreview(dragDropInfo);
417 frameNode->SetDraggable(true);
418 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
419 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
420 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
421 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE_EQUAL_DEFAULT);
422 /**
423 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
424 * @tc.expected: dragEventActuator's userCallback_ is not null.
425 */
__anondbf094731702(GestureEvent& info) 426 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094731802(GestureEvent& info) 427 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094731902(GestureEvent& info) 428 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094731a02() 429 GestureEventNoParameter actionCancel = []() {};
430 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
431 std::move(actionEnd), std::move(actionCancel));
432 dragEventActuator->ReplaceDragEvent(dragEvent);
433 dragEventActuator->SetCustomDragEvent(dragEvent);
434 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
435 /**
436 * @tc.steps: step3. Invoke OnCollectTouchTarget when callback_ is not null.
437 * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's HasThumbnailCallback() return true.
438 */
439 TouchTestResult finalResult;
440 ResponseLinkResult responseLinkResult;
441 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
442 EXPECT_NE(getEventTargetImpl, nullptr);
443 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), false);
444 frameNode->GetOrCreateFocusHub();
445 dragEventActuator->OnCollectTouchTarget(
446 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
447 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
448 dragEventActuator->OnCollectTouchTarget(
449 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
450 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
451 /**
452 * @tc.steps: step4. Invoke thumbnail callback.
453 * @tc.expected: cover dragPreviewInfo.customNode == nullptr, dragPreviewInfo.pixelMap == nullptr.
454 */
455 EXPECT_EQ(frameNode->GetDragPreview().customNode, nullptr);
456 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
457 EXPECT_EQ(gestureEventHub->GetPixelMap(), frameNode->GetRenderContext()->GetThumbnailPixelMap());
458 /**
459 * @tc.steps: step5. Invoke thumbnail callback.
460 * @tc.expected: cover dragPreviewInfo.customNode != nullptr, dragPreviewInfo.pixelMap == nullptr.
461 */
462 RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
463 dragDropInfo.customNode = customNode;
464 frameNode->SetDragPreview(dragDropInfo);
465 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
466 EXPECT_NE(frameNode->GetDragPreview().customNode, nullptr);
467 }
468
469 /**
470 * @tc.name: DragEventTestNg004
471 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget.
472 * @tc.type: FUNC
473 */
474 HWTEST_F(DragEventTestNg, DragEventTestNg004, TestSize.Level1)
475 {
476 /**
477 * @tc.steps: step1. Create DragEventActuator.
478 */
479 SystemProperties::debugEnabled_ = true;
480 auto eventHub = AceType::MakeRefPtr<EventHub>();
481 auto frameNode = FrameNode::CreateFrameNode(
482 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
483 DragDropInfo dragDropInfo;
484 frameNode->SetDragPreview(dragDropInfo);
485 frameNode->SetDraggable(true);
486 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
487 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
488 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
489 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
490 /**
491 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
492 * @tc.expected: dragEventActuator's userCallback_ is not null.
493 */
__anondbf094731b02(GestureEvent& info) 494 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094731c02(GestureEvent& info) 495 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094731d02(GestureEvent& info) 496 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094731e02() 497 GestureEventNoParameter actionCancel = []() {};
498 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
499 std::move(actionEnd), std::move(actionCancel));
500 dragEventActuator->ReplaceDragEvent(dragEvent);
501 dragEventActuator->SetCustomDragEvent(dragEvent);
502 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
503 /**
504 * @tc.steps: step3. Call the function OnCollectTouchTarget when sourceType is SourceType::MOUSE.
505 * @tc.expected: cover touchRestrict.sourceType == SourceType::MOUSE.
506 */
507 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
508 EXPECT_NE(getEventTargetImpl, nullptr);
509 TouchTestResult finalResult;
510 ResponseLinkResult responseLinkResult;
511 frameNode->GetOrCreateFocusHub();
512 dragEventActuator->OnCollectTouchTarget(
513 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT_MOUSE, getEventTargetImpl, finalResult, responseLinkResult);
514 EXPECT_FALSE(finalResult.empty());
515 }
516
517 /**
518 * @tc.name: DragEventTestNg005
519 * @tc.desc: Create DragEventActuator and invoke longPressUpdate callback.
520 * @tc.type: FUNC
521 */
522 HWTEST_F(DragEventTestNg, DragEventTestNg005, TestSize.Level1)
523 {
524 /**
525 * @tc.steps: step1. Create DragEventActuator.
526 */
527 auto eventHub = AceType::MakeRefPtr<EventHub>();
528 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
529 DragDropInfo dragDropInfo;
530 frameNode->SetDragPreview(dragDropInfo);
531 frameNode->SetDraggable(true);
532 frameNode->GetOrCreateFocusHub();
533 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
534 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
535 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
536 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
537 /**
538 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
539 * @tc.expected: dragEventActuator's userCallback_ is not null.
540 */
__anondbf094731f02(GestureEvent& info) 541 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094732002(GestureEvent& info) 542 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094732102(GestureEvent& info) 543 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094732202() 544 GestureEventNoParameter actionCancel = []() {};
545 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
546 std::move(actionEnd), std::move(actionCancel));
547 dragEventActuator->ReplaceDragEvent(dragEvent);
548 dragEventActuator->SetCustomDragEvent(dragEvent);
549 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
550 /**
551 * @tc.steps: step3. Create callback and set as dragEventActuator's longPressUpdate_.
552 * @tc.expected: previewLongPressRecognizer_'s onAction_ is not null.
553 */
554 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
555 TouchTestResult finalResult;
556 ResponseLinkResult responseLinkResult;
557 frameNode->GetOrCreateFocusHub();
558 dragEventActuator->OnCollectTouchTarget(
559 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
560 EXPECT_NE(dragEventActuator->previewLongPressRecognizer_->onAction_, nullptr);
561 /**
562 * @tc.steps: step4. Invoke longPressUpdateValue callback.
563 * @tc.expected: cover longPressUpdateValue callback.
564 */
565 SystemProperties::debugEnabled_ = true;
566 GestureEvent info = GestureEvent();
567 (*(dragEventActuator->longPressRecognizer_->onAction_))(info);
568 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
569 SystemProperties::debugEnabled_ = false;
570 (*(dragEventActuator->longPressRecognizer_->onAction_))(info);
571 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
572 /**
573 * @tc.steps: step5. Invoke longPressUpdate callback.
574 * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == true.
575 */
576 SystemProperties::debugEnabled_ = true;
577 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
578 EXPECT_EQ(dragEventActuator->IsAllowedDrag(), true);
579 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
580 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
581 /**
582 * @tc.steps: step6. Invoke longPressUpdate callback.
583 * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == false.
584 */
585 SystemProperties::debugEnabled_ = false;
586 frameNode->SetDraggable(false);
587 EXPECT_EQ(dragEventActuator->IsAllowedDrag(), false);
588 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
589 EXPECT_EQ(dragEventActuator->isReceivedLongPress_, true);
590 /**
591 * @tc.steps: step7. Invoke longPressUpdate callback.
592 * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == false.
593 */
594 gestureEventHub->SetTextDraggable(true);
595 gestureEventHub->SetIsTextDraggable(false);
596 dragEventActuator->SetIsNotInPreviewState(true);
597 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
598 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
599 /**
600 * @tc.steps: step8. Invoke longPressUpdate callback.
601 * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == true.
602 */
603 gestureEventHub->SetIsTextDraggable(true);
604 dragEventActuator->SetIsNotInPreviewState(true);
605 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
606 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
607 }
608
609 /**
610 * @tc.name: DragEventTestNg006
611 * @tc.desc: Create DragEventActuator and invoke onActionStart callback.
612 * @tc.type: FUNC
613 */
614 HWTEST_F(DragEventTestNg, DragEventTestNg006, TestSize.Level1)
615 {
616 /**
617 * @tc.steps: step1. Create DragEventActuator.
618 */
619 SystemProperties::debugEnabled_ = true;
620 auto eventHub = AceType::MakeRefPtr<EventHub>();
621 auto frameNode = FrameNode::CreateFrameNode(
622 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
623 frameNode->SetDraggable(true);
624 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
625 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
626 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
627 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
628 /**
629 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
630 * @tc.expected: dragEventActuator's userCallback_ is not null.
631 */
632 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anondbf094732302(GestureEvent& info) 633 auto actionStart = [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
__anondbf094732402(GestureEvent& info) 634 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094732502(GestureEvent& info) 635 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094732602() 636 GestureEventNoParameter actionCancel = []() {};
637 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
638 std::move(actionEnd), std::move(actionCancel));
639 dragEventActuator->ReplaceDragEvent(dragEvent);
640 dragEventActuator->SetCustomDragEvent(dragEvent);
641 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
642 /**
643 * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
644 * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionStart is not nullptr.
645 */
646 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
647 EXPECT_NE(getEventTargetImpl, nullptr);
648 TouchTestResult finalResult;
649 ResponseLinkResult responseLinkResult;
650 frameNode->GetOrCreateFocusHub();
651 dragEventActuator->OnCollectTouchTarget(
652 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
653 EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
654
655 /**
656 * @tc.steps: Create prepareDragFrameNode for drag start.
657 * @tc.expected: Create prepareDragFrameNode success.
658 */
659 auto pipeline = PipelineContext::GetCurrentContext();
660 auto dragDropManager = pipeline->GetDragDropManager();
661 ASSERT_NE(dragDropManager, nullptr);
662 DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
663
664 /**
665 * @tc.steps: step4. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
666 * @tc.expected: cover pattern->IsSelected() == false or GetMouseStatus() == MouseStatus::MOVE
667 */
668 GestureEvent info = GestureEvent();
669 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
670 info.SetSourceDevice(SourceType::MOUSE);
671 gestureEventHub->SetTextDraggable(true);
672 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
673 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
674
675 auto pattern = frameNode->GetPattern<TextPattern>();
676 pattern->mouseStatus_ = MouseStatus::MOVE;
677 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
678 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
679 EXPECT_EQ(pattern->GetMouseStatus(), MouseStatus::MOVE);
680 /**
681 * @tc.steps: step5. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
682 * @tc.expected: cover GetTextDraggable() is false, Trigger drag start event set by user.
683 */
684 gestureEventHub->SetTextDraggable(false);
685 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
686 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
687 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
688 /**
689 * @tc.steps: step6. Invoke onActionStart callback, when info.GetSourceDevice() is not SourceType::MOUSE.
690 * @tc.expected: cover gestureHub->GetTextDraggable() is true
691 */
692 info.SetSourceDevice(SourceType::TOUCH);
693 gestureEventHub->SetTextDraggable(true);
694 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
695 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
696 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
697 }
698
699 /**
700 * @tc.name: DragEventTestNg007
701 * @tc.desc: Create DragEventActuator and invoke onActionCancel callback.
702 * @tc.type: FUNC
703 */
704 HWTEST_F(DragEventTestNg, DragEventTestNg007, TestSize.Level1)
705 {
706 /**
707 * @tc.steps: step1. Create DragEventActuator.
708 */
709 auto eventHub = AceType::MakeRefPtr<EventHub>();
710 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
711 frameNode->SetDraggable(true);
712 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
713 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
714 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
715 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
716 /**
717 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
718 * @tc.expected: dragEventActuator's userCallback_ is not null.
719 */
720 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anondbf094732702(GestureEvent& info) 721 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094732802(GestureEvent& info) 722 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094732902(GestureEvent& info) 723 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094732a02() 724 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
725 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
726 };
727 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
728 std::move(actionEnd), std::move(actionCancel));
729 dragEventActuator->ReplaceDragEvent(dragEvent);
730 dragEventActuator->SetCustomDragEvent(dragEvent);
731 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
732 /**
733 * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
734 * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionCancel is not nullptr.
735 */
736 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
737 TouchTestResult finalResult;
738 ResponseLinkResult responseLinkResult;
739 frameNode->GetOrCreateFocusHub();
740 dragEventActuator->OnCollectTouchTarget(
741 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
742 dragEventActuator->panRecognizer_->onActionCancel_ = std::make_unique<GestureEventFunc>(
__anondbf094732b02(GestureEvent& info) 743 [&unknownPropertyValue](GestureEvent& info) { unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE; });
744 EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
745 /**
746 * @tc.steps: step4. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
747 * @tc.expected: cover gestureHub->GetIsTextDraggable() is false.
748 */
749 SystemProperties::debugEnabled_ = true;
750 GestureEvent info = GestureEvent();
751 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
752 gestureEventHub->SetTextDraggable(true);
753 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
754 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
755 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
756 /**
757 * @tc.steps: step5. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
758 * @tc.expected: cover gestureHub->GetIsTextDraggable() is true.
759 */
760 SystemProperties::debugEnabled_ = false;
761 gestureEventHub->SetIsTextDraggable(true);
762 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
763 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
764 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
765 /**
766 * @tc.steps: step6. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
767 * @tc.expected: cover getDeviceType() != SourceType::MOUSE.
768 */
769 eventHub->AttachHost(nullptr);
770 EXPECT_EQ(dragEventActuator->GetIsBindOverlayValue(dragEventActuator), true);
771 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
772 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
773 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
774 /**
775 * @tc.steps: step7. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
776 * @tc.expected: cover getDeviceType() == SourceType::MOUSE.
777 */
778 auto context = PipelineContext::GetCurrentContext();
779 ASSERT_NE(context, nullptr);
780 context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
781 auto taskExecutor = context->GetTaskExecutor();
782 ASSERT_NE(taskExecutor, nullptr);
783 dragEventActuator->panRecognizer_->deviceType_ = SourceType::MOUSE;
784 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
785 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
786 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
787
788 gestureEventHub->SetTextDraggable(false);
789 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
790 (*(dragEventActuator->panRecognizer_->onActionCancel_))(info);
791 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
792 }
793
794 /**
795 * @tc.name: DragEventTestNg008
796 * @tc.desc: Create DragEventActuator and invoke HideTextAnimation function.
797 * @tc.type: FUNC
798 */
799 HWTEST_F(DragEventTestNg, DragEventTestNg008, TestSize.Level1)
800 {
801 /**
802 * @tc.steps: step1. Create DragEventActuator.
803 */
804 auto eventHub = AceType::MakeRefPtr<EventHub>();
805 auto frameNode = FrameNode::CreateFrameNode(
806 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
807 NG::DragDropInfo dragPreviewInfo;
808 void* voidPtr = static_cast<void*>(new char[0]);
809 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
810 dragPreviewInfo.pixelMap = pixelMap;
811 frameNode->SetDragPreview(dragPreviewInfo);
812 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
813 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
814 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
815 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
816 /**
817 * @tc.steps: step2. Invoke HideTextAnimation function, when isAllowedDrag is false.
818 * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
819 */
820 SystemProperties::debugEnabled_ = true;
821 frameNode->SetDraggable(false);
822 gestureEventHub->SetTextDraggable(false);
823 dragEventActuator->HideTextAnimation();
824 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
825 gestureEventHub->SetTextDraggable(true);
826 dragEventActuator->HideTextAnimation();
827 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
828 /**
829 * @tc.steps: step3. Invoke HideTextAnimation function, when isAllowedDrag is true.
830 * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
831 */
832 SystemProperties::debugEnabled_ = false;
833 frameNode->SetDraggable(true);
834 gestureEventHub->SetTextDraggable(false);
835 dragEventActuator->HideTextAnimation();
836 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
837 gestureEventHub->SetTextDraggable(true);
838 dragEventActuator->HideTextAnimation();
839 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
840 }
841
842 /**
843 * @tc.name: DragEventTestNg009
844 * @tc.desc: Invoke GetPreviewPixelMap.
845 * @tc.type: FUNC
846 */
847 HWTEST_F(DragEventTestNg, DragEventTestNg009, TestSize.Level1)
848 {
849 EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(NO_COMPONENT_ID, nullptr), nullptr);
850 EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(COMPONENT_ID, nullptr), nullptr);
851
852 auto frameNode = FrameNode::CreateFrameNode(
853 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
854
855 EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(NO_COMPONENT_ID, frameNode), nullptr);
856 EXPECT_EQ(DragDropFuncWrapper::GetPreviewPixelMap(COMPONENT_ID, frameNode), nullptr);
857 }
858
859 /**
860 * @tc.name: DragEventExecutePreDragActionTest001
861 * @tc.desc: Create DragEventActuator and test ExecutePreDragAction function.
862 * @tc.type: FUNC
863 */
864 HWTEST_F(DragEventTestNg, DragEventExecutePreDragActionTest001, TestSize.Level1)
865 {
866 /**
867 * @tc.steps: step1. Create DragEventActuator.
868 */
869 auto eventHub = AceType::MakeRefPtr<EventHub>();
870 auto frameNode = FrameNode::CreateFrameNode(
871 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
872 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
873 frameNode->eventHub_ = eventHub;
874 frameNode->SetDraggable(true);
875 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
876 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
877 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
878
879 /**
880 * @tc.steps: step2. Create onPreDrag function and bind to eventHub.
881 * @tc.expected: Bind onPreDrag function successful.
882 */
883 MockFunction<void(const PreDragStatus&)> mockOnPreFunction;
884 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_DETECTING_STATUS)).WillOnce(Return());
885 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION)).WillOnce(Return());
886 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::PREVIEW_LIFT_STARTED)).WillOnce(Return());
887 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::PREVIEW_LANDING_STARTED)).WillOnce(Return());
888 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG)).WillOnce(Return());
889 std::function<void(const PreDragStatus&)> mockOnPreDragFunc = mockOnPreFunction.AsStdFunction();
890
__anondbf094732c02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 891 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
892 DragDropInfo info;
893 return info;
894 };
895 eventHub->SetOnDragStart(std::move(onDragStart));
896 eventHub->SetOnPreDrag(mockOnPreDragFunc);
897 EXPECT_NE(eventHub->GetOnPreDrag(), nullptr);
898
899 /**
900 * @tc.steps: step3. Call ExecutePreDragAction Function.
901 * @tc.expected: Call function successful.
902 */
903 auto pipeline = PipelineContext::GetMainPipelineContext();
904 auto dragDropManager = pipeline->GetDragDropManager();
905 ASSERT_NE(dragDropManager, nullptr);
906 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_DETECTING_STATUS);
907 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS, frameNode);
908 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION);
909 DragEventActuator::ExecutePreDragAction(PreDragStatus::READY_TO_TRIGGER_DRAG_ACTION, frameNode);
910 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LIFT_STARTED);
911 DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LIFT_STARTED, frameNode);
912 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LIFT_FINISHED);
913 DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LIFT_FINISHED, frameNode);
914 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LANDING_STARTED);
915 DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LANDING_STARTED, frameNode);
916 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::PREVIEW_LANDING_FINISHED);
917 DragEventActuator::ExecutePreDragAction(PreDragStatus::PREVIEW_LANDING_FINISHED, frameNode);
918 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_CANCELED_BEFORE_DRAG);
919 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG, frameNode);
920 EXPECT_EQ(DragDropGlobalController::GetInstance().GetPreDragStatus(), PreDragStatus::ACTION_CANCELED_BEFORE_DRAG);
921 }
922
923 /**
924 * @tc.name: DragEventExecutePreDragActionTest002
925 * @tc.desc: Create DragEventActuator and test ExecutePreDragAction function.
926 * @tc.type: FUNC
927 */
928 HWTEST_F(DragEventTestNg, DragEventExecutePreDragActionTest002, TestSize.Level1)
929 {
930 /**
931 * @tc.steps: step1. Create DragEventActuator.
932 */
933 auto eventHub = AceType::MakeRefPtr<EventHub>();
934 auto frameNode = FrameNode::CreateFrameNode(
935 V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
936 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
937 frameNode->eventHub_ = eventHub;
938 frameNode->SetDraggable(true);
939 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
940 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
941 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
942 auto pipeline = PipelineContext::GetMainPipelineContext();
943 auto dragDropManager = pipeline->GetDragDropManager();
944 ASSERT_NE(dragDropManager, nullptr);
945 DragDropGlobalController::GetInstance().SetPrepareDragFrameNode(frameNode);
946 DragDropGlobalController::GetInstance().SetPreDragStatus(PreDragStatus::ACTION_DETECTING_STATUS);
947 /**
948 * @tc.steps: step2. Create onPreDrag function and bind to eventHub.
949 * @tc.expected: Bind onPreDrag function successful.
950 */
951 MockFunction<void(const PreDragStatus&)> mockOnPreFunction;
952 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_DETECTING_STATUS)).WillOnce(Return());
953 EXPECT_CALL(mockOnPreFunction, Call(PreDragStatus::ACTION_CANCELED_BEFORE_DRAG)).WillOnce(Return());
954 std::function<void(const PreDragStatus&)> mockOnPreDragFunc = mockOnPreFunction.AsStdFunction();
955
__anondbf094732d02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 956 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
957 DragDropInfo info;
958 return info;
959 };
960 eventHub->SetOnDragStart(std::move(onDragStart));
961 eventHub->SetOnPreDrag(mockOnPreDragFunc);
962 EXPECT_NE(eventHub->GetOnPreDrag(), nullptr);
963
964 /**
965 * @tc.steps: step3. Call ExecutePreDragAction Function with same status.
966 * @tc.expected: first call function successful, second call canceled.
967 */
968 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
969 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
970
971 /**
972 * @tc.steps: step4. Call ExecutePreDragAction Function with fail parameters.
973 * @tc.expected: not call any function.
974 */
975 gestureEventHub->SetTextDraggable(true);
976 frameNode->SetDraggable(false);
977 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
978 dragDropManager->ResetDragging(DragDropMgrState::DRAGGING);
979 DragEventActuator::ExecutePreDragAction(PreDragStatus::ACTION_DETECTING_STATUS);
980 }
981
982 /**
983 * @tc.name: DragEventShowBadgeTest01
984 * @tc.desc: Test the GetCustomerBadgeNumber function of setting different NumberBadge.
985 * @tc.type: FUNC
986 */
987 HWTEST_F(DragEventTestNg, DragEventShowBadgeTest01, TestSize.Level1)
988 {
989 /**
990 * @tc.steps: step1. Create frameNode.
991 */
992 auto frameNode = FrameNode::CreateFrameNode(
993 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
994 EXPECT_NE(frameNode, nullptr);
995
996 /**
997 * @tc.steps: step2. Do not set NumberBadge.
998 * @tc.expected: badgeNumber has no value.
999 */
1000 auto dragPreviewOptions = frameNode->GetDragPreviewOption();
1001 auto badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1002 EXPECT_EQ(badgeNumber.has_value(), false);
1003
1004 /**
1005 * @tc.steps: step3. Set NumberBadge value is true.
1006 * @tc.expected: badgeNumber has no value.
1007 */
1008 NG::DragPreviewOption previewOptions;
1009 previewOptions.isNumber = false;
1010 previewOptions.badgeNumber = true;
1011 frameNode->SetDragPreviewOptions(previewOptions);
1012 dragPreviewOptions = frameNode->GetDragPreviewOption();
1013 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1014 EXPECT_EQ(badgeNumber.has_value(), false);
1015
1016 /**
1017 * @tc.steps: step4. Set NumberBadge value is false.
1018 * @tc.expected: badgeNumber has value.
1019 */
1020 previewOptions.isNumber = false;
1021 previewOptions.badgeNumber = false;
1022 frameNode->SetDragPreviewOptions(previewOptions);
1023 dragPreviewOptions = frameNode->GetDragPreviewOption();
1024 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1025 EXPECT_EQ(badgeNumber.has_value(), true);
1026 EXPECT_EQ(badgeNumber.value(), 1);
1027
1028 /**
1029 * @tc.steps: step5. Set the NumberBadge to a special value 3.
1030 * @tc.expected: badgeNumber is the set value.
1031 */
1032 previewOptions.isNumber = true;
1033 previewOptions.badgeNumber = NUMBER_BADGE_SIZE_3;
1034 frameNode->SetDragPreviewOptions(previewOptions);
1035 dragPreviewOptions = frameNode->GetDragPreviewOption();
1036 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1037 EXPECT_EQ(badgeNumber.has_value(), true);
1038 EXPECT_EQ(badgeNumber.value(), NUMBER_BADGE_SIZE_3);
1039
1040 /**
1041 * @tc.steps: step6. Set the NumberBadge to a special value 0.
1042 * @tc.expected: badgeNumber is 1.
1043 */
1044 previewOptions.isNumber = true;
1045 previewOptions.badgeNumber = 0;
1046 frameNode->SetDragPreviewOptions(previewOptions);
1047 dragPreviewOptions = frameNode->GetDragPreviewOption();
1048 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1049 EXPECT_EQ(badgeNumber.has_value(), true);
1050 EXPECT_EQ(badgeNumber.value(), 1);
1051
1052 /**
1053 * @tc.steps: step7. Set the NumberBadge to a special value -1.
1054 * @tc.expected: badgeNumber is 1.
1055 */
1056 previewOptions.isNumber = true;
1057 previewOptions.badgeNumber = -1;
1058 frameNode->SetDragPreviewOptions(previewOptions);
1059 dragPreviewOptions = frameNode->GetDragPreviewOption();
1060 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1061 EXPECT_EQ(badgeNumber.has_value(), true);
1062 EXPECT_EQ(badgeNumber.value(), 1);
1063
1064 /**
1065 * @tc.steps: step8. Set the NumberBadge to a special value 100.
1066 * @tc.expected: badgeNumber is the set value.
1067 */
1068 previewOptions.isNumber = true;
1069 previewOptions.badgeNumber = NUMBER_BADGE_SIZE_100;
1070 frameNode->SetDragPreviewOptions(previewOptions);
1071 dragPreviewOptions = frameNode->GetDragPreviewOption();
1072 badgeNumber = dragPreviewOptions.GetCustomerBadgeNumber();
1073 EXPECT_EQ(badgeNumber.has_value(), true);
1074 EXPECT_EQ(badgeNumber.value(), NUMBER_BADGE_SIZE_100);
1075 }
1076
1077 /**
1078 * @tc.name: TestCreateGatherNode001
1079 * @tc.desc: Create List GatherNode
1080 * @tc.type: FUNC
1081 */
1082 HWTEST_F(DragEventTestNg, TestCreateGatherNode001, TestSize.Level1)
1083 {
1084 /**
1085 * @tc.steps: step1. Create List Node.
1086 */
1087 auto listNode = FrameNode::CreateFrameNode(
1088 V2::LIST_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ListPattern>());
1089 ASSERT_NE(listNode, nullptr);
1090 /**
1091 * @tc.steps: step2. Create List Item Node.
1092 */
1093 auto listItemNode1 = FrameNode::CreateFrameNode(V2::LIST_ITEM_ETS_TAG,
1094 ElementRegister::GetInstance()->MakeUniqueId(),
1095 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1096 ASSERT_NE(listItemNode1, nullptr);
1097 auto listItemNode2 = FrameNode::CreateFrameNode(V2::LIST_ITEM_ETS_TAG,
1098 ElementRegister::GetInstance()->MakeUniqueId(),
1099 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1100 ASSERT_NE(listItemNode2, nullptr);
1101 auto itemPattern1 = listItemNode1->GetPattern<ListItemPattern>();
1102 ASSERT_NE(itemPattern1, nullptr);
1103 itemPattern1->SetSelected(true);
1104 auto itemPattern2 = listItemNode2->GetPattern<ListItemPattern>();
1105 ASSERT_NE(itemPattern2, nullptr);
1106 itemPattern2->SetSelected(true);
1107 NG::DragPreviewOption option { true, false, true };
1108 listItemNode1->SetDragPreviewOptions(option);
1109 listNode->AddChild(listItemNode1);
1110 listNode->AddChild(listItemNode2);
1111 /**
1112 * @tc.steps: step3. Create DragEventActuator.
1113 */
1114 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094732e02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1115 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1116 DragDropInfo info;
1117 return info;
1118 };
1119 eventHub->SetOnDragStart(std::move(onDragStart));
1120 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode1));
1121 listItemNode1->eventHub_ = eventHub;
1122 listItemNode1->SetDraggable(true);
1123 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1124 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1125 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1126 /**
1127 * @tc.steps: step4. Create GatherNode.
1128 */
1129 dragEventActuator->FindItemParentNode(listItemNode1);
1130 auto gatherNode = DragEventActuator::CreateGatherNode(dragEventActuator);
1131 EXPECT_EQ(gatherNode, nullptr);
1132 }
1133
1134 /**
1135 * @tc.name: TestCreateGatherNode002
1136 * @tc.desc: Create Grid GatherNode
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(DragEventTestNg, TestCreateGatherNode002, TestSize.Level1)
1140 {
1141 /**
1142 * @tc.steps: step1. Create Grid Node.
1143 */
1144 auto gridNode = FrameNode::CreateFrameNode(
1145 V2::GRID_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<GridPattern>());
1146 ASSERT_NE(gridNode, nullptr);
1147 /**
1148 * @tc.steps: step2. Create Grid Item Node.
1149 */
1150 auto gridItemNode1 = FrameNode::CreateFrameNode(
1151 V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1152 AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1153 ASSERT_NE(gridItemNode1, nullptr);
1154 auto gridItemNode2 = FrameNode::CreateFrameNode(
1155 V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1156 AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1157 ASSERT_NE(gridItemNode2, nullptr);
1158 auto itemPattern1 = gridItemNode1->GetPattern<GridItemPattern>();
1159 ASSERT_NE(itemPattern1, nullptr);
1160 itemPattern1->SetSelected(true);
1161 auto itemPattern2 = gridItemNode2->GetPattern<GridItemPattern>();
1162 ASSERT_NE(itemPattern2, nullptr);
1163 itemPattern2->SetSelected(true);
1164 NG::DragPreviewOption option { true, false, true };
1165 gridItemNode1->SetDragPreviewOptions(option);
1166 gridNode->AddChild(gridItemNode1);
1167 gridNode->AddChild(gridItemNode2);
1168 /**
1169 * @tc.steps: step3. Create DragEventActuator.
1170 */
1171 auto eventHub = AceType::MakeRefPtr<EventHub>();
1172 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode1));
__anondbf094732f02(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1173 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1174 DragDropInfo info;
1175 return info;
1176 };
1177 eventHub->SetOnDragStart(std::move(onDragStart));
1178 gridItemNode1->eventHub_ = eventHub;
1179 gridItemNode1->SetDraggable(true);
1180 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1181 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1182 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1183 /**
1184 * @tc.steps: step4. Create GatherNode.
1185 */
1186 dragEventActuator->FindItemParentNode(gridItemNode1);
1187 auto gatherNode = DragEventActuator::CreateGatherNode(dragEventActuator);
1188 EXPECT_EQ(gatherNode, nullptr);
1189 }
1190
1191 /**
1192 * @tc.name: TestCreateImageNode001
1193 * @tc.desc: Create ImageNode of FrameNode
1194 * @tc.type: FUNC
1195 */
1196 HWTEST_F(DragEventTestNg, TestCreateImageNode001, TestSize.Level1)
1197 {
1198 /**
1199 * @tc.steps: step1. Create FrameNode.
1200 */
1201 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1202 ASSERT_NE(frameNode, nullptr);
1203 /**
1204 * @tc.steps: step2. Create GatherNodeChildInfo.
1205 */
1206 NG::GatherNodeChildInfo gatherNodeChildInfo;
1207 /**
1208 * @tc.steps: step3. Create ImageNode.
1209 */
1210 auto imageNode = DragEventActuator::CreateImageNode(frameNode, gatherNodeChildInfo);
1211 EXPECT_NE(imageNode, nullptr);
1212 }
1213
1214 /**
1215 * @tc.name: TestResetNode001
1216 * @tc.desc: Reset Node scale
1217 * @tc.type: FUNC
1218 */
1219 HWTEST_F(DragEventTestNg, TestResetNode001, TestSize.Level1)
1220 {
1221 /**
1222 * @tc.steps: step1. Create FrameNode.
1223 */
1224 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1225 ASSERT_NE(frameNode, nullptr);
1226 NG::DragPreviewOption option { true, true, false };
1227 frameNode->SetDragPreviewOptions(option);
1228 /**
1229 * @tc.steps: step2. Set Scale
1230 */
1231 auto renderContext = frameNode->GetRenderContext();
1232 ASSERT_NE(renderContext, nullptr);
1233 renderContext->UpdateTransformScale({0.9f, 0.9f});
1234 auto scale = renderContext->GetTransformScaleValue({ 1.0f, 1.0f });
1235 EXPECT_EQ(scale.x, 0.9f);
1236 EXPECT_EQ(scale.y, 0.9f);
1237 /**
1238 * @tc.steps: step3. Reset frameNode scale.
1239 */
1240 DragDropFuncWrapper::ResetNode(frameNode);
1241 auto resetScale = renderContext->GetTransformScaleValue({ 0.0f, 0.0f });
1242 EXPECT_EQ(resetScale.x, 1.0f);
1243 EXPECT_EQ(resetScale.y, 1.0f);
1244 }
1245
1246 /**
1247 * @tc.name: TestGetFrameNodePreviewPixelMap001
1248 * @tc.desc: Create frameNode and get DragPreviewInfo.PixelMap.
1249 * @tc.type: FUNC
1250 */
1251 HWTEST_F(DragEventTestNg, TestGetFrameNodePreviewPixelMap002, TestSize.Level1)
1252 {
1253 /**
1254 * @tc.steps: step1. Create FrameNode.
1255 */
1256 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1257 ASSERT_NE(frameNode, nullptr);
1258 /**
1259 * @tc.steps: step2. Set DragPreviewInfo.
1260 */
1261 NG::DragDropInfo dragPreviewInfo;
1262 void* voidPtr = static_cast<void*>(new char[0]);
1263 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
1264 ASSERT_NE(pixelMap, nullptr);
1265 dragPreviewInfo.pixelMap = pixelMap;
1266 frameNode->SetDragPreview(dragPreviewInfo);
1267 /**
1268 * @tc.steps: step3. Get PixelMap.
1269 */
1270 DragEventActuator::GetFrameNodePreviewPixelMap(frameNode);
1271 /**
1272 * @tc.steps: step4. Get GestureEventHub.
1273 */
1274 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
1275 ASSERT_NE(gestureHub, nullptr);
1276 /**
1277 * @tc.steps: step5. Get DragPreviewPixelMap.
1278 */
1279 auto dragPreviewPixelMap = gestureHub->GetDragPreviewPixelMap();
1280 EXPECT_EQ(dragPreviewPixelMap, pixelMap);
1281 }
1282
1283 /**
1284 * @tc.name: TestIsBelongToMultiItemNode001
1285 * @tc.desc: Test IsBelongToMultiItemNode
1286 * @tc.type: FUNC
1287 */
1288 HWTEST_F(DragEventTestNg, TestIsBelongToMultiItemNode001, TestSize.Level1)
1289 {
1290 /**
1291 * @tc.steps: step1. Create ListItemNode.
1292 */
1293 auto listItemNode = FrameNode::CreateFrameNode(
1294 V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1295 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1296 ASSERT_NE(listItemNode, nullptr);
1297 auto itemPattern = listItemNode->GetPattern<ListItemPattern>();
1298 ASSERT_NE(itemPattern, nullptr);
1299 itemPattern->SetSelected(true);
1300 NG::DragPreviewOption option { true, false, true };
1301 listItemNode->SetDragPreviewOptions(option);
1302 /**
1303 * @tc.steps: step2. Create frameNode.
1304 */
1305 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1306 ASSERT_NE(frameNode, nullptr);
1307 listItemNode->AddChild(frameNode);
1308 /**
1309 * @tc.steps: step3. Create frameNode's DragEventActuator.
1310 */
1311 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094733002(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1312 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1313 DragDropInfo info;
1314 return info;
1315 };
1316 eventHub->SetOnDragStart(std::move(onDragStart));
1317 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode));
1318 listItemNode->eventHub_ = eventHub;
1319 listItemNode->SetDraggable(true);
1320 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1321 ASSERT_NE(gestureEventHub, nullptr);
1322 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1323 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1324 ASSERT_NE(dragEventActuator, nullptr);
1325 /**
1326 * @tc.steps: step4. Run IsBelongToMultiItemNode.
1327 */
1328 auto isBelongToMultiItemNode = dragEventActuator->IsBelongToMultiItemNode(frameNode);
1329 EXPECT_EQ(isBelongToMultiItemNode, true);
1330 }
1331
1332 /**
1333 * @tc.name: TestIsBelongToMultiItemNode002
1334 * @tc.desc: Test IsBelongToMultiItemNode
1335 * @tc.type: FUNC
1336 */
1337 HWTEST_F(DragEventTestNg, TestIsBelongToMultiItemNode002, TestSize.Level1)
1338 {
1339 /**
1340 * @tc.steps: step1. Create GridItemNode.
1341 */
1342 auto gridItemNode = FrameNode::CreateFrameNode(
1343 V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1344 AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1345 ASSERT_NE(gridItemNode, nullptr);
1346 auto itemPattern = gridItemNode->GetPattern<GridItemPattern>();
1347 ASSERT_NE(itemPattern, nullptr);
1348 itemPattern->SetSelected(true);
1349 NG::DragPreviewOption option { true, false, true };
1350 gridItemNode->SetDragPreviewOptions(option);
1351 /**
1352 * @tc.steps: step2. Create frameNode.
1353 */
1354 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
1355 ASSERT_NE(frameNode, nullptr);
1356 gridItemNode->AddChild(frameNode);
1357 /**
1358 * @tc.steps: step3. Create frameNode's DragEventActuator.
1359 */
1360 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094733102(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1361 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1362 DragDropInfo info;
1363 return info;
1364 };
1365 eventHub->SetOnDragStart(std::move(onDragStart));
1366 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode));
1367 gridItemNode->eventHub_ = eventHub;
1368 gridItemNode->SetDraggable(true);
1369 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1370 ASSERT_NE(gestureEventHub, nullptr);
1371 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1372 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1373 ASSERT_NE(dragEventActuator, nullptr);
1374 /**
1375 * @tc.steps: step4. Run IsBelongToMultiItemNode.
1376 */
1377 auto isBelongToMultiItemNode = dragEventActuator->IsBelongToMultiItemNode(frameNode);
1378 EXPECT_EQ(isBelongToMultiItemNode, true);
1379 }
1380
1381 /**
1382 * @tc.name: TestIsSelectedItemNode001
1383 * @tc.desc: Test IsSelectedItemNode
1384 * @tc.type: FUNC
1385 */
1386 HWTEST_F(DragEventTestNg, TestIsSelectedItemNode001, TestSize.Level1)
1387 {
1388 /**
1389 * @tc.steps: step1. Create GridItemNode.
1390 */
1391 auto gridItemNode = FrameNode::CreateFrameNode(
1392 V2::GRID_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1393 AceType::MakeRefPtr<GridItemPattern>(nullptr, GridItemStyle::NONE));
1394 ASSERT_NE(gridItemNode, nullptr);
1395 auto itemPattern = gridItemNode->GetPattern<GridItemPattern>();
1396 ASSERT_NE(itemPattern, nullptr);
1397 itemPattern->SetSelected(true);
1398 NG::DragPreviewOption option { true, false, true };
1399 gridItemNode->SetDragPreviewOptions(option);
1400 /**
1401 * @tc.steps: step2. Create GridItemNode's DragEventActuator.
1402 */
1403 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094733202(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1404 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1405 DragDropInfo info;
1406 return info;
1407 };
1408 eventHub->SetOnDragStart(std::move(onDragStart));
1409 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(gridItemNode));
1410 gridItemNode->eventHub_ = eventHub;
1411 gridItemNode->SetDraggable(true);
1412 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1413 ASSERT_NE(gestureEventHub, nullptr);
1414 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1415 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1416 ASSERT_NE(dragEventActuator, nullptr);
1417 /**
1418 * @tc.steps: step3. Run IsBelongToMultiItemNode.
1419 */
1420 auto isSelectedItemNode = dragEventActuator->IsSelectedItemNode(gridItemNode);
1421 EXPECT_EQ(isSelectedItemNode, true);
1422 }
1423
1424 /**
1425 * @tc.name: TestIsSelectedItemNode002
1426 * @tc.desc: Test IsSelectedItemNode
1427 * @tc.type: FUNC
1428 */
1429 HWTEST_F(DragEventTestNg, TestIsSelectedItemNode002, TestSize.Level1)
1430 {
1431 /**
1432 * @tc.steps: step1. Create ListItemNode.
1433 */
1434 auto listItemNode = FrameNode::CreateFrameNode(
1435 V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1436 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1437 ASSERT_NE(listItemNode, nullptr);
1438 auto itemPattern = listItemNode->GetPattern<ListItemPattern>();
1439 ASSERT_NE(itemPattern, nullptr);
1440 itemPattern->SetSelected(true);
1441 NG::DragPreviewOption option { true, false, true };
1442 listItemNode->SetDragPreviewOptions(option);
1443 /**
1444 * @tc.steps: step2. Create ListItemNode's DragEventActuator.
1445 */
1446 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094733302(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1447 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1448 DragDropInfo info;
1449 return info;
1450 };
1451 eventHub->SetOnDragStart(std::move(onDragStart));
1452 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode));
1453 listItemNode->eventHub_ = eventHub;
1454 listItemNode->SetDraggable(true);
1455 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1456 ASSERT_NE(gestureEventHub, nullptr);
1457 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1458 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1459 ASSERT_NE(dragEventActuator, nullptr);
1460 /**
1461 * @tc.steps: step3. Run IsBelongToMultiItemNode.
1462 */
1463 auto isSelectedItemNode = dragEventActuator->IsSelectedItemNode(listItemNode);
1464 EXPECT_EQ(isSelectedItemNode, true);
1465 }
1466
1467 /**
1468 * @tc.name: TestIsNeedGather001
1469 * @tc.desc: Test IsNeedGather
1470 * @tc.type: FUNC
1471 */
1472 HWTEST_F(DragEventTestNg, TestIsNeedGather001, TestSize.Level1)
1473 {
1474 /**
1475 * @tc.steps: step1. Create List Node.
1476 */
1477 auto listNode = FrameNode::CreateFrameNode(
1478 V2::LIST_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ListPattern>());
1479 ASSERT_NE(listNode, nullptr);
1480 /**
1481 * @tc.steps: step2. Create List Item Node.
1482 */
1483 auto listItemNode1 = FrameNode::CreateFrameNode(
1484 V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1485 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1486 ASSERT_NE(listItemNode1, nullptr);
1487 auto listItemNode2 = FrameNode::CreateFrameNode(
1488 V2::LIST_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
1489 AceType::MakeRefPtr<ListItemPattern>(nullptr, V2::ListItemStyle::NONE));
1490 ASSERT_NE(listItemNode2, nullptr);
1491 auto itemPattern1 = listItemNode1->GetPattern<ListItemPattern>();
1492 ASSERT_NE(itemPattern1, nullptr);
1493 itemPattern1->SetSelected(true);
1494 auto itemPattern2 = listItemNode2->GetPattern<ListItemPattern>();
1495 ASSERT_NE(itemPattern2, nullptr);
1496 itemPattern2->SetSelected(true);
1497 NG::DragPreviewOption option { true, false, true };
1498 listItemNode1->SetDragPreviewOptions(option);
1499 listNode->AddChild(listItemNode1);
1500 listNode->AddChild(listItemNode2);
1501 /**
1502 * @tc.steps: step3. Create DragEventActuator.
1503 */
1504 auto eventHub = AceType::MakeRefPtr<EventHub>();
__anondbf094733402(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 1505 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
1506 DragDropInfo info;
1507 return info;
1508 };
1509 eventHub->SetOnDragStart(std::move(onDragStart));
1510 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(listItemNode1));
1511 listItemNode1->eventHub_ = eventHub;
1512 listItemNode1->SetDraggable(true);
1513 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1514 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1515 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1516 /**
1517 * @tc.steps: step4. Test IsNeedGather().
1518 */
1519 dragEventActuator->IsBelongToMultiItemNode(listItemNode1);
1520 EXPECT_EQ(dragEventActuator->isSelectedItemNode_, true);
1521 dragEventActuator->FindItemParentNode(listItemNode1);
1522 bool isNeedGather = dragEventActuator->IsNeedGather();
1523 EXPECT_EQ(isNeedGather, false);
1524 }
1525
1526 /**
1527 * @tc.name: TestMountGatherNode001
1528 * @tc.desc: Test MountGatherNode.
1529 * @tc.type: FUNC
1530 */
1531 HWTEST_F(DragEventTestNg, TestMountGatherNode001, TestSize.Level1)
1532 {
1533 /**
1534 * @tc.steps: step1. Create DragEventActuator.
1535 */
1536 auto eventHub = AceType::MakeRefPtr<EventHub>();
1537 auto frameNode = FrameNode::CreateFrameNode(
1538 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1539 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1540 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1541 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1542 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1543 /**
1544 * @tc.steps: step2. Create a stackNode.
1545 */
1546 auto stackNode = FrameNode::GetOrCreateFrameNode(V2::STACK_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anondbf094733502() 1547 []() { return AceType::MakeRefPtr<StackPattern>(); });
1548 /**
1549 * @tc.steps: step3. Invoke MountGatherNode function.
1550 */
1551 auto pipeline = PipelineContext::GetCurrentContext();
1552 auto overlayManager = pipeline->GetOverlayManager();
1553 EXPECT_NE(overlayManager, nullptr);
1554 std::vector<NG::GatherNodeChildInfo> gatherNodeChildrenInfo;
1555 dragEventActuator->MountGatherNode(overlayManager, frameNode, stackNode, gatherNodeChildrenInfo);
1556 EXPECT_EQ(overlayManager->hasGatherNode_, true);
1557 }
1558
1559 /**
1560 * @tc.name: TestUpdateDefaultShadow
1561 * @tc.desc: Test get default shadow attribute.
1562 * @tc.type: FUNC
1563 */
1564 HWTEST_F(DragEventTestNg, TestUpdateDefaultShadow, TestSize.Level1)
1565 {
1566 /**
1567 * @tc.steps: step1. Create FrameNode.
1568 */
1569 auto frameNode = FrameNode::CreateFrameNode(
1570 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1571 EXPECT_NE(frameNode, nullptr);
1572 auto eventHub = AceType::MakeRefPtr<EventHub>();
1573 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1574 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1575 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1576 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1577 /**
1578 * @tc.steps: step2. get DragPreviewOption.
1579 */
1580 auto dragPreviewOption = frameNode->GetDragPreviewOption();
1581 EXPECT_EQ(dragPreviewOption.options.shadow, std::nullopt);
1582 /**
1583 * @tc.steps: step3. set enableDefaultShadow.
1584 */
1585 dragPreviewOption.isDefaultShadowEnabled = true;
1586 frameNode->SetDragPreviewOptions(dragPreviewOption);
1587 /**
1588 * @tc.steps: step4. Invoke UpdatePreviewOptionDefaultAttr.
1589 */
1590 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1591 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1592 auto shadowTheme = AceType::MakeRefPtr<ShadowTheme>();
1593 auto themeStyle = AceType::MakeRefPtr<ThemeStyle>();
1594 shadowTheme->SetThemeStyle(themeStyle);
1595 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(shadowTheme));
1596
1597 dragEventActuator->UpdatePreviewOptionDefaultAttr(frameNode);
1598 dragPreviewOption = frameNode->GetDragPreviewOption();
1599 EXPECT_NE(dragPreviewOption.options.shadow, std::nullopt);
1600 }
1601
1602 /**
1603 * @tc.name: TestApplyShadow
1604 * @tc.desc: Test set default shadow attribute.
1605 * @tc.type: FUNC
1606 */
1607 HWTEST_F(DragEventTestNg, TestApplyShadow, TestSize.Level1)
1608 {
1609 /**
1610 * @tc.steps: step1. Create FrameNode.
1611 */
1612 auto frameNode = FrameNode::CreateFrameNode(
1613 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1614 EXPECT_NE(frameNode, nullptr);
1615 /**
1616 * @tc.steps: step2. get DragPreviewOption.
1617 */
1618 auto dragPreviewOption = frameNode->GetDragPreviewOption();
1619 EXPECT_EQ(dragPreviewOption.options.shadow, std::nullopt);
1620 /**
1621 * @tc.steps: step3. set defaultShadow.
1622 */
1623 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1624 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1625 auto shadowTheme = AceType::MakeRefPtr<ShadowTheme>();
1626 auto themeStyle = AceType::MakeRefPtr<ThemeStyle>();
1627 shadowTheme->SetThemeStyle(themeStyle);
1628 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(shadowTheme));
1629
1630 dragPreviewOption.options.shadow = DragEventActuator::GetDefaultShadow();
1631 frameNode->SetDragPreviewOptions(dragPreviewOption);
1632 /**
1633 * @tc.steps: step4. Invoke ApplyNewestOptionExecutedFromModifierToNode
1634 */
1635 auto imageNode = FrameNode::CreateFrameNode(
1636 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1637 EXPECT_NE(imageNode, nullptr);
1638 imageNode->SetDragPreviewOptions(frameNode->GetDragPreviewOption());
1639 DragDropFuncWrapper::ApplyNewestOptionExecutedFromModifierToNode(frameNode, imageNode);
1640 auto imageContext = imageNode->GetRenderContext();
1641 EXPECT_NE(imageContext, nullptr);
1642 auto shadow = imageContext->GetBackShadow();
1643 EXPECT_NE(shadow, std::nullopt);
1644 }
1645
1646 /**
1647 * @tc.name: TestBlurStyleToEffection001
1648 * @tc.desc: Test BlurStyleToEffection.
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(DragEventTestNg, TestBlurStyleToEffection001, TestSize.Level1)
1652 {
1653 /**
1654 * @tc.steps: step1. Create DragEventActuator.
1655 */
1656 auto eventHub = AceType::MakeRefPtr<EventHub>();
1657 auto frameNode = FrameNode::CreateFrameNode(
1658 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1659 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1660 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1661 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1662 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1663 /**
1664 * @tc.steps: step2. Invoke BlurStyleToEffection function.
1665 */
1666 std::vector<float> vecGrayScale = {0.0f, 0.0f};
1667 BlurStyleOption blurStyleInfo = {BlurStyle::NO_MATERIAL, ThemeColorMode::SYSTEM,
1668 AdaptiveColor::DEFAULT, 1.0, {vecGrayScale}};
1669 std::optional<BlurStyleOption> optBlurStyleInfo(blurStyleInfo);
1670 auto optEffectOption = DragDropFuncWrapper::BlurStyleToEffection(optBlurStyleInfo);
1671 auto pipeline = PipelineContext::GetCurrentContext();
1672 ASSERT_NE(pipeline, nullptr);
1673 EXPECT_EQ(optEffectOption.has_value(), false);
1674 /**
1675 * @tc.steps: step3. Create themeManager.
1676 */
1677 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1678 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1679 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<BlurStyleTheme>()));
1680 auto blurStyleTheme = pipeline->GetTheme<BlurStyleTheme>();
1681 EXPECT_NE(blurStyleTheme, nullptr);
1682 auto resAdapter = RefPtr<ResourceAdapter>();
1683 auto themeConstants = AceType::MakeRefPtr<ThemeConstants>(resAdapter);
1684 std::unordered_map<std::string, ResValueWrapper> attributes;
1685 ResValueWrapper resValueWrapper;
1686 resValueWrapper.type = ThemeConstantsType::THEME;
1687 resValueWrapper.value = AceType::MakeRefPtr<ThemeStyle>();
1688 attributes.insert(std::pair<std::string, ResValueWrapper>(THEME_BLUR_STYLE_COMMON, resValueWrapper));
1689 themeConstants->currentThemeStyle_ = AceType::MakeRefPtr<ThemeStyle>();
1690 themeConstants->currentThemeStyle_->SetAttributes(attributes);
1691 auto blThemeInstance = BlurStyleTheme::Builder().Build(themeConstants);
1692 EXPECT_CALL(*themeManager, GetTheme(BlurStyleTheme::TypeId())).WillRepeatedly(Return(blThemeInstance));
1693 /**
1694 * @tc.steps: step4. Invoke BlurStyleToEffection function.
1695 */
1696 optEffectOption = DragDropFuncWrapper::BlurStyleToEffection(optBlurStyleInfo);
1697 ASSERT_NE(optEffectOption.has_value(), true);
1698 }
1699
1700 /**
1701 * @tc.name: TestRadiusToSigma001
1702 * @tc.desc: Test RadiusToSigma.
1703 * @tc.type: FUNC
1704 */
1705 HWTEST_F(DragEventTestNg, TestRadiusToSigma001, TestSize.Level1)
1706 {
1707 /**
1708 * @tc.steps: step1. Create DragEventActuator.
1709 */
1710 auto eventHub = AceType::MakeRefPtr<EventHub>();
1711 auto frameNode = FrameNode::CreateFrameNode(
1712 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1713 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1714 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1715 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1716 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1717 /**
1718 * @tc.steps: step2. Invoke RadiusToSigma function invalid.
1719 */
1720 float radius = -1.0f;
1721 auto sigMa = DragDropFuncWrapper::RadiusToSigma(radius);
1722 EXPECT_EQ(sigMa, 0.0f);
1723 /**
1724 * @tc.steps: step3. Invoke RadiusToSigma function.
1725 */
1726 float scaleHalf = 0.5f;
1727 float blurSigmaScale = 0.57735f;
1728 radius = 2.0f;
1729 float retSigMa = blurSigmaScale * radius + scaleHalf;
1730 sigMa = DragDropFuncWrapper::RadiusToSigma(radius);
1731 EXPECT_EQ(sigMa, retSigMa);
1732 }
1733
1734 /**
1735 * @tc.name: GetDefaultBorderRadiusTest001
1736 * @tc.desc: Create DragEventActuator and invoke GetDefaultBorderRadius function.
1737 * @tc.type: FUNC
1738 */
1739 HWTEST_F(DragEventTestNg, GetDefaultBorderRadiusTest001, TestSize.Level1)
1740 {
1741 /**
1742 * @tc.steps: step1. Create DragEventActuator.
1743 */
1744 auto eventHub = AceType::MakeRefPtr<EventHub>();
1745 auto frameNode = FrameNode::CreateFrameNode(
1746 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1747 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1748 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1749 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1750 /**
1751 * @tc.steps: step2. Test GetDefaultBorderRadius
1752 */
1753 NG::DragPreviewOption dragPreviewOptions { false, false, false, false, true };
1754 dragPreviewOptions.options.borderRadius = dragEventActuator->GetDefaultBorderRadius();
1755 frameNode->SetDragPreviewOptions(dragPreviewOptions);
1756 auto dragPreviewOption = frameNode->GetDragPreviewOption();
1757 auto borderRadius = dragPreviewOption.options.borderRadius;
1758 EXPECT_EQ(borderRadius.value().radiusTopLeft.value().Value(), 12.0);
1759 EXPECT_EQ(borderRadius.value().radiusTopRight.value().Value(), 12.0);
1760 EXPECT_EQ(borderRadius.value().radiusBottomRight.value().Value(), 12.0);
1761 EXPECT_EQ(borderRadius.value().radiusBottomLeft.value().Value(), 12.0);
1762 /**
1763 * @tc.steps: step3. Test PrepareRadiusParametersForDragData
1764 */
1765 auto arkExtraInfoJson = JsonUtil::Create(true);
1766 dragEventActuator->PrepareRadiusParametersForDragData(frameNode, arkExtraInfoJson);
1767 auto radiusTopLeft = arkExtraInfoJson->GetDouble("drag_corner_radius1", -1);
1768 auto radiusTopRight = arkExtraInfoJson->GetDouble("drag_corner_radius2", -1);
1769 auto radiusBottomRight = arkExtraInfoJson->GetDouble("drag_corner_radius3", -1);
1770 auto radiusBottomLeft = arkExtraInfoJson->GetDouble("drag_corner_radius4", -1);
1771 EXPECT_EQ(radiusTopLeft, 12.0);
1772 EXPECT_EQ(radiusTopRight, 12.0);
1773 EXPECT_EQ(radiusBottomRight, 12.0);
1774 EXPECT_EQ(radiusBottomLeft, 12.0);
1775 }
1776
1777 /**
1778 * @tc.name: GetSetPressedKeyCodesTest001
1779 * @tc.desc: Test GetPressedKeyCodes and SetPressedKeyCodes function.
1780 * @tc.type: FUNC
1781 */
1782 HWTEST_F(DragEventTestNg, GetSetPressedKeyCodesTest001, TestSize.Level1)
1783 {
__anondbf094733602(GestureEvent& info) 1784 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094733702(GestureEvent& info) 1785 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094733802(GestureEvent& info) 1786 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094733902() 1787 GestureEventNoParameter actionCancel = []() {};
1788 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
1789 std::move(actionEnd), std::move(actionCancel));
1790 dragEvent->SetPressedKeyCodes({KeyCode::KEY_DPAD_LEFT, KeyCode::KEY_DPAD_RIGHT});
1791 auto pressedKeyCodes = dragEvent->GetPressedKeyCodes();
1792 EXPECT_EQ(pressedKeyCodes.size(), 2);
1793 EXPECT_EQ(pressedKeyCodes[1], KeyCode::KEY_DPAD_RIGHT);
1794 }
1795
1796 /**
1797 * @tc.name: SetResponseRegionFullTest
1798 * @tc.desc: Test ResetResponseRegion function.
1799 * @tc.type: FUNC
1800 */
1801 HWTEST_F(DragEventTestNg, ReSetResponseRegion, TestSize.Level1)
1802 {
1803 /**
1804 * @tc.steps: step1. Create DragEventActuator.
1805 */
1806 auto frameNode = FrameNode::CreateFrameNode(
1807 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
1808 auto eventHub = AceType::MakeRefPtr<EventHub>();
1809 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1810 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1811 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1812 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1813
1814 /**
1815 * @tc.steps: step2. Set frameNode response region.
1816 */
1817 auto setRect = DimensionRect(Dimension(100.0f), Dimension(100.0f));
1818 auto originRect = DimensionRect(Dimension(1.0f), Dimension(1.0f));
1819 dragEventActuator->isResponseRegionFull_ = true;
1820 dragEventActuator->responseRegion_ = { originRect };
1821 gestureEventHub->responseRegion_ = { setRect };
1822 ASSERT_EQ(gestureEventHub->responseRegion_.size(), 1);
1823 EXPECT_EQ(gestureEventHub->responseRegion_[0].width_, setRect.width_);
1824 EXPECT_EQ(gestureEventHub->responseRegion_[0].height_, setRect.height_);
1825
1826 /**
1827 * @tc.steps: step3. call ResetResponseRegion.
1828 */
1829 dragEventActuator->ResetResponseRegion();
1830 EXPECT_EQ(dragEventActuator->isResponseRegionFull_, false);
1831 ASSERT_EQ(gestureEventHub->responseRegion_.size(), 1);
1832 EXPECT_EQ(gestureEventHub->responseRegion_[0].width_, originRect.width_);
1833 EXPECT_EQ(gestureEventHub->responseRegion_[0].height_, originRect.height_);
1834 }
1835
1836 /**
1837 * @tc.name: SetResponseRegionFullTest
1838 * @tc.desc: Test DragClog001 function.
1839 * @tc.type: FUNC
1840 */
1841 HWTEST_F(DragEventTestNg, DragClog001, TestSize.Level1)
1842 {
1843 auto pipeline = PipelineContext::GetCurrentContext();
1844 ASSERT_NE(pipeline, nullptr);
1845 auto dragDropManager = pipeline->GetDragDropManager();
1846 ASSERT_NE(dragDropManager, nullptr);
__anondbf094733a02()1847 DragDropGlobalController::GetInstance().SetAsyncDragCallback([](){});
1848 dragDropManager->RemoveDeadlineTimer();
1849 EXPECT_EQ(DragDropGlobalController::GetInstance().GetAsyncDragCallback(), nullptr);
1850 auto frameNode = FrameNode::CreateFrameNode("MyButton", 102, AceType::MakeRefPtr<Pattern>());
1851 auto guestureEventHub = frameNode->GetOrCreateGestureEventHub();
1852 ASSERT_NE(guestureEventHub, nullptr);
1853 GestureEvent info;
1854 info.SetSourceDevice(SourceType::MOUSE);
1855 guestureEventHub->HandleOnDragStart(info);
1856 dragDropManager->HandleSyncOnDragStart(DragStartRequestStatus::READY);
1857 EXPECT_EQ(DragDropGlobalController::GetInstance().GetAsyncDragCallback(), nullptr);
1858 }
1859
1860 /**
1861 * @tc.name: DragEventPreviewLongPressActionTestNG001
1862 * @tc.desc: Test DragEventPreviewLongPressActionTestNG001 function.
1863 * @tc.type: FUNC
1864 */
1865 HWTEST_F(DragEventTestNg, DragEventPreviewLongPressActionTestNG001, TestSize.Level1)
1866 {
1867 auto pipeline = PipelineContext::GetCurrentContext();
1868 ASSERT_NE(pipeline, nullptr);
1869 auto dragDropManager = pipeline->GetDragDropManager();
1870 ASSERT_NE(dragDropManager, nullptr);
1871 /**
1872 * @tc.steps: step1. Create DragEventActuator.
1873 */
1874 auto eventHub = AceType::MakeRefPtr<EventHub>();
1875 auto frameNode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), false);
1876 EXPECT_NE(frameNode, nullptr);
1877 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1878 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1879 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1880 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1881
__anondbf094733b02(GestureEvent& info) 1882 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anondbf094733c02(GestureEvent& info) 1883 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anondbf094733d02(GestureEvent& info) 1884 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anondbf094733e02() 1885 GestureEventNoParameter actionCancel = []() {};
1886 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
1887 std::move(actionEnd), std::move(actionCancel));
1888 dragEventActuator->ReplaceDragEvent(dragEvent);
1889 dragEventActuator->SetCustomDragEvent(dragEvent);
1890 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
1891 /**
1892 * @tc.steps: step2. Invoke OnCollectTouchTarget.
1893 * @tc.expected: call OnCollectTouchTarget and create previewLongPressRecognizer_ successful.
1894 */
1895 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
1896 EXPECT_NE(getEventTargetImpl, nullptr);
1897 TouchTestResult finalResult;
1898 ResponseLinkResult responseLinkResult;
1899 frameNode->GetOrCreateFocusHub();
1900 dragEventActuator->OnCollectTouchTarget(
1901 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult, responseLinkResult);
1902 EXPECT_NE(dragEventActuator->previewLongPressRecognizer_->onAction_, nullptr);
1903
1904 /**
1905 * @tc.steps: step3. Test previewLongPressRecognizer_ onAction callback with pan success.
1906 * @tc.expected: onAction callback complete successful.
1907 */
1908 dragEventActuator->isOnBeforeLiftingAnimation_ = true;
1909 GestureEvent info = GestureEvent();
1910 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
1911 EXPECT_FALSE(dragEventActuator->isOnBeforeLiftingAnimation_);
1912
1913 /**
1914 * @tc.steps: step4. Test previewLongPressRecognizer_ onAction callback with pan reject.
1915 * @tc.expected: onAction callback return.
1916 */
1917 dragEventActuator->isOnBeforeLiftingAnimation_ = true;
1918 auto panRecognizer = dragEventActuator->panRecognizer_;
1919 panRecognizer->disposal_ = GestureDisposal::REJECT;
1920 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
1921 EXPECT_TRUE(dragEventActuator->isOnBeforeLiftingAnimation_);
1922 }
1923
1924 /**
1925 * @tc.name: GetThumbnailPixelMap
1926 * @tc.desc: test GetThumbnailPixelMap.
1927 * @tc.type: FUNC
1928 */
1929 HWTEST_F(DragEventTestNg, GetThumbnailPixelMap, TestSize.Level1)
1930 {
1931 /**
1932 * @tc.steps: step1. Create DragEventActuator.
1933 */
1934 auto eventHub = AceType::MakeRefPtr<EventHub>();
1935 auto frameNode = FrameNode::CreateFrameNode(
1936 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
1937 DragDropInfo dragDropInfo;
1938 frameNode->SetDragPreview(dragDropInfo);
1939 NG::DragPreviewOption previewOptions;
1940 previewOptions.isLiftingDisabled = true;
1941 frameNode->SetDragPreviewOptions(previewOptions);
1942
1943 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1944 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1945 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1946 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE_EQUAL_DEFAULT);
1947 dragEventActuator->gestureEventHub_ = gestureEventHub;
1948 /**
1949 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
1950 * @tc.expected: dragEventActuator's userCallback_ is not null.
1951 */
1952
1953 dragEventActuator->GetThumbnailPixelMap(true);
1954 EXPECT_FALSE(dragEventActuator->isOnBeforeLiftingAnimation_);
1955 }
1956
1957 /**
1958 * @tc.name: DragEventTextPixelMapNullTest001
1959 * @tc.desc: Test SetTextPixelMap clears and applies textPixelMap_ correctly to avoid reuse.
1960 * @tc.type: FUNC
1961 */
1962 HWTEST_F(DragEventTestNg, DragEventTextPixelMapNullTest001, TestSize.Level1)
1963 {
1964 /**
1965 * @tc.steps: step1. Create FrameNode, EventHub, GestureEventHub and DragEventActuator, and set up dragNode.
1966 */
1967 auto eventHub = AceType::MakeRefPtr<EventHub>();
1968 ASSERT_NE(eventHub, nullptr);
1969 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
1970 ASSERT_NE(frameNode, nullptr);
1971 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
1972 auto gestureHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
1973 ASSERT_NE(gestureHub, nullptr);
1974 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
1975 AceType::WeakClaim(AceType::RawPtr(gestureHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
1976 ASSERT_NE(dragEventActuator, nullptr);
1977 auto textPattern = frameNode->GetPattern<TextPattern>();
1978 ASSERT_NE(textPattern, nullptr);
1979 auto dragNode = FrameNode::CreateFrameNode(V2::IMAGE_ETS_TAG, -1, AceType::MakeRefPtr<ImagePattern>());
1980 ASSERT_NE(dragNode, nullptr);
1981 textPattern->dragNode_ = dragNode;
1982
1983 /**
1984 * @tc.steps: step2. Set initial textPixelMap_ and call SetTextPixelMap.
1985 * @tc.expected: The pixel map is applied to gestureHub and internal pointer is cleared.
1986 */
1987 auto textPixelMap = AceType::MakeRefPtr<MockPixelMap>();
1988 ASSERT_NE(textPixelMap, nullptr);
1989 dragEventActuator->textPixelMap_ = textPixelMap;
1990 dragEventActuator->SetTextPixelMap(gestureHub);
1991 EXPECT_EQ(gestureHub->GetPixelMap(), textPixelMap);
1992 EXPECT_EQ(dragEventActuator->textPixelMap_, nullptr);
1993
1994 /**
1995 * @tc.steps: step2. Call SetTextPixelMap again after textPixelMap_ is cleared.
1996 * @tc.expected: gestureHub pixel map is set to nullptr.
1997 */
1998 dragEventActuator->SetTextPixelMap(gestureHub);
1999 EXPECT_EQ(gestureHub->GetPixelMap(), nullptr);
2000
2001 /**
2002 * @tc.steps: step5. Set renderContext to dragNode and call again.
2003 * @tc.expected: gestureHub pixel map remains nullptr due to GetThumbnailPixelMap returning null.
2004 */
2005 dragNode->renderContext_ = AceType::MakeRefPtr<RenderContext>();
2006 dragEventActuator->SetTextPixelMap(gestureHub);
2007 EXPECT_EQ(gestureHub->GetPixelMap(), nullptr);
2008 }
2009
2010 /**
2011 * @tc.name: DragEventSetDragDampStartPointInfoTest001
2012 * @tc.desc: Test SetDragDampStartPointInfo resets drag positions and sets correct start point and pointer ID.
2013 * @tc.type: FUNC
2014 */
2015 HWTEST_F(DragEventTestNg, DragEventSetDragDampStartPointInfoTest001, TestSize.Level1)
2016 {
2017 /**
2018 * @tc.steps: step1. Create FrameNode, EventHub, GestureEventHub, and DragEventActuator.
2019 */
2020 auto eventHub = AceType::MakeRefPtr<EventHub>();
2021 ASSERT_NE(eventHub, nullptr);
2022 auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
2023 ASSERT_NE(frameNode, nullptr);
2024 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
2025 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
2026 ASSERT_NE(gestureEventHub, nullptr);
2027 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
2028 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
2029 ASSERT_NE(dragEventActuator, nullptr);
2030
2031 /**
2032 * @tc.steps: step2. Get PipelineContext and DragDropManager.
2033 * @tc.expected: DragDropManager is not null.
2034 */
2035 auto pipeline = PipelineContext::GetCurrentContext();
2036 ASSERT_NE(pipeline, nullptr);
2037 auto dragDropManager = pipeline->GetDragDropManager();
2038 ASSERT_NE(dragDropManager, nullptr);
2039
2040 /**
2041 * @tc.steps: step3. Call SetDragDampStartPointInfo with testPoint and pointerId.
2042 * @tc.expected: All previous drag positions are reset; new start point and pointer ID are recorded.
2043 */
2044 Point testPoint(POINT_X, POINT_Y);
2045 int32_t testPointerId = POINTER_ID;
2046 dragEventActuator->SetDragDampStartPointInfo(testPoint, testPointerId);
2047
2048 EXPECT_EQ(dragDropManager->dragMovePosition_, OffsetF());
2049 EXPECT_EQ(dragDropManager->lastDragMovePosition_, OffsetF());
2050 EXPECT_EQ(dragDropManager->dragTotalMovePosition_, OffsetF());
2051 EXPECT_EQ(dragDropManager->dragDampStartPoint_.GetX(), testPoint.GetX());
2052 EXPECT_EQ(dragDropManager->dragDampStartPoint_.GetY(), testPoint.GetY());
2053 EXPECT_EQ(dragDropManager->currentPointerId_, testPointerId);
2054 }
2055
2056 /**
2057 * @tc.name: DragEventTryTriggerThumbnailCallbackTest001
2058 * @tc.desc: Test TryTriggerThumbnailCallback handles different conditions to prevent incorrect thumbnail generation.
2059 * @tc.type: FUNC
2060 */
2061 HWTEST_F(DragEventTestNg, DragEventTryTriggerThumbnailCallbackTest001, TestSize.Level1)
2062 {
2063 /**
2064 * @tc.steps: step1. Create FrameNode, EventHub, GestureEventHub and DragEventActuator.
2065 */
2066 auto eventHub = AceType::MakeRefPtr<EventHub>();
2067 ASSERT_NE(eventHub, nullptr);
2068 auto frameNode = FrameNode::CreateFrameNode(
2069 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
2070 ASSERT_NE(frameNode, nullptr);
2071 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
2072
2073 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
2074 ASSERT_NE(gestureEventHub, nullptr);
2075 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
2076 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
2077 ASSERT_NE(dragEventActuator, nullptr);
2078 dragEventActuator->gestureEventHub_ = AceType::WeakClaim(AceType::RawPtr(gestureEventHub));
2079
2080 /**
2081 * @tc.steps: step2. Test early return when isThumbnailCallbackTriggered_ is already true.
2082 * @tc.expected: isThumbnailCallbackTriggered_ remains true.
2083 */
2084 dragEventActuator->isThumbnailCallbackTriggered_ = true;
2085 dragEventActuator->TryTriggerThumbnailCallback();
2086 EXPECT_TRUE(dragEventActuator->isThumbnailCallbackTriggered_);
2087
2088 /**
2089 * @tc.steps: step3. Test early return when FrameNode tag is WEB_ETS_TAG.
2090 * @tc.expected: isThumbnailCallbackTriggered_ remains false.
2091 */
2092 frameNode->tag_ = V2::WEB_ETS_TAG;
2093 dragEventActuator->isThumbnailCallbackTriggered_ = false;
2094 dragEventActuator->TryTriggerThumbnailCallback();
2095 EXPECT_FALSE(dragEventActuator->isThumbnailCallbackTriggered_);
2096 frameNode->tag_ = V2::TEXT_ETS_TAG;
2097
2098 /**
2099 * @tc.steps: step4. Test early return when text is marked as draggable.
2100 * @tc.expected: isThumbnailCallbackTriggered_ remains false.
2101 */
2102 gestureEventHub->SetTextDraggable(true);
2103 dragEventActuator->isThumbnailCallbackTriggered_ = false;
2104 dragEventActuator->TryTriggerThumbnailCallback();
2105 EXPECT_FALSE(dragEventActuator->isThumbnailCallbackTriggered_);
2106 gestureEventHub->SetTextDraggable(false);
2107
2108 /**
2109 * @tc.steps: step5. Test successful path when none of the early-return conditions are met.
2110 * @tc.expected: isThumbnailCallbackTriggered_ is set to true.
2111 */
2112 dragEventActuator->isThumbnailCallbackTriggered_ = false;
2113 dragEventActuator->TryTriggerThumbnailCallback();
2114 EXPECT_TRUE(dragEventActuator->isThumbnailCallbackTriggered_);
2115 }
2116
2117 /**
2118 * @tc.name: SetDragNodeNeedClean
2119 * @tc.desc: test SetDragNodeNeedClean isDragNodeNeedClean_ true.
2120 * @tc.type: FUNC
2121 */
2122 HWTEST_F(DragEventTestNg, SetDragNodeNeedClean, TestSize.Level1)
2123 {
2124 auto pipelineContext = PipelineContext::GetCurrentContext();
2125 ASSERT_NE(pipelineContext, nullptr);
2126 auto overlayManager = pipelineContext->overlayManager_;
2127 ASSERT_NE(overlayManager, nullptr);
2128 auto dragDropManager = pipelineContext->GetDragDropManager();
2129 ASSERT_NE(dragDropManager, nullptr);
2130 overlayManager->SetDragNodeNeedClean();
2131 EXPECT_TRUE(dragDropManager->IsDragNodeNeedClean());
2132 }
2133 } // namespace OHOS::Ace::NG
2134