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

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: tests added, CL for review 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/views/widget/root_view.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 returned false) are not dispatched
2108 // 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 processed.
2137 GestureEventForTest begin(ui::ET_GESTURE_BEGIN, 5, 5);
2138 widget->OnGestureEvent(&begin);
2139 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_BEGIN));
2140 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_BEGIN));
2141 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_BEGIN));
2142 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_BEGIN));
2143 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2144 EXPECT_FALSE(begin.handled());
2145 v1->ResetCounts();
2146 v2->ResetCounts();
2147 v3->ResetCounts();
2148 v4->ResetCounts();
2149
2150 // ui::ET_GESTURE_END events not corresponding to the release of the
2151 // final touch point should never be processed.
2152 ui::GestureEventDetails details(ui::ET_GESTURE_END, 5, 5);
2153 details.set_touch_points(2);
2154 GestureEventForTest end_second_touch_point(details, 5, 5);
2155 widget->OnGestureEvent(&end_second_touch_point);
2156 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2157 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2158 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2159 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2160 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2161 EXPECT_FALSE(end_second_touch_point.handled());
2162 v1->ResetCounts();
2163 v2->ResetCounts();
2164 v3->ResetCounts();
2165 v4->ResetCounts();
2166
2167 // ui::ET_GESTURE_SCROLL_UPDATE events should never be processed when there
2168 // is no default gesture handler set.
2169 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, 5, 5);
2170 widget->OnGestureEvent(&scroll_update);
2171 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2172 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2173 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2174 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2175 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2176 EXPECT_FALSE(scroll_update.handled());
2177 v1->ResetCounts();
2178 v2->ResetCounts();
2179 v3->ResetCounts();
2180 v4->ResetCounts();
2181
2182 // ui::ET_GESTURE_SCROLL_END events should never be processed when there
2183 // is no default gesture handler set.
2184 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, 5, 5);
2185 widget->OnGestureEvent(&scroll_end);
2186 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2187 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2188 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2189 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2190 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2191 EXPECT_FALSE(scroll_end.handled());
2192 v1->ResetCounts();
2193 v2->ResetCounts();
2194 v3->ResetCounts();
2195 v4->ResetCounts();
2196
2197 // ui::ET_SCROLL_FLING_START events should never be processed when there
2198 // is no default gesture handler set.
2199 GestureEventForTest scroll_fling_start(ui::ET_SCROLL_FLING_START, 5, 5);
2200 widget->OnGestureEvent(&scroll_fling_start);
2201 EXPECT_EQ(0, v1->GetEventCount(ui::ET_SCROLL_FLING_START));
2202 EXPECT_EQ(0, v2->GetEventCount(ui::ET_SCROLL_FLING_START));
2203 EXPECT_EQ(0, v3->GetEventCount(ui::ET_SCROLL_FLING_START));
2204 EXPECT_EQ(0, v4->GetEventCount(ui::ET_SCROLL_FLING_START));
2205 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2206 EXPECT_FALSE(scroll_fling_start.handled());
2207 v1->ResetCounts();
2208 v2->ResetCounts();
2209 v3->ResetCounts();
2210 v4->ResetCounts();
2211
2212 widget->Close();
2213 }
2214
2106 // Tests that a (non-scroll) gesture event is dispatched to the correct views 2215 // 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 2216 // in a view hierarchy and that the default gesture handler in RootView is set
2108 // correctly. 2217 // correctly.
2109 TEST_F(WidgetTest, GestureEventDispatch) { 2218 TEST_F(WidgetTest, GestureEventDispatch) {
2110 Widget* widget = CreateTopLevelNativeWidget(); 2219 Widget* widget = CreateTopLevelNativeWidget();
2111 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); 2220 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2112 2221
2113 // Define a hierarchy of four views (coordinates are in 2222 // Define a hierarchy of four views (coordinates are in
2114 // their parent coordinate space). 2223 // their parent coordinate space).
2115 // v1 (0, 0, 300, 300) 2224 // v1 (0, 0, 300, 300)
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 3324
3216 EXPECT_EQ(test_rect, root_view->bounds()); 3325 EXPECT_EQ(test_rect, root_view->bounds());
3217 widget->ReorderNativeViews(); 3326 widget->ReorderNativeViews();
3218 EXPECT_EQ(test_rect, root_view->bounds()); 3327 EXPECT_EQ(test_rect, root_view->bounds());
3219 3328
3220 widget->CloseNow(); 3329 widget->CloseNow();
3221 } 3330 }
3222 3331
3223 } // namespace test 3332 } // namespace test
3224 } // namespace views 3333 } // namespace views
OLDNEW
« ui/views/widget/root_view.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