Chromium Code Reviews| Index: views/view_unittest.cc |
| diff --git a/views/view_unittest.cc b/views/view_unittest.cc |
| index 03b7cfefa9433a8289cdc65a501e0f20fc1e5f1e..35e474e7f6c14f2b5e948c10ad081c75738525d8 100644 |
| --- a/views/view_unittest.cc |
| +++ b/views/view_unittest.cc |
| @@ -274,6 +274,48 @@ class TestViewIgnoreTouch : public TestView { |
| virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
| }; |
| +#if defined(TOUCH_UI) |
|
rjkroege
2011/11/10 16:34:40
add a TOOO about making this test work on non-X pl
Gajen
2011/11/11 13:39:07
Done.
|
| +// Test GestureManager for touch to mouse conversion. |
| +class TestGestureManager : 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); |
| + TestGestureManager(); |
| + |
| + bool previously_handled_flag_; |
| + int last_touch_event_; |
| + View *last_view_; |
| + bool dispatched_synthetic_event_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestGestureManager); |
| +}; |
| + |
| +// A TouchEvent with filled in native event part to ease touch to |
| +// mouse conversion. |
| +class MockTouchEvent : public TouchEvent { |
| + public: |
| + // Create a new touch event. |
| + MockTouchEvent(ui::EventType type, |
| + int x, |
| + int y, |
| + int flags, |
| + int touch_id, |
| + float radius_x, |
| + float radius_y, |
| + float angle, |
| + float force); |
| +}; |
| +#endif |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // OnBoundsChanged |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -381,6 +423,7 @@ TEST_F(ViewTest, MouseEvent) { |
| //////////////////////////////////////////////////////////////////////////////// |
| // TouchEvent |
| //////////////////////////////////////////////////////////////////////////////// |
| + |
|
rjkroege
2011/11/10 16:34:40
remove
Gajen
2011/11/11 13:39:07
Done.
|
| bool MockGestureManager::ProcessTouchEventForGesture( |
| const TouchEvent& event, |
| View* source, |
| @@ -537,6 +580,101 @@ TEST_F(ViewTest, TouchEvent) { |
| widget->CloseNow(); |
| } |
| +#if defined(TOUCH_UI) |
|
rjkroege
2011/11/10 16:34:40
there is lot of code in this file that assumes tou
Gajen
2011/11/11 13:39:07
Now placed, X11 based code and actual test "TouchT
|
| +bool TestGestureManager::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; |
| + return dispatched_synthetic_event_ = |
| + GestureManager::ProcessTouchEventForGesture(event, source, status); |
| +} |
| + |
| +TestGestureManager::TestGestureManager() { |
| +} |
| + |
| +MockTouchEvent::MockTouchEvent(ui::EventType type, |
| + int x, |
| + int y, |
| + int flags, |
| + int touch_id, |
| + float radius_x, |
| + float radius_y, |
| + float angle, |
| + float force) |
| + : TouchEvent(type, x, y, flags, touch_id, radius_x, radius_y, |
| + angle, force) { |
| + // Set XEvent and its internal fields. |
|
rjkroege
2011/11/10 16:34:40
this code could be completely portable with differ
Gajen
2011/11/11 13:39:07
Added new files test_event_utils/_x/.h/.cc under v
|
| + base::NativeEvent native_event = ui::GetNativeEventForTesting(); |
| + ui::SetNativeEventLocationForTesting(native_event, x, y); |
| + set_native_event(native_event); |
| +} |
| + |
| +// Tests Real GestureManager instead of the mock one and validates Touch event |
| +// to Mouse conversion when view hierarchy doesn't handle touch events. |
| +TEST_F(ViewTest, TouchToMouse) { |
| + TestGestureManager gm; |
| + |
| + TestView* v1 = new TestViewIgnoreTouch(); |
| + v1->SetBounds(0, 0, 300, 300); |
| + |
| + TestView* v2 = new TestViewIgnoreTouch(); |
| + v2->SetBounds(100, 100, 100, 100); |
| + |
| + scoped_ptr<Widget> widget(new Widget()); |
| + Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + params.bounds = gfx::Rect(50, 50, 650, 650); |
| + widget->Init(params); |
| + View* root = widget->GetRootView(); |
| + root->AddChildView(v1); |
| + static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm); |
| + v1->AddChildView(v2); |
| + |
| + // Test press. |
| + v1->Reset(); |
| + v2->Reset(); |
| + gm.Reset(); |
| + |
| + MockTouchEvent pressed(ui::ET_TOUCH_PRESSED, |
| + 110, |
| + 120, |
| + 0, /* no flags */ |
| + 0, /* first finger touch */ |
| + 1.0, 0.0, 1.0, 0.0); |
| + root->OnTouchEvent(pressed); |
| + |
| + EXPECT_EQ(v2->last_touch_event_type_, 0); |
| + 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 v1 and v2 didn't handled the touch-event, the gesture manager should |
| + // handle it. |
| + EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED); |
| + EXPECT_EQ(root, gm.last_view_); |
| + EXPECT_EQ(gm.previously_handled_flag_, false); |
| + EXPECT_EQ(gm.dispatched_synthetic_event_, true); |
| + |
| + // Check GestureManager converted Touch event to Mouse and propogates to v2 |
| + // but v1. |
| + EXPECT_EQ(v2->last_mouse_event_type_, ui::ET_MOUSE_PRESSED); |
| + EXPECT_EQ(v2->location_.x(), 10); |
| + EXPECT_EQ(v2->location_.y(), 20); |
| + EXPECT_EQ(v1->last_mouse_event_type_, 0); |
| + EXPECT_EQ(v1->location_.x(), 0); |
| + EXPECT_EQ(v1->location_.y(), 0); |
| + widget->CloseNow(); |
| +} |
| +#endif |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // Painting |
| //////////////////////////////////////////////////////////////////////////////// |