Get foreground tab on Android
[chromium-blink-merge.git] / webkit / child / touch_fling_gesture_curve_unittest.cc
blob91b06092bbecf8b2b91847819c025c9736c8de89
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Tests for the TouchFlingGestureCurve.
7 #include "webkit/child/touch_fling_gesture_curve.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
12 #include "third_party/WebKit/public/platform/WebFloatSize.h"
13 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
14 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
15 #include "third_party/WebKit/public/platform/WebSize.h"
17 using blink::WebFloatPoint;
18 using blink::WebFloatSize;
19 using blink::WebGestureCurve;
20 using blink::WebGestureCurveTarget;
21 using blink::WebSize;
23 namespace {
25 class MockGestureCurveTarget : public WebGestureCurveTarget {
26 public:
27 virtual void scrollBy(const WebFloatSize& delta) {
28 cumulative_delta_.width += delta.width;
29 cumulative_delta_.height += delta.height;
32 virtual void notifyCurrentFlingVelocity(const WebFloatSize& velocity) {
33 current_velocity_ = velocity;
36 WebFloatSize cumulative_delta() const { return cumulative_delta_; }
37 void resetCumulativeDelta() { cumulative_delta_ = WebFloatSize(); }
39 WebFloatSize current_velocity() const { return current_velocity_; }
41 private:
42 WebFloatSize cumulative_delta_;
43 WebFloatSize current_velocity_;
46 } // namespace anonymous
48 TEST(TouchFlingGestureCurve, flingCurveTouch)
50 double initialVelocity = 5000;
51 MockGestureCurveTarget target;
53 scoped_ptr<WebGestureCurve> curve(webkit_glue::TouchFlingGestureCurve::Create(
54 WebFloatPoint(initialVelocity, 0),
55 -5.70762e+03f, 1.72e+02f, 3.7e+00f, WebSize()));
57 // Note: the expectations below are dependent on the curve parameters hard
58 // coded into the create call above.
59 EXPECT_TRUE(curve->apply(0, &target));
60 EXPECT_TRUE(curve->apply(0.25, &target));
61 EXPECT_NEAR(target.current_velocity().width, 1878, 1);
62 EXPECT_EQ(target.current_velocity().height, 0);
63 EXPECT_TRUE(curve->apply(0.45f, &target)); // Use non-uniform tick spacing.
64 EXPECT_TRUE(curve->apply(1, &target));
65 EXPECT_FALSE(curve->apply(1.5, &target));
66 EXPECT_NEAR(target.cumulative_delta().width, 1193, 1);
67 EXPECT_EQ(target.cumulative_delta().height, 0);
68 EXPECT_EQ(target.current_velocity().width, 0);
69 EXPECT_EQ(target.current_velocity().height, 0);