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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/launcher/launcher.h" | 11 #include "ash/launcher/launcher.h" |
12 #include "ash/launcher/launcher_button.h" | 12 #include "ash/launcher/launcher_button.h" |
13 #include "ash/launcher/launcher_icon_observer.h" | 13 #include "ash/launcher/launcher_icon_observer.h" |
14 #include "ash/launcher/launcher_item_delegate_manager.h" | |
15 #include "ash/launcher/launcher_model.h" | 14 #include "ash/launcher/launcher_model.h" |
16 #include "ash/launcher/launcher_tooltip_manager.h" | 15 #include "ash/launcher/launcher_tooltip_manager.h" |
17 #include "ash/launcher/launcher_types.h" | 16 #include "ash/launcher/launcher_types.h" |
18 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
19 #include "ash/shelf/shelf_layout_manager.h" | 18 #include "ash/shelf/shelf_layout_manager.h" |
20 #include "ash/shelf/shelf_widget.h" | 19 #include "ash/shelf/shelf_widget.h" |
21 #include "ash/shell.h" | 20 #include "ash/shell.h" |
22 #include "ash/shell_window_ids.h" | 21 #include "ash/shell_window_ids.h" |
23 #include "ash/test/ash_test_base.h" | 22 #include "ash/test/ash_test_base.h" |
24 #include "ash/test/launcher_test_api.h" | 23 #include "ash/test/launcher_test_api.h" |
25 #include "ash/test/launcher_view_test_api.h" | 24 #include "ash/test/launcher_view_test_api.h" |
26 #include "ash/test/shell_test_api.h" | 25 #include "ash/test/shell_test_api.h" |
27 #include "ash/test/test_launcher_delegate.h" | 26 #include "ash/test/test_launcher_delegate.h" |
28 #include "ash/test/test_launcher_item_delegate.h" | |
29 #include "base/basictypes.h" | 27 #include "base/basictypes.h" |
30 #include "base/command_line.h" | 28 #include "base/command_line.h" |
31 #include "base/compiler_specific.h" | 29 #include "base/compiler_specific.h" |
32 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
33 #include "grit/ash_resources.h" | 31 #include "grit/ash_resources.h" |
34 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
35 #include "ui/aura/test/aura_test_base.h" | 33 #include "ui/aura/test/aura_test_base.h" |
36 #include "ui/aura/test/event_generator.h" | 34 #include "ui/aura/test/event_generator.h" |
37 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
38 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 model_ = test_api.launcher_model(); | 205 model_ = test_api.launcher_model(); |
208 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 206 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
209 launcher_view_ = test::LauncherTestAPI(launcher).launcher_view(); | 207 launcher_view_ = test::LauncherTestAPI(launcher).launcher_view(); |
210 | 208 |
211 // The bounds should be big enough for 4 buttons + overflow chevron. | 209 // The bounds should be big enough for 4 buttons + overflow chevron. |
212 launcher_view_->SetBounds(0, 0, 500, 50); | 210 launcher_view_->SetBounds(0, 0, 500, 50); |
213 | 211 |
214 test_api_.reset(new LauncherViewTestAPI(launcher_view_)); | 212 test_api_.reset(new LauncherViewTestAPI(launcher_view_)); |
215 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 213 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
216 | 214 |
217 item_manager_ = | |
218 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | |
219 DCHECK(item_manager_); | |
220 | |
221 // Add browser shortcut launcher item at index 0 for test. | 215 // Add browser shortcut launcher item at index 0 for test. |
222 AddBrowserShortcut(); | 216 AddBrowserShortcut(); |
223 } | 217 } |
224 | 218 |
225 virtual void TearDown() OVERRIDE { | 219 virtual void TearDown() OVERRIDE { |
226 test_api_.reset(); | 220 test_api_.reset(); |
227 AshTestBase::TearDown(); | 221 AshTestBase::TearDown(); |
228 } | 222 } |
229 | 223 |
230 protected: | 224 protected: |
231 void CreateAndSetLauncherItemDelegateForID(LauncherID id) { | |
232 scoped_ptr<LauncherItemDelegate> delegate( | |
233 new ash::test::TestLauncherItemDelegate(NULL)); | |
234 item_manager_->SetLauncherItemDelegate(id, delegate.Pass()); | |
235 } | |
236 | |
237 LauncherID AddBrowserShortcut() { | 225 LauncherID AddBrowserShortcut() { |
238 LauncherItem browser_shortcut; | 226 LauncherItem browser_shortcut; |
239 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 227 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
240 | 228 |
241 LauncherID id = model_->next_id(); | 229 LauncherID id = model_->next_id(); |
242 model_->AddAt(browser_index_, browser_shortcut); | 230 model_->AddAt(browser_index_, browser_shortcut); |
243 CreateAndSetLauncherItemDelegateForID(id); | |
244 test_api_->RunMessageLoopUntilAnimationsDone(); | 231 test_api_->RunMessageLoopUntilAnimationsDone(); |
245 return id; | 232 return id; |
246 } | 233 } |
247 | 234 |
248 LauncherID AddAppShortcut() { | 235 LauncherID AddAppShortcut() { |
249 LauncherItem item; | 236 LauncherItem item; |
250 item.type = TYPE_APP_SHORTCUT; | 237 item.type = TYPE_APP_SHORTCUT; |
251 item.status = STATUS_CLOSED; | 238 item.status = STATUS_CLOSED; |
252 | 239 |
253 LauncherID id = model_->next_id(); | 240 LauncherID id = model_->next_id(); |
254 model_->Add(item); | 241 model_->Add(item); |
255 CreateAndSetLauncherItemDelegateForID(id); | |
256 test_api_->RunMessageLoopUntilAnimationsDone(); | 242 test_api_->RunMessageLoopUntilAnimationsDone(); |
257 return id; | 243 return id; |
258 } | 244 } |
259 | 245 |
260 LauncherID AddPanel() { | 246 LauncherID AddPanel() { |
261 LauncherID id = AddPanelNoWait(); | 247 LauncherID id = AddPanelNoWait(); |
262 test_api_->RunMessageLoopUntilAnimationsDone(); | 248 test_api_->RunMessageLoopUntilAnimationsDone(); |
263 return id; | 249 return id; |
264 } | 250 } |
265 | 251 |
266 LauncherID AddPlatformAppNoWait() { | 252 LauncherID AddPlatformAppNoWait() { |
267 LauncherItem item; | 253 LauncherItem item; |
268 item.type = TYPE_PLATFORM_APP; | 254 item.type = TYPE_PLATFORM_APP; |
269 item.status = STATUS_RUNNING; | 255 item.status = STATUS_RUNNING; |
270 | 256 |
271 LauncherID id = model_->next_id(); | 257 LauncherID id = model_->next_id(); |
272 model_->Add(item); | 258 model_->Add(item); |
273 CreateAndSetLauncherItemDelegateForID(id); | |
274 return id; | 259 return id; |
275 } | 260 } |
276 | 261 |
277 LauncherID AddPanelNoWait() { | 262 LauncherID AddPanelNoWait() { |
278 LauncherItem item; | 263 LauncherItem item; |
279 item.type = TYPE_APP_PANEL; | 264 item.type = TYPE_APP_PANEL; |
280 item.status = STATUS_RUNNING; | 265 item.status = STATUS_RUNNING; |
281 | 266 |
282 LauncherID id = model_->next_id(); | 267 LauncherID id = model_->next_id(); |
283 model_->Add(item); | 268 model_->Add(item); |
284 CreateAndSetLauncherItemDelegateForID(id); | |
285 return id; | 269 return id; |
286 } | 270 } |
287 | 271 |
288 LauncherID AddPlatformApp() { | 272 LauncherID AddPlatformApp() { |
289 LauncherID id = AddPlatformAppNoWait(); | 273 LauncherID id = AddPlatformAppNoWait(); |
290 test_api_->RunMessageLoopUntilAnimationsDone(); | 274 test_api_->RunMessageLoopUntilAnimationsDone(); |
291 return id; | 275 return id; |
292 } | 276 } |
293 | 277 |
294 void RemoveByID(LauncherID id) { | 278 void RemoveByID(LauncherID id) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 return launcher_view_->tooltip_manager()->anchor_; | 379 return launcher_view_->tooltip_manager()->anchor_; |
396 } | 380 } |
397 | 381 |
398 void ShowTooltip() { | 382 void ShowTooltip() { |
399 launcher_view_->tooltip_manager()->ShowInternal(); | 383 launcher_view_->tooltip_manager()->ShowInternal(); |
400 } | 384 } |
401 | 385 |
402 LauncherModel* model_; | 386 LauncherModel* model_; |
403 internal::LauncherView* launcher_view_; | 387 internal::LauncherView* launcher_view_; |
404 int browser_index_; | 388 int browser_index_; |
405 LauncherItemDelegateManager* item_manager_; | |
406 | 389 |
407 scoped_ptr<LauncherViewTestAPI> test_api_; | 390 scoped_ptr<LauncherViewTestAPI> test_api_; |
408 | 391 |
409 private: | 392 private: |
410 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); | 393 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); |
411 }; | 394 }; |
412 | 395 |
413 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { | 396 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { |
414 public: | 397 public: |
415 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() { | 398 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() { |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 test_api_->GetButtonCount()); | 1291 test_api_->GetButtonCount()); |
1309 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); | 1292 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); |
1310 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); | 1293 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); |
1311 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); | 1294 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); |
1312 } | 1295 } |
1313 | 1296 |
1314 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); | 1297 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); |
1315 | 1298 |
1316 } // namespace test | 1299 } // namespace test |
1317 } // namespace ash | 1300 } // namespace ash |
OLD | NEW |