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