OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_button.h" | 8 #include "ash/launcher/launcher_button.h" |
9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
10 #include "ash/launcher/launcher_icon_observer.h" | 10 #include "ash/launcher/launcher_icon_observer.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 test_api_.reset(new LauncherViewTestAPI(launcher_view_.get())); | 125 test_api_.reset(new LauncherViewTestAPI(launcher_view_.get())); |
126 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 126 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
127 } | 127 } |
128 | 128 |
129 protected: | 129 protected: |
130 LauncherID AddAppShortcut() { | 130 LauncherID AddAppShortcut() { |
131 LauncherItem item; | 131 LauncherItem item; |
132 item.type = TYPE_APP_SHORTCUT; | 132 item.type = TYPE_APP_SHORTCUT; |
133 item.status = STATUS_CLOSED; | 133 item.status = STATUS_CLOSED; |
134 | 134 |
135 int id = model_->next_id(); | 135 LauncherID id = model_->next_id(); |
136 model_->Add(item); | 136 model_->Add(item); |
137 test_api_->RunMessageLoopUntilAnimationsDone(); | 137 test_api_->RunMessageLoopUntilAnimationsDone(); |
138 return id; | 138 return id; |
139 } | 139 } |
140 | 140 |
141 LauncherID AddTabbedBrowser() { | 141 LauncherID AddTabbedBrowserNoWait() { |
142 LauncherItem item; | 142 LauncherItem item; |
143 item.type = TYPE_TABBED; | 143 item.type = TYPE_TABBED; |
144 item.status = STATUS_RUNNING; | 144 item.status = STATUS_RUNNING; |
145 | 145 |
146 int id = model_->next_id(); | 146 LauncherID id = model_->next_id(); |
147 model_->Add(item); | 147 model_->Add(item); |
| 148 return id; |
| 149 } |
| 150 |
| 151 LauncherID AddTabbedBrowser() { |
| 152 LauncherID id = AddTabbedBrowserNoWait(); |
148 test_api_->RunMessageLoopUntilAnimationsDone(); | 153 test_api_->RunMessageLoopUntilAnimationsDone(); |
149 return id; | 154 return id; |
150 } | 155 } |
151 | 156 |
152 void RemoveByID(LauncherID id) { | 157 void RemoveByID(LauncherID id) { |
153 model_->RemoveItemAt(model_->ItemIndexByID(id)); | 158 model_->RemoveItemAt(model_->ItemIndexByID(id)); |
154 test_api_->RunMessageLoopUntilAnimationsDone(); | 159 test_api_->RunMessageLoopUntilAnimationsDone(); |
155 } | 160 } |
156 | 161 |
157 internal::LauncherButton* GetButtonByID(LauncherID id) { | 162 internal::LauncherButton* GetButtonByID(LauncherID id) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 253 |
249 // Add tabbed browser until overflow. | 254 // Add tabbed browser until overflow. |
250 LauncherID last_added= AddTabbedBrowser(); | 255 LauncherID last_added= AddTabbedBrowser(); |
251 while (!test_api_->IsOverflowButtonVisible()) | 256 while (!test_api_->IsOverflowButtonVisible()) |
252 last_added = AddTabbedBrowser(); | 257 last_added = AddTabbedBrowser(); |
253 | 258 |
254 RemoveByID(last_added); | 259 RemoveByID(last_added); |
255 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | 260 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
256 } | 261 } |
257 | 262 |
| 263 // Adds browser button without waiting for animation to finish and verifies |
| 264 // that all added buttons are visible. |
| 265 TEST_F(LauncherViewTest, AddButtonQuickly) { |
| 266 // All buttons should be visible. |
| 267 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 268 test_api_->GetButtonCount()); |
| 269 |
| 270 // Add a few tabbed browser quickly without wait for animation. |
| 271 int added_count = 0; |
| 272 while (!test_api_->IsOverflowButtonVisible()) { |
| 273 AddTabbedBrowserNoWait(); |
| 274 ++added_count; |
| 275 } |
| 276 |
| 277 // LauncherView should be big enough to hold at least 3 new buttons. |
| 278 ASSERT_GE(added_count, 3); |
| 279 |
| 280 // Wait for the last animation to finish. |
| 281 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 282 |
| 283 // Verifies non-overflow buttons are visible. |
| 284 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { |
| 285 internal::LauncherButton* button = test_api_->GetButton(i); |
| 286 EXPECT_TRUE(button->visible()) << "button index=" << i; |
| 287 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; |
| 288 } |
| 289 } |
| 290 |
258 } // namespace test | 291 } // namespace test |
259 } // namespace ash | 292 } // namespace ash |
OLD | NEW |