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

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: Updated tests Created 4 years, 6 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.
2110 class TestAppListPresenter : public app_list::AppListPresenter {
2111 public:
2112 TestAppListPresenter() : is_visible_(false), target_visibility_(false) {}
2113 ~TestAppListPresenter() override {}
2114
2115 void FinishVisibilityChange() { is_visible_ = target_visibility_; }
2116
2117 // app_list::AppListPresenter:
2118 void Show(int64_t display_id) override {
2119 if (target_visibility_)
bruthig 2016/06/22 19:07:29 nit: This quick return isn't adding too much value
mohsen 2016/06/23 15:49:55 Removed.
2120 return;
2121 target_visibility_ = true;
2122 }
2123 void Dismiss() override {
2124 if (!target_visibility_)
2125 return;
2126 target_visibility_ = false;
2127 }
2128 void ToggleAppList(int64_t display_id) override {
bruthig 2016/06/22 19:07:29 Interesting, I find it weird that the AppListPrese
mohsen 2016/06/23 15:49:55 Yes, that's actually how AppListPresenterImpl prev
2129 if (is_visible_)
2130 Dismiss();
2131 else
2132 Show(display_id);
2133 }
2134 bool IsVisible() const override { return is_visible_; }
2135 bool GetTargetVisibility() const override { return target_visibility_; }
2136
2137 private:
2138 bool is_visible_;
2139 bool target_visibility_;
2140
2141 DISALLOW_COPY_AND_ASSIGN(TestAppListPresenter);
2142 };
2143
2144 // A test ShellDelegate implementation that returns a TestAppListPresenter as
2145 // the app list presenter.
2146 class TestAppListShellDelegate : public TestShellDelegate {
2147 public:
2148 TestAppListShellDelegate()
2149 : app_list_presenter_(new TestAppListPresenter()) {}
2150 ~TestAppListShellDelegate() override {}
2151
2152 TestAppListPresenter* app_list_presenter() const {
2153 return app_list_presenter_.get();
2154 }
2155
2156 // TestShellDelegate:
2157 app_list::AppListPresenter* GetAppListPresenter() override {
2158 return app_list_presenter();
2159 }
2160
2161 private:
2162 std::unique_ptr<TestAppListPresenter> app_list_presenter_;
2163
2164 DISALLOW_COPY_AND_ASSIGN(TestAppListShellDelegate);
2165 };
2166
2105 } // namespace 2167 } // namespace
2106 2168
2107 class ShelfViewInkDropTest : public ShelfViewTest { 2169 class ShelfViewInkDropTest : public ShelfViewTest {
2108 public: 2170 public:
2109 ShelfViewInkDropTest() : ink_drop_(nullptr), browser_button_(nullptr) {} 2171 ShelfViewInkDropTest()
2172 : app_list_button_(nullptr),
2173 app_list_button_ink_drop_(nullptr),
2174 browser_button_(nullptr),
2175 browser_button_ink_drop_(nullptr) {}
2110 ~ShelfViewInkDropTest() override {} 2176 ~ShelfViewInkDropTest() override {}
2111 2177
2112 void SetUp() override { 2178 void SetUp() override {
2179 shell_delegate_ = new TestAppListShellDelegate;
2180 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
2181
2113 ShelfViewTest::SetUp(); 2182 ShelfViewTest::SetUp();
2114 2183
2115 // TODO(mohsen): Ideally, we would want to set material mode before calling 2184 // TODO(mohsen): Ideally, we would want to set material mode before calling
2116 // ShelfViewTest::SetUp() so that everything is set up with the correct 2185 // ShelfViewTest::SetUp() so that everything is set up with the correct
2117 // material mode. Currently, this is not possible as it expects material 2186 // material mode. Currently, this is not possible as it expects material
2118 // mode be UNINITIALIZED. (See https://crbug.com/620093) 2187 // mode be UNINITIALIZED. (See https://crbug.com/620093)
2119 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI( 2188 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI(
2120 ash::MaterialDesignController::MATERIAL_NORMAL)); 2189 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 } 2190 }
2129 2191
2130 void TearDown() override { 2192 void TearDown() override {
2131 ash_md_controller_.reset(); 2193 ash_md_controller_.reset();
2132 2194
2133 ShelfViewTest::TearDown(); 2195 ShelfViewTest::TearDown();
2134 } 2196 }
2135 2197
2136 protected: 2198 protected:
2199 void InitAppListButtonInkDrop() {
2200 app_list_button_ = shelf_view_->GetAppListButton();
2201
2202 views::InkDropImpl* ink_drop_impl =
2203 new views::InkDropImpl(app_list_button_);
2204 app_list_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2205 views::test::InkDropHostViewTestApi(app_list_button_)
2206 .SetInkDrop(base::WrapUnique(app_list_button_ink_drop_));
2207 }
2208
2209 void InitBrowserButtonInkDrop() {
2210 browser_button_ = test_api_->GetButton(browser_index_);
2211
2212 views::InkDropImpl* ink_drop_impl = new views::InkDropImpl(browser_button_);
2213 browser_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2214 views::test::InkDropHostViewTestApi(browser_button_)
2215 .SetInkDrop(base::WrapUnique(browser_button_ink_drop_));
2216 }
2217
2218 void ShowAppList() {
2219 shell_delegate_->app_list_presenter()->Show(0);
2220 // Similar to real AppListPresenter, notify button that the app list is
2221 // shown.
2222 app_list_button_->OnAppListShown();
2223 }
2224
2225 void DismissAppList() {
2226 shell_delegate_->app_list_presenter()->Dismiss();
2227 // Similar to real AppListPresenter, notify button that the app list is
2228 // dismissed.
2229 app_list_button_->OnAppListDismissed();
2230 }
2231
2232 void FinishAppListVisibilityChange() {
2233 shell_delegate_->app_list_presenter()->FinishVisibilityChange();
2234 }
2235
2137 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI> 2236 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI>
2138 ash_md_controller_; 2237 ash_md_controller_;
2139 2238
2140 InkDropSpy* ink_drop_; 2239 TestAppListShellDelegate* shell_delegate_; // Owned by Shell.
2240
2241 AppListButton* app_list_button_;
2242 InkDropSpy* app_list_button_ink_drop_;
2141 ShelfButton* browser_button_; 2243 ShelfButton* browser_button_;
2244 InkDropSpy* browser_button_ink_drop_;
2142 2245
2143 private: 2246 private:
2144 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest); 2247 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest);
2145 }; 2248 };
2146 2249
2250 // Tests that changing visibility of the app list transitions app list button's
2251 // ink drop states correctly.
2252 TEST_F(ShelfViewInkDropTest, AppListButtonWhenVisibilityChanges) {
2253 InitAppListButtonInkDrop();
2254
2255 ShowAppList();
2256 FinishAppListVisibilityChange();
2257 EXPECT_EQ(views::InkDropState::ACTIVATED,
2258 app_list_button_ink_drop_->GetTargetInkDropState());
2259 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2260 ElementsAre(views::InkDropState::ACTIVATED));
2261
2262 DismissAppList();
2263 FinishAppListVisibilityChange();
2264 EXPECT_EQ(views::InkDropState::HIDDEN,
2265 app_list_button_ink_drop_->GetTargetInkDropState());
2266 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2267 ElementsAre(views::InkDropState::DEACTIVATED));
2268 }
2269
2270 // Tests that when the app list is hidden, mouse press on the app list button,
2271 // which shows the app list, transitions ink drop states correctly. Also, tests
2272 // that mouse drag and mouse release does not affect the ink drop state.
2273 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenHidden) {
2274 InitAppListButtonInkDrop();
2275
2276 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2277 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2278
2279 // Mouse press on the button, which shows the app list, should end up in the
2280 // activated state.
2281 generator.PressLeftButton();
2282 // Similar to real AppListPresenter, notify button that the app list is shown.
2283 app_list_button_->OnAppListShown();
2284 FinishAppListVisibilityChange();
2285 EXPECT_EQ(views::InkDropState::ACTIVATED,
2286 app_list_button_ink_drop_->GetTargetInkDropState());
2287 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2288 ElementsAre(views::InkDropState::ACTION_PENDING,
2289 views::InkDropState::ACTIVATED));
2290
2291 // Dragging mouse out and back and releasing the button should not change the
2292 // ink drop state.
2293 generator.MoveMouseBy(app_list_button_->width(), 0);
2294 generator.MoveMouseBy(-app_list_button_->width(), 0);
2295 generator.ReleaseLeftButton();
2296 EXPECT_EQ(views::InkDropState::ACTIVATED,
2297 app_list_button_ink_drop_->GetTargetInkDropState());
2298 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2299 IsEmpty());
2300 }
2301
2302 // Tests that when the app list is visible, mouse press on the app list button,
2303 // which dismisses the app list, transitions ink drop states correctly. Also,
2304 // tests that mouse drag and mouse release does not affect the ink drop state.
2305 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenVisible) {
2306 InitAppListButtonInkDrop();
2307
2308 // Show the app list.
2309 ShowAppList();
2310 FinishAppListVisibilityChange();
2311 EXPECT_EQ(views::InkDropState::ACTIVATED,
2312 app_list_button_ink_drop_->GetTargetInkDropState());
2313 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2314 ElementsAre(views::InkDropState::ACTIVATED));
2315
2316 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2317 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2318
2319 // Mouse press on the button, which dismisses the app list, should end up in
2320 // the hidden state.
2321 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2322 DismissAppList();
2323 generator.PressLeftButton();
2324 FinishAppListVisibilityChange();
2325 EXPECT_EQ(views::InkDropState::HIDDEN,
2326 app_list_button_ink_drop_->GetTargetInkDropState());
2327 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2328 ElementsAre(views::InkDropState::DEACTIVATED));
2329
2330 // Dragging mouse out and back and releasing the button should not change the
2331 // ink drop state.
2332 generator.MoveMouseBy(app_list_button_->width(), 0);
2333 generator.MoveMouseBy(-app_list_button_->width(), 0);
2334 generator.ReleaseLeftButton();
2335 EXPECT_EQ(views::InkDropState::HIDDEN,
2336 app_list_button_ink_drop_->GetTargetInkDropState());
2337 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2338 IsEmpty());
2339 }
2340
2341 // Tests that when the app list is hidden, tapping on the app list button
2342 // transitions ink drop states correctly.
2343 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenHidden) {
2344 InitAppListButtonInkDrop();
2345
2346 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2347 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2348
2349 // Touch press on the button should end up in the pending state.
2350 generator.PressTouch();
2351 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2352 app_list_button_ink_drop_->GetTargetInkDropState());
2353 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2354 ElementsAre(views::InkDropState::ACTION_PENDING));
2355
2356 // Touch release on the button, which shows the app list, should end up in the
2357 // activated state.
2358 generator.ReleaseTouch();
2359 // Similar to real AppListPresenter, notify button that the app list is shown.
2360 app_list_button_->OnAppListShown();
2361 FinishAppListVisibilityChange();
2362 EXPECT_EQ(views::InkDropState::ACTIVATED,
2363 app_list_button_ink_drop_->GetTargetInkDropState());
2364 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2365 ElementsAre(views::InkDropState::ACTIVATED));
2366 }
2367
2368 // Tests that when the app list is visible, tapping on the app list button
2369 // transitions ink drop states correctly.
2370 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenVisible) {
2371 InitAppListButtonInkDrop();
2372
2373 // Show the app list.
2374 ShowAppList();
2375 FinishAppListVisibilityChange();
2376 EXPECT_EQ(views::InkDropState::ACTIVATED,
2377 app_list_button_ink_drop_->GetTargetInkDropState());
2378 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2379 ElementsAre(views::InkDropState::ACTIVATED));
2380
2381 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2382 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2383
2384 // Touch press on the button, which dismisses the app list, should end up in
2385 // the hidden state.
2386 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2387 DismissAppList();
2388 generator.PressTouch();
2389 EXPECT_EQ(views::InkDropState::HIDDEN,
2390 app_list_button_ink_drop_->GetTargetInkDropState());
2391 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2392 ElementsAre(views::InkDropState::DEACTIVATED));
2393
2394 // Touch release on the button should not change the ink drop state.
2395 generator.ReleaseTouch();
2396 FinishAppListVisibilityChange();
2397 EXPECT_EQ(views::InkDropState::HIDDEN,
2398 app_list_button_ink_drop_->GetTargetInkDropState());
2399 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2400 IsEmpty());
2401 }
2402
2403 // Tests that when the app list is hidden, tapping down on the app list button
2404 // and dragging the touch point transitions ink drop states correctly.
2405 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenHidden) {
2406 InitAppListButtonInkDrop();
2407
2408 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2409 gfx::Point touch_location =
2410 app_list_button_->GetBoundsInScreen().CenterPoint();
2411 generator.MoveMouseTo(touch_location);
2412
2413 // Touch press on the button should end up in the pending state.
2414 generator.PressTouch();
2415 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2416 app_list_button_ink_drop_->GetTargetInkDropState());
2417 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2418 ElementsAre(views::InkDropState::ACTION_PENDING));
2419
2420 // Dragging the touch point should hide the pending ink drop.
2421 touch_location.Offset(app_list_button_->width(), 0);
2422 generator.MoveTouch(touch_location);
2423 EXPECT_EQ(views::InkDropState::HIDDEN,
2424 app_list_button_ink_drop_->GetTargetInkDropState());
2425 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2426 ElementsAre(views::InkDropState::HIDDEN));
2427
2428 // Touch release should not change the ink drop state.
2429 generator.ReleaseTouch();
2430 EXPECT_EQ(views::InkDropState::HIDDEN,
2431 app_list_button_ink_drop_->GetTargetInkDropState());
2432 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2433 IsEmpty());
2434 }
2435
2436 // Tests that when the app list is visible, tapping down on the app list button
2437 // and dragging the touch point transitions ink drop states correctly.
2438 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenVisible) {
2439 InitAppListButtonInkDrop();
2440
2441 // Show the app list.
2442 ShowAppList();
2443 FinishAppListVisibilityChange();
2444 EXPECT_EQ(views::InkDropState::ACTIVATED,
2445 app_list_button_ink_drop_->GetTargetInkDropState());
2446 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2447 ElementsAre(views::InkDropState::ACTIVATED));
2448
2449 ui::test::EventGenerator generator(shelf_view_->GetWidget()->GetNativeView());
2450 gfx::Point touch_location =
2451 app_list_button_->GetBoundsInScreen().CenterPoint();
2452 generator.MoveMouseTo(touch_location);
2453
2454 // Touch press on the button, which dismisses the app list, should end up in
2455 // the hidden state.
2456 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2457 DismissAppList();
2458 generator.PressTouch();
2459 EXPECT_EQ(views::InkDropState::HIDDEN,
2460 app_list_button_ink_drop_->GetTargetInkDropState());
2461 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2462 ElementsAre(views::InkDropState::DEACTIVATED));
2463
2464 // Dragging the touch point and releasing should not change the ink drop
2465 // state.
2466 touch_location.Offset(app_list_button_->width(), 0);
2467 generator.MoveTouch(touch_location);
2468 generator.ReleaseTouch();
2469 FinishAppListVisibilityChange();
2470 EXPECT_EQ(views::InkDropState::HIDDEN,
2471 app_list_button_ink_drop_->GetTargetInkDropState());
2472 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2473 ElementsAre(views::InkDropState::HIDDEN));
2474 }
2475
2147 // Tests that clicking on a shelf item that does not show a menu transitions ink 2476 // Tests that clicking on a shelf item that does not show a menu transitions ink
2148 // drop states correctly. 2477 // drop states correctly.
2149 TEST_F(ShelfViewInkDropTest, WithoutMenuPressRelease) { 2478 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressRelease) {
2479 InitBrowserButtonInkDrop();
2480
2150 views::CustomButton* button = browser_button_; 2481 views::CustomButton* button = browser_button_;
2151 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2482 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2152 2483
2153 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2484 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2154 press_location, ui::EventTimeForNow(), 2485 mouse_location, ui::EventTimeForNow(),
2155 ui::EF_LEFT_MOUSE_BUTTON, 0); 2486 ui::EF_LEFT_MOUSE_BUTTON, 0);
2156 button->OnMousePressed(press_event); 2487 button->OnMousePressed(press_event);
2157 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2488 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2158 ink_drop_->GetTargetInkDropState()); 2489 browser_button_ink_drop_->GetTargetInkDropState());
2159 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2490 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2160 ElementsAre(views::InkDropState::ACTION_PENDING)); 2491 ElementsAre(views::InkDropState::ACTION_PENDING));
2161 2492
2162 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2493 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2163 press_location, ui::EventTimeForNow(), 2494 mouse_location, ui::EventTimeForNow(),
2164 ui::EF_LEFT_MOUSE_BUTTON, 0); 2495 ui::EF_LEFT_MOUSE_BUTTON, 0);
2165 button->OnMouseReleased(release_event); 2496 button->OnMouseReleased(release_event);
2166 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2497 EXPECT_EQ(views::InkDropState::HIDDEN,
2167 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2498 browser_button_ink_drop_->GetTargetInkDropState());
2499 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2168 ElementsAre(views::InkDropState::ACTION_TRIGGERED)); 2500 ElementsAre(views::InkDropState::ACTION_TRIGGERED));
2169 } 2501 }
2170 2502
2171 // Tests that dragging outside of a shelf item transitions ink drop states 2503 // Tests that dragging outside of a shelf item transitions ink drop states
2172 // correctly. 2504 // correctly.
2173 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseOutside) { 2505 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseOutside) {
2506 InitBrowserButtonInkDrop();
2507
2174 views::CustomButton* button = browser_button_; 2508 views::CustomButton* button = browser_button_;
2175 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2509 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2176 2510
2177 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2511 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2178 press_location, ui::EventTimeForNow(), 2512 mouse_location, ui::EventTimeForNow(),
2179 ui::EF_LEFT_MOUSE_BUTTON, 0); 2513 ui::EF_LEFT_MOUSE_BUTTON, 0);
2180 button->OnMousePressed(press_event); 2514 button->OnMousePressed(press_event);
2181 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2515 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2182 ink_drop_->GetTargetInkDropState()); 2516 browser_button_ink_drop_->GetTargetInkDropState());
2183 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2517 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2184 ElementsAre(views::InkDropState::ACTION_PENDING)); 2518 ElementsAre(views::InkDropState::ACTION_PENDING));
2185 2519
2186 press_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0); 2520 mouse_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0);
2187 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, press_location, 2521 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, mouse_location,
2188 press_location, ui::EventTimeForNow(), 2522 mouse_location, ui::EventTimeForNow(),
2189 ui::EF_LEFT_MOUSE_BUTTON, 0); 2523 ui::EF_LEFT_MOUSE_BUTTON, 0);
2190 button->OnMouseDragged(drag_event_small); 2524 button->OnMouseDragged(drag_event_small);
2191 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2525 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2192 ink_drop_->GetTargetInkDropState()); 2526 browser_button_ink_drop_->GetTargetInkDropState());
2193 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2527 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2194 2528 IsEmpty());
2195 press_location.Offset(test_api_->GetMinimumDragDistance(), 0); 2529
2196 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, press_location, 2530 mouse_location.Offset(test_api_->GetMinimumDragDistance(), 0);
2197 press_location, ui::EventTimeForNow(), 2531 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, mouse_location,
2532 mouse_location, ui::EventTimeForNow(),
2198 ui::EF_LEFT_MOUSE_BUTTON, 0); 2533 ui::EF_LEFT_MOUSE_BUTTON, 0);
2199 button->OnMouseDragged(drag_event_large); 2534 button->OnMouseDragged(drag_event_large);
2200 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2535 EXPECT_EQ(views::InkDropState::HIDDEN,
2201 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2536 browser_button_ink_drop_->GetTargetInkDropState());
2537 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2202 ElementsAre(views::InkDropState::HIDDEN)); 2538 ElementsAre(views::InkDropState::HIDDEN));
2203 2539
2204 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2540 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2205 press_location, ui::EventTimeForNow(), 2541 mouse_location, ui::EventTimeForNow(),
2206 ui::EF_LEFT_MOUSE_BUTTON, 0); 2542 ui::EF_LEFT_MOUSE_BUTTON, 0);
2207 button->OnMouseReleased(release_event); 2543 button->OnMouseReleased(release_event);
2208 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2544 EXPECT_EQ(views::InkDropState::HIDDEN,
2209 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2545 browser_button_ink_drop_->GetTargetInkDropState());
2546 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2547 IsEmpty());
2210 } 2548 }
2211 2549
2212 // Tests that dragging outside of a shelf item and back transitions ink drop 2550 // Tests that dragging outside of a shelf item and back transitions ink drop
2213 // states correctly. 2551 // states correctly.
2214 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseInside) { 2552 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseInside) {
2553 InitBrowserButtonInkDrop();
2554
2215 views::CustomButton* button = browser_button_; 2555 views::CustomButton* button = browser_button_;
2216 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2556 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2217 2557
2218 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2558 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2219 press_location, ui::EventTimeForNow(), 2559 mouse_location, ui::EventTimeForNow(),
2220 ui::EF_LEFT_MOUSE_BUTTON, 0); 2560 ui::EF_LEFT_MOUSE_BUTTON, 0);
2221 button->OnMousePressed(press_event); 2561 button->OnMousePressed(press_event);
2222 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2562 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2223 ink_drop_->GetTargetInkDropState()); 2563 browser_button_ink_drop_->GetTargetInkDropState());
2224 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2564 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2225 ElementsAre(views::InkDropState::ACTION_PENDING)); 2565 ElementsAre(views::InkDropState::ACTION_PENDING));
2226 2566
2227 press_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0); 2567 mouse_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0);
2228 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, press_location, 2568 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, mouse_location,
2229 press_location, ui::EventTimeForNow(), 2569 mouse_location, ui::EventTimeForNow(),
2230 ui::EF_LEFT_MOUSE_BUTTON, 0); 2570 ui::EF_LEFT_MOUSE_BUTTON, 0);
2231 button->OnMouseDragged(drag_event_outside); 2571 button->OnMouseDragged(drag_event_outside);
2232 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2572 EXPECT_EQ(views::InkDropState::HIDDEN,
2233 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2573 browser_button_ink_drop_->GetTargetInkDropState());
2574 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2234 ElementsAre(views::InkDropState::HIDDEN)); 2575 ElementsAre(views::InkDropState::HIDDEN));
2235 2576
2236 press_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0); 2577 mouse_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0);
2237 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, press_location, 2578 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, mouse_location,
2238 press_location, ui::EventTimeForNow(), 2579 mouse_location, ui::EventTimeForNow(),
2239 ui::EF_LEFT_MOUSE_BUTTON, 0); 2580 ui::EF_LEFT_MOUSE_BUTTON, 0);
2240 button->OnMouseDragged(drag_event_inside); 2581 button->OnMouseDragged(drag_event_inside);
2241 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2582 EXPECT_EQ(views::InkDropState::HIDDEN,
2242 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2583 browser_button_ink_drop_->GetTargetInkDropState());
2243 2584 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2244 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2585 IsEmpty());
2245 press_location, ui::EventTimeForNow(), 2586
2587 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2588 mouse_location, ui::EventTimeForNow(),
2246 ui::EF_LEFT_MOUSE_BUTTON, 0); 2589 ui::EF_LEFT_MOUSE_BUTTON, 0);
2247 button->OnMouseReleased(release_event); 2590 button->OnMouseReleased(release_event);
2248 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2591 EXPECT_EQ(views::InkDropState::HIDDEN,
2249 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2592 browser_button_ink_drop_->GetTargetInkDropState());
2593 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2594 IsEmpty());
2250 } 2595 }
2251 2596
2252 // Tests that clicking on a shelf item that shows an app list menu transitions 2597 // Tests that clicking on a shelf item that shows an app list menu transitions
2253 // ink drop state correctly. 2598 // ink drop state correctly.
2254 TEST_F(ShelfViewInkDropTest, WithMenuPressRelease) { 2599 TEST_F(ShelfViewInkDropTest, ShelfButtonWithMenuPressRelease) {
2600 InitBrowserButtonInkDrop();
2601
2255 // Set a delegate for the shelf item that returns an app list menu. 2602 // Set a delegate for the shelf item that returns an app list menu.
2256 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 2603 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
2257 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate; 2604 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate;
2258 item_manager_->SetShelfItemDelegate(browser_shelf_id, 2605 item_manager_->SetShelfItemDelegate(browser_shelf_id,
2259 base::WrapUnique(list_menu_delegate)); 2606 base::WrapUnique(list_menu_delegate));
2260 2607
2261 views::CustomButton* button = browser_button_; 2608 views::CustomButton* button = browser_button_;
2262 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2609 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2263 2610
2264 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2611 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2265 press_location, ui::EventTimeForNow(), 2612 mouse_location, ui::EventTimeForNow(),
2266 ui::EF_LEFT_MOUSE_BUTTON, 0); 2613 ui::EF_LEFT_MOUSE_BUTTON, 0);
2267 button->OnMousePressed(press_event); 2614 button->OnMousePressed(press_event);
2268 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2615 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2269 ink_drop_->GetTargetInkDropState()); 2616 browser_button_ink_drop_->GetTargetInkDropState());
2270 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2617 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2271 ElementsAre(views::InkDropState::ACTION_PENDING)); 2618 ElementsAre(views::InkDropState::ACTION_PENDING));
2272 2619
2273 base::ThreadTaskRunnerHandle::Get()->PostTask( 2620 base::ThreadTaskRunnerHandle::Get()->PostTask(
2274 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu, 2621 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu,
2275 base::Unretained(test_api_.get()))); 2622 base::Unretained(test_api_.get())));
2276 2623
2277 // Mouse release will spawn a menu which will then get closed by the above 2624 // Mouse release will spawn a menu which will then get closed by the above
2278 // posted task. 2625 // posted task.
2279 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2626 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2280 press_location, ui::EventTimeForNow(), 2627 mouse_location, ui::EventTimeForNow(),
2281 ui::EF_LEFT_MOUSE_BUTTON, 0); 2628 ui::EF_LEFT_MOUSE_BUTTON, 0);
2282 button->OnMouseReleased(release_event); 2629 button->OnMouseReleased(release_event);
2283 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2630 EXPECT_EQ(views::InkDropState::HIDDEN,
2284 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2631 browser_button_ink_drop_->GetTargetInkDropState());
2632 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2285 ElementsAre(views::InkDropState::ACTIVATED, 2633 ElementsAre(views::InkDropState::ACTIVATED,
2286 views::InkDropState::DEACTIVATED)); 2634 views::InkDropState::DEACTIVATED));
2287 } 2635 }
2288 2636
2289 } // namespace test 2637 } // namespace test
2290 } // namespace ash 2638 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698