Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/apz/test/gtest/InputUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_layers_InputUtils_h
8
#define mozilla_layers_InputUtils_h
9
10
/**
11
 * Defines a set of utility functions for generating input events
12
 * to an APZC/APZCTM during APZ gtests.
13
 */
14
15
#include "APZTestCommon.h"
16
#include "gfxPrefs.h"
17
18
/* The InputReceiver template parameter used in the helper functions below needs
19
 * to be a class that implements functions with the signatures:
20
 * nsEventStatus ReceiveInputEvent(const InputData& aEvent,
21
 *                                 ScrollableLayerGuid* aGuid,
22
 *                                 uint64_t* aOutInputBlockId);
23
 * void SetAllowedTouchBehavior(uint64_t aInputBlockId,
24
 *                              const nsTArray<uint32_t>& aBehaviours);
25
 * The classes that currently implement these are APZCTreeManager and
26
 * TestAsyncPanZoomController. Using this template allows us to test individual
27
 * APZC instances in isolation and also an entire APZ tree, while using the same
28
 * code to dispatch input events.
29
 */
30
31
PinchGestureInput
32
CreatePinchGestureInput(PinchGestureInput::PinchGestureType aType,
33
                        const ScreenPoint& aFocus,
34
                        float aCurrentSpan, float aPreviousSpan)
35
0
{
36
0
  ParentLayerPoint localFocus(aFocus.x, aFocus.y);
37
0
  PinchGestureInput result(aType, 0, TimeStamp(), localFocus,
38
0
                           aCurrentSpan, aPreviousSpan, 0);
39
0
  result.mFocusPoint = aFocus;
40
0
  return result;
41
0
}
42
43
template<class InputReceiver>
44
void
45
SetDefaultAllowedTouchBehavior(const RefPtr<InputReceiver>& aTarget,
46
                               uint64_t aInputBlockId,
47
                               int touchPoints = 1)
48
0
{
49
0
  nsTArray<uint32_t> defaultBehaviors;
50
0
  // use the default value where everything is allowed
51
0
  for (int i = 0; i < touchPoints; i++) {
52
0
    defaultBehaviors.AppendElement(mozilla::layers::AllowedTouchBehavior::HORIZONTAL_PAN
53
0
                                 | mozilla::layers::AllowedTouchBehavior::VERTICAL_PAN
54
0
                                 | mozilla::layers::AllowedTouchBehavior::PINCH_ZOOM
55
0
                                 | mozilla::layers::AllowedTouchBehavior::DOUBLE_TAP_ZOOM);
56
0
  }
57
0
  aTarget->SetAllowedTouchBehavior(aInputBlockId, defaultBehaviors);
58
0
}
Unexecuted instantiation: void SetDefaultAllowedTouchBehavior<TestAsyncPanZoomController>(RefPtr<TestAsyncPanZoomController> const&, unsigned long, int)
Unexecuted instantiation: void SetDefaultAllowedTouchBehavior<TestAPZCTreeManager>(RefPtr<TestAPZCTreeManager> const&, unsigned long, int)
59
60
61
MultiTouchInput
62
CreateMultiTouchInput(MultiTouchInput::MultiTouchType aType, TimeStamp aTime)
63
0
{
64
0
  return MultiTouchInput(aType, MillisecondsSinceStartup(aTime), aTime, 0);
65
0
}
66
67
template<class InputReceiver>
68
nsEventStatus
69
TouchDown(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
70
          TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
71
0
{
72
0
  MultiTouchInput mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, aTime);
73
0
  mti.mTouches.AppendElement(CreateSingleTouchData(0, aPoint));
74
0
  return aTarget->ReceiveInputEvent(mti, nullptr, aOutInputBlockId);
75
0
}
Unexecuted instantiation: nsEventStatus TouchDown<TestAsyncPanZoomController>(RefPtr<TestAsyncPanZoomController> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp, unsigned long*)
Unexecuted instantiation: nsEventStatus TouchDown<TestAPZCTreeManager>(RefPtr<TestAPZCTreeManager> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp, unsigned long*)
76
77
template<class InputReceiver>
78
nsEventStatus
79
TouchMove(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
80
          TimeStamp aTime)
81
0
{
82
0
  MultiTouchInput mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime);
83
0
  mti.mTouches.AppendElement(CreateSingleTouchData(0, aPoint));
84
0
  return aTarget->ReceiveInputEvent(mti, nullptr, nullptr);
85
0
}
Unexecuted instantiation: nsEventStatus TouchMove<TestAsyncPanZoomController>(RefPtr<TestAsyncPanZoomController> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp)
Unexecuted instantiation: nsEventStatus TouchMove<TestAPZCTreeManager>(RefPtr<TestAPZCTreeManager> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp)
86
87
template<class InputReceiver>
88
nsEventStatus
89
TouchUp(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
90
        TimeStamp aTime)
91
0
{
92
0
  MultiTouchInput mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_END, aTime);
93
0
  mti.mTouches.AppendElement(CreateSingleTouchData(0, aPoint));
94
0
  return aTarget->ReceiveInputEvent(mti, nullptr, nullptr);
95
0
}
Unexecuted instantiation: nsEventStatus TouchUp<TestAsyncPanZoomController>(RefPtr<TestAsyncPanZoomController> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp)
Unexecuted instantiation: nsEventStatus TouchUp<TestAPZCTreeManager>(RefPtr<TestAPZCTreeManager> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::TimeStamp)
96
97
template<class InputReceiver>
98
void
99
PinchWithPinchInput(const RefPtr<InputReceiver>& aTarget,
100
                    const ScreenIntPoint& aFocus,
101
                    const ScreenIntPoint& aSecondFocus, float aScale,
102
                    nsEventStatus (*aOutEventStatuses)[3] = nullptr)
