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 <optional>
17
18 #include "gtest/gtest.h"
19
20 #include "base/utils/time_util.h"
21 #include "core/event/touch_event.h"
22 #define private public
23 #define protected public
24
25 #include "test/mock/core/pipeline/mock_pipeline_context.h"
26 #include "test/mock/core/render/mock_render_context.h"
27
28 #include "base/memory/ace_type.h"
29 #include "base/memory/referenced.h"
30 #include "core/components_ng/base/frame_node.h"
31 #include "core/components_ng/gestures/tap_gesture.h"
32 #include "core/components_ng/manager/post_event/post_event_manager.h"
33 #include "core/components_ng/pattern/pattern.h"
34
35 using namespace testing;
36 using namespace testing::ext;
37
38 namespace OHOS::Ace::NG {
39 namespace {
40 const std::string ROOT_TAG("root");
41 } // namespace
42
43 class PostEventManagerTestNg : public testing::Test {
44 public:
45 static void SetUpTestSuite();
46 static void TearDownTestSuite();
47 RefPtr<PostEventManager> postEventManager_;
48 RefPtr<FrameNode> root_;
49 void Init();
50 };
51
SetUpTestSuite()52 void PostEventManagerTestNg::SetUpTestSuite()
53 {
54 MockPipelineContext::SetUp();
55 }
56
TearDownTestSuite()57 void PostEventManagerTestNg::TearDownTestSuite()
58 {
59 MockPipelineContext::TearDown();
60 }
61
Init()62 void PostEventManagerTestNg::Init()
63 {
64 postEventManager_ = AceType::MakeRefPtr<PostEventManager>();
65 ASSERT_NE(postEventManager_, nullptr);
66 root_ = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
67 root_->SetExclusiveEventForChild(true);
68 auto mockRenderContext = AceType::MakeRefPtr<MockRenderContext>();
69 root_->renderContext_ = mockRenderContext;
70 auto localPoint = PointF(10, 10);
71 mockRenderContext->rect_ = RectF(0, 0, 100, 100);
72 root_->SetActive(true);
73 }
74
75 /**
76 * @tc.name: PostEventManagerTest001
77 * @tc.desc: test post event.
78 * @tc.type: FUNC
79 */
80 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest001, TestSize.Level1)
81 {
82 /**
83 * @tc.steps: step1. construct a FrameNode and set gesture.
84 */
85 Init();
86 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
87 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
88 auto gesture = AceType::MakeRefPtr<TapGesture>();
89 gestureEventHub->AddGesture(gesture);
90 DimensionRect responseRect(Dimension(100), Dimension(100), DimensionOffset());
91 std::vector<DimensionRect> responseRegion;
92 responseRegion.emplace_back(responseRect);
93 gestureEventHub->SetResponseRegion(responseRegion);
94 auto paintRect = root_->renderContext_->GetPaintRectWithoutTransform();
95 root_->GetResponseRegionList(paintRect, 1);
96 EXPECT_FALSE(gestureEventHub->GetResponseRegion().empty());
97
98 /**
99 * @tc.steps: step2. call PostEvent func and check return value.
100 */
101 TouchEvent touchEvent;
102 touchEvent.type = TouchType::DOWN;
103 touchEvent.x = 10;
104 touchEvent.y = 10;
105 auto result = postEventManager_->PostEvent(root_, touchEvent);
106 EXPECT_FALSE(result);
107
108 /**
109 * @tc.steps: step3. call PostEvent func with same event and check return value.
110 */
111 result = postEventManager_->PostEvent(root_, touchEvent);
112 EXPECT_EQ(result, false);
113
114 /**
115 * @tc.steps: step4. call PostEvent func with touch up event and check return value.
116 */
117 TouchEvent touchMoveEvent;
118 touchMoveEvent.type = TouchType::MOVE;
119 touchMoveEvent.x = 15;
120 touchMoveEvent.y = 15;
121 auto currentTime = GetSysTimestamp();
122 std::chrono::nanoseconds nanoseconds(currentTime);
123 TimeStamp time(nanoseconds);
124 touchMoveEvent.time = time;
125 result = postEventManager_->PostEvent(root_, touchMoveEvent);
126 EXPECT_FALSE(result);
127
128 /**
129 * @tc.steps: step5. call PostEvent func with touch up event and check return value.
130 */
131 TouchEvent touchUpEvent;
132 touchUpEvent.type = TouchType::UP;
133 touchUpEvent.x = 15;
134 touchUpEvent.y = 15;
135 currentTime = GetSysTimestamp();
136 std::chrono::nanoseconds nanosecondsUp(currentTime);
137 TimeStamp timeUp(nanosecondsUp);
138 touchUpEvent.time = timeUp;
139 result = postEventManager_->PostEvent(root_, touchUpEvent);
140 EXPECT_FALSE(result);
141 }
142
143 /**
144 * @tc.name: PostEventManagerTest002
145 * @tc.desc: test post touch down type event twice.
146 * @tc.type: FUNC
147 */
148 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest002, TestSize.Level1)
149 {
150 /**
151 * @tc.steps: step1. construct a FrameNode and set gesture.
152 */
153 Init();
154 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
155 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
156 auto gesture = AceType::MakeRefPtr<TapGesture>();
157 gestureEventHub->AddGesture(gesture);
158 DimensionRect responseRect(Dimension(100), Dimension(100), DimensionOffset());
159 std::vector<DimensionRect> responseRegion;
160 responseRegion.emplace_back(responseRect);
161 gestureEventHub->SetResponseRegion(responseRegion);
162 auto paintRect = root_->renderContext_->GetPaintRectWithoutTransform();
163 root_->GetResponseRegionList(paintRect, 1);
164 EXPECT_FALSE(gestureEventHub->GetResponseRegion().empty());
165
166 /**
167 * @tc.steps: step2. call PostEvent func and check return value.
168 */
169 TouchEvent touchEvent;
170 touchEvent.type = TouchType::DOWN;
171 touchEvent.x = 10;
172 touchEvent.y = 10;
173 auto result = postEventManager_->PostEvent(root_, touchEvent);
174 EXPECT_FALSE(result);
175
176 /**
177 * @tc.steps: step3. call PostEvent func with another down event check whether cancel event will be sent or not.
178 */
179 TouchEvent touchMoveEvent;
180 touchMoveEvent.type = TouchType::DOWN;
181 touchMoveEvent.x = 15;
182 touchMoveEvent.y = 15;
183 auto currentTime = GetSysTimestamp();
184 std::chrono::nanoseconds nanoseconds(currentTime);
185 TimeStamp time(nanoseconds);
186 touchMoveEvent.time = time;
187 result = postEventManager_->PostEvent(root_, touchMoveEvent);
188 EXPECT_FALSE(result);
189 }
190
191 /**
192 * @tc.name: PostEventManagerTest003
193 * @tc.desc: test post event when touch test result is null.
194 * @tc.type: FUNC
195 */
196 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest003, TestSize.Level1)
197 {
198 /**
199 * @tc.steps: step1. construct a FrameNode and set gesture.
200 */
201 Init();
202 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
203 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
204 auto gesture = AceType::MakeRefPtr<TapGesture>();
205 gestureEventHub->AddGesture(gesture);
206
207 /**
208 * @tc.steps: step2. call PostEvent func when touch test result is null.
209 */
210 TouchEvent touchEvent;
211 touchEvent.type = TouchType::DOWN;
212 touchEvent.x = 10;
213 touchEvent.y = 10;
214 auto result = postEventManager_->PostEvent(root_, touchEvent);
215 EXPECT_EQ(result, false);
216 }
217
218 /**
219 * @tc.name: PostEventManagerTest004
220 * @tc.desc: test post touch event event but has no down event.
221 * @tc.type: FUNC
222 */
223 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest004, TestSize.Level1)
224 {
225 /**
226 * @tc.steps: step1. construct a FrameNode and set gesture.
227 */
228 Init();
229 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
230 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
231 auto gesture = AceType::MakeRefPtr<TapGesture>();
232 gestureEventHub->AddGesture(gesture);
233 DimensionRect responseRect(Dimension(100), Dimension(100), DimensionOffset());
234 std::vector<DimensionRect> responseRegion;
235 responseRegion.emplace_back(responseRect);
236 gestureEventHub->SetResponseRegion(responseRegion);
237 auto paintRect = root_->renderContext_->GetPaintRectWithoutTransform();
238 root_->GetResponseRegionList(paintRect, 1);
239 EXPECT_FALSE(gestureEventHub->GetResponseRegion().empty());
240
241 /**
242 * @tc.steps: step2. call PostEvent func and check return value.
243 */
244 TouchEvent touchEvent;
245 touchEvent.type = TouchType::MOVE;
246 touchEvent.x = 10;
247 touchEvent.y = 10;
248 auto result = postEventManager_->PostEvent(root_, touchEvent);
249 EXPECT_EQ(result, false);
250 }
251
252 /**
253 * @tc.name: PostEventManagerTest005
254 * @tc.desc: test multi fingers post event.
255 * @tc.type: FUNC
256 */
257 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest005, TestSize.Level1)
258 {
259 /**
260 * @tc.steps: step1. construct a FrameNode and set gesture.
261 */
262 Init();
263 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
264 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
265 auto gesture = AceType::MakeRefPtr<TapGesture>();
266 gestureEventHub->AddGesture(gesture);
267 DimensionRect responseRect(Dimension(100), Dimension(100), DimensionOffset());
268 std::vector<DimensionRect> responseRegion;
269 responseRegion.emplace_back(responseRect);
270 gestureEventHub->SetResponseRegion(responseRegion);
271 auto paintRect = root_->renderContext_->GetPaintRectWithoutTransform();
272 root_->GetResponseRegionList(paintRect, 1);
273 EXPECT_FALSE(gestureEventHub->GetResponseRegion().empty());
274
275 /**
276 * @tc.steps: step2. call finger 0 PostEvent func and check return value.
277 */
278 TouchEvent touchEvent;
279 touchEvent.type = TouchType::DOWN;
280 touchEvent.x = 10;
281 touchEvent.y = 10;
282 auto result = postEventManager_->PostEvent(root_, touchEvent);
283 EXPECT_FALSE(result);
284
285 /**
286 * @tc.steps: step3. call finger 1 PostEvent func and check return value.
287 */
288 TouchEvent anotherTouchEvent;
289 anotherTouchEvent.type = TouchType::DOWN;
290 anotherTouchEvent.id = 1;
291 anotherTouchEvent.x = 20;
292 anotherTouchEvent.y = 20;
293 result = postEventManager_->PostEvent(root_, anotherTouchEvent);
294 EXPECT_FALSE(result);
295
296 /**
297 * @tc.steps: step3. call PostEvent func with touch up event and check return value.
298 */
299 TouchEvent touchMoveEvent;
300 touchMoveEvent.type = TouchType::MOVE;
301 touchMoveEvent.x = 15;
302 touchMoveEvent.y = 15;
303 auto currentTime = GetSysTimestamp();
304 std::chrono::nanoseconds nanoseconds(currentTime);
305 TimeStamp time(nanoseconds);
306 touchMoveEvent.time = time;
307 result = postEventManager_->PostEvent(root_, touchMoveEvent);
308 EXPECT_FALSE(result);
309
310 /**
311 * @tc.steps: step4. call PostEvent func with touch up event and check return value.
312 */
313 TouchEvent touchUpEvent;
314 touchUpEvent.type = TouchType::UP;
315 touchUpEvent.x = 15;
316 touchUpEvent.y = 15;
317 currentTime = GetSysTimestamp();
318 std::chrono::nanoseconds nanosecondsUp(currentTime);
319 TimeStamp timeUp(nanosecondsUp);
320 touchUpEvent.time = timeUp;
321 result = postEventManager_->PostEvent(root_, touchUpEvent);
322 EXPECT_FALSE(result);
323 }
324
325 /**
326 * @tc.name: PostEventManagerTest006
327 * @tc.desc: test multi fingers post event.
328 * @tc.type: FUNC
329 */
330 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest006, TestSize.Level1)
331 {
332 Init();
333 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
334 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
335 auto gesture = AceType::MakeRefPtr<TapGesture>();
336 gestureEventHub->AddGesture(gesture);
337
338 TouchEvent touchUpEvent;
339 touchUpEvent.type = TouchType::HOVER_ENTER;
340 touchUpEvent.x = 15;
341 touchUpEvent.y = 15;
342 auto currentTime = GetSysTimestamp();
343 std::chrono::nanoseconds nanosecondsUp(currentTime);
344 TimeStamp timeUp(nanosecondsUp);
345 touchUpEvent.time = timeUp;
346 postEventManager_->PostEvent(root_, touchUpEvent);
347 }
348
349 /**
350 * @tc.name: PostEventManagerTest007
351 * @tc.desc: test multi fingers post event.
352 * @tc.type: FUNC
353 */
354 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest007, TestSize.Level1)
355 {
356 Init();
357 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
358 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
359 auto gesture = AceType::MakeRefPtr<TapGesture>();
360 gestureEventHub->AddGesture(gesture);
361
362 TouchEvent touchUpEvent;
363 touchUpEvent.type = TouchType::DOWN;
364 touchUpEvent.x = 15;
365 touchUpEvent.y = 15;
366 touchUpEvent.id = 2;
367 auto currentTime = GetSysTimestamp();
368 std::chrono::nanoseconds nanosecondsUp(currentTime);
369 TimeStamp timeUp(nanosecondsUp);
370 touchUpEvent.time = timeUp;
371 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
372 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
373 PostEventAction eventAction;
374 eventAction.targetNode = UInode;
375 eventAction.touchEvent = touchUpEvent;
376 postEventManager_->postEventAction_.push_back(eventAction);
377 auto result = postEventManager_->PostDownEvent(UInode, touchUpEvent);
378 EXPECT_EQ(result, false);
379 }
380
381 /**
382 * @tc.name: PostEventManagerTest008
383 * @tc.desc: test lastEventMap.
384 * @tc.type: FUNC
385 */
386 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest008, TestSize.Level1)
387 {
388 Init();
389 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
390 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
391 auto gesture = AceType::MakeRefPtr<TapGesture>();
392 gestureEventHub->AddGesture(gesture);
393 TouchEvent touchUpEvent;
394 touchUpEvent.type = TouchType::DOWN;
395 touchUpEvent.x = 15;
396 touchUpEvent.y = 15;
397 touchUpEvent.id = 2;
398 auto currentTime = GetSysTimestamp();
399 std::chrono::nanoseconds nanosecondsUp(currentTime);
400 TimeStamp timeUp(nanosecondsUp);
401 touchUpEvent.time = timeUp;
402 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
403 PostEventAction eventAction;
404 eventAction.targetNode = frameNode;
405 eventAction.touchEvent = touchUpEvent;
406 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
407 postEventManager_->postEventAction_.push_back(eventAction);
408 auto result = postEventManager_->PostDownEvent(root_, touchUpEvent);
409 EXPECT_EQ(result, false);
410 }
411
412 /**
413 * @tc.name: PostEventManagerTest009
414 * @tc.desc: test lastEventMap.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest009, TestSize.Level1)
418 {
419 Init();
420 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
421 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
422 auto gesture = AceType::MakeRefPtr<TapGesture>();
423 gestureEventHub->AddGesture(gesture);
424 TouchEvent touchUpEvent;
425 touchUpEvent.type = TouchType::UP;
426 touchUpEvent.x = 15;
427 touchUpEvent.y = 15;
428 touchUpEvent.id = 2;
429 auto currentTime = GetSysTimestamp();
430 std::chrono::nanoseconds nanosecondsUp(currentTime);
431 TimeStamp timeUp(nanosecondsUp);
432 touchUpEvent.time = timeUp;
433 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
434 PostEventAction eventAction;
435 eventAction.targetNode = frameNode;
436 eventAction.touchEvent = touchUpEvent;
437 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
438 postEventManager_->postEventAction_.push_back(eventAction);
439 auto result = postEventManager_->PostUpEvent(root_, touchUpEvent);
440 EXPECT_EQ(result, false);
441 }
442
443 /**
444 * @tc.name: PostEventManagerTest010
445 * @tc.desc: test lastEventMap.
446 * @tc.type: FUNC
447 */
448 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest0010, TestSize.Level1)
449 {
450 Init();
451 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
452 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
453 auto gesture = AceType::MakeRefPtr<TapGesture>();
454 gestureEventHub->AddGesture(gesture);
455
456 TouchEvent touchUpEvent;
457 touchUpEvent.type = TouchType::DOWN;
458 touchUpEvent.x = 15;
459 touchUpEvent.y = 15;
460 touchUpEvent.id = 2;
461 auto currentTime = GetSysTimestamp();
462 std::chrono::nanoseconds nanosecondsUp(currentTime);
463 TimeStamp timeUp(nanosecondsUp);
464 touchUpEvent.time = timeUp;
465 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
466 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
467 PostEventAction eventAction;
468 eventAction.targetNode = UInode;
469 eventAction.touchEvent = touchUpEvent;
470 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
471 postEventManager_->postEventAction_.push_back(eventAction);
472 auto result = postEventManager_->PostDownEvent(UInode, touchUpEvent);
473 EXPECT_EQ(result, false);
474 }
475
476 /**
477 * @tc.name: PostEventManagerTest011
478 * @tc.desc: test lastEventMap.
479 * @tc.type: FUNC
480 */
481 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest0011, TestSize.Level1)
482 {
483 Init();
484 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
485 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
486 auto gesture = AceType::MakeRefPtr<TapGesture>();
487 gestureEventHub->AddGesture(gesture);
488
489 TouchEvent touchUpEvent;
490 touchUpEvent.type = TouchType::UP;
491 touchUpEvent.x = 15;
492 touchUpEvent.y = 15;
493 touchUpEvent.id = 2;
494 auto currentTime = GetSysTimestamp();
495 std::chrono::nanoseconds nanosecondsUp(currentTime);
496 TimeStamp timeUp(nanosecondsUp);
497 touchUpEvent.time = timeUp;
498 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
499 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
500 PostEventAction eventAction;
501 eventAction.targetNode = UInode;
502 eventAction.touchEvent = touchUpEvent;
503 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
504 postEventManager_->postEventAction_.push_back(eventAction);
505 auto result = postEventManager_->PostDownEvent(UInode, touchUpEvent);
506 EXPECT_EQ(result, false);
507 }
508
509 /**
510 * @tc.name: PostEventManagerTest012
511 * @tc.desc: test lastEventMap.
512 * @tc.type: FUNC
513 */
514 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest0012, TestSize.Level1)
515 {
516 Init();
517 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
518 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
519 auto gesture = AceType::MakeRefPtr<TapGesture>();
520 gestureEventHub->AddGesture(gesture);
521
522 TouchEvent touchUpEvent;
523 touchUpEvent.type = TouchType::DOWN;
524 touchUpEvent.x = 15;
525 touchUpEvent.y = 15;
526 touchUpEvent.id = 2;
527 auto currentTime = GetSysTimestamp();
528 std::chrono::nanoseconds nanosecondsUp(currentTime);
529 TimeStamp timeUp(nanosecondsUp);
530 touchUpEvent.time = timeUp;
531 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
532 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
533 PostEventAction eventAction;
534 eventAction.targetNode = UInode;
535 eventAction.touchEvent = touchUpEvent;
536 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
537 postEventManager_->postEventAction_.push_back(eventAction);
538 auto result = postEventManager_->PostDownEvent(UInode, touchUpEvent);
539 EXPECT_EQ(result, false);
540 }
541
542 /**
543 * @tc.name: PostEventManagerTest013
544 * @tc.desc: test lastEventMap.
545 * @tc.type: FUNC
546 */
547 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest0013, TestSize.Level1)
548 {
549 Init();
550 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
551 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
552 auto gesture = AceType::MakeRefPtr<TapGesture>();
553 gestureEventHub->AddGesture(gesture);
554
555 TouchEvent touchUpEvent;
556 touchUpEvent.type = TouchType::DOWN;
557 touchUpEvent.x = 15;
558 touchUpEvent.y = 15;
559 touchUpEvent.id = 2;
560 auto currentTime = GetSysTimestamp();
561 std::chrono::nanoseconds nanosecondsUp(currentTime);
562 TimeStamp timeUp(nanosecondsUp);
563 touchUpEvent.time = timeUp;
564 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
565 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
566 PostEventAction eventAction;
567 eventAction.targetNode = UInode;
568 eventAction.touchEvent = touchUpEvent;
569 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
570 postEventManager_->postEventAction_.push_back(eventAction);
571 auto result = postEventManager_->PostMoveEvent(UInode, touchUpEvent);
572 EXPECT_EQ(result, true);
573 }
574
575 /**
576 * @tc.name: PostEventManagerTest014
577 * @tc.desc: test lastEventMap.
578 * @tc.type: FUNC
579 */
580 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest014, TestSize.Level1)
581 {
582 Init();
583 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
584 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
585 auto gesture = AceType::MakeRefPtr<TapGesture>();
586 gestureEventHub->AddGesture(gesture);
587
588 TouchEvent touchUpEvent;
589 touchUpEvent.type = TouchType::DOWN;
590 touchUpEvent.x = 15;
591 touchUpEvent.y = 15;
592 touchUpEvent.id = 2;
593 auto currentTime = GetSysTimestamp();
594 std::chrono::nanoseconds nanosecondsUp(currentTime);
595 TimeStamp timeUp(nanosecondsUp);
596 touchUpEvent.time = timeUp;
597 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
598 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
599 PostEventAction eventAction;
600 eventAction.targetNode = UInode;
601 eventAction.touchEvent = touchUpEvent;
602 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
603 postEventManager_->postEventAction_.push_back(eventAction);
604 auto result = postEventManager_->PostUpEvent(UInode, touchUpEvent);
605 EXPECT_EQ(result, true);
606 }
607
608 /**
609 * @tc.name: PostEventManagerTest015
610 * @tc.desc: test lastEventMap.
611 * @tc.type: FUNC
612 */
613 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest015, TestSize.Level1)
614 {
615 Init();
616 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
617 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
618 auto gesture = AceType::MakeRefPtr<TapGesture>();
619 gestureEventHub->AddGesture(gesture);
620
621 TouchEvent touchUpEvent;
622 touchUpEvent.type = TouchType::DOWN;
623 touchUpEvent.x = 15;
624 touchUpEvent.y = 15;
625 touchUpEvent.id = 2;
626 auto currentTime = GetSysTimestamp();
627 std::chrono::nanoseconds nanosecondsUp(currentTime);
628 TimeStamp timeUp(nanosecondsUp);
629 touchUpEvent.time = timeUp;
630 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
631 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
632 PostEventAction eventAction;
633 eventAction.targetNode = UInode;
634 eventAction.touchEvent = touchUpEvent;
635 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
636 postEventManager_->postEventAction_.push_back(eventAction);
637 postEventManager_->CheckAndClearPostEventAction(UInode, touchUpEvent.id);
638 postEventManager_->CheckAndClearPostEventAction(UInode, (touchUpEvent.id + 1));
639 postEventManager_->CheckAndClearPostEventAction(UInode, touchUpEvent.id);
640 EXPECT_EQ(touchUpEvent.id, 2);
641 }
642
643 /**
644 * @tc.name: PostEventManagerTest016
645 * @tc.desc: test lastEventMap.
646 * @tc.type: FUNC
647 */
648 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest016, TestSize.Level1)
649 {
650 Init();
651 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
652 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
653 auto gesture = AceType::MakeRefPtr<TapGesture>();
654 gestureEventHub->AddGesture(gesture);
655
656 TouchEvent touchUpEvent;
657 touchUpEvent.type = TouchType::UP;
658 touchUpEvent.x = 15;
659 touchUpEvent.y = 15;
660 touchUpEvent.id = 2;
661 auto currentTime = GetSysTimestamp();
662 std::chrono::nanoseconds nanosecondsUp(currentTime);
663 TimeStamp timeUp(nanosecondsUp);
664 touchUpEvent.time = timeUp;
665 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
666 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
667 PostEventAction eventAction;
668 eventAction.targetNode = UInode;
669 eventAction.touchEvent = touchUpEvent;
670 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
671 postEventManager_->postEventAction_.push_back(eventAction);
672 postEventManager_->CheckAndClearPostEventAction(UInode, touchUpEvent.id);
673 EXPECT_EQ(touchUpEvent.y, 15);
674 }
675
676 /**
677 * @tc.name: PostEventManagerTest017
678 * @tc.desc: test lastEventMap.
679 * @tc.type: FUNC
680 */
681 HWTEST_F(PostEventManagerTestNg, PostEventManagerTest017, TestSize.Level1)
682 {
683 Init();
684 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
685 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
686 auto gesture = AceType::MakeRefPtr<TapGesture>();
687 gestureEventHub->AddGesture(gesture);
688
689 TouchEvent touchUpEvent;
690 touchUpEvent.type = TouchType::CANCEL;
691 touchUpEvent.x = 15;
692 touchUpEvent.y = 15;
693 touchUpEvent.id = 2;
694 auto currentTime = GetSysTimestamp();
695 std::chrono::nanoseconds nanosecondsUp(currentTime);
696 TimeStamp timeUp(nanosecondsUp);
697 touchUpEvent.time = timeUp;
698 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
699 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
700 PostEventAction eventAction;
701 eventAction.targetNode = UInode;
702 eventAction.touchEvent = touchUpEvent;
703 postEventManager_->lastEventMap_.insert(std::make_pair(touchUpEvent.id, eventAction));
704 postEventManager_->postEventAction_.push_back(eventAction);
705 postEventManager_->CheckAndClearPostEventAction(UInode, touchUpEvent.id);
706 EXPECT_EQ(touchUpEvent.x, 15);
707 }
708
709 /**
710 * @tc.name: HandlePostEventTest001
711 * @tc.desc: test HandlePostEvent func.
712 * @tc.type: FUNC
713 */
714 HWTEST_F(PostEventManagerTestNg, HandlePostEventTest001, TestSize.Level1)
715 {
716 /**
717 * @tc.steps: step1. construct a FrameNode and set gesture.
718 */
719 Init();
720
721 /**
722 * @tc.steps: step2. mock user touch event.
723 */
724 auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 1,
__anonda29c8ce0202() 725 []() { return AceType::MakeRefPtr<Pattern>(); });
726 TouchEvent touchEvent;
727
728 const std::vector<Ace::TouchType> touchTypeArray = { Ace::TouchType::DOWN, Ace::TouchType::UP };
729 int32_t touchStateCount = 4;
730 for (int32_t i = 0; i < touchStateCount; ++i) {
731 int32_t index = i % touchTypeArray.size();
732 touchEvent.type = touchTypeArray[index];
733 touchEvent.id = touchTypeArray.size() > 0 ? i / touchTypeArray.size() : i;
734 postEventManager_->HandlePostEvent(buttonNode, touchEvent);
735 }
736 EXPECT_TRUE(postEventManager_->lastEventMap_.empty());
737 }
738
739 /**
740 * @tc.name: PostDownEventTest001
741 * @tc.desc: test PostDownEvent func.
742 * @tc.type: FUNC
743 */
744 HWTEST_F(PostEventManagerTestNg, PostDownEventTest001, TestSize.Level1)
745 {
746 /**
747 * @tc.steps: step1. construct a FrameNode and set gesture.
748 */
749 Init();
750
751 /**
752 * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand
753 * action event through the PostDownEvent function.
754 */
755 int32_t nodeId = 1;
756 auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, nodeId,
__anonda29c8ce0302() 757 []() { return AceType::MakeRefPtr<Pattern>(); });
758 TouchEvent touchEvent;
759 touchEvent.type = Ace::TouchType::DOWN;
760 touchEvent.id = nodeId;
761 postEventManager_->HandlePostEvent(buttonNode, touchEvent);
762
763 postEventManager_->PostDownEvent(buttonNode, touchEvent);
764 EXPECT_TRUE(postEventManager_->postEventAction_.empty());
765 EXPECT_TRUE(postEventManager_->lastEventMap_.empty());
766 }
767
768 /**
769 * @tc.name: PostTouchEventTest001
770 * @tc.desc: test PostTouchEvent func.
771 * @tc.type: FUNC
772 */
773 HWTEST_F(PostEventManagerTestNg, PostTouchEventTest001, TestSize.Level1)
774 {
775 /**
776 * @tc.steps: step1. construct a FrameNode and set gesture.
777 */
778 Init();
779
780 /**
781 * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand
782 * action event through the PostDownEvent function.
783 */
784 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
785 auto uiNode = AceType::DynamicCast<NG::UINode>(frameNode);
786 TouchEvent touchEvent;
787 touchEvent.type = Ace::TouchType::DOWN;
788 postEventManager_->passThroughResult_ = true;
789 postEventManager_->PostTouchEvent(uiNode, std::move(touchEvent));
790
791 EXPECT_FALSE(postEventManager_->passThroughResult_);
792 }
793
794 /**
795 * @tc.name: PostTouchEventTest002
796 * @tc.desc: test PostTouchEvent func.
797 * @tc.type: FUNC
798 */
799 HWTEST_F(PostEventManagerTestNg, PostTouchEventTest002, TestSize.Level1)
800 {
801 /**
802 * @tc.steps: step1. construct a FrameNode and set gesture.
803 */
804 Init();
805
806 /**
807 * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand
808 * action event through the PostDownEvent function.
809 */
810 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
811 auto uiNode = AceType::DynamicCast<NG::UINode>(frameNode);
812 TouchEvent touchEvent;
813 touchEvent.type = Ace::TouchType::DOWN;
814 postEventManager_->passThroughResult_ = true;
815 auto pipelineContext = PipelineContext::GetCurrentContextSafelyWithCheck();
816 ASSERT_NE(pipelineContext, nullptr);
817 pipelineContext->eventManager_ = AceType::MakeRefPtr<EventManager>();
818 ASSERT_NE(pipelineContext->eventManager_, nullptr);
819 pipelineContext->eventManager_->isDragCancelPending_ = false;
820 postEventManager_->PostTouchEvent(uiNode, std::move(touchEvent));
821 EXPECT_FALSE(postEventManager_->passThroughResult_);
822 pipelineContext->eventManager_->isDragCancelPending_ = true;
823 postEventManager_->PostTouchEvent(uiNode, std::move(touchEvent));
824 EXPECT_FALSE(postEventManager_->passThroughResult_);
825 }
826
827 /**
828 * @tc.name: PostMouseEventTest001
829 * @tc.desc: test PostMouseEvent func.
830 * @tc.type: FUNC
831 */
832 HWTEST_F(PostEventManagerTestNg, PostMouseEventTest001, TestSize.Level1)
833 {
834 /**
835 * @tc.steps: step1. construct a FrameNode and set gesture.
836 */
837 Init();
838
839 /**
840 * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand
841 * action event through the PostDownEvent function.
842 */
843 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
844 auto uiNode = AceType::DynamicCast<NG::UINode>(frameNode);
845 MouseEvent mouseEvent;
846 postEventManager_->passThroughResult_ = true;
847 postEventManager_->PostMouseEvent(uiNode, std::move(mouseEvent));
848
849 EXPECT_FALSE(postEventManager_->passThroughResult_);
850 }
851
852 /**
853 * @tc.name: PostAxisEventTest001
854 * @tc.desc: test PostAxisEvent func.
855 * @tc.type: FUNC
856 */
857 HWTEST_F(PostEventManagerTestNg, PostAxisEventTest001, TestSize.Level1)
858 {
859 /**
860 * @tc.steps: step1. construct a FrameNode and set gesture.
861 */
862 Init();
863
864 /**
865 * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand
866 * action event through the PostDownEvent function.
867 */
868 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
869 auto uiNode = AceType::DynamicCast<NG::UINode>(frameNode);
870 AxisEvent axisEvent;
871 postEventManager_->passThroughResult_ = true;
872 postEventManager_->PostAxisEvent(uiNode, std::move(axisEvent));
873
874 EXPECT_FALSE(postEventManager_->passThroughResult_);
875 }
876
877 /**
878 * @tc.name: CheckTouchEventTest001
879 * @tc.desc: test CheckTouchEvent.
880 * @tc.type: FUNC
881 */
882 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest001, TestSize.Level1)
883 {
884 Init();
885 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
886 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
887 auto gesture = AceType::MakeRefPtr<TapGesture>();
888 gestureEventHub->AddGesture(gesture);
889
890 TouchEvent touchUpEvent;
891 touchUpEvent.type = TouchType::DOWN;
892 touchUpEvent.x = 15;
893 touchUpEvent.y = 15;
894 touchUpEvent.id = 2;
895 auto currentTime = GetSysTimestamp();
896 std::chrono::nanoseconds nanosecondsUp(currentTime);
897 TimeStamp timeUp(nanosecondsUp);
898 touchUpEvent.time = timeUp;
899 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
900 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
901 PostEventAction eventAction;
902 eventAction.targetNode = UInode;
903 eventAction.touchEvent = touchUpEvent;
904 postEventManager_->postInputEventAction_.clear();
905 auto result = postEventManager_->CheckTouchEvent(UInode, touchUpEvent);
906 EXPECT_TRUE(result);
907 }
908
909 /**
910 * @tc.name: CheckTouchEventTest002
911 * @tc.desc: test CheckTouchEvent.
912 * @tc.type: FUNC
913 */
914 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest002, TestSize.Level1)
915 {
916 Init();
917 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
918 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
919 auto gesture = AceType::MakeRefPtr<TapGesture>();
920 gestureEventHub->AddGesture(gesture);
921
922 TouchEvent touchUpEvent;
923 touchUpEvent.type = TouchType::DOWN;
924 touchUpEvent.x = 15;
925 touchUpEvent.y = 15;
926 touchUpEvent.id = 2;
927 auto currentTime = GetSysTimestamp();
928 std::chrono::nanoseconds nanosecondsUp(currentTime);
929 TimeStamp timeUp(nanosecondsUp);
930 touchUpEvent.time = timeUp;
931 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
932 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
933 PostEventAction eventAction;
934 eventAction.targetNode = UInode;
935 eventAction.touchEvent = touchUpEvent;
936 postEventManager_->postInputEventAction_.push_back(eventAction);
937 auto result = postEventManager_->CheckTouchEvent(UInode, touchUpEvent);
938 EXPECT_FALSE(result);
939 }
940
941 /**
942 * @tc.name: CheckTouchEventTest003
943 * @tc.desc: test CheckTouchEvent.
944 * @tc.type: FUNC
945 */
946 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest003, TestSize.Level1)
947 {
948 Init();
949 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
950 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
951 auto gesture = AceType::MakeRefPtr<TapGesture>();
952 gestureEventHub->AddGesture(gesture);
953
954 TouchEvent firstTouchEvent;
955 firstTouchEvent.type = TouchType::DOWN;
956 firstTouchEvent.x = 15;
957 firstTouchEvent.y = 15;
958 firstTouchEvent.id = 2;
959 TouchEvent secondTouchEvent;
960 secondTouchEvent.type = TouchType::DOWN;
961 secondTouchEvent.x = 15;
962 secondTouchEvent.y = 15;
963 secondTouchEvent.id = 2;
964 auto currentTime = GetSysTimestamp();
965 std::chrono::nanoseconds nanosecondsUp(currentTime);
966 TimeStamp timeUp(nanosecondsUp);
967 firstTouchEvent.time = timeUp;
968 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
969 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
970 PostEventAction eventAction;
971 eventAction.targetNode = UInode;
972 eventAction.touchEvent = firstTouchEvent;
973 postEventManager_->postInputEventAction_.push_back(eventAction);
974 auto result = postEventManager_->CheckTouchEvent(UInode, secondTouchEvent);
975 EXPECT_FALSE(result);
976 }
977
978 /**
979 * @tc.name: CheckTouchEventTest004
980 * @tc.desc: test CheckTouchEvent.
981 * @tc.type: FUNC
982 */
983 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest004, TestSize.Level1)
984 {
985 Init();
986 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
987 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
988 auto gesture = AceType::MakeRefPtr<TapGesture>();
989 gestureEventHub->AddGesture(gesture);
990
991 TouchEvent firstTouchEvent;
992 firstTouchEvent.type = TouchType::CANCEL;
993 firstTouchEvent.x = 15;
994 firstTouchEvent.y = 15;
995 firstTouchEvent.id = 2;
996 TouchEvent secondTouchEvent;
997 secondTouchEvent.type = TouchType::CANCEL;
998 secondTouchEvent.x = 15;
999 secondTouchEvent.y = 15;
1000 secondTouchEvent.id = 2;
1001 auto currentTime = GetSysTimestamp();
1002 std::chrono::nanoseconds nanosecondsUp(currentTime);
1003 TimeStamp timeUp(nanosecondsUp);
1004 firstTouchEvent.time = timeUp;
1005 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
1006 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
1007 PostEventAction eventAction;
1008 eventAction.targetNode = UInode;
1009 eventAction.touchEvent = firstTouchEvent;
1010 postEventManager_->postInputEventAction_.push_back(eventAction);
1011 auto result = postEventManager_->CheckTouchEvent(UInode, secondTouchEvent);
1012 EXPECT_FALSE(result);
1013 }
1014
1015 /**
1016 * @tc.name: CheckTouchEventTest005
1017 * @tc.desc: test CheckTouchEvent.
1018 * @tc.type: FUNC
1019 */
1020 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest005, TestSize.Level1)
1021 {
1022 Init();
1023 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
1024 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
1025 auto gesture = AceType::MakeRefPtr<TapGesture>();
1026 gestureEventHub->AddGesture(gesture);
1027
1028 TouchEvent firstTouchEvent;
1029 firstTouchEvent.type = TouchType::UP;
1030 firstTouchEvent.x = 15;
1031 firstTouchEvent.y = 15;
1032 firstTouchEvent.id = 2;
1033 TouchEvent secondTouchEvent;
1034 secondTouchEvent.type = TouchType::UP;
1035 secondTouchEvent.x = 15;
1036 secondTouchEvent.y = 15;
1037 secondTouchEvent.id = 2;
1038 auto currentTime = GetSysTimestamp();
1039 std::chrono::nanoseconds nanosecondsUp(currentTime);
1040 TimeStamp timeUp(nanosecondsUp);
1041 firstTouchEvent.time = timeUp;
1042 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
1043 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
1044 PostEventAction eventAction;
1045 eventAction.targetNode = UInode;
1046 eventAction.touchEvent = firstTouchEvent;
1047 postEventManager_->postInputEventAction_.push_back(eventAction);
1048 auto result = postEventManager_->CheckTouchEvent(UInode, secondTouchEvent);
1049 EXPECT_FALSE(result);
1050 }
1051
1052 /**
1053 * @tc.name: CheckTouchEventTest006
1054 * @tc.desc: test CheckTouchEvent.
1055 * @tc.type: FUNC
1056 */
1057 HWTEST_F(PostEventManagerTestNg, CheckTouchEventTest006, TestSize.Level1)
1058 {
1059 Init();
1060 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
1061 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
1062 auto gesture = AceType::MakeRefPtr<TapGesture>();
1063 gestureEventHub->AddGesture(gesture);
1064
1065 TouchEvent touchUpEvent;
1066 touchUpEvent.type = TouchType::MOVE;
1067 touchUpEvent.x = 15;
1068 touchUpEvent.y = 15;
1069 touchUpEvent.id = 2;
1070 auto currentTime = GetSysTimestamp();
1071 std::chrono::nanoseconds nanosecondsUp(currentTime);
1072 TimeStamp timeUp(nanosecondsUp);
1073 touchUpEvent.time = timeUp;
1074 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
1075 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
1076 PostEventAction eventAction;
1077 eventAction.targetNode = UInode;
1078 eventAction.touchEvent = touchUpEvent;
1079 postEventManager_->postInputEventAction_.push_back(eventAction);
1080 auto result = postEventManager_->CheckTouchEvent(UInode, touchUpEvent);
1081 EXPECT_FALSE(result);
1082 }
1083
1084 /**
1085 * @tc.name: ClearPostInputActionsTest001
1086 * @tc.desc: test ClearPostInputActions.
1087 * @tc.type: FUNC
1088 */
1089 HWTEST_F(PostEventManagerTestNg, ClearPostInputActionsTest001, TestSize.Level1)
1090 {
1091 Init();
1092 auto gestureEventHub = root_->GetOrCreateGestureEventHub();
1093 gestureEventHub->SetHitTestMode(HitTestMode::HTMBLOCK);
1094 auto gesture = AceType::MakeRefPtr<TapGesture>();
1095 gestureEventHub->AddGesture(gesture);
1096
1097 TouchEvent touchUpEvent;
1098 touchUpEvent.type = TouchType::MOVE;
1099 touchUpEvent.x = 15;
1100 touchUpEvent.y = 15;
1101 touchUpEvent.id = 2;
1102 auto currentTime = GetSysTimestamp();
1103 std::chrono::nanoseconds nanosecondsUp(currentTime);
1104 TimeStamp timeUp(nanosecondsUp);
1105 touchUpEvent.time = timeUp;
1106 auto frameNode = AceType::MakeRefPtr<FrameNode>(ROOT_TAG, -1, AceType::MakeRefPtr<Pattern>(), true);
1107 auto UInode = AceType::DynamicCast<NG::UINode>(frameNode);
1108 PostEventAction eventAction;
1109 eventAction.targetNode = UInode;
1110 eventAction.touchEvent = touchUpEvent;
1111 postEventManager_->postInputEventAction_.push_back(eventAction);
1112 postEventManager_->ClearPostInputActions(UInode, touchUpEvent.id);
1113 EXPECT_TRUE(postEventManager_->postInputEventAction_.empty());
1114 }
1115 } // namespace OHOS::Ace::NG
1116