Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/apz/test/gtest/TestPanning.cpp
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
#include "APZCBasicTester.h"
8
#include "APZTestCommon.h"
9
#include "InputUtils.h"
10
11
class APZCPanningTester : public APZCBasicTester {
12
protected:
13
  void DoPanTest(bool aShouldTriggerScroll, bool aShouldBeConsumed, uint32_t aBehavior)
14
0
  {
15
0
    if (aShouldTriggerScroll) {
16
0
      // One repaint request for each pan.
17
0
      EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(2);
18
0
    } else {
19
0
      EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(0);
20
0
    }
21
0
22
0
    int touchStart = 50;
23
0
    int touchEnd = 10;
24
0
    ParentLayerPoint pointOut;
25
0
    AsyncTransform viewTransformOut;
26
0
27
0
    nsTArray<uint32_t> allowedTouchBehaviors;
28
0
    allowedTouchBehaviors.AppendElement(aBehavior);
29
0
30
0
    // Pan down
31
0
    PanAndCheckStatus(apzc, touchStart, touchEnd, aShouldBeConsumed, &allowedTouchBehaviors);
32
0
    apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut);
33
0
34
0
    if (aShouldTriggerScroll) {
35
0
      EXPECT_EQ(ParentLayerPoint(0, -(touchEnd-touchStart)), pointOut);
36
0
      EXPECT_NE(AsyncTransform(), viewTransformOut);
37
0
    } else {
38
0
      EXPECT_EQ(ParentLayerPoint(), pointOut);
39
0
      EXPECT_EQ(AsyncTransform(), viewTransformOut);
40
0
    }
41
0
42
0
    // Clear the fling from the previous pan, or stopping it will
43
0
    // consume the next touchstart
44
0
    apzc->CancelAnimation();
45
0
46
0
    // Pan back
47
0
    PanAndCheckStatus(apzc, touchEnd, touchStart, aShouldBeConsumed, &allowedTouchBehaviors);
48
0
    apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut);
49
0
50
0
    EXPECT_EQ(ParentLayerPoint(), pointOut);
51
0
    EXPECT_EQ(AsyncTransform(), viewTransformOut);
52
0
  }
53
54
  void DoPanWithPreventDefaultTest()
55
0
  {
56
0
    MakeApzcWaitForMainThread();
57
0
58
0
    int touchStart = 50;
59
0
    int touchEnd = 10;
60
0
    ParentLayerPoint pointOut;
61
0
    AsyncTransform viewTransformOut;
62
0
    uint64_t blockId = 0;
63
0
64
0
    // Pan down
65
0
    nsTArray<uint32_t> allowedTouchBehaviors;
66
0
    allowedTouchBehaviors.AppendElement(mozilla::layers::AllowedTouchBehavior::VERTICAL_PAN);
67
0
    PanAndCheckStatus(apzc, touchStart, touchEnd, true, &allowedTouchBehaviors, &blockId);
68
0
69
0
    // Send the signal that content has handled and preventDefaulted the touch
70
0
    // events. This flushes the event queue.
71
0
    apzc->ContentReceivedInputBlock(blockId, true);
72
0
73
0
    apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut);
74
0
    EXPECT_EQ(ParentLayerPoint(), pointOut);
75
0
    EXPECT_EQ(AsyncTransform(), viewTransformOut);
76
0
77
0
    apzc->AssertStateIsReset();
78
0
  }
79
};
80
81
0
TEST_F(APZCPanningTester, Pan) {
82
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, false);
83
0
  SCOPED_GFX_PREF(APZVelocityBias, float, 0.0); // Velocity bias can cause extra repaint requests
84
0
  DoPanTest(true, true, mozilla::layers::AllowedTouchBehavior::NONE);
85
0
}
86
87
// In the each of the following 4 pan tests we are performing two pan gestures: vertical pan from top
88
// to bottom and back - from bottom to top.
89
// According to the pointer-events/touch-action spec AUTO and PAN_Y touch-action values allow vertical
90
// scrolling while NONE and PAN_X forbid it. The first parameter of DoPanTest method specifies this
91
// behavior.
92
// However, the events will be marked as consumed even if the behavior in PAN_X, because the user could
93
// move their finger horizontally too - APZ has no way of knowing beforehand and so must consume the
94
// events.
95
0
TEST_F(APZCPanningTester, PanWithTouchActionAuto) {
96
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, true);
97
0
  SCOPED_GFX_PREF(APZVelocityBias, float, 0.0); // Velocity bias can cause extra repaint requests
98
0
  DoPanTest(true, true, mozilla::layers::AllowedTouchBehavior::HORIZONTAL_PAN
99
0
                      | mozilla::layers::AllowedTouchBehavior::VERTICAL_PAN);
100
0
}
101
102
0
TEST_F(APZCPanningTester, PanWithTouchActionNone) {
103
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, true);
104
0
  SCOPED_GFX_PREF(APZVelocityBias, float, 0.0); // Velocity bias can cause extra repaint requests
105
0
  DoPanTest(false, false, 0);
106
0
}
107
108
0
TEST_F(APZCPanningTester, PanWithTouchActionPanX) {
109
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, true);
110
0
  SCOPED_GFX_PREF(APZVelocityBias, float, 0.0); // Velocity bias can cause extra repaint requests
111
0
  DoPanTest(false, true, mozilla::layers::AllowedTouchBehavior::HORIZONTAL_PAN);
112
0
}
113
114
0
TEST_F(APZCPanningTester, PanWithTouchActionPanY) {
115
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, true);
116
0
  SCOPED_GFX_PREF(APZVelocityBias, float, 0.0); // Velocity bias can cause extra repaint requests
117
0
  DoPanTest(true, true, mozilla::layers::AllowedTouchBehavior::VERTICAL_PAN);
118
0
}
119
120
0
TEST_F(APZCPanningTester, PanWithPreventDefaultAndTouchAction) {
121
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, true);
122
0
  DoPanWithPreventDefaultTest();
123
0
}
124
125
0
TEST_F(APZCPanningTester, PanWithPreventDefault) {
126
0
  SCOPED_GFX_PREF(TouchActionEnabled, bool, false);
127
0
  DoPanWithPreventDefaultTest();
128
0
}