• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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/manager/drag_drop/drag_drop_initiating_test_ng.h"
17 #define private public
18 #define protected public
19 
20 #include "core/components_ng/manager/drag_drop/drag_drop_initiating/drag_drop_initiating_handler.h"
21 #include "core/components_ng/manager/drag_drop/drag_drop_initiating/drag_drop_initiating_state_base.h"
22 #include "core/event/touch_event.h"
23 #include "core/gestures/drag_event.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS::Ace::NG {
29 namespace {
30 constexpr float DEFAULT_OPACITY = 0.95f;
31 constexpr float DEFAULT_SCALE = 2.0f;
32 }
33 
SetUpTestCase()34 void DragDropInitiatingStateBaseTestNG::SetUpTestCase()
35 {
36     MockPipelineContext::SetUp();
37     MockContainer::SetUp();
38 }
39 
TearDownTestCase()40 void DragDropInitiatingStateBaseTestNG::TearDownTestCase()
41 {
42     MockPipelineContext::TearDown();
43     MockContainer::TearDown();
44 }
45 
46 struct HandleTextDragStartTestCase {
47     SourceType type = SourceType::MOUSE;
48     bool isSelected = false;
49     bool textDraggable = false;
50     bool expectResult = false;
51 };
52 
53 const std::vector<HandleTextDragStartTestCase> HANDLE_TEXT_DRAG_START_TEST_CASES = {
54     { SourceType::TOUCH, false, false, false },
55     { SourceType::TOUCH, true, false, true },
56     { SourceType::TOUCH, false, false, false },
57     { SourceType::TOUCH, false, true, false },
58     { SourceType::MOUSE, false, true, false },
59     { SourceType::MOUSE, true, true, true }
60 };
61 
CreateDragDropEventActuator()62 RefPtr<DragDropEventActuator> CreateDragDropEventActuator()
63 {
64     auto eventHub = AceType::MakeRefPtr<EventHub>();
65     CHECK_NULL_RETURN(eventHub, nullptr);
66     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
67     CHECK_NULL_RETURN(gestureEventHub, nullptr);
68     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
69     CHECK_NULL_RETURN(frameNode, nullptr);
70     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
71     auto dragDropEventActuator =
72         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
73     CHECK_NULL_RETURN(dragDropEventActuator, nullptr);
74     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
75     CHECK_NULL_RETURN(handler, nullptr);
76     auto machine = handler->initiatingFlow_;
77     CHECK_NULL_RETURN(machine, nullptr);
78     machine->InitializeState();
79     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
80     return dragDropEventActuator;
81 }
82 
GetDragDropState(RefPtr<DragDropEventActuator> actuator,DragDropInitiatingStatus state)83 RefPtr<DragDropInitiatingStateBase> GetDragDropState(RefPtr<DragDropEventActuator> actuator,
84     DragDropInitiatingStatus state)
85 {
86     CHECK_NULL_RETURN(actuator, nullptr);
87     auto handler = actuator->dragDropInitiatingHandler_;
88     CHECK_NULL_RETURN(handler, nullptr);
89     auto machine = handler->initiatingFlow_;
90     CHECK_NULL_RETURN(machine, nullptr);
91     return machine->dragDropInitiatingState_[static_cast<int32_t>(state)];
92 }
93 
94 /**
95  * @tc.name: DragDropInitiatingStateBaseTestNG001
96  * @tc.desc: Test PrepareFinalPixelMapForDragThroughTouch function.
97  * @tc.type: FUNC
98  */
99 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG001, TestSize.Level1)
100 {
101     /**
102      * @tc.steps: step1. create DragDropEventActuator.
103      */
104     auto actuator = CreateDragDropEventActuator();
105     ASSERT_NE(actuator, nullptr);
106 
107     /**
108      * @tc.steps: step2. get DragDropInitiatingStateBase.
109      */
110     auto state = GetDragDropState(actuator, DragDropInitiatingStatus::IDLE);
111     ASSERT_NE(state, nullptr);
112     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
113     ASSERT_NE(stateIdle, nullptr);
114     auto machine = stateIdle->GetStateMachine();
115     ASSERT_NE(machine, nullptr);
116 
117     /**
118      * @tc.steps: step3. trigger PrepareFinalPixelMapForDragThroughTouch.
119      */
120     stateIdle->PrepareFinalPixelMapForDragThroughTouch(nullptr, false);
121     auto params = machine->GetDragDropInitiatingParams();
122     EXPECT_FALSE(params.isThumbnailCallbackTriggered);
123 
124     stateIdle->PrepareFinalPixelMapForDragThroughTouch(nullptr, true);
125     params = machine->GetDragDropInitiatingParams();
126     EXPECT_TRUE(params.isThumbnailCallbackTriggered);
127 }
128 
129 /**
130  * @tc.name: DragDropInitiatingStateBaseTestNG002
131  * @tc.desc: Test HidePixelMap function.
132  * @tc.type: FUNC
133  */
134 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG002, TestSize.Level1)
135 {
136     /**
137      * @tc.steps: step1. create DragDropEventActuator.
138      */
139     auto eventHub = AceType::MakeRefPtr<EventHub>();
140     ASSERT_NE(eventHub, nullptr);
141     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
142     ASSERT_NE(gestureEventHub, nullptr);
143     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
144     ASSERT_NE(frameNode, nullptr);
145     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
146     auto dragDropEventActuator =
147         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
148     ASSERT_NE(dragDropEventActuator, nullptr);
149     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
150     ASSERT_NE(handler, nullptr);
151     auto machine = handler->initiatingFlow_;
152     ASSERT_NE(machine, nullptr);
153     machine->InitializeState();
154     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
155     /**
156      * @tc.steps: step2. get DragDropInitiatingStateBase.
157      */
158     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
159     ASSERT_NE(state, nullptr);
160     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
161     ASSERT_NE(stateIdle, nullptr);
162 
163     /**
164      * @tc.steps: step3. set multi drag and default animation.
165      */
166     auto& params = machine->GetDragDropInitiatingParams();
167     params.hasGatherNode = true;
168     auto dragPreviewOption = frameNode->GetDragPreviewOption();
169     dragPreviewOption.defaultAnimationBeforeLifting = true;
170     frameNode->SetDragPreviewOptions(dragPreviewOption);
171     auto layoutProperty = frameNode->GetLayoutProperty();
172     ASSERT_NE(layoutProperty, nullptr);
173     layoutProperty->UpdateVisibility(VisibleType::INVISIBLE);
174 
175     /**
176      * @tc.steps: step4. trigger HidePixelMap.
177      */
178     stateIdle->HidePixelMap(false, 0, 0, false);
179     layoutProperty = frameNode->GetLayoutProperty();
180     ASSERT_NE(layoutProperty, nullptr);
181     auto type = layoutProperty->GetVisibilityValue(VisibleType::INVISIBLE);
182     EXPECT_EQ(type, VisibleType::VISIBLE);
183 }
184 
185 /**
186  * @tc.name: DragDropInitiatingStateBaseTestNG003
187  * @tc.desc: Test UpdateDragPreviewOptionFromModifier function.
188  * @tc.type: FUNC
189  */
190 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG003, TestSize.Level1)
191 {
192     /**
193      * @tc.steps: step1. create DragDropEventActuator.
194      */
195     auto eventHub = AceType::MakeRefPtr<EventHub>();
196     ASSERT_NE(eventHub, nullptr);
197     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
198     ASSERT_NE(gestureEventHub, nullptr);
199     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
200     ASSERT_NE(frameNode, nullptr);
201     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
202     auto dragDropEventActuator =
203         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
204     ASSERT_NE(dragDropEventActuator, nullptr);
205     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
206     ASSERT_NE(handler, nullptr);
207     auto machine = handler->initiatingFlow_;
208     ASSERT_NE(machine, nullptr);
209     machine->InitializeState();
210     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
211 
212     /**
213      * @tc.steps: step2. get DragDropInitiatingStateBase.
214      */
215     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
216     ASSERT_NE(state, nullptr);
217     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
218     ASSERT_NE(stateIdle, nullptr);
219 
220     /**
221      * @tc.steps: step3. set onApply.
222      */
223     auto dragPreviewOption = frameNode->GetDragPreviewOption();
__anonc7496a690202(WeakPtr<NG::FrameNode> frameNodes) 224     dragPreviewOption.onApply = [](WeakPtr<NG::FrameNode> frameNodes) {
225     };
226     frameNode->SetDragPreviewOptions(dragPreviewOption);
227 
228     /**
229      * @tc.steps: step4. trigger UpdateDragPreviewOptionFromModifier.
230      */
231     stateIdle->UpdateDragPreviewOptionFromModifier();
232     dragPreviewOption = frameNode->GetDragPreviewOption();
233     EXPECT_EQ(dragPreviewOption.options.opacity, DEFAULT_OPACITY);
234 }
235 
236 /**
237  * @tc.name: DragDropInitiatingStateBaseTestNG004
238  * @tc.desc: Test CheckStatusForPanActionBegin function.
239  * @tc.type: FUNC
240  */
241 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG004, TestSize.Level1)
242 {
243     /**
244      * @tc.steps: step1. create DragDropEventActuator.
245      */
246     auto eventHub = AceType::MakeRefPtr<EventHub>();
247     ASSERT_NE(eventHub, nullptr);
248     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
249     ASSERT_NE(gestureEventHub, nullptr);
250     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
251     ASSERT_NE(frameNode, nullptr);
252     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
253     auto dragDropEventActuator =
254         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
255     ASSERT_NE(dragDropEventActuator, nullptr);
256     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
257     ASSERT_NE(handler, nullptr);
258     auto machine = handler->initiatingFlow_;
259     ASSERT_NE(machine, nullptr);
260     machine->InitializeState();
261     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
262 
263     /**
264      * @tc.steps: step2. get DragDropInitiatingStateBase.
265      */
266     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
267     ASSERT_NE(state, nullptr);
268     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
269     ASSERT_NE(stateIdle, nullptr);
270 
271     /**
272      * @tc.steps: step3. update IsDragNodeNeedClean and draggable.
273      */
274     auto pipelineContext = MockPipelineContext::GetCurrentContext();
275     ASSERT_NE(pipelineContext, nullptr);
276     auto dragDropManager = pipelineContext->GetDragDropManager();
277     ASSERT_NE(dragDropManager, nullptr);
278     dragDropManager->SetIsDragNodeNeedClean(false);
279     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
280     ASSERT_NE(gestureHub, nullptr);
281     gestureHub->textDraggable_ = true;
282     gestureHub->isTextDraggable_ = false;
283 
284     /**
285      * @tc.steps: step4. trigger CheckStatusForPanActionBegin.
286      */
287     GestureEvent info;
288     auto result = stateIdle->CheckStatusForPanActionBegin(frameNode, info);
289     EXPECT_FALSE(result);
290 }
291 
292 /**
293  * @tc.name: DragDropInitiatingStateBaseTestNG005
294  * @tc.desc: Test SetTextPixelMap function.
295  * @tc.type: FUNC
296  */
297 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG005, TestSize.Level1)
298 {
299     /**
300      * @tc.steps: step1. create DragDropEventActuator.
301      */
302     auto eventHub = AceType::MakeRefPtr<EventHub>();
303     ASSERT_NE(eventHub, nullptr);
304     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
305     ASSERT_NE(gestureEventHub, nullptr);
306     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
307     ASSERT_NE(frameNode, nullptr);
308     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
309     auto dragDropEventActuator =
310         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
311     ASSERT_NE(dragDropEventActuator, nullptr);
312     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
313     ASSERT_NE(handler, nullptr);
314     auto machine = handler->initiatingFlow_;
315     ASSERT_NE(machine, nullptr);
316     machine->InitializeState();
317     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
318 
319     /**
320      * @tc.steps: step2. get DragDropInitiatingStateBase.
321      */
322     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
323     ASSERT_NE(state, nullptr);
324     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
325     ASSERT_NE(stateIdle, nullptr);
326     auto& params = machine->GetDragDropInitiatingParams();
327 
328     /**
329      * @tc.steps: step3. trigger SetTextPixelMap.
330      */
331     auto textPixelMap = AceType::MakeRefPtr<MockPixelMap>();
332     ASSERT_NE(textPixelMap, nullptr);
333     params.preScaledPixelMap = textPixelMap;
334     stateIdle->SetTextPixelMap();
335     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
336     ASSERT_NE(gestureHub, nullptr);
337     EXPECT_NE(gestureHub->pixelMap_, textPixelMap);
338     EXPECT_NE(params.preScaledPixelMap, nullptr);
339 
340     stateIdle->SetTextPixelMap();
341     EXPECT_NE(gestureHub->pixelMap_, textPixelMap);
342 }
343 
344 /**
345  * @tc.name: DragDropInitiatingStateBaseTestNG006
346  * @tc.desc: Test HideTextAnimation function.
347  * @tc.type: FUNC
348  */
349 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG006, TestSize.Level1)
350 {
351     /**
352      * @tc.steps: step1. create DragDropEventActuator.
353      */
354     auto eventHub = AceType::MakeRefPtr<EventHub>();
355     ASSERT_NE(eventHub, nullptr);
356     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
357     ASSERT_NE(gestureEventHub, nullptr);
358     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
359     ASSERT_NE(frameNode, nullptr);
360     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
361     auto dragDropEventActuator =
362         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
363     ASSERT_NE(dragDropEventActuator, nullptr);
364     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
365     ASSERT_NE(handler, nullptr);
366     auto machine = handler->initiatingFlow_;
367     ASSERT_NE(machine, nullptr);
368     machine->InitializeState();
369     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
370 
371     /**
372      * @tc.steps: step2. get DragDropInitiatingStateBase.
373      */
374     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
375     ASSERT_NE(state, nullptr);
376     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
377     ASSERT_NE(stateIdle, nullptr);
378     auto context = frameNode->GetRenderContext();
379     ASSERT_NE(context, nullptr);
380     context->UpdateTransformScale(VectorF(DEFAULT_SCALE, DEFAULT_SCALE));
381 
382     /**
383      * @tc.steps: step3. trigger HideTextAnimation.
384      */
385     stateIdle->HideTextAnimation(false, 0.0f, 0.0f);
386     auto scale = context->GetTransformScaleValue({ 1.0f, 1.0f });
387     EXPECT_EQ(scale.x, DEFAULT_SCALE);
388     EXPECT_EQ(scale.y, DEFAULT_SCALE);
389 
390     frameNode->draggable_ = true;
391     stateIdle->HideTextAnimation(false, 0.0f, 0.0f);
392     scale = context->GetTransformScaleValue({ 1.0f, 1.0f });
393     EXPECT_EQ(scale.x, DEFAULT_SCALE);
394     EXPECT_EQ(scale.y, DEFAULT_SCALE);
395 
396     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
397     ASSERT_NE(pipeline, nullptr);
398     auto manager = pipeline->GetOverlayManager();
399     ASSERT_NE(manager, nullptr);
400     auto dragNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
401     ASSERT_NE(dragNode, nullptr);
402     manager->pixmapColumnNodeWeak_ = dragNode;
403     stateIdle->HideTextAnimation(false, 0.0f, 0.0f);
404     scale = context->GetTransformScaleValue({ 1.0f, 1.0f });
405     EXPECT_EQ(scale.x, 2.0f);
406     EXPECT_EQ(scale.y, 2.0f);
407 }
408 
409 /**
410  * @tc.name: DragDropInitiatingStateBaseTestNG007
411  * @tc.desc: Test HandleTextDragCallback function.
412  * @tc.type: FUNC
413  */
414 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG007, TestSize.Level1)
415 {
416     /**
417      * @tc.steps: step1. create DragDropEventActuator.
418      */
419     auto eventHub = AceType::MakeRefPtr<EventHub>();
420     ASSERT_NE(eventHub, nullptr);
421     auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
422     ASSERT_NE(gestureEventHub, nullptr);
423     auto frameNode = AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
424     ASSERT_NE(frameNode, nullptr);
425     eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
426     auto dragDropEventActuator =
427         AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
428     ASSERT_NE(dragDropEventActuator, nullptr);
429     auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
430     ASSERT_NE(handler, nullptr);
431     auto machine = handler->initiatingFlow_;
432     ASSERT_NE(machine, nullptr);
433     machine->InitializeState();
434     machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
435 
436     /**
437      * @tc.steps: step2. get DragDropInitiatingStateBase.
438      */
439     auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
440     ASSERT_NE(state, nullptr);
441     auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
442     ASSERT_NE(stateIdle, nullptr);
443     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
444     ASSERT_NE(gestureHub, nullptr);
445     gestureHub->pixelMap_ = AceType::MakeRefPtr<MockPixelMap>();
446     gestureHub->isTextDraggable_ = false;
447 
448     /**
449      * @tc.steps: step3. trigger HandleTextDragCallback.
450      */
451     stateIdle->HandleTextDragCallback();
452     EXPECT_EQ(gestureHub->pixelMap_, nullptr);
453 }
454 
455 /**
456  * @tc.name: DragDropInitiatingStateBaseTestNG008
457  * @tc.desc: Test HandleTextDragStart function.
458  * @tc.type: FUNC
459  */
460 HWTEST_F(DragDropInitiatingStateBaseTestNG, DragDropInitiatingStateBaseTestNG008, TestSize.Level1)
461 {
462     for (const auto& testCase : HANDLE_TEXT_DRAG_START_TEST_CASES) {
463         /**
464          * @tc.steps: step1. create DragDropEventActuator.
465          */
466         auto eventHub = AceType::MakeRefPtr<EventHub>();
467         ASSERT_NE(eventHub, nullptr);
468         auto gestureEventHub = AceType::MakeRefPtr<GestureEventHub>(AceType::WeakClaim(AceType::RawPtr(eventHub)));
469         ASSERT_NE(gestureEventHub, nullptr);
470         auto frameNode =
471             AceType::MakeRefPtr<FrameNode>(V2::SEARCH_Field_ETS_TAG, -1, AceType::MakeRefPtr<TextPattern>());
472         ASSERT_NE(frameNode, nullptr);
473         eventHub->host_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
474         auto dragDropEventActuator =
475             AceType::MakeRefPtr<DragDropEventActuator>(AceType::WeakClaim(AceType::RawPtr(gestureEventHub)));
476         ASSERT_NE(dragDropEventActuator, nullptr);
477         auto handler = dragDropEventActuator->dragDropInitiatingHandler_;
478         ASSERT_NE(handler, nullptr);
479         auto machine = handler->initiatingFlow_;
480         ASSERT_NE(machine, nullptr);
481         machine->InitializeState();
482         machine->currentState_ = static_cast<int32_t>(DragDropInitiatingStatus::IDLE);
483 
484         /**
485          * @tc.steps: step2. get DragDropInitiatingStateBase.
486          */
487         auto state = GetDragDropState(dragDropEventActuator, DragDropInitiatingStatus::IDLE);
488         ASSERT_NE(state, nullptr);
489         auto stateIdle = AceType::DynamicCast<DragDropInitiatingStateBase>(state);
490         ASSERT_NE(stateIdle, nullptr);
491         auto gestureHub = frameNode->GetOrCreateGestureEventHub();
492         ASSERT_NE(gestureHub, nullptr);
493         gestureHub->isTextDraggable_ = true;
494         auto pattern = frameNode->GetPattern<TextBase>();
495         ASSERT_NE(pattern, nullptr);
496         GestureEvent info;
497         info.SetSourceDevice(testCase.type);
498         if (testCase.isSelected) {
499             pattern->textSelector_.Update(3, 4);
500         }
501         gestureHub->textDraggable_ = testCase.textDraggable;
502 
503         /**
504          * @tc.steps: step3. get DragDropInitiatingStateBase.
505          */
506         stateIdle->HandleTextDragStart(frameNode, info);
507         EXPECT_EQ(gestureHub->isTextDraggable_, testCase.expectResult);
508     }
509 }
510 } // namespace OHOS::Ace::NG