103
0
{
104
0
  nsEventStatus actualStatus = aTarget->ReceiveInputEvent(
105
0
      CreatePinchGestureInput(PinchGestureInput::PINCHGESTURE_START,
106
0
                              aFocus, 10.0, 10.0),
107
0
      nullptr);
108
0
  if (aOutEventStatuses) {
109
0
    (*aOutEventStatuses)[0] = actualStatus;
110
0
  }
111
0
  actualStatus = aTarget->ReceiveInputEvent(
112
0
      CreatePinchGestureInput(PinchGestureInput::PINCHGESTURE_SCALE,
113
0
                              aSecondFocus, 10.0 * aScale, 10.0),
114
0
      nullptr);
115
0
  if (aOutEventStatuses) {
116
0
    (*aOutEventStatuses)[1] = actualStatus;
117
0
  }
118
0
  actualStatus = aTarget->ReceiveInputEvent(
119
0
      CreatePinchGestureInput(PinchGestureInput::PINCHGESTURE_END,
120
0
                              PinchGestureInput::BothFingersLifted<ScreenPixel>(),
121
0
                              10.0 * aScale, 10.0 * aScale),
122
0
      nullptr);
123
0
  if (aOutEventStatuses) {
124
0
    (*aOutEventStatuses)[2] = actualStatus;
125
0
  }
126
0
}
127
128
template<class InputReceiver>
129
void
130
PinchWithPinchInputAndCheckStatus(const RefPtr<InputReceiver>& aTarget,
131
                                  const ScreenIntPoint& aFocus, float aScale,
132
                                  bool aShouldTriggerPinch)
133
0
{
134
0
  nsEventStatus statuses[3];  // scalebegin, scale, scaleend
135
0
  PinchWithPinchInput(aTarget, aFocus, aFocus, aScale, &statuses);
136
0
137
0
  nsEventStatus expectedStatus = aShouldTriggerPinch
138
0
      ? nsEventStatus_eConsumeNoDefault
139
0
      : nsEventStatus_eIgnore;
140
0
  EXPECT_EQ(expectedStatus, statuses[0]);
141
0
  EXPECT_EQ(expectedStatus, statuses[1]);
142
0
}
143
144
template<class InputReceiver>
145
nsEventStatus
146
Wheel(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
147
      const ScreenPoint& aDelta, TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
148
0
{
149
0
  ScrollWheelInput input(MillisecondsSinceStartup(aTime), aTime, 0,
150
0
      ScrollWheelInput::SCROLLMODE_INSTANT, ScrollWheelInput::SCROLLDELTA_PIXEL,
151
0
      aPoint, aDelta.x, aDelta.y, false, WheelDeltaAdjustmentStrategy::eNone);
152
0
  return aTarget->ReceiveInputEvent(input, nullptr, aOutInputBlockId);
153
0
}
154
155
template<class InputReceiver>
156
nsEventStatus
157
SmoothWheel(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
158
            const ScreenPoint& aDelta, TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
159
0
{
160
0
  ScrollWheelInput input(MillisecondsSinceStartup(aTime), aTime, 0,
161
0
      ScrollWheelInput::SCROLLMODE_SMOOTH, ScrollWheelInput::SCROLLDELTA_LINE,
162
0
      aPoint, aDelta.x, aDelta.y, false, WheelDeltaAdjustmentStrategy::eNone);
163
0
  return aTarget->ReceiveInputEvent(input, nullptr, aOutInputBlockId);
164
0
}
Unexecuted instantiation: nsEventStatus SmoothWheel<TestAsyncPanZoomController>(RefPtr<TestAsyncPanZoomController> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::gfx::PointTyped<mozilla::ScreenPixel, float> const&, mozilla::TimeStamp, unsigned long*)
Unexecuted instantiation: nsEventStatus SmoothWheel<TestAPZCTreeManager>(RefPtr<TestAPZCTreeManager> const&, mozilla::gfx::IntPointTyped<mozilla::ScreenPixel> const&, mozilla::gfx::PointTyped<mozilla::ScreenPixel, float> const&, mozilla::TimeStamp, unsigned long*)
165
166
template<class InputReceiver>
167
nsEventStatus
168
MouseDown(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
169
          TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
170
0
{
171
0
  MouseInput input(MouseInput::MOUSE_DOWN, MouseInput::ButtonType::LEFT_BUTTON,
172
0
        0, 0, aPoint, MillisecondsSinceStartup(aTime), aTime, 0);
173
0
  return aTarget->ReceiveInputEvent(input, nullptr, aOutInputBlockId);
174
0
}
175
176
template<class InputReceiver>
177
nsEventStatus
178
MouseMove(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
179
          TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
180
0
{
181
0
  MouseInput input(MouseInput::MOUSE_MOVE, MouseInput::ButtonType::LEFT_BUTTON,
182
0
        0, 0, aPoint, MillisecondsSinceStartup(aTime), aTime, 0);
183
0
  return aTarget->ReceiveInputEvent(input, nullptr, aOutInputBlockId);
184
0
}
185
186
template<class InputReceiver>
187
nsEventStatus
188
MouseUp(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
189
        TimeStamp aTime, uint64_t* aOutInputBlockId = nullptr)
190
{
191
  MouseInput input(MouseInput::MOUSE_UP, MouseInput::ButtonType::LEFT_BUTTON,
192
        0, 0, aPoint, MillisecondsSinceStartup(aTime), aTime, 0);
193
  return aTarget->ReceiveInputEvent(input, nullptr, aOutInputBlockId);
194
}
195
196
197
#endif // mozilla_layers_InputUtils_h