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

Side by Side Diff: ash/launcher/launcher_view_unittest.cc

Issue 10068027: ash: Fix launcher icon overlaps with status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use last_visible_index_ part from 9808026 and add tests Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/launcher/launcher_button.h"
6 #include "ash/launcher/launcher_model.h"
7 #include "ash/launcher/launcher_view.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/aura/test/aura_test_base.h"
10
11 namespace ash {
12 namespace test {
13
14 class LauncherViewTest : public aura::test::AuraTestBase {
15 public:
16 LauncherViewTest() {}
17 virtual ~LauncherViewTest() {}
18
19 virtual void SetUp() OVERRIDE {
20 aura::test::AuraTestBase::SetUp();
21
22 model_.reset(new LauncherModel);
23
24 launcher_view_.reset(new internal::LauncherView(model_.get(), NULL));
25 launcher_view_->Init();
26 // The bounds should be big enough for 4 buttons + overflow chevron.
27 launcher_view_->SetBounds(0, 0, 500, 50);
28
29 test_api_.reset(new internal::LauncherView::TestAPI(launcher_view_.get()));
30 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
31 }
32
33 protected:
34 LauncherID AddAppShortcut() {
35 LauncherItem item;
36 item.type = TYPE_APP_SHORTCUT;
37 item.status = STATUS_CLOSED;
38
39 int id = model_->next_id();
40 model_->Add(item);
41 test_api_->RunMessageLoopUntilAnimationsDone();
42 return id;
43 }
44
45 LauncherID AddTabbedBrowser() {
46 LauncherItem item;
47 item.type = TYPE_TABBED;
48 item.status = STATUS_RUNNING;
49
50 int id = model_->next_id();
51 model_->Add(item);
52 test_api_->RunMessageLoopUntilAnimationsDone();
53 return id;
54 }
55
56 void RemoveByID(LauncherID id) {
57 model_->RemoveItemAt(model_->ItemIndexByID(id));
58 test_api_->RunMessageLoopUntilAnimationsDone();
59 }
60
61 internal::LauncherButton* GetButtonByID(LauncherID id) {
62 int index = model_->ItemIndexByID(id);
63 return test_api_->GetButton(index);
64 }
65
66 scoped_ptr<LauncherModel> model_;
67 scoped_ptr<internal::LauncherView> launcher_view_;
68 scoped_ptr<internal::LauncherView::TestAPI> test_api_;
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
72 };
73
74 // Adds browser button until overflow and verifies that the last added browser
75 // button is hidden.
76 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) {
77 // All buttons should be visible.
78 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
79 test_api_->GetButtonCount());
80
81 // Add tabbed browser until overflow.
82 LauncherID last_added = AddTabbedBrowser();
83 while (!test_api_->IsOverflowButtonVisible()) {
84 // Added button is visible after animation while in this loop.
85 EXPECT_TRUE(GetButtonByID(last_added)->visible());
86
87 last_added = AddTabbedBrowser();
88 }
89
90 // The last added button should be invisible.
91 EXPECT_FALSE(GetButtonByID(last_added)->visible());
92 }
93
94 // Adds one browser button then adds app shortcut until overflow. Verifies that
95 // the browser button gets hidden on overflow and last added app shortcut is
96 // still visible.
97 TEST_F(LauncherViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) {
98 // All buttons should be visible.
99 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
100 test_api_->GetButtonCount());
101
102 LauncherID browser_button_id = AddTabbedBrowser();
103
104 // Add app shortcut until overflow.
105 LauncherID last_added = AddAppShortcut();
106 while (!test_api_->IsOverflowButtonVisible()) {
107 // Added button is visible after animation while in this loop.
108 EXPECT_TRUE(GetButtonByID(last_added)->visible());
109
110 last_added = AddAppShortcut();
111 }
112
113 // The last added app short button should be visible.
114 EXPECT_TRUE(GetButtonByID(last_added)->visible());
115 // And the browser button is invisible.
116 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
117 }
118
119 // Adds button until overflow then removes first added one. Verifies that
120 // the last added one changes from invisible to visible and overflow
121 // chevron is gone.
122 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) {
123 // All buttons should be visible.
124 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
125 test_api_->GetButtonCount());
126
127 // Add tabbed browser until overflow.
128 LauncherID first_added= AddTabbedBrowser();
129 LauncherID last_added = first_added;
130 while (!test_api_->IsOverflowButtonVisible())
131 last_added = AddTabbedBrowser();
132
133 // Expect add more than 1 button. First added is visible and last is not.
134 EXPECT_NE(first_added, last_added);
135 EXPECT_TRUE(GetButtonByID(first_added)->visible());
136 EXPECT_FALSE(GetButtonByID(last_added)->visible());
137
138 // Remove first added.
139 RemoveByID(first_added);
140
141 // Last added button becomes visible and overflow chevron is gone.
142 EXPECT_TRUE(GetButtonByID(last_added)->visible());
143 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
144 }
145
146 // Verifies that remove last overflowed button should hide overflow chevron.
147 TEST_F(LauncherViewTest, RemoveLastOverflowed) {
148 // All buttons should be visible.
149 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
150 test_api_->GetButtonCount());
151
152 // Add tabbed browser until overflow.
153 LauncherID last_added= AddTabbedBrowser();
154 while (!test_api_->IsOverflowButtonVisible())
155 last_added = AddTabbedBrowser();
156
157 RemoveByID(last_added);
158 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
159 }
160
161 } // namespace test
162 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698