1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <iostream>
#include <string>
#include "AccessibleCaretManager.h"
#include "mozilla/AccessibleCaretEventHub.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TouchEvents.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::DefaultValue;
using ::testing::Eq;
using ::testing::InSequence;
using ::testing::MockFunction;
using ::testing::Return;
// -----------------------------------------------------------------------------
// This file test the state transitions of AccessibleCaretEventHub under
// various combination of events and callbacks.
namespace mozilla {
class MockAccessibleCaretManager : public AccessibleCaretManager {
public:
MockAccessibleCaretManager() : AccessibleCaretManager(nullptr) {}
MOCK_METHOD2(PressCaret,
nsresult(const nsPoint& aPoint, EventClassID aEventClass));
MOCK_METHOD1(DragCaret, nsresult(const nsPoint& aPoint));
MOCK_METHOD0(ReleaseCaret, nsresult());
MOCK_METHOD1(TapCaret, nsresult(const nsPoint& aPoint));
MOCK_METHOD1(SelectWordOrShortcut, nsresult(const nsPoint& aPoint));
MOCK_METHOD0(OnScrollStart, void());
MOCK_METHOD0(OnScrollEnd, void());
MOCK_METHOD0(OnScrollPositionChanged, void());
MOCK_METHOD0(OnBlur, void());
};
class MockAccessibleCaretEventHub : public AccessibleCaretEventHub {
public:
using AccessibleCaretEventHub::DragCaretState;
using AccessibleCaretEventHub::LongTapState;
using AccessibleCaretEventHub::NoActionState;
using AccessibleCaretEventHub::PressCaretState;
using AccessibleCaretEventHub::PressNoCaretState;
using AccessibleCaretEventHub::ScrollState;
MockAccessibleCaretEventHub() : AccessibleCaretEventHub(nullptr) {
mManager = MakeUnique<MockAccessibleCaretManager>();
mInitialized = true;
}
nsPoint GetTouchEventPosition(WidgetTouchEvent* aEvent,
int32_t aIdentifier) const override {
// Return the device point directly.
LayoutDeviceIntPoint touchIntPoint = aEvent->mTouches[0]->mRefPoint;
return nsPoint(touchIntPoint.x, touchIntPoint.y);
}
nsPoint GetMouseEventPosition(WidgetMouseEvent* aEvent) const override {
// Return the device point directly.
LayoutDeviceIntPoint mouseIntPoint = aEvent->AsGUIEvent()->mRefPoint;
return nsPoint(mouseIntPoint.x, mouseIntPoint.y);
}
MockAccessibleCaretManager* GetMockAccessibleCaretManager() {
return static_cast<MockAccessibleCaretManager*>(mManager.get());
}
};
// Print the name of the state for debugging.
static ::std::ostream& operator<<(
::std::ostream& aOstream,
const MockAccessibleCaretEventHub::State* aState) {
return aOstream << aState->Name();
}
class AccessibleCaretEventHubTester : public ::testing::Test {
public:
AccessibleCaretEventHubTester() {
DefaultValue<nsresult>::Set(NS_OK);
EXPECT_EQ(mHub->GetState(), MockAccessibleCaretEventHub::NoActionState());
// AccessibleCaretEventHub requires the caller to hold a ref to it. We just
// add ref here for the sake of convenience.
mHub.get()->AddRef();
}
~AccessibleCaretEventHubTester() override {
// Release the ref added in the constructor.
mHub.get()->Release();
}
static UniquePtr<WidgetEvent> CreateMouseEvent(EventMessage aMessage,
nscoord aX, nscoord aY) {
auto event = MakeUnique<WidgetMouseEvent>(true, aMessage, nullptr,
WidgetMouseEvent::eReal);
event->mButton = MouseButton::ePrimary;
event->mRefPoint = LayoutDeviceIntPoint(aX, aY);
return std::move(event);
}
static UniquePtr<WidgetEvent> CreateMousePressEvent(nscoord aX, nscoord aY) {
return CreateMouseEvent(eMouseDown, aX, aY);
}
static UniquePtr<WidgetEvent> CreateMouseMoveEvent(nscoord aX, nscoord aY) {
return CreateMouseEvent(eMouseMove, aX, aY);
}
static UniquePtr<WidgetEvent> CreateMouseReleaseEvent(nscoord aX,
nscoord aY) {
return CreateMouseEvent(eMouseUp, aX, aY);
}
static UniquePtr<WidgetEvent> CreateLongTapEvent(nscoord aX, nscoord aY) {
return CreateMouseEvent(eMouseLongTap, aX, aY);
}
static UniquePtr<WidgetEvent> CreateTouchEvent(EventMessage aMessage,
nscoord aX, nscoord aY) {
auto event = MakeUnique<WidgetTouchEvent>(true, aMessage, nullptr);
int32_t identifier = 0;
LayoutDeviceIntPoint point(aX, aY);
LayoutDeviceIntPoint radius(19, 19);
float rotationAngle = 0;
float force = 1;
RefPtr<dom::Touch> touch(
new dom::Touch(identifier, point, radius, rotationAngle, force));
event->mTouches.AppendElement(touch);
return std::move(event);
}
static UniquePtr<WidgetEvent> CreateTouchStartEvent(nscoord aX, nscoord aY) {
return CreateTouchEvent(eTouchStart, aX, aY);
}
static UniquePtr<WidgetEvent> CreateTouchMoveEvent(nscoord aX, nscoord aY) {
return CreateTouchEvent(eTouchMove, aX, aY);
}
static UniquePtr<WidgetEvent> CreateTouchEndEvent(nscoord aX, nscoord aY) {
return CreateTouchEvent(eTouchEnd, aX, aY);
}
static UniquePtr<WidgetEvent> CreateTouchCancelEvent(nscoord aX, nscoord aY) {
return CreateTouchEvent(eTouchCancel, aX, aY);
}
static UniquePtr<WidgetEvent> CreateWheelEvent(EventMessage aMessage) {
auto event = MakeUnique<WidgetWheelEvent>(true, aMessage, nullptr);
return std::move(event);
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestAsyncPanZoomScroll();
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HandleEventAndCheckState(
UniquePtr<WidgetEvent> aEvent,
MockAccessibleCaretEventHub::State* aExpectedState,
nsEventStatus aExpectedEventStatus) {
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
nsEventStatus rv = hub->HandleEvent(aEvent.get());
EXPECT_EQ(hub->GetState(), aExpectedState);
EXPECT_EQ(rv, aExpectedEventStatus);
}
void CheckState(MockAccessibleCaretEventHub::State* aExpectedState) {
EXPECT_EQ(mHub->GetState(), aExpectedState);
}
template <typename PressEventCreator, typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestPressReleaseOnNoCaret(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestPressReleaseOnCaret(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestPressMoveReleaseOnNoCaret(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestPressMoveReleaseOnCaret(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestLongTapWithSelectWordSuccessful(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestLongTapWithSelectWordFailed(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator);
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TestEventDrivenAsyncPanZoomScroll(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator);
// Member variables
RefPtr<MockAccessibleCaretEventHub> mHub{new MockAccessibleCaretEventHub()};
}; // class AccessibleCaretEventHubTester
TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnNoCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressReleaseOnNoCaret(CreateMousePressEvent, CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnNoCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchEndEvent);
}
template <typename PressEventCreator, typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestPressReleaseOnNoCaret(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), ReleaseCaret()).Times(0);
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), TapCaret(_)).Times(0);
HandleEventAndCheckState(aPressEventCreator(0, 0),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aReleaseEventCreator(0, 0),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressReleaseOnCaret(CreateMousePressEvent, CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressReleaseOnCaret(CreateTouchStartEvent, CreateTouchEndEvent);
}
template <typename PressEventCreator, typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestPressReleaseOnCaret(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), SelectWordOrShortcut(_))
.Times(0);
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), ReleaseCaret());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), TapCaret(_));
}
HandleEventAndCheckState(aPressEventCreator(0, 0),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(CreateLongTapEvent(0, 0),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(aReleaseEventCreator(0, 0),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eConsumeNoDefault);
}
TEST_F(AccessibleCaretEventHubTester, TestMousePressMoveReleaseOnNoCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressMoveReleaseOnNoCaret(CreateMousePressEvent, CreateMouseMoveEvent,
CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchPressMoveReleaseOnNoCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressMoveReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchMoveEvent,
CreateTouchEndEvent);
}
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestPressMoveReleaseOnNoCaret(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
nscoord x0 = 0, y0 = 0;
nscoord x1 = 100, y1 = 100;
nscoord x2 = 300, y2 = 300;
nscoord x3 = 400, y3 = 400;
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_)).Times(0);
}
HandleEventAndCheckState(aPressEventCreator(x0, y0),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
// A small move with the distance between (x0, y0) and (x1, y1) below the
// tolerance value.
HandleEventAndCheckState(aMoveEventCreator(x1, y1),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
// A large move to simulate a dragging to select text since the distance
// between (x0, y0) and (x2, y2) is above the tolerance value.
HandleEventAndCheckState(aMoveEventCreator(x2, y2),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aReleaseEventCreator(x3, y3),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestMousePressMoveReleaseOnCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressMoveReleaseOnCaret(CreateMousePressEvent, CreateMouseMoveEvent,
CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchPressMoveReleaseOnCaret)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestPressMoveReleaseOnCaret(CreateTouchStartEvent, CreateTouchMoveEvent,
CreateTouchEndEvent);
}
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestPressMoveReleaseOnCaret(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
nscoord x0 = 0, y0 = 0;
nscoord x1 = 100, y1 = 100;
nscoord x2 = 300, y2 = 300;
nscoord x3 = 400, y3 = 400;
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_))
.Times(2) // two valid drag operations
.WillRepeatedly(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), ReleaseCaret())
.WillOnce(Return(NS_OK));
}
HandleEventAndCheckState(aPressEventCreator(x0, y0),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
// A small move with the distance between (x0, y0) and (x1, y1) below the
// tolerance value.
HandleEventAndCheckState(aMoveEventCreator(x1, y1),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
// A large move forms a valid drag since the distance between (x0, y0) and
// (x2, y2) is above the tolerance value.
HandleEventAndCheckState(aMoveEventCreator(x2, y2),
MockAccessibleCaretEventHub::DragCaretState(),
nsEventStatus_eConsumeNoDefault);
// Also a valid drag since the distance between (x0, y0) and (x3, y3) above
// the tolerance value even if the distance between (x2, y2) and (x3, y3) is
// below the tolerance value.
HandleEventAndCheckState(aMoveEventCreator(x3, y3),
MockAccessibleCaretEventHub::DragCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(aReleaseEventCreator(x3, y3),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eConsumeNoDefault);
}
TEST_F(AccessibleCaretEventHubTester,
TestTouchStartMoveEndOnCaretWithTouchCancelIgnored)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
nscoord x0 = 0, y0 = 0;
nscoord x1 = 100, y1 = 100;
nscoord x2 = 300, y2 = 300;
nscoord x3 = 400, y3 = 400;
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_))
.WillOnce(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), ReleaseCaret())
.WillOnce(Return(NS_OK));
}
// All the eTouchCancel events should be ignored in this test.
HandleEventAndCheckState(CreateTouchStartEvent(x0, y0),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(CreateTouchCancelEvent(x0, y0),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eIgnore);
// A small move with the distance between (x0, y0) and (x1, y1) below the
// tolerance value.
HandleEventAndCheckState(CreateTouchMoveEvent(x1, y1),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(CreateTouchCancelEvent(x1, y1),
MockAccessibleCaretEventHub::PressCaretState(),
nsEventStatus_eIgnore);
// A large move forms a valid drag since the distance between (x0, y0) and
// (x2, y2) is above the tolerance value.
HandleEventAndCheckState(CreateTouchMoveEvent(x2, y2),
MockAccessibleCaretEventHub::DragCaretState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(CreateTouchCancelEvent(x2, y2),
MockAccessibleCaretEventHub::DragCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(CreateTouchEndEvent(x3, y3),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eConsumeNoDefault);
HandleEventAndCheckState(CreateTouchCancelEvent(x3, y3),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordSuccessful)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestLongTapWithSelectWordSuccessful(CreateMousePressEvent,
CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordSuccessful)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestLongTapWithSelectWordSuccessful(CreateTouchStartEvent,
CreateTouchEndEvent);
}
template <typename PressEventCreator, typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestLongTapWithSelectWordSuccessful(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
MockFunction<void(::std::string aCheckPointName)> check;
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), SelectWordOrShortcut(_))
.WillOnce(Return(NS_OK));
EXPECT_CALL(check, Call("longtap with scrolling"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), SelectWordOrShortcut(_))
.WillOnce(Return(NS_OK));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
}
// Test long tap without scrolling.
HandleEventAndCheckState(aPressEventCreator(0, 0),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(CreateLongTapEvent(0, 0),
MockAccessibleCaretEventHub::LongTapState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aReleaseEventCreator(0, 0),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
// On Fennec, after long tap, the script might scroll and zoom the input field
// to the center of the screen to make typing easier before the user lifts the
// finger.
check.Call("longtap with scrolling");
HandleEventAndCheckState(aPressEventCreator(1, 1),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(CreateLongTapEvent(1, 1),
MockAccessibleCaretEventHub::LongTapState(),
nsEventStatus_eIgnore);
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
HandleEventAndCheckState(aReleaseEventCreator(1, 1),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordFailed)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestLongTapWithSelectWordFailed(CreateMousePressEvent,
CreateMouseReleaseEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordFailed)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestLongTapWithSelectWordFailed(CreateTouchStartEvent, CreateTouchEndEvent);
}
template <typename PressEventCreator, typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestLongTapWithSelectWordFailed(
PressEventCreator aPressEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), SelectWordOrShortcut(_))
.WillOnce(Return(NS_ERROR_FAILURE));
}
HandleEventAndCheckState(aPressEventCreator(0, 0),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(CreateLongTapEvent(0, 0),
MockAccessibleCaretEventHub::LongTapState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aReleaseEventCreator(0, 0),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestTouchEventDrivenAsyncPanZoomScroll)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestEventDrivenAsyncPanZoomScroll(CreateTouchStartEvent, CreateTouchMoveEvent,
CreateTouchEndEvent);
}
TEST_F(AccessibleCaretEventHubTester, TestMouseEventDrivenAsyncPanZoomScroll)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
TestEventDrivenAsyncPanZoomScroll(CreateMousePressEvent, CreateMouseMoveEvent,
CreateMouseReleaseEvent);
}
template <typename PressEventCreator, typename MoveEventCreator,
typename ReleaseEventCreator>
void AccessibleCaretEventHubTester::TestEventDrivenAsyncPanZoomScroll(
PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
ReleaseEventCreator aReleaseEventCreator) {
MockFunction<void(::std::string aCheckPointName)> check;
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_)).Times(0);
EXPECT_CALL(check, Call("1"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
EXPECT_CALL(check, Call("2"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), PressCaret(_, _))
.WillOnce(Return(NS_ERROR_FAILURE));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_)).Times(0);
EXPECT_CALL(check, Call("3"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
}
// Receive press event.
HandleEventAndCheckState(aPressEventCreator(0, 0),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aMoveEventCreator(100, 100),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
check.Call("1");
// Event driven scroll started
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
HandleEventAndCheckState(aMoveEventCreator(160, 160),
MockAccessibleCaretEventHub::ScrollState(),
nsEventStatus_eIgnore);
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
// Event driven scroll ended
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
HandleEventAndCheckState(aReleaseEventCreator(210, 210),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
check.Call("2");
// Receive another press event.
HandleEventAndCheckState(aPressEventCreator(220, 220),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
HandleEventAndCheckState(aMoveEventCreator(230, 230),
MockAccessibleCaretEventHub::PressNoCaretState(),
nsEventStatus_eIgnore);
check.Call("3");
// Another APZ scroll started
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
// Another APZ scroll ended
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
HandleEventAndCheckState(aReleaseEventCreator(310, 310),
MockAccessibleCaretEventHub::NoActionState(),
nsEventStatus_eIgnore);
}
TEST_F(AccessibleCaretEventHubTester, TestAsyncPanZoomScroll)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION { TestAsyncPanZoomScroll(); }
void AccessibleCaretEventHubTester::TestAsyncPanZoomScroll() {
MockFunction<void(::std::string aCheckPointName)> check;
{
InSequence dummy;
EXPECT_CALL(check, Call("1"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(),
OnScrollPositionChanged());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
EXPECT_CALL(check, Call("2"));
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(),
OnScrollPositionChanged());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
}
// First APZ scrolling.
check.Call("1");
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
// Second APZ scrolling.
check.Call("2");
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
}
TEST_F(AccessibleCaretEventHubTester, TestAsyncPanZoomScrollStartedThenBlur)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd()).Times(0);
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnBlur());
}
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->NotifyBlur(true);
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
}
TEST_F(AccessibleCaretEventHubTester, TestAsyncPanZoomScrollEndedThenBlur)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
{
InSequence dummy;
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollStart());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnScrollEnd());
EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), OnBlur());
}
RefPtr<MockAccessibleCaretEventHub> hub(mHub);
hub->AsyncPanZoomStarted();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->ScrollPositionChanged();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::ScrollState());
hub->AsyncPanZoomStopped();
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
hub->NotifyBlur(true);
EXPECT_EQ(hub->GetState(), MockAccessibleCaretEventHub::NoActionState());
}
} // namespace mozilla
|