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 "gtest/gtest.h"
17
18 #define private public
19 #define protected public
20
21 #include "test/mock/core/pipeline/mock_pipeline_context.h"
22 #include "test/mock/core/render/mock_render_context.h"
23
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 #include "core/components_ng/event/drag_event.h"
27 #include "core/components_ng/event/event_hub.h"
28 #include "core/components_ng/pattern/text/text_pattern.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS::Ace::NG {
34 namespace {
35 constexpr double GESTURE_EVENT_PROPERTY_DEFAULT_VALUE = 0.0;
36 constexpr double GESTURE_EVENT_PROPERTY_VALUE = 10.0;
37 const PanDirection DRAG_DIRECTION = { PanDirection::LEFT };
38 const TouchRestrict DRAG_TOUCH_RESTRICT = { TouchRestrict::CLICK };
39 const TouchRestrict DRAG_TOUCH_RESTRICT_MOUSE = {
40 .forbiddenType = TouchRestrict::CLICK,
41 .sourceType = SourceType::MOUSE
42 };
43 constexpr int32_t FINGERS_NUMBER = 2;
44 constexpr int32_t TOUCH_TEST_RESULT_SIZE = 1;
45 constexpr int32_t TOUCH_TEST_RESULT_SIZE_2 = 2;
46 constexpr float DISTANCE = 10.5f;
47 constexpr float WIDTH = 400.0f;
48 constexpr float HEIGHT = 400.0f;
49 const OffsetF COORDINATE_OFFSET(WIDTH, HEIGHT);
50 constexpr int32_t FINGERS_NUMBER_GREATER_THAN_DEFAULT = 2;
51 constexpr float DISTANCE_GREATER_THAN_DEFAULT = 6.0f;
52 constexpr float DISTANCE_EQUAL_DEFAULT = 5.0f;
53 constexpr float IMAGE_INVALID_RECT_WIDTH = 100.0f;
54 } // namespace
55
56 class DragEventTestNg : public testing::Test {
57 public:
58 static void SetUpTestSuite();
59 static void TearDownTestSuite();
60 void SetUp() override;
61 void TearDown() override;
62 };
63
SetUpTestSuite()64 void DragEventTestNg::SetUpTestSuite()
65 {
66 GTEST_LOG_(INFO) << "DragEventTestNg SetUpTestCase";
67 }
68
TearDownTestSuite()69 void DragEventTestNg::TearDownTestSuite()
70 {
71 GTEST_LOG_(INFO) << "DragEventTestNg TearDownTestCase";
72 }
73
SetUp()74 void DragEventTestNg::SetUp()
75 {
76 MockPipelineContext::SetUp();
77 }
78
TearDown()79 void DragEventTestNg::TearDown()
80 {
81 MockPipelineContext::TearDown();
82 }
83
84 /**
85 * @tc.name: DragEventTest001
86 * @tc.desc: Create DragEvent and execute its callback functions.
87 * @tc.type: FUNC
88 */
89 HWTEST_F(DragEventTestNg, DragEventTest001, TestSize.Level1)
90 {
91 /**
92 * @tc.steps: step1. Create GestureEventFunc as the arguments of the construction of DragEvent.
93 */
94 double unknownPropertyValue = 0.0;
95 GestureEventFunc actionStart = [&unknownPropertyValue](
__anon5b7ac9720202( GestureEvent& info) 96 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
97 GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anon5b7ac9720302( GestureEvent& info) 98 GestureEvent& info) { unknownPropertyValue = info.GetAngle(); };
99 GestureEventFunc actionEnd = [&unknownPropertyValue](
__anon5b7ac9720402( GestureEvent& info) 100 GestureEvent& info) { unknownPropertyValue = info.GetOffsetX(); };
__anon5b7ac9720502() 101 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
102 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
103 };
104
105 /**
106 * @tc.steps: step2. Create DragEvent.
107 */
108 const DragEvent dragEvent =
109 DragEvent(std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
110
111 /**
112 * @tc.steps: step3. Get and execute DragEvent ActionStartEvent.
113 * @tc.expected: Execute ActionStartEvent which unknownPropertyValue is assigned in.
114 */
115 GestureEvent info = GestureEvent();
116 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
117 dragEvent.GetActionStartEventFunc()(info);
118 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
119
120 /**
121 * @tc.steps: step4. Get and execute DragEvent ActionUpdateEvent.
122 * @tc.expected: Execute ActionUpdateEvent which unknownPropertyValue is assigned in.
123 */
124 unknownPropertyValue = 0.0;
125 info.SetAngle(GESTURE_EVENT_PROPERTY_VALUE);
126 dragEvent.GetActionUpdateEventFunc()(info);
127 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
128
129 /**
130 * @tc.steps: step5. Get and execute DragEvent ActionEndEvent.
131 * @tc.expected: Execute ActionEndEvent which unknownPropertyValue is assigned in.
132 */
133 unknownPropertyValue = 0.0;
134 info.SetOffsetX(GESTURE_EVENT_PROPERTY_VALUE);
135 dragEvent.GetActionEndEventFunc()(info);
136 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
137
138 /**
139 * @tc.steps: step6. Get and execute DragEvent ActionCancelEvent.
140 * @tc.expected: Execute ActionCancelEvent which unknownPropertyValue is assigned in.
141 */
142 unknownPropertyValue = 0.0;
143 dragEvent.GetActionCancelEventFunc()();
144 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
145 }
146
147 /**
148 * @tc.name: DragEventActuatorPropertyTest002
149 * @tc.desc: Create DragEventActuator and test its property value.
150 * @tc.type: FUNC
151 */
152 HWTEST_F(DragEventTestNg, DragEventActuatorPropertyTest002, TestSize.Level1)
153 {
154 /**
155 * @tc.steps: step1. Create DragEventActuator.
156 */
157 auto eventHub = AceType::MakeRefPtr<EventHub>();
158 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
159 DragEventActuator dragEventActuator = DragEventActuator(
160 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
161
162 /**
163 * @tc.steps: step2. Create DragEventActuator when fingers number and distance are both greater than the default.
164 * @tc.expected: panEventActuator is initialized with the fingers_ and distance_ defined before.
165 */
166 auto dragEventActuator2 =
167 AceType::MakeRefPtr<DragEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION,
168 FINGERS_NUMBER_GREATER_THAN_DEFAULT, DISTANCE_GREATER_THAN_DEFAULT);
169 EXPECT_NE(dragEventActuator2, nullptr);
170 EXPECT_EQ(dragEventActuator2->fingers_, FINGERS_NUMBER_GREATER_THAN_DEFAULT);
171 EXPECT_EQ(dragEventActuator2->distance_, DISTANCE_GREATER_THAN_DEFAULT);
172
173 /**
174 * @tc.steps: step3. Get DragEventActuator direction, fingers_ and distance_.
175 * @tc.expected: DragEventActuator's direction, fingers_ and distance_ are equal with the parameters passed in the
176 * constructor.
177 */
178 EXPECT_EQ(dragEventActuator.GetDirection().type, DRAG_DIRECTION.type);
179 EXPECT_EQ(dragEventActuator.fingers_, FINGERS_NUMBER);
180 EXPECT_EQ(dragEventActuator.distance_, DISTANCE);
181 /**
182 * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent and CustomDragEvent.
183 * @tc.expected: Get DragEventActuator's DragEvent and CustomDragEvent which are equal with the DragEvent create
184 * before.
185 */
__anon5b7ac9720602(GestureEvent& info) 186 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon5b7ac9720702(GestureEvent& info) 187 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9720802(GestureEvent& info) 188 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9720902() 189 GestureEventNoParameter actionCancel = []() {};
190
191 auto dragEvent = AceType::MakeRefPtr<DragEvent>(
192 std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
193 dragEventActuator.ReplaceDragEvent(dragEvent);
194 EXPECT_EQ(dragEvent, dragEventActuator.userCallback_);
195 dragEventActuator.SetCustomDragEvent(dragEvent);
196 EXPECT_EQ(dragEvent, dragEventActuator.customCallback_);
197 }
198
199 /**
200 * @tc.name: DragEventActuatorOnCollectTouchTargetTest003
201 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
202 * @tc.type: FUNC
203 */
204 HWTEST_F(DragEventTestNg, DragEventActuatorOnCollectTouchTargetTest003, TestSize.Level1)
205 {
206 /**
207 * @tc.steps: step1. Create DragEventActuator.
208 */
209 auto eventHub = AceType::MakeRefPtr<EventHub>();
210 auto framenode = FrameNode::CreateFrameNode("test", 1, AceType::MakeRefPtr<Pattern>(), false);
211 EXPECT_NE(framenode, nullptr);
212 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(framenode));
213 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
214 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
215 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
216
217 /**
218 * @tc.steps: step2. Invoke OnCollectTouchTarget without setting userCallback_.
219 * @tc.expected: userCallback_ is null and return directly.
220 */
221 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
222 EXPECT_NE(getEventTargetImpl, nullptr);
223 TouchTestResult finalResult;
224 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
225 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
226 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
227 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
228 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
229 EXPECT_EQ(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
230 EXPECT_TRUE(finalResult.empty());
231
232 /**
233 * @tc.steps: step3. Create DragEvent and set as DragEventActuator's DragEvent.
234 * @tc.expected: DragEventActuator's userCallback_ is not null.
235 */
236 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
237 GestureEventFunc actionStart = [&unknownPropertyValue](
__anon5b7ac9720a02( GestureEvent& info) 238 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
239 GestureEventFunc actionUpdate = [&unknownPropertyValue](
__anon5b7ac9720b02( GestureEvent& info) 240 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
241 GestureEventFunc actionEnd = [&unknownPropertyValue](
__anon5b7ac9720c02( GestureEvent& info) 242 GestureEvent& info) { unknownPropertyValue = info.GetScale(); };
__anon5b7ac9720d02() 243 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
244 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
245 };
246 auto dragEvent = AceType::MakeRefPtr<DragEvent>(
247 std::move(actionStart), std::move(actionUpdate), std::move(actionEnd), std::move(actionCancel));
248 dragEventActuator->ReplaceDragEvent(dragEvent);
249 dragEventActuator->SetCustomDragEvent(dragEvent);
250 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
251
252 /**
253 * @tc.steps: step4. Invoke OnCollectTouchTarget when userCallback_ is not null.
254 * @tc.expected: panRecognizer_ action and finalResult will be assigned value.
255 */
256 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
257
258 EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
259 EXPECT_NE(dragEventActuator->panRecognizer_->onActionUpdate_, nullptr);
260 EXPECT_NE(dragEventActuator->panRecognizer_->onActionEnd_, nullptr);
261 EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
262 EXPECT_FALSE(finalResult.size() == TOUCH_TEST_RESULT_SIZE);
263
264 /**
265 * @tc.steps: step5. Invoke OnCollectTouchTarget when SequencedRecognizer_ is null.
266 * @tc.expected: Result size will be increased by one.
267 */
268 dragEventActuator->SequencedRecognizer_ = nullptr;
269 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
270 EXPECT_TRUE(finalResult.size() != TOUCH_TEST_RESULT_SIZE_2);
271
272 /**
273 * @tc.steps: step6. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
274 * function exists.
275 * @tc.expected: The functions have been executed and the unknownPropertyValue has been assigned the correct
276 * value.
277 */
278 GestureEvent info = GestureEvent();
279 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
280 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
281 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
282 (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
283 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
284 (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
285 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
286 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
287 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
288
289 /**
290 * @tc.steps: step7. Invoke onActionStart, onActionUpdate, onActionEnd, onActionCancel when the onActionStart
291 * function not exist.
292 * @tc.expected: The functions have not been executed.
293 */
294 SystemProperties::debugEnabled_ = true;
295 auto dragEventNullptr = AceType::MakeRefPtr<DragEvent>(nullptr, nullptr, nullptr, nullptr);
296 dragEventActuator->ReplaceDragEvent(dragEventNullptr);
297 dragEventActuator->SetCustomDragEvent(dragEventNullptr);
298 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
299 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
300 (*(dragEventActuator->panRecognizer_->onActionUpdate_))(info);
301 (*(dragEventActuator->panRecognizer_->onActionEnd_))(info);
302 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
303 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_DEFAULT_VALUE);
304 }
305
306 /**
307 * @tc.name: DragEventTestNg001
308 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget function.
309 * @tc.type: FUNC
310 */
311 HWTEST_F(DragEventTestNg, DragEventTestNg001, TestSize.Level1)
312 {
313 /**
314 * @tc.steps: step1. Create DragEventActuator.
315 */
316 auto eventHub = AceType::MakeRefPtr<EventHub>();
317 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
318 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
319 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, 0, 50.0f);
320 dragEventActuator->StartDragTaskForWeb(GestureEvent());
__anon5b7ac9720e02(GestureEvent&) 321 auto actionStart = [](GestureEvent&) {};
__anon5b7ac9720f02(GestureEvent&) 322 auto longPressUpdate = [](GestureEvent&) {};
323 dragEventActuator->actionStart_ = actionStart;
324 dragEventActuator->StartDragTaskForWeb(GestureEvent());
325
326 dragEventActuator->CancelDragForWeb();
__anon5b7ac9721002() 327 auto actionCancel = []() {};
328 dragEventActuator->actionCancel_ = actionCancel;
329 dragEventActuator->CancelDragForWeb();
330
331 dragEventActuator->StartLongPressActionForWeb();
332 dragEventActuator->isReceivedLongPress_ = true;
333 dragEventActuator->StartLongPressActionForWeb();
334 dragEventActuator->isReceivedLongPress_ = true;
335 dragEventActuator->longPressUpdate_ = longPressUpdate;
336 dragEventActuator->StartLongPressActionForWeb();
337 ASSERT_FALSE(dragEventActuator->isReceivedLongPress_);
338 }
339
340 /**
341 * @tc.name: DragEventTestNg002
342 * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
343 * @tc.type: FUNC
344 */
345 HWTEST_F(DragEventTestNg, DragEventTestNg002, TestSize.Level1)
346 {
347 /**
348 * @tc.steps: step1. Create FrameNode and set dragPreview.
349 */
350 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<Pattern>());
351 frameNode->SetDraggable(true);
352 NG::DragDropInfo dragPreviewInfo;
353 void* voidPtr = static_cast<void*>(new char[0]);
354 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
355 dragPreviewInfo.pixelMap = pixelMap;
356 frameNode->SetDragPreview(dragPreviewInfo);
357
358 /**
359 * @tc.steps: step2. Get eventHub and set onDragStart.
360 * @tc.expected: eventHub is not nullptr.
361 */
362 auto eventHub = frameNode->GetEventHub<EventHub>();
363 EXPECT_NE(eventHub, nullptr);
364 eventHub->AttachHost(frameNode);
__anon5b7ac9721102(const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) 365 auto onDragStart = [](const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
366 DragDropInfo info;
367 void* voidPtr = static_cast<void*>(new char[0]);
368 info.pixelMap = PixelMap::CreatePixelMap(voidPtr);
369 return info;
370 };
371 eventHub->SetOnDragStart(std::move(onDragStart));
372
373 /**
374 * @tc.steps: step3. Create gestureEventHub and dragEventActuator.
375 */
376 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
377 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
378 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
379
380 /**
381 * @tc.steps: step4. Create DragEvent and set as DragEventActuator's DragEvent.
382 * @tc.expected: dragEventActuator's userCallback_ is not null.
383 */
384 TouchTestResult finalResult;
385 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon5b7ac9721202(GestureEvent& info) 386 GestureEventFunc actionStart = [&unknownPropertyValue](GestureEvent& info) {
387 unknownPropertyValue = info.GetScale();
388 };
__anon5b7ac9721302(GestureEvent& info) 389 GestureEventFunc actionUpdate = [&unknownPropertyValue](GestureEvent& info) {
390 unknownPropertyValue = info.GetScale();
391 };
__anon5b7ac9721402(GestureEvent& info) 392 GestureEventFunc actionEnd = [&unknownPropertyValue](GestureEvent& info) {
393 unknownPropertyValue = info.GetScale();
394 };
__anon5b7ac9721502() 395 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
396 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
397 };
398 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
399 std::move(actionEnd), std::move(actionCancel));
400 dragEventActuator->ReplaceDragEvent(dragEvent);
401 dragEventActuator->SetCustomDragEvent(dragEvent);
402 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
403
404 /**
405 * @tc.steps: step5. Invoke OnCollectTouchTarget when userCallback_ is not null.
406 * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's callback is not nullptr.
407 */
408 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
409 EXPECT_NE(getEventTargetImpl, nullptr);
410 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
411 EXPECT_NE(dragEventActuator->longPressRecognizer_, nullptr);
412 EXPECT_NE(dragEventActuator->longPressRecognizer_->callback_, nullptr);
413
414 /**
415 * @tc.steps: step6. Invoke thumbnail callback.
416 * @tc.expected: GestureEventHub's pixelMap is not nullptr.
417 */
418 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
419 EXPECT_NE(gestureEventHub->pixelMap_, nullptr);
420 }
421
422 /**
423 * @tc.name: DragEventTestNg003
424 * @tc.desc: Create DragEventActuator and invoke thumbnail callback.
425 * @tc.type: FUNC
426 */
427 HWTEST_F(DragEventTestNg, DragEventTestNg003, TestSize.Level1)
428 {
429 /**
430 * @tc.steps: step1. Create DragEventActuator.
431 */
432 SystemProperties::debugEnabled_ = true;
433 auto eventHub = AceType::MakeRefPtr<EventHub>();
434 auto frameNode = FrameNode::CreateFrameNode(
435 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
436 DragDropInfo dragDropInfo;
437 frameNode->SetDragPreview(dragDropInfo);
438 frameNode->SetDraggable(true);
439 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
440 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
441 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
442 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE_EQUAL_DEFAULT);
443 /**
444 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
445 * @tc.expected: dragEventActuator's userCallback_ is not null.
446 */
__anon5b7ac9721602(GestureEvent& info) 447 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon5b7ac9721702(GestureEvent& info) 448 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9721802(GestureEvent& info) 449 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9721902() 450 GestureEventNoParameter actionCancel = []() {};
451 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
452 std::move(actionEnd), std::move(actionCancel));
453 dragEventActuator->ReplaceDragEvent(dragEvent);
454 dragEventActuator->SetCustomDragEvent(dragEvent);
455 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
456 /**
457 * @tc.steps: step3. Invoke OnCollectTouchTarget when callback_ is not null.
458 * @tc.expected: longPressRecognizer is not nullptr and longPressRecognizer's HasThumbnailCallback() return true.
459 */
460 TouchTestResult finalResult;
461 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
462 EXPECT_NE(getEventTargetImpl, nullptr);
463 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), false);
464 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
465 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
466 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
467 EXPECT_EQ(dragEventActuator->longPressRecognizer_->HasThumbnailCallback(), true);
468 /**
469 * @tc.steps: step4. Invoke thumbnail callback.
470 * @tc.expected: cover dragPreviewInfo.customNode == nullptr, dragPreviewInfo.pixelMap == nullptr.
471 */
472 EXPECT_EQ(frameNode->GetDragPreview().customNode, nullptr);
473 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
474 EXPECT_EQ(gestureEventHub->GetPixelMap(), frameNode->GetRenderContext()->GetThumbnailPixelMap());
475 /**
476 * @tc.steps: step5. Invoke thumbnail callback.
477 * @tc.expected: cover dragPreviewInfo.customNode != nullptr, dragPreviewInfo.pixelMap == nullptr.
478 */
479 RefPtr<UINode> customNode = AceType::MakeRefPtr<FrameNode>("node", -1, AceType::MakeRefPtr<Pattern>());
480 dragDropInfo.customNode = customNode;
481 frameNode->SetDragPreview(dragDropInfo);
482 dragEventActuator->longPressRecognizer_->callback_(Offset(WIDTH, HEIGHT));
483 EXPECT_NE(frameNode->GetDragPreview().customNode, nullptr);
484 }
485
486 /**
487 * @tc.name: DragEventTestNg004
488 * @tc.desc: Create DragEventActuator and invoke OnCollectTouchTarget.
489 * @tc.type: FUNC
490 */
491 HWTEST_F(DragEventTestNg, DragEventTestNg004, TestSize.Level1)
492 {
493 /**
494 * @tc.steps: step1. Create DragEventActuator.
495 */
496 SystemProperties::debugEnabled_ = true;
497 auto eventHub = AceType::MakeRefPtr<EventHub>();
498 auto frameNode = FrameNode::CreateFrameNode(
499 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
500 DragDropInfo dragDropInfo;
501 frameNode->SetDragPreview(dragDropInfo);
502 frameNode->SetDraggable(true);
503 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
504 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
505 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
506 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
507 /**
508 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
509 * @tc.expected: dragEventActuator's userCallback_ is not null.
510 */
__anon5b7ac9721a02(GestureEvent& info) 511 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon5b7ac9721b02(GestureEvent& info) 512 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9721c02(GestureEvent& info) 513 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9721d02() 514 GestureEventNoParameter actionCancel = []() {};
515 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
516 std::move(actionEnd), std::move(actionCancel));
517 dragEventActuator->ReplaceDragEvent(dragEvent);
518 dragEventActuator->SetCustomDragEvent(dragEvent);
519 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
520 /**
521 * @tc.steps: step3. Call the function OnCollectTouchTarget when sourceType is SourceType::MOUSE.
522 * @tc.expected: cover touchRestrict.sourceType == SourceType::MOUSE.
523 */
524 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
525 EXPECT_NE(getEventTargetImpl, nullptr);
526 TouchTestResult finalResult;
527 dragEventActuator->OnCollectTouchTarget(
528 COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT_MOUSE, getEventTargetImpl, finalResult);
529 EXPECT_FALSE(finalResult.empty());
530 }
531
532 /**
533 * @tc.name: DragEventTestNg005
534 * @tc.desc: Create DragEventActuator and invoke longPressUpdate callback.
535 * @tc.type: FUNC
536 */
537 HWTEST_F(DragEventTestNg, DragEventTestNg005, TestSize.Level1)
538 {
539 /**
540 * @tc.steps: step1. Create DragEventActuator.
541 */
542 auto eventHub = AceType::MakeRefPtr<EventHub>();
543 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
544 DragDropInfo dragDropInfo;
545 frameNode->SetDragPreview(dragDropInfo);
546 frameNode->SetDraggable(true);
547 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
548 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
549 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
550 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
551 /**
552 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
553 * @tc.expected: dragEventActuator's userCallback_ is not null.
554 */
__anon5b7ac9721e02(GestureEvent& info) 555 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon5b7ac9721f02(GestureEvent& info) 556 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9722002(GestureEvent& info) 557 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9722102() 558 GestureEventNoParameter actionCancel = []() {};
559 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
560 std::move(actionEnd), std::move(actionCancel));
561 dragEventActuator->ReplaceDragEvent(dragEvent);
562 dragEventActuator->SetCustomDragEvent(dragEvent);
563 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
564 /**
565 * @tc.steps: step3. Create callback and set as dragEventActuator's longPressUpdate_.
566 * @tc.expected: previewLongPressRecognizer_'s onAction_ is not null.
567 */
568 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
569 TouchTestResult finalResult;
570 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
571 EXPECT_NE(dragEventActuator->previewLongPressRecognizer_->onAction_, nullptr);
572 /**
573 * @tc.steps: step4. Invoke longPressUpdateValue callback.
574 * @tc.expected: cover longPressUpdateValue callback.
575 */
576 SystemProperties::debugEnabled_ = true;
577 GestureEvent info = GestureEvent();
578 (*(dragEventActuator->longPressRecognizer_->onActionUpdate_))(info);
579 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
580 SystemProperties::debugEnabled_ = false;
581 (*(dragEventActuator->longPressRecognizer_->onActionUpdate_))(info);
582 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), true);
583 /**
584 * @tc.steps: step5. Invoke longPressUpdate callback.
585 * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == true.
586 */
587 SystemProperties::debugEnabled_ = true;
588 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
589 EXPECT_EQ(dragEventActuator->IsAllowedDrag(), true);
590 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
591 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
592 /**
593 * @tc.steps: step6. Invoke longPressUpdate callback.
594 * @tc.expected: cover longPressUpdate when GetTextDraggable() == false, isAllowedDrag == false.
595 */
596 SystemProperties::debugEnabled_ = false;
597 frameNode->SetDraggable(false);
598 EXPECT_EQ(dragEventActuator->IsAllowedDrag(), false);
599 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
600 EXPECT_EQ(dragEventActuator->isReceivedLongPress_, true);
601 /**
602 * @tc.steps: step7. Invoke longPressUpdate callback.
603 * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == false.
604 */
605 gestureEventHub->SetTextDraggable(true);
606 gestureEventHub->SetIsTextDraggable(false);
607 dragEventActuator->SetIsNotInPreviewState(true);
608 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
609 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
610 /**
611 * @tc.steps: step8. Invoke longPressUpdate callback.
612 * @tc.expected: cover longPressUpdate when GetTextDraggable() == true, GetIsTextDraggable() == true.
613 */
614 gestureEventHub->SetIsTextDraggable(true);
615 dragEventActuator->SetIsNotInPreviewState(true);
616 (*(dragEventActuator->previewLongPressRecognizer_->onAction_))(info);
617 EXPECT_EQ(dragEventActuator->GetIsNotInPreviewState(), false);
618 }
619
620 /**
621 * @tc.name: DragEventTestNg006
622 * @tc.desc: Create DragEventActuator and invoke onActionStart callback.
623 * @tc.type: FUNC
624 */
625 HWTEST_F(DragEventTestNg, DragEventTestNg006, TestSize.Level1)
626 {
627 /**
628 * @tc.steps: step1. Create DragEventActuator.
629 */
630 SystemProperties::debugEnabled_ = true;
631 auto eventHub = AceType::MakeRefPtr<EventHub>();
632 auto frameNode = FrameNode::CreateFrameNode(
633 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
634 frameNode->SetDraggable(true);
635 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
636 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
637 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
638 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
639 /**
640 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
641 * @tc.expected: dragEventActuator's userCallback_ is not null.
642 */
643 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon5b7ac9722202(GestureEvent& info) 644 GestureEventFunc actionStart = [&unknownPropertyValue](GestureEvent& info) {
645 unknownPropertyValue = info.GetScale();
646 };
__anon5b7ac9722302(GestureEvent& info) 647 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9722402(GestureEvent& info) 648 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9722502() 649 GestureEventNoParameter actionCancel = []() {};
650 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
651 std::move(actionEnd), std::move(actionCancel));
652 dragEventActuator->ReplaceDragEvent(dragEvent);
653 dragEventActuator->SetCustomDragEvent(dragEvent);
654 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
655 /**
656 * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
657 * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionStart is not nullptr.
658 */
659 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
660 EXPECT_NE(getEventTargetImpl, nullptr);
661 TouchTestResult finalResult;
662 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
663 EXPECT_NE(dragEventActuator->panRecognizer_->onActionStart_, nullptr);
664 /**
665 * @tc.steps: step4. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
666 * @tc.expected: cover pattern->IsSelected() == false or GetMouseStatus() == MouseStatus::MOVE
667 */
668 GestureEvent info = GestureEvent();
669 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
670 info.SetSourceDevice(SourceType::MOUSE);
671 gestureEventHub->SetTextDraggable(true);
672 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
673 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
674
675 auto pattern = frameNode->GetPattern<TextPattern>();
676 pattern->mouseStatus_ = MouseStatus::MOVE;
677 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
678 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
679 EXPECT_EQ(pattern->GetMouseStatus(), MouseStatus::MOVE);
680 /**
681 * @tc.steps: step5. Invoke onActionStart callback, when info.GetSourceDevice() is SourceType::MOUSE.
682 * @tc.expected: cover GetTextDraggable() is false, Trigger drag start event set by user.
683 */
684 gestureEventHub->SetTextDraggable(false);
685 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
686 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
687 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
688 /**
689 * @tc.steps: step6. Invoke onActionStart callback, when info.GetSourceDevice() is not SourceType::MOUSE.
690 * @tc.expected: cover gestureHub->GetTextDraggable() is true
691 */
692 info.SetSourceDevice(SourceType::TOUCH);
693 gestureEventHub->SetTextDraggable(true);
694 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
695 (*(dragEventActuator->panRecognizer_->onActionStart_))(info);
696 EXPECT_EQ(gestureEventHub->GetIsTextDraggable(), false);
697 }
698
699 /**
700 * @tc.name: DragEventTestNg007
701 * @tc.desc: Create DragEventActuator and invoke onActionCancel callback.
702 * @tc.type: FUNC
703 */
704 HWTEST_F(DragEventTestNg, DragEventTestNg007, TestSize.Level1)
705 {
706 /**
707 * @tc.steps: step1. Create DragEventActuator.
708 */
709 auto eventHub = AceType::MakeRefPtr<EventHub>();
710 auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::TEXT_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
711 frameNode->SetDraggable(true);
712 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
713 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
714 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
715 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
716 /**
717 * @tc.steps: step2. Create DragEvent and set as DragEventActuator's DragEvent.
718 * @tc.expected: dragEventActuator's userCallback_ is not null.
719 */
720 double unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
__anon5b7ac9722602(GestureEvent& info) 721 GestureEventFunc actionStart = [](GestureEvent& info) {};
__anon5b7ac9722702(GestureEvent& info) 722 GestureEventFunc actionUpdate = [](GestureEvent& info) {};
__anon5b7ac9722802(GestureEvent& info) 723 GestureEventFunc actionEnd = [](GestureEvent& info) {};
__anon5b7ac9722902() 724 GestureEventNoParameter actionCancel = [&unknownPropertyValue]() {
725 unknownPropertyValue = GESTURE_EVENT_PROPERTY_VALUE;
726 };
727 auto dragEvent = AceType::MakeRefPtr<DragEvent>(std::move(actionStart), std::move(actionUpdate),
728 std::move(actionEnd), std::move(actionCancel));
729 dragEventActuator->ReplaceDragEvent(dragEvent);
730 dragEventActuator->SetCustomDragEvent(dragEvent);
731 EXPECT_NE(dragEventActuator->userCallback_, nullptr);
732 /**
733 * @tc.steps: step3. Invoke OnCollectTouchTarget when userCallback_ is not null.
734 * @tc.expected: longPressRecognizer is not nullptr and panRecognizer's callback onActionCancel is not nullptr.
735 */
736 auto getEventTargetImpl = eventHub->CreateGetEventTargetImpl();
737 TouchTestResult finalResult;
738 dragEventActuator->OnCollectTouchTarget(COORDINATE_OFFSET, DRAG_TOUCH_RESTRICT, getEventTargetImpl, finalResult);
739 EXPECT_NE(dragEventActuator->panRecognizer_->onActionCancel_, nullptr);
740 /**
741 * @tc.steps: step4. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
742 * @tc.expected: cover gestureHub->GetIsTextDraggable() is false.
743 */
744 SystemProperties::debugEnabled_ = true;
745 GestureEvent info = GestureEvent();
746 info.SetScale(GESTURE_EVENT_PROPERTY_VALUE);
747 gestureEventHub->SetTextDraggable(true);
748 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
749 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
750 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
751 /**
752 * @tc.steps: step5. Invoke onActionCancel callback, when gestureHub->GetTextDraggable() is true.
753 * @tc.expected: cover gestureHub->GetIsTextDraggable() is true.
754 */
755 SystemProperties::debugEnabled_ = false;
756 gestureEventHub->SetIsTextDraggable(true);
757 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
758 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
759 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
760 /**
761 * @tc.steps: step6. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
762 * @tc.expected: cover getDeviceType() != SourceType::MOUSE.
763 */
764 eventHub->AttachHost(nullptr);
765 EXPECT_EQ(dragEventActuator->GetIsBindOverlayValue(dragEventActuator), true);
766 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
767 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
768 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
769 /**
770 * @tc.steps: step7. Invoke onActionCancel callback, GetIsBindOverlayValue is true.
771 * @tc.expected: cover getDeviceType() == SourceType::MOUSE.
772 */
773 dragEventActuator->panRecognizer_->deviceType_ = SourceType::MOUSE;
774 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
775 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
776 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
777
778 gestureEventHub->SetTextDraggable(false);
779 unknownPropertyValue = GESTURE_EVENT_PROPERTY_DEFAULT_VALUE;
780 (*(dragEventActuator->panRecognizer_->onActionCancel_))();
781 EXPECT_EQ(unknownPropertyValue, GESTURE_EVENT_PROPERTY_VALUE);
782 }
783
784 /**
785 * @tc.name: DragEventTestNg008
786 * @tc.desc: Create DragEventActuator and invoke HideTextAnimation function.
787 * @tc.type: FUNC
788 */
789 HWTEST_F(DragEventTestNg, DragEventTestNg008, TestSize.Level1)
790 {
791 /**
792 * @tc.steps: step1. Create DragEventActuator.
793 */
794 auto eventHub = AceType::MakeRefPtr<EventHub>();
795 auto frameNode = FrameNode::CreateFrameNode(
796 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
797 NG::DragDropInfo dragPreviewInfo;
798 void* voidPtr = static_cast<void*>(new char[0]);
799 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
800 dragPreviewInfo.pixelMap = pixelMap;
801 frameNode->SetDragPreview(dragPreviewInfo);
802 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
803 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
804 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
805 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
806 /**
807 * @tc.steps: step2. Invoke HideTextAnimation function, when isAllowedDrag is false.
808 * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
809 */
810 SystemProperties::debugEnabled_ = true;
811 frameNode->SetDraggable(false);
812 gestureEventHub->SetTextDraggable(false);
813 dragEventActuator->HideTextAnimation();
814 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
815 gestureEventHub->SetTextDraggable(true);
816 dragEventActuator->HideTextAnimation();
817 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
818 /**
819 * @tc.steps: step3. Invoke HideTextAnimation function, when isAllowedDrag is true.
820 * @tc.expected: cover branch gestureHub->GetIsTextDraggable().
821 */
822 SystemProperties::debugEnabled_ = false;
823 frameNode->SetDraggable(true);
824 gestureEventHub->SetTextDraggable(false);
825 dragEventActuator->HideTextAnimation();
826 EXPECT_EQ(gestureEventHub->GetTextDraggable(), false);
827 gestureEventHub->SetTextDraggable(true);
828 dragEventActuator->HideTextAnimation();
829 EXPECT_EQ(gestureEventHub->GetTextDraggable(), true);
830 }
831
832 /**
833 * @tc.name: DragEventTestNg009
834 * @tc.desc: Create DragEventActuator and invoke MountPixelMap function.
835 * @tc.type: FUNC
836 */
837 HWTEST_F(DragEventTestNg, DragEventTestNg009, TestSize.Level1)
838 {
839 /**
840 * @tc.steps: step1. Create DragEventActuator.
841 */
842 auto eventHub = AceType::MakeRefPtr<EventHub>();
843 auto frameNode = FrameNode::CreateFrameNode(
844 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
845 eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
846 auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
847 auto dragEventActuator = AceType::MakeRefPtr<DragEventActuator>(
848 AceType::WeakClaim(AceType::RawPtr(gestureEventHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
849 /**
850 * @tc.steps: step2. CreatePixelMap and Invoke CreatePreviewNode function.
851 * @tc.expected: GetClickEffectLevelValue is correct.
852 */
853 frameNode->eventHub_->SetEnabled(true);
854 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
855 ASSERT_NE(gestureHub, nullptr);
856 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
857 ASSERT_NE(mockRenderContext, nullptr);
858 frameNode->renderContext_ = mockRenderContext;
859 void* voidPtr = static_cast<void*>(new char[0]);
860 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
861 gestureHub->SetPixelMap(pixelMap);
862 EXPECT_NE(frameNode->GetPixelMap(), nullptr);
863 RefPtr<FrameNode> imageNode = AceType::DynamicCast<FrameNode>(frameNode->GetFirstChild());
864 dragEventActuator->CreatePreviewNode(frameNode, imageNode);
865 auto imageContext = imageNode->GetRenderContext();
866 auto clickEffectInfo = imageContext->GetClickEffectLevelValue();
867 EXPECT_EQ(clickEffectInfo.level, ClickEffectLevel::LIGHT);
868 /**
869 * @tc.steps: step3. Invoke MountPixelMap function.
870 * @tc.expected: MountPixelMapToRootNode success, overlayManager's hasPixelMap is true.
871 */
872 auto pipeline = PipelineContext::GetCurrentContext();
873 auto overlayManager = pipeline->GetOverlayManager();
874 EXPECT_NE(overlayManager, nullptr);
875 dragEventActuator->MountPixelMap(overlayManager, gestureHub, imageNode);
876 EXPECT_EQ(overlayManager->hasPixelMap_, true);
877 /**
878 * @tc.steps: step4. Invoke SetPreviewDefaultAnimateProperty function.
879 * @tc.expected: cover branch IsPreviewNeedScale() == true.
880 */
881 imageNode->GetGeometryNode()->frame_.rect_.width_ = IMAGE_INVALID_RECT_WIDTH;
882 EXPECT_EQ(imageNode->IsPreviewNeedScale(), true);
883 dragEventActuator->SetPreviewDefaultAnimateProperty(imageNode);
884 TranslateOptions result = imageContext->GetTransformTranslate().value();
885 TranslateOptions expectValue { 0.0f, 0.0f, 0.0f };
886 EXPECT_EQ(result.x.calcvalue_, expectValue.x.calcvalue_);
887 }
888 } // namespace OHOS::Ace::NG
889