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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 406943002: Add test WidgetTest.GestureEventDispatch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/view_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 EXPECT_EQ(view, GetGestureHandler(root_view)); 2004 EXPECT_EQ(view, GetGestureHandler(root_view));
2005 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2005 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
2006 view->set_handle_mode(EventCountView::PROPAGATE_EVENTS); 2006 view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2007 widget->OnGestureEvent(&end); 2007 widget->OnGestureEvent(&end);
2008 EXPECT_FALSE(end.handled()); 2008 EXPECT_FALSE(end.handled());
2009 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2009 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2010 2010
2011 widget->Close(); 2011 widget->Close();
2012 } 2012 }
2013 2013
2014 // Tests that a (non-scroll) gesture event is dispatched to the correct views
2015 // in a view hierarchy and that the default gesture handler in RootView is set
2016 // correctly.
2017 // TODO(tdanderson): Create a test similar to ViewTest.ScrollGestureEvent.
2018 TEST_F(WidgetTest, GestureEventDispatch) {
2019 Widget* widget = CreateTopLevelNativeWidget();
2020 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2021
2022 // Define a hierarchy of four views (coordinates are in
2023 // their parent coordinate space).
2024 // v1 (0, 0, 300, 300)
2025 // v2 (0, 0, 100, 100)
2026 // v3 (0, 0, 50, 50)
2027 // v4(0, 0, 10, 10)
2028 EventCountView* v1 = new EventCountView();
2029 v1->SetBounds(0, 0, 300, 300);
2030 EventCountView* v2 = new EventCountView();
2031 v2->SetBounds(0, 0, 100, 100);
2032 EventCountView* v3 = new EventCountView();
2033 v3->SetBounds(0, 0, 50, 50);
2034 EventCountView* v4 = new EventCountView();
2035 v4->SetBounds(0, 0, 10, 10);
2036 internal::RootView* root_view =
2037 static_cast<internal::RootView*>(widget->GetRootView());
2038 root_view->AddChildView(v1);
2039 v1->AddChildView(v2);
2040 v2->AddChildView(v3);
2041 v3->AddChildView(v4);
2042
2043 widget->Show();
2044
2045 // No gesture handler is set in the root view and none of the views in the
2046 // view hierarchy handle a ui::ET_GESTURE_TAP event. In this case the tap
2047 // event should be dispatched to all views in the hierarchy, the gesture
2048 // handler should remain unset, and the event should remain unhandled.
2049 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5);
2050 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2051 widget->OnGestureEvent(&tap);
2052 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_TAP));
2053 EXPECT_EQ(1, v2->GetEventCount(ui::ET_GESTURE_TAP));
2054 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP));
2055 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP));
2056 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2057 EXPECT_FALSE(tap.handled());
2058
2059 // No gesture handler is set in the root view and |v1|, |v2|, and |v3| all
2060 // handle a ui::ET_GESTURE_TAP event. In this case the tap event should be
2061 // dispatched to |v4| and |v3|, the gesture handler should be set to |v3|,
2062 // and the event should be marked as handled.
2063 v1->ResetCounts();
2064 v2->ResetCounts();
2065 v3->ResetCounts();
2066 v4->ResetCounts();
2067 v1->set_handle_mode(EventCountView::CONSUME_EVENTS);
2068 v2->set_handle_mode(EventCountView::CONSUME_EVENTS);
2069 v3->set_handle_mode(EventCountView::CONSUME_EVENTS);
2070 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2071 widget->OnGestureEvent(&tap);
2072 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2073 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2074 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP));
2075 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP));
2076 EXPECT_EQ(v3, GetGestureHandler(root_view));
2077 EXPECT_TRUE(tap.handled());
2078
2079 // The gesture handler is set to |v3| and all views handle all gesture event
2080 // types. In this case subsequent gesture events should only be dispatched to
2081 // |v3| and marked as handled. The gesture handler should remain as |v3|.
2082 v1->ResetCounts();
2083 v2->ResetCounts();
2084 v3->ResetCounts();
2085 v4->ResetCounts();
2086 v4->set_handle_mode(EventCountView::CONSUME_EVENTS);
2087 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2088 widget->OnGestureEvent(&tap);
2089 EXPECT_TRUE(tap.handled());
2090 GestureEventForTest show_press(ui::ET_GESTURE_SHOW_PRESS, 5, 5);
2091 widget->OnGestureEvent(&show_press);
2092 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2093 widget->OnGestureEvent(&tap);
2094 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2095 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2096 EXPECT_EQ(2, v3->GetEventCount(ui::ET_GESTURE_TAP));
2097 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP));
2098 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SHOW_PRESS));
2099 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SHOW_PRESS));
2100 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_SHOW_PRESS));
2101 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SHOW_PRESS));
2102 EXPECT_TRUE(tap.handled());
2103 EXPECT_TRUE(show_press.handled());
2104 EXPECT_EQ(v3, GetGestureHandler(root_view));
2105
2106 // The gesture handler is set to |v3|, but |v3| does not handle
2107 // ui::ET_GESTURE_TAP events. In this case a tap gesture should be dispatched
2108 // only to |v3|, but the event should remain unhandled. The gesture handler
2109 // should remain as |v3|.
2110 v1->ResetCounts();
2111 v2->ResetCounts();
2112 v3->ResetCounts();
2113 v4->ResetCounts();
2114 v3->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2115 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 5, 5);
2116 widget->OnGestureEvent(&tap);
2117 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2118 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2119 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP));
2120 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP));
2121 EXPECT_FALSE(tap.handled());
2122 EXPECT_EQ(v3, GetGestureHandler(root_view));
2123
2124 widget->Close();
2125 }
2126
2014 // Test the result of Widget::GetAllChildWidgets(). 2127 // Test the result of Widget::GetAllChildWidgets().
2015 TEST_F(WidgetTest, GetAllChildWidgets) { 2128 TEST_F(WidgetTest, GetAllChildWidgets) {
2016 // Create the following widget hierarchy: 2129 // Create the following widget hierarchy:
2017 // 2130 //
2018 // toplevel 2131 // toplevel
2019 // +-- w1 2132 // +-- w1
2020 // +-- w11 2133 // +-- w11
2021 // +-- w2 2134 // +-- w2
2022 // +-- w21 2135 // +-- w21
2023 // +-- w22 2136 // +-- w22
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); 2728 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED));
2616 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); 2729 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED));
2617 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); 2730 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED));
2618 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); 2731 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags());
2619 2732
2620 widget->CloseNow(); 2733 widget->CloseNow();
2621 } 2734 }
2622 2735
2623 } // namespace test 2736 } // namespace test
2624 } // namespace views 2737 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698