summaryrefslogtreecommitdiffstats
path: root/ui/views/view_unittest.cc
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 00:48:01 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 00:48:01 +0000
commit912b6f3be7f1e31b4107ecb8b572245d9f65ff47 (patch)
treed43a9f10d01316cc817cd7619f1561e0ed279e04 /ui/views/view_unittest.cc
parent7d692835b4257b2621f969037f52e1dca67d833e (diff)
downloadchromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.zip
chromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.tar.gz
chromium_src-912b6f3be7f1e31b4107ecb8b572245d9f65ff47.tar.bz2
aura: Move GestureRecognizer from views into aura.
Remove deprecated GestureManager, and move the functional GestureRecognizer from views into aura. BUG=110227 TEST=views_unittests:GestureEvent, aura_unittests:GestureRecognizerTest Review URL: https://chromiumcodereview.appspot.com/9255019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/view_unittest.cc')
-rw-r--r--ui/views/view_unittest.cc371
1 files changed, 33 insertions, 338 deletions
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 73f52e9..45e7dbd 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -29,8 +29,6 @@
#include "ui/views/focus/accelerator_handler.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/touchui/gesture_manager.h"
-#include "ui/views/touchui/gesture_recognizer.h"
#include "ui/views/view.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget.h"
@@ -41,8 +39,9 @@
#include "ui/views/test/test_views_delegate.h"
#endif
#if defined(USE_AURA)
+#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
-#include "ui/views/touchui/gesture_recognizer.h"
+#include "ui/aura/gestures/gesture_recognizer.h"
#endif
#if !defined(USE_WEBKIT_COMPOSITOR)
#include "ui/gfx/compositor/test/test_texture.h"
@@ -252,51 +251,6 @@ class TestView : public View {
std::map<ui::Accelerator, int> accelerator_count_map_;
};
-// Mock instance of the GestureManager for testing.
-class MockGestureManager : public GestureManager {
- public:
- // Reset all test state.
- void Reset() {
- last_touch_event_ = 0;
- last_view_ = NULL;
- previously_handled_flag_ = false;
- dispatched_synthetic_event_ = false;
- }
-
- bool ProcessTouchEventForGesture(const TouchEvent& event,
- View* source,
- ui::TouchStatus status);
- MockGestureManager();
-
- bool previously_handled_flag_;
- int last_touch_event_;
- View *last_view_;
- bool dispatched_synthetic_event_;
-
- DISALLOW_COPY_AND_ASSIGN(MockGestureManager);
-};
-
-// GestureRecognizer for testing.
-class TestGestureRecognizer : public GestureRecognizer {
- public:
- TestGestureRecognizer();
-
- // Reset all test state.
- void reset() {
- last_touch_event_ = 0;
- previously_handled_flag_ = false;
- }
-
- virtual Gestures* ProcessTouchEventForGesture(
- const TouchEvent& event,
- ui::TouchStatus status) OVERRIDE;
-
- bool previously_handled_flag_;
- int last_touch_event_;
-
- DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer);
-};
-
// A view subclass that ignores all touch events for testing purposes.
class TestViewIgnoreTouch : public TestView {
public:
@@ -314,23 +268,27 @@ class TestViewConsumeGesture : public TestView {
virtual ~TestViewConsumeGesture() {}
private:
- virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
- virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE;
+ virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE {
+ last_gesture_event_type_ = event.type();
+ location_.SetPoint(event.x(), event.y());
+ return ui::GESTURE_STATUS_CONSUMED;
+ }
DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture);
};
-// A view subclass that ignores all Gesture and touch events.
-class TestViewIgnoreTouchAndGesture: public TestView {
+// A view subclass that ignores all Gesture events.
+class TestViewIgnoreGesture: public TestView {
public:
- TestViewIgnoreTouchAndGesture() : TestView() {}
- virtual ~TestViewIgnoreTouchAndGesture() {}
+ TestViewIgnoreGesture() : TestView() {}
+ virtual ~TestViewIgnoreGesture() {}
private:
- virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
- virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE;
+ virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE {
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
- DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreTouchAndGesture);
+ DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture);
};
////////////////////////////////////////////////////////////////////////////////
@@ -440,24 +398,6 @@ TEST_F(ViewTest, MouseEvent) {
////////////////////////////////////////////////////////////////////////////////
// TouchEvent
////////////////////////////////////////////////////////////////////////////////
-bool MockGestureManager::ProcessTouchEventForGesture(
- const TouchEvent& event,
- View* source,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN) {
- dispatched_synthetic_event_ = false;
- return false;
- }
- last_touch_event_ = event.type();
- last_view_ = source;
- previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN;
- dispatched_synthetic_event_ = true;
- return true;
-}
-
-MockGestureManager::MockGestureManager() {
-}
-
ui::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) {
last_touch_event_type_ = event.type();
location_.SetPoint(event.x(), event.y());
@@ -482,8 +422,6 @@ ui::TouchStatus TestViewIgnoreTouch::OnTouchEvent(const TouchEvent& event) {
}
TEST_F(ViewTest, TouchEvent) {
- MockGestureManager gm;
-
TestView* v1 = new TestView();
v1->SetBounds(0, 0, 300, 300);
@@ -501,7 +439,6 @@ TEST_F(ViewTest, TouchEvent) {
View* root = widget->GetRootView();
root->AddChildView(v1);
- static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm);
v1->AddChildView(v2);
v2->AddChildView(v3);
@@ -512,7 +449,6 @@ TEST_F(ViewTest, TouchEvent) {
// does.
v1->Reset();
v2->Reset();
- gm.Reset();
TouchEvent unhandled(ui::ET_TOUCH_MOVED,
400,
@@ -525,15 +461,9 @@ TEST_F(ViewTest, TouchEvent) {
EXPECT_EQ(v1->last_touch_event_type_, 0);
EXPECT_EQ(v2->last_touch_event_type_, 0);
- EXPECT_EQ(gm.previously_handled_flag_, false);
- EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_MOVED);
- EXPECT_EQ(gm.last_view_, root);
- EXPECT_EQ(gm.dispatched_synthetic_event_, true);
-
// Test press, drag, release touch sequence.
v1->Reset();
v2->Reset();
- gm.Reset();
TouchEvent pressed(ui::ET_TOUCH_PRESSED,
110,
@@ -550,11 +480,6 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- // Since v2 handled the touch-event, the gesture manager should not handle it.
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
// Drag event out of bounds. Should still go to v2
v1->Reset();
v2->Reset();
@@ -572,10 +497,6 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
// Released event out of bounds. Should still go to v2
v1->Reset();
v2->Reset();
@@ -589,79 +510,24 @@ TEST_F(ViewTest, TouchEvent) {
// Make sure v1 did not receive the event
EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(gm.last_touch_event_, 0);
- EXPECT_EQ(NULL, gm.last_view_);
- EXPECT_EQ(gm.previously_handled_flag_, false);
-
widget->CloseNow();
}
-////////////////////////////////////////////////////////////////////////////////
-// GestureEvent
-////////////////////////////////////////////////////////////////////////////////
-
-GestureRecognizer::Gestures* TestGestureRecognizer::ProcessTouchEventForGesture(
- const TouchEvent& event,
- ui::TouchStatus status) {
- if (status != ui::TOUCH_STATUS_UNKNOWN) {
- return NULL;
- }
- last_touch_event_ = event.type();
- previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN;
- return GestureRecognizer::ProcessTouchEventForGesture(event, status);
-}
-
-TestGestureRecognizer::TestGestureRecognizer() {
-}
-
ui::GestureStatus TestView::OnGestureEvent(const GestureEvent& event) {
return ui::GESTURE_STATUS_UNKNOWN;
}
-// GestureConsumer view should ignore TouchEvent for testing purposes.
-ui::TouchStatus TestViewConsumeGesture::OnTouchEvent(
- const TouchEvent& event) {
- return ui::TOUCH_STATUS_UNKNOWN;
-}
-
-ui::GestureStatus TestViewConsumeGesture::OnGestureEvent(
- const GestureEvent& event) {
- last_gesture_event_type_ = event.type();
- location_.SetPoint(event.x(), event.y());
- return ui::GESTURE_STATUS_CONSUMED;
-}
-
-// IgnoreTouchAndGesture view should ignore touch and Gesture event for
-// testing purposes.
-ui::TouchStatus TestViewIgnoreTouchAndGesture::OnTouchEvent(
- const TouchEvent& event) {
- return ui::TOUCH_STATUS_UNKNOWN;
-}
-
-ui::GestureStatus TestViewIgnoreTouchAndGesture::OnGestureEvent(
- const GestureEvent& event) {
- return ui::GESTURE_STATUS_UNKNOWN;
-}
-
-#if defined(TOUCH_UI)
TEST_F(ViewTest, GestureEvent) {
- MockGestureManager gm;
- TestGestureRecognizer gr;
-
// Views hierarchy for non delivery of GestureEvent.
TestView* v1 = new TestViewConsumeGesture();
v1->SetBounds(0, 0, 300, 300);
- TestView* v2 = new TestView();
+ TestView* v2 = new TestViewConsumeGesture();
v2->SetBounds(100, 100, 100, 100);
- TestView* v3 = new TestViewConsumeGesture();
+ TestView* v3 = new TestViewIgnoreGesture();
v3->SetBounds(0, 0, 100, 100);
- // Views hierarchy for delivery of GestureEvent.
- TestView* v4 = new TestViewConsumeGesture();
- v4->SetBounds(200, 200, 100, 100);
-
scoped_ptr<Widget> widget(new Widget());
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -670,209 +536,38 @@ TEST_F(ViewTest, GestureEvent) {
View* root = widget->GetRootView();
root->AddChildView(v1);
- static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm);
- static_cast<internal::RootView*>(root)->SetGestureRecognizerForTesting(&gr);
v1->AddChildView(v2);
v2->AddChildView(v3);
- v1->AddChildView(v4);
-
- // |v3| completely obscures |v2|, but all the touch events on |v3| should
- // reach |v2| because |v3| doesn't process any touch events, hence no gesture
- // conversion take place.
- // Both |v4| and |v1| ignore touch events, hence |v4| should recieve gesture
- // events.
+ // |v3| completely obscures |v2|, but all the gesture events on |v3| should
+ // reach |v2| because |v3| doesn't process any gesture events. However, since
+ // |v2| does process gesture events, gesture events on |v3| or |v2| should not
+ // reach |v1|.
- // Make sure if none of the views handle the touch event, the gesture manager
- // does.
v1->Reset();
v2->Reset();
v3->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent unhandled(ui::ET_TOUCH_MOVED,
- 400,
- 400,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(unhandled);
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v2->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, 0);
-
- EXPECT_EQ(gr.previously_handled_flag_, false);
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_MOVED);
+ // Gesture on |v3|
+ GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0);
+ root->OnGestureEvent(g1);
+ EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_);
+ EXPECT_EQ(gfx::Point(10, 10), v2->location_);
+ EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_);
- // Test press, drag, release touch sequence.
v1->Reset();
v2->Reset();
v3->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent pressed(ui::ET_TOUCH_PRESSED,
- 110,
- 120,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- v2->last_touch_event_was_handled_ = true;
- root->OnTouchEvent(pressed);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(v2->location_.x(), 10);
- EXPECT_EQ(v2->location_.y(), 20);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- // Since v2 handled the touch-event, the gesture recognizer should not
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
+ // Gesture on |v1|
+ GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0);
+ root->OnGestureEvent(g2);
+ EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_);
+ EXPECT_EQ(gfx::Point(80, 80), v1->location_);
+ EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_);
- // Drag event out of bounds. Should still go to v2
- v1->Reset();
- v2->Reset();
- TouchEvent dragged(ui::ET_TOUCH_MOVED,
- 50,
- 40,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(dragged);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_MOVED);
- EXPECT_EQ(v2->location_.x(), -50);
- EXPECT_EQ(v2->location_.y(), -60);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Released event out of bounds. Should still go to v2
- v1->Reset();
- v2->Reset();
- TouchEvent released(ui::ET_TOUCH_RELEASED, 0, 0, 0, 0 /* first finger */,
- 1.0, 0.0, 1.0, 0.0);
- v2->last_touch_event_was_handled_ = true;
- root->OnTouchEvent(released);
- EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED);
- EXPECT_EQ(v2->location_.x(), -100);
- EXPECT_EQ(v2->location_.y(), -100);
- // Make sure v1 did not receive the event
- EXPECT_EQ(v1->last_touch_event_type_, 0);
-
- EXPECT_EQ(gr.last_touch_event_, 0);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Gesture event handling test.
- // 1) Test gesture type ui::ET_GESTURE_TAP_DOWN.
- v1->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent second_pressed(ui::ET_TOUCH_PRESSED,
- 210,
- 220,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- base::Time pressed_time = second_pressed.time_stamp();
- root->OnTouchEvent(second_pressed);
-
- // Since v1 and V4 didn't handled touch event, the gesture manager should
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Check v4 should receive gesture event but not v1.
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP_DOWN);
- EXPECT_EQ(v4->location_.x(), 10);
- EXPECT_EQ(v4->location_.y(), 20);
-
- // 2) Test gesture type ui::ET_GESTURE_TAP.
- v1->Reset();
- v4->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent second_released(ui::ET_TOUCH_RELEASED,
- 210,
- 220,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
-
- // Set touch time with-in click window.
- second_released.set_time_stamp(base::Time::FromDoubleT(
- pressed_time.ToDoubleT() + 0.7));
- root->OnTouchEvent(second_released);
-
- // Since v1 and V4 didn't handled touch event, the gesture manager should
- // handle it.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_RELEASED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
-
- // Check v4 should receive gesture event but not v1.
- EXPECT_EQ(v1->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_touch_event_type_, 0);
- EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP);
- EXPECT_EQ(v4->location_.x(), 10);
- EXPECT_EQ(v4->location_.y(), 20);
-
- // 3) Test Gesture to mouse conversion.
- // Views hierarchy for delivery of mouse event in absence of Touch and
- // Gesture handlers.
- TestView* v5 = new TestViewIgnoreTouchAndGesture();
- v5->SetBounds(0, 0, 300, 300);
-
- TestView* v6 = new TestViewIgnoreTouchAndGesture();
- v6->SetBounds(100, 100, 100, 100);
-
- root->AddChildView(v5);
- v5->AddChildView(v6);
-
- v5->Reset();
- v6->Reset();
- gr.reset();
- gm.Reset();
-
- TouchEvent third_pressed(ui::ET_TOUCH_PRESSED,
- 110,
- 120,
- 0, /* no flags */
- 0, /* first finger touch */
- 1.0, 0.0, 1.0, 0.0);
- root->OnTouchEvent(third_pressed);
-
- // Since v5 and V6 didn't handled touch and gesture event, gesture recognizer
- // and manager should recieve touch event.
- EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gr.previously_handled_flag_, false);
- EXPECT_EQ(gm.previously_handled_flag_, false);
- EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED);
- EXPECT_EQ(gm.last_view_, root);
- EXPECT_EQ(gm.dispatched_synthetic_event_, true);
-
- // Check v6 shouldn't recieve touch and gesture event but mouse event.
- EXPECT_EQ(v6->last_touch_event_type_, 0);
- EXPECT_EQ(v6->last_gesture_event_type_, 0);
-
- // Check v5 shouldn't recieve touch, gesture and mouse event.
- EXPECT_EQ(v5->last_touch_event_type_, 0);
- EXPECT_EQ(v5->last_gesture_event_type_, 0);
widget->CloseNow();
}
-#endif
////////////////////////////////////////////////////////////////////////////////
// Painting