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