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