| OLD | NEW |
| 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 "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 13 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 14 #include "ash/common/shelf/shelf_menu_model.h" |
| 14 #include "ash/common/shelf/shelf_model.h" | 15 #include "ash/common/shelf/shelf_model.h" |
| 15 #include "ash/common/shell_window_ids.h" | 16 #include "ash/common/shell_window_ids.h" |
| 16 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
| 17 #include "ash/shelf/app_list_button.h" | 18 #include "ash/shelf/app_list_button.h" |
| 18 #include "ash/shelf/overflow_bubble.h" | 19 #include "ash/shelf/overflow_bubble.h" |
| 19 #include "ash/shelf/overflow_bubble_view.h" | 20 #include "ash/shelf/overflow_bubble_view.h" |
| 20 #include "ash/shelf/shelf.h" | 21 #include "ash/shelf/shelf.h" |
| 21 #include "ash/shelf/shelf_button.h" | 22 #include "ash/shelf/shelf_button.h" |
| 22 #include "ash/shelf/shelf_icon_observer.h" | 23 #include "ash/shelf/shelf_icon_observer.h" |
| 23 #include "ash/shelf/shelf_tooltip_manager.h" | 24 #include "ash/shelf/shelf_tooltip_manager.h" |
| 24 #include "ash/shelf/shelf_widget.h" | 25 #include "ash/shelf/shelf_widget.h" |
| 25 #include "ash/shell.h" | 26 #include "ash/shell.h" |
| 26 #include "ash/test/ash_test_base.h" | 27 #include "ash/test/ash_test_base.h" |
| 28 #include "ash/test/material_design_controller_test_api.h" |
| 27 #include "ash/test/overflow_bubble_view_test_api.h" | 29 #include "ash/test/overflow_bubble_view_test_api.h" |
| 28 #include "ash/test/shelf_test_api.h" | 30 #include "ash/test/shelf_test_api.h" |
| 29 #include "ash/test/shelf_view_test_api.h" | 31 #include "ash/test/shelf_view_test_api.h" |
| 30 #include "ash/test/shell_test_api.h" | 32 #include "ash/test/shell_test_api.h" |
| 31 #include "ash/test/test_shelf_delegate.h" | 33 #include "ash/test/test_shelf_delegate.h" |
| 32 #include "ash/test/test_shelf_item_delegate.h" | 34 #include "ash/test/test_shelf_item_delegate.h" |
| 33 #include "ash/test/test_system_tray_delegate.h" | 35 #include "ash/test/test_system_tray_delegate.h" |
| 34 #include "base/compiler_specific.h" | 36 #include "base/compiler_specific.h" |
| 35 #include "base/i18n/rtl.h" | 37 #include "base/i18n/rtl.h" |
| 36 #include "base/run_loop.h" | 38 #include "base/run_loop.h" |
| 37 #include "base/strings/string_number_conversions.h" | 39 #include "base/strings/string_number_conversions.h" |
| 40 #include "base/strings/utf_string_conversions.h" |
| 38 #include "base/test/histogram_tester.h" | 41 #include "base/test/histogram_tester.h" |
| 39 #include "base/test/user_action_tester.h" | 42 #include "base/test/user_action_tester.h" |
| 43 #include "base/threading/thread_task_runner_handle.h" |
| 40 #include "base/time/time.h" | 44 #include "base/time/time.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "ui/aura/test/aura_test_base.h" | 46 #include "ui/aura/test/aura_test_base.h" |
| 42 #include "ui/aura/window.h" | 47 #include "ui/aura/window.h" |
| 43 #include "ui/aura/window_event_dispatcher.h" | 48 #include "ui/aura/window_event_dispatcher.h" |
| 44 #include "ui/compositor/layer.h" | 49 #include "ui/compositor/layer.h" |
| 45 #include "ui/events/event.h" | 50 #include "ui/events/event.h" |
| 46 #include "ui/events/event_constants.h" | 51 #include "ui/events/event_constants.h" |
| 47 #include "ui/events/event_utils.h" | 52 #include "ui/events/event_utils.h" |
| 48 #include "ui/events/test/event_generator.h" | 53 #include "ui/events/test/event_generator.h" |
| 49 #include "ui/gfx/geometry/point.h" | 54 #include "ui/gfx/geometry/point.h" |
| 55 #include "ui/views/animation/ink_drop_impl.h" |
| 56 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
| 50 #include "ui/views/bubble/bubble_frame_view.h" | 57 #include "ui/views/bubble/bubble_frame_view.h" |
| 51 #include "ui/views/view_model.h" | 58 #include "ui/views/view_model.h" |
| 52 #include "ui/views/widget/widget.h" | 59 #include "ui/views/widget/widget.h" |
| 53 #include "ui/views/widget/widget_delegate.h" | 60 #include "ui/views/widget/widget_delegate.h" |
| 54 #include "ui/wm/core/coordinate_conversion.h" | 61 #include "ui/wm/core/coordinate_conversion.h" |
| 55 | 62 |
| 63 using testing::ElementsAre; |
| 64 using testing::IsEmpty; |
| 65 |
| 56 namespace ash { | 66 namespace ash { |
| 57 namespace test { | 67 namespace test { |
| 58 | 68 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 69 //////////////////////////////////////////////////////////////////////////////// |
| 60 // ShelfIconObserver tests. | 70 // ShelfIconObserver tests. |
| 61 | 71 |
| 62 class TestShelfIconObserver : public ShelfIconObserver { | 72 class TestShelfIconObserver : public ShelfIconObserver { |
| 63 public: | 73 public: |
| 64 explicit TestShelfIconObserver(Shelf* shelf) | 74 explicit TestShelfIconObserver(Shelf* shelf) |
| 65 : shelf_(shelf), | 75 : shelf_(shelf), |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 shelf_view_->PointerPressedOnButton(button, pointer, click_event); | 473 shelf_view_->PointerPressedOnButton(button, pointer, click_event); |
| 464 return button; | 474 return button; |
| 465 } | 475 } |
| 466 | 476 |
| 467 // Simulates a single mouse click. | 477 // Simulates a single mouse click. |
| 468 void SimulateClick(int button_index) { | 478 void SimulateClick(int button_index) { |
| 469 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); | 479 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); |
| 470 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), | 480 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), |
| 471 button->GetBoundsInScreen().origin(), | 481 button->GetBoundsInScreen().origin(), |
| 472 ui::EventTimeForNow(), 0, 0); | 482 ui::EventTimeForNow(), 0, 0); |
| 473 test_api_->ButtonPressed(button, release_event); | 483 test_api_->ButtonPressed( |
| 484 button, release_event, |
| 485 views::test::InkDropHostViewTestApi(button).ink_drop()); |
| 474 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false); | 486 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false); |
| 475 } | 487 } |
| 476 | 488 |
| 477 // Simulates the second click of a double click. | 489 // Simulates the second click of a double click. |
| 478 void SimulateDoubleClick(int button_index) { | 490 void SimulateDoubleClick(int button_index) { |
| 479 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); | 491 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); |
| 480 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), | 492 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), |
| 481 button->GetBoundsInScreen().origin(), | 493 button->GetBoundsInScreen().origin(), |
| 482 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, | 494 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, |
| 483 0); | 495 0); |
| 484 test_api_->ButtonPressed(button, release_event); | 496 test_api_->ButtonPressed( |
| 497 button, release_event, |
| 498 views::test::InkDropHostViewTestApi(button).ink_drop()); |
| 485 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false); | 499 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false); |
| 486 } | 500 } |
| 487 | 501 |
| 488 void DoDrag(int dist_x, | 502 void DoDrag(int dist_x, |
| 489 int dist_y, | 503 int dist_y, |
| 490 views::View* button, | 504 views::View* button, |
| 491 ShelfView::Pointer pointer, | 505 ShelfView::Pointer pointer, |
| 492 views::View* to) { | 506 views::View* to) { |
| 493 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, gfx::Point(dist_x, dist_y), | 507 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, gfx::Point(dist_x, dist_y), |
| 494 to->GetBoundsInScreen().origin(), | 508 to->GetBoundsInScreen().origin(), |
| (...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 AddAppShortcut(); | 2002 AddAppShortcut(); |
| 1989 } | 2003 } |
| 1990 test_api_->RunMessageLoopUntilAnimationsDone(); | 2004 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1991 CheckAllItemsAreInBounds(); | 2005 CheckAllItemsAreInBounds(); |
| 1992 } | 2006 } |
| 1993 | 2007 |
| 1994 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 2008 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
| 1995 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 2009 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
| 1996 testing::Bool()); | 2010 testing::Bool()); |
| 1997 | 2011 |
| 2012 namespace { |
| 2013 |
| 2014 // An InkDrop implementation that wraps another InkDrop instance to keep track |
| 2015 // of state changes requested on it. Note that this will only track transitions |
| 2016 // routed through AnimateToState() and not the ones performed directly on the |
| 2017 // ripple inside the contained |ink_drop|. |
| 2018 class InkDropSpy : public views::InkDrop { |
| 2019 public: |
| 2020 explicit InkDropSpy(std::unique_ptr<views::InkDrop> ink_drop) |
| 2021 : ink_drop_(std::move(ink_drop)) {} |
| 2022 ~InkDropSpy() override {} |
| 2023 |
| 2024 std::vector<views::InkDropState> GetAndResetRequestedStates() { |
| 2025 std::vector<views::InkDropState> requested_states; |
| 2026 requested_states.swap(requested_states_); |
| 2027 return requested_states; |
| 2028 } |
| 2029 |
| 2030 // views::InkDrop: |
| 2031 views::InkDropState GetTargetInkDropState() const override { |
| 2032 return ink_drop_->GetTargetInkDropState(); |
| 2033 } |
| 2034 void AnimateToState(views::InkDropState ink_drop_state) override { |
| 2035 requested_states_.push_back(ink_drop_state); |
| 2036 ink_drop_->AnimateToState(ink_drop_state); |
| 2037 } |
| 2038 void SnapToActivated() override { ink_drop_->SnapToActivated(); } |
| 2039 void SetHovered(bool is_hovered) override { |
| 2040 ink_drop_->SetHovered(is_hovered); |
| 2041 } |
| 2042 void SetFocused(bool is_focused) override { |
| 2043 ink_drop_->SetFocused(is_focused); |
| 2044 } |
| 2045 |
| 2046 std::unique_ptr<views::InkDrop> ink_drop_; |
| 2047 std::vector<views::InkDropState> requested_states_; |
| 2048 |
| 2049 private: |
| 2050 DISALLOW_COPY_AND_ASSIGN(InkDropSpy); |
| 2051 }; |
| 2052 |
| 2053 // A menu model that contains minimum number of items needed for a menu to be |
| 2054 // shown on a shelf item. |
| 2055 class TestShelfMenuModel : public ShelfMenuModel, |
| 2056 public ui::SimpleMenuModel::Delegate { |
| 2057 public: |
| 2058 TestShelfMenuModel() : ShelfMenuModel(this) { Build(); } |
| 2059 ~TestShelfMenuModel() override {} |
| 2060 |
| 2061 private: |
| 2062 void Build() { |
| 2063 // A menu is expected to have at least 6 items. Three spacing separators, |
| 2064 // one title, and at least two more items. |
| 2065 AddSeparator(ui::SPACING_SEPARATOR); |
| 2066 AddItem(0, base::ASCIIToUTF16("Title")); |
| 2067 AddSeparator(ui::SPACING_SEPARATOR); |
| 2068 AddItem(1, base::ASCIIToUTF16("Item 1")); |
| 2069 AddItem(2, base::ASCIIToUTF16("Item 2")); |
| 2070 AddSeparator(ui::SPACING_SEPARATOR); |
| 2071 } |
| 2072 |
| 2073 // ShelfMenuModel: |
| 2074 bool IsCommandActive(int command_id) const override { return false; } |
| 2075 |
| 2076 // ui::SimpleMenuModel::Delegate: |
| 2077 bool IsCommandIdChecked(int command_id) const override { return false; } |
| 2078 bool IsCommandIdEnabled(int command_id) const override { |
| 2079 return command_id != 0; |
| 2080 } |
| 2081 bool GetAcceleratorForCommandId(int command_id, |
| 2082 ui::Accelerator* accelerator) override { |
| 2083 return false; |
| 2084 } |
| 2085 void ExecuteCommand(int command_id, int event_flags) override {} |
| 2086 |
| 2087 DISALLOW_COPY_AND_ASSIGN(TestShelfMenuModel); |
| 2088 }; |
| 2089 |
| 2090 // A ShelfItemDelegate that returns a menu for the shelf item. |
| 2091 class ListMenuShelfItemDelegate : public TestShelfItemDelegate { |
| 2092 public: |
| 2093 ListMenuShelfItemDelegate() : TestShelfItemDelegate(nullptr) {} |
| 2094 ~ListMenuShelfItemDelegate() override {} |
| 2095 |
| 2096 private: |
| 2097 // TestShelfItemDelegate: |
| 2098 ShelfMenuModel* CreateApplicationMenu(int event_flags) override { |
| 2099 return new TestShelfMenuModel; |
| 2100 } |
| 2101 |
| 2102 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); |
| 2103 }; |
| 2104 |
| 2105 } // namespace |
| 2106 |
| 2107 class ShelfViewInkDropTest : public ShelfViewTest { |
| 2108 public: |
| 2109 ShelfViewInkDropTest() : ink_drop_(nullptr), browser_button_(nullptr) {} |
| 2110 ~ShelfViewInkDropTest() override {} |
| 2111 |
| 2112 void SetUp() override { |
| 2113 ShelfViewTest::SetUp(); |
| 2114 |
| 2115 // TODO(mohsen): Ideally, we would want to set material mode before calling |
| 2116 // ShelfViewTest::SetUp() so that everything is set up with the correct |
| 2117 // material mode. Currently, this is not possible as it expects material |
| 2118 // mode be UNINITIALIZED. (See https://crbug.com/620093) |
| 2119 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI( |
| 2120 ash::MaterialDesignController::MATERIAL_NORMAL)); |
| 2121 |
| 2122 browser_button_ = test_api_->GetButton(browser_index_); |
| 2123 |
| 2124 views::InkDropImpl* ink_drop_impl = new views::InkDropImpl(browser_button_); |
| 2125 ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl)); |
| 2126 views::test::InkDropHostViewTestApi(browser_button_) |
| 2127 .SetInkDrop(base::WrapUnique(ink_drop_)); |
| 2128 } |
| 2129 |
| 2130 void TearDown() override { |
| 2131 ash_md_controller_.reset(); |
| 2132 |
| 2133 ShelfViewTest::TearDown(); |
| 2134 } |
| 2135 |
| 2136 protected: |
| 2137 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI> |
| 2138 ash_md_controller_; |
| 2139 |
| 2140 InkDropSpy* ink_drop_; |
| 2141 ShelfButton* browser_button_; |
| 2142 |
| 2143 private: |
| 2144 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest); |
| 2145 }; |
| 2146 |
| 2147 // Tests that clicking on a shelf item that does not show a menu transitions ink |
| 2148 // drop states correctly. |
| 2149 TEST_F(ShelfViewInkDropTest, WithoutMenuPressRelease) { |
| 2150 views::CustomButton* button = browser_button_; |
| 2151 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); |
| 2152 |
| 2153 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, |
| 2154 press_location, ui::EventTimeForNow(), |
| 2155 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2156 button->OnMousePressed(press_event); |
| 2157 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2158 ink_drop_->GetTargetInkDropState()); |
| 2159 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2160 ElementsAre(views::InkDropState::ACTION_PENDING)); |
| 2161 |
| 2162 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, |
| 2163 press_location, ui::EventTimeForNow(), |
| 2164 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2165 button->OnMouseReleased(release_event); |
| 2166 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2167 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2168 ElementsAre(views::InkDropState::ACTION_TRIGGERED)); |
| 2169 } |
| 2170 |
| 2171 // Tests that dragging outside of a shelf item transitions ink drop states |
| 2172 // correctly. |
| 2173 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseOutside) { |
| 2174 views::CustomButton* button = browser_button_; |
| 2175 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); |
| 2176 |
| 2177 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, |
| 2178 press_location, ui::EventTimeForNow(), |
| 2179 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2180 button->OnMousePressed(press_event); |
| 2181 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2182 ink_drop_->GetTargetInkDropState()); |
| 2183 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2184 ElementsAre(views::InkDropState::ACTION_PENDING)); |
| 2185 |
| 2186 press_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0); |
| 2187 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, press_location, |
| 2188 press_location, ui::EventTimeForNow(), |
| 2189 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2190 button->OnMouseDragged(drag_event_small); |
| 2191 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2192 ink_drop_->GetTargetInkDropState()); |
| 2193 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); |
| 2194 |
| 2195 press_location.Offset(test_api_->GetMinimumDragDistance(), 0); |
| 2196 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, press_location, |
| 2197 press_location, ui::EventTimeForNow(), |
| 2198 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2199 button->OnMouseDragged(drag_event_large); |
| 2200 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2201 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2202 ElementsAre(views::InkDropState::HIDDEN)); |
| 2203 |
| 2204 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, |
| 2205 press_location, ui::EventTimeForNow(), |
| 2206 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2207 button->OnMouseReleased(release_event); |
| 2208 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2209 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); |
| 2210 } |
| 2211 |
| 2212 // Tests that dragging outside of a shelf item and back transitions ink drop |
| 2213 // states correctly. |
| 2214 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseInside) { |
| 2215 views::CustomButton* button = browser_button_; |
| 2216 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); |
| 2217 |
| 2218 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, |
| 2219 press_location, ui::EventTimeForNow(), |
| 2220 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2221 button->OnMousePressed(press_event); |
| 2222 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2223 ink_drop_->GetTargetInkDropState()); |
| 2224 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2225 ElementsAre(views::InkDropState::ACTION_PENDING)); |
| 2226 |
| 2227 press_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0); |
| 2228 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, press_location, |
| 2229 press_location, ui::EventTimeForNow(), |
| 2230 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2231 button->OnMouseDragged(drag_event_outside); |
| 2232 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2233 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2234 ElementsAre(views::InkDropState::HIDDEN)); |
| 2235 |
| 2236 press_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0); |
| 2237 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, press_location, |
| 2238 press_location, ui::EventTimeForNow(), |
| 2239 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2240 button->OnMouseDragged(drag_event_inside); |
| 2241 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2242 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); |
| 2243 |
| 2244 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, |
| 2245 press_location, ui::EventTimeForNow(), |
| 2246 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2247 button->OnMouseReleased(release_event); |
| 2248 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2249 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); |
| 2250 } |
| 2251 |
| 2252 // Tests that clicking on a shelf item that shows an app list menu transitions |
| 2253 // ink drop state correctly. |
| 2254 TEST_F(ShelfViewInkDropTest, WithMenuPressRelease) { |
| 2255 // Set a delegate for the shelf item that returns an app list menu. |
| 2256 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 2257 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate; |
| 2258 item_manager_->SetShelfItemDelegate(browser_shelf_id, |
| 2259 base::WrapUnique(list_menu_delegate)); |
| 2260 |
| 2261 views::CustomButton* button = browser_button_; |
| 2262 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); |
| 2263 |
| 2264 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, |
| 2265 press_location, ui::EventTimeForNow(), |
| 2266 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2267 button->OnMousePressed(press_event); |
| 2268 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2269 ink_drop_->GetTargetInkDropState()); |
| 2270 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2271 ElementsAre(views::InkDropState::ACTION_PENDING)); |
| 2272 |
| 2273 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2274 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu, |
| 2275 base::Unretained(test_api_.get()))); |
| 2276 |
| 2277 // Mouse release will spawn a menu which will then get closed by the above |
| 2278 // posted task. |
| 2279 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, |
| 2280 press_location, ui::EventTimeForNow(), |
| 2281 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2282 button->OnMouseReleased(release_event); |
| 2283 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); |
| 2284 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), |
| 2285 ElementsAre(views::InkDropState::ACTIVATED, |
| 2286 views::InkDropState::DEACTIVATED)); |
| 2287 } |
| 2288 |
| 1998 } // namespace test | 2289 } // namespace test |
| 1999 } // namespace ash | 2290 } // namespace ash |
| OLD | NEW |