summaryrefslogtreecommitdiffstats
path: root/webkit/child/touch_fling_gesture_curve_unittest.cc
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 23:09:31 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 23:09:31 +0000
commitbd6da4796782dadd66ad6d580dfd3a9bed5641b2 (patch)
tree29b052f19a3592a5954c9390181c9ecce561fb69 /webkit/child/touch_fling_gesture_curve_unittest.cc
parent311a64be267032dce25cf7a1ee652a3bb233bf69 (diff)
downloadchromium_src-bd6da4796782dadd66ad6d580dfd3a9bed5641b2.zip
chromium_src-bd6da4796782dadd66ad6d580dfd3a9bed5641b2.tar.gz
chromium_src-bd6da4796782dadd66ad6d580dfd3a9bed5641b2.tar.bz2
move webkit/glue/touch_fling_* to webkit/child/
(pipelined on https://codereview.chromium.org/16424008/) TBR=jamesr@chromium.org BUG=237249 Review URL: https://codereview.chromium.org/16816003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/child/touch_fling_gesture_curve_unittest.cc')
-rw-r--r--webkit/child/touch_fling_gesture_curve_unittest.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/webkit/child/touch_fling_gesture_curve_unittest.cc b/webkit/child/touch_fling_gesture_curve_unittest.cc
new file mode 100644
index 0000000..5e4a90a
--- /dev/null
+++ b/webkit/child/touch_fling_gesture_curve_unittest.cc
@@ -0,0 +1,71 @@
+ // Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Tests for the TouchFlingGestureCurve.
+
+#include "webkit/child/touch_fling_gesture_curve.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebFloatPoint.h"
+#include "third_party/WebKit/public/platform/WebFloatSize.h"
+#include "third_party/WebKit/public/platform/WebGestureCurve.h"
+#include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
+#include "third_party/WebKit/public/platform/WebSize.h"
+
+using WebKit::WebFloatPoint;
+using WebKit::WebFloatSize;
+using WebKit::WebGestureCurve;
+using WebKit::WebGestureCurveTarget;
+using WebKit::WebSize;
+
+namespace {
+
+class MockGestureCurveTarget : public WebGestureCurveTarget {
+ public:
+ virtual void scrollBy(const WebFloatSize& delta) {
+ cumulative_delta_.width += delta.width;
+ cumulative_delta_.height += delta.height;
+ }
+
+ virtual void notifyCurrentFlingVelocity(const WebFloatSize& velocity) {
+ current_velocity_ = velocity;
+ }
+
+ WebFloatSize cumulative_delta() const { return cumulative_delta_; }
+ void resetCumulativeDelta() { cumulative_delta_ = WebFloatSize(); }
+
+ WebFloatSize current_velocity() const { return current_velocity_; }
+
+ private:
+ WebFloatSize cumulative_delta_;
+ WebFloatSize current_velocity_;
+};
+
+} // namespace anonymous
+
+TEST(TouchFlingGestureCurve, flingCurveTouch)
+{
+ double initialVelocity = 5000;
+ MockGestureCurveTarget target;
+
+ scoped_ptr<WebGestureCurve> curve(webkit_glue::TouchFlingGestureCurve::Create(
+ WebFloatPoint(initialVelocity, 0),
+ -5.70762e+03f, 1.72e+02f, 3.7e+00f, WebSize()));
+
+ // Note: the expectations below are dependent on the curve parameters hard
+ // coded into the create call above.
+ EXPECT_TRUE(curve->apply(0, &target));
+ EXPECT_TRUE(curve->apply(0.25, &target));
+ EXPECT_NEAR(target.current_velocity().width, 1878, 1);
+ EXPECT_EQ(target.current_velocity().height, 0);
+ EXPECT_TRUE(curve->apply(0.45f, &target)); // Use non-uniform tick spacing.
+ EXPECT_TRUE(curve->apply(1, &target));
+ EXPECT_FALSE(curve->apply(1.5, &target));
+ EXPECT_NEAR(target.cumulative_delta().width, 1193, 1);
+ EXPECT_EQ(target.cumulative_delta().height, 0);
+ EXPECT_EQ(target.current_velocity().width, 0);
+ EXPECT_EQ(target.current_velocity().height, 0);
+}
+