• 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 #ifndef TEST_UNITTEST_CORE_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_TEST_NG_H
17 #define TEST_UNITTEST_CORE_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_TEST_NG_H
18 #include <cstdint>
19 #include <string>
20 
21 #include "gtest/gtest.h"
22 
23 #define private public
24 #define protected public
25 
26 #include "test/mock/base/mock_pixel_map.h"
27 #include "test/mock/core/common/mock_container.h"
28 #include "test/mock/core/common/mock_interaction_interface.h"
29 #include "test/mock/core/common/mock_theme_manager.h"
30 #include "test/mock/core/pipeline/mock_pipeline_context.h"
31 #include "test/mock/core/render/mock_render_context.h"
32 
33 #include "base/memory/ace_type.h"
34 #include "base/memory/referenced.h"
35 #include "core/components/theme/blur_style_theme.h"
36 #include "core/components/theme/shadow_theme.h"
37 #include "core/components_ng/event/drag_drop_event.h"
38 #include "core/components_ng/event/drag_event.h"
39 #include "core/components_ng/event/event_hub.h"
40 #include "core/components_ng/manager/drag_drop/drag_drop_global_controller.h"
41 #include "core/components_ng/manager/drag_drop/drag_drop_initiating/drag_drop_initiating_state_machine.h"
42 #include "core/components_ng/pattern/grid/grid_item_pattern.h"
43 #include "core/components_ng/pattern/grid/grid_pattern.h"
44 #include "core/components_ng/pattern/list/list_item_pattern.h"
45 #include "core/components_ng/pattern/list/list_pattern.h"
46 #include "core/components_ng/pattern/stack/stack_pattern.h"
47 #include "core/components_ng/pattern/text/text_pattern.h"
48 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h"
49 #include "core/event/touch_event.h"
50 
51 namespace OHOS::Ace::NG {
52 constexpr int32_t DEFAULT_DRAG_POINTER_ID = 5;
53 enum class DragDropInitiatingReceivedInput {
54     HandleLongPressOnAction = 1 << 0,
55     HandleLongPressOnActionEnd = 1 << 1,
56     HandleLongPressOnActionCancel = 1 << 2,
57     HandlePreviewLongPressOnAction = 1 << 3,
58     HandlePreviewLongPressOnActionEnd = 1 << 4,
59     HandlePreviewLongPressOnActionCancel = 1 << 5,
60     HandlePanOnActionStart = 1 << 6,
61     HandlePanOnActionUpdate = 1 << 7,
62     HandlePanOnActionEnd = 1 << 8,
63     HandlePanOnActionCancel = 1 << 9,
64     HandlePanOnReject = 1 << 10,
65     HandleSequenceOnActionCancel = 1 << 11,
66     HandleHitTesting = 1 << 12,
67     HandleTouchEvent = 1 << 13,
68     HandlePullEvent = 1 << 14,
69     HandleReStartDrag = 1 << 15,
70     HandleDragStart = 1 << 16,
71     HandleDragEnd = 1 << 17,
72     TransMenuShow = 1 << 18,
73     TransDragWindowToFwk = 1 << 19,
74 };
75 
76 struct DragDropInitiatingStateTestCase {
77     DragDropInitiatingStatus originStatus = DragDropInitiatingStatus::IDLE;
78     DragDropInitiatingReceivedInput receivedInput = DragDropInitiatingReceivedInput::HandleLongPressOnAction;
79     DragDropInitiatingStatus expectStatus = DragDropInitiatingStatus::IDLE;
DragDropInitiatingStateTestCaseDragDropInitiatingStateTestCase80     DragDropInitiatingStateTestCase(DragDropInitiatingStatus originStatus,
81         DragDropInitiatingReceivedInput receivedInput, DragDropInitiatingStatus expectStatus)
82         : originStatus(originStatus), receivedInput(receivedInput), expectStatus(expectStatus)
83     {}
84 };
85 
86 constexpr int32_t DRAG_ACTION_NONE_ARGS = 984064; //0b11110000010000000000
87 constexpr int32_t DRAG_ACTION_DRAG_POINTER_EVENT_ARGS = 16384;
88 constexpr int32_t DRAG_ACTION_TOUCH_EVENT_ARGS = 12288;
89 constexpr int32_t DRAG_ACTION_GESTURE_EVENT_ARGS = 35839;
90 
91 class DragDropInitiatingStateTestNG : public testing::Test {
92 public:
93     static void DoMachineAction(const RefPtr<DragDropInitiatingStateMachine>& machine,
94         DragDropInitiatingReceivedInput receivedInput, const DragPointerEvent& dragPointerEvent);
95     static void DoMachineAction(const RefPtr<DragDropInitiatingStateMachine>& machine,
96         DragDropInitiatingReceivedInput receivedInput, const TouchEvent& touchEvent);
97     static void DoMachineAction(const RefPtr<DragDropInitiatingStateMachine>& machine,
98         DragDropInitiatingReceivedInput receivedInput, const GestureEvent& info);
99     static void DoMachineAction(
100         const RefPtr<DragDropInitiatingStateMachine>& machine, DragDropInitiatingReceivedInput receivedInput);
101     static testing::AssertionResult CheckDragDropInitiatingStatus(
102         int32_t caseNum, DragDropInitiatingStatus dragStatus, DragDropInitiatingStatus expectStatus);
103 };
104 
105 class DragDropInitiatingStateBaseTestNG : public DragDropInitiatingStateTestNG {
106 public:
107     static void SetUpTestCase();
108     static void TearDownTestCase();
109 };
110 
111 class DragDropInitiatingStateIdleTestNG : public DragDropInitiatingStateTestNG {
112 public:
113     static void SetUpTestCase();
114     static void TearDownTestCase();
115 };
116 
117 class DragDropInitiatingStateLiftingTestNG : public DragDropInitiatingStateTestNG {
118 public:
119     static void SetUpTestCase();
120     static void TearDownTestCase();
121 };
122 
123 class DragDropInitiatingStateMachineTestNG : public DragDropInitiatingStateTestNG {
124 public:
125     static void SetUpTestCase();
126     static void TearDownTestCase();
127 };
128 
129 class DragDropInitiatingStateMovingTestNG : public DragDropInitiatingStateTestNG {
130 public:
131     static void SetUpTestCase();
132     static void TearDownTestCase();
133 };
134 
135 class DragDropInitiatingStatePressTestNG : public DragDropInitiatingStateTestNG {
136 public:
137     static void SetUpTestCase();
138     static void TearDownTestCase();
139 };
140 
141 class DragDropInitiatingStateReadyTestNG : public DragDropInitiatingStateTestNG {
142 public:
143     static void SetUpTestCase();
144     static void TearDownTestCase();
145 };
146 
147 class DragDropInitiatingHandlerTestNg : public DragDropInitiatingStateTestNG {
148 public:
149     static void SetUpTestCase();
150     static void TearDownTestCase();
151 };
152 } // namespace OHOS::Ace::NG
153 #endif // TEST_UNITTEST_CORE_MANAGER_DRAG_DROP_DRAG_DROP_INITIATING_TEST_NG_H