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 16 #include "mozilla/layers/APZSampler.h" 17 #include "mozilla/layers/APZUpdater.h" 18 19 class APZCBasicTester : public APZCTesterBase { 20 public: 21 explicit APZCBasicTester( 22 AsyncPanZoomController::GestureBehavior aGestureBehavior = 23 AsyncPanZoomController::DEFAULT_GESTURES) mGestureBehavior(aGestureBehavior)24 : mGestureBehavior(aGestureBehavior) {} 25 26 protected: SetUp()27 virtual void SetUp() { 28 APZCTesterBase::SetUp(); 29 APZThreadUtils::SetThreadAssertionsEnabled(false); 30 APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); 31 32 tm = new TestAPZCTreeManager(mcc); 33 updater = new APZUpdater(tm, false); 34 sampler = new APZSampler(tm, false); 35 apzc = 36 new TestAsyncPanZoomController(LayersId{0}, mcc, tm, mGestureBehavior); 37 apzc->SetFrameMetrics(TestFrameMetrics()); 38 apzc->GetScrollMetadata().SetIsLayersIdRoot(true); 39 } 40 41 /** 42 * Get the APZC's scroll range in CSS pixels. 43 */ GetScrollRange()44 CSSRect GetScrollRange() const { 45 const FrameMetrics& metrics = apzc->GetFrameMetrics(); 46 return CSSRect(metrics.GetScrollableRect().TopLeft(), 47 metrics.GetScrollableRect().Size() - 48 metrics.CalculateCompositedSizeInCssPixels()); 49 } 50 TearDown()51 virtual void TearDown() { 52 while (mcc->RunThroughDelayedTasks()) 53 ; 54 apzc->Destroy(); 55 tm->ClearTree(); 56 tm->ClearContentController(); 57 } 58 MakeApzcWaitForMainThread()59 void MakeApzcWaitForMainThread() { apzc->SetWaitForMainThread(); } 60 MakeApzcZoomable()61 void MakeApzcZoomable() { 62 apzc->UpdateZoomConstraints(ZoomConstraints( 63 true, true, CSSToParentLayerScale(0.25f), CSSToParentLayerScale(4.0f))); 64 } 65 MakeApzcUnzoomable()66 void MakeApzcUnzoomable() { 67 apzc->UpdateZoomConstraints(ZoomConstraints(false, false, 68 CSSToParentLayerScale(1.0f), 69 CSSToParentLayerScale(1.0f))); 70 } 71 72 /** 73 * Sample animations once, 1 ms later than the last sample. 74 */ SampleAnimationOnce()75 void SampleAnimationOnce() { 76 const TimeDuration increment = TimeDuration::FromMilliseconds(1); 77 ParentLayerPoint pointOut; 78 AsyncTransform viewTransformOut; 79 mcc->AdvanceBy(increment); 80 apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut); 81 } 82 /** 83 * Sample animations one frame, 17 ms later than the last sample. 84 */ SampleAnimationOneFrame()85 void SampleAnimationOneFrame() { 86 const TimeDuration increment = TimeDuration::FromMilliseconds(17); 87 ParentLayerPoint pointOut; 88 AsyncTransform viewTransformOut; 89 mcc->AdvanceBy(increment); 90 apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut); 91 } 92 93 AsyncPanZoomController::GestureBehavior mGestureBehavior; 94 RefPtr<TestAPZCTreeManager> tm; 95 RefPtr<APZSampler> sampler; 96 RefPtr<APZUpdater> updater; 97 RefPtr<TestAsyncPanZoomController> apzc; 98 }; 99 100 #endif // mozilla_layers_APZCBasicTester_h 101