• 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 "drag_drop_spring_loading_test_ng.h"
17 
18 #include <cstdint>
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS::Ace::NG {
24 namespace {
25 constexpr int32_t SEQUENCE_INIT = -1;
26 constexpr int32_t SEQUENCE_ZERO = 0;
27 constexpr int32_t SEQUENCE_ONCE = 1;
28 constexpr int32_t SEQUENCE_FOURTH = 4;
29 constexpr int32_t DOUBLE = 2;
30 constexpr uint64_t SHORT_TIME = 100;
31 constexpr uint64_t LONG_TIME = 10000;
32 constexpr size_t SM_POOL_SIZE = 5;
33 
34 const Point FIRST_POINT(50, 50);
35 const Point SECOND_POINT(60, 50);
36 const Point THIRD_POINT(50, 60);
37 } // namespace
38 
SetUpTestCase()39 void DragSpringLoadingTestNg::SetUpTestCase()
40 {
41     MockPipelineContext::SetUp();
42     MockContainer::SetUp();
43 }
44 
TearDownTestCase()45 void DragSpringLoadingTestNg::TearDownTestCase()
46 {
47     MockPipelineContext::TearDown();
48     MockContainer::TearDown();
49 }
50 
SetUp()51 void DragSpringLoadingTestNg::SetUp()
52 {
53     detector_ = AceType::MakeRefPtr<DragDropSpringLoadingDetector>();
54     dragFrameNode_ = FrameNode::CreateFrameNode(
55         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
56     ASSERT_NE(dragFrameNode_, nullptr);
57     auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
58     geometryNode->SetFrameSize(FRAME_SIZE);
59     dragFrameNode_->SetGeometryNode(geometryNode);
60     dropFrameNode_ = FrameNode::CreateFrameNode(
61         V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
62     auto dropGeometryNode = AceType::MakeRefPtr<GeometryNode>();
63     geometryNode->SetFrameSize(FRAME_SIZE * DOUBLE);
64     dropFrameNode_->SetGeometryNode(dropGeometryNode);
65 
66     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
67     ASSERT_NE(pipeline, nullptr);
68     pipeline->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
69     detector_->stateMachine_->taskExecutor_ =
70         SingleTaskExecutor::Make(pipeline->taskExecutor_, TaskExecutor::TaskType::UI);
71     auto now = std::chrono::system_clock::now();
72     curTimeStamp_ =
73         static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count());
74 }
75 
76 const std::vector<DragDropSpringLoadingDetectorTestCase> DRAG_DROP_SPRING_LOADING_DETECTOR_TEST_CASES = {
77     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
78         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
79         false, { false, false }),
80     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
81         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
82         false, { true, false }),
83     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
84         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false),
85     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
86         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, false,
87         false, { true, true }),
88     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
89         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, false,
90         true),
91     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
92         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, true, false,
93         true, { false, true }),
94     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
95         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, true,
96         true, { false, true }),
97     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
98         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, true, true,
99         { false, false }),
100     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
101         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, true,
102         true, { false, true }),
103     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
104         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, true,
105         true, { false, true }),
106     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_MOVE,
107         DragDropSpringLoadingState::CANCEL, DragDropSpringLoadingState::END, SEQUENCE_FOURTH, FIRST_POINT, true, true,
108         true, { false, true }),
109     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
110         DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
111         false, { false, false }),
112     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
113         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
114         true, { false, false }),
115     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
116         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
117         true, { false, true }),
118     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
119         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, true, false,
120         true, { true, true }),
121     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
122         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, true, false,
123         true, { true, true }),
124     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
125         DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, true, false,
126         true, { true, true }),
127     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT,
128         DragDropSpringLoadingState::CANCEL, DragDropSpringLoadingState::CANCEL, SEQUENCE_INIT, FIRST_POINT, true, false,
129         true, { true, true }),
130     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::THRESHOLD,
131         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, false, true,
132         { true, true }, { false, false }),
133     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::THRESHOLD,
134         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, false, true,
135         { true, true }, { true, false }),
136     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::THRESHOLD,
137         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, false, true,
138         { true, true }, { true, true }),
139     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::THRESHOLD,
140         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, true, true,
141         { true, true }, { true, true }),
142     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::THRESHOLD,
143         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, SEQUENCE_INIT, FIRST_POINT, true, true, true,
144         { true, true }, { true, false }),
145     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::INTERCEPT,
146         DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, true, true, true,
147         { true, true }, { true, false }),
148     DragDropSpringLoadingDetectorTestCase(DragDropSpringLoadingReceivedInput::INTERCEPT,
149         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, SEQUENCE_INIT, FIRST_POINT, false, false,
150         false, { true, true }, { true, false }),
151 };
152 
153 const std::vector<DragDropSpringLoadingStateHandler> DRAG_DROP_SPRING_LOADING_STATE_HANDLER_TEST_CASES = {
154     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::IDLE_ON_ENTER,
155         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::END, true, SEQUENCE_FOURTH),
156     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::IDLE_ON_ENTER,
157         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::BEGIN, false, SEQUENCE_INIT),
158     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
159         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::BEGIN, false, SEQUENCE_INIT),
160     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
161         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::BEGIN, true, SEQUENCE_ZERO, false,
162         { true, false }),
163     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
164         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
165         { true, false }),
166     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
167         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
168         { false, false }),
169     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
170         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true, { true, true }),
171     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
172         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
173         { true, false, false }),
174     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
175         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
176         { true, false, true }),
177     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::BEGIN_ON_ENTER,
178         DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::END, true, SEQUENCE_ONCE, false,
179         { false, false }, SEQUENCE_ZERO),
180     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
181         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::BEGIN, false, SEQUENCE_INIT),
182     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
183         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::UPDATE, true, SEQUENCE_ZERO, false,
184         { true, false }),
185     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
186         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
187         { true, false }),
188     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
189         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true,
190         { false, false }),
191     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
192         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::END, true, SEQUENCE_ONCE, false,
193         { false, false }, SEQUENCE_ZERO),
194     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
195         DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::UPDATE, true, SEQUENCE_ZERO, false,
196         { true, false }, SEQUENCE_ZERO),
197     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::END_ON_ENTER,
198         DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::BEGIN, false, SEQUENCE_INIT),
199     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
200         DragDropSpringLoadingState::END, DragDropSpringLoadingState::END, true, SEQUENCE_ZERO, false, { true, false }),
201     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
202         DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true, { true, false }),
203     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::UPDATE_ON_ENTER,
204         DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, true, { false, false }),
205     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::CANCEL_ON_ENTER,
206         DragDropSpringLoadingState::CANCEL, DragDropSpringLoadingState::CANCEL, false, SEQUENCE_INIT),
207     DragDropSpringLoadingStateHandler(DragDropSpringLoadingReceivedInput::CANCEL_ON_ENTER,
208         DragDropSpringLoadingState::CANCEL, DragDropSpringLoadingState::IDLE, true, SEQUENCE_INIT, false,
209         { false, false }),
210 };
211 
CheckDragDropSpringLoadingStatus(int32_t caseNum,DragDropSpringLoadingState currentStatus,DragDropSpringLoadingState expectStatus)212 testing::AssertionResult DragSpringLoadingTestNg::CheckDragDropSpringLoadingStatus(
213     int32_t caseNum, DragDropSpringLoadingState currentStatus, DragDropSpringLoadingState expectStatus)
214 {
215     if (currentStatus == expectStatus) {
216         return testing::AssertionSuccess();
217     }
218     return testing::AssertionFailure() << "TestCaseNum: " << caseNum
219                                        << ", actual state: " << static_cast<int32_t>(currentStatus)
220                                        << ", expect state: " << static_cast<int32_t>(expectStatus);
221 }
222 
CheckDragDropSpringLoadingNotifySequence(int32_t caseNum,int32_t notifySequence,int32_t expectNotifySequence)223 testing::AssertionResult DragSpringLoadingTestNg::CheckDragDropSpringLoadingNotifySequence(
224     int32_t caseNum, int32_t notifySequence, int32_t expectNotifySequence)
225 {
226     if (notifySequence == expectNotifySequence) {
227         return testing::AssertionSuccess();
228     }
229     return testing::AssertionFailure() << "TestCaseNum: " << caseNum
230                                        << ", actual notifySequence: " << static_cast<int32_t>(notifySequence)
231                                        << ", expect notifySequence: " << static_cast<int32_t>(expectNotifySequence);
232 }
233 
HandleMoveInput(const DragDropSpringLoadingDetectorTestCase & testCase)234 void DragSpringLoadingTestNg::HandleMoveInput(const DragDropSpringLoadingDetectorTestCase& testCase)
235 {
236     RefPtr<FrameNode> dropFrameNode = nullptr;
237     if (testCase.hasCallback) {
238         dropFrameNode_->eventHub_->SetCustomerOnDragSpringLoading(
239             [](const RefPtr<DragSpringLoadingContext>& info) { ASSERT_NE(info, nullptr); });
240     }
241     if (testCase.hasDefaultFrameNode) {
242         dragFrameNode_->eventHub_ = AceType::MakeRefPtr<EventHub>();
243         detector_->preTargetFrameNode_ = dragFrameNode_;
244         if (!testCase.paramsTestCase.hasFrameNode) {
245             dropFrameNode = dragFrameNode_;
246             dropFrameNode->eventHub_->SetCustomerOnDragSpringLoading(
247                 [](const RefPtr<DragSpringLoadingContext>& info) { ASSERT_NE(info, nullptr); });
248         }
249     }
250     if (testCase.paramsTestCase.hasFrameNode) {
251         dropFrameNode = dropFrameNode_;
252         if (!testCase.paramsTestCase.hasEventHub) {
253             dropFrameNode->eventHub_ = nullptr;
254         }
255     }
256     if (!testCase.isMovementExceedThreshold) {
257         detector_->preMovePoint_ = testCase.movePoint;
258         detector_->preTimeStamp_ = curTimeStamp_;
259     } else {
260         detector_->preMovePoint_ = Point(0, 0);
261         detector_->preTimeStamp_ = curTimeStamp_ - SHORT_TIME;
262     }
263     detector_->NotifyMove({ testCase.movePoint, dropFrameNode, curTimeStamp_, testCase.extraInfo });
264 }
265 
HandleNotifyInterceptInput(const DragDropSpringLoadingDetectorTestCase & testCase)266 void DragSpringLoadingTestNg::HandleNotifyInterceptInput(const DragDropSpringLoadingDetectorTestCase& testCase)
267 {
268     if (testCase.hasDefaultFrameNode) {
269         detector_->preTargetFrameNode_ = dropFrameNode_;
270         if (!testCase.paramsTestCase.hasEventHub) {
271             detector_->preTargetFrameNode_->eventHub_ = nullptr;
272         } else if (testCase.hasCallback) {
273             detector_->preTargetFrameNode_->eventHub_->SetCustomerOnDragSpringLoading(
274                 [](const RefPtr<DragSpringLoadingContext>& info) { ASSERT_NE(info, nullptr); });
275         }
276     }
277     detector_->NotifyIntercept(testCase.extraInfo);
278 }
279 
HandleThresholdInput(const DragDropSpringLoadingDetectorTestCase & testCase)280 void DragSpringLoadingTestNg::HandleThresholdInput(const DragDropSpringLoadingDetectorTestCase& testCase)
281 {
282     if (!testCase.isMovementExceedThreshold) {
283         if (testCase.preInfoTestCase.hasPreTimeStamp) {
284             detector_->preTimeStamp_ = curTimeStamp_;
285         }
286         if (testCase.preInfoTestCase.hasPreMovePoint) {
287             detector_->preTimeStamp_ = curTimeStamp_ - LONG_TIME;
288         }
289     } else {
290         if (testCase.preInfoTestCase.hasPreMovePoint) {
291             detector_->preMovePoint_ = SECOND_POINT;
292         } else {
293             detector_->preMovePoint_ = THIRD_POINT;
294         }
295         detector_->preTimeStamp_ = curTimeStamp_ - SHORT_TIME;
296     }
297     detector_->IsMovementExceedThreshold(curTimeStamp_, testCase.movePoint);
298 }
299 
HandleDragSpringLoadingCallback(const RefPtr<DragSpringLoadingContext> & info,const DragDropSpringLoadingStateHandler & testCase)300 void HandleDragSpringLoadingCallback(
301     const RefPtr<DragSpringLoadingContext>& info, const DragDropSpringLoadingStateHandler& testCase)
302 {
303     ASSERT_NE(info, nullptr);
304     auto config = info->GetDragSpringLoadingConfiguration();
305     ASSERT_NE(config, nullptr);
306 
307     config->updateNotifyCount = testCase.updateNotifyCount;
308     info->SetDragSpringLoadingConfiguration(config);
309 
310     if (testCase.abort) {
311         info->SetSpringLoadingAborted();
312     }
313 }
314 
SetupTestCaseConditions(const DragDropSpringLoadingStateHandler & testCase)315 void DragSpringLoadingTestNg::SetupTestCaseConditions(const DragDropSpringLoadingStateHandler& testCase)
316 {
317     auto machine = detector_->stateMachine_;
318     if (testCase.hasCallback) {
319         dropFrameNode_->eventHub_->SetCustomerOnDragSpringLoading(
320             [testCase](
321                 const RefPtr<DragSpringLoadingContext>& info) { HandleDragSpringLoadingCallback(info, testCase); });
322     }
323     if ((static_cast<int32_t>(testCase.receivedInput) & DRAG_DROP_SPRING_LOADING_DETECTOR_SET_USERCONFIG) != 0) {
324         auto relatedConfigurations = dropFrameNode_->GetOrCreateDragDropRelatedConfigurations();
325         ASSERT_NE(relatedConfigurations, nullptr);
326         machine->SetUserConfig(relatedConfigurations->GetOrCreateDragSpringLoadingConfiguration());
327     }
328     if (testCase.springLoadingMachineTestCase.transitionFailed) {
329         if (testCase.springLoadingMachineTestCase.isAllowedTransition) {
330             machine->stateMachinePool_->states_[DragDropSpringLoadingState::CANCEL].stateHandler = nullptr;
331         } else {
332             if (testCase.springLoadingMachineTestCase.isAllowedTransitionFind) {
333                 machine->stateMachinePool_->states_[testCase.originStatus].transitions.clear();
334             } else {
335                 machine->stateMachinePool_->states_.erase(testCase.originStatus);
336             }
337         }
338     } else {
339         if (testCase.originStatus == DragDropSpringLoadingState::END) {
340             machine->stateMachinePool_->states_[testCase.originStatus].transitions.emplace_back(
341                 DragDropSpringLoadingState::CANCEL);
342         }
343     }
344 }
345 
346 /**
347  * @tc.name: DragSpringLoadingTest001
348  * @tc.desc: Test State Machine RegisterStateHandler
349  * @tc.type: FUNC
350  */
351 HWTEST_F(DragSpringLoadingTestNg, DragSpringLoadingTest001, TestSize.Level1)
352 {
353     ASSERT_NE(detector_, nullptr);
354     auto smPool = detector_->stateMachine_->stateMachinePool_;
355     ASSERT_TRUE(smPool);
356     EXPECT_EQ(smPool->states_.size(), SM_POOL_SIZE);
357 
358     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::IDLE, DragDropSpringLoadingState::BEGIN));
359 
360     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::UPDATE));
361     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::END));
362     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::BEGIN, DragDropSpringLoadingState::CANCEL));
363 
364     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::UPDATE));
365     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::END));
366     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::UPDATE, DragDropSpringLoadingState::CANCEL));
367 
368     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::END, DragDropSpringLoadingState::IDLE));
369 
370     EXPECT_TRUE(smPool->IsAllowedTransition(DragDropSpringLoadingState::CANCEL, DragDropSpringLoadingState::IDLE));
371 }
372 
373 /**
374  * @tc.name: DragSpringLoadingTest002
375  * @tc.desc: Test DragDropSpringLoadingDetector
376  * @tc.type: FUNC
377  */
378 HWTEST_F(DragSpringLoadingTestNg, DragSpringLoadingTest002, TestSize.Level1)
379 {
380     ASSERT_NE(detector_, nullptr);
381     ASSERT_NE(dropFrameNode_, nullptr);
382     ASSERT_NE(dragFrameNode_, nullptr);
383     int32_t caseNum = 0;
384     for (const auto& testCase : DRAG_DROP_SPRING_LOADING_DETECTOR_TEST_CASES) {
385         dropFrameNode_->eventHub_ = AceType::MakeRefPtr<EventHub>();
386         auto machine = detector_->stateMachine_;
387         ASSERT_NE(machine, nullptr);
388         machine->ResetMachine();
389         detector_->ResetState();
390         detector_->preTargetFrameNode_ = nullptr;
391         detector_->preMovePoint_ = Point(0, 0);
392         detector_->preTimeStamp_ = 0;
393         machine->currentState_ = testCase.originStatus;
394         if (testCase.originStatus == DragDropSpringLoadingState::IDLE) {
395             machine->isWaitingForIdleFinish_ = true;
396         }
397         if (testCase.receivedInput == DragDropSpringLoadingReceivedInput::NOTIFY_MOVE) {
398             HandleMoveInput(testCase);
399         } else if (testCase.receivedInput == DragDropSpringLoadingReceivedInput::NOTIFY_INTERCEPT) {
400             HandleNotifyInterceptInput(testCase);
401         } else if (testCase.receivedInput == DragDropSpringLoadingReceivedInput::THRESHOLD) {
402             HandleThresholdInput(testCase);
403         } else if (testCase.receivedInput == DragDropSpringLoadingReceivedInput::INTERCEPT) {
404             if (machine->IsInSpringLoadingState()) {
405                 machine->stateMachinePool_->states_[testCase.originStatus].transitions.clear();
406             }
407             detector_->Intercept(testCase.extraInfo);
408         }
409         EXPECT_TRUE(DragSpringLoadingTestNg::CheckDragDropSpringLoadingStatus(
410             caseNum, machine->currentState_, testCase.expectStatus));
411         EXPECT_TRUE(DragSpringLoadingTestNg::CheckDragDropSpringLoadingNotifySequence(
412             caseNum, machine->GetCurrentNotifySequence(), testCase.notifySequence));
413         caseNum++;
414     }
415 }
416 
417 /**
418  * @tc.name: DragSpringLoadingTest003
419  * @tc.desc: Test DragDropSpringLoadingState Handler
420  * @tc.type: FUNC
421  */
422 HWTEST_F(DragSpringLoadingTestNg, DragSpringLoadingTest003, TestSize.Level1)
423 {
424     ASSERT_NE(dropFrameNode_, nullptr);
425     int32_t caseNum = 0;
426     for (const auto& testCase : DRAG_DROP_SPRING_LOADING_STATE_HANDLER_TEST_CASES) {
427         detector_ = AceType::MakeRefPtr<DragDropSpringLoadingDetector>();
428         auto machine = detector_->stateMachine_;
429         ASSERT_NE(machine, nullptr);
430         machine->ResetMachine();
431         ASSERT_NE(machine->stateMachinePool_, nullptr);
432         detector_->ResetState();
433         detector_->preTargetFrameNode_ = dropFrameNode_;
434         detector_->preMovePoint_ = Point(0, 0);
435         detector_->preTimeStamp_ = 0;
436         machine->currentState_ = testCase.originStatus;
437         dropFrameNode_->eventHub_ = AceType::MakeRefPtr<EventHub>();
438         SetupTestCaseConditions(testCase);
439         auto handler = machine->stateMachinePool_->GetStateHandler(testCase.originStatus);
440         if (testCase.springLoadingMachineTestCase.transitionFailed &&
441             !testCase.springLoadingMachineTestCase.isAllowedTransitionFind) {
442             ASSERT_EQ(handler, nullptr);
443             EXPECT_FALSE(machine->stateMachinePool_->IsAllowedTransition(testCase.originStatus, testCase.expectStatus));
444             caseNum++;
445             continue;
446         }
447         ASSERT_NE(handler, nullptr);
448         handler->OnEnter(testCase.extraInfo);
449         EXPECT_TRUE(DragSpringLoadingTestNg::CheckDragDropSpringLoadingStatus(
450             caseNum, machine->currentState_, testCase.expectStatus));
451         EXPECT_TRUE(DragSpringLoadingTestNg::CheckDragDropSpringLoadingNotifySequence(
452             caseNum, machine->GetCurrentNotifySequence(), testCase.notifySequence));
453         caseNum++;
454     }
455 }
456 
457 /**
458  * @tc.name: DragSpringLoadingTest004
459  * @tc.desc: Test NotifyMove
460  * @tc.type: FUNC
461  */
462  HWTEST_F(DragSpringLoadingTestNg, DragSpringLoadingTest004, TestSize.Level1)
463 {
464     /**
465      * @tc.steps: step1. initialize detector.
466      */
467     ASSERT_NE(detector_, nullptr);
468     ASSERT_NE(dropFrameNode_, nullptr);
469     ASSERT_NE(dragFrameNode_, nullptr);
470     dropFrameNode_->eventHub_ = AceType::MakeRefPtr<EventHub>();
471     auto machine = detector_->stateMachine_;
472     ASSERT_NE(machine, nullptr);
473     machine->ResetMachine();
474     detector_->ResetState();
475     dragFrameNode_->eventHub_ = AceType::MakeRefPtr<EventHub>();
476     detector_->preTargetFrameNode_ = dropFrameNode_;
477     detector_->preMovePoint_ = Point(0, 0);
478     detector_->preTimeStamp_ = 0;
479     machine->currentState_ = DragDropSpringLoadingState::BEGIN;
480 
481     /**
482      * @tc.steps: step2. call NotifyIntercept.
483      */
484     detector_->NotifyIntercept("");
485     EXPECT_EQ(detector_->preTargetFrameNode_, nullptr);
486 
487     detector_->preTargetFrameNode_ = dropFrameNode_;
488     detector_->preTargetFrameNode_->eventHub_->SetCustomerOnDragSpringLoading(
__anond1bfb96f0602(const RefPtr<DragSpringLoadingContext>& info) 489                             [](const RefPtr<DragSpringLoadingContext>& info) { ASSERT_NE(info, nullptr); });
490     machine->stateMachinePool_ = nullptr;
491     detector_->NotifyIntercept("");
492     EXPECT_EQ(machine->currentState_, DragDropSpringLoadingState::IDLE);
493 
494     detector_->preTargetFrameNode_ = dropFrameNode_;
495     machine->isWaitingForIdleFinish_ = true;
496     detector_->NotifyIntercept("");
497     EXPECT_FALSE(machine->isWaitingForIdleFinish_);
498 }
499 } // namespace OHOS::Ace::NG
500