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

Unified Diff: ash/launcher/launcher_view_unittest.cc

Issue 22793011: ash:Shelf - Enable Alternate Shelf and Side Shelf by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits + extra test case Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/launcher/launcher_view.cc ('k') | ash/root_window_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/launcher/launcher_view_unittest.cc
diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc
index 77316553cf1a6bf6b3b3237826e841239c1ff352..fb81d65102c3025b9769914fcc61131d10c501a9 100644
--- a/ash/launcher/launcher_view_unittest.cc
+++ b/ash/launcher/launcher_view_unittest.cc
@@ -195,7 +195,7 @@ TEST_F(LauncherViewIconObserverTest, BoundsChanged) {
class LauncherViewTest : public AshTestBase {
public:
- LauncherViewTest() : model_(NULL), launcher_view_(NULL) {}
+ LauncherViewTest() : model_(NULL), launcher_view_(NULL), browser_index_(1) {}
virtual ~LauncherViewTest() {}
virtual void SetUp() OVERRIDE {
@@ -213,7 +213,7 @@ class LauncherViewTest : public AshTestBase {
// Add browser shortcut launcher item at index 0 for test.
AddBrowserShortcut();
- }
+ }
virtual void TearDown() OVERRIDE {
test_api_.reset();
@@ -221,13 +221,13 @@ class LauncherViewTest : public AshTestBase {
}
protected:
- LauncherID AddBrowserShortcut() {
+ virtual LauncherID AddBrowserShortcut() {
LauncherItem browser_shortcut;
browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
browser_shortcut.is_incognito = false;
LauncherID id = model_->next_id();
- model_->AddAt(0, browser_shortcut);
+ model_->AddAt(browser_index_, browser_shortcut);
test_api_->RunMessageLoopUntilAnimationsDone();
return id;
}
@@ -383,9 +383,9 @@ class LauncherViewTest : public AshTestBase {
// Add 5 app launcher buttons for testing.
for (int i = 0; i < 5; ++i) {
LauncherID id = AddAppShortcut();
- // browser shortcut is located at index 0. So we should start to add app
- // shortcut at index 1.
- id_map->insert(id_map->begin() + (i + 1),
+ // App Icon is located at index 0, and browser shortcut is located at
+ // index 1. So we should start to add app shortcuts at index 2.
+ id_map->insert(id_map->begin() + (i + browser_index_ + 1),
std::make_pair(id, GetButtonByID(id)));
}
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
@@ -401,6 +401,7 @@ class LauncherViewTest : public AshTestBase {
LauncherModel* model_;
internal::LauncherView* launcher_view_;
+ int browser_index_;
scoped_ptr<LauncherViewTestAPI> test_api_;
@@ -408,6 +409,24 @@ class LauncherViewTest : public AshTestBase {
DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
};
+class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest {
+ public:
+ LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {
+ browser_index_ = 0;
+ }
+
+ virtual ~LauncherViewLegacyShelfLayoutTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ ash::switches::kAshDisableAlternateShelfLayout);
+ LauncherViewTest::SetUp();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LauncherViewLegacyShelfLayoutTest);
+};
+
class LauncherViewTextDirectionTest
: public LauncherViewTest,
public testing::WithParamInterface<bool> {
@@ -540,6 +559,29 @@ TEST_F(LauncherViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) {
ASSERT_LT(items_added, 10000);
}
+ EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
+}
+
+TEST_F(LauncherViewLegacyShelfLayoutTest,
+ AddAppShortcutWithBrowserButtonUntilOverflow) {
+ // All buttons should be visible.
+ ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
+ test_api_->GetButtonCount());
+
+ LauncherID browser_button_id = AddTabbedBrowser();
+
+ // Add app shortcut until overflow.
+ int items_added = 0;
+ LauncherID last_added = AddAppShortcut();
+ while (!test_api_->IsOverflowButtonVisible()) {
+ // Added button is visible after animation while in this loop.
+ EXPECT_TRUE(GetButtonByID(last_added)->visible());
+
+ last_added = AddAppShortcut();
+ ++items_added;
+ ASSERT_LT(items_added, 10000);
+ }
+
// The last added app short button should be visible.
EXPECT_TRUE(GetButtonByID(last_added)->visible());
// And the browser button is invisible.
@@ -554,6 +596,34 @@ TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) {
int items_added = 0;
LauncherID first_added = AddTabbedBrowser();
EXPECT_TRUE(GetButtonByID(first_added)->visible());
+ while (true) {
+ LauncherID added = AddTabbedBrowser();
+ if (test_api_->IsOverflowButtonVisible()) {
+ EXPECT_FALSE(GetButtonByID(added)->visible());
+ RemoveByID(added);
+ break;
+ }
+ ++items_added;
+ ASSERT_LT(items_added, 10000);
+ }
+
+ EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
+ LauncherID panel = AddPanel();
+ EXPECT_TRUE(GetButtonByID(panel)->visible());
+ EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
+ RemoveByID(panel);
+ EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
+}
+
+TEST_F(LauncherViewLegacyShelfLayoutTest, AddPanelHidesTabbedBrowser) {
+ ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
+ test_api_->GetButtonCount());
+
+ // Add tabbed browser items until an overflow, remembering the last visible
+ // tabbed browser item.
+ int items_added = 0;
+ LauncherID first_added = AddTabbedBrowser();
+ EXPECT_TRUE(GetButtonByID(first_added)->visible());
LauncherID last_visible = first_added;
while (true) {
LauncherID added = AddTabbedBrowser();
@@ -614,6 +684,44 @@ TEST_F(LauncherViewTest, BrowserHidesExcessPanels) {
EXPECT_FALSE(GetButtonByID(browser)->visible());
}
+TEST_F(LauncherViewLegacyShelfLayoutTest, BrowserHidesExcessPanels) {
+ ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
+ test_api_->GetButtonCount());
+
+ // Add tabbed browser.
+ LauncherID browser = AddTabbedBrowser();
+ LauncherID first_panel = AddPanel();
+
+ EXPECT_TRUE(GetButtonByID(browser)->visible());
+ EXPECT_TRUE(GetButtonByID(first_panel)->visible());
+
+ // Add panels until there is an overflow.
+ LauncherID last_panel = first_panel;
+ int items_added = 0;
+ while (!test_api_->IsOverflowButtonVisible()) {
+ last_panel = AddPanel();
+ ++items_added;
+ ASSERT_LT(items_added, 10000);
+ }
+
+ // The first panel should now be hidden by the new browsers needing space.
+ EXPECT_FALSE(GetButtonByID(first_panel)->visible());
+ EXPECT_TRUE(GetButtonByID(last_panel)->visible());
+ EXPECT_TRUE(GetButtonByID(browser)->visible());
+
+ // Adding browsers should eventually begin to hide browsers. We will add
+ // browsers until either the last panel or browser is hidden.
+ items_added = 0;
+ while (GetButtonByID(browser)->visible() &&
+ GetButtonByID(last_panel)->visible()) {
+ browser = AddTabbedBrowser();
+ ++items_added;
+ ASSERT_LT(items_added, 10000);
+ }
+ EXPECT_TRUE(GetButtonByID(last_panel)->visible());
+ EXPECT_FALSE(GetButtonByID(browser)->visible());
+}
+
// Adds button until overflow then removes first added one. Verifies that
// the last added one changes from invisible to visible and overflow
// chevron is gone.
@@ -705,6 +813,73 @@ TEST_F(LauncherViewTest, ModelChangesWhileDragging) {
SetupForDragTest(&id_map);
// Dragging browser shortcut at index 0.
+ EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
+ views::View* dragged_button = SimulateDrag(
+ internal::LauncherButtonHost::MOUSE, 1, 3);
+ std::rotate(id_map.begin() + 1,
+ id_map.begin() + 2,
+ id_map.begin() + 4);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+ EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
+
+ // Dragging changes model order.
+ dragged_button = SimulateDrag(
+ internal::LauncherButtonHost::MOUSE, 1, 3);
+ std::rotate(id_map.begin() + 1,
+ id_map.begin() + 2,
+ id_map.begin() + 4);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ // Cancelling the drag operation restores previous order.
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ true);
+ std::rotate(id_map.begin() + 1,
+ id_map.begin() + 3,
+ id_map.begin() + 4);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ // Deleting an item keeps the remaining intact.
+ dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
+ model_->RemoveItemAt(1);
+ id_map.erase(id_map.begin() + 1);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+
+ // Adding a launcher item cancels the drag and respects the order.
+ dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
+ LauncherID new_id = AddAppShortcut();
+ id_map.insert(id_map.begin() + 6,
+ std::make_pair(new_id, GetButtonByID(new_id)));
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+
+ // Adding a launcher item at the end (i.e. a panel) cancels drag and respects
James Cook 2013/08/27 17:08:52 nit: one space before "cancels"
+ // the order.
+ dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
+ new_id = AddPanel();
+ id_map.insert(id_map.begin() + 7,
+ std::make_pair(new_id, GetButtonByID(new_id)));
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+}
+
+TEST_F(LauncherViewLegacyShelfLayoutTest, ModelChangesWhileDragging) {
+ internal::LauncherButtonHost* button_host = launcher_view_;
+
+ std::vector<std::pair<LauncherID, views::View*> > id_map;
+ SetupForDragTest(&id_map);
+
+ // Dragging browser shortcut at index 0.
EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
views::View* dragged_button = SimulateDrag(
internal::LauncherButtonHost::MOUSE, 0, 2);
@@ -753,7 +928,7 @@ TEST_F(LauncherViewTest, ModelChangesWhileDragging) {
internal::LauncherButtonHost::MOUSE,
false);
- // Adding a launcher item at the end (i.e. a panel) canels drag and respects
+ // Adding a launcher item at the end (i.e. a panel) cancels drag and respects
James Cook 2013/08/27 17:08:52 nit: one space before "cancels"
// the order.
dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2);
new_id = AddPanel();
@@ -774,6 +949,52 @@ TEST_F(LauncherViewTest, SimultaneousDrag) {
// Start a mouse drag.
views::View* dragged_button_mouse = SimulateDrag(
+ internal::LauncherButtonHost::MOUSE, 1, 3);
+ std::rotate(id_map.begin() + 1,
+ id_map.begin() + 2,
+ id_map.begin() + 4);
+
+ // Attempt a touch drag before the mouse drag finishes.
+ views::View* dragged_button_touch = SimulateDrag(
+ internal::LauncherButtonHost::TOUCH, 4, 2);
+ // Nothing changes since 2nd drag is ignored.
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ // Finish the mouse drag.
+ button_host->PointerReleasedOnButton(dragged_button_mouse,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ // Now start a touch drag.
+ dragged_button_touch = SimulateDrag(
+ internal::LauncherButtonHost::TOUCH, 4, 2);
+ std::rotate(id_map.begin() + 3,
+ id_map.begin() + 4,
+ id_map.begin() + 5);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ // And attempt a mouse drag before the touch drag finishes.
+ dragged_button_mouse = SimulateDrag(
+ internal::LauncherButtonHost::MOUSE, 1, 2);
+
+ // Nothing changes since 2nd drag is ignored.
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+
+ button_host->PointerReleasedOnButton(dragged_button_touch,
+ internal::LauncherButtonHost::TOUCH,
+ false);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+}
+
+TEST_F(LauncherViewLegacyShelfLayoutTest, SimultaneousDrag) {
+ internal::LauncherButtonHost* button_host = launcher_view_;
+
+ std::vector<std::pair<LauncherID, views::View*> > id_map;
+ SetupForDragTest(&id_map);
+
+ // Start a mouse drag.
+ views::View* dragged_button_mouse = SimulateDrag(
internal::LauncherButtonHost::MOUSE, 0, 2);
std::rotate(id_map.begin(),
id_map.begin() + 1,
@@ -825,6 +1046,29 @@ TEST_F(LauncherViewTest, ClickOneDragAnother) {
SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
// Dragging browser index at 0 should change the model order correctly.
+ EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
+ views::View* dragged_button = SimulateDrag(
+ internal::LauncherButtonHost::MOUSE, 1, 3);
+ std::rotate(id_map.begin() + 1,
+ id_map.begin() + 2,
+ id_map.begin() + 4);
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
+ button_host->PointerReleasedOnButton(dragged_button,
+ internal::LauncherButtonHost::MOUSE,
+ false);
+ EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
+}
+
+TEST_F(LauncherViewLegacyShelfLayoutTest, ClickOneDragAnother) {
+ internal::LauncherButtonHost* button_host = launcher_view_;
+
+ std::vector<std::pair<LauncherID, views::View*> > id_map;
+ SetupForDragTest(&id_map);
+
+ // A click on item 1 is simulated.
+ SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
+
+ // Dragging browser index at 0 should change the model order correctly.
EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
views::View* dragged_button = SimulateDrag(
internal::LauncherButtonHost::MOUSE, 0, 2);
@@ -857,7 +1101,8 @@ TEST_F(LauncherViewTest, LauncherItemStatus) {
ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state());
}
-TEST_F(LauncherViewTest, LauncherItemPositionReflectedOnStateChanged) {
+TEST_F(LauncherViewLegacyShelfLayoutTest,
+ LauncherItemPositionReflectedOnStateChanged) {
ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
test_api_->GetButtonCount());
@@ -887,19 +1132,6 @@ TEST_F(LauncherViewTest, LauncherItemPositionReflectedOnStateChanged) {
ASSERT_NE(item1_button->GetIconBounds().y(),
item2_button->GetIconBounds().y());
item1_button->ClearState(internal::LauncherButton::STATE_HOVERED);
-
- // Enable the alternate shelf layout.
- CommandLine::ForCurrentProcess()->AppendSwitch(
- ash::switches::kAshUseAlternateShelfLayout);
- launcher_view_->Layout();
-
- // Since default alignment in tests is bottom, state is reflected in y-axis.
- // In alternate shelf layout there is no visible hovered state.
- ASSERT_EQ(item1_button->GetIconBounds().y(),
- item2_button->GetIconBounds().y());
- item1_button->AddState(internal::LauncherButton::STATE_HOVERED);
- ASSERT_EQ(item1_button->GetIconBounds().y(),
- item2_button->GetIconBounds().y());
}
// Confirm that item status changes are reflected in the buttons
@@ -1074,13 +1306,13 @@ TEST_F(LauncherViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
// Move the mouse cursor slightly to the right of the item. The tooltip should
// stay open.
- generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
+ generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
// Make sure there is no delayed close.
RunAllPendingInMessageLoop();
EXPECT_TRUE(tooltip_manager->IsVisible());
// Move back - it should still stay open.
- generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
+ generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
// Make sure there is no delayed close.
RunAllPendingInMessageLoop();
EXPECT_TRUE(tooltip_manager->IsVisible());
@@ -1132,7 +1364,7 @@ TEST_F(LauncherViewTest, ResizeDuringOverflowAddAnimation) {
// Check that the first item in the list follows Fitt's law by including the
// first pixel and being therefore bigger then the others.
-TEST_F(LauncherViewTest, CheckFittsLaw) {
+TEST_F(LauncherViewLegacyShelfLayoutTest, CheckFittsLaw) {
// All buttons should be visible.
ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
test_api_->GetButtonCount());
« no previous file with comments | « ash/launcher/launcher_view.cc ('k') | ash/root_window_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698