Chromium Code Reviews| 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..bb0049bf791f0fe68619e8dd0931ac34a38e867d 100644 |
| --- a/ash/launcher/launcher_view_unittest.cc |
| +++ b/ash/launcher/launcher_view_unittest.cc |
| @@ -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(1, browser_shortcut); |
| test_api_->RunMessageLoopUntilAnimationsDone(); |
| return id; |
| } |
| @@ -371,7 +371,7 @@ class LauncherViewTest : public AshTestBase { |
| return button; |
| } |
| - void SetupForDragTest( |
| + virtual void SetupForDragTest( |
| std::vector<std::pair<LauncherID, views::View*> >* id_map) { |
| // Initialize |id_map| with the automatically-created launcher buttons. |
| for (size_t i = 0; i < model_->items().size(); ++i) { |
| @@ -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 + 2), |
| std::make_pair(id, GetButtonByID(id))); |
| } |
| ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
| @@ -408,6 +408,52 @@ class LauncherViewTest : public AshTestBase { |
| DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); |
| }; |
| +class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { |
| + public: |
| + LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {} |
|
James Cook
2013/08/22 00:19:12
see below, but this could do something like:
{
Harry McCleave
2013/08/27 00:37:00
Done.
|
| + |
| + virtual void SetUp() OVERRIDE { |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + ash::switches::kAshDisableAlternateShelfLayout); |
| + LauncherViewTest::SetUp(); |
| + } |
| + |
| + protected: |
| + virtual LauncherID AddBrowserShortcut() OVERRIDE { |
| + LauncherItem browser_shortcut; |
| + browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
| + browser_shortcut.is_incognito = false; |
| + |
| + LauncherID id = model_->next_id(); |
| + model_->AddAt(0, browser_shortcut); |
| + test_api_->RunMessageLoopUntilAnimationsDone(); |
| + return id; |
| + } |
| + |
| + virtual void SetupForDragTest( |
|
James Cook
2013/08/22 00:19:12
This feels to me like it doesn't need to be duplic
Harry McCleave
2013/08/27 00:37:00
Done.
|
| + std::vector<std::pair<LauncherID, views::View*> >* id_map) OVERRIDE { |
| + // Initialize |id_map| with the automatically-created launcher buttons. |
| + for (size_t i = 0; i < model_->items().size(); ++i) { |
| + internal::LauncherButton* button = test_api_->GetButton(i); |
| + id_map->push_back(std::make_pair(model_->items()[i].id, button)); |
| + } |
| + ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
| + |
| + // 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), |
| + std::make_pair(id, GetButtonByID(id))); |
| + } |
| + ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LauncherViewLegacyShelfLayoutTest); |
| +}; |
| + |
| class LauncherViewTextDirectionTest |
| : public LauncherViewTest, |
| public testing::WithParamInterface<bool> { |
| @@ -540,6 +586,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 +623,33 @@ 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 until overflow, remember last visible tabbed browser. |
| + 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 +710,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 +839,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) canels drag and respects |
| + // 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); |
| @@ -774,6 +975,53 @@ 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); |
| + (void)button_host;(void)dragged_button_mouse;(void)dragged_button_touch; |
| + // 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 +1073,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 +1128,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 +1159,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 +1333,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 +1391,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()); |