Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/apz/test/gtest/TestSnapping.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 "APZCTreeManagerTester.h"
8
#include "APZTestCommon.h"
9
#include "gfxPrefs.h"
10
#include "InputUtils.h"
11
12
class APZCSnappingTester : public APZCTreeManagerTester
13
{
14
};
15
16
TEST_F(APZCSnappingTester, Bug1265510)
17
0
{
18
0
  SCOPED_GFX_VAR(UseWebRender, bool, false);
19
0
20
0
  const char* layerTreeSyntax = "c(t)";
21
0
  nsIntRegion layerVisibleRegion[] = {
22
0
    nsIntRegion(IntRect(0, 0, 100, 100)),
23
0
    nsIntRegion(IntRect(0, 100, 100, 100))
24
0
  };
25
0
  root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers);
26
0
  SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 100, 200));
27
0
  SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1, CSSRect(0, 0, 100, 200));
28
0
  SetScrollHandoff(layers[1], root);
29
0
30
0
  ScrollSnapInfo snap;
31
0
  snap.mScrollSnapTypeY = NS_STYLE_SCROLL_SNAP_TYPE_MANDATORY;
32
0
  snap.mScrollSnapIntervalY = Some(100 * AppUnitsPerCSSPixel());
33
0
34
0
  ScrollMetadata metadata = root->GetScrollMetadata(0);
35
0
  metadata.SetSnapInfo(ScrollSnapInfo(snap));
36
0
  root->SetScrollMetadata(metadata);
37
0
38
0
  UniquePtr<ScopedLayerTreeRegistration> registration = MakeUnique<ScopedLayerTreeRegistration>(manager, LayersId{0}, root, mcc);
39
0
  manager->UpdateHitTestingTree(LayersId{0}, root, false, LayersId{0}, 0);
40
0
41
0
  TestAsyncPanZoomController* outer = ApzcOf(layers[0]);
42
0
  TestAsyncPanZoomController* inner = ApzcOf(layers[1]);
43
0
44
0
  // Position the mouse near the bottom of the outer frame and scroll by 60px.
45
0
  // (6 lines of 10px each). APZC will actually scroll to y=100 because of the
46
0
  // mandatory snap coordinate there.
47
0
  TimeStamp now = mcc->Time();
48
0
  SmoothWheel(manager, ScreenIntPoint(50, 80), ScreenPoint(0, 6), now);
49
0
  // Advance in 5ms increments until we've scrolled by 70px. At this point, the
50
0
  // closest snap point is y=100, and the inner frame should be under the mouse
51
0
  // cursor.
52
0
  while (outer->GetCurrentAsyncScrollOffset(AsyncPanZoomController::AsyncTransformConsumer::eForHitTesting).y < 70) {
53
0
    mcc->AdvanceByMillis(5);
54
0
    outer->AdvanceAnimations(mcc->Time());
55
0
  }
56
0
  // Now do another wheel in a new transaction. This should start scrolling the
57
0
  // inner frame; we verify that it does by checking the inner scroll position.
58
0
  TimeStamp newTransactionTime = now + TimeDuration::FromMilliseconds(gfxPrefs::MouseWheelTransactionTimeoutMs() + 100);
59
0
  SmoothWheel(manager, ScreenIntPoint(50, 80), ScreenPoint(0, 6), newTransactionTime);
60
0
  inner->AdvanceAnimationsUntilEnd();
61
0
  EXPECT_LT(0.0f, inner->GetCurrentAsyncScrollOffset(AsyncPanZoomController::AsyncTransformConsumer::eForHitTesting).y);
62
0
63
0
  // However, the outer frame should also continue to the snap point, otherwise
64
0
  // it is demonstrating incorrect behaviour by violating the mandatory snapping.
65
0
  outer->AdvanceAnimationsUntilEnd();
66
0
  EXPECT_EQ(100.0f, outer->GetCurrentAsyncScrollOffset(AsyncPanZoomController::AsyncTransformConsumer::eForHitTesting).y);
67
0
}
68
69
TEST_F(APZCSnappingTester, Snap_After_Pinch)
70
0
{
71
0
  SCOPED_GFX_VAR(UseWebRender, bool, false);
72
0
73
0
  const char* layerTreeSyntax = "c";
74
0
  nsIntRegion layerVisibleRegion[] = {
75
0
    nsIntRegion(IntRect(0, 0, 100, 100)),
76
0
  };
77
0
  root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers);
78
0
  SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 100, 200));
79
0
80
0
  // Set up some basic scroll snapping
81
0
  ScrollSnapInfo snap;
82
0
  snap.mScrollSnapTypeY = NS_STYLE_SCROLL_SNAP_TYPE_MANDATORY;
83
0
  snap.mScrollSnapIntervalY = Some(100 * AppUnitsPerCSSPixel());
84
0
85
0
  // Save the scroll snap info on the root APZC.
86
0
  // Also mark the root APZC as "root content", since APZC only allows
87
0
  // zooming on the root content APZC.
88
0
  ScrollMetadata metadata = root->GetScrollMetadata(0);
89
0
  metadata.SetSnapInfo(ScrollSnapInfo(snap));
90
0
  metadata.GetMetrics().SetIsRootContent(true);
91
0
  root->SetScrollMetadata(metadata);
92
0
93
0
  UniquePtr<ScopedLayerTreeRegistration> registration = MakeUnique<ScopedLayerTreeRegistration>(manager, LayersId{0}, root, mcc);
94
0
  manager->UpdateHitTestingTree(LayersId{0}, root, false, LayersId{0}, 0);
95
0
96
0
  RefPtr<TestAsyncPanZoomController> apzc = ApzcOf(root);
97
0
98
0
  // Allow zooming
99
0
  apzc->UpdateZoomConstraints(ZoomConstraints(true, true, CSSToParentLayerScale(0.25f), CSSToParentLayerScale(4.0f)));
100
0
101
0
  PinchWithPinchInput(apzc, ScreenIntPoint(50, 50), ScreenIntPoint(50, 50), 1.2f);
102
0
103
0
  apzc->AssertStateIsSmoothScroll();
104
0
}