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

Side by Side Diff: ui/views/controls/menu/menu_controller_unittest.cc

Issue 2786693002: Add PointerDetails to ui::MouseEvent's constructors (Closed)
Patch Set: mouse event constructor Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/menu/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 IncrementSelection(); 947 IncrementSelection();
948 EXPECT_EQ(5, pending_state_item()->GetCommand()); 948 EXPECT_EQ(5, pending_state_item()->GetCommand());
949 EXPECT_FALSE(button1->IsHotTracked()); 949 EXPECT_FALSE(button1->IsHotTracked());
950 EXPECT_FALSE(button2->IsHotTracked()); 950 EXPECT_FALSE(button2->IsHotTracked());
951 EXPECT_TRUE(button3->IsHotTracked()); 951 EXPECT_TRUE(button3->IsHotTracked());
952 952
953 // Move a mouse to hot track the |button1|. 953 // Move a mouse to hot track the |button1|.
954 SubmenuView* sub_menu = menu_item()->GetSubmenu(); 954 SubmenuView* sub_menu = menu_item()->GetSubmenu();
955 gfx::Point location(button1->GetBoundsInScreen().CenterPoint()); 955 gfx::Point location(button1->GetBoundsInScreen().CenterPoint());
956 View::ConvertPointFromScreen(sub_menu->GetScrollViewContainer(), &location); 956 View::ConvertPointFromScreen(sub_menu->GetScrollViewContainer(), &location);
957 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, 957 ui::MouseEvent event(
958 ui::EventTimeForNow(), 0, 0); 958 ui::ET_MOUSE_MOVED, location, location, ui::EventTimeForNow(), 0, 0,
959 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
959 ProcessMouseMoved(sub_menu, event); 960 ProcessMouseMoved(sub_menu, event);
960 961
961 // Incrementing selection should move hot tracking to the second button (next 962 // Incrementing selection should move hot tracking to the second button (next
962 // after the first button). 963 // after the first button).
963 IncrementSelection(); 964 IncrementSelection();
964 EXPECT_EQ(5, pending_state_item()->GetCommand()); 965 EXPECT_EQ(5, pending_state_item()->GetCommand());
965 EXPECT_FALSE(button1->IsHotTracked()); 966 EXPECT_FALSE(button1->IsHotTracked());
966 EXPECT_TRUE(button2->IsHotTracked()); 967 EXPECT_TRUE(button2->IsHotTracked());
967 EXPECT_FALSE(button3->IsHotTracked()); 968 EXPECT_FALSE(button3->IsHotTracked());
968 969
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 submenu->ShowAt(owner(), menu_item()->bounds(), false); 1245 submenu->ShowAt(owner(), menu_item()->bounds(), false);
1245 gfx::Point location(submenu->bounds().bottom_right()); 1246 gfx::Point location(submenu->bounds().bottom_right());
1246 location.Offset(1, 1); 1247 location.Offset(1, 1);
1247 1248
1248 MenuHost* host = GetMenuHost(submenu); 1249 MenuHost* host = GetMenuHost(submenu);
1249 // Normally created as the full Widget is brought up. Explicitly created here 1250 // Normally created as the full Widget is brought up. Explicitly created here
1250 // for testing. 1251 // for testing.
1251 std::unique_ptr<MenuHostRootView> root_view(CreateMenuHostRootView(host)); 1252 std::unique_ptr<MenuHostRootView> root_view(CreateMenuHostRootView(host));
1252 DestroyMenuController(); 1253 DestroyMenuController();
1253 1254
1254 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, 1255 ui::MouseEvent event(
1255 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1256 ui::ET_MOUSE_MOVED, location, location, ui::EventTimeForNow(),
1257 ui::EF_LEFT_MOUSE_BUTTON, 0,
1258 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1256 1259
1257 // This should not attempt to access the destroyed MenuController and should 1260 // This should not attempt to access the destroyed MenuController and should
1258 // not crash. 1261 // not crash.
1259 root_view->OnMouseMoved(event); 1262 root_view->OnMouseMoved(event);
1260 } 1263 }
1261 1264
1262 // Tets that an asynchronous menu nested within an asynchronous menu closes both 1265 // Tets that an asynchronous menu nested within an asynchronous menu closes both
1263 // menus, and notifies both delegates. 1266 // menus, and notifies both delegates.
1264 TEST_F(MenuControllerTest, DoubleAsynchronousNested) { 1267 TEST_F(MenuControllerTest, DoubleAsynchronousNested) {
1265 MenuController* controller = menu_controller(); 1268 MenuController* controller = menu_controller();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, 1311 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT,
1309 false, false, &mouse_event_flags); 1312 false, false, &mouse_event_flags);
1310 EXPECT_EQ(run_result, nullptr); 1313 EXPECT_EQ(run_result, nullptr);
1311 1314
1312 // Show a sub menu to target with a pointer selection. However have the event 1315 // Show a sub menu to target with a pointer selection. However have the event
1313 // occur outside of the bounds of the entire menu. 1316 // occur outside of the bounds of the entire menu.
1314 SubmenuView* sub_menu = item->GetSubmenu(); 1317 SubmenuView* sub_menu = item->GetSubmenu();
1315 sub_menu->ShowAt(owner(), item->bounds(), false); 1318 sub_menu->ShowAt(owner(), item->bounds(), false);
1316 gfx::Point location(sub_menu->bounds().bottom_right()); 1319 gfx::Point location(sub_menu->bounds().bottom_right());
1317 location.Offset(1, 1); 1320 location.Offset(1, 1);
1318 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, 1321 ui::MouseEvent event(
1319 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1322 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(),
1323 ui::EF_LEFT_MOUSE_BUTTON, 0,
1324 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1320 1325
1321 // When attempting to select outside of all menus this should lead to a 1326 // When attempting to select outside of all menus this should lead to a
1322 // shutdown. This should not crash while attempting to repost the event. 1327 // shutdown. This should not crash while attempting to repost the event.
1323 SetSelectionOnPointerDown(sub_menu, &event); 1328 SetSelectionOnPointerDown(sub_menu, &event);
1324 1329
1325 EXPECT_FALSE(IsAsyncRun()); 1330 EXPECT_FALSE(IsAsyncRun());
1326 EXPECT_EQ(delegate, GetCurrentDelegate()); 1331 EXPECT_EQ(delegate, GetCurrentDelegate());
1327 EXPECT_EQ(0, delegate->on_menu_closed_called()); 1332 EXPECT_EQ(0, delegate->on_menu_closed_called());
1328 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); 1333 EXPECT_EQ(1, nested_delegate->on_menu_closed_called());
1329 EXPECT_EQ(nullptr, nested_delegate->on_menu_closed_menu()); 1334 EXPECT_EQ(nullptr, nested_delegate->on_menu_closed_menu());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, 1413 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT,
1409 false, false, &mouse_event_flags); 1414 false, false, &mouse_event_flags);
1410 EXPECT_EQ(run_result, nullptr); 1415 EXPECT_EQ(run_result, nullptr);
1411 1416
1412 // Show a sub menu to target with a pointer selection. However have the event 1417 // Show a sub menu to target with a pointer selection. However have the event
1413 // occur outside of the bounds of the entire menu. 1418 // occur outside of the bounds of the entire menu.
1414 SubmenuView* sub_menu = item->GetSubmenu(); 1419 SubmenuView* sub_menu = item->GetSubmenu();
1415 sub_menu->ShowAt(owner(), item->bounds(), true); 1420 sub_menu->ShowAt(owner(), item->bounds(), true);
1416 gfx::Point location(sub_menu->bounds().bottom_right()); 1421 gfx::Point location(sub_menu->bounds().bottom_right());
1417 location.Offset(1, 1); 1422 location.Offset(1, 1);
1418 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, 1423 ui::MouseEvent event(
1419 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1424 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(),
1425 ui::EF_LEFT_MOUSE_BUTTON, 0,
1426 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1420 1427
1421 // This will lead to MenuController being deleted during the event repost. 1428 // This will lead to MenuController being deleted during the event repost.
1422 // The remainder of this test, and TearDown should not crash. 1429 // The remainder of this test, and TearDown should not crash.
1423 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); 1430 DestroyMenuControllerOnMenuClosed(nested_delegate.get());
1424 // When attempting to select outside of all menus this should lead to a 1431 // When attempting to select outside of all menus this should lead to a
1425 // shutdown. This should not crash while attempting to repost the event. 1432 // shutdown. This should not crash while attempting to repost the event.
1426 SetSelectionOnPointerDown(sub_menu, &event); 1433 SetSelectionOnPointerDown(sub_menu, &event);
1427 1434
1428 // Close to remove observers before test TearDown 1435 // Close to remove observers before test TearDown
1429 sub_menu->Close(); 1436 sub_menu->Close();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 1652
1646 SubmenuView* nested_menu_submenu = nested_menu_item_1->GetSubmenu(); 1653 SubmenuView* nested_menu_submenu = nested_menu_item_1->GetSubmenu();
1647 nested_menu_submenu->SetBounds(0, 0, 100, 100); 1654 nested_menu_submenu->SetBounds(0, 0, 100, 100);
1648 nested_menu_submenu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), false); 1655 nested_menu_submenu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), false);
1649 GetMenuHost(nested_menu_submenu) 1656 GetMenuHost(nested_menu_submenu)
1650 ->SetContentsView(nested_menu_submenu->GetScrollViewContainer()); 1657 ->SetContentsView(nested_menu_submenu->GetScrollViewContainer());
1651 1658
1652 // Press down outside of the context menu, and within the empty menu item. 1659 // Press down outside of the context menu, and within the empty menu item.
1653 // This should close the first context menu. 1660 // This should close the first context menu.
1654 gfx::Point press_location(sub_menu_view->bounds().CenterPoint()); 1661 gfx::Point press_location(sub_menu_view->bounds().CenterPoint());
1655 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 1662 ui::MouseEvent press_event(
1656 press_location, ui::EventTimeForNow(), 1663 ui::ET_MOUSE_PRESSED, press_location, press_location,
1657 ui::EF_RIGHT_MOUSE_BUTTON, 0); 1664 ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON, 0,
1665 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1658 ProcessMousePressed(nested_menu_submenu, press_event); 1666 ProcessMousePressed(nested_menu_submenu, press_event);
1659 EXPECT_EQ(nested_controller_delegate_1->on_menu_closed_called(), 1); 1667 EXPECT_EQ(nested_controller_delegate_1->on_menu_closed_called(), 1);
1660 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate()); 1668 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate());
1661 1669
1662 // While the current state is the menu item which launched the sub menu, cause 1670 // While the current state is the menu item which launched the sub menu, cause
1663 // a drag in the empty menu item. This should not hide the menu. 1671 // a drag in the empty menu item. This should not hide the menu.
1664 SetState(sub_menu_item.get()); 1672 SetState(sub_menu_item.get());
1665 press_location.Offset(-5, 0); 1673 press_location.Offset(-5, 0);
1666 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, press_location, 1674 ui::MouseEvent drag_event(
1667 press_location, ui::EventTimeForNow(), 1675 ui::ET_MOUSE_DRAGGED, press_location, press_location,
1668 ui::EF_RIGHT_MOUSE_BUTTON, 0); 1676 ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON, 0,
1677 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1669 ProcessMouseDragged(sub_menu_view, drag_event); 1678 ProcessMouseDragged(sub_menu_view, drag_event);
1670 EXPECT_EQ(menu_delegate()->will_hide_menu_count(), 0); 1679 EXPECT_EQ(menu_delegate()->will_hide_menu_count(), 0);
1671 1680
1672 // Release the mouse in the empty menu item, triggering a context menu 1681 // Release the mouse in the empty menu item, triggering a context menu
1673 // request. 1682 // request.
1674 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 1683 ui::MouseEvent release_event(
1675 press_location, ui::EventTimeForNow(), 1684 ui::ET_MOUSE_RELEASED, press_location, press_location,
1676 ui::EF_RIGHT_MOUSE_BUTTON, 0); 1685 ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON, 0,
1686 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1677 ProcessMouseReleased(sub_menu_view, release_event); 1687 ProcessMouseReleased(sub_menu_view, release_event);
1678 EXPECT_EQ(sub_menu_item_delegate->show_context_menu_count(), 1); 1688 EXPECT_EQ(sub_menu_item_delegate->show_context_menu_count(), 1);
1679 EXPECT_EQ(sub_menu_item_delegate->show_context_menu_source(), 1689 EXPECT_EQ(sub_menu_item_delegate->show_context_menu_source(),
1680 sub_menu_item.get()); 1690 sub_menu_item.get());
1681 1691
1682 // Nest a context menu. 1692 // Nest a context menu.
1683 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_2 = 1693 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_2 =
1684 base::MakeUnique<TestMenuDelegate>(); 1694 base::MakeUnique<TestMenuDelegate>();
1685 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_2 = 1695 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_2 =
1686 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_2.get()); 1696 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_2.get());
(...skipping 12 matching lines...) Expand all
1699 // crash. 1709 // crash.
1700 TestAsyncEscapeKey(); 1710 TestAsyncEscapeKey();
1701 EXPECT_EQ(nested_controller_delegate_2->on_menu_closed_called(), 1); 1711 EXPECT_EQ(nested_controller_delegate_2->on_menu_closed_called(), 1);
1702 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate()); 1712 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate());
1703 } 1713 }
1704 1714
1705 #endif // defined(USE_AURA) 1715 #endif // defined(USE_AURA)
1706 1716
1707 } // namespace test 1717 } // namespace test
1708 } // namespace views 1718 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698