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

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

Issue 565583005: Clean up GestureEventDetails constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload to the most recent patch 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
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 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 Widget* widget = CreateTopLevelPlatformWidget(); 1332 Widget* widget = CreateTopLevelPlatformWidget();
1333 widget->GetRootView()->AddChildView(noscroll_view); 1333 widget->GetRootView()->AddChildView(noscroll_view);
1334 widget->GetRootView()->AddChildView(scroll_view); 1334 widget->GetRootView()->AddChildView(scroll_view);
1335 1335
1336 { 1336 {
1337 ui::GestureEvent begin( 1337 ui::GestureEvent begin(
1338 5, 1338 5,
1339 5, 1339 5,
1340 0, 1340 0,
1341 base::TimeDelta(), 1341 base::TimeDelta(),
1342 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); 1342 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN));
1343 widget->OnGestureEvent(&begin); 1343 widget->OnGestureEvent(&begin);
1344 ui::GestureEvent update( 1344 ui::GestureEvent update(
1345 25, 1345 25,
1346 15, 1346 15,
1347 0, 1347 0,
1348 base::TimeDelta(), 1348 base::TimeDelta(),
1349 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); 1349 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10));
1350 widget->OnGestureEvent(&update); 1350 widget->OnGestureEvent(&update);
1351 ui::GestureEvent end( 1351 ui::GestureEvent end(25,
1352 25, 1352 15,
1353 15, 1353 0,
1354 0, 1354 base::TimeDelta(),
1355 base::TimeDelta(), 1355 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
1356 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0));
1357 widget->OnGestureEvent(&end); 1356 widget->OnGestureEvent(&end);
1358 1357
1359 EXPECT_EQ(1, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); 1358 EXPECT_EQ(1, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
1360 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); 1359 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
1361 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); 1360 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END));
1362 } 1361 }
1363 1362
1364 { 1363 {
1365 ui::GestureEvent begin( 1364 ui::GestureEvent begin(
1366 65, 1365 65,
1367 5, 1366 5,
1368 0, 1367 0,
1369 base::TimeDelta(), 1368 base::TimeDelta(),
1370 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); 1369 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN));
1371 widget->OnGestureEvent(&begin); 1370 widget->OnGestureEvent(&begin);
1372 ui::GestureEvent update( 1371 ui::GestureEvent update(
1373 85, 1372 85,
1374 15, 1373 15,
1375 0, 1374 0,
1376 base::TimeDelta(), 1375 base::TimeDelta(),
1377 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); 1376 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10));
1378 widget->OnGestureEvent(&update); 1377 widget->OnGestureEvent(&update);
1379 ui::GestureEvent end( 1378 ui::GestureEvent end(85,
1380 85, 1379 15,
1381 15, 1380 0,
1382 0, 1381 base::TimeDelta(),
1383 base::TimeDelta(), 1382 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
1384 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0));
1385 widget->OnGestureEvent(&end); 1383 widget->OnGestureEvent(&end);
1386 1384
1387 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); 1385 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
1388 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); 1386 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
1389 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); 1387 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END));
1390 } 1388 }
1391 1389
1392 widget->CloseNow(); 1390 widget->CloseNow();
1393 } 1391 }
1394 1392
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 // the target phase. 1461 // the target phase.
1464 view->set_handle_mode(EventCountView::CONSUME_EVENTS); 1462 view->set_handle_mode(EventCountView::CONSUME_EVENTS);
1465 1463
1466 // Dispatch a ui::ET_GESTURE_TAP_DOWN and a ui::ET_GESTURE_TAP_CANCEL event. 1464 // Dispatch a ui::ET_GESTURE_TAP_DOWN and a ui::ET_GESTURE_TAP_CANCEL event.
1467 // The events are handled at the target phase and should not reach the 1465 // The events are handled at the target phase and should not reach the
1468 // post-target handler. 1466 // post-target handler.
1469 ui::GestureEvent tap_down(5, 1467 ui::GestureEvent tap_down(5,
1470 5, 1468 5,
1471 0, 1469 0,
1472 ui::EventTimeForNow(), 1470 ui::EventTimeForNow(),
1473 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 1471 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
1474 0,
1475 0));
1476 widget->OnGestureEvent(&tap_down); 1472 widget->OnGestureEvent(&tap_down);
1477 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_DOWN)); 1473 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1478 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_DOWN)); 1474 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1479 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_DOWN)); 1475 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1480 1476
1481 ui::GestureEvent tap_cancel(5, 1477 ui::GestureEvent tap_cancel(
1482 5, 1478 5,
1483 0, 1479 5,
1484 ui::EventTimeForNow(), 1480 0,
1485 ui::GestureEventDetails(ui::ET_GESTURE_TAP_CANCEL, 1481 ui::EventTimeForNow(),
1486 0, 1482 ui::GestureEventDetails(ui::ET_GESTURE_TAP_CANCEL));
1487 0));
1488 widget->OnGestureEvent(&tap_cancel); 1483 widget->OnGestureEvent(&tap_cancel);
1489 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); 1484 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1490 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); 1485 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1491 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); 1486 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1492 1487
1493 h1.ResetCounts(); 1488 h1.ResetCounts();
1494 view->ResetCounts(); 1489 view->ResetCounts();
1495 h2.ResetCounts(); 1490 h2.ResetCounts();
1496 1491
1497 // Dispatch a ui::ET_SCROLL event. The event is handled at the target phase 1492 // Dispatch a ui::ET_SCROLL event. The event is handled at the target phase
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 gfx::Point move_location(45, 15); 1942 gfx::Point move_location(45, 15);
1948 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, 0, 0); 1943 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, 0, 0);
1949 widget->OnMouseEvent(&move); 1944 widget->OnMouseEvent(&move);
1950 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); 1945 EXPECT_EQ(view, GetMouseMoveHandler(root_view));
1951 widget->Hide(); 1946 widget->Hide();
1952 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); 1947 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view));
1953 1948
1954 // Check RootView::gesture_handler_. 1949 // Check RootView::gesture_handler_.
1955 widget->Show(); 1950 widget->Show();
1956 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 1951 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1957 ui::GestureEvent tap_down( 1952 ui::GestureEvent tap_down(15,
1958 15, 1953 15,
1959 15, 1954 0,
1960 0, 1955 base::TimeDelta(),
1961 base::TimeDelta(), 1956 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
1962 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0));
1963 widget->OnGestureEvent(&tap_down); 1957 widget->OnGestureEvent(&tap_down);
1964 EXPECT_EQ(view, GetGestureHandler(root_view)); 1958 EXPECT_EQ(view, GetGestureHandler(root_view));
1965 widget->Hide(); 1959 widget->Hide();
1966 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 1960 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1967 1961
1968 widget->Close(); 1962 widget->Close();
1969 } 1963 }
1970 1964
1971 // Convenience to make constructing a GestureEvent simpler. 1965 // Convenience to make constructing a GestureEvent simpler.
1972 class GestureEventForTest : public ui::GestureEvent { 1966 class GestureEventForTest : public ui::GestureEvent {
1973 public: 1967 public:
1974 GestureEventForTest(ui::EventType type, int x, int y) 1968 GestureEventForTest(ui::EventType type, int x, int y)
1975 : GestureEvent(x, 1969 : GestureEvent(x,
1976 y, 1970 y,
1977 0, 1971 0,
1978 base::TimeDelta(), 1972 base::TimeDelta(),
1979 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} 1973 ui::GestureEventDetails(type)) {}
1980 1974
1981 GestureEventForTest(ui::GestureEventDetails details, int x, int y) 1975 GestureEventForTest(ui::GestureEventDetails details, int x, int y)
1982 : GestureEvent(x, y, 0, base::TimeDelta(), details) {} 1976 : GestureEvent(x, y, 0, base::TimeDelta(), details) {}
1983 }; 1977 };
1984 1978
1985 // Tests that the |gesture_handler_| member in RootView is always NULL 1979 // Tests that the |gesture_handler_| member in RootView is always NULL
1986 // after the dispatch of a ui::ET_GESTURE_END event corresponding to 1980 // after the dispatch of a ui::ET_GESTURE_END event corresponding to
1987 // the release of the final touch point on the screen and that 1981 // the release of the final touch point on the screen and that
1988 // ui::ET_GESTURE_END events corresponding to the removal of any other touch 1982 // ui::ET_GESTURE_END events corresponding to the removal of any other touch
1989 // point are never dispatched to a view. Also verifies that 1983 // point are never dispatched to a view. Also verifies that
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 // should not set the gesture handler and should not be marked as handled 2016 // should not set the gesture handler and should not be marked as handled
2023 // because it is never dispatched. 2017 // because it is never dispatched.
2024 begin = GestureEventForTest(ui::ET_GESTURE_BEGIN, 15, 15); 2018 begin = GestureEventForTest(ui::ET_GESTURE_BEGIN, 15, 15);
2025 widget->OnGestureEvent(&begin); 2019 widget->OnGestureEvent(&begin);
2026 EXPECT_FALSE(begin.handled()); 2020 EXPECT_FALSE(begin.handled());
2027 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2021 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2028 2022
2029 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_BEGIN 2023 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_BEGIN
2030 // corresponding to a second touch point should not set the gesture handler 2024 // corresponding to a second touch point should not set the gesture handler
2031 // and should not be marked as handled because it is never dispatched. 2025 // and should not be marked as handled because it is never dispatched.
2032 ui::GestureEventDetails details(ui::ET_GESTURE_END, 15, 15); 2026 ui::GestureEventDetails details(ui::ET_GESTURE_END);
2033 details.set_touch_points(2); 2027 details.set_touch_points(2);
2034 GestureEventForTest end_second_touch_point(details, 15, 15); 2028 GestureEventForTest end_second_touch_point(details, 15, 15);
2035 widget->OnGestureEvent(&end_second_touch_point); 2029 widget->OnGestureEvent(&end_second_touch_point);
2036 EXPECT_FALSE(end_second_touch_point.handled()); 2030 EXPECT_FALSE(end_second_touch_point.handled());
2037 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2031 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2038 2032
2039 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END 2033 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END
2040 // event corresponding to the final touch point should not set the gesture 2034 // event corresponding to the final touch point should not set the gesture
2041 // handler. Furthermore, it should not be marked as handled because it was 2035 // handler. Furthermore, it should not be marked as handled because it was
2042 // not dispatched (GESTURE_END events are only dispatched in cases where 2036 // not dispatched (GESTURE_END events are only dispatched in cases where
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 3209
3216 EXPECT_EQ(test_rect, root_view->bounds()); 3210 EXPECT_EQ(test_rect, root_view->bounds());
3217 widget->ReorderNativeViews(); 3211 widget->ReorderNativeViews();
3218 EXPECT_EQ(test_rect, root_view->bounds()); 3212 EXPECT_EQ(test_rect, root_view->bounds());
3219 3213
3220 widget->CloseNow(); 3214 widget->CloseNow();
3221 } 3215 }
3222 3216
3223 } // namespace test 3217 } // namespace test
3224 } // namespace views 3218 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget_interactive_uitest.cc ('k') | ui/wm/core/user_activity_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698