Bug 1169690 - Gtests. r=kats

This commit is contained in:
Botond Ballo 2015-06-03 19:38:50 -04:00
parent d39507d6ab
commit c2e7f78131
2 changed files with 70 additions and 2 deletions

View File

@ -545,6 +545,7 @@ public:
// HandleFlingOverscroll() (which acquires the tree lock) would violate
// the lock ordering. Instead we schedule HandleFlingOverscroll() to be
// called after mMonitor is released.
APZC_LOG("%p fling went into overscroll, handing off with velocity %s\n", &mApzc, Stringify(velocity).c_str());
mDeferredTasks.append(NewRunnableMethod(&mApzc,
&AsyncPanZoomController::HandleFlingOverscroll,
velocity,
@ -2131,6 +2132,7 @@ void AsyncPanZoomController::AcceptFling(const ParentLayerPoint& aVelocity,
bool aHandoff) {
// We may have a pre-existing velocity for whatever reason (for example,
// a previously handed off fling). We don't want to clobber that.
APZC_LOG("%p accepting fling with velocity %s\n", this, Stringify(aVelocity).c_str());
mX.SetVelocity(mX.GetVelocity() + aVelocity.x);
mY.SetVelocity(mY.GetVelocity() + aVelocity.y);
SetState(FLING);

View File

@ -206,6 +206,8 @@ public:
return mFrameMetrics;
}
using AsyncPanZoomController::GetVelocityVector;
void AssertStateIsReset() const {
ReentrantMonitorAutoEnter lock(mMonitor);
EXPECT_EQ(NOTHING, mState);
@ -1857,6 +1859,22 @@ protected:
manager->ClearTree();
}
/**
* Sample animations once for all APZCs, 1 ms later than the last sample.
*/
void SampleAnimationsOnce() {
const TimeDuration increment = TimeDuration::FromMilliseconds(1);
ParentLayerPoint pointOut;
ViewTransform viewTransformOut;
mcc->AdvanceBy(increment);
for (const nsRefPtr<Layer>& layer : layers) {
if (TestAsyncPanZoomController* apzc = ApzcOf(layer)) {
apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut);
}
}
}
nsRefPtr<MockContentControllerDelayed> mcc;
nsTArray<nsRefPtr<Layer> > layers;
@ -2528,14 +2546,15 @@ protected:
manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
}
void CreateScrollgrabLayerTree() {
void CreateScrollgrabLayerTree(bool makeParentScrollable = true) {
const char* layerTreeSyntax = "c(t)";
nsIntRegion layerVisibleRegion[] = {
nsIntRegion(IntRect(0, 0, 100, 100)), // scroll-grabbing parent
nsIntRegion(IntRect(0, 20, 100, 80)) // child
};
root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers);
SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 100, 120));
float parentHeight = makeParentScrollable ? 120 : 100;
SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 100, parentHeight));
SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1, CSSRect(0, 0, 100, 200));
SetScrollHandoff(layers[1], root);
registration = MakeUnique<ScopedLayerTreeRegistration>(0, root, mcc);
@ -2543,6 +2562,43 @@ protected:
rootApzc = ApzcOf(root);
rootApzc->GetFrameMetrics().SetHasScrollgrab(true);
}
void TestFlingAcceleration() {
// Jack up the fling acceleration multiplier so we can easily determine
// whether acceleration occured.
const float kAcceleration = 100.0f;
SCOPED_GFX_PREF(APZFlingAccelBaseMultiplier, float, kAcceleration);
nsRefPtr<TestAsyncPanZoomController> childApzc = ApzcOf(layers[1]);
// Pan once, enough to fully scroll the scrollgrab parent and then scroll
// and fling the child.
Pan(manager, mcc, 70, 40);
// Give the fling animation a chance to start.
SampleAnimationsOnce();
float childVelocityAfterFling1 = childApzc->GetVelocityVector().y;
// Pan again.
Pan(manager, mcc, 70, 40);
// Give the fling animation a chance to start.
// This time it should be accelerated.
SampleAnimationsOnce();
float childVelocityAfterFling2 = childApzc->GetVelocityVector().y;
// We should have accelerated once.
// The division by 2 is to account for friction.
EXPECT_GT(childVelocityAfterFling2,
childVelocityAfterFling1 * kAcceleration / 2);
// We should not have accelerated twice.
// The division by 4 is to account for friction.
EXPECT_LE(childVelocityAfterFling2,
childVelocityAfterFling1 * kAcceleration * kAcceleration / 4);
}
};
// Here we test that if the processing of a touch block is deferred while we
@ -2744,6 +2800,16 @@ TEST_F(APZOverscrollHandoffTester, ScrollgrabFling) {
childApzc->AssertStateIsReset();
}
TEST_F(APZOverscrollHandoffTester, ScrollgrabFlingAcceleration1) {
CreateScrollgrabLayerTree(true /* make parent scrollable */);
TestFlingAcceleration();
}
TEST_F(APZOverscrollHandoffTester, ScrollgrabFlingAcceleration2) {
CreateScrollgrabLayerTree(false /* do not make parent scrollable */);
TestFlingAcceleration();
}
class APZEventRegionsTester : public APZCTreeManagerTester {
protected:
UniquePtr<ScopedLayerTreeRegistration> registration;