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