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

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

Issue 552503003: Introduce EventProcessor::OnEventProcessingStarted() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: two comments from sadrul Created 6 years, 3 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
« ui/events/event_processor.cc ('K') | « ui/views/widget/root_view.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 2085 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 EXPECT_EQ(view, GetGestureHandler(root_view)); 2096 EXPECT_EQ(view, GetGestureHandler(root_view));
2097 2097
2098 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2098 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
2099 widget->OnGestureEvent(&end); 2099 widget->OnGestureEvent(&end);
2100 EXPECT_FALSE(end.handled()); 2100 EXPECT_FALSE(end.handled());
2101 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2101 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2102 2102
2103 widget->Close(); 2103 widget->Close();
2104 } 2104 }
2105 2105
2106 // Tests that gesture events which should not be processed (because
2107 // RootView::OnEventProcessingStarted() has marked them as handled) are not
2108 // dispatched to any views.
2109 TEST_F(WidgetTest, GestureEventNotProcessed) {
2110 Widget* widget = CreateTopLevelNativeWidget();
2111 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2112
2113 // Define a hierarchy of four views (coordinates are in
2114 // their parent coordinate space).
2115 // v1 (0, 0, 300, 300)
2116 // v2 (0, 0, 100, 100)
2117 // v3 (0, 0, 50, 50)
2118 // v4(0, 0, 10, 10)
2119 EventCountView* v1 = new EventCountView();
2120 v1->SetBounds(0, 0, 300, 300);
2121 EventCountView* v2 = new EventCountView();
2122 v2->SetBounds(0, 0, 100, 100);
2123 EventCountView* v3 = new EventCountView();
2124 v3->SetBounds(0, 0, 50, 50);
2125 EventCountView* v4 = new EventCountView();
2126 v4->SetBounds(0, 0, 10, 10);
2127 internal::RootView* root_view =
2128 static_cast<internal::RootView*>(widget->GetRootView());
2129 root_view->AddChildView(v1);
2130 v1->AddChildView(v2);
2131 v2->AddChildView(v3);
2132 v3->AddChildView(v4);
2133
2134 widget->Show();
2135
2136 // ui::ET_GESTURE_BEGIN events should never be seen by any view, but
2137 // they should be marked as handled by OnEventProcessingStarted().
2138 GestureEventForTest begin(ui::ET_GESTURE_BEGIN, 5, 5);
2139 widget->OnGestureEvent(&begin);
2140 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_BEGIN));
2141 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_BEGIN));
2142 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_BEGIN));
2143 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_BEGIN));
2144 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2145 EXPECT_TRUE(begin.handled());
2146 v1->ResetCounts();
2147 v2->ResetCounts();
2148 v3->ResetCounts();
2149 v4->ResetCounts();
2150
2151 // ui::ET_GESTURE_END events not corresponding to the release of the
2152 // final touch point should never be seen by any view, but they should
2153 // be marked as handled by OnEventProcessingStarted().
2154 ui::GestureEventDetails details(ui::ET_GESTURE_END, 5, 5);
2155 details.set_touch_points(2);
2156 GestureEventForTest end_second_touch_point(details, 5, 5);
2157 widget->OnGestureEvent(&end_second_touch_point);
2158 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2159 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2160 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2161 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2162 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2163 EXPECT_TRUE(end_second_touch_point.handled());
2164 v1->ResetCounts();
2165 v2->ResetCounts();
2166 v3->ResetCounts();
2167 v4->ResetCounts();
2168
2169 // ui::ET_GESTURE_SCROLL_UPDATE events should never be seen by any view when
2170 // there is no default gesture handler set, but they should be marked as
2171 // handled by OnEventProcessingStarted().
2172 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, 5, 5);
2173 widget->OnGestureEvent(&scroll_update);
2174 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2175 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2176 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2177 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2178 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2179 EXPECT_TRUE(scroll_update.handled());
2180 v1->ResetCounts();
2181 v2->ResetCounts();
2182 v3->ResetCounts();
2183 v4->ResetCounts();
2184
2185 // ui::ET_GESTURE_SCROLL_END events should never be seen by any view when
2186 // there is no default gesture handler set, but they should be marked as
2187 // handled by OnEventProcessingStarted().
2188 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, 5, 5);
2189 widget->OnGestureEvent(&scroll_end);
2190 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2191 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2192 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2193 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2194 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2195 EXPECT_TRUE(scroll_end.handled());
2196 v1->ResetCounts();
2197 v2->ResetCounts();
2198 v3->ResetCounts();
2199 v4->ResetCounts();
2200
2201 // ui::ET_SCROLL_FLING_START events should never be seen by any view when
2202 // there is no default gesture handler set, but they should be marked as
2203 // handled by OnEventProcessingStarted().
2204 GestureEventForTest scroll_fling_start(ui::ET_SCROLL_FLING_START, 5, 5);
2205 widget->OnGestureEvent(&scroll_fling_start);
2206 EXPECT_EQ(0, v1->GetEventCount(ui::ET_SCROLL_FLING_START));
2207 EXPECT_EQ(0, v2->GetEventCount(ui::ET_SCROLL_FLING_START));
2208 EXPECT_EQ(0, v3->GetEventCount(ui::ET_SCROLL_FLING_START));
2209 EXPECT_EQ(0, v4->GetEventCount(ui::ET_SCROLL_FLING_START));
2210 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2211 EXPECT_TRUE(scroll_fling_start.handled());
2212 v1->ResetCounts();
2213 v2->ResetCounts();
2214 v3->ResetCounts();
2215 v4->ResetCounts();
2216
2217 widget->Close();
2218 }
2219
2106 // Tests that a (non-scroll) gesture event is dispatched to the correct views 2220 // Tests that a (non-scroll) gesture event is dispatched to the correct views
2107 // in a view hierarchy and that the default gesture handler in RootView is set 2221 // in a view hierarchy and that the default gesture handler in RootView is set
2108 // correctly. 2222 // correctly.
2109 TEST_F(WidgetTest, GestureEventDispatch) { 2223 TEST_F(WidgetTest, GestureEventDispatch) {
2110 Widget* widget = CreateTopLevelNativeWidget(); 2224 Widget* widget = CreateTopLevelNativeWidget();
2111 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); 2225 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2112 2226
2113 // Define a hierarchy of four views (coordinates are in 2227 // Define a hierarchy of four views (coordinates are in
2114 // their parent coordinate space). 2228 // their parent coordinate space).
2115 // v1 (0, 0, 300, 300) 2229 // v1 (0, 0, 300, 300)
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 3329
3216 EXPECT_EQ(test_rect, root_view->bounds()); 3330 EXPECT_EQ(test_rect, root_view->bounds());
3217 widget->ReorderNativeViews(); 3331 widget->ReorderNativeViews();
3218 EXPECT_EQ(test_rect, root_view->bounds()); 3332 EXPECT_EQ(test_rect, root_view->bounds());
3219 3333
3220 widget->CloseNow(); 3334 widget->CloseNow();
3221 } 3335 }
3222 3336
3223 } // namespace test 3337 } // namespace test
3224 } // namespace views 3338 } // namespace views
OLDNEW
« ui/events/event_processor.cc ('K') | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698