1 /*
2 * Copyright (C) 2023 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 #include <map>
18 #include <memory>
19 #include "accessibility_common_helper.h"
20 #include "accessibility_screen_touch.h"
21 #include "accessibility_ut_helper.h"
22 #include "accessible_ability_manager_service.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Accessibility {
29 namespace {
30 constexpr uint32_t CLICK_RESPONSE_TIME_LONG = 600; // ms
31 constexpr uint32_t IGNORE_REPEAT_CLICK_TIME_LONGEST = 1300; // ms
32 constexpr uint32_t CLICK_RESPONSE_DELAY_LONG = 2;
33 constexpr uint32_t IGNORE_REPEAT_CLICK_LONGEST = 4;
34 constexpr uint32_t TIMESTAMP_800 = 800;
35 constexpr uint32_t TIMESTAMP_1200 = 1200;
36 constexpr uint32_t TIMESTAMP_1500 = 1500;
37 constexpr uint32_t TIMESTAMP_1600 = 1600;
38 constexpr uint32_t TIMESTAMP_1700 = 1700;
39 constexpr uint32_t TIMESTAMP_2700 = 2700;
40 constexpr uint32_t TIMESTAMP_2800 = 2800;
41 } // namespace
42
43 class AccessibilityScreenTouchUnitTest : public ::testing::Test {
44 public:
AccessibilityScreenTouchUnitTest()45 AccessibilityScreenTouchUnitTest()
46 {}
~AccessibilityScreenTouchUnitTest()47 ~AccessibilityScreenTouchUnitTest()
48 {}
49
50 static void SetUpTestCase();
51 static void TearDownTestCase();
52 void SetUp() override;
53 void TearDown() override;
54 std::shared_ptr<MMI::PointerEvent> SetPointerEvent(uint32_t time, uint32_t action);
55
56 std::shared_ptr<AccessibilityScreenTouch> screenTouch_ = nullptr;
57 };
58
SetUpTestCase()59 void AccessibilityScreenTouchUnitTest::SetUpTestCase()
60 {
61 GTEST_LOG_(INFO) << "###################### AccessibilityScreenTouchUnitTest Start ######################";
62 Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
63 AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
64 }
65
TearDownTestCase()66 void AccessibilityScreenTouchUnitTest::TearDownTestCase()
67 {
68 GTEST_LOG_(INFO) << "###################### AccessibilityScreenTouchUnitTest End ######################";
69 Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
70 }
71
SetUp()72 void AccessibilityScreenTouchUnitTest::SetUp()
73 {
74 GTEST_LOG_(INFO) << "SetUp";
75 }
76
TearDown()77 void AccessibilityScreenTouchUnitTest::TearDown()
78 {
79 GTEST_LOG_(INFO) << "TearDown";
80 }
81
SetPointerEvent(uint32_t time,uint32_t action)82 std::shared_ptr<MMI::PointerEvent> AccessibilityScreenTouchUnitTest::SetPointerEvent(uint32_t time, uint32_t action)
83 {
84 std::shared_ptr<MMI::PointerEvent> event = MMI::PointerEvent::Create();
85 event->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
86 event->SetPointerAction(action);
87 event->SetPointerId(0);
88 MMI::PointerEvent::PointerItem item;
89 item.SetPointerId(0);
90 event->AddPointerItem(item);
91 event->SetActionTime(time);
92 return event;
93 }
94
95 /**
96 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_001
97 * @tc.name: OnPointerEvent
98 * @tc.desc: Test function OnPointerEvent
99 */
100 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_001, TestSize.Level1)
101 {
102 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_001 start";
103 sptr<AccessibilityAccountData> accountData =
104 Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
105 if (!accountData) {
106 GTEST_LOG_(INFO) << "accountData is nullptr";
107 return;
108 }
109
110 accountData->GetConfig()->SetClickResponseTime(CLICK_RESPONSE_DELAY_LONG);
111 accountData->GetConfig()->SetIgnoreRepeatClickState(true);
112 accountData->GetConfig()->SetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_LONGEST);
113 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
114
115 EXPECT_EQ(screenTouch_->GetRealClickResponseTime(), CLICK_RESPONSE_TIME_LONG);
116 EXPECT_EQ(screenTouch_->GetRealIgnoreRepeatClickTime(), IGNORE_REPEAT_CLICK_TIME_LONGEST);
117 EXPECT_EQ(screenTouch_->GetRealIgnoreRepeatClickState(), true);
118 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_001 end";
119 }
120
121 /**
122 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_002
123 * @tc.name: OnPointerEvent
124 * @tc.desc: Test function OnPointerEvent
125 */
126 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_002, TestSize.Level1)
127 {
128 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_002 start";
129 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
130 std::shared_ptr<MMI::PointerEvent> event = MMI::PointerEvent::Create();
131 if (screenTouch_ == nullptr || event == nullptr) {
132 GTEST_LOG_(INFO) << "null pointer";
133 }
134
135 event->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
136 EXPECT_EQ(screenTouch_->OnPointerEvent(*event), false);
137 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_002 end";
138 }
139
140 /**
141 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_003
142 * @tc.name: OnPointerEvent
143 * @tc.desc: Test function OnPointerEvent
144 */
145 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_003, TestSize.Level1)
146 {
147 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_003 start";
148 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
149 std::shared_ptr<MMI::PointerEvent> event = MMI::PointerEvent::Create();
150 if (screenTouch_ == nullptr || event == nullptr) {
151 GTEST_LOG_(INFO) << "null pointer";
152 }
153
154 event->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
155 event->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
156
157 EXPECT_EQ(screenTouch_->OnPointerEvent(*event), true);
158 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_003 end.";
159 }
160
161 /**
162 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_004
163 * @tc.name: OnPointerEvent
164 * @tc.desc: Test function OnPointerEvent
165 */
166 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_004, TestSize.Level1)
167 {
168 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_004 start";
169 sptr<AccessibilityAccountData> accountData =
170 Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
171 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
172 if (accountData == nullptr || screenTouch_ == nullptr) {
173 return;
174 }
175
176 accountData->GetConfig()->SetClickResponseTime(0);
177 accountData->GetConfig()->SetIgnoreRepeatClickState(true);
178 accountData->GetConfig()->SetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_LONGEST);
179
180 auto eventDown = SetPointerEvent(TIMESTAMP_1500, MMI::PointerEvent::POINTER_ACTION_DOWN);
181 screenTouch_->OnPointerEvent(*eventDown);
182
183 auto eventMove = SetPointerEvent(TIMESTAMP_1600, MMI::PointerEvent::POINTER_ACTION_MOVE);
184 screenTouch_->OnPointerEvent(*eventMove);
185
186 auto eventUp = SetPointerEvent(TIMESTAMP_1700, MMI::PointerEvent::POINTER_ACTION_UP);
187 EXPECT_EQ(screenTouch_->OnPointerEvent(*eventUp), true);
188 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_004 end";
189 }
190
191 /**
192 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_005
193 * @tc.name: OnPointerEvent
194 * @tc.desc: Test function OnPointerEvent
195 */
196 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_005, TestSize.Level1)
197 {
198 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_005 start";
199 sptr<AccessibilityAccountData> accountData =
200 Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
201 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
202 if (accountData == nullptr || screenTouch_ == nullptr) {
203 return;
204 }
205
206 accountData->GetConfig()->SetClickResponseTime(0);
207 accountData->GetConfig()->SetIgnoreRepeatClickState(true);
208 accountData->GetConfig()->SetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_LONGEST);
209
210 auto eventDown = SetPointerEvent(TIMESTAMP_1200, MMI::PointerEvent::POINTER_ACTION_DOWN);
211 screenTouch_->OnPointerEvent(*eventDown);
212
213 auto eventMove = SetPointerEvent(TIMESTAMP_1600, MMI::PointerEvent::POINTER_ACTION_MOVE);
214 screenTouch_->OnPointerEvent(*eventMove);
215
216 auto eventUp = SetPointerEvent(TIMESTAMP_1700, MMI::PointerEvent::POINTER_ACTION_UP);
217 EXPECT_EQ(screenTouch_->OnPointerEvent(*eventUp), true);
218 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_005 end";
219 }
220
221 /**
222 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_006
223 * @tc.name: OnPointerEvent
224 * @tc.desc: Test function OnPointerEvent
225 */
226 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_006, TestSize.Level1)
227 {
228 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_006 start";
229 sptr<AccessibilityAccountData> accountData =
230 Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
231 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
232 if (accountData == nullptr || screenTouch_ == nullptr) {
233 return;
234 }
235
236 accountData->GetConfig()->SetClickResponseTime(CLICK_RESPONSE_DELAY_LONG);
237 accountData->GetConfig()->SetIgnoreRepeatClickState(false);
238 accountData->GetConfig()->SetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_LONGEST);
239
240 auto eventDown = SetPointerEvent(0, MMI::PointerEvent::POINTER_ACTION_DOWN);
241 screenTouch_->OnPointerEvent(*eventDown);
242
243 auto eventMove1 = SetPointerEvent(TIMESTAMP_800, MMI::PointerEvent::POINTER_ACTION_MOVE);
244 screenTouch_->OnPointerEvent(*eventMove1);
245
246 auto eventMove2 = SetPointerEvent(TIMESTAMP_1600, MMI::PointerEvent::POINTER_ACTION_MOVE);
247 screenTouch_->OnPointerEvent(*eventMove2);
248
249 auto eventUp = SetPointerEvent(TIMESTAMP_1700, MMI::PointerEvent::POINTER_ACTION_UP);
250 EXPECT_EQ(screenTouch_->OnPointerEvent(*eventUp), true);
251 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_006 end";
252 }
253
254 /**
255 * @tc.number: AccessibilityScreenTouch_Unittest_OnPointerEvent_007
256 * @tc.name: OnPointerEvent
257 * @tc.desc: Test function OnPointerEvent
258 */
259 HWTEST_F(AccessibilityScreenTouchUnitTest, AccessibilityScreenTouch_Unittest_OnPointerEvent_007, TestSize.Level1)
260 {
261 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_007 start";
262 sptr<AccessibilityAccountData> accountData =
263 Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
264 screenTouch_ = std::make_shared<AccessibilityScreenTouch>();
265 if (accountData == nullptr || screenTouch_ == nullptr) {
266 GTEST_LOG_(INFO) << "accountData is nullptr or screenTouch_ is nullptr";
267 return;
268 }
269
270 accountData->GetConfig()->SetClickResponseTime(CLICK_RESPONSE_DELAY_LONG);
271 accountData->GetConfig()->SetIgnoreRepeatClickState(true);
272 accountData->GetConfig()->SetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_LONGEST);
273
274 auto eventDown = SetPointerEvent(TIMESTAMP_1600, MMI::PointerEvent::POINTER_ACTION_DOWN);
275 screenTouch_->OnPointerEvent(*eventDown);
276
277 auto eventMove1 = SetPointerEvent(TIMESTAMP_1700, MMI::PointerEvent::POINTER_ACTION_MOVE);
278 screenTouch_->OnPointerEvent(*eventMove1);
279
280 auto eventMove2 = SetPointerEvent(TIMESTAMP_2700, MMI::PointerEvent::POINTER_ACTION_MOVE);
281 screenTouch_->OnPointerEvent(*eventMove2);
282
283 auto eventUp = SetPointerEvent(TIMESTAMP_2800, MMI::PointerEvent::POINTER_ACTION_UP);
284 EXPECT_EQ(screenTouch_->OnPointerEvent(*eventUp), true);
285 GTEST_LOG_(INFO) << "AccessibilityScreenTouch_Unittest_OnPointerEvent_007 end";
286 }
287 } // namespace Accessibility
288 } // namespace OHOS