APZCBasicTester.h (4044B)
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) 24 : mGestureBehavior(aGestureBehavior) {} 25 26 protected: 27 virtual void SetUp() { 28 APZCTesterBase::SetUp(); 29 APZThreadUtils::SetThreadAssertionsEnabled(false); 30 APZThreadUtils::SetControllerThread(NS_GetCurrentThread()); 31 32 tm = CreateTreeManager(); 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 // Since we're working with just one APZC, make it the root-content one. 40 // Tests that want to test the behaviour of a non-root-content APZC 41 // generally want to do so in a context where it has a root-content 42 // ancestor, and so would use APZCTreeManagerTester. 43 // Note that some tests overwrite the initial FrameMetrics; such tests 44 // still need to take care that the root-content flag is set on the new 45 // FrameMetrics they set (if they care about root-content behaviours like 46 // zooming). 47 apzc->GetFrameMetrics().SetIsRootContent(true); 48 } 49 50 /** 51 * Get the APZC's scroll range in CSS pixels. 52 */ 53 CSSRect GetScrollRange() const { 54 const FrameMetrics& metrics = apzc->GetFrameMetrics(); 55 return CSSRect(metrics.GetScrollableRect().TopLeft(), 56 metrics.GetScrollableRect().Size() - 57 metrics.CalculateCompositedSizeInCssPixels()); 58 } 59 60 virtual TestAPZCTreeManager* CreateTreeManager() { 61 return new TestAPZCTreeManager(mcc); 62 } 63 64 virtual void TearDown() { 65 while (mcc->RunThroughDelayedTasks()); 66 apzc->Destroy(); 67 tm->ClearTree(); 68 tm->ClearContentController(); 69 70 APZCTesterBase::TearDown(); 71 } 72 73 void MakeApzcWaitForMainThread() { apzc->SetWaitForMainThread(); } 74 75 void MakeApzcZoomable() { 76 MOZ_ASSERT(apzc->GetFrameMetrics().IsRootContent()); 77 apzc->UpdateZoomConstraints(ZoomConstraints( 78 true, true, CSSToParentLayerScale(0.25f), CSSToParentLayerScale(4.0f))); 79 } 80 81 void MakeApzcUnzoomable() { 82 apzc->UpdateZoomConstraints(ZoomConstraints(false, false, 83 CSSToParentLayerScale(1.0f), 84 CSSToParentLayerScale(1.0f))); 85 } 86 87 /** 88 * Sample animations once, 1 ms later than the last sample. 89 */ 90 bool SampleAnimationOnce() { 91 const TimeDuration increment = TimeDuration::FromMilliseconds(1); 92 ParentLayerPoint pointOut; 93 AsyncTransform viewTransformOut; 94 mcc->AdvanceBy(increment); 95 return apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut); 96 } 97 /** 98 * Sample animations one frame, 17 ms later than the last sample. 99 */ 100 bool SampleAnimationOneFrame() { 101 const TimeDuration increment = TimeDuration::FromMilliseconds(17); 102 ParentLayerPoint pointOut; 103 AsyncTransform viewTransformOut; 104 mcc->AdvanceBy(increment); 105 return apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut); 106 } 107 108 AsyncPanZoomController::GestureBehavior mGestureBehavior; 109 RefPtr<TestAPZCTreeManager> tm; 110 RefPtr<APZSampler> sampler; 111 RefPtr<APZUpdater> updater; 112 RefPtr<TestAsyncPanZoomController> apzc; 113 }; 114 115 #endif // mozilla_layers_APZCBasicTester_h