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