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

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, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 ShelfButton* button = test_api_->GetButton(i); 1475 ShelfButton* button = test_api_->GetButton(i);
1476 if (!button) 1476 if (!button)
1477 continue; 1477 continue;
1478 1478
1479 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1479 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1480 button->GetMirroredBounds().CenterPoint())) 1480 button->GetMirroredBounds().CenterPoint()))
1481 << "ShelfView tries to hide on button " << i; 1481 << "ShelfView tries to hide on button " << i;
1482 } 1482 }
1483 1483
1484 // The tooltip should not hide on the app-list button. 1484 // The tooltip should not hide on the app-list button.
1485 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1485 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1486 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1486 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1487 app_list_button->GetMirroredBounds().CenterPoint())); 1487 app_list_button->GetMirroredBounds().CenterPoint()));
1488 1488
1489 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. 1489 // 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(); 1490 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds();
1491 gfx::Rect platform_button_rect = 1491 gfx::Rect platform_button_rect =
1492 GetButtonByID(platform_button_id)->GetMirroredBounds(); 1492 GetButtonByID(platform_button_id)->GetMirroredBounds();
1493 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect)); 1493 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect));
1494 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1494 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1495 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint())); 1495 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint()));
1496 1496
1497 // The tooltip should hide if it's outside of all buttons. 1497 // The tooltip should hide if it's outside of all buttons.
1498 gfx::Rect all_area; 1498 gfx::Rect all_area;
1499 for (int i = 0; i < test_api_->GetButtonCount(); i++) { 1499 for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1500 ShelfButton* button = test_api_->GetButton(i); 1500 ShelfButton* button = test_api_->GetButton(i);
1501 if (!button) 1501 if (!button)
1502 continue; 1502 continue;
1503 1503
1504 all_area.Union(button->GetMirroredBounds()); 1504 all_area.Union(button->GetMirroredBounds());
1505 } 1505 }
1506 all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds()); 1506 all_area.Union(shelf_view_->GetAppListButton()->GetMirroredBounds());
1507 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin())); 1507 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin()));
1508 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1508 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1509 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); 1509 gfx::Point(all_area.right() - 1, all_area.bottom() - 1)));
1510 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1510 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1511 gfx::Point(all_area.right(), all_area.y()))); 1511 gfx::Point(all_area.right(), all_area.y())));
1512 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1512 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1513 gfx::Point(all_area.x() - 1, all_area.y()))); 1513 gfx::Point(all_area.x() - 1, all_area.y())));
1514 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1514 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1515 gfx::Point(all_area.x(), all_area.y() - 1))); 1515 gfx::Point(all_area.x(), all_area.y() - 1)));
1516 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1516 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1517 gfx::Point(all_area.x(), all_area.bottom()))); 1517 gfx::Point(all_area.x(), all_area.bottom())));
1518 } 1518 }
1519 1519
1520 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) { 1520 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
1521 Shell::GetInstance()->ShowAppList(NULL); 1521 Shell::GetInstance()->ShowAppList(NULL);
1522 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1522 ASSERT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1523 1523
1524 // The tooltip shouldn't hide if the mouse is on normal buttons. 1524 // The tooltip shouldn't hide if the mouse is on normal buttons.
1525 for (int i = 1; i < test_api_->GetButtonCount(); i++) { 1525 for (int i = 1; i < test_api_->GetButtonCount(); i++) {
1526 ShelfButton* button = test_api_->GetButton(i); 1526 ShelfButton* button = test_api_->GetButton(i);
1527 if (!button) 1527 if (!button)
1528 continue; 1528 continue;
1529 1529
1530 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( 1530 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1531 button->GetMirroredBounds().CenterPoint())) 1531 button->GetMirroredBounds().CenterPoint()))
1532 << "ShelfView tries to hide on button " << i; 1532 << "ShelfView tries to hide on button " << i;
1533 } 1533 }
1534 1534
1535 // The tooltip should hide on the app-list button. 1535 // The tooltip should hide on the app-list button.
1536 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1536 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1537 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1537 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1538 app_list_button->GetMirroredBounds().CenterPoint())); 1538 app_list_button->GetMirroredBounds().CenterPoint()));
1539 } 1539 }
1540 1540
1541 // Test that by moving the mouse cursor off the button onto the bubble it closes 1541 // Test that by moving the mouse cursor off the button onto the bubble it closes
1542 // the bubble. 1542 // the bubble.
1543 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { 1543 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
1544 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager(); 1544 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1545 tooltip_manager->set_timer_delay_for_test(0); 1545 tooltip_manager->set_timer_delay_for_test(0);
1546 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1546 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1547 1547
1548 // Move the mouse off any item and check that no tooltip is shown. 1548 // Move the mouse off any item and check that no tooltip is shown.
1549 generator.MoveMouseTo(gfx::Point(0, 0)); 1549 generator.MoveMouseTo(gfx::Point(0, 0));
1550 EXPECT_FALSE(tooltip_manager->IsVisible()); 1550 EXPECT_FALSE(tooltip_manager->IsVisible());
1551 1551
1552 // Move the mouse over the button and check that it is visible. 1552 // Move the mouse over the button and check that it is visible.
1553 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1553 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1554 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1554 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1555 generator.MoveMouseTo(bounds.CenterPoint()); 1555 generator.MoveMouseTo(bounds.CenterPoint());
1556 // Wait for the timer to go off. 1556 // Wait for the timer to go off.
1557 RunAllPendingInMessageLoop(); 1557 RunAllPendingInMessageLoop();
1558 EXPECT_TRUE(tooltip_manager->IsVisible()); 1558 EXPECT_TRUE(tooltip_manager->IsVisible());
1559 1559
1560 // Move the mouse cursor slightly to the right of the item. The tooltip should 1560 // Move the mouse cursor slightly to the right of the item. The tooltip should
1561 // stay open. 1561 // stay open.
1562 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); 1562 generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
1563 // Make sure there is no delayed close. 1563 // Make sure there is no delayed close.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 1853
1854 // Make the added running platform app to be an app shortcut. 1854 // 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 1855 // This app shortcut should be a swapped view in overflow bubble, which is
1856 // invisible. 1856 // invisible.
1857 SetShelfItemTypeToAppShortcut(platform_app_id); 1857 SetShelfItemTypeToAppShortcut(platform_app_id);
1858 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); 1858 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible());
1859 } 1859 }
1860 1860
1861 // Tests that the AppListButton renders as active in response to touches. 1861 // Tests that the AppListButton renders as active in response to touches.
1862 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) { 1862 TEST_F(ShelfViewTest, AppListButtonTouchFeedback) {
1863 AppListButton* app_list_button = 1863 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1864 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1865 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1864 EXPECT_FALSE(app_list_button->draw_background_as_active());
1866 1865
1867 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1866 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1868 generator.set_current_location(app_list_button-> 1867 generator.set_current_location(app_list_button->
1869 GetBoundsInScreen().CenterPoint()); 1868 GetBoundsInScreen().CenterPoint());
1870 generator.PressTouch(); 1869 generator.PressTouch();
1871 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1870 EXPECT_TRUE(app_list_button->draw_background_as_active());
1872 1871
1873 generator.ReleaseTouch(); 1872 generator.ReleaseTouch();
1874 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1873 EXPECT_FALSE(app_list_button->draw_background_as_active());
1875 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); 1874 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1876 } 1875 }
1877 1876
1878 // Tests that a touch that slides out of the bounds of the AppListButton leads 1877 // Tests that a touch that slides out of the bounds of the AppListButton leads
1879 // to the end of rendering an active state. 1878 // to the end of rendering an active state.
1880 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) { 1879 TEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) {
1881 AppListButton* app_list_button = 1880 AppListButton* app_list_button = shelf_view_->GetAppListButton();
1882 static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
1883 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1881 EXPECT_FALSE(app_list_button->draw_background_as_active());
1884 1882
1885 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1883 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1886 generator.set_current_location(app_list_button-> 1884 generator.set_current_location(app_list_button->
1887 GetBoundsInScreen().CenterPoint()); 1885 GetBoundsInScreen().CenterPoint());
1888 generator.PressTouch(); 1886 generator.PressTouch();
1889 EXPECT_TRUE(app_list_button->draw_background_as_active()); 1887 EXPECT_TRUE(app_list_button->draw_background_as_active());
1890 1888
1891 gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1, 1889 gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1,
1892 app_list_button-> 1890 app_list_button->
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); 1969 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
1972 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); 1970 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1973 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1971 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
1974 if (ShelfButton* button = test_api_->GetButton(i)) 1972 if (ShelfButton* button = test_api_->GetButton(i))
1975 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); 1973 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
1976 CheckAppListButtonIsInBounds(); 1974 CheckAppListButtonIsInBounds();
1977 } 1975 }
1978 1976
1979 void CheckAppListButtonIsInBounds() { 1977 void CheckAppListButtonIsInBounds() {
1980 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1978 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1981 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> 1979 gfx::Rect app_list_button_bounds =
1982 GetBoundsInScreen(); 1980 shelf_view_->GetAppListButton()->GetBoundsInScreen();
1983 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds)); 1981 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds));
1984 } 1982 }
1985 1983
1986 private: 1984 private:
1987 ScopedTextDirectionChange text_direction_change_; 1985 ScopedTextDirectionChange text_direction_change_;
1988 1986
1989 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest); 1987 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest);
1990 }; 1988 };
1991 1989
1992 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) { 1990 TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 ui::EF_LEFT_MOUSE_BUTTON, 0); 2279 ui::EF_LEFT_MOUSE_BUTTON, 0);
2282 button->OnMouseReleased(release_event); 2280 button->OnMouseReleased(release_event);
2283 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); 2281 EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
2284 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(), 2282 EXPECT_THAT(ink_drop_->GetAndResetRequestedStates(),
2285 ElementsAre(views::InkDropState::ACTIVATED, 2283 ElementsAre(views::InkDropState::ACTIVATED,
2286 views::InkDropState::DEACTIVATED)); 2284 views::InkDropState::DEACTIVATED));
2287 } 2285 }
2288 2286
2289 } // namespace test 2287 } // namespace test
2290 } // namespace ash 2288 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698