Bug 1031024 - Fix up the OverScrollPanning gtest to actually test overscrolling. r=drs

This commit is contained in:
Kartikaya Gupta 2014-06-27 16:39:11 -04:00
parent e4dd591b98
commit 1ab71deca1

View File

@ -13,6 +13,7 @@
#include "mozilla/layers/GeckoContentController.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/Preferences.h"
#include "base/task.h"
#include "Layers.h"
#include "TestLayers.h"
@ -58,6 +59,24 @@ public:
MOCK_METHOD2(PostDelayedTask, void(Task* aTask, int aDelayMs));
};
class TestScopedBoolPref {
public:
TestScopedBoolPref(const char* aPref, bool aVal)
: mPref(aPref)
{
mOldVal = Preferences::GetBool(aPref);
Preferences::SetBool(aPref, aVal);
}
~TestScopedBoolPref() {
Preferences::SetBool(mPref, mOldVal);
}
private:
const char* mPref;
bool mOldVal;
};
class MockContentControllerDelayed : public MockContentController {
public:
MockContentControllerDelayed()
@ -884,6 +903,8 @@ TEST_F(AsyncPanZoomControllerTester, FlingStopTap) {
}
TEST_F(AsyncPanZoomControllerTester, OverScrollPanning) {
TestScopedBoolPref overscrollEnabledPref("apz.overscroll.enabled", true);
TimeStamp testStartTime = TimeStamp::Now();
AsyncPanZoomController::SetFrameTime(testStartTime);
@ -894,21 +915,41 @@ TEST_F(AsyncPanZoomControllerTester, OverScrollPanning) {
apzc->SetFrameMetrics(TestFrameMetrics());
apzc->NotifyLayersUpdated(TestFrameMetrics(), true);
EXPECT_CALL(*mcc, SendAsyncScrollDOMEvent(_,_,_)).Times(AtLeast(1));
EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(1);
// Pan sufficiently to hit overscroll behavior
int time = 0;
int touchStart = 500;
int touchEnd = 10;
ApzcPan(apzc, tm, time, touchStart, touchEnd);
EXPECT_TRUE(apzc->IsOverscrolled());
// Note that in the calls to SampleContentTransformForFrame below, the time
// increment used is sufficiently large for the animation to have completed. However,
// any single call to SampleContentTransformForFrame will not finish an animation
// *and* also proceed through the following animation, if there is one.
// Therefore the minimum number of calls to go from an overscroll-inducing pan
// to a reset state is 3; these are documented further below.
ScreenPoint pointOut;
ViewTransform viewTransformOut;
// Pan down
ApzcPan(apzc, tm, time, touchStart, touchEnd);
apzc->SampleContentTransformForFrame(testStartTime+TimeDuration::FromMilliseconds(1000), &viewTransformOut, pointOut);
// This sample will run to the end of the non-overscrolling fling animation
// and will schedule the overscrolling fling animation.
apzc->SampleContentTransformForFrame(testStartTime + TimeDuration::FromMilliseconds(10000), &viewTransformOut, pointOut);
EXPECT_EQ(ScreenPoint(0, 90), pointOut);
EXPECT_TRUE(apzc->IsOverscrolled());
// This sample will run to the end of the overscrolling fling animation and
// will schedule the snapback animation.
apzc->SampleContentTransformForFrame(testStartTime + TimeDuration::FromMilliseconds(20000), &viewTransformOut, pointOut);
EXPECT_EQ(ScreenPoint(0, 90), pointOut);
EXPECT_TRUE(apzc->IsOverscrolled());
// This sample will run to the end of the snapback animation and reset the state.
apzc->SampleContentTransformForFrame(testStartTime + TimeDuration::FromMilliseconds(30000), &viewTransformOut, pointOut);
EXPECT_EQ(ScreenPoint(0, 90), pointOut);
EXPECT_FALSE(apzc->IsOverscrolled());
apzc->AssertStateIsReset();
apzc->Destroy();
}