| Index: ui/events/gestures/touch_point_state_unittest.cc
|
| diff --git a/ui/events/gestures/touch_point_state_unittest.cc b/ui/events/gestures/touch_point_state_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f4521b3b85cb21bb8b33c8bab8926163d56fb6f2
|
| --- /dev/null
|
| +++ b/ui/events/gestures/touch_point_state_unittest.cc
|
| @@ -0,0 +1,119 @@
|
| +// Copyright 2013 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.
|
| +
|
| +#include "testing/gtest/include/gtest/gtest-spi.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/events/gestures/test/eager_gesture_recognition_test_base.h"
|
| +#include "ui/events/gestures/touch_point_state.h"
|
| +
|
| +namespace ui {
|
| +
|
| +// Printing helper to allow gtest to give helpful error output.
|
| +static std::ostream& operator<<(std::ostream& os,
|
| + const ui::TouchPointState& tps) {
|
| + return os << "TouchPointState(" << tps.touch_id()
|
| + << ", " << (tps.has_press() ? "true" : "false")
|
| + << ", " << (tps.has_release() ? "true" : "false")
|
| + << ", " << tps.move_count()
|
| + << ", " << tps.timer_count()
|
| + << ")";
|
| +}
|
| +
|
| +namespace test {
|
| +
|
| +class TouchPointStateTest : public EagerGestureRecognitionTestBase {
|
| + public:
|
| + TouchPointStateTest() {}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TouchPointStateTest);
|
| +};
|
| +
|
| +TEST_F(TouchPointStateTest, InitializeTouchPointState) {
|
| + TouchPointState tps(0);
|
| + EXPECT_EQ(TouchPointState(0, false, false, 0, 0), tps);
|
| + tps.Update(Press(0));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 0), tps);
|
| +}
|
| +
|
| +TEST_F(TouchPointStateTest, UpdateTouchPointState) {
|
| + TouchPointState tps(0);
|
| + EXPECT_EQ(TouchPointState(0, false, false, 0, 0), tps);
|
| + tps.Update(Press(0));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 0), tps);
|
| +
|
| + tps.Update(Move(0));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 1, 0), tps);
|
| + tps.Update(Move(0));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 2, 0), tps);
|
| + tps.Update(Move(0));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 3, 0), tps);
|
| +
|
| + tps.Update(Release(0));
|
| + EXPECT_EQ(TouchPointState(0, true, true, 3, 0), tps);
|
| +}
|
| +
|
| +TEST_F(TouchPointStateTest, Contains) {
|
| + EXPECT_TRUE(TouchPointState(0, false, false, 0, 0).
|
| + Contains(TouchPointState(0, false, false, 0, 0)));
|
| + EXPECT_TRUE(TouchPointState(0, false, false, 1, 0).
|
| + Contains(TouchPointState(0, false, false, 0, 0)));
|
| + EXPECT_FALSE(TouchPointState(0, false, false, 0, 0).
|
| + Contains(TouchPointState(0, true, false, 0, 0)));
|
| + EXPECT_FALSE(TouchPointState(0, false, false, 0, 0).
|
| + Contains(TouchPointState(0, false, false, 5, 0)));
|
| +}
|
| +
|
| +TEST_F(TouchPointStateTest, EmptyIntersection) {
|
| + EXPECT_TRUE(TouchPointState(0, false, false, 0, 0).
|
| + HasEmptyIntersection(TouchPointState(0, false, false, 0, 0)));
|
| + EXPECT_TRUE(TouchPointState(0, false, false, 1, 0).
|
| + HasEmptyIntersection(TouchPointState(0, true, false, 0, 0)));
|
| + EXPECT_FALSE(TouchPointState(0, false, false, 1, 0).
|
| + HasEmptyIntersection(TouchPointState(0, false, false, 1, 0)));
|
| + EXPECT_FALSE(TouchPointState(0, true, false, 0, 0).
|
| + HasEmptyIntersection(TouchPointState(0, true, false, 5, 0)));
|
| +}
|
| +
|
| +TEST_F(TouchPointStateTest, CopyForGestureType) {
|
| + TouchPointState tps1(0, true, true, 1, 1);
|
| + scoped_ptr<TouchPointState> tps1_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_SCROLL_BEGIN,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 1, 0), *tps1_filtered.get());
|
| +
|
| + TouchPointState tps2(0, true, true, 1, 0);
|
| + scoped_ptr<TouchPointState> tps2_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_TAP,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(tps2, *tps2_filtered.get());
|
| +
|
| + TouchPointState tps3(0, true, true, 1, 0);
|
| + scoped_ptr<TouchPointState> tps3_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_TAP_DOWN,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 0), *tps3_filtered.get());
|
| +
|
| + TouchPointState tps4(0, true, true, 1, 1);
|
| + scoped_ptr<TouchPointState> tps4_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_BEGIN,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 0), *tps4_filtered.get());
|
| +
|
| + TouchPointState tps5(0, true, true, 1, 2);
|
| + scoped_ptr<TouchPointState> tps5_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_LONG_PRESS,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 2), *tps5_filtered.get());
|
| +
|
| + TouchPointState tps6(0, true, true, 1, 2);
|
| + scoped_ptr<TouchPointState> tps6_filtered(
|
| + tps1.CopyForGestureType(ET_GESTURE_SHOW_PRESS,
|
| + TouchPointState::WAIT_FOR_ACK));
|
| + EXPECT_EQ(TouchPointState(0, true, false, 0, 1), *tps6_filtered.get());
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace ui
|
|
|