Index: ash/shelf/shelf_view_unittest.cc |
diff --git a/ash/shelf/shelf_view_unittest.cc b/ash/shelf/shelf_view_unittest.cc |
index 87fe1b9b512436aaae546e49c01e4b6c9be99c39..3b9956e24edf92ffd6ae19fc0fb3f82e66b68531 100644 |
--- a/ash/shelf/shelf_view_unittest.cc |
+++ b/ash/shelf/shelf_view_unittest.cc |
@@ -270,7 +270,8 @@ |
shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
// The bounds should be big enough for 4 buttons + overflow chevron. |
- shelf_view_->SetBounds(0, 0, 500, kShelfSize); |
+ shelf_view_->SetBounds(0, 0, 500, |
+ internal::ShelfLayoutManager::GetPreferredShelfSize()); |
test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
@@ -581,6 +582,24 @@ |
DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); |
}; |
+class ShelfViewLegacyShelfLayoutTest : public ShelfViewTest { |
+ public: |
+ ShelfViewLegacyShelfLayoutTest() : ShelfViewTest() { |
+ browser_index_ = 0; |
+ } |
+ |
+ virtual ~ShelfViewLegacyShelfLayoutTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ ash::switches::kAshDisableAlternateShelfLayout); |
+ ShelfViewTest::SetUp(); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ShelfViewLegacyShelfLayoutTest); |
+}; |
+ |
class ScopedTextDirectionChange { |
public: |
ScopedTextDirectionChange(bool is_rtl) |
@@ -726,6 +745,33 @@ |
EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
} |
+TEST_F(ShelfViewLegacyShelfLayoutTest, |
+ AddAppShortcutWithBrowserButtonUntilOverflow) { |
+ // All buttons should be visible. |
+ ASSERT_EQ(test_api_->GetButtonCount(), |
+ test_api_->GetLastVisibleIndex() + 1); |
+ |
+ |
+ ShelfID browser_button_id = AddPlatformApp(); |
+ |
+ // Add app shortcut until overflow. |
+ int items_added = 0; |
+ ShelfID 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 platform app button is invisible. |
+ EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
+} |
+ |
TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) { |
// All buttons should be visible. |
ASSERT_EQ(test_api_->GetButtonCount(), |
@@ -754,6 +800,36 @@ |
EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
} |
+TEST_F(ShelfViewLegacyShelfLayoutTest, AddPanelHidesPlatformAppButton) { |
+ // All buttons should be visible. |
+ ASSERT_EQ(test_api_->GetButtonCount(), |
+ test_api_->GetLastVisibleIndex() + 1); |
+ |
+ // Add platform app button until overflow, remember last visible platform app |
+ // button. |
+ int items_added = 0; |
+ ShelfID first_added = AddPlatformApp(); |
+ EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
+ ShelfID last_visible = first_added; |
+ while (true) { |
+ ShelfID added = AddPlatformApp(); |
+ if (test_api_->IsOverflowButtonVisible()) { |
+ EXPECT_FALSE(GetButtonByID(added)->visible()); |
+ break; |
+ } |
+ last_visible = added; |
+ ++items_added; |
+ ASSERT_LT(items_added, 10000); |
+ } |
+ |
+ ShelfID panel = AddPanel(); |
+ EXPECT_TRUE(GetButtonByID(panel)->visible()); |
+ EXPECT_FALSE(GetButtonByID(last_visible)->visible()); |
+ |
+ RemoveByID(panel); |
+ EXPECT_TRUE(GetButtonByID(last_visible)->visible()); |
+} |
+ |
// When there are more panels then platform app buttons we should hide panels |
// rather than platform apps. |
TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) { |
@@ -937,6 +1013,72 @@ |
// Adding a shelf item at the end (i.e. a panel) canels drag and respects |
// the order. |
dragged_button = SimulateDrag(internal::ShelfButtonHost::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::ShelfButtonHost::MOUSE, |
+ false); |
+} |
+ |
+TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { |
+ internal::ShelfButtonHost* button_host = shelf_view_; |
+ |
+ std::vector<std::pair<ShelfID, 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::ShelfButtonHost::MOUSE, 0, 2); |
+ std::rotate(id_map.begin(), |
+ id_map.begin() + 1, |
+ id_map.begin() + 3); |
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
+ button_host->PointerReleasedOnButton(dragged_button, |
+ internal::ShelfButtonHost::MOUSE, |
+ false); |
+ EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); |
+ |
+ // Dragging changes model order. |
+ dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
+ std::rotate(id_map.begin(), |
+ id_map.begin() + 1, |
+ id_map.begin() + 3); |
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
+ |
+ // Cancelling the drag operation restores previous order. |
+ button_host->PointerReleasedOnButton(dragged_button, |
+ internal::ShelfButtonHost::MOUSE, |
+ true); |
+ std::rotate(id_map.begin(), |
+ id_map.begin() + 2, |
+ id_map.begin() + 3); |
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
+ |
+ // Deleting an item keeps the remaining intact. |
+ dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
+ model_->RemoveItemAt(1); |
+ id_map.erase(id_map.begin() + 1); |
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
+ button_host->PointerReleasedOnButton(dragged_button, |
+ internal::ShelfButtonHost::MOUSE, |
+ false); |
+ |
+ // Adding a shelf item cancels the drag and respects the order. |
+ dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
+ ShelfID new_id = AddAppShortcut(); |
+ id_map.insert(id_map.begin() + 5, |
+ std::make_pair(new_id, GetButtonByID(new_id))); |
+ ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
+ button_host->PointerReleasedOnButton(dragged_button, |
+ internal::ShelfButtonHost::MOUSE, |
+ false); |
+ |
+ // Adding a shelf item at the end (i.e. a panel) canels drag and respects |
+ // the order. |
+ dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
new_id = AddPanel(); |
id_map.insert(id_map.begin() + 7, |
std::make_pair(new_id, GetButtonByID(new_id))); |
@@ -1037,6 +1179,40 @@ |
ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); |
} |
+TEST_F(ShelfViewLegacyShelfLayoutTest, |
+ ShelfItemPositionReflectedOnStateChanged) { |
+ // All buttons should be visible. |
+ ASSERT_EQ(test_api_->GetButtonCount(), |
+ test_api_->GetLastVisibleIndex() + 1); |
+ |
+ // Add 2 items to the shelf. |
+ ShelfID item1_id = AddPlatformApp(); |
+ ShelfID item2_id = AddPlatformAppNoWait(); |
+ internal::ShelfButton* item1_button = GetButtonByID(item1_id); |
+ internal::ShelfButton* item2_button = GetButtonByID(item2_id); |
+ |
+ internal::ShelfButton::State state_mask = |
+ static_cast<internal::ShelfButton::State>( |
+ internal::ShelfButton::STATE_NORMAL | |
+ internal::ShelfButton::STATE_HOVERED | |
+ internal::ShelfButton::STATE_RUNNING | |
+ internal::ShelfButton::STATE_ACTIVE | |
+ internal::ShelfButton::STATE_ATTENTION | |
+ internal::ShelfButton::STATE_FOCUSED); |
+ |
+ // Clear the button states. |
+ item1_button->ClearState(state_mask); |
+ item2_button->ClearState(state_mask); |
+ |
+ // Since default alignment in tests is bottom, state is reflected in y-axis. |
+ ASSERT_EQ(item1_button->GetIconBounds().y(), |
+ item2_button->GetIconBounds().y()); |
+ item1_button->AddState(internal::ShelfButton::STATE_HOVERED); |
+ ASSERT_NE(item1_button->GetIconBounds().y(), |
+ item2_button->GetIconBounds().y()); |
+ item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); |
+} |
+ |
// Confirm that item status changes are reflected in the buttons |
// for platform apps. |
TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { |
@@ -1298,7 +1474,7 @@ |
// Resize shelf view with that animation running and stay overflown. |
gfx::Rect bounds = shelf_view_->bounds(); |
- bounds.set_width(bounds.width() - kShelfSize); |
+ bounds.set_width(bounds.width() - kShelfPreferredSize); |
shelf_view_->SetBoundsRect(bounds); |
ASSERT_TRUE(test_api_->IsOverflowButtonVisible()); |
@@ -1371,6 +1547,17 @@ |
test_for_overflow_view.GetPreferredSize().width()); |
} |
+// 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(ShelfViewLegacyShelfLayoutTest, CheckFittsLaw) { |
+ // All buttons should be visible. |
+ ASSERT_EQ(test_api_->GetButtonCount(), |
+ test_api_->GetLastVisibleIndex() + 1); |
+ gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); |
+ gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); |
+ EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); |
+} |
+ |
// Check the drag insertion bounds of scrolled overflow bubble. |
TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) { |
UpdateDisplay("400x300"); |
@@ -1437,7 +1624,8 @@ |
ShelfTestAPI(secondary_shelf).shelf_view(); |
// The bounds should be big enough for 4 buttons + overflow chevron. |
- shelf_view_for_secondary->SetBounds(0, 0, 500, kShelfSize); |
+ shelf_view_for_secondary->SetBounds(0, 0, 500, |
+ internal::ShelfLayoutManager::GetPreferredShelfSize()); |
ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); |
// Speeds up animation for test. |