Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: ui/views/view_unittest.cc

Issue 404213003: [WIP] Allow scroll events to permanently change the default gesture handler in RootView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: friend test Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index b1cac7eef7be8f3c13a1c38a7168a373277634b8..544e9997450b7643b940e0d388a0c42600f241ec 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -18,7 +18,6 @@
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/events/event.h"
-#include "ui/events/gestures/gesture_recognizer.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/path.h"
@@ -177,18 +176,6 @@ void ScrambleTree(views::View* view) {
view->SetVisible(!view->visible());
}
-// Convenience to make constructing a GestureEvent simpler.
-class GestureEventForTest : public ui::GestureEvent {
- public:
- GestureEventForTest(ui::EventType type, int x, int y, int flags)
- : GestureEvent(x, y, flags, base::TimeDelta(),
- ui::GestureEventDetails(type, 0.0f, 0.0f)) {
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GestureEventForTest);
-};
-
} // namespace
namespace views {
@@ -212,8 +199,6 @@ class TestView : public View {
location_.SetPoint(0, 0);
received_mouse_enter_ = false;
received_mouse_exit_ = false;
- last_gesture_event_type_ = 0;
- last_gesture_event_was_handled_ = false;
last_clip_.setEmpty();
accelerator_count_map_.clear();
can_process_events_within_subtree_ = true;
@@ -245,9 +230,6 @@ class TestView : public View {
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
- // Ignores GestureEvent by default.
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
-
virtual void Paint(gfx::Canvas* canvas, const CullSet& cull_set) OVERRIDE;
virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
@@ -269,10 +251,6 @@ class TestView : public View {
// Painting.
std::vector<gfx::Rect> scheduled_paint_rects_;
- // GestureEvent
- int last_gesture_event_type_;
- bool last_gesture_event_was_handled_;
-
// Painting.
SkRect last_clip_;
@@ -286,53 +264,6 @@ class TestView : public View {
bool can_process_events_within_subtree_;
};
-// A view subclass that consumes all Gesture events for testing purposes.
-class TestViewConsumeGesture : public TestView {
- public:
- TestViewConsumeGesture() : TestView() {}
- virtual ~TestViewConsumeGesture() {}
-
- protected:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
- last_gesture_event_type_ = event->type();
- location_.SetPoint(event->x(), event->y());
- event->StopPropagation();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture);
-};
-
-// A view subclass that ignores all Gesture events.
-class TestViewIgnoreGesture: public TestView {
- public:
- TestViewIgnoreGesture() : TestView() {}
- virtual ~TestViewIgnoreGesture() {}
-
- private:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
- }
-
- DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture);
-};
-
-// A view subclass that ignores all scroll-gesture events, but consume all other
-// gesture events.
-class TestViewIgnoreScrollGestures : public TestViewConsumeGesture {
- public:
- TestViewIgnoreScrollGestures() {}
- virtual ~TestViewIgnoreScrollGestures() {}
-
- private:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
- if (event->IsScrollGestureEvent())
- return;
- TestViewConsumeGesture::OnGestureEvent(event);
- }
-
- DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreScrollGestures);
-};
-
////////////////////////////////////////////////////////////////////////////////
// OnBoundsChanged
////////////////////////////////////////////////////////////////////////////////
@@ -479,127 +410,6 @@ TEST_F(ViewTest, DeleteOnPressed) {
}
////////////////////////////////////////////////////////////////////////////////
-// GestureEvent
-////////////////////////////////////////////////////////////////////////////////
-
-void TestView::OnGestureEvent(ui::GestureEvent* event) {
-}
-
-TEST_F(ViewTest, ScrollGestureEvent) {
- // Views hierarchy for non delivery of GestureEvent.
- TestView* v1 = new TestViewConsumeGesture();
- v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
-
- TestView* v2 = new TestViewIgnoreScrollGestures();
- v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
-
- TestView* v3 = new TestViewIgnoreGesture();
- v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100));
-
- scoped_ptr<Widget> widget(new Widget());
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.bounds = gfx::Rect(50, 50, 650, 650);
- widget->Init(params);
- internal::RootView* root =
- static_cast<internal::RootView*>(widget->GetRootView());
- ui::EventDispatchDetails details;
-
- root->AddChildView(v1);
- v1->AddChildView(v2);
- v2->AddChildView(v3);
-
- // |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|.
-
- v1->Reset();
- v2->Reset();
- v3->Reset();
-
- // Gesture on |v3|
- GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0);
- details = root->OnEventFromSource(&g1);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- 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_);
-
- v2->Reset();
-
- // Send scroll gestures on |v3|. The gesture should reach |v2|, however,
- // since it does not process scroll-gesture events, these events should reach
- // |v1|.
- GestureEventForTest gscroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, 115, 115, 0);
- details = root->OnEventFromSource(&gscroll_begin);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_);
- EXPECT_EQ(ui::ET_GESTURE_SCROLL_BEGIN, v1->last_gesture_event_type_);
- v1->Reset();
-
- // Send a second tap on |v1|. The event should reach |v2| since it is the
- // default gesture handler, and not |v1| (even though it is the view under the
- // point, and is the scroll event handler).
- GestureEventForTest second_tap(ui::ET_GESTURE_TAP, 70, 70, 0);
- details = root->OnEventFromSource(&second_tap);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_);
- EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_);
- v2->Reset();
-
- GestureEventForTest gscroll_end(ui::ET_GESTURE_SCROLL_END, 50, 50, 0);
- details = root->OnEventFromSource(&gscroll_end);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- EXPECT_EQ(ui::ET_GESTURE_SCROLL_END, v1->last_gesture_event_type_);
- v1->Reset();
-
- // Simulate an up so that RootView is no longer targetting |v3|.
- GestureEventForTest g1_up(ui::ET_GESTURE_END, 110, 110, 0);
- details = root->OnEventFromSource(&g1_up);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- EXPECT_EQ(ui::ET_GESTURE_END, v2->last_gesture_event_type_);
-
- v1->Reset();
- v2->Reset();
- v3->Reset();
-
- // Gesture on |v1|
- GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0);
- details = root->OnEventFromSource(&g2);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- 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_);
-
- // Send event |g1| again. Even though the coordinates target |v3| it should go
- // to |v1| as that is the view the touch was initially down on.
- v1->last_gesture_event_type_ = ui::ET_UNKNOWN;
- v3->last_gesture_event_type_ = ui::ET_UNKNOWN;
- details = root->OnEventFromSource(&g1);
- EXPECT_FALSE(details.dispatcher_destroyed);
- EXPECT_FALSE(details.target_destroyed);
-
- EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_);
- EXPECT_EQ(ui::ET_UNKNOWN, v3->last_gesture_event_type_);
- EXPECT_EQ("110,110", v1->location_.ToString());
-
- widget->CloseNow();
-}
-
-////////////////////////////////////////////////////////////////////////////////
// Painting
////////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698