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

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: Rebased 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
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 ShelfButton* button = test_api_->GetButton(i); 1450 ShelfButton* button = test_api_->GetButton(i);
1448 if (!button) 1451 if (!button)
1449 continue; 1452 continue;
1450 1453
1451 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1454 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1452 button->GetMirroredBounds().CenterPoint())) 1455 button->GetMirroredBounds().CenterPoint()))
1453 << "ShelfView tries to hide on button " << i; 1456 << "ShelfView tries to hide on button " << i;
1454 } 1457 }
1455 1458
1456 // The tooltip should not hide on the app-list button. 1459 // The tooltip should not hide on the app-list button.
1457 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1460 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1458 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1461 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1459 app_list_button->GetMirroredBounds().CenterPoint())); 1462 app_list_button->GetMirroredBounds().CenterPoint()));
1460 1463
1461 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. 1464 // The tooltip shouldn't hide if the mouse is in the gap between two buttons.
1462 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); 1465 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds();
1463 gfx::Rect platform_button_rect = 1466 gfx::Rect platform_button_rect =
1464 GetButtonByID(platform_button_id)->GetMirroredBounds(); 1467 GetButtonByID(platform_button_id)->GetMirroredBounds();
1465 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect)); 1468 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect));
1466 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1469 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1467 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint())); 1470 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint()));
1468 1471
1469 // The tooltip should hide if it's outside of all buttons. 1472 // The tooltip should hide if it's outside of all buttons.
1470 gfx::Rect all_area; 1473 gfx::Rect all_area;
1471 for (int i = 0; i < test_api_->GetButtonCount(); i++) { 1474 for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1472 ShelfButton* button = test_api_->GetButton(i); 1475 ShelfButton* button = test_api_->GetButton(i);
1473 if (!button) 1476 if (!button)
1474 continue; 1477 continue;
1475 1478
1476 all_area.Union(button->GetMirroredBounds()); 1479 all_area.Union(button->GetMirroredBounds());
1477 } 1480 }
1478 all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds()); 1481 all_area.Union(shelf_view_->GetAppListButton()->GetMirroredBounds());
1479 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin())); 1482 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin()));
1480 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1483 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1481 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); 1484 gfx::Point(all_area.right() - 1, all_area.bottom() - 1)));
1482 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1485 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1483 gfx::Point(all_area.right(), all_area.y()))); 1486 gfx::Point(all_area.right(), all_area.y())));
1484 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1487 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1485 gfx::Point(all_area.x() - 1, all_area.y()))); 1488 gfx::Point(all_area.x() - 1, all_area.y())));
1486 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1489 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1487 gfx::Point(all_area.x(), all_area.y() - 1))); 1490 gfx::Point(all_area.x(), all_area.y() - 1)));
1488 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1491 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1489 gfx::Point(all_area.x(), all_area.bottom()))); 1492 gfx::Point(all_area.x(), all_area.bottom())));
1490 } 1493 }
1491 1494
1492 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) { 1495 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
1493 Shell::GetInstance()->ShowAppList(NULL); 1496 Shell::GetInstance()->ShowAppList(NULL);
1494 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1497 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1495 1498
1496 // The tooltip shouldn't hide if the mouse is on normal buttons. 1499 // The tooltip shouldn't hide if the mouse is on normal buttons.
1497 for (int i = 1; i < test_api_->GetButtonCount(); i++) { 1500 for (int i = 1; i < test_api_->GetButtonCount(); i++) {
1498 ShelfButton* button = test_api_->GetButton(i); 1501 ShelfButton* button = test_api_->GetButton(i);
1499 if (!button) 1502 if (!button)
1500 continue; 1503 continue;
1501 1504
1502 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1505 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1503 button->GetMirroredBounds().CenterPoint())) 1506 button->GetMirroredBounds().CenterPoint()))
1504 << "ShelfView tries to hide on button " << i; 1507 << "ShelfView tries to hide on button " << i;
1505 } 1508 }
1506 1509
1507 // The tooltip should hide on the app-list button. 1510 // The tooltip should hide on the app-list button.
1508 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1511 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1509 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1512 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1510 app_list_button->GetMirroredBounds().CenterPoint())); 1513 app_list_button->GetMirroredBounds().CenterPoint()));
1511 } 1514 }
1512 1515
1513 // Test that by moving the mouse cursor off the button onto the bubble it closes 1516 // Test that by moving the mouse cursor off the button onto the bubble it closes
1514 // the bubble. 1517 // the bubble.
1515 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { 1518 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
1516 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager(); 1519 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1517 tooltip_manager->set_timer_delay_for_test(0); 1520 tooltip_manager->set_timer_delay_for_test(0);
1518 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1521 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1519 1522
1520 // Move the mouse off any item and check that no tooltip is shown. 1523 // Move the mouse off any item and check that no tooltip is shown.
1521 generator.MoveMouseTo(gfx::Point(0, 0)); 1524 generator.MoveMouseTo(gfx::Point(0, 0));
1522 EXPECT_FALSE(tooltip_manager->IsVisible()); 1525 EXPECT_FALSE(tooltip_manager->IsVisible());
1523 1526
1524 // Move the mouse over the button and check that it is visible. 1527 // Move the mouse over the button and check that it is visible.
1525 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1528 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1526 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1529 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1527 generator.MoveMouseTo(bounds.CenterPoint()); 1530 generator.MoveMouseTo(bounds.CenterPoint());
1528 // Wait for the timer to go off. 1531 // Wait for the timer to go off.
1529 RunAllPendingInMessageLoop(); 1532 RunAllPendingInMessageLoop();
1530 EXPECT_TRUE(tooltip_manager->IsVisible()); 1533 EXPECT_TRUE(tooltip_manager->IsVisible());
1531 1534
1532 // Move the mouse cursor slightly to the right of the item. The tooltip should 1535 // Move the mouse cursor slightly to the right of the item. The tooltip should
1533 // stay open. 1536 // stay open.
1534 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); 1537 generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
1535 // Make sure there is no delayed close. 1538 // Make sure there is no delayed close.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 1827
1825 // Make the added running platform app to be an app shortcut. 1828 // Make the added running platform app to be an app shortcut.
1826 // This app shortcut should be a swapped view in overflow bubble, which is 1829 // This app shortcut should be a swapped view in overflow bubble, which is
1827 // invisible. 1830 // invisible.
1828 SetShelfItemTypeToAppShortcut(platform_app_id); 1831 SetShelfItemTypeToAppShortcut(platform_app_id);
1829 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); 1832 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible());
1830 } 1833 }
1831 1834
1832 // Tests that the AppListButton renders as active in response to touches. 1835 // Tests that the AppListButton renders as active in response to touches.
1833 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) { 1836 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) {
1834 AppListButton* app_list_button = 1837 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1835 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1836 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1838 EXPECT_FALSE(app_list_button->draw_background_as_active());
1837 1839
1838 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1840 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1839 generator.set_current_location( 1841 generator.set_current_location(
1840 app_list_button->GetBoundsInScreen().CenterPoint()); 1842 app_list_button->GetBoundsInScreen().CenterPoint());
1841 generator.PressTouch(); 1843 generator.PressTouch();
1842 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1844 EXPECT_TRUE(app_list_button->draw_background_as_active());
1843 1845
1844 generator.ReleaseTouch(); 1846 generator.ReleaseTouch();
1845 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1847 EXPECT_FALSE(app_list_button->draw_background_as_active());
1846 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1848 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1847 } 1849 }
1848 1850
1849 // Tests that a touch that slides out of the bounds of the AppListButton leads 1851 // Tests that a touch that slides out of the bounds of the AppListButton leads
1850 // to the end of rendering an active state. 1852 // to the end of rendering an active state.
1851 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) { 1853 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) {
1852 AppListButton* app_list_button = 1854 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1853 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1854 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1855 EXPECT_FALSE(app_list_button->draw_background_as_active());
1855 1856
1856 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1857 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1857 generator.set_current_location( 1858 generator.set_current_location(
1858 app_list_button->GetBoundsInScreen().CenterPoint()); 1859 app_list_button->GetBoundsInScreen().CenterPoint());
1859 generator.PressTouch(); 1860 generator.PressTouch();
1860 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1861 EXPECT_TRUE(app_list_button->draw_background_as_active());
1861 1862
1862 gfx::Point moved_point( 1863 gfx::Point moved_point(
1863 app_list_button->GetBoundsInScreen().right() + 1, 1864 app_list_button->GetBoundsInScreen().right() + 1,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); 1944 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1944 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1945 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
1945 if (ShelfButton* button = test_api_->GetButton(i)) 1946 if (ShelfButton* button = test_api_->GetButton(i))
1946 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); 1947 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
1947 CheckAppListButtonIsInBounds(); 1948 CheckAppListButtonIsInBounds();
1948 } 1949 }
1949 1950
1950 void CheckAppListButtonIsInBounds() { 1951 void CheckAppListButtonIsInBounds() {
1951 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1952 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1952 gfx::Rect app_list_button_bounds = 1953 gfx::Rect app_list_button_bounds =
1953 shelf_view_->GetAppListButtonView()->GetBoundsInScreen(); 1954 shelf_view_->GetAppListButton()->GetBoundsInScreen();
1954 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds)); 1955 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds));
1955 } 1956 }
1956 1957
1957 private: 1958 private:
1958 ScopedTextDirectionChange text_direction_change_; 1959 ScopedTextDirectionChange text_direction_change_;
1959 1960
1960 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest); 1961 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest);
1961 }; 1962 };
1962 1963
1963 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) { 1964 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 2068
2068 private: 2069 private:
2069 // TestShelfItemDelegate: 2070 // TestShelfItemDelegate:
2070 ShelfMenuModel* CreateApplicationMenu(int event_flags) override { 2071 ShelfMenuModel* CreateApplicationMenu(int event_flags) override {
2071 return new TestShelfMenuModel; 2072 return new TestShelfMenuModel;
2072 } 2073 }
2073 2074
2074 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); 2075 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate);
2075 }; 2076 };
2076 2077
2078 // A test implementation for AppListPresenter that does not change visibility
2079 // state immediately to simulate an in-flight animation. Calling
2080 // FinishVisibilityChange() will change the visibility to the requested one,
2081 // simulating end of the animation. Similar to the actual AppListPresenter, this
2082 // class toggles app list visibility based on the actual visibility rather than
2083 // the target visibility (which might be different due to in-flight animation).
2084 class TestAppListPresenter : public app_list::AppListPresenter {
2085 public:
2086 TestAppListPresenter() {}
2087 ~TestAppListPresenter() override {}
2088
2089 void FinishVisibilityChange() { is_visible_ = target_visibility_; }
2090
2091 // app_list::AppListPresenter:
2092 void Show(int64_t display_id) override { target_visibility_ = true; }
2093 void Dismiss() override { target_visibility_ = false; }
2094 void ToggleAppList(int64_t display_id) override {
2095 if (is_visible_)
2096 Dismiss();
2097 else
2098 Show(display_id);
2099 }
2100 bool IsVisible() const override { return is_visible_; }
2101 bool GetTargetVisibility() const override { return target_visibility_; }
2102
2103 private:
2104 bool is_visible_ = false;
2105 bool target_visibility_ = false;
2106
2107 DISALLOW_COPY_AND_ASSIGN(TestAppListPresenter);
2108 };
2109
2110 // A test ShellDelegate implementation that returns a TestAppListPresenter as
2111 // the app list presenter.
2112 class TestAppListShellDelegate : public TestShellDelegate {
2113 public:
2114 TestAppListShellDelegate()
2115 : app_list_presenter_(new TestAppListPresenter()) {}
2116 ~TestAppListShellDelegate() override {}
2117
2118 TestAppListPresenter* app_list_presenter() const {
2119 return app_list_presenter_.get();
2120 }
2121
2122 // TestShellDelegate:
2123 app_list::AppListPresenter* GetAppListPresenter() override {
2124 return app_list_presenter();
2125 }
2126
2127 private:
2128 std::unique_ptr<TestAppListPresenter> app_list_presenter_;
2129
2130 DISALLOW_COPY_AND_ASSIGN(TestAppListShellDelegate);
2131 };
2132
2077 } // namespace 2133 } // namespace
2078 2134
2079 class ShelfViewInkDropTest : public ShelfViewTest { 2135 class ShelfViewInkDropTest : public ShelfViewTest {
2080 public: 2136 public:
2081 ShelfViewInkDropTest() : ink_drop_(nullptr), browser_button_(nullptr) {} 2137 ShelfViewInkDropTest() {}
2082 ~ShelfViewInkDropTest() override {} 2138 ~ShelfViewInkDropTest() override {}
2083 2139
2084 void SetUp() override { 2140 void SetUp() override {
2141 shell_delegate_ = new TestAppListShellDelegate;
2142 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
2143
2085 ShelfViewTest::SetUp(); 2144 ShelfViewTest::SetUp();
2086 2145
2087 // TODO(mohsen): Ideally, we would want to set material mode before calling 2146 // TODO(mohsen): Ideally, we would want to set material mode before calling
2088 // ShelfViewTest::SetUp() so that everything is set up with the correct 2147 // ShelfViewTest::SetUp() so that everything is set up with the correct
2089 // material mode. Currently, this is not possible as it expects material 2148 // material mode. Currently, this is not possible as it expects material
2090 // mode be UNINITIALIZED. (See https://crbug.com/620093) 2149 // mode be UNINITIALIZED. (See https://crbug.com/620093)
2091 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI( 2150 ash_md_controller_.reset(new ash::test::MaterialDesignControllerTestAPI(
2092 ash::MaterialDesignController::MATERIAL_NORMAL)); 2151 ash::MaterialDesignController::MATERIAL_EXPERIMENTAL));
2093
2094 browser_button_ = test_api_->GetButton(browser_index_);
2095
2096 views::InkDropImpl* ink_drop_impl = new views::InkDropImpl(browser_button_);
2097 ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2098 views::test::InkDropHostViewTestApi(browser_button_)
2099 .SetInkDrop(base::WrapUnique(ink_drop_));
2100 } 2152 }
2101 2153
2102 void TearDown() override { 2154 void TearDown() override {
2103 ash_md_controller_.reset(); 2155 ash_md_controller_.reset();
2104 2156
2105 ShelfViewTest::TearDown(); 2157 ShelfViewTest::TearDown();
2106 } 2158 }
2107 2159
2108 protected: 2160 protected:
2161 void InitAppListButtonInkDrop() {
2162 app_list_button_ = shelf_view_->GetAppListButton();
2163
2164 views::InkDropImpl* ink_drop_impl =
2165 new views::InkDropImpl(app_list_button_);
2166 app_list_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2167 views::test::InkDropHostViewTestApi(app_list_button_)
2168 .SetInkDrop(base::WrapUnique(app_list_button_ink_drop_), false);
2169 }
2170
2171 void InitBrowserButtonInkDrop() {
2172 browser_button_ = test_api_->GetButton(browser_index_);
2173
2174 views::InkDropImpl* ink_drop_impl = new views::InkDropImpl(browser_button_);
2175 browser_button_ink_drop_ = new InkDropSpy(base::WrapUnique(ink_drop_impl));
2176 views::test::InkDropHostViewTestApi(browser_button_)
2177 .SetInkDrop(base::WrapUnique(browser_button_ink_drop_));
2178 }
2179
2180 void ShowAppList() {
2181 shell_delegate_->app_list_presenter()->Show(0);
2182 // Similar to real AppListPresenter, notify button that the app list is
2183 // shown.
2184 app_list_button_->OnAppListShown();
2185 }
2186
2187 void DismissAppList() {
2188 shell_delegate_->app_list_presenter()->Dismiss();
2189 // Similar to real AppListPresenter, notify button that the app list is
2190 // dismissed.
2191 app_list_button_->OnAppListDismissed();
2192 }
2193
2194 void FinishAppListVisibilityChange() {
2195 shell_delegate_->app_list_presenter()->FinishVisibilityChange();
2196 }
2197
2109 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI> 2198 std::unique_ptr<ash::test::MaterialDesignControllerTestAPI>
2110 ash_md_controller_; 2199 ash_md_controller_;
2111 2200
2112 InkDropSpy* ink_drop_; 2201 TestAppListShellDelegate* shell_delegate_ = nullptr; // Owned by Shell.
2113 ShelfButton* browser_button_; 2202
2203 AppListButton* app_list_button_ = nullptr;
2204 InkDropSpy* app_list_button_ink_drop_ = nullptr;
2205 ShelfButton* browser_button_ = nullptr;
2206 InkDropSpy* browser_button_ink_drop_ = nullptr;
2114 2207
2115 private: 2208 private:
2116 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest); 2209 DISALLOW_COPY_AND_ASSIGN(ShelfViewInkDropTest);
2117 }; 2210 };
2118 2211
2212 // Tests that changing visibility of the app list transitions app list button's
2213 // ink drop states correctly.
2214 TEST_F(ShelfViewInkDropTest, AppListButtonWhenVisibilityChanges) {
2215 InitAppListButtonInkDrop();
2216
2217 ShowAppList();
2218 FinishAppListVisibilityChange();
2219 EXPECT_EQ(views::InkDropState::ACTIVATED,
2220 app_list_button_ink_drop_->GetTargetInkDropState());
2221 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2222 ElementsAre(views::InkDropState::ACTIVATED));
2223
2224 DismissAppList();
2225 FinishAppListVisibilityChange();
2226 EXPECT_EQ(views::InkDropState::HIDDEN,
2227 app_list_button_ink_drop_->GetTargetInkDropState());
2228 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2229 ElementsAre(views::InkDropState::DEACTIVATED));
2230 }
2231
2232 // Tests that when the app list is hidden, mouse press on the app list button,
2233 // which shows the app list, transitions ink drop states correctly. Also, tests
2234 // that mouse drag and mouse release does not affect the ink drop state.
2235 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenHidden) {
2236 InitAppListButtonInkDrop();
2237
2238 ui::test::EventGenerator& generator = GetEventGenerator();
2239 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2240
2241 // Mouse press on the button, which shows the app list, should end up in the
2242 // activated state.
2243 generator.PressLeftButton();
2244 // Similar to real AppListPresenter, notify button that the app list is shown.
2245 app_list_button_->OnAppListShown();
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::ACTION_PENDING,
2251 views::InkDropState::ACTIVATED));
2252
2253 // Dragging mouse out and back and releasing the button should not change the
2254 // ink drop state.
2255 generator.MoveMouseBy(app_list_button_->width(), 0);
2256 generator.MoveMouseBy(-app_list_button_->width(), 0);
2257 generator.ReleaseLeftButton();
2258 EXPECT_EQ(views::InkDropState::ACTIVATED,
2259 app_list_button_ink_drop_->GetTargetInkDropState());
2260 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2261 IsEmpty());
2262 }
2263
2264 // Tests that when the app list is visible, mouse press on the app list button,
2265 // which dismisses the app list, transitions ink drop states correctly. Also,
2266 // tests that mouse drag and mouse release does not affect the ink drop state.
2267 TEST_F(ShelfViewInkDropTest, AppListButtonMouseEventsWhenVisible) {
2268 InitAppListButtonInkDrop();
2269
2270 // Show the app list.
2271 ShowAppList();
2272 FinishAppListVisibilityChange();
2273 EXPECT_EQ(views::InkDropState::ACTIVATED,
2274 app_list_button_ink_drop_->GetTargetInkDropState());
2275 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2276 ElementsAre(views::InkDropState::ACTIVATED));
2277
2278 ui::test::EventGenerator& generator = GetEventGenerator();
2279 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2280
2281 // Mouse press on the button, which dismisses the app list, should end up in
2282 // the hidden state.
2283 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2284 DismissAppList();
2285 generator.PressLeftButton();
2286 FinishAppListVisibilityChange();
2287 EXPECT_EQ(views::InkDropState::HIDDEN,
2288 app_list_button_ink_drop_->GetTargetInkDropState());
2289 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2290 ElementsAre(views::InkDropState::DEACTIVATED));
2291
2292 // Dragging mouse out and back and releasing the button should not change the
2293 // ink drop state.
2294 generator.MoveMouseBy(app_list_button_->width(), 0);
2295 generator.MoveMouseBy(-app_list_button_->width(), 0);
2296 generator.ReleaseLeftButton();
2297 EXPECT_EQ(views::InkDropState::HIDDEN,
2298 app_list_button_ink_drop_->GetTargetInkDropState());
2299 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2300 IsEmpty());
2301 }
2302
2303 #if !defined(OS_WIN)
2304 // There is no ink drop effect for gesture events on Windows.
2305
2306 // Tests that when the app list is hidden, tapping on the app list button
2307 // transitions ink drop states correctly.
2308 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenHidden) {
2309 InitAppListButtonInkDrop();
2310
2311 ui::test::EventGenerator& generator = GetEventGenerator();
2312 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2313
2314 // Touch press on the button should end up in the pending state.
2315 generator.PressTouch();
2316 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2317 app_list_button_ink_drop_->GetTargetInkDropState());
2318 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2319 ElementsAre(views::InkDropState::ACTION_PENDING));
2320
2321 // Touch release on the button, which shows the app list, should end up in the
2322 // activated state.
2323 generator.ReleaseTouch();
2324 // Similar to real AppListPresenter, notify button that the app list is shown.
2325 app_list_button_->OnAppListShown();
2326 FinishAppListVisibilityChange();
2327 EXPECT_EQ(views::InkDropState::ACTIVATED,
2328 app_list_button_ink_drop_->GetTargetInkDropState());
2329 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2330 ElementsAre(views::InkDropState::ACTIVATED));
2331 }
2332
2333 // Tests that when the app list is visible, tapping on the app list button
2334 // transitions ink drop states correctly.
2335 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapWhenVisible) {
2336 InitAppListButtonInkDrop();
2337
2338 // Show the app list.
2339 ShowAppList();
2340 FinishAppListVisibilityChange();
2341 EXPECT_EQ(views::InkDropState::ACTIVATED,
2342 app_list_button_ink_drop_->GetTargetInkDropState());
2343 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2344 ElementsAre(views::InkDropState::ACTIVATED));
2345
2346 ui::test::EventGenerator& generator = GetEventGenerator();
2347 generator.MoveMouseTo(app_list_button_->GetBoundsInScreen().CenterPoint());
2348
2349 // Touch press on the button, which dismisses the app list, should end up in
2350 // the hidden state.
2351 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2352 DismissAppList();
2353 generator.PressTouch();
2354 EXPECT_EQ(views::InkDropState::HIDDEN,
2355 app_list_button_ink_drop_->GetTargetInkDropState());
2356 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2357 ElementsAre(views::InkDropState::DEACTIVATED));
2358
2359 // Touch release on the button should not change the ink drop state.
2360 generator.ReleaseTouch();
2361 FinishAppListVisibilityChange();
2362 EXPECT_EQ(views::InkDropState::HIDDEN,
2363 app_list_button_ink_drop_->GetTargetInkDropState());
2364 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2365 IsEmpty());
2366 }
2367
2368 // Tests that when the app list is hidden, tapping down on the app list button
2369 // and dragging the touch point transitions ink drop states correctly.
2370 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenHidden) {
2371 InitAppListButtonInkDrop();
2372
2373 ui::test::EventGenerator& generator = GetEventGenerator();
2374 gfx::Point touch_location =
2375 app_list_button_->GetBoundsInScreen().CenterPoint();
2376 generator.MoveMouseTo(touch_location);
2377
2378 // Touch press on the button should end up in the pending state.
2379 generator.PressTouch();
2380 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2381 app_list_button_ink_drop_->GetTargetInkDropState());
2382 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2383 ElementsAre(views::InkDropState::ACTION_PENDING));
2384
2385 // Dragging the touch point should hide the pending ink drop.
2386 touch_location.Offset(app_list_button_->width(), 0);
2387 generator.MoveTouch(touch_location);
2388 EXPECT_EQ(views::InkDropState::HIDDEN,
2389 app_list_button_ink_drop_->GetTargetInkDropState());
2390 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2391 ElementsAre(views::InkDropState::HIDDEN));
2392
2393 // Touch release should not change the ink drop state.
2394 generator.ReleaseTouch();
2395 EXPECT_EQ(views::InkDropState::HIDDEN,
2396 app_list_button_ink_drop_->GetTargetInkDropState());
2397 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2398 IsEmpty());
2399 }
2400
2401 // Tests that when the app list is visible, tapping down on the app list button
2402 // and dragging the touch point transitions ink drop states correctly.
2403 TEST_F(ShelfViewInkDropTest, AppListButtonGestureTapDragWhenVisible) {
2404 InitAppListButtonInkDrop();
2405
2406 // Show the app list.
2407 ShowAppList();
2408 FinishAppListVisibilityChange();
2409 EXPECT_EQ(views::InkDropState::ACTIVATED,
2410 app_list_button_ink_drop_->GetTargetInkDropState());
2411 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2412 ElementsAre(views::InkDropState::ACTIVATED));
2413
2414 ui::test::EventGenerator& generator = GetEventGenerator();
2415 gfx::Point touch_location =
2416 app_list_button_->GetBoundsInScreen().CenterPoint();
2417 generator.MoveMouseTo(touch_location);
2418
2419 // Touch press on the button, which dismisses the app list, should end up in
2420 // the hidden state.
2421 // Dismiss app list similar to pre-target handler in real AppListPresenter.
2422 DismissAppList();
2423 generator.PressTouch();
2424 EXPECT_EQ(views::InkDropState::HIDDEN,
2425 app_list_button_ink_drop_->GetTargetInkDropState());
2426 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2427 ElementsAre(views::InkDropState::DEACTIVATED));
2428
2429 // Dragging the touch point and releasing should not change the ink drop
2430 // state.
2431 touch_location.Offset(app_list_button_->width(), 0);
2432 generator.MoveTouch(touch_location);
2433 generator.ReleaseTouch();
2434 FinishAppListVisibilityChange();
2435 EXPECT_EQ(views::InkDropState::HIDDEN,
2436 app_list_button_ink_drop_->GetTargetInkDropState());
2437 EXPECT_THAT(app_list_button_ink_drop_->GetAndResetRequestedStates(),
2438 ElementsAre(views::InkDropState::HIDDEN));
2439 }
2440 #endif // !defined(OS_WIN)
2441
2119 // Tests that clicking on a shelf item that does not show a menu transitions ink 2442 // Tests that clicking on a shelf item that does not show a menu transitions ink
2120 // drop states correctly. 2443 // drop states correctly.
2121 TEST_F(ShelfViewInkDropTest, WithoutMenuPressRelease) { 2444 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressRelease) {
2445 InitBrowserButtonInkDrop();
2446
2122 views::CustomButton* button = browser_button_; 2447 views::CustomButton* button = browser_button_;
2123 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2448 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2124 2449
2125 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2450 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2126 press_location, ui::EventTimeForNow(), 2451 mouse_location, ui::EventTimeForNow(),
2127 ui::EF_LEFT_MOUSE_BUTTON, 0); 2452 ui::EF_LEFT_MOUSE_BUTTON, 0);
2128 button->OnMousePressed(press_event); 2453 button->OnMousePressed(press_event);
2129 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2454 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2130 ink_drop_->GetTargetInkDropState()); 2455 browser_button_ink_drop_->GetTargetInkDropState());
2131 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2456 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2132 ElementsAre(views::InkDropState::ACTION_PENDING)); 2457 ElementsAre(views::InkDropState::ACTION_PENDING));
2133 2458
2134 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2459 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2135 press_location, ui::EventTimeForNow(), 2460 mouse_location, ui::EventTimeForNow(),
2136 ui::EF_LEFT_MOUSE_BUTTON, 0); 2461 ui::EF_LEFT_MOUSE_BUTTON, 0);
2137 button->OnMouseReleased(release_event); 2462 button->OnMouseReleased(release_event);
2138 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2463 EXPECT_EQ(views::InkDropState::HIDDEN,
2139 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2464 browser_button_ink_drop_->GetTargetInkDropState());
2465 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2140 ElementsAre(views::InkDropState::ACTION_TRIGGERED)); 2466 ElementsAre(views::InkDropState::ACTION_TRIGGERED));
2141 } 2467 }
2142 2468
2143 // Tests that dragging outside of a shelf item transitions ink drop states 2469 // Tests that dragging outside of a shelf item transitions ink drop states
2144 // correctly. 2470 // correctly.
2145 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseOutside) { 2471 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseOutside) {
2472 InitBrowserButtonInkDrop();
2473
2146 views::CustomButton* button = browser_button_; 2474 views::CustomButton* button = browser_button_;
2147 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2475 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2148 2476
2149 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2477 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2150 press_location, ui::EventTimeForNow(), 2478 mouse_location, ui::EventTimeForNow(),
2151 ui::EF_LEFT_MOUSE_BUTTON, 0); 2479 ui::EF_LEFT_MOUSE_BUTTON, 0);
2152 button->OnMousePressed(press_event); 2480 button->OnMousePressed(press_event);
2153 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2481 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2154 ink_drop_->GetTargetInkDropState()); 2482 browser_button_ink_drop_->GetTargetInkDropState());
2155 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2483 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2156 ElementsAre(views::InkDropState::ACTION_PENDING)); 2484 ElementsAre(views::InkDropState::ACTION_PENDING));
2157 2485
2158 press_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0); 2486 mouse_location.Offset(test_api_->GetMinimumDragDistance() / 2, 0);
2159 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, press_location, 2487 ui::MouseEvent drag_event_small(ui::ET_MOUSE_DRAGGED, mouse_location,
2160 press_location, ui::EventTimeForNow(), 2488 mouse_location, ui::EventTimeForNow(),
2161 ui::EF_LEFT_MOUSE_BUTTON, 0); 2489 ui::EF_LEFT_MOUSE_BUTTON, 0);
2162 button->OnMouseDragged(drag_event_small); 2490 button->OnMouseDragged(drag_event_small);
2163 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2491 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2164 ink_drop_->GetTargetInkDropState()); 2492 browser_button_ink_drop_->GetTargetInkDropState());
2165 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2493 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2166 2494 IsEmpty());
2167 press_location.Offset(test_api_->GetMinimumDragDistance(), 0); 2495
2168 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, press_location, 2496 mouse_location.Offset(test_api_->GetMinimumDragDistance(), 0);
2169 press_location, ui::EventTimeForNow(), 2497 ui::MouseEvent drag_event_large(ui::ET_MOUSE_DRAGGED, mouse_location,
2498 mouse_location, ui::EventTimeForNow(),
2170 ui::EF_LEFT_MOUSE_BUTTON, 0); 2499 ui::EF_LEFT_MOUSE_BUTTON, 0);
2171 button->OnMouseDragged(drag_event_large); 2500 button->OnMouseDragged(drag_event_large);
2172 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2501 EXPECT_EQ(views::InkDropState::HIDDEN,
2173 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2502 browser_button_ink_drop_->GetTargetInkDropState());
2503 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2174 ElementsAre(views::InkDropState::HIDDEN)); 2504 ElementsAre(views::InkDropState::HIDDEN));
2175 2505
2176 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2506 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2177 press_location, ui::EventTimeForNow(), 2507 mouse_location, ui::EventTimeForNow(),
2178 ui::EF_LEFT_MOUSE_BUTTON, 0); 2508 ui::EF_LEFT_MOUSE_BUTTON, 0);
2179 button->OnMouseReleased(release_event); 2509 button->OnMouseReleased(release_event);
2180 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2510 EXPECT_EQ(views::InkDropState::HIDDEN,
2181 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2511 browser_button_ink_drop_->GetTargetInkDropState());
2512 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2513 IsEmpty());
2182 } 2514 }
2183 2515
2184 // Tests that dragging outside of a shelf item and back transitions ink drop 2516 // Tests that dragging outside of a shelf item and back transitions ink drop
2185 // states correctly. 2517 // states correctly.
2186 TEST_F(ShelfViewInkDropTest, WithoutMenuPressDragReleaseInside) { 2518 TEST_F(ShelfViewInkDropTest, ShelfButtonWithoutMenuPressDragReleaseInside) {
2519 InitBrowserButtonInkDrop();
2520
2187 views::CustomButton* button = browser_button_; 2521 views::CustomButton* button = browser_button_;
2188 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2522 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2189 2523
2190 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2524 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2191 press_location, ui::EventTimeForNow(), 2525 mouse_location, ui::EventTimeForNow(),
2192 ui::EF_LEFT_MOUSE_BUTTON, 0); 2526 ui::EF_LEFT_MOUSE_BUTTON, 0);
2193 button->OnMousePressed(press_event); 2527 button->OnMousePressed(press_event);
2194 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2528 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2195 ink_drop_->GetTargetInkDropState()); 2529 browser_button_ink_drop_->GetTargetInkDropState());
2196 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2530 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2197 ElementsAre(views::InkDropState::ACTION_PENDING)); 2531 ElementsAre(views::InkDropState::ACTION_PENDING));
2198 2532
2199 press_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0); 2533 mouse_location.Offset(test_api_->GetMinimumDragDistance() * 2, 0);
2200 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, press_location, 2534 ui::MouseEvent drag_event_outside(ui::ET_MOUSE_DRAGGED, mouse_location,
2201 press_location, ui::EventTimeForNow(), 2535 mouse_location, ui::EventTimeForNow(),
2202 ui::EF_LEFT_MOUSE_BUTTON, 0); 2536 ui::EF_LEFT_MOUSE_BUTTON, 0);
2203 button->OnMouseDragged(drag_event_outside); 2537 button->OnMouseDragged(drag_event_outside);
2204 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2538 EXPECT_EQ(views::InkDropState::HIDDEN,
2205 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2539 browser_button_ink_drop_->GetTargetInkDropState());
2540 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2206 ElementsAre(views::InkDropState::HIDDEN)); 2541 ElementsAre(views::InkDropState::HIDDEN));
2207 2542
2208 press_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0); 2543 mouse_location.Offset(-test_api_->GetMinimumDragDistance() * 2, 0);
2209 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, press_location, 2544 ui::MouseEvent drag_event_inside(ui::ET_MOUSE_DRAGGED, mouse_location,
2210 press_location, ui::EventTimeForNow(), 2545 mouse_location, ui::EventTimeForNow(),
2211 ui::EF_LEFT_MOUSE_BUTTON, 0); 2546 ui::EF_LEFT_MOUSE_BUTTON, 0);
2212 button->OnMouseDragged(drag_event_inside); 2547 button->OnMouseDragged(drag_event_inside);
2213 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2548 EXPECT_EQ(views::InkDropState::HIDDEN,
2214 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2549 browser_button_ink_drop_->GetTargetInkDropState());
2215 2550 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2216 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2551 IsEmpty());
2217 press_location, ui::EventTimeForNow(), 2552
2553 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2554 mouse_location, ui::EventTimeForNow(),
2218 ui::EF_LEFT_MOUSE_BUTTON, 0); 2555 ui::EF_LEFT_MOUSE_BUTTON, 0);
2219 button->OnMouseReleased(release_event); 2556 button->OnMouseReleased(release_event);
2220 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2557 EXPECT_EQ(views::InkDropState::HIDDEN,
2221 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), IsEmpty()); 2558 browser_button_ink_drop_->GetTargetInkDropState());
2559 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2560 IsEmpty());
2222 } 2561 }
2223 2562
2224 // Tests that clicking on a shelf item that shows an app list menu transitions 2563 // Tests that clicking on a shelf item that shows an app list menu transitions
2225 // ink drop state correctly. 2564 // ink drop state correctly.
2226 TEST_F(ShelfViewInkDropTest, WithMenuPressRelease) { 2565 TEST_F(ShelfViewInkDropTest, ShelfButtonWithMenuPressRelease) {
2566 InitBrowserButtonInkDrop();
2567
2227 // Set a delegate for the shelf item that returns an app list menu. 2568 // Set a delegate for the shelf item that returns an app list menu.
2228 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 2569 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
2229 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate; 2570 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate;
2230 item_manager_->SetShelfItemDelegate(browser_shelf_id, 2571 item_manager_->SetShelfItemDelegate(browser_shelf_id,
2231 base::WrapUnique(list_menu_delegate)); 2572 base::WrapUnique(list_menu_delegate));
2232 2573
2233 views::CustomButton* button = browser_button_; 2574 views::CustomButton* button = browser_button_;
2234 gfx::Point press_location = button->GetLocalBounds().CenterPoint(); 2575 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint();
2235 2576
2236 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, press_location, 2577 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location,
2237 press_location, ui::EventTimeForNow(), 2578 mouse_location, ui::EventTimeForNow(),
2238 ui::EF_LEFT_MOUSE_BUTTON, 0); 2579 ui::EF_LEFT_MOUSE_BUTTON, 0);
2239 button->OnMousePressed(press_event); 2580 button->OnMousePressed(press_event);
2240 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2581 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2241 ink_drop_->GetTargetInkDropState()); 2582 browser_button_ink_drop_->GetTargetInkDropState());
2242 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2583 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2243 ElementsAre(views::InkDropState::ACTION_PENDING)); 2584 ElementsAre(views::InkDropState::ACTION_PENDING));
2244 2585
2245 base::ThreadTaskRunnerHandle::Get()->PostTask( 2586 base::ThreadTaskRunnerHandle::Get()->PostTask(
2246 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu, 2587 FROM_HERE, base::Bind(&ShelfViewTestAPI::CloseMenu,
2247 base::Unretained(test_api_.get()))); 2588 base::Unretained(test_api_.get())));
2248 2589
2249 // Mouse release will spawn a menu which will then get closed by the above 2590 // Mouse release will spawn a menu which will then get closed by the above
2250 // posted task. 2591 // posted task.
2251 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, press_location, 2592 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, mouse_location,
2252 press_location, ui::EventTimeForNow(), 2593 mouse_location, ui::EventTimeForNow(),
2253 ui::EF_LEFT_MOUSE_BUTTON, 0); 2594 ui::EF_LEFT_MOUSE_BUTTON, 0);
2254 button->OnMouseReleased(release_event); 2595 button->OnMouseReleased(release_event);
2255 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2596 EXPECT_EQ(views::InkDropState::HIDDEN,
2256 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2597 browser_button_ink_drop_->GetTargetInkDropState());
2598 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(),
2257 ElementsAre(views::InkDropState::ACTIVATED, 2599 ElementsAre(views::InkDropState::ACTIVATED,
2258 views::InkDropState::DEACTIVATED)); 2600 views::InkDropState::DEACTIVATED));
2259 } 2601 }
2260 2602
2261 } // namespace test 2603 } // namespace test
2262 } // namespace ash 2604 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698