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