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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5304cb1ddab43f990a35aae6a59207f4039b4fbb |
| --- /dev/null |
| +++ b/ash/launcher/launcher_view_unittest.cc |
| @@ -0,0 +1,163 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/launcher/launcher_button.h" |
| +#include "ash/launcher/launcher_model.h" |
| +#include "ash/launcher/launcher_view.h" |
|
sky
2012/04/23 20:47:25
launcher_view should be the first include (test fi
xiyuan
2012/04/23 21:01:21
Done.
|
| +#include "ash/test/launcher_view_test_api.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "ui/aura/test/aura_test_base.h" |
| + |
| +namespace ash { |
| +namespace test { |
| + |
| +class LauncherViewTest : public aura::test::AuraTestBase { |
| + public: |
| + LauncherViewTest() {} |
| + virtual ~LauncherViewTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + aura::test::AuraTestBase::SetUp(); |
| + |
| + model_.reset(new LauncherModel); |
| + |
| + launcher_view_.reset(new internal::LauncherView(model_.get(), NULL)); |
| + launcher_view_->Init(); |
| + // The bounds should be big enough for 4 buttons + overflow chevron. |
| + launcher_view_->SetBounds(0, 0, 500, 50); |
| + |
| + test_api_.reset(new LauncherViewTestAPI(launcher_view_.get())); |
| + test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| + } |
| + |
| + protected: |
| + LauncherID AddAppShortcut() { |
| + LauncherItem item; |
| + item.type = TYPE_APP_SHORTCUT; |
| + item.status = STATUS_CLOSED; |
| + |
| + int id = model_->next_id(); |
| + model_->Add(item); |
| + test_api_->RunMessageLoopUntilAnimationsDone(); |
| + return id; |
| + } |
| + |
| + LauncherID AddTabbedBrowser() { |
| + LauncherItem item; |
| + item.type = TYPE_TABBED; |
| + item.status = STATUS_RUNNING; |
| + |
| + int id = model_->next_id(); |
| + model_->Add(item); |
| + test_api_->RunMessageLoopUntilAnimationsDone(); |
| + return id; |
| + } |
| + |
| + void RemoveByID(LauncherID id) { |
| + model_->RemoveItemAt(model_->ItemIndexByID(id)); |
| + test_api_->RunMessageLoopUntilAnimationsDone(); |
| + } |
| + |
| + internal::LauncherButton* GetButtonByID(LauncherID id) { |
| + int index = model_->ItemIndexByID(id); |
| + return test_api_->GetButton(index); |
| + } |
| + |
| + scoped_ptr<LauncherModel> model_; |
| + scoped_ptr<internal::LauncherView> launcher_view_; |
| + scoped_ptr<LauncherViewTestAPI> test_api_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); |
| +}; |
| + |
| +// Adds browser button until overflow and verifies that the last added browser |
| +// button is hidden. |
| +TEST_F(LauncherViewTest, AddBrowserUntilOverflow) { |
| + // All buttons should be visible. |
| + ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| + test_api_->GetButtonCount()); |
| + |
| + // Add tabbed browser until overflow. |
| + LauncherID last_added = AddTabbedBrowser(); |
| + while (!test_api_->IsOverflowButtonVisible()) { |
| + // Added button is visible after animation while in this loop. |
| + EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| + |
| + last_added = AddTabbedBrowser(); |
| + } |
| + |
| + // The last added button should be invisible. |
| + EXPECT_FALSE(GetButtonByID(last_added)->visible()); |
| +} |
| + |
| +// Adds one browser button then adds app shortcut until overflow. Verifies that |
| +// the browser button gets hidden on overflow and last added app shortcut is |
| +// still visible. |
| +TEST_F(LauncherViewTest, 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. |
| + 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(); |
| + } |
| + |
| + // The last added app short button should be visible. |
| + EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| + // And the browser button is invisible. |
| + EXPECT_FALSE(GetButtonByID(browser_button_id)->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. |
| +TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { |
| + // All buttons should be visible. |
| + ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| + test_api_->GetButtonCount()); |
| + |
| + // Add tabbed browser until overflow. |
| + LauncherID first_added= AddTabbedBrowser(); |
| + LauncherID last_added = first_added; |
| + while (!test_api_->IsOverflowButtonVisible()) |
| + last_added = AddTabbedBrowser(); |
| + |
| + // Expect add more than 1 button. First added is visible and last is not. |
| + EXPECT_NE(first_added, last_added); |
| + EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
| + EXPECT_FALSE(GetButtonByID(last_added)->visible()); |
| + |
| + // Remove first added. |
| + RemoveByID(first_added); |
| + |
| + // Last added button becomes visible and overflow chevron is gone. |
| + EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| + EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
| +} |
| + |
| +// Verifies that remove last overflowed button should hide overflow chevron. |
| +TEST_F(LauncherViewTest, RemoveLastOverflowed) { |
| + // All buttons should be visible. |
| + ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| + test_api_->GetButtonCount()); |
| + |
| + // Add tabbed browser until overflow. |
| + LauncherID last_added= AddTabbedBrowser(); |
| + while (!test_api_->IsOverflowButtonVisible()) |
| + last_added = AddTabbedBrowser(); |
| + |
| + RemoveByID(last_added); |
| + EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
| +} |
| + |
| +} // namespace test |
| +} // namespace ash |