Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/apz/test/gtest/APZCBasicTester.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_APZCBasicTester_h
8
#define mozilla_layers_APZCBasicTester_h
9
10
/**
11
 * Defines a test fixture used for testing a single APZC.
12
 */
13
14
#include "APZTestCommon.h"
15
#include "gfxPrefs.h"
16
#include "mozilla/layers/APZSampler.h"
17
#include "mozilla/layers/APZUpdater.h"
18
19
class APZCBasicTester : public APZCTesterBase {
20
public:
21
  explicit APZCBasicTester(AsyncPanZoomController::GestureBehavior aGestureBehavior = AsyncPanZoomController::DEFAULT_GESTURES)
22
    : mGestureBehavior(aGestureBehavior)
23
0
  {
24
0
  }
25
26
protected:
27
  virtual void SetUp()
28
0
  {
29
0
    gfxPrefs::GetSingleton();
30
0
    APZThreadUtils::SetThreadAssertionsEnabled(false);
31
0
    APZThreadUtils::SetControllerThread(MessageLoop::current());
32
0
33
0
    tm = new TestAPZCTreeManager(mcc);
34
0
    updater = new APZUpdater(tm, false);
35
0
    sampler = new APZSampler(tm, false);
36
0
    apzc = new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior);
37
0
    apzc->SetFrameMetrics(TestFrameMetrics());
38
0
    apzc->GetScrollMetadata().SetIsLayersIdRoot(true);
39
0
  }
40
41
  /**
42
   * Get the APZC's scroll range in CSS pixels.
43
   */
44
  CSSRect GetScrollRange() const
45
0
  {
46
0
    const FrameMetrics& metrics = apzc->GetFrameMetrics();
47
0
    return CSSRect(
48
0
        metrics.GetScrollableRect().TopLeft(),
49
0
        metrics.GetScrollableRect().Size() - metrics.CalculateCompositedSizeInCssPixels());
50
0
  }
51
52
  virtual void TearDown()
53
0
  {
54
0
    while (mcc->RunThroughDelayedTasks());
55
0
    apzc->Destroy();
56
0
    tm->ClearTree();
57
0
    tm->ClearContentController();
58
0
  }
59
60
  void MakeApzcWaitForMainThread()
61
0
  {
62
0
    apzc->SetWaitForMainThread();
63
0
  }
64
65
  void MakeApzcZoomable()
66
0
  {
67
0
    apzc->UpdateZoomConstraints(ZoomConstraints(true, true, CSSToParentLayerScale(0.25f), CSSToParentLayerScale(4.0f)));
68
0
  }
69
70
  void MakeApzcUnzoomable()
71
0
  {
72
0
    apzc->UpdateZoomConstraints(ZoomConstraints(false, false, CSSToParentLayerScale(1.0f), CSSToParentLayerScale(1.0f)));
73
0
  }
74
75
  void PanIntoOverscroll();
76
77
  /**
78
   * Sample animations once, 1 ms later than the last sample.
79
   */
80
  void SampleAnimationOnce()
81
0
  {
82
0
    const TimeDuration increment = TimeDuration::FromMilliseconds(1);
83
0
    ParentLayerPoint pointOut;
84
0
    AsyncTransform viewTransformOut;
85
0
    mcc->AdvanceBy(increment);
86
0
    apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut);
87
0
  }
88
89
  /**
90
   * Sample animations until we recover from overscroll.
91
   * @param aExpectedScrollOffset the expected reported scroll offset
92
   *                              throughout the animation
93
   */
94
  void SampleAnimationUntilRecoveredFromOverscroll(const ParentLayerPoint& aExpectedScrollOffset)
95
0
  {
96
0
    const TimeDuration increment = TimeDuration::FromMilliseconds(1);
97
0
    bool recoveredFromOverscroll = false;
98
0
    ParentLayerPoint pointOut;
99
0
    AsyncTransform viewTransformOut;
100
0
    while (apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut)) {
101
0
      // The reported scroll offset should be the same throughout.
102
0
      EXPECT_EQ(aExpectedScrollOffset, pointOut);
103
0
104
0
      // Trigger computation of the overscroll tranform, to make sure
105
0
      // no assetions fire during the calculation.
106
0
      apzc->GetOverscrollTransform(AsyncPanZoomController::eForHitTesting);
107
0
108
0
      if (!apzc->IsOverscrolled()) {
109
0
        recoveredFromOverscroll = true;
110
0
      }
111
0
112
0
      mcc->AdvanceBy(increment);
113
0
    }
114
0
    EXPECT_TRUE(recoveredFromOverscroll);
115
0
    apzc->AssertStateIsReset();
116
0
  }
117
118
  void TestOverscroll();
119
120
  AsyncPanZoomController::GestureBehavior mGestureBehavior;
121
  RefPtr<TestAPZCTreeManager> tm;
122
  RefPtr<APZSampler> sampler;
123
  RefPtr<APZUpdater> updater;
124
  RefPtr<TestAsyncPanZoomController> apzc;
125
};
126
127
#endif // mozilla_layers_APZCBasicTester_h