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: ash/shelf/shelf_view_unittest.cc

Issue 2070143003: Add MD ink drop ripple to app list button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b612539_shelf_button_ripple
Patch Set: Addressed review comments Created 4 years, 5 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 "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_menu_model.h"
15 #include "ash/common/shelf/shelf_model.h" 15 #include "ash/common/shelf/shelf_model.h"
16 #include "ash/common/shell_window_ids.h" 16 #include "ash/common/shell_window_ids.h"
17 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
18 #include "ash/shelf/app_list_button.h" 18 #include "ash/shelf/app_list_button.h"
19 #include "ash/shelf/overflow_bubble.h" 19 #include "ash/shelf/overflow_bubble.h"
20 #include "ash/shelf/overflow_bubble_view.h" 20 #include "ash/shelf/overflow_bubble_view.h"
21 #include "ash/shelf/shelf.h" 21 #include "ash/shelf/shelf.h"
22 #include "ash/shelf/shelf_button.h" 22 #include "ash/shelf/shelf_button.h"
23 #include "ash/shelf/shelf_icon_observer.h" 23 #include "ash/shelf/shelf_icon_observer.h"
24 #include "ash/shelf/shelf_tooltip_manager.h" 24 #include "ash/shelf/shelf_tooltip_manager.h"
25 #include "ash/shelf/shelf_widget.h" 25 #include "ash/shelf/shelf_widget.h"
26 #include "ash/shell.h" 26 #include "ash/shell.h"
27 #include "ash/test/ash_test_base.h" 27 #include "ash/test/ash_test_base.h"
28 #include "ash/test/ash_test_helper.h"
28 #include "ash/test/material_design_controller_test_api.h" 29 #include "ash/test/material_design_controller_test_api.h"
29 #include "ash/test/overflow_bubble_view_test_api.h" 30 #include "ash/test/overflow_bubble_view_test_api.h"
30 #include "ash/test/shelf_test_api.h" 31 #include "ash/test/shelf_test_api.h"
31 #include "ash/test/shelf_view_test_api.h" 32 #include "ash/test/shelf_view_test_api.h"
32 #include "ash/test/shell_test_api.h" 33 #include "ash/test/shell_test_api.h"
33 #include "ash/test/test_shelf_delegate.h" 34 #include "ash/test/test_shelf_delegate.h"
34 #include "ash/test/test_shelf_item_delegate.h" 35 #include "ash/test/test_shelf_item_delegate.h"
36 #include "ash/test/test_shell_delegate.h"
35 #include "ash/test/test_system_tray_delegate.h" 37 #include "ash/test/test_system_tray_delegate.h"
36 #include "base/compiler_specific.h" 38 #include "base/compiler_specific.h"
37 #include "base/i18n/rtl.h" 39 #include "base/i18n/rtl.h"
38 #include "base/run_loop.h" 40 #include "base/run_loop.h"
39 #include "base/strings/string_number_conversions.h" 41 #include "base/strings/string_number_conversions.h"
40 #include "base/strings/utf_string_conversions.h" 42 #include "base/strings/utf_string_conversions.h"
41 #include "base/test/histogram_tester.h" 43 #include "base/test/histogram_tester.h"
42 #include "base/test/user_action_tester.h" 44 #include "base/test/user_action_tester.h"
43 #include "base/threading/thread_task_runner_handle.h" 45 #include "base/threading/thread_task_runner_handle.h"
44 #include "base/time/time.h" 46 #include "base/time/time.h"
45 #include "testing/gmock/include/gmock/gmock.h" 47 #include "testing/gmock/include/gmock/gmock.h"
48 #include "ui/app_list/presenter/app_list_presenter.h"
46 #include "ui/aura/test/aura_test_base.h" 49 #include "ui/aura/test/aura_test_base.h"
47 #include "ui/aura/window.h" 50 #include "ui/aura/window.h"
48 #include "ui/aura/window_event_dispatcher.h" 51 #include "ui/aura/window_event_dispatcher.h"
49 #include "ui/compositor/layer.h" 52 #include "ui/compositor/layer.h"
50 #include "ui/events/event.h" 53 #include "ui/events/event.h"
51 #include "ui/events/event_constants.h" 54 #include "ui/events/event_constants.h"
52 #include "ui/events/event_utils.h" 55 #include "ui/events/event_utils.h"
53 #include "ui/events/test/event_generator.h" 56 #include "ui/events/test/event_generator.h"
54 #include "ui/gfx/geometry/point.h" 57 #include "ui/gfx/geometry/point.h"
55 #include "ui/views/animation/ink_drop_impl.h" 58 #include "ui/views/animation/ink_drop_impl.h"
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 ShelfButton* button = test_api_->GetButton(i); 1478 ShelfButton* button = test_api_->GetButton(i);
1476 if (!button) 1479 if (!button)
1477 continue; 1480 continue;
1478 1481
1479 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1482 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1480 button->GetMirroredBounds().CenterPoint())) 1483 button->GetMirroredBounds().CenterPoint()))
1481 << "ShelfView tries to hide on button " << i; 1484 << "ShelfView tries to hide on button " << i;
1482 } 1485 }
1483 1486
1484 // The tooltip should not hide on the app-list button. 1487 // The tooltip should not hide on the app-list button.
1485 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1488 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1486 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1489 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1487 app_list_button->GetMirroredBounds().CenterPoint())); 1490 app_list_button->GetMirroredBounds().CenterPoint()));
1488 1491
1489 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. 1492 // The tooltip shouldn't hide if the mouse is in the gap between two buttons.
1490 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); 1493 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds();
1491 gfx::Rect platform_button_rect = 1494 gfx::Rect platform_button_rect =
1492 GetButtonByID(platform_button_id)->GetMirroredBounds(); 1495 GetButtonByID(platform_button_id)->GetMirroredBounds();
1493 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect)); 1496 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect));
1494 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1497 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1495 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint())); 1498 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint()));
1496 1499
1497 // The tooltip should hide if it's outside of all buttons. 1500 // The tooltip should hide if it's outside of all buttons.
1498 gfx::Rect all_area; 1501 gfx::Rect all_area;
1499 for (int i = 0; i < test_api_->GetButtonCount(); i++) { 1502 for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1500 ShelfButton* button = test_api_->GetButton(i); 1503 ShelfButton* button = test_api_->GetButton(i);
1501 if (!button) 1504 if (!button)
1502 continue; 1505 continue;
1503 1506
1504 all_area.Union(button->GetMirroredBounds()); 1507 all_area.Union(button->GetMirroredBounds());
1505 } 1508 }
1506 all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds()); 1509 all_area.Union(shelf_view_->GetAppListButton()->GetMirroredBounds());
1507 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin())); 1510 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin()));
1508 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1511 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1509 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); 1512 gfx::Point(all_area.right() - 1, all_area.bottom() - 1)));
1510 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1513 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1511 gfx::Point(all_area.right(), all_area.y()))); 1514 gfx::Point(all_area.right(), all_area.y())));
1512 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1515 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1513 gfx::Point(all_area.x() - 1, all_area.y()))); 1516 gfx::Point(all_area.x() - 1, all_area.y())));
1514 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1517 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1515 gfx::Point(all_area.x(), all_area.y() - 1))); 1518 gfx::Point(all_area.x(), all_area.y() - 1)));
1516 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1519 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1517 gfx::Point(all_area.x(), all_area.bottom()))); 1520 gfx::Point(all_area.x(), all_area.bottom())));
1518 } 1521 }
1519 1522
1520 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) { 1523 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
1521 Shell::GetInstance()->ShowAppList(NULL); 1524 Shell::GetInstance()->ShowAppList(NULL);
1522 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1525 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1523 1526
1524 // The tooltip shouldn't hide if the mouse is on normal buttons. 1527 // The tooltip shouldn't hide if the mouse is on normal buttons.
1525 for (int i = 1; i < test_api_->GetButtonCount(); i++) { 1528 for (int i = 1; i < test_api_->GetButtonCount(); i++) {
1526 ShelfButton* button = test_api_->GetButton(i); 1529 ShelfButton* button = test_api_->GetButton(i);
1527 if (!button) 1530 if (!button)
1528 continue; 1531 continue;
1529 1532
1530 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1533 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1531 button->GetMirroredBounds().CenterPoint())) 1534 button->GetMirroredBounds().CenterPoint()))
1532 << "ShelfView tries to hide on button " << i; 1535 << "ShelfView tries to hide on button " << i;
1533 } 1536 }
1534 1537
1535 // The tooltip should hide on the app-list button. 1538 // The tooltip should hide on the app-list button.
1536 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1539 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1537 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1540 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1538 app_list_button->GetMirroredBounds().CenterPoint())); 1541 app_list_button->GetMirroredBounds().CenterPoint()));
1539 } 1542 }
1540 1543
1541 // Test that by moving the mouse cursor off the button onto the bubble it closes 1544 // Test that by moving the mouse cursor off the button onto the bubble it closes
1542 // the bubble. 1545 // the bubble.
1543 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { 1546 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
1544 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager(); 1547 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1545 tooltip_manager->set_timer_delay_for_test(0); 1548 tooltip_manager->set_timer_delay_for_test(0);
1546 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1549 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1547 1550
1548 // Move the mouse off any item and check that no tooltip is shown. 1551 // Move the mouse off any item and check that no tooltip is shown.
1549 generator.MoveMouseTo(gfx::Point(0, 0)); 1552 generator.MoveMouseTo(gfx::Point(0, 0));
1550 EXPECT_FALSE(tooltip_manager->IsVisible()); 1553 EXPECT_FALSE(tooltip_manager->IsVisible());
1551 1554
1552 // Move the mouse over the button and check that it is visible. 1555 // Move the mouse over the button and check that it is visible.
1553 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1556 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1554 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1557 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1555 generator.MoveMouseTo(bounds.CenterPoint()); 1558 generator.MoveMouseTo(bounds.CenterPoint());
1556 // Wait for the timer to go off. 1559 // Wait for the timer to go off.
1557 RunAllPendingInMessageLoop(); 1560 RunAllPendingInMessageLoop();
1558 EXPECT_TRUE(tooltip_manager->IsVisible()); 1561 EXPECT_TRUE(tooltip_manager->IsVisible());
1559 1562
1560 // Move the mouse cursor slightly to the right of the item. The tooltip should 1563 // Move the mouse cursor slightly to the right of the item. The tooltip should
1561 // stay open. 1564 // stay open.
1562 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); 1565 generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
1563 // Make sure there is no delayed close. 1566 // Make sure there is no delayed close.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 1856
1854 // Make the added running platform app to be an app shortcut. 1857 // Make the added running platform app to be an app shortcut.
1855 // This app shortcut should be a swapped view in overflow bubble, which is 1858 // This app shortcut should be a swapped view in overflow bubble, which is
1856 // invisible. 1859 // invisible.
1857 SetShelfItemTypeToAppShortcut(platform_app_id); 1860 SetShelfItemTypeToAppShortcut(platform_app_id);
1858 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); 1861 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible());
1859 } 1862 }
1860 1863
1861 // Tests that the AppListButton renders as active in response to touches. 1864 // Tests that the AppListButton renders as active in response to touches.
1862 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) { 1865 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) {
1863 AppListButton* app_list_button = 1866 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1864 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1865 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1867 EXPECT_FALSE(app_list_button->draw_background_as_active());
1866 1868
1867 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1869 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1868 generator.set_current_location(app_list_button-> 1870 generator.set_current_location(app_list_button->
1869 GetBoundsInScreen().CenterPoint()); 1871 GetBoundsInScreen().CenterPoint());
1870 generator.PressTouch(); 1872 generator.PressTouch();
1871 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1873 EXPECT_TRUE(app_list_button->draw_background_as_active());
1872 1874
1873 generator.ReleaseTouch(); 1875 generator.ReleaseTouch();
1874 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1876 EXPECT_FALSE(app_list_button->draw_background_as_active());
1875 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1877 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1876 } 1878 }
1877 1879
1878 // Tests that a touch that slides out of the bounds of the AppListButton leads 1880 // Tests that a touch that slides out of the bounds of the AppListButton leads
1879 // to the end of rendering an active state. 1881 // to the end of rendering an active state.
1880 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) { 1882 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) {
1881 AppListButton* app_list_button = 1883 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1882 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1883 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1884 EXPECT_FALSE(app_list_button->draw_background_as_active());
1884 1885
1885 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1886 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1886 generator.set_current_location(app_list_button-> 1887 generator.set_current_location(app_list_button->
1887 GetBoundsInScreen().CenterPoint()); 1888 GetBoundsInScreen().CenterPoint());
1888 generator.PressTouch(); 1889 generator.PressTouch();
1889 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1890 EXPECT_TRUE(app_list_button->draw_background_as_active());
1890 1891
1891 gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1, 1892 gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1,
1892 app_list_button-> 1893 app_list_button->
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); 1972 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
1972 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); 1973 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1973 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1974 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
1974 if (ShelfButton* button = test_api_->GetButton(i)) 1975 if (ShelfButton* button = test_api_->GetButton(i))
1975 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); 1976 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
1976 CheckAppListButtonIsInBounds(); 1977 CheckAppListButtonIsInBounds();
1977 } 1978 }
1978 1979
1979 void CheckAppListButtonIsInBounds() { 1980 void CheckAppListButtonIsInBounds() {
1980 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1981 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1981 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> 1982 gfx::Rect app_list_button_bounds =
1982 GetBoundsInScreen(); 1983 shelf_view_->GetAppListButton()->GetBoundsInScreen();
1983 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds)); 1984 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds));
1984 } 1985 }
1985 1986
1986 private: 1987 private:
1987 ScopedTextDirectionChange text_direction_change_; 1988 ScopedTextDirectionChange text_direction_change_;
1988 1989
1989 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest); 1990 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest);
1990 }; 1991 };
1991 1992
1992 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) { 1993 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 2096
2096 private: 2097 private:
2097 // TestShelfItemDelegate: 2098 // TestShelfItemDelegate:
2098 ShelfMenuModel* CreateApplicationMenu(int event_flags) override { 2099 ShelfMenuModel* CreateApplicationMenu(int event_flags) override {
2099 return new TestShelfMenuModel; 2100 return new TestShelfMenuModel;
2100 } 2101 }
2101 2102
2102 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); 2103 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate);
2103 }; 2104 };
2104 2105
2106 // A test implementation for AppListPresenter that does not change visibility
2107 // state immediately to simulate an in-flight animation. Calling
2108 // FinishVisibilityChange() will change the visibility to the requested one,
2109 // simulating end of the animation. Similar to the actual AppListPresenter, this
2110 // class toggles app list visibility based on the actual visibility rather than
2111 // the target visibility (which might be different due to in-flight animation).
2112 class TestAppListPresenter : public app_list::AppListPresenter {
2113 public:
2114 TestAppListPresenter() {}
2115 ~TestAppListPresenter() override {}
2116
2117 void FinishVisibilityChange() { is_visible_ = target_visibility_; }
2118
2119 // app_list::AppListPresenter:
2120 void Show(int64_t display_id) override { target_visibility_ = true; }
2121 void Dismiss() override { target_visibility_ = false; }
2122 void ToggleAppList(int64_t display_id) override {
2123 if (is_visible_)
2124 Dismiss();
2125 else
2126 Show(display_id);
2127 }
2128 bool IsVisible() const override { return is_visible_; }
2129 bool GetTargetVisibility() const override { return target_visibility_; }
2130
2131 private:
2132 bool is_visible_ = false;
2133 bool target_visibility_ = false;
2134
2135 DISALLOW_COPY_AND_ASSIGN(TestAppListPresenter);
2136 };
2137
2138 // A test ShellDelegate implementation that returns a TestAppListPresenter as
2139 // the app list presenter.
2140 class TestAppListShellDelegate : public TestShellDelegate {
2141 public:
2142 TestAppListShellDelegate()
2143 : app_list_presenter_(new TestAppListPresenter()) {}
2144 ~TestAppListShellDelegate() override {}
2145
2146 TestAppListPresenter* app_list_presenter() const {
2147 return app_list_presenter_.get();
2148 }
2149
2150 // TestShellDelegate:
2151 app_list::AppListPresenter* GetAppListPresenter() override {
2152 return app_list_presenter();
2153 }
2154
2155 private:
2156 std::unique_ptr<TestAppListPresenter> app_list_presenter_;
2157
2158 DISALLOW_COPY_AND_ASSIGN(TestAppListShellDelegate);
2159 };
2160
2105 } // namespace 2161 } // namespace
2106 2162
2107 class ShelfViewInkDropTest : public ShelfViewTest { 2163 class ShelfViewInkDropTest : public ShelfViewTest {
2108 public: 2164 public:
2109 ShelfViewInkDropTest() : ink_drop_(nullptr), browser_button_(nullptr) {} 2165 ShelfViewInkDropTest() {}
2110 ~ShelfViewInkDropTest() override {} 2166 ~ShelfViewInkDropTest() override {}
2111 2167
2112 void SetUp() override { 2168 void SetUp() override {
2169 shell_delegate_ = new TestAppListShellDelegate;
2170 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
2171
2113 ShelfViewTest::SetUp(); 2172 ShelfViewTest::SetUp();
2114 2173
2115 // TODO(mohsen): Ideally, we would want to set material mode before calling 2174 // TODO(mohsen): Ideally, we would want to set material mode before calling
2116 // ShelfViewTest::SetUp() so that everything is set up with the correct 2175 // ShelfViewTest::SetUp() so that everything is set up with the correct
2117 // material mode. Currently, this is not possible as it expects material 2176 // material mode. Currently, this is not possible as it expects material
2118 // mode be UNINITIALIZED. (See https://crbug.com/620093) 2177 // mode be UNINITIALIZED. (See https://crbug.com/620093)
2119 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI( 2178 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI(
2120 ash::MaterialDesignController::MATERIAL_NORMAL)); 2179 ash::MaterialDesignController::MATERIAL_EXPERIMENTAL));
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 } 2180 }
2129 2181
2130 void TearDown() override { 2182 void TearDown() override {
2131 ash_md_controller_.reset(); 2183 ash_md_controller_.reset();
2132 2184
2133 ShelfViewTest::TearDown(); 2185 ShelfViewTest::TearDown();
2134 } 2186 }
2135 2187
2136 protected: 2188 protected:
2189 void InitAppListButtonInkDrop() {
2190 app_list_button_ = shelf_view_->GetAppListButton();
2191
2192 views::InkDropImpl* ink_drop_impl =
2193 new views::InkDropImpl(app_list_button_);
2194 app_list_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2195 views::test::InkDropHostViewTestApi(app_list_button_)
2196 .SetInkDrop(base::WrapUnique(app_list_button_ink_drop_), false);
2197 }
2198
2199 void InitBrowserButtonInkDrop() {
2200 browser_button_ = test_api_->GetButton(browser_index_);
2201
2202 views::InkDropImpl* ink_drop_impl = new views::InkDropImpl(browser_button_);
2203 browser_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2204 views::test::InkDropHostViewTestApi(browser_button_)
2205 .SetInkDrop(base::WrapUnique(browser_button_ink_drop_));
2206 }
2207
2208 void ShowAppList() {
2209 shell_delegate_->app_list_presenter()->Show(0);
2210 // Similar to real AppListPresenter, notify button that the app list is
2211 // shown.
2212 app_list_button_->OnAppListShown();
2213 }
2214
2215 void DismissAppList() {
2216 shell_delegate_->app_list_presenter()->Dismiss();
2217 // Similar to real AppListPresenter, notify button that the app list is
2218 // dismissed.
2219 app_list_button_->OnAppListDismissed();
2220 }
2221
2222 void FinishAppListVisibilityChange() {
2223 shell_delegate_->app_list_presenter()->FinishVisibilityChange();
2224 }
2225
2137 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI> 2226 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI>
2138 ash_md_controller_; 2227 ash_md_controller_;
2139 2228
2140 InkDropSpy* ink_drop_; 2229 TestAppListShellDelegate* shell_delegate_ = nullptr; // Owned by Shell.
2141 ShelfButton* browser_button_; 2230
2231 AppListButton* app_list_button_ = nullptr;
2232 InkDropSpy* app_list_button_ink_drop_ = nullptr;
2233 ShelfButton* browser_button_ = nullptr;
2234 InkDropSpy* browser_button_ink_drop_ = nullptr;
2142 2235
2143 private: 2236 private:
2144 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest); 2237 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest);
2145 }; 2238 };
2146 2239
2240 // Tests that changing visibility of the app list transitions app list button's
2241 // ink drop states correctly.
2242 TEST_F(ShelfViewInkDropTest, AppListButtonWhenVisibilityChanges) {
2243 InitAppListButtonInkDrop();
2244
2245 ShowAppList();
2246 FinishAppListVisibilityChange();
2247 EXPECT_EQ(views::InkDropState::ACTIVATED,
2248 app_list_button_ink_drop_->GetTargetInkDropState());
2249 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2250 ElementsAre(views::InkDropState::ACTIVATED));
2251
2252 DismissAppList();
2253 FinishAppListVisibilityChange();
2254 EXPECT_EQ(views::InkDropState::HIDDEN,
2255 app_list_button_ink_drop_->GetTargetInkDropState());
2256 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2257 ElementsAre(views::InkDropState::DEACTIVATED));
2258 }
2259
2260 // Tests that when the app list is hidden, mouse press on the app list button,
2261 // which shows the app list, transitions ink drop states correctly. Also, tests
2262 // that mouse drag and mouse release does not affect the ink drop state.
2263 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenHidden) {
2264 InitAppListButtonInkDrop();
2265
2266 ui::test::EventGenerator& generator = GetEventGenerator();
2267 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2268
2269 // Mouse press on the button, which shows the app list, should end up in the
2270 // activated state.
2271 generator.PressLeftButton();
2272 // Similar to real AppListPresenter, notify button that the app list is shown.
2273 app_list_button_->OnAppListShown();
2274 FinishAppListVisibilityChange();
2275 EXPECT_EQ(views::InkDropState::ACTIVATED,
2276 app_list_button_ink_drop_->GetTargetInkDropState());
2277 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2278 ElementsAre(views::InkDropState::ACTION_PENDING,
2279 views::InkDropState::ACTIVATED));
2280
2281 // Dragging mouse out and back and releasing the button should not change the
2282 // ink drop state.
2283 generator.MoveMouseBy(app_list_button_->width(), 0);
2284 generator.MoveMouseBy(-app_list_button_->width(), 0);
2285 generator.ReleaseLeftButton();
2286 EXPECT_EQ(views::InkDropState::ACTIVATED,
2287 app_list_button_ink_drop_->GetTargetInkDropState());
2288 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2289 IsEmpty());
2290 }
2291
2292 // Tests that when the app list is visible, mouse press on the app list button,
2293 // which dismisses the app list, transitions ink drop states correctly. Also,
2294 // tests that mouse drag and mouse release does not affect the ink drop state.
2295 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenVisible) {
2296 InitAppListButtonInkDrop();
2297
2298 // Show the app list.
2299 ShowAppList();
2300 FinishAppListVisibilityChange();
2301 EXPECT_EQ(views::InkDropState::ACTIVATED,
2302 app_list_button_ink_drop_->GetTargetInkDropState());
2303 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2304 ElementsAre(views::InkDropState::ACTIVATED));
2305
2306 ui::test::EventGenerator& generator = GetEventGenerator();
2307 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2308
2309 // Mouse press on the button, which dismisses the app list, should end up in
2310 // the hidden state.
2311 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2312 DismissAppList();
2313 generator.PressLeftButton();
2314 FinishAppListVisibilityChange();
2315 EXPECT_EQ(views::InkDropState::HIDDEN,
2316 app_list_button_ink_drop_->GetTargetInkDropState());
2317 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2318 ElementsAre(views::InkDropState::DEACTIVATED));
2319
2320 // Dragging mouse out and back and releasing the button should not change the
2321 // ink drop state.
2322 generator.MoveMouseBy(app_list_button_->width(), 0);
2323 generator.MoveMouseBy(-app_list_button_->width(), 0);
2324 generator.ReleaseLeftButton();
2325 EXPECT_EQ(views::InkDropState::HIDDEN,
2326 app_list_button_ink_drop_->GetTargetInkDropState());
2327 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2328 IsEmpty());
2329 }
2330
2331 // Tests that when the app list is hidden, tapping on the app list button
2332 // transitions ink drop states correctly.
2333 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenHidden) {
2334 InitAppListButtonInkDrop();
2335
2336 ui::test::EventGenerator& generator = GetEventGenerator();
2337 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2338
2339 // Touch press on the button should end up in the pending state.
2340 generator.PressTouch();
2341 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2342 app_list_button_ink_drop_->GetTargetInkDropState());
2343 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2344 ElementsAre(views::InkDropState::ACTION_PENDING));
2345
2346 // Touch release on the button, which shows the app list, should end up in the
2347 // activated state.
2348 generator.ReleaseTouch();
2349 // Similar to real AppListPresenter, notify button that the app list is shown.
2350 app_list_button_->OnAppListShown();
2351 FinishAppListVisibilityChange();
2352 EXPECT_EQ(views::InkDropState::ACTIVATED,
2353 app_list_button_ink_drop_->GetTargetInkDropState());
2354 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2355 ElementsAre(views::InkDropState::ACTIVATED));
2356 }
2357
2358 // Tests that when the app list is visible, tapping on the app list button
2359 // transitions ink drop states correctly.
2360 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenVisible) {
2361 InitAppListButtonInkDrop();
2362
2363 // Show the app list.
2364 ShowAppList();
2365 FinishAppListVisibilityChange();
2366 EXPECT_EQ(views::InkDropState::ACTIVATED,
2367 app_list_button_ink_drop_->GetTargetInkDropState());
2368 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2369 ElementsAre(views::InkDropState::ACTIVATED));
2370
2371 ui::test::EventGenerator& generator = GetEventGenerator();
2372 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2373
2374 // Touch press on the button, which dismisses the app list, should end up in
2375 // the hidden state.
2376 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2377 DismissAppList();
2378 generator.PressTouch();
2379 EXPECT_EQ(views::InkDropState::HIDDEN,
2380 app_list_button_ink_drop_->GetTargetInkDropState());
2381 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2382 ElementsAre(views::InkDropState::DEACTIVATED));
2383
2384 // Touch release on the button should not change the ink drop state.
2385 generator.ReleaseTouch();
2386 FinishAppListVisibilityChange();
2387 EXPECT_EQ(views::InkDropState::HIDDEN,
2388 app_list_button_ink_drop_->GetTargetInkDropState());
2389 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2390 IsEmpty());
2391 }
2392
2393 // Tests that when the app list is hidden, tapping down on the app list button
2394 // and dragging the touch point transitions ink drop states correctly.
2395 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenHidden) {
2396 InitAppListButtonInkDrop();
2397
2398 ui::test::EventGenerator& generator = GetEventGenerator();
2399 gfx::Point touch_location =
2400 app_list_button_->GetBoundsInScreen().CenterPoint();
2401 generator.MoveMouseTo(touch_location);
2402
2403 // Touch press on the button should end up in the pending state.
2404 generator.PressTouch();
2405 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2406 app_list_button_ink_drop_->GetTargetInkDropState());
2407 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2408 ElementsAre(views::InkDropState::ACTION_PENDING));
2409
2410 // Dragging the touch point should hide the pending ink drop.
2411 touch_location.Offset(app_list_button_->width(), 0);
2412 generator.MoveTouch(touch_location);
2413 EXPECT_EQ(views::InkDropState::HIDDEN,
2414 app_list_button_ink_drop_->GetTargetInkDropState());
2415 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2416 ElementsAre(views::InkDropState::HIDDEN));
2417
2418 // Touch release should not change the ink drop state.
2419 generator.ReleaseTouch();
2420 EXPECT_EQ(views::InkDropState::HIDDEN,
2421 app_list_button_ink_drop_->GetTargetInkDropState());
2422 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2423 IsEmpty());
2424 }
2425
2426 // Tests that when the app list is visible, tapping down on the app list button
2427 // and dragging the touch point transitions ink drop states correctly.
2428 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenVisible) {
2429 InitAppListButtonInkDrop();
2430
2431 // Show the app list.
2432 ShowAppList();
2433 FinishAppListVisibilityChange();
2434 EXPECT_EQ(views::InkDropState::ACTIVATED,
2435 app_list_button_ink_drop_->GetTargetInkDropState());
2436 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2437 ElementsAre(views::InkDropState::ACTIVATED));
2438
2439 ui::test::EventGenerator& generator = GetEventGenerator();
2440 gfx::Point touch_location =
2441 app_list_button_->GetBoundsInScreen().CenterPoint();
2442 generator.MoveMouseTo(touch_location);
2443
2444 // Touch press on the button, which dismisses the app list, should end up in
2445 // the hidden state.
2446 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2447 DismissAppList();
2448 generator.PressTouch();
2449 EXPECT_EQ(views::InkDropState::HIDDEN,
2450 app_list_button_ink_drop_->GetTargetInkDropState());
2451 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2452 ElementsAre(views::InkDropState::DEACTIVATED));
2453
2454 // Dragging the touch point and releasing should not change the ink drop
2455 // state.
2456 touch_location.Offset(app_list_button_->width(), 0);
2457 generator.MoveTouch(touch_location);
2458 generator.ReleaseTouch();
2459 FinishAppListVisibilityChange();
2460 EXPECT_EQ(views::InkDropState::HIDDEN,
2461 app_list_button_ink_drop_->GetTargetInkDropState());
2462 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2463 ElementsAre(views::InkDropState::HIDDEN));
2464 }
2465
2147 // Tests that clicking on a shelf item that does not show a menu transitions ink 2466 // Tests that clicking on a shelf item that does not show a menu transitions ink
2148 // drop states correctly. 2467 // drop states correctly.
2149 TEST_F(ShelfViewInkDropTest, WithoutMenuPressRelease) { 2468 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressRelease) {
2469 InitBrowserButtonInkDrop();
2470
2150 views::CustomButton* button = browser_button_; 2471 views::CustomButton* button = browser_button_;
2151 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2472 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2152 2473
2153 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2474 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2154 press_location, ui::EventTimeForNow(), 2475 mouse_location, ui::EventTimeForNow(),
2155 ui::EF_LEFT_MOUSE_BUTTON, 0); 2476 ui::EF_LEFT_MOUSE_BUTTON, 0);
2156 button->OnMousePressed(press_event); 2477 button->OnMousePressed(press_event);
2157 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2478 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2158 ink_drop_->GetTargetInkDropState()); 2479 browser_button_ink_drop_->GetTargetInkDropState());
2159 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2480 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2160 ElementsAre(views::InkDropState::ACTION_PENDING)); 2481 ElementsAre(views::InkDropState::ACTION_PENDING));
2161 2482
2162 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2483 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2163 press_location, ui::EventTimeForNow(), 2484 mouse_location, ui::EventTimeForNow(),
2164 ui::EF_LEFT_MOUSE_BUTTON, 0); 2485 ui::EF_LEFT_MOUSE_BUTTON, 0);
2165 button->OnMouseReleased(release_event); 2486 button->OnMouseReleased(release_event);
2166 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2487 EXPECT_EQ(views::InkDropState::HIDDEN,
2167 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2488 browser_button_ink_drop_->GetTargetInkDropState());
2489 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2168 ElementsAre(views::InkDropState::ACTION_TRIGGERED)); 2490 ElementsAre(views::InkDropState::ACTION_TRIGGERED));
2169 } 2491 }
2170 2492
2171 // Tests that dragging outside of a shelf item transitions ink drop states 2493 // Tests that dragging outside of a shelf item transitions ink drop states
2172 // correctly. 2494 // correctly.
2173 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseOutside) { 2495 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseOutside) {
2496 InitBrowserButtonInkDrop();
2497
2174 views::CustomButton* button = browser_button_; 2498 views::CustomButton* button = browser_button_;
2175 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2499 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2176 2500
2177 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2501 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2178 press_location, ui::EventTimeForNow(), 2502 mouse_location, ui::EventTimeForNow(),
2179 ui::EF_LEFT_MOUSE_BUTTON, 0); 2503 ui::EF_LEFT_MOUSE_BUTTON, 0);
2180 button->OnMousePressed(press_event); 2504 button->OnMousePressed(press_event);
2181 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2505 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2182 ink_drop_->GetTargetInkDropState()); 2506 browser_button_ink_drop_->GetTargetInkDropState());
2183 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2507 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2184 ElementsAre(views::InkDropState::ACTION_PENDING)); 2508 ElementsAre(views::InkDropState::ACTION_PENDING));
2185 2509
2186 press_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0); 2510 mouse_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0);
2187 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, press_location, 2511 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, mouse_location,
2188 press_location, ui::EventTimeForNow(), 2512 mouse_location, ui::EventTimeForNow(),
2189 ui::EF_LEFT_MOUSE_BUTTON, 0); 2513 ui::EF_LEFT_MOUSE_BUTTON, 0);
2190 button->OnMouseDragged(drag_event_small); 2514 button->OnMouseDragged(drag_event_small);
2191 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2515 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2192 ink_drop_->GetTargetInkDropState()); 2516 browser_button_ink_drop_->GetTargetInkDropState());
2193 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2517 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2194 2518 IsEmpty());
2195 press_location.Offset(test_api_->GetMinimumDragDistance(), 0); 2519
2196 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, press_location, 2520 mouse_location.Offset(test_api_->GetMinimumDragDistance(), 0);
2197 press_location, ui::EventTimeForNow(), 2521 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, mouse_location,
2522 mouse_location, ui::EventTimeForNow(),
2198 ui::EF_LEFT_MOUSE_BUTTON, 0); 2523 ui::EF_LEFT_MOUSE_BUTTON, 0);
2199 button->OnMouseDragged(drag_event_large); 2524 button->OnMouseDragged(drag_event_large);
2200 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2525 EXPECT_EQ(views::InkDropState::HIDDEN,
2201 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2526 browser_button_ink_drop_->GetTargetInkDropState());
2527 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2202 ElementsAre(views::InkDropState::HIDDEN)); 2528 ElementsAre(views::InkDropState::HIDDEN));
2203 2529
2204 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2530 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2205 press_location, ui::EventTimeForNow(), 2531 mouse_location, ui::EventTimeForNow(),
2206 ui::EF_LEFT_MOUSE_BUTTON, 0); 2532 ui::EF_LEFT_MOUSE_BUTTON, 0);
2207 button->OnMouseReleased(release_event); 2533 button->OnMouseReleased(release_event);
2208 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2534 EXPECT_EQ(views::InkDropState::HIDDEN,
2209 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2535 browser_button_ink_drop_->GetTargetInkDropState());
2536 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2537 IsEmpty());
2210 } 2538 }
2211 2539
2212 // Tests that dragging outside of a shelf item and back transitions ink drop 2540 // Tests that dragging outside of a shelf item and back transitions ink drop
2213 // states correctly. 2541 // states correctly.
2214 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseInside) { 2542 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseInside) {
2543 InitBrowserButtonInkDrop();
2544
2215 views::CustomButton* button = browser_button_; 2545 views::CustomButton* button = browser_button_;
2216 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2546 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2217 2547
2218 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2548 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2219 press_location, ui::EventTimeForNow(), 2549 mouse_location, ui::EventTimeForNow(),
2220 ui::EF_LEFT_MOUSE_BUTTON, 0); 2550 ui::EF_LEFT_MOUSE_BUTTON, 0);
2221 button->OnMousePressed(press_event); 2551 button->OnMousePressed(press_event);
2222 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2552 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2223 ink_drop_->GetTargetInkDropState()); 2553 browser_button_ink_drop_->GetTargetInkDropState());
2224 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2554 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2225 ElementsAre(views::InkDropState::ACTION_PENDING)); 2555 ElementsAre(views::InkDropState::ACTION_PENDING));
2226 2556
2227 press_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0); 2557 mouse_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0);
2228 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, press_location, 2558 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, mouse_location,
2229 press_location, ui::EventTimeForNow(), 2559 mouse_location, ui::EventTimeForNow(),
2230 ui::EF_LEFT_MOUSE_BUTTON, 0); 2560 ui::EF_LEFT_MOUSE_BUTTON, 0);
2231 button->OnMouseDragged(drag_event_outside); 2561 button->OnMouseDragged(drag_event_outside);
2232 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2562 EXPECT_EQ(views::InkDropState::HIDDEN,
2233 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2563 browser_button_ink_drop_->GetTargetInkDropState());
2564 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2234 ElementsAre(views::InkDropState::HIDDEN)); 2565 ElementsAre(views::InkDropState::HIDDEN));
2235 2566
2236 press_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0); 2567 mouse_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0);
2237 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, press_location, 2568 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, mouse_location,
2238 press_location, ui::EventTimeForNow(), 2569 mouse_location, ui::EventTimeForNow(),
2239 ui::EF_LEFT_MOUSE_BUTTON, 0); 2570 ui::EF_LEFT_MOUSE_BUTTON, 0);
2240 button->OnMouseDragged(drag_event_inside); 2571 button->OnMouseDragged(drag_event_inside);
2241 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2572 EXPECT_EQ(views::InkDropState::HIDDEN,
2242 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2573 browser_button_ink_drop_->GetTargetInkDropState());
2243 2574 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2244 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2575 IsEmpty());
2245 press_location, ui::EventTimeForNow(), 2576
2577 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2578 mouse_location, ui::EventTimeForNow(),
2246 ui::EF_LEFT_MOUSE_BUTTON, 0); 2579 ui::EF_LEFT_MOUSE_BUTTON, 0);
2247 button->OnMouseReleased(release_event); 2580 button->OnMouseReleased(release_event);
2248 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2581 EXPECT_EQ(views::InkDropState::HIDDEN,
2249 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2582 browser_button_ink_drop_->GetTargetInkDropState());
2583 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2584 IsEmpty());
2250 } 2585 }
2251 2586
2252 // Tests that clicking on a shelf item that shows an app list menu transitions 2587 // Tests that clicking on a shelf item that shows an app list menu transitions
2253 // ink drop state correctly. 2588 // ink drop state correctly.
2254 TEST_F(ShelfViewInkDropTest, WithMenuPressRelease) { 2589 TEST_F(ShelfViewInkDropTest, ShelfButtonWithMenuPressRelease) {
2590 InitBrowserButtonInkDrop();
2591
2255 // Set a delegate for the shelf item that returns an app list menu. 2592 // Set a delegate for the shelf item that returns an app list menu.
2256 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 2593 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
2257 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate; 2594 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate;
2258 item_manager_->SetShelfItemDelegate(browser_shelf_id, 2595 item_manager_->SetShelfItemDelegate(browser_shelf_id,
2259 base::WrapUnique(list_menu_delegate)); 2596 base::WrapUnique(list_menu_delegate));
2260 2597
2261 views::CustomButton* button = browser_button_; 2598 views::CustomButton* button = browser_button_;
2262 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2599 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2263 2600
2264 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2601 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2265 press_location, ui::EventTimeForNow(), 2602 mouse_location, ui::EventTimeForNow(),
2266 ui::EF_LEFT_MOUSE_BUTTON, 0); 2603 ui::EF_LEFT_MOUSE_BUTTON, 0);
2267 button->OnMousePressed(press_event); 2604 button->OnMousePressed(press_event);
2268 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2605 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2269 ink_drop_->GetTargetInkDropState()); 2606 browser_button_ink_drop_->GetTargetInkDropState());
2270 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2607 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2271 ElementsAre(views::InkDropState::ACTION_PENDING)); 2608 ElementsAre(views::InkDropState::ACTION_PENDING));
2272 2609
2273 base::ThreadTaskRunnerHandle::Get()->PostTask( 2610 base::ThreadTaskRunnerHandle::Get()->PostTask(
2274 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu, 2611 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu,
2275 base::Unretained(test_api_.get()))); 2612 base::Unretained(test_api_.get())));
2276 2613
2277 // Mouse release will spawn a menu which will then get closed by the above 2614 // Mouse release will spawn a menu which will then get closed by the above
2278 // posted task. 2615 // posted task.
2279 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2616 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2280 press_location, ui::EventTimeForNow(), 2617 mouse_location, ui::EventTimeForNow(),
2281 ui::EF_LEFT_MOUSE_BUTTON, 0); 2618 ui::EF_LEFT_MOUSE_BUTTON, 0);
2282 button->OnMouseReleased(release_event); 2619 button->OnMouseReleased(release_event);
2283 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2620 EXPECT_EQ(views::InkDropState::HIDDEN,
2284 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2621 browser_button_ink_drop_->GetTargetInkDropState());
2622 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2285 ElementsAre(views::InkDropState::ACTIVATED, 2623 ElementsAre(views::InkDropState::ACTIVATED,
2286 views::InkDropState::DEACTIVATED)); 2624 views::InkDropState::DEACTIVATED));
2287 } 2625 }
2288 2626
2289 } // namespace test 2627 } // namespace test
2290 } // namespace ash 2628 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shell.h » ('j') | ui/views/animation/ink_drop_host_view.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698