Commit 8aa5ee43 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Delete most overflow shelf view test code

Change-Id: Iaadce70c24f55fe5bb68ffdd6963c7812f25e271
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065273Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743113}
parent 20a9e600
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shelf/back_button.h" #include "ash/shelf/back_button.h"
#include "ash/shelf/home_button.h" #include "ash/shelf/home_button.h"
#include "ash/shelf/overflow_bubble.h"
#include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/overflow_bubble_view_test_api.h"
#include "ash/shelf/overflow_button.h" #include "ash/shelf/overflow_button.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_app_button.h" #include "ash/shelf/shelf_app_button.h"
...@@ -348,7 +345,7 @@ class ShelfViewTest : public AshTestBase { ...@@ -348,7 +345,7 @@ class ShelfViewTest : public AshTestBase {
->GetStatusAreaWidget() ->GetStatusAreaWidget()
->GetContentsView(); ->GetContentsView();
// The bounds should be big enough for 4 buttons + overflow button. // The bounds should be big enough for 4 buttons.
ASSERT_GE(GetPrimaryShelf() ASSERT_GE(GetPrimaryShelf()
->shelf_widget() ->shelf_widget()
->hotseat_widget() ->hotseat_widget()
...@@ -586,148 +583,6 @@ class ShelfViewTest : public AshTestBase { ...@@ -586,148 +583,6 @@ class ShelfViewTest : public AshTestBase {
} }
} }
// Helper function for testing dragging an item off one shelf to another
// shelf. |main_to_overflow| is true if we are moving the item from the main
// shelf to the overflow shelf; it is false if we are moving the item from the
// overflow shelf to the main shelf. |cancel| is true if we want to cancel the
// dragging halfway through.
void TestDraggingAnItemFromShelfToOtherShelf(bool main_to_overflow,
bool cancel) {
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI test_api_for_overflow(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
const ShelfView* overflow_shelf_view = shelf_view_->overflow_shelf();
int total_item_count = model_->item_count();
// Intialize some ids to test after the drag operation is canceled or
// completed. These ids are set assuming the both the main shelf and
// overflow shelf has more than 3 items.
ShelfID last_visible_item_id_in_shelf =
GetItemId(shelf_view_->last_visible_index());
ShelfID second_last_visible_item_id_in_shelf =
GetItemId(shelf_view_->last_visible_index() - 1);
ShelfID first_visible_item_id_in_overflow =
GetItemId(overflow_shelf_view->first_visible_index());
ShelfID second_last_visible_item_id_in_overflow =
GetItemId(overflow_shelf_view->last_visible_index() - 1);
// |src_api| represents the test api of the shelf we are moving the item
// from. |dest_api| represents the test api of the shelf we are moving the
// item too.
ShelfViewTestAPI* src_api =
main_to_overflow ? test_api_.get() : &test_api_for_overflow;
const ShelfView* src_shelf_view =
main_to_overflow ? shelf_view_ : overflow_shelf_view;
ShelfViewTestAPI* dest_api =
main_to_overflow ? &test_api_for_overflow : test_api_.get();
const ShelfView* dest_shelf_view =
main_to_overflow ? overflow_shelf_view : shelf_view_;
// Set the item to be dragged depending on |main_to_overflow|.
int drag_item_index =
main_to_overflow ? 3 : src_shelf_view->last_visible_index();
ShelfID drag_item_id = GetItemId(drag_item_index);
ShelfAppButton* drag_button = src_api->GetButton(drag_item_index);
gfx::Point center_point_of_drag_item = GetButtonCenter(drag_button);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(center_point_of_drag_item);
// Rip an item off this source shelf.
generator->PressLeftButton();
gfx::Point rip_off_point(center_point_of_drag_item.x(), 0);
generator->MoveMouseTo(rip_off_point);
src_api->RunMessageLoopUntilAnimationsDone();
dest_api->RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(src_api->IsRippedOffFromShelf());
ASSERT_FALSE(src_api->DraggedItemToAnotherShelf());
// Move a dragged item into the destination shelf at |drop_index|.
int drop_index =
main_to_overflow ? dest_shelf_view->last_visible_index() : 3;
ShelfAppButton* drop_button = dest_api->GetButton(drop_index);
gfx::Point drop_point = GetButtonCenter(drop_button);
// To insert at |drop_index|, a smaller x-axis value of |drop_point|
// should be used. If |drop_index| is the last item, a larger x-axis
// value of |drop_point| should be used.
int drop_point_x_shift = main_to_overflow
? ShelfConfig::Get()->button_size() / 4
: -ShelfConfig::Get()->button_size() / 4;
gfx::Point modified_drop_point(drop_point.x() + drop_point_x_shift,
drop_point.y());
generator->MoveMouseTo(modified_drop_point);
src_api->RunMessageLoopUntilAnimationsDone();
dest_api->RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(src_api->IsRippedOffFromShelf());
ASSERT_TRUE(src_api->DraggedItemToAnotherShelf());
if (cancel)
drag_button->OnMouseCaptureLost();
generator->ReleaseLeftButton();
src_api->RunMessageLoopUntilAnimationsDone();
dest_api->RunMessageLoopUntilAnimationsDone();
ASSERT_FALSE(src_api->IsRippedOffFromShelf());
ASSERT_FALSE(src_api->DraggedItemToAnotherShelf());
// Compare pre-stored items' id with newly positioned items' after dragging
// is canceled or finished.
if (cancel) {
// Item ids should remain unchanged if operation was canceled.
EXPECT_EQ(last_visible_item_id_in_shelf,
GetItemId(shelf_view_->last_visible_index()));
EXPECT_EQ(second_last_visible_item_id_in_shelf,
GetItemId(shelf_view_->last_visible_index() - 1));
EXPECT_EQ(first_visible_item_id_in_overflow,
GetItemId(overflow_shelf_view->first_visible_index()));
EXPECT_EQ(second_last_visible_item_id_in_overflow,
GetItemId(overflow_shelf_view->last_visible_index() - 1));
} else {
EXPECT_EQ(drag_item_id, GetItemId(drop_index));
EXPECT_EQ(total_item_count, model_->item_count());
if (main_to_overflow) {
// If we move an item from the main shelf to the overflow shelf, the
// following should happen:
// 1) The former last item on the main shelf should now be the second
// last item on the main shelf.
// 2) The former first item on the overflow shelf should now be the last
// item on the main shelf.
// 3) The dragged item should now be the last item on the main shelf.
EXPECT_EQ(last_visible_item_id_in_shelf,
GetItemId(shelf_view_->last_visible_index() - 1));
EXPECT_EQ(first_visible_item_id_in_overflow,
GetItemId(shelf_view_->last_visible_index()));
EXPECT_EQ(drag_item_id,
GetItemId(overflow_shelf_view->last_visible_index()));
} else {
// If we move an item from the overflow shelf to the main shelf, the
// following should happen:
// 1) The former last item on the main shelf should now be the first
// item on the overflow shelf.
// 2) The former second last item on the main shelf should now be the
// last item on the main shelf.
// 3) The former first item on the overflow shelf should now be the
// second item on the overflow shelf.
// 4) The former second item on the overflow shelf should now be the
// last item on the overflow shelf (since there are 3 items on the
// overflow shelf).
EXPECT_EQ(last_visible_item_id_in_shelf,
GetItemId(overflow_shelf_view->first_visible_index()));
EXPECT_EQ(second_last_visible_item_id_in_shelf,
GetItemId(shelf_view_->last_visible_index()));
EXPECT_EQ(first_visible_item_id_in_overflow,
GetItemId(overflow_shelf_view->first_visible_index() + 1));
EXPECT_EQ(second_last_visible_item_id_in_overflow,
GetItemId(overflow_shelf_view->last_visible_index()));
}
}
test_api_->HideOverflowBubble();
}
// Returns the item's ShelfID at |index|. // Returns the item's ShelfID at |index|.
ShelfID GetItemId(int index) { ShelfID GetItemId(int index) {
DCHECK_GE(index, 0); DCHECK_GE(index, 0);
...@@ -851,31 +706,6 @@ TEST_F(ShelfViewNotScrollableTest, AddBrowserUntilOverflow) { ...@@ -851,31 +706,6 @@ TEST_F(ShelfViewNotScrollableTest, AddBrowserUntilOverflow) {
EXPECT_FALSE(GetButtonByID(last_added)->GetVisible()); EXPECT_FALSE(GetButtonByID(last_added)->GetVisible());
} }
TEST_F(ShelfViewNotScrollableTest, OverflowVisibleIndex) {
AddAppShortcutsUntilOverflow();
ASSERT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
const int last_visible_index = shelf_view_->last_visible_index();
test_api_->ShowOverflowBubble();
auto overflow_test_api = std::make_unique<ShelfViewTestAPI>(
shelf_view_->overflow_bubble()->bubble_view()->shelf_view());
base::RunLoop().RunUntilIdle();
// Opening overflow doesn't change last visible index.
EXPECT_EQ(last_visible_index, shelf_view_->last_visible_index());
test_api_->HideOverflowBubble();
AddAppShortcut();
test_api_->ShowOverflowBubble();
overflow_test_api = std::make_unique<ShelfViewTestAPI>(
shelf_view_->overflow_bubble()->bubble_view()->shelf_view());
base::RunLoop().RunUntilIdle();
// Adding another shortcut should go into overflow bubble and not change
// shelf index.
EXPECT_EQ(last_visible_index, shelf_view_->last_visible_index());
}
// Adds one platform app button then adds app shortcut until overflow. Verifies // Adds one platform app button then adds app shortcut until overflow. Verifies
// that the browser button gets hidden on overflow and last added app shortcut // that the browser button gets hidden on overflow and last added app shortcut
// is still visible. // is still visible.
...@@ -1006,50 +836,6 @@ TEST_F(ShelfViewNotScrollableTest, RemoveLastOverflowed) { ...@@ -1006,50 +836,6 @@ TEST_F(ShelfViewNotScrollableTest, RemoveLastOverflowed) {
EXPECT_FALSE(shelf_view_->GetOverflowButton()->GetVisible()); EXPECT_FALSE(shelf_view_->GetOverflowButton()->GetVisible());
} }
// Tests the visiblity of certain shelf items when the overflow bubble is open
// and entering or exiting tablet mode.
TEST_F(ShelfViewNotScrollableTest, OverflowVisibleItemsInTabletMode) {
// Helper to check whether the item with index |index| is visible on the shelf
// associated with |shelf_test_api|.
auto is_visible_on_shelf = [](int index, ShelfViewTestAPI* shelf_test_api) {
return shelf_test_api->shelf_view()
->view_model_for_test()
->view_at(index)
->GetVisible();
};
// Setup the shelf so the overflow bubble is visible.
AddAppShortcutsUntilOverflow();
test_api_->ShowOverflowBubble();
ShelfViewTestAPI overflow_test_api(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
// The main shelf is currently showing the item at |last_visible_index|.
const int last_visible_index = shelf_view_->last_visible_index();
EXPECT_TRUE(is_visible_on_shelf(last_visible_index, test_api_.get()));
EXPECT_FALSE(is_visible_on_shelf(last_visible_index, &overflow_test_api));
// Verify that after entering tablet mode, the last item on the main shelf
// is no longer visible on the main shelf but is now visible on the overflow
// shelf, due to the back button taking up space on the main shelf. The shelf
// model and corresponding view should be updated to reflect this.
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
test_api_->RunMessageLoopUntilAnimationsDone();
overflow_test_api.RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
EXPECT_FALSE(is_visible_on_shelf(last_visible_index, test_api_.get()));
EXPECT_TRUE(is_visible_on_shelf(last_visible_index, &overflow_test_api));
// Verify that the item at |last_visible_index| is once again shown on the
// main shelf after exiting tablet mode.
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
test_api_->RunMessageLoopUntilAnimationsDone();
overflow_test_api.RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
EXPECT_TRUE(is_visible_on_shelf(last_visible_index, test_api_.get()));
EXPECT_FALSE(is_visible_on_shelf(last_visible_index, &overflow_test_api));
}
// Adds platform app button without waiting for animation to finish and verifies // Adds platform app button without waiting for animation to finish and verifies
// that all added buttons are visible. // that all added buttons are visible.
TEST_F(ShelfViewNotScrollableTest, AddButtonQuickly) { TEST_F(ShelfViewNotScrollableTest, AddButtonQuickly) {
...@@ -1285,45 +1071,6 @@ TEST_F(ShelfViewTest, ShelfRipOff) { ...@@ -1285,45 +1071,6 @@ TEST_F(ShelfViewTest, ShelfRipOff) {
generator->MoveMouseTo(first_app_location); generator->MoveMouseTo(first_app_location);
generator->ReleaseLeftButton(); generator->ReleaseLeftButton();
EXPECT_FALSE(test_api_->IsRippedOffFromShelf()); EXPECT_FALSE(test_api_->IsRippedOffFromShelf());
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
AddAppShortcutsUntilOverflow();
ShelfID overflow_app_id = AddAppShortcut();
// Open overflow shelf and test api for it.
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI test_api_for_overflow(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
// Verify that when an app from the main shelf is dragged to a location on the
// overflow shelf, it is ripped off.
gfx::Point second_app_location =
GetButtonCenter(GetButtonByID(second_app_id));
gfx::Point overflow_app_location = GetButtonCenter(
test_api_for_overflow.GetButton(model_->ItemIndexByID(overflow_app_id)));
generator->set_current_screen_location(second_app_location);
generator->PressLeftButton();
generator->MoveMouseTo(overflow_app_location);
EXPECT_TRUE(test_api_->IsRippedOffFromShelf());
generator->MoveMouseTo(second_app_location);
generator->ReleaseLeftButton();
EXPECT_FALSE(test_api_->IsRippedOffFromShelf());
// Verify that when an app from the overflow shelf is dragged to a location on
// the main shelf, it is ripped off.
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
generator->set_current_screen_location(overflow_app_location);
generator->PressLeftButton();
generator->MoveMouseTo(second_app_location);
EXPECT_TRUE(test_api_for_overflow.IsRippedOffFromShelf());
generator->MoveMouseTo(overflow_app_location);
generator->ReleaseLeftButton();
EXPECT_FALSE(test_api_for_overflow.IsRippedOffFromShelf());
} }
// Tests that drag and drop a pinned running app will unpin it. // Tests that drag and drop a pinned running app will unpin it.
...@@ -1445,8 +1192,6 @@ TEST_F(ShelfViewNotScrollableTest, ButtonTitlesTest) { ...@@ -1445,8 +1192,6 @@ TEST_F(ShelfViewNotScrollableTest, ButtonTitlesTest) {
->navigation_widget() ->navigation_widget()
->GetBackButton() ->GetBackButton()
->GetAccessibleName()); ->GetAccessibleName());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME),
shelf_view_->GetOverflowButton()->GetAccessibleName());
for (int i = 0; i < test_api_->GetButtonCount(); i++) { for (int i = 0; i < test_api_->GetButtonCount(); i++) {
ShelfAppButton* button = test_api_->GetButton(i); ShelfAppButton* button = test_api_->GetButton(i);
...@@ -1739,149 +1484,6 @@ TEST_F(ShelfViewNotScrollableTest, ResizeDuringOverflowAddAnimation) { ...@@ -1739,149 +1484,6 @@ TEST_F(ShelfViewNotScrollableTest, ResizeDuringOverflowAddAnimation) {
EXPECT_EQ(app_list_ideal_bounds, app_list_bounds); EXPECT_EQ(app_list_ideal_bounds, app_list_bounds);
} }
// Checks the overflow bubble size when an item is ripped off and re-inserted.
TEST_F(ShelfViewNotScrollableTest, OverflowBubbleSize) {
AddAppShortcutsUntilOverflow();
// Add one more button to prevent the overflow bubble to disappear upon
// dragging an item out on windows (flakiness, see crbug.com/436131).
AddAppShortcut();
// Show overflow bubble.
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
const ShelfView* overflow_shelf_view = shelf_view_->overflow_shelf();
int ripped_index = overflow_shelf_view->last_visible_index();
gfx::Size bubble_size = overflow_shelf_view->GetPreferredSize();
int item_width =
ShelfConfig::Get()->button_size() + ShelfConfig::Get()->button_spacing();
ui::test::EventGenerator* generator = GetEventGenerator();
ShelfAppButton* button = test_for_overflow_view.GetButton(ripped_index);
// Rip off the last visible item.
gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
gfx::Point rip_off_point(start_point.x(), 0);
generator->MoveMouseTo(start_point.x(), start_point.y());
base::RunLoop().RunUntilIdle();
generator->PressLeftButton();
base::RunLoop().RunUntilIdle();
generator->MoveMouseTo(rip_off_point.x(), rip_off_point.y());
base::RunLoop().RunUntilIdle();
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
// Check the overflow bubble size when an item is ripped off.
EXPECT_EQ(bubble_size.width() - item_width,
overflow_shelf_view->GetPreferredSize().width());
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
// Re-insert an item into the overflow bubble.
int first_index = overflow_shelf_view->first_visible_index();
button = test_for_overflow_view.GetButton(first_index);
// Check the bubble size after an item is re-inserted.
generator->MoveMouseTo(button->GetBoundsInScreen().CenterPoint());
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
EXPECT_EQ(bubble_size.width(),
overflow_shelf_view->GetPreferredSize().width());
generator->ReleaseLeftButton();
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
EXPECT_EQ(bubble_size.width(),
overflow_shelf_view->GetPreferredSize().width());
}
TEST_F(ShelfViewNotScrollableTest,
DISABLED_OverflowShelfColorIsDerivedFromWallpaper) {
WallpaperControllerTestApi wallpaper_test_api(
Shell::Get()->wallpaper_controller());
const SkColor opaque_expected_color =
wallpaper_test_api.ApplyColorProducingWallpaper();
AddAppShortcutsUntilOverflow();
test_api_->ShowOverflowBubble();
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
EXPECT_EQ(opaque_expected_color, SkColorSetA(bubble_view->color(), 255));
}
// Check the drag insertion bounds of scrolled overflow bubble.
TEST_F(ShelfViewNotScrollableTest,
CheckDragInsertBoundsOfScrolledOverflowBubble) {
UpdateDisplay("400x300");
AddAppShortcutsUntilOverflow();
// Show overflow bubble.
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
int item_width =
ShelfConfig::Get()->button_size() + ShelfConfig::Get()->button_spacing();
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
OverflowBubbleViewTestAPI bubble_view_api(bubble_view);
// Add more buttons until OverflowBubble is scrollable and it has 3 invisible
// items.
while (bubble_view->shelf_view()->GetPreferredSize().width() <
(bubble_view->GetContentsBounds().width() + 3 * item_width)) {
AddAppShortcut();
}
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI test_for_overflow_view(bubble_view->shelf_view());
const ShelfView* overflow_shelf_view = shelf_view_->overflow_shelf();
int first_index = overflow_shelf_view->first_visible_index();
int last_index = overflow_shelf_view->last_visible_index();
views::View* left_arrow_button = bubble_view->left_arrow();
views::View* right_arrow_button = bubble_view->right_arrow();
ShelfAppButton* first_button = test_for_overflow_view.GetButton(first_index);
ShelfAppButton* last_button = test_for_overflow_view.GetButton(last_index);
gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint();
gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint();
gfx::Rect drag_reinsert_bounds =
test_for_overflow_view.GetBoundsForDragInsertInScreen();
EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point));
EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point));
// Verfies that at the beginning, the left button is invisible while the right
// button shows.
EXPECT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_FALSE(left_arrow_button->GetVisible());
EXPECT_TRUE(right_arrow_button->GetVisible());
// Scroll the overflow shelf view a little bit. Then verifies that both arrow
// buttons show.
bubble_view->ScrollByXOffset(item_width, /*animate=*/false);
EXPECT_EQ(OverflowBubbleView::SHOW_BUTTONS, bubble_view->layout_strategy());
EXPECT_TRUE(left_arrow_button->GetVisible());
EXPECT_TRUE(right_arrow_button->GetVisible());
// Scroll sufficiently to completely show last item.
bubble_view->ScrollByXOffset(
bubble_view->shelf_view()->GetPreferredSize().width() -
bubble_view->GetContentsBounds().width(),
/*animate=*/false);
drag_reinsert_bounds =
test_for_overflow_view.GetBoundsForDragInsertInScreen();
first_point = first_button->GetBoundsInScreen().CenterPoint();
last_point = last_button->GetBoundsInScreen().CenterPoint();
EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point));
EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
// Verifies that when the last item shows, the right arrow button is invisible
// while the left one shows.
EXPECT_EQ(OverflowBubbleView::SHOW_LEFT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_TRUE(left_arrow_button->GetVisible());
EXPECT_FALSE(right_arrow_button->GetVisible());
}
// Check the drag insertion bounds of shelf view in multi monitor environment. // Check the drag insertion bounds of shelf view in multi monitor environment.
TEST_F(ShelfViewNotScrollableTest, CheckDragInsertBoundsWithMultiMonitor) { TEST_F(ShelfViewNotScrollableTest, CheckDragInsertBoundsWithMultiMonitor) {
UpdateDisplay("800x600,800x600"); UpdateDisplay("800x600,800x600");
...@@ -1985,153 +1587,6 @@ TEST_F(ShelfViewTest, CheckRipOffFromLeftShelfAlignmentWithMultiMonitor) { ...@@ -1985,153 +1587,6 @@ TEST_F(ShelfViewTest, CheckRipOffFromLeftShelfAlignmentWithMultiMonitor) {
generator.ReleaseLeftButton(); generator.ReleaseLeftButton();
} }
// Checks various drag and drop operations from OverflowBubble to Shelf, and
// vice versa.
TEST_F(ShelfViewNotScrollableTest, CheckDragAndDropFromShelfToOtherShelf) {
AddAppShortcutsUntilOverflow();
// Add one more button to prevent the overflow bubble to disappear upon
// dragging an item out on windows (flakiness, see crbug.com/425097).
AddAppShortcut();
TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */,
false /* cancel */);
TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */,
true /* cancel */);
TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */,
false /* cancel */);
TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */,
true /* cancel */);
}
// Checks taking a screenshot while dragging an app into the overflow menu.
TEST_F(ShelfViewNotScrollableTest, TestDragToOverflowAndTakeScreenshot) {
// We'll need UI controls to trigger the accelerator for taking a screenshot.
ui_controls::InstallUIControlsAura(test::CreateAshUIControls());
AddAppShortcutsUntilOverflow();
// Add a couple more to make sure we can easily drag into the overflow menu.
AddAppShortcut();
AddAppShortcut();
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfView* overflow_shelf_view = shelf_view_->overflow_shelf();
ShelfViewTestAPI test_api_for_overflow(overflow_shelf_view);
EXPECT_LE(2, overflow_shelf_view->number_of_visible_apps());
views::View* drag_button =
test_api_.get()->GetViewAt(shelf_view_->last_visible_index());
ShelfID drag_id = GetItemId(shelf_view_->last_visible_index());
const gfx::Point drag_point = drag_button->GetBoundsInScreen().CenterPoint();
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(drag_point);
// Rip the item off the main shelf.
generator->PressLeftButton();
const gfx::Point rip_off_point(drag_point.x(), 0);
generator->MoveMouseTo(rip_off_point);
test_api_.get()->RunMessageLoopUntilAnimationsDone();
test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(test_api_.get()->IsRippedOffFromShelf());
ASSERT_FALSE(test_api_.get()->DraggedItemToAnotherShelf());
// Move the dragged item into the overflow shelf.
views::View* drop_button = test_api_for_overflow.GetViewAt(
overflow_shelf_view->last_visible_index());
const gfx::Point drop_point = drop_button->GetBoundsInScreen().CenterPoint();
generator->MoveMouseTo(drop_point);
test_api_.get()->RunMessageLoopUntilAnimationsDone();
test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(test_api_.get()->IsRippedOffFromShelf());
ASSERT_TRUE(test_api_.get()->DraggedItemToAnotherShelf());
// Do not release the mouse button yet.
TestScreenshotDelegate* screenshot_delegate = GetScreenshotDelegate();
screenshot_delegate->set_can_take_screenshot(true);
EXPECT_EQ(0, screenshot_delegate->handle_take_screenshot_count());
// Send the key press to take a screenshot, synchronously.
base::RunLoop loop;
ui_controls::SendKeyPressNotifyWhenDone(
Shell::GetPrimaryRootWindow(), ui::VKEY_SNAPSHOT, false /* ctrl */,
false /* shift */, false /* alt */, false /* cmd */, loop.QuitClosure());
loop.Run();
EXPECT_EQ(1, screenshot_delegate->handle_take_screenshot_count());
// Now, finally complete the drag and verify that it was successful.
generator->ReleaseLeftButton();
EXPECT_EQ(drag_id, GetItemId(overflow_shelf_view->last_visible_index()));
ui_controls::InstallUIControlsAura(nullptr);
}
// Checks drag-reorder items within the overflow shelf.
TEST_F(ShelfViewNotScrollableTest, TestDragWithinOverflow) {
// Prepare the overflow and open it.
AddAppShortcutsUntilOverflow();
// Add a couple more to make sure we have things to drag.
AddAppShortcut();
AddAppShortcut();
test_api_->ShowOverflowBubble();
ShelfView* overflow_shelf_view =
shelf_view_->overflow_bubble()->bubble_view()->shelf_view();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
ShelfViewTestAPI overflow_api(overflow_shelf_view);
// We are going to drag the first item in the overflow (A) onto the last
// one (B).
int item_a_initial_index = overflow_shelf_view->first_visible_index();
int item_b_initial_index = overflow_shelf_view->last_visible_index();
ShelfID item_a = GetItemId(item_a_initial_index);
ShelfID item_b = GetItemId(item_b_initial_index);
ShelfAppButton* item_a_button = overflow_api.GetButton(item_a_initial_index);
ShelfAppButton* item_b_button = overflow_api.GetButton(item_b_initial_index);
gfx::Point drag_point = GetButtonCenter(item_a_button);
gfx::Point drop_point = GetButtonCenter(item_b_button);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(drag_point);
EXPECT_EQ(nullptr, overflow_shelf_view->drag_view());
// TODO(manucornet): Test the same thing with only touches.
generator->PressLeftButton();
generator->MoveMouseTo(drop_point);
EXPECT_NE(nullptr, overflow_shelf_view->drag_view());
generator->ReleaseLeftButton();
overflow_api.RunMessageLoopUntilAnimationsDone();
// Now, item A should be the last item, and item B should be just before it.
ShelfID new_first_visible_item =
GetItemId(overflow_shelf_view->first_visible_index());
EXPECT_NE(item_a, new_first_visible_item);
EXPECT_EQ(item_a, GetItemId(overflow_shelf_view->last_visible_index()));
EXPECT_EQ(item_b, GetItemId(overflow_shelf_view->last_visible_index() - 1));
test_api_->HideOverflowBubble();
}
// Checks creating app shortcut for an opened platform app in overflow bubble
// should be invisible to the shelf. See crbug.com/605793.
TEST_F(ShelfViewNotScrollableTest, CheckOverflowStatusPinOpenedAppToShelf) {
AddAppShortcutsUntilOverflow();
// Add a running Platform app.
ShelfID platform_app_id = AddApp();
EXPECT_FALSE(GetButtonByID(platform_app_id)->GetVisible());
// Make the added running platform app to be an app shortcut.
// This app shortcut should be a swapped view in overflow bubble, which is
// invisible.
SetShelfItemTypeToAppShortcut(platform_app_id);
EXPECT_FALSE(GetButtonByID(platform_app_id)->GetVisible());
}
// Verifies that Launcher_ButtonPressed_* UMA user actions are recorded when an // Verifies that Launcher_ButtonPressed_* UMA user actions are recorded when an
// item is selected. // item is selected.
TEST_F(ShelfViewTest, TEST_F(ShelfViewTest,
...@@ -2184,97 +1639,6 @@ TEST_F(ShelfViewTest, ...@@ -2184,97 +1639,6 @@ TEST_F(ShelfViewTest,
kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1);
} }
TEST_F(ShelfViewNotScrollableTest, TestHideOverflow) {
// Use an event generator instead of SimulateClick because the overflow bubble
// uses a Shell pre-target EventHandler to observe input events.
ui::test::EventGenerator* generator = GetEventGenerator();
// Add one app (which is on the main shelf) and then add buttons until
// overflow. Add two more apps (which are on the overflow shelf).
ShelfID first_app_id = AddAppShortcut();
ShelfID second_app_id = AddAppShortcut();
AddAppShortcutsUntilOverflow();
ShelfID overflow_app_id1 = AddAppShortcut();
ShelfID overflow_app_id2 = AddAppShortcut();
// Verify that by pressing anywhere outside the shelf and overflow bubble, the
// overflow bubble will close if it were open.
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
test_api_->ShowOverflowBubble();
// Make sure the point we chose is not on the shelf or its overflow bubble.
ASSERT_FALSE(shelf_view_->GetBoundsInScreen().Contains(
generator->current_screen_location()));
ASSERT_FALSE(test_api_->overflow_bubble()
->bubble_view()
->shelf_view()
->GetBoundsInScreen()
.Contains(generator->current_screen_location()));
generator->PressLeftButton();
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
generator->ReleaseLeftButton();
// Verify that by clicking a app which is on the main shelf while the overflow
// bubble is opened, the overflow bubble will close.
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
test_api_->ShowOverflowBubble();
generator->set_current_screen_location(GetButtonCenter(first_app_id));
generator->ClickLeftButton();
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
// Verify that by clicking a app which is on the overflow shelf, the overflow
// bubble will close.
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
test_api_->ShowOverflowBubble();
ShelfViewTestAPI test_api_for_overflow(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
ShelfAppButton* button_on_overflow_shelf =
test_api_for_overflow.GetButton(model_->ItemIndexByID(overflow_app_id2));
generator->set_current_screen_location(
GetButtonCenter(button_on_overflow_shelf));
generator->ClickLeftButton();
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
// Verify that dragging apps on the main shelf does not close the overflow
// bubble.
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
test_api_->ShowOverflowBubble();
generator->set_current_screen_location(GetButtonCenter(first_app_id));
generator->DragMouseTo(GetButtonCenter(second_app_id));
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
test_api_->HideOverflowBubble();
// Verify dragging apps on the overflow shelf does not close the overflow
// bubble.
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
test_api_->ShowOverflowBubble();
ShelfViewTestAPI test_api_for_overflow2(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
button_on_overflow_shelf =
test_api_for_overflow2.GetButton(model_->ItemIndexByID(overflow_app_id1));
ShelfAppButton* button_on_overflow_shelf1 =
test_api_for_overflow2.GetButton(model_->ItemIndexByID(overflow_app_id2));
generator->set_current_screen_location(
GetButtonCenter(button_on_overflow_shelf));
generator->DragMouseTo(GetButtonCenter(button_on_overflow_shelf1));
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
TEST_F(ShelfViewNotScrollableTest, UnpinningCancelsOverflow) {
// Add just enough items for overflow; one fewer would not require overflow.
const ShelfID first_shelf_id = AddAppShortcut();
AddAppShortcutsUntilOverflow();
test_api_->ShowOverflowBubble();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
// Unpinning an item should hide the overflow button and close the bubble.
model_->UnpinAppWithID(first_shelf_id.app_id);
test_api_->RunMessageLoopUntilAnimationsDone();
EXPECT_FALSE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Verify the animations of the shelf items are as long as expected. // Verify the animations of the shelf items are as long as expected.
TEST_F(ShelfViewTest, TestShelfItemsAnimations) { TEST_F(ShelfViewTest, TestShelfItemsAnimations) {
TestShelfObserver observer(shelf_view_->shelf()); TestShelfObserver observer(shelf_view_->shelf());
...@@ -2369,18 +1733,6 @@ TEST_F(ShelfViewTest, TabletModeStartAndEndClosesContextMenu) { ...@@ -2369,18 +1733,6 @@ TEST_F(ShelfViewTest, TabletModeStartAndEndClosesContextMenu) {
EXPECT_FALSE(test_api_->CloseMenu()); EXPECT_FALSE(test_api_->CloseMenu());
} }
// Tests that the overflow button does not show a context menu.
TEST_F(ShelfViewNotScrollableTest, NoContextMenuOnOverflowButton) {
ui::test::EventGenerator* generator = GetEventGenerator();
AddAppShortcutsUntilOverflow();
views::View* overflow_button = shelf_view_->GetOverflowButton();
generator->MoveMouseTo(overflow_button->GetBoundsInScreen().CenterPoint());
generator->PressRightButton();
EXPECT_FALSE(test_api_->CloseMenu());
}
// Tests that ShelfWindowWatcher buttons show a context menu on right click. // Tests that ShelfWindowWatcher buttons show a context menu on right click.
TEST_F(ShelfViewTest, ShelfWindowWatcherButtonShowsContextMenu) { TEST_F(ShelfViewTest, ShelfWindowWatcherButtonShowsContextMenu) {
ui::test::EventGenerator* generator = GetEventGenerator(); ui::test::EventGenerator* generator = GetEventGenerator();
...@@ -2673,31 +2025,6 @@ TEST_F(ShelfViewTest, IconCenteringTest) { ...@@ -2673,31 +2025,6 @@ TEST_F(ShelfViewTest, IconCenteringTest) {
app_buttons[0]->GetBoundsInScreen().x(), app_buttons[0]->GetBoundsInScreen().x(),
screen_width - app_buttons[n_buttons - 1]->GetBoundsInScreen().right()); screen_width - app_buttons[n_buttons - 1]->GetBoundsInScreen().right());
} }
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
// Now add apps until the overflow button appears.
while (!shelf_view_->GetOverflowButton()->GetVisible()) {
app_buttons.push_back(GetButtonByID(AddApp()));
n_buttons = app_buttons.size();
}
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
// Now that the apps + overflow button are centered over the available space
// on the shelf, check that the the distance between the left app and the
// home button is equal to the distance between the overflow button
// and the status area.
ExpectWithinOnePixel(
app_buttons[0]->GetBoundsInScreen().x() - shelf_view_->shelf_widget()
->navigation_widget()
->GetHomeButton()
->GetBoundsInScreen()
.right(),
status_area_->GetBoundsInScreen().x() -
(shelf_view_->GetOverflowButton()->GetBoundsInScreen().right() +
ShelfConfig::Get()->overflow_button_margin()));
} }
TEST_F(ShelfViewTest, FirstAndLastVisibleIndex) { TEST_F(ShelfViewTest, FirstAndLastVisibleIndex) {
...@@ -2714,54 +2041,6 @@ TEST_F(ShelfViewTest, FirstAndLastVisibleIndex) { ...@@ -2714,54 +2041,6 @@ TEST_F(ShelfViewTest, FirstAndLastVisibleIndex) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false); Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_EQ(0, shelf_view_->first_visible_index()); EXPECT_EQ(0, shelf_view_->first_visible_index());
EXPECT_EQ(0, shelf_view_->last_visible_index()); EXPECT_EQ(0, shelf_view_->last_visible_index());
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
// Now let's add some apps until the overflow button shows up, each time
// checking the first and last visible indices are what we expect.
int last_visible_index = 0;
int last_visible_index_before_overflow;
ShelfID last_added_item_id;
while (true) {
last_added_item_id = AddApp();
if (shelf_view_->GetOverflowButton()->GetVisible()) {
last_visible_index_before_overflow = last_visible_index;
break;
}
last_visible_index++;
EXPECT_EQ(0, shelf_view_->first_visible_index());
EXPECT_EQ(last_visible_index, shelf_view_->last_visible_index());
}
// The overflow button is now visible. Check that the last visible index is
// one less than before, because the overflow button replaces the last visible
// app.
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_EQ(last_visible_index_before_overflow - 1,
shelf_view_->last_visible_index());
// Now remove the last item we just added. That should get rid of the
// overflow button, and get back to the previous state.
RemoveByID(last_added_item_id);
EXPECT_EQ(0, shelf_view_->first_visible_index());
EXPECT_EQ(last_visible_index_before_overflow,
shelf_view_->last_visible_index());
// Adding another app should let the overflow button appear again.
AddApp();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_EQ(last_visible_index_before_overflow - 1,
shelf_view_->last_visible_index());
// And now adding more apps shouldn't change the last visible index.
const int how_many_more_apps = 5;
for (int i = 0; i < how_many_more_apps; ++i) {
AddApp();
EXPECT_EQ(last_visible_index_before_overflow - 1,
shelf_view_->last_visible_index());
}
} }
TEST_F(ShelfViewTest, ReplacingDelegateCancelsContextMenu) { TEST_F(ShelfViewTest, ReplacingDelegateCancelsContextMenu) {
...@@ -2781,286 +2060,32 @@ TEST_F(ShelfViewTest, ReplacingDelegateCancelsContextMenu) { ...@@ -2781,286 +2060,32 @@ TEST_F(ShelfViewTest, ReplacingDelegateCancelsContextMenu) {
EXPECT_FALSE(shelf_view_->IsShowingMenu()); EXPECT_FALSE(shelf_view_->IsShowingMenu());
} }
class OverflowBubbleViewTest : public ShelfViewNotScrollableTest { // Test class that tests both context and application menus.
class ShelfViewMenuTest : public ShelfViewTest,
public testing::WithParamInterface<bool> {
public: public:
OverflowBubbleViewTest() = default; ShelfViewMenuTest() = default;
~OverflowBubbleViewTest() override = default; ~ShelfViewMenuTest() override = default;
void SetUp() override {
ShelfViewNotScrollableTest::SetUp();
UpdateDisplay("300x600"); DISALLOW_COPY_AND_ASSIGN(ShelfViewMenuTest);
AddAppShortcutsUntilOverflow(); };
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
int GetMaxAccommodatedShelfNum() const { INSTANTIATE_TEST_SUITE_P(All, ShelfViewMenuTest, testing::Bool());
const int available_width_for_shortcuts =
GetPrimaryDisplay().work_area().width() - 2 * bubble_view_min_margin_ -
2 * end_padding_;
return std::ceil(available_width_for_shortcuts / unit()); // Tests that menu anchor points are aligned with the shelf button bounds.
} TEST_P(ShelfViewMenuTest, ShelfViewMenuAnchorPoint) {
const ShelfAppButton* shelf_button = GetButtonByID(AddApp());
const bool context_menu = GetParam();
EXPECT_EQ(ShelfAlignment::kBottom, GetPrimaryShelf()->alignment());
protected: // Test for bottom shelf.
static int unit() { EXPECT_EQ(
return ShelfConfig::Get()->button_size() + shelf_button->GetBoundsInScreen().y(),
ShelfConfig::Get()->button_spacing(); test_api_->GetMenuAnchorRect(*shelf_button, gfx::Point(), context_menu)
} .y());
const int bubble_view_min_margin_ = OverflowBubbleView::kMinimumMargin; // Test for left shelf.
const int end_padding_ = OverflowBubbleView::kEndPadding; GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
const int fading_zone_ = OverflowBubbleView::kFadingZone;
private:
DISALLOW_COPY_AND_ASSIGN(OverflowBubbleViewTest);
};
// Verifies that the arrow buttons of OverflowBubbleView work as expected.
TEST_F(OverflowBubbleViewTest, CheckOverflowBubbleViewArrowButton) {
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
const int button_size = ShelfConfig::Get()->button_size();
const gfx::Size shelf_icon_size(button_size, button_size);
const int arrow_button_size = OverflowBubbleView::GetArrowButtonSize();
// Add sufficient app icons to ensure that it needs to press the right arrow
// buttons twice to reach the end.
int current_item_count = bubble_view->shelf_view()->last_visible_index() -
bubble_view->shelf_view()->first_visible_index() + 1;
const int max_accommodated_shelf_num = GetMaxAccommodatedShelfNum();
int additional_item_num =
2 * max_accommodated_shelf_num - 1 - current_item_count;
while (additional_item_num) {
AddAppShortcut();
additional_item_num--;
}
const gfx::Rect overflow_bubble_bounds = bubble_view->GetBoundsInScreen();
views::View* left_arrow_button = bubble_view->left_arrow();
views::View* right_arrow_button = bubble_view->right_arrow();
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
// Verifies that the overflow bubble has the correct bounds. In detail:
// (1) The width of the overflow bubble should be the multiple of |unit|.
// (2) The overflow bubble's gap between left and right display edge should
// be the same.
EXPECT_EQ(
overflow_bubble_bounds.origin().x(),
GetPrimaryDisplay().bounds().right() - overflow_bubble_bounds.right());
const int available_width_for_bubble =
GetPrimaryDisplay().bounds().width() - 2 * bubble_view_min_margin_;
const int remainder = available_width_for_bubble % unit();
EXPECT_EQ(remainder / 2 + bubble_view_min_margin_,
overflow_bubble_bounds.origin().x());
EXPECT_EQ(0, overflow_bubble_bounds.width() % unit());
// Verifies the following things right after showing the overflow bubble view:
// (1) The layout strategy is SHOW_RIGHT_ARROW_BUTTON.
// (2) The right button is visible.
// (3) The left button is invisible.
// (4) The first visible shelf button has the correct origin.
EXPECT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_TRUE(right_arrow_button->GetVisible());
EXPECT_FALSE(left_arrow_button->GetVisible());
gfx::Rect expected_first_icon_bounds(overflow_bubble_bounds.origin(),
shelf_icon_size);
expected_first_icon_bounds.Offset(end_padding_, 0);
EXPECT_EQ(expected_first_icon_bounds,
test_for_overflow_view
.GetButton(bubble_view->shelf_view()->first_visible_index())
->GetBoundsInScreen());
// Taps at the right arrow button.
const gfx::Point right_button_center =
right_arrow_button->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->GestureTapAt(right_button_center);
// Verifies that the layout strategy is SHOW_BUTTONS.
EXPECT_EQ(OverflowBubbleView::SHOW_BUTTONS, bubble_view->layout_strategy());
// Verifies that the right button shows in the expected bounds.
EXPECT_TRUE(right_arrow_button->GetVisible());
gfx::Rect expected_right_arrow_bounds =
gfx::Rect(overflow_bubble_bounds.width() - button_size, 0, button_size,
button_size);
expected_right_arrow_bounds.ClampToCenteredSize(
gfx::Size(arrow_button_size, arrow_button_size));
EXPECT_EQ(expected_right_arrow_bounds, right_arrow_button->bounds());
// Verifies that the left button shows in the expected bounds.
EXPECT_TRUE(left_arrow_button->GetVisible());
gfx::Rect expected_left_arrow_bounds =
gfx::Rect(0, 0, button_size, button_size);
expected_left_arrow_bounds.ClampToCenteredSize(
gfx::Size(arrow_button_size, arrow_button_size));
EXPECT_EQ(expected_left_arrow_bounds, left_arrow_button->bounds());
// Verifies that the scroll offset of the overflow bubble should be expected.
const int expected_scroll_distance =
overflow_bubble_bounds.width() - 2 * unit();
EXPECT_EQ(expected_scroll_distance, bubble_view->scroll_offset().x());
// Tap at the right arrow button. Then check the following things:
// (1) The layout strategy is SHOW_LEFT_ARROW_BUTTON.
// (2) The left button is visible.
// (3) The right button is invisible.
// (4) The last visible shelf button has the expected bounds in screen.
GetEventGenerator()->GestureTapAt(right_button_center);
EXPECT_EQ(OverflowBubbleView::SHOW_LEFT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_FALSE(right_arrow_button->GetVisible());
EXPECT_TRUE(left_arrow_button->GetVisible());
gfx::Rect expected_last_icon_bounds(overflow_bubble_bounds.top_right(),
shelf_icon_size);
expected_last_icon_bounds.Offset(-button_size - end_padding_, 0);
EXPECT_EQ(expected_last_icon_bounds,
test_for_overflow_view
.GetButton(bubble_view->shelf_view()->last_visible_index())
->GetBoundsInScreen());
// Tap at the left arrow button twice. Check the following things:
// (1) The layout strategy is SHOW_RIGHT_ARROW_BUTTON.
// (2) The right button is visible.
// (3) The left button is invisible.
const gfx::Point left_button_center =
left_arrow_button->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->GestureTapAt(left_button_center);
GetEventGenerator()->GestureTapAt(left_button_center);
EXPECT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
EXPECT_TRUE(right_arrow_button->GetVisible());
EXPECT_FALSE(left_arrow_button->GetVisible());
}
// Verifies that the overflow bubble view handles the gesture events correctly.
TEST_F(OverflowBubbleViewTest, CheckGestureDraggingOverflowBubbleView) {
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
// Calculates the start point of the gesture drag event. Ensures that the
// start point is not within the bounds of any shelf icon.
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->bubble_view()->shelf_view());
const gfx::Rect first_icon_bounds =
test_for_overflow_view
.GetButton(bubble_view->shelf_view()->first_visible_index())
->GetBoundsInScreen();
gfx::Point gesture_drag_point = first_icon_bounds.right_center();
gesture_drag_point.Offset(1, 0);
// Verifies that gesture dragging is disabled when no arrow button shows.
ASSERT_EQ(OverflowBubbleView::NOT_SHOW_ARROW_BUTTONS,
bubble_view->layout_strategy());
gfx::Point gesture_end_point = gesture_drag_point;
gesture_end_point.Offset(-ShelfConfig::Get()->button_size(), 0);
GetEventGenerator()->GestureScrollSequence(
gesture_drag_point, gesture_end_point,
base::TimeDelta::FromMilliseconds(100), 5);
EXPECT_EQ(0, bubble_view->scroll_offset().x());
// Adds enough shelf icons to show the right arrow button.
int max_accommodated_shelf_num = GetMaxAccommodatedShelfNum();
while (max_accommodated_shelf_num) {
AddAppShortcut();
max_accommodated_shelf_num--;
}
ASSERT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
// Verifies that the small gesutre offset will not scroll the overflow bubble.
gesture_end_point = gesture_drag_point;
gesture_end_point.Offset(-10, 0);
GetEventGenerator()->GestureScrollSequence(
gesture_drag_point, gesture_end_point,
base::TimeDelta::FromMilliseconds(100), 1);
EXPECT_EQ(0, bubble_view->scroll_offset().x());
// Verifies that the large gesture offset will scroll the overflow bubble. The
// scroll offset is adjusted to fully show all of shelf icons.
gesture_end_point = gesture_drag_point;
gesture_end_point.Offset(-ShelfConfig::Get()->button_size(), 0);
GetEventGenerator()->GestureScrollSequence(
gesture_drag_point, gesture_end_point,
base::TimeDelta::FromMilliseconds(100), 1);
EXPECT_EQ(unit(), bubble_view->scroll_offset().x());
}
// Verifies that the leftmost/rightmost shelf icon has correct fading in/out
// behavior when scrolling the overflow bubble.
TEST_F(OverflowBubbleViewTest, CheckFadingBehaviorOfOverflowBubbleView) {
const int max_accommodated_shelf_num = GetMaxAccommodatedShelfNum();
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
views::ViewModel* shelf_view_model = bubble_view->shelf_view()->view_model();
const int base_index = bubble_view->shelf_view()->first_visible_index();
// Add enough app shortcuts to the shelf to ensure that the right arrow button
// shows.
for (int i = 0; i < max_accommodated_shelf_num; i++)
AddAppShortcut();
ASSERT_EQ(OverflowBubbleView::SHOW_RIGHT_ARROW_BUTTON,
bubble_view->layout_strategy());
// Verifies that at the beginning, the first/last visible index of the
// overflow bubble is correct. Note that the last visible index should be
// |base_index| + |max_accommodated_shelf_num| - 2, because one place is
// occupied by the arrow button.
EXPECT_EQ(base_index, bubble_view->GetFirstVisibleIndex());
EXPECT_EQ(base_index + max_accommodated_shelf_num - 2,
bubble_view->GetLastVisibleIndex());
// Scroll the overflow bubble by half of |fading_zone_|.
bubble_view->ScrollByXOffset(fading_zone_ / 2, false);
ASSERT_EQ(OverflowBubbleView::SHOW_BUTTONS, bubble_view->layout_strategy());
// Verifies that the first visible index increases by 1 because the left arrow
// button shows. The app short referred by the first visible index has the
// correct opacity.
EXPECT_EQ(base_index + 1, bubble_view->GetFirstVisibleIndex());
views::View* leftmost_view =
shelf_view_model->view_at(bubble_view->GetFirstVisibleIndex());
EXPECT_EQ(0.5f, leftmost_view->layer()->opacity());
// Verifies that the last visible index is expected. Note that we need to
// check the opacity of the app shortcut whose index is |last_visible_index| +
// 1. See OverflowBubbleView::UpdateOpacityOfEdgeIcons for more details.
EXPECT_EQ(base_index + max_accommodated_shelf_num - 2,
bubble_view->GetLastVisibleIndex());
ASSERT_LT(bubble_view->GetLastVisibleIndex() + 1,
shelf_view_model->view_size());
views::View* rightmost_view =
shelf_view_model->view_at(bubble_view->GetLastVisibleIndex() + 1);
EXPECT_EQ(0.f, rightmost_view->layer()->opacity());
}
// Test class that tests both context and application menus.
class ShelfViewMenuTest : public ShelfViewTest,
public testing::WithParamInterface<bool> {
public:
ShelfViewMenuTest() = default;
~ShelfViewMenuTest() override = default;
DISALLOW_COPY_AND_ASSIGN(ShelfViewMenuTest);
};
INSTANTIATE_TEST_SUITE_P(All, ShelfViewMenuTest, testing::Bool());
// Tests that menu anchor points are aligned with the shelf button bounds.
TEST_P(ShelfViewMenuTest, ShelfViewMenuAnchorPoint) {
const ShelfAppButton* shelf_button = GetButtonByID(AddApp());
const bool context_menu = GetParam();
EXPECT_EQ(ShelfAlignment::kBottom, GetPrimaryShelf()->alignment());
// Test for bottom shelf.
EXPECT_EQ(
shelf_button->GetBoundsInScreen().y(),
test_api_->GetMenuAnchorRect(*shelf_button, gfx::Point(), context_menu)
.y());
// Test for left shelf.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
EXPECT_EQ( EXPECT_EQ(
shelf_button->GetBoundsInScreen().x(), shelf_button->GetBoundsInScreen().x(),
...@@ -3194,18 +2219,6 @@ TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) { ...@@ -3194,18 +2219,6 @@ TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
test_api_->RunMessageLoopUntilAnimationsDone(); test_api_->RunMessageLoopUntilAnimationsDone();
EXPECT_FALSE(shelf_view_->GetOverflowButton()->GetVisible()); EXPECT_FALSE(shelf_view_->GetOverflowButton()->GetVisible());
CheckAllItemsAreInBounds(); CheckAllItemsAreInBounds();
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
// Same for overflow case.
while (!shelf_view_->GetOverflowButton()->GetVisible()) {
AddAppShortcut();
}
test_api_->RunMessageLoopUntilAnimationsDone();
CheckAllItemsAreInBounds();
} }
INSTANTIATE_TEST_SUITE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); INSTANTIATE_TEST_SUITE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
...@@ -3735,457 +2748,6 @@ TEST_F(ShelfViewInkDropTest, DismissingMenuWithDoubleClickDoesntShowInkDrop) { ...@@ -3735,457 +2748,6 @@ TEST_F(ShelfViewInkDropTest, DismissingMenuWithDoubleClickDoesntShowInkDrop) {
browser_button_ink_drop_->GetTargetInkDropState()); browser_button_ink_drop_->GetTargetInkDropState());
} }
// Test fixture for testing material design ink drop on overflow button.
class OverflowButtonInkDropTest : public ShelfViewNotScrollableTest {
public:
OverflowButtonInkDropTest() = default;
~OverflowButtonInkDropTest() override = default;
void SetUp() override {
ShelfViewNotScrollableTest::SetUp();
overflow_button_ = shelf_view_->GetOverflowButton();
auto overflow_button_ink_drop =
std::make_unique<InkDropSpy>(std::make_unique<views::InkDropImpl>(
overflow_button_, overflow_button_->size()));
overflow_button_ink_drop_ = overflow_button_ink_drop.get();
views::test::InkDropHostViewTestApi(overflow_button_)
.SetInkDrop(std::move(overflow_button_ink_drop));
AddAppShortcutsUntilOverflow();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
protected:
gfx::Point GetScreenPointInsideOverflowButton() const {
return overflow_button_->GetBoundsInScreen().CenterPoint();
}
gfx::Point GetScreenPointOutsideOverflowButton() const {
gfx::Point point = GetScreenPointInsideOverflowButton();
point.Offset(overflow_button_->width(), 0);
return point;
}
OverflowButton* overflow_button_ = nullptr;
InkDropSpy* overflow_button_ink_drop_ = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(OverflowButtonInkDropTest);
};
// Tests ink drop state transitions for the overflow button when the overflow
// bubble is shown or hidden.
TEST_F(OverflowButtonInkDropTest, OnOverflowBubbleShowHide) {
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTIVATED));
test_api_->HideOverflowBubble();
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::DEACTIVATED));
}
// Tests ink drop state transitions for the overflow button when the user
// clicks on it.
TEST_F(OverflowButtonInkDropTest, MouseActivate) {
ui::test::EventGenerator* generator = GetEventGenerator();
gfx::Point mouse_location = GetScreenPointInsideOverflowButton();
generator->MoveMouseTo(mouse_location);
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTIVATED));
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user
// presses left mouse button on it and drags it out of the button bounds.
TEST_F(OverflowButtonInkDropTest, MouseDragOut) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->MoveMouseTo(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::HIDDEN));
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user
// presses left mouse button on it and drags it out of the button bounds and
// back.
TEST_F(OverflowButtonInkDropTest, MouseDragOutAndBack) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->MoveMouseTo(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::HIDDEN));
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTIVATED));
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user
// right clicks on the button to show the context menu.
TEST_F(OverflowButtonInkDropTest, MouseContextMenu) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressRightButton();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseRightButton();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user taps
// on it.
TEST_F(OverflowButtonInkDropTest, TouchActivate) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTIVATED));
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user taps
// down on it and drags it out of the button bounds.
TEST_F(OverflowButtonInkDropTest, TouchDragOut) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->MoveTouch(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::HIDDEN));
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when the user taps
// down on it and drags it out of the button bounds and back.
TEST_F(OverflowButtonInkDropTest, TouchDragOutAndBack) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTION_PENDING,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTION_PENDING));
generator->MoveTouch(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::HIDDEN));
generator->MoveTouch(GetScreenPointInsideOverflowButton());
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Test fixture to run overflow button tests for LTR and RTL directions.
class OverflowButtonTextDirectionTest
: public OverflowButtonInkDropTest,
public testing::WithParamInterface<bool> {
public:
OverflowButtonTextDirectionTest() : scoped_locale_(GetParam() ? "he" : "") {}
~OverflowButtonTextDirectionTest() override = default;
private:
// Restores locale to the default when destructor is called.
base::test::ScopedRestoreICUDefaultLocale scoped_locale_;
DISALLOW_COPY_AND_ASSIGN(OverflowButtonTextDirectionTest);
};
INSTANTIATE_TEST_SUITE_P(
All,
OverflowButtonTextDirectionTest,
testing::Bool());
// Test fixture for testing material design ink drop on overflow button when
// it is active.
class OverflowButtonActiveInkDropTest : public OverflowButtonInkDropTest {
public:
OverflowButtonActiveInkDropTest() = default;
~OverflowButtonActiveInkDropTest() override = default;
void SetUp() override {
OverflowButtonInkDropTest::SetUp();
test_api_->ShowOverflowBubble();
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::ACTIVATED));
}
private:
DISALLOW_COPY_AND_ASSIGN(OverflowButtonActiveInkDropTest);
};
// Tests ink drop state transitions for the overflow button when it is active
// and the user clicks on it.
TEST_F(OverflowButtonActiveInkDropTest, MouseDeactivate) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::DEACTIVATED));
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when it is active
// and the user presses left mouse button on it and drags it out of the button
// bounds.
TEST_F(OverflowButtonActiveInkDropTest, MouseDragOut) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveMouseTo(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when it is active
// and the user presses left mouse button on it and drags it out of the button
// bounds and back.
TEST_F(OverflowButtonActiveInkDropTest, MouseDragOutAndBack) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
generator->PressLeftButton();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveMouseTo(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveMouseTo(GetScreenPointInsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseLeftButton();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::DEACTIVATED));
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when it is active
// and the user taps on it.
TEST_F(OverflowButtonActiveInkDropTest, TouchDeactivate) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::HIDDEN,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
ElementsAre(views::InkDropState::DEACTIVATED));
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when it is active
// and the user taps down on it and drags it out of the button bounds.
TEST_F(OverflowButtonActiveInkDropTest, TouchDragOut) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveTouch(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Tests ink drop state transitions for the overflow button when it is active
// and the user taps down on it and drags it out of the button bounds and
// back.
TEST_F(OverflowButtonActiveInkDropTest, TouchDragOutAndBack) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(GetScreenPointInsideOverflowButton());
generator->PressTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveTouch(GetScreenPointOutsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->MoveTouch(GetScreenPointInsideOverflowButton());
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
generator->ReleaseTouch();
EXPECT_EQ(views::InkDropState::ACTIVATED,
overflow_button_ink_drop_->GetTargetInkDropState());
EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
IsEmpty());
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
class ShelfViewFocusTest : public ShelfViewTest { class ShelfViewFocusTest : public ShelfViewTest {
public: public:
ShelfViewFocusTest() = default; ShelfViewFocusTest() = default;
...@@ -4275,21 +2837,6 @@ TEST_F(ShelfViewFocusTest, BackwardCycling) { ...@@ -4275,21 +2837,6 @@ TEST_F(ShelfViewFocusTest, BackwardCycling) {
EXPECT_TRUE(test_api_->GetViewAt(1)->HasFocus()); EXPECT_TRUE(test_api_->GetViewAt(1)->HasFocus());
} }
// Verify that the overflow bubble does not activate when it is opened.
TEST_F(ShelfViewFocusTest, OverflowNotActivatedWhenOpened) {
// No overflow bubble when scrollable shelf enabled.
// TODO(https://crbug.com/1002576): revisit when scrollable shelf is launched.
if (chromeos::switches::ShouldShowScrollableShelf())
return;
std::unique_ptr<aura::Window> window = CreateTestWindow();
wm::ActivateWindow(window.get());
AddAppShortcutsUntilOverflow();
test_api_->ShowOverflowBubble();
EXPECT_TRUE(wm::IsActiveWindow(window.get()));
}
// Verifies that focus moves as expected between the shelf and the status area. // Verifies that focus moves as expected between the shelf and the status area.
TEST_F(ShelfViewFocusTest, FocusCyclingBetweenShelfAndStatusWidget) { TEST_F(ShelfViewFocusTest, FocusCyclingBetweenShelfAndStatusWidget) {
// The first element of the shelf (the home button) is focused at start. // The first element of the shelf (the home button) is focused at start.
...@@ -4396,237 +2943,4 @@ TEST_F(ShelfViewFocusWithNoShelfNavigationTest, ...@@ -4396,237 +2943,4 @@ TEST_F(ShelfViewFocusWithNoShelfNavigationTest,
ExpectFocused(status_area_); ExpectFocused(status_area_);
} }
// TODO(https://crbug.com/1009638): remove when scrollable shelf is launched.
class ShelfViewOverflowFocusTest : public ShelfViewFocusTest {
public:
ShelfViewOverflowFocusTest() = default;
~ShelfViewOverflowFocusTest() override = default;
// AshTestBase:
void SetUp() override {
scoped_feature_list_.InitWithFeatures({},
{chromeos::features::kShelfScrollable,
chromeos::features::kShelfHotseat});
ShelfViewFocusTest::SetUp();
// Add app shortcuts until the overflow button is visible. At this point
// there will be two items on the overflow shelf.
AddAppShortcutsUntilOverflow();
// Add two more shortcuts for a total of four items on the overflow shelf.
AddAppShortcut();
AddAppShortcut();
items_ = test_api_->GetButtonCount();
last_item_on_main_shelf_index_ = shelf_view_->last_visible_index();
}
// Opens the overflow bubble. Focuses the home button for testing purposes.
void OpenOverflow() {
test_api_->ShowOverflowBubble();
overflow_shelf_test_api_ = std::make_unique<ShelfViewTestAPI>(
shelf_view_->overflow_bubble()->bubble_view()->shelf_view());
// Focus the home button.
Shelf* shelf = Shelf::ForWindow(Shell::GetPrimaryRootWindow());
shelf->shelf_focus_cycler()->FocusNavigation(false /* last_element */);
}
protected:
int items_ = 0;
int last_item_on_main_shelf_index_ = 0;
std::unique_ptr<ShelfViewTestAPI> overflow_shelf_test_api_;
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ShelfViewOverflowFocusTest);
};
// Tests that the overflow button is visible and that not all the items are
// visible on the main shelf.
TEST_F(ShelfViewOverflowFocusTest, Basic) {
EXPECT_TRUE(shelf_view_->GetOverflowButton()->GetVisible());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
EXPECT_EQ(last_item_on_main_shelf_index_, items_ - 5);
EXPECT_TRUE(GetPrimaryShelf()->navigation_widget()->IsActive());
EXPECT_TRUE(shelf_view_->shelf_widget()
->navigation_widget()
->GetHomeButton()
->HasFocus());
}
TEST_F(ShelfViewOverflowFocusTest, OpenOverflow) {
OpenOverflow();
ASSERT_TRUE(overflow_shelf_test_api_);
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
EXPECT_TRUE(shelf_view_->shelf_widget()
->navigation_widget()
->GetHomeButton()
->HasFocus());
}
// Tests that when cycling through the items with tab, the items in the overflow
// shelf are ignored because it is not visible.
TEST_F(ShelfViewOverflowFocusTest, ForwardCycling) {
// Focus the last visible item on the shelf.
Shell::Get()->focus_cycler()->FocusWidget(
GetPrimaryShelf()->hotseat_widget());
shelf_view_->shelf_widget()
->hotseat_widget()
->GetFocusManager()
->SetFocusedView(test_api_->GetViewAt(last_item_on_main_shelf_index_));
EXPECT_TRUE(test_api_->GetViewAt(last_item_on_main_shelf_index_)->HasFocus());
// Focus the overflow button.
DoTab();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
}
// Tests that when cycling through the items with shift tab, the items in the
// overflow shelf are ignored because it is not visible.
TEST_F(ShelfViewOverflowFocusTest, BackwardCycling) {
while (!shelf_view_->GetOverflowButton()->HasFocus())
DoTab();
DoShiftTab();
EXPECT_TRUE(test_api_->GetViewAt(last_item_on_main_shelf_index_)->HasFocus());
}
// Tests that cycling through elements with tab works as expected when the
// overflow bubble is open.
TEST_F(ShelfViewOverflowFocusTest, ForwardCyclingWithBubbleOpen) {
OpenOverflow();
// Focus the last item on the main shelf.
Shell::Get()->focus_cycler()->FocusWidget(
GetPrimaryShelf()->hotseat_widget());
shelf_view_->shelf_widget()
->hotseat_widget()
->GetFocusManager()
->SetFocusedView(test_api_->GetViewAt(last_item_on_main_shelf_index_));
// Focus the overflow button.
DoTab();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
// Tests that after pressing tab once more, the overflow bubble widget now is
// active, and the first item on the overflow bubble shelf has focus.
DoTab();
EXPECT_TRUE(
test_api_->overflow_bubble()->bubble_view()->GetWidget()->IsActive());
const int first_index_overflow_shelf = last_item_on_main_shelf_index_ + 1;
EXPECT_TRUE(overflow_shelf_test_api_->GetViewAt(first_index_overflow_shelf)
->HasFocus());
}
// Tests that backwards cycling through elements with shift tab works as
// expected when the overflow bubble is open.
TEST_F(ShelfViewOverflowFocusTest, BackwardCyclingWithBubbleOpen) {
OpenOverflow();
// Focus the first item on the overflow shelf.
while (!test_api_->overflow_bubble()->bubble_view()->GetWidget()->IsActive())
DoTab();
EXPECT_FALSE(GetPrimaryShelf()->hotseat_widget()->IsActive());
EXPECT_FALSE(shelf_view_->GetOverflowButton()->HasFocus());
// Tests that after pressing shift tab once, the main shelf is active and
// the overflow button has focus.
DoShiftTab();
EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive());
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
// One more shift tab and the last item on the main shelf has focus.
DoShiftTab();
EXPECT_TRUE(test_api_->GetViewAt(last_item_on_main_shelf_index_)->HasFocus());
}
// Tests that the keyboard focus remains on the overflow button when toggling
// the overflow bubble, so that the bubble can be toggled repeatedly without
// resetting with keyboard focus back to the first subview of the shelf.
TEST_F(ShelfViewOverflowFocusTest, ToggleBubbleWithKeyboard) {
GetPrimaryShelf()->shelf_focus_cycler()->FocusShelf(false /* last_element */);
EXPECT_FALSE(shelf_view_->GetOverflowButton()->HasFocus());
// Focus the last item on the main shelf.
shelf_view_->shelf_widget()
->hotseat_widget()
->GetFocusManager()
->SetFocusedView(test_api_->GetViewAt(last_item_on_main_shelf_index_));
// Focus the overflow button.
DoTab();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
DoEnter();
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
DoEnter();
EXPECT_FALSE(shelf_view_->IsShowingOverflowBubble());
DoEnter();
EXPECT_TRUE(shelf_view_->IsShowingOverflowBubble());
}
// Verifies that focus moves as expected between the shelf and the status area
// when the overflow bubble is showing.
TEST_F(ShelfViewOverflowFocusTest, FocusCyclingBetweenShelfAndStatusWidget) {
OpenOverflow();
const int first_index_overflow_shelf = last_item_on_main_shelf_index_ + 1;
// We start with the home button focused. Shift-tab should focus the status
// area.
DoShiftTab();
ExpectNotFocused(navigation_view_);
ExpectNotFocused(shelf_view_);
ExpectFocused(status_area_);
// Focus the shelf again.
DoTab();
ExpectFocused(navigation_view_);
EXPECT_TRUE(shelf_view_->shelf_widget()
->navigation_widget()
->GetHomeButton()
->HasFocus());
ExpectNotFocused(shelf_view_);
ExpectNotFocused(status_area_);
// Now advance to the last item on the main shelf.
while (!test_api_->GetViewAt(last_item_on_main_shelf_index_)->HasFocus())
DoTab();
ExpectNotFocused(status_area_);
// Focus the overflow button
DoTab();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
// Tab into the overflow bubble.
DoTab();
EXPECT_TRUE(overflow_shelf_test_api_->GetViewAt(first_index_overflow_shelf)
->HasFocus());
// Back onto the overflow button itself.
DoShiftTab();
EXPECT_TRUE(shelf_view_->GetOverflowButton()->HasFocus());
// Now advance until we get to the status area.
while (!status_area_->GetWidget()->IsActive())
DoTab();
// Go back once, we should be in the overflow bubble again.
DoShiftTab();
ExpectNotFocused(status_area_);
ExpectFocused(test_api_->overflow_bubble()->bubble_view());
// Go into the status area again.
DoTab();
ExpectFocused(status_area_);
// Now advance until the status area isn't focused anymore.
while (status_area_->GetWidget()->IsActive())
DoTab();
// This should have brought focus to the home button.
EXPECT_TRUE(shelf_view_->shelf_widget()
->navigation_widget()
->GetHomeButton()
->HasFocus());
}
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment