| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/launcher/launcher_item_delegate_manager.h" | |
| 13 #include "ash/launcher/launcher_model.h" | 12 #include "ash/launcher/launcher_model.h" |
| 14 #include "ash/launcher/launcher_model_observer.h" | 13 #include "ash/launcher/launcher_model_observer.h" |
| 15 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 16 #include "ash/test/launcher_item_delegate_manager_test_api.h" | |
| 17 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 20 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 21 #include "base/values.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/test_extension_system.h" | 23 #include "chrome/browser/extensions/test_extension_system.h" |
| 26 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 24 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 27 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | |
| 28 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 25 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 29 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" | 26 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" |
| 30 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_commands.h" | 28 #include "chrome/browser/ui/browser_commands.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 33 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
| 34 #include "chrome/browser/ui/host_desktop.h" | 31 #include "chrome/browser/ui/host_desktop.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
| 37 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 TestV2AppLauncherItemController(const std::string& app_id, | 187 TestV2AppLauncherItemController(const std::string& app_id, |
| 191 ChromeLauncherController* controller) | 188 ChromeLauncherController* controller) |
| 192 : LauncherItemController(LauncherItemController::TYPE_APP, | 189 : LauncherItemController(LauncherItemController::TYPE_APP, |
| 193 app_id, | 190 app_id, |
| 194 controller) { | 191 controller) { |
| 195 } | 192 } |
| 196 | 193 |
| 197 virtual ~TestV2AppLauncherItemController() {} | 194 virtual ~TestV2AppLauncherItemController() {} |
| 198 | 195 |
| 199 // Override for LauncherItemController: | 196 // Override for LauncherItemController: |
| 197 virtual string16 GetTitle() OVERRIDE { return string16(); } |
| 200 virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE { | 198 virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE { |
| 201 return true; | 199 return true; |
| 202 } | 200 } |
| 203 virtual bool IsOpen() const OVERRIDE { return true; } | 201 virtual bool IsOpen() const OVERRIDE { return true; } |
| 204 virtual bool IsVisible() const OVERRIDE { return true; } | 202 virtual bool IsVisible() const OVERRIDE { return true; } |
| 205 virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {} | 203 virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {} |
| 206 virtual void Activate(ash::LaunchSource source) OVERRIDE {} | 204 virtual void Activate(ash::LaunchSource source) OVERRIDE {} |
| 207 virtual void Close() OVERRIDE {} | 205 virtual void Close() OVERRIDE {} |
| 208 virtual void ItemSelected(const ui::Event& event) OVERRIDE {} | 206 virtual void Clicked(const ui::Event& event) OVERRIDE {} |
| 209 virtual string16 GetTitle() OVERRIDE { return string16(); } | 207 virtual void OnRemoved() OVERRIDE {} |
| 210 virtual ChromeLauncherAppMenuItems GetApplicationList( | 208 virtual ChromeLauncherAppMenuItems GetApplicationList( |
| 211 int event_flags) OVERRIDE { | 209 int event_flags) OVERRIDE { |
| 212 ChromeLauncherAppMenuItems items; | 210 ChromeLauncherAppMenuItems items; |
| 213 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); | 211 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); |
| 214 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); | 212 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); |
| 215 return items.Pass(); | 213 return items.Pass(); |
| 216 } | 214 } |
| 217 virtual ui::MenuModel* CreateContextMenu( | |
| 218 aura::RootWindow* root_window) OVERRIDE { return NULL; } | |
| 219 virtual ash::LauncherMenuModel* CreateApplicationMenu( | |
| 220 int event_flags) OVERRIDE { return NULL; } | |
| 221 virtual bool IsDraggable() OVERRIDE { return false; } | |
| 222 virtual bool ShouldShowTooltip() OVERRIDE { return false; } | |
| 223 | 215 |
| 224 private: | 216 private: |
| 225 | 217 |
| 226 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | 218 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); |
| 227 }; | 219 }; |
| 228 | 220 |
| 229 } // namespace | 221 } // namespace |
| 230 | 222 |
| 231 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { | 223 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { |
| 232 protected: | 224 protected: |
| 233 ChromeLauncherControllerTest() : test_controller_(NULL), | 225 ChromeLauncherControllerTest() : extension_service_(NULL) { |
| 234 extension_service_(NULL) { | |
| 235 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); | 226 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); |
| 236 } | 227 } |
| 237 | 228 |
| 238 virtual ~ChromeLauncherControllerTest() { | 229 virtual ~ChromeLauncherControllerTest() { |
| 239 } | 230 } |
| 240 | 231 |
| 241 virtual void SetUp() OVERRIDE { | 232 virtual void SetUp() OVERRIDE { |
| 242 BrowserWithTestWindowTest::SetUp(); | 233 BrowserWithTestWindowTest::SetUp(); |
| 243 | 234 |
| 244 model_.reset(new ash::LauncherModel); | 235 model_.reset(new ash::LauncherModel); |
| 245 model_observer_.reset(new TestLauncherModelObserver); | 236 model_observer_.reset(new TestLauncherModelObserver); |
| 246 model_->AddObserver(model_observer_.get()); | 237 model_->AddObserver(model_observer_.get()); |
| 247 | 238 |
| 248 if (ash::Shell::HasInstance()) { | |
| 249 item_delegate_manager_ = | |
| 250 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | |
| 251 } else { | |
| 252 item_delegate_manager_ = | |
| 253 new ash::LauncherItemDelegateManager(model_.get()); | |
| 254 } | |
| 255 | |
| 256 DictionaryValue manifest; | 239 DictionaryValue manifest; |
| 257 manifest.SetString(extensions::manifest_keys::kName, | 240 manifest.SetString(extensions::manifest_keys::kName, |
| 258 "launcher controller test extension"); | 241 "launcher controller test extension"); |
| 259 manifest.SetString(extensions::manifest_keys::kVersion, "1"); | 242 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| 260 manifest.SetString(extensions::manifest_keys::kDescription, | 243 manifest.SetString(extensions::manifest_keys::kDescription, |
| 261 "for testing pinned apps"); | 244 "for testing pinned apps"); |
| 262 | 245 |
| 263 extensions::TestExtensionSystem* extension_system( | 246 extensions::TestExtensionSystem* extension_system( |
| 264 static_cast<extensions::TestExtensionSystem*>( | 247 static_cast<extensions::TestExtensionSystem*>( |
| 265 extensions::ExtensionSystem::Get(profile()))); | 248 extensions::ExtensionSystem::Get(profile()))); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 &error); | 302 &error); |
| 320 extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 303 extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
| 321 manifest, | 304 manifest, |
| 322 Extension::NO_FLAGS, | 305 Extension::NO_FLAGS, |
| 323 "ffffffffffffffffffffffffffffffff", | 306 "ffffffffffffffffffffffffffffffff", |
| 324 &error); | 307 &error); |
| 325 } | 308 } |
| 326 | 309 |
| 327 // Creates a running V2 app (not pinned) of type |app_id|. | 310 // Creates a running V2 app (not pinned) of type |app_id|. |
| 328 virtual void CreateRunningV2App(const std::string& app_id) { | 311 virtual void CreateRunningV2App(const std::string& app_id) { |
| 329 DCHECK(!test_controller_); | 312 DCHECK(!test_controller_.get()); |
| 330 ash::LauncherID id = | 313 ash::LauncherID id = |
| 331 launcher_controller_->CreateAppShortcutLauncherItemWithType( | 314 launcher_controller_->CreateAppShortcutLauncherItemWithType( |
| 332 app_id, | 315 app_id, |
| 333 model_->item_count(), | 316 model_->item_count(), |
| 334 ash::TYPE_PLATFORM_APP); | 317 ash::TYPE_PLATFORM_APP); |
| 335 DCHECK(id); | 318 DCHECK(id); |
| 336 // Change the created launcher controller into a V2 app controller. | 319 // Change the created launcher controller into a V2 app controller. |
| 337 test_controller_ = new TestV2AppLauncherItemController(app_id, | 320 test_controller_.reset(new TestV2AppLauncherItemController(app_id, |
| 338 launcher_controller_.get()); | 321 launcher_controller_.get())); |
| 339 launcher_controller_->SetItemController(id, test_controller_); | 322 launcher_controller_->SetItemController(id, test_controller_.get()); |
| 340 } | 323 } |
| 341 | 324 |
| 342 // Sets the stage for a multi user test. | 325 // Sets the stage for a multi user test. |
| 343 virtual void SetUpMultiUserScenario(base::ListValue* user_a, | 326 virtual void SetUpMultiUserScenario(base::ListValue* user_a, |
| 344 base::ListValue* user_b) { | 327 base::ListValue* user_b) { |
| 345 InitLauncherController(); | 328 InitLauncherController(); |
| 346 EXPECT_EQ("AppList, Chrome, ", GetPinnedAppStatus()); | 329 EXPECT_EQ("AppList, Chrome, ", GetPinnedAppStatus()); |
| 347 | 330 |
| 348 // Set an empty pinned pref to begin with. | 331 // Set an empty pinned pref to begin with. |
| 349 base::ListValue no_user; | 332 base::ListValue no_user; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 371 InsertPrefValue(user_a, 3, extension4_->id()); | 354 InsertPrefValue(user_a, 3, extension4_->id()); |
| 372 InsertPrefValue(user_a, 4, extension5_->id()); | 355 InsertPrefValue(user_a, 4, extension5_->id()); |
| 373 InsertPrefValue(user_a, 5, extension6_->id()); | 356 InsertPrefValue(user_a, 5, extension6_->id()); |
| 374 | 357 |
| 375 // Set user b preferences. | 358 // Set user b preferences. |
| 376 InsertPrefValue(user_b, 0, extension7_->id()); | 359 InsertPrefValue(user_b, 0, extension7_->id()); |
| 377 InsertPrefValue(user_b, 1, extension8_->id()); | 360 InsertPrefValue(user_b, 1, extension8_->id()); |
| 378 } | 361 } |
| 379 | 362 |
| 380 virtual void TearDown() OVERRIDE { | 363 virtual void TearDown() OVERRIDE { |
| 381 if (!ash::Shell::HasInstance()) | |
| 382 delete item_delegate_manager_; | |
| 383 model_->RemoveObserver(model_observer_.get()); | 364 model_->RemoveObserver(model_observer_.get()); |
| 384 model_observer_.reset(); | 365 model_observer_.reset(); |
| 385 launcher_controller_.reset(); | 366 launcher_controller_.reset(); |
| 386 model_.reset(); | 367 model_.reset(); |
| 387 | 368 |
| 388 BrowserWithTestWindowTest::TearDown(); | 369 BrowserWithTestWindowTest::TearDown(); |
| 370 test_controller_.reset(); |
| 389 } | 371 } |
| 390 | 372 |
| 391 void AddAppListLauncherItem() { | 373 void AddAppListLauncherItem() { |
| 392 ash::LauncherItem app_list; | 374 ash::LauncherItem app_list; |
| 393 app_list.type = ash::TYPE_APP_LIST; | 375 app_list.type = ash::TYPE_APP_LIST; |
| 394 model_->Add(app_list); | 376 model_->Add(app_list); |
| 395 } | 377 } |
| 396 | 378 |
| 397 void InitLauncherController() { | 379 void InitLauncherController() { |
| 398 AddAppListLauncherItem(); | 380 AddAppListLauncherItem(); |
| 399 launcher_controller_.reset( | 381 launcher_controller_.reset( |
| 400 new ChromeLauncherController(profile(), model_.get())); | 382 new ChromeLauncherController(profile(), model_.get())); |
| 401 if (!ash::Shell::HasInstance()) | |
| 402 SetLauncherItemDelegateManager(item_delegate_manager_); | |
| 403 launcher_controller_->Init(); | 383 launcher_controller_->Init(); |
| 404 } | 384 } |
| 405 | 385 |
| 406 void InitLauncherControllerWithBrowser() { | 386 void InitLauncherControllerWithBrowser() { |
| 407 chrome::NewTab(browser()); | 387 chrome::NewTab(browser()); |
| 408 BrowserList::SetLastActive(browser()); | 388 BrowserList::SetLastActive(browser()); |
| 409 InitLauncherController(); | 389 InitLauncherController(); |
| 410 } | 390 } |
| 411 | 391 |
| 412 void SetAppIconLoader(extensions::AppIconLoader* loader) { | 392 void SetAppIconLoader(extensions::AppIconLoader* loader) { |
| 413 launcher_controller_->SetAppIconLoaderForTest(loader); | 393 launcher_controller_->SetAppIconLoaderForTest(loader); |
| 414 } | 394 } |
| 415 | 395 |
| 416 void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { | 396 void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { |
| 417 launcher_controller_->SetAppTabHelperForTest(helper); | 397 launcher_controller_->SetAppTabHelperForTest(helper); |
| 418 } | 398 } |
| 419 | 399 |
| 420 void SetLauncherItemDelegateManager( | |
| 421 ash::LauncherItemDelegateManager* manager) { | |
| 422 launcher_controller_->SetLauncherItemDelegateManagerForTest(manager); | |
| 423 } | |
| 424 | |
| 425 void InsertPrefValue(base::ListValue* pref_value, | 400 void InsertPrefValue(base::ListValue* pref_value, |
| 426 int index, | 401 int index, |
| 427 const std::string& extension_id) { | 402 const std::string& extension_id) { |
| 428 base::DictionaryValue* entry = new DictionaryValue(); | 403 base::DictionaryValue* entry = new DictionaryValue(); |
| 429 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); | 404 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); |
| 430 pref_value->Insert(index, entry); | 405 pref_value->Insert(index, entry); |
| 431 } | 406 } |
| 432 | 407 |
| 433 // Gets the currently configured app launchers from the controller. | 408 // Gets the currently configured app launchers from the controller. |
| 434 void GetAppLaunchers(ChromeLauncherController* controller, | 409 void GetAppLaunchers(ChromeLauncherController* controller, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 scoped_refptr<Extension> extension2_; | 530 scoped_refptr<Extension> extension2_; |
| 556 scoped_refptr<Extension> extension3_; | 531 scoped_refptr<Extension> extension3_; |
| 557 scoped_refptr<Extension> extension4_; | 532 scoped_refptr<Extension> extension4_; |
| 558 scoped_refptr<Extension> extension5_; | 533 scoped_refptr<Extension> extension5_; |
| 559 scoped_refptr<Extension> extension6_; | 534 scoped_refptr<Extension> extension6_; |
| 560 scoped_refptr<Extension> extension7_; | 535 scoped_refptr<Extension> extension7_; |
| 561 scoped_refptr<Extension> extension8_; | 536 scoped_refptr<Extension> extension8_; |
| 562 scoped_ptr<ChromeLauncherController> launcher_controller_; | 537 scoped_ptr<ChromeLauncherController> launcher_controller_; |
| 563 scoped_ptr<TestLauncherModelObserver> model_observer_; | 538 scoped_ptr<TestLauncherModelObserver> model_observer_; |
| 564 scoped_ptr<ash::LauncherModel> model_; | 539 scoped_ptr<ash::LauncherModel> model_; |
| 565 | 540 scoped_ptr<TestV2AppLauncherItemController> test_controller_; |
| 566 // |item_delegate_manager_| owns |test_controller_|. | |
| 567 LauncherItemController* test_controller_; | |
| 568 | 541 |
| 569 ExtensionService* extension_service_; | 542 ExtensionService* extension_service_; |
| 570 | 543 |
| 571 ash::LauncherItemDelegateManager* item_delegate_manager_; | |
| 572 | |
| 573 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 544 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
| 574 }; | 545 }; |
| 575 | 546 |
| 576 // The testing framework to test the legacy shelf layout. | 547 // The testing framework to test the legacy shelf layout. |
| 577 class LegacyShelfLayoutChromeLauncherControllerTest | 548 class LegacyShelfLayoutChromeLauncherControllerTest |
| 578 : public ChromeLauncherControllerTest { | 549 : public ChromeLauncherControllerTest { |
| 579 protected: | 550 protected: |
| 580 LegacyShelfLayoutChromeLauncherControllerTest() { | 551 LegacyShelfLayoutChromeLauncherControllerTest() { |
| 581 } | 552 } |
| 582 | 553 |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 for (size_t i = 0; i < expected_items; i++) { | 1496 for (size_t i = 0; i < expected_items; i++) { |
| 1526 EXPECT_EQ(title[i], items[1 + i]->title()); | 1497 EXPECT_EQ(title[i], items[1 + i]->title()); |
| 1527 // Check that the first real item has a leading separator. | 1498 // Check that the first real item has a leading separator. |
| 1528 if (i == 1) | 1499 if (i == 1) |
| 1529 EXPECT_TRUE(items[i]->HasLeadingSeparator()); | 1500 EXPECT_TRUE(items[i]->HasLeadingSeparator()); |
| 1530 else | 1501 else |
| 1531 EXPECT_FALSE(items[i]->HasLeadingSeparator()); | 1502 EXPECT_FALSE(items[i]->HasLeadingSeparator()); |
| 1532 } | 1503 } |
| 1533 | 1504 |
| 1534 scoped_ptr<ash::LauncherMenuModel> menu( | 1505 scoped_ptr<ash::LauncherMenuModel> menu( |
| 1535 new LauncherApplicationMenuItemModel( | 1506 controller->CreateApplicationMenu(item, 0)); |
| 1536 controller->GetApplicationList(item, 0))); | |
| 1537 // The first element in the menu is a spacing separator. On some systems | 1507 // The first element in the menu is a spacing separator. On some systems |
| 1538 // (e.g. Windows) such things do not exist. As such we check the existence | 1508 // (e.g. Windows) such things do not exist. As such we check the existence |
| 1539 // and adjust dynamically. | 1509 // and adjust dynamically. |
| 1540 int first_item = menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR ? 1 : 0; | 1510 int first_item = menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR ? 1 : 0; |
| 1541 int expected_menu_items = first_item + | 1511 int expected_menu_items = first_item + |
| 1542 (expected_items ? (expected_items + 3) : 2); | 1512 (expected_items ? (expected_items + 3) : 2); |
| 1543 EXPECT_EQ(expected_menu_items, menu->GetItemCount()); | 1513 EXPECT_EQ(expected_menu_items, menu->GetItemCount()); |
| 1544 EXPECT_FALSE(menu->IsEnabledAt(first_item)); | 1514 EXPECT_FALSE(menu->IsEnabledAt(first_item)); |
| 1545 if (expected_items) { | 1515 if (expected_items) { |
| 1546 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | 1516 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 item_gmail.type = ash::TYPE_APP_SHORTCUT; | 1660 item_gmail.type = ash::TYPE_APP_SHORTCUT; |
| 1691 item_gmail.id = gmail_id; | 1661 item_gmail.id = gmail_id; |
| 1692 string16 two_menu_items[] = {title1, title2}; | 1662 string16 two_menu_items[] = {title1, title2}; |
| 1693 EXPECT_TRUE(CheckMenuCreation( | 1663 EXPECT_TRUE(CheckMenuCreation( |
| 1694 launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); | 1664 launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); |
| 1695 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 1665 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 1696 // Execute the second item in the list (which shouldn't do anything since that | 1666 // Execute the second item in the list (which shouldn't do anything since that |
| 1697 // item is per definition already the active tab). | 1667 // item is per definition already the active tab). |
| 1698 { | 1668 { |
| 1699 scoped_ptr<ash::LauncherMenuModel> menu( | 1669 scoped_ptr<ash::LauncherMenuModel> menu( |
| 1700 new LauncherApplicationMenuItemModel( | 1670 launcher_controller_->CreateApplicationMenu(item_gmail, 0)); |
| 1701 launcher_controller_->GetApplicationList(item_gmail, 0))); | |
| 1702 // The first element in the menu is a spacing separator. On some systems | 1671 // The first element in the menu is a spacing separator. On some systems |
| 1703 // (e.g. Windows) such things do not exist. As such we check the existence | 1672 // (e.g. Windows) such things do not exist. As such we check the existence |
| 1704 // and adjust dynamically. | 1673 // and adjust dynamically. |
| 1705 int first_item = | 1674 int first_item = |
| 1706 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; | 1675 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; |
| 1707 menu->ActivatedAt(first_item + 3); | 1676 menu->ActivatedAt(first_item + 3); |
| 1708 } | 1677 } |
| 1709 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 1678 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 1710 | 1679 |
| 1711 // Execute the first item. | 1680 // Execute the first item. |
| 1712 { | 1681 { |
| 1713 scoped_ptr<ash::LauncherMenuModel> menu( | 1682 scoped_ptr<ash::LauncherMenuModel> menu( |
| 1714 new LauncherApplicationMenuItemModel( | 1683 launcher_controller_->CreateApplicationMenu(item_gmail, 0)); |
| 1715 launcher_controller_->GetApplicationList(item_gmail, 0))); | |
| 1716 int first_item = | 1684 int first_item = |
| 1717 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; | 1685 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; |
| 1718 menu->ActivatedAt(first_item + 2); | 1686 menu->ActivatedAt(first_item + 2); |
| 1719 } | 1687 } |
| 1720 // Now the active tab should be the second item. | 1688 // Now the active tab should be the second item. |
| 1721 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 1689 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 1722 } | 1690 } |
| 1723 | 1691 |
| 1724 // Checks that the generated menu list properly deletes items. | 1692 // Checks that the generated menu list properly deletes items. |
| 1725 TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) { | 1693 TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 TEST_F(ChromeLauncherControllerTest, AppPanels) { | 1734 TEST_F(ChromeLauncherControllerTest, AppPanels) { |
| 1767 InitLauncherControllerWithBrowser(); | 1735 InitLauncherControllerWithBrowser(); |
| 1768 // App list and Browser shortcut LauncherItems are added. | 1736 // App list and Browser shortcut LauncherItems are added. |
| 1769 EXPECT_EQ(2, model_observer_->added()); | 1737 EXPECT_EQ(2, model_observer_->added()); |
| 1770 | 1738 |
| 1771 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); | 1739 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); |
| 1772 SetAppIconLoader(app_icon_loader); | 1740 SetAppIconLoader(app_icon_loader); |
| 1773 | 1741 |
| 1774 // Test adding an app panel | 1742 // Test adding an app panel |
| 1775 std::string app_id = extension1_->id(); | 1743 std::string app_id = extension1_->id(); |
| 1776 ShellWindowLauncherItemController* app_panel_controller = | 1744 ShellWindowLauncherItemController app_panel_controller( |
| 1777 new ShellWindowLauncherItemController( | 1745 LauncherItemController::TYPE_APP_PANEL, "id", app_id, |
| 1778 LauncherItemController::TYPE_APP_PANEL, | 1746 launcher_controller_.get()); |
| 1779 "id", | |
| 1780 app_id, | |
| 1781 launcher_controller_.get()); | |
| 1782 ash::LauncherID launcher_id1 = launcher_controller_->CreateAppLauncherItem( | 1747 ash::LauncherID launcher_id1 = launcher_controller_->CreateAppLauncherItem( |
| 1783 app_panel_controller, app_id, ash::STATUS_RUNNING); | 1748 &app_panel_controller, app_id, ash::STATUS_RUNNING); |
| 1784 int panel_index = model_observer_->last_index(); | 1749 int panel_index = model_observer_->last_index(); |
| 1785 EXPECT_EQ(3, model_observer_->added()); | 1750 EXPECT_EQ(3, model_observer_->added()); |
| 1786 EXPECT_EQ(0, model_observer_->changed()); | 1751 EXPECT_EQ(0, model_observer_->changed()); |
| 1787 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1752 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 1788 model_observer_->clear_counts(); | 1753 model_observer_->clear_counts(); |
| 1789 | 1754 |
| 1790 // App panels should have a separate identifier than the app id | 1755 // App panels should have a separate identifier than the app id |
| 1791 EXPECT_EQ(0, launcher_controller_->GetLauncherIDForAppID(app_id)); | 1756 EXPECT_EQ(0, launcher_controller_->GetLauncherIDForAppID(app_id)); |
| 1792 | 1757 |
| 1793 // Setting the app image image should not change the panel if it set its icon | 1758 // Setting the app image image should not change the panel if it set its icon |
| 1794 app_panel_controller->set_image_set_by_controller(true); | 1759 app_panel_controller.set_image_set_by_controller(true); |
| 1795 gfx::ImageSkia image; | 1760 gfx::ImageSkia image; |
| 1796 launcher_controller_->SetAppImage(app_id, image); | 1761 launcher_controller_->SetAppImage(app_id, image); |
| 1797 EXPECT_EQ(0, model_observer_->changed()); | 1762 EXPECT_EQ(0, model_observer_->changed()); |
| 1798 model_observer_->clear_counts(); | 1763 model_observer_->clear_counts(); |
| 1799 | 1764 |
| 1800 // Add a second app panel and verify that it get the same index as the first | 1765 // Add a second app panel and verify that it get the same index as the first |
| 1801 // one had, being added to the left of the existing panel. | 1766 // one had, being added to the left of the existing panel. |
| 1802 ShellWindowLauncherItemController* app_panel_controller2 = | |
| 1803 new ShellWindowLauncherItemController( | |
| 1804 LauncherItemController::TYPE_APP_PANEL, | |
| 1805 "id", | |
| 1806 app_id, | |
| 1807 launcher_controller_.get()); | |
| 1808 | |
| 1809 ash::LauncherID launcher_id2 = launcher_controller_->CreateAppLauncherItem( | 1767 ash::LauncherID launcher_id2 = launcher_controller_->CreateAppLauncherItem( |
| 1810 app_panel_controller2, app_id, ash::STATUS_RUNNING); | 1768 &app_panel_controller, app_id, ash::STATUS_RUNNING); |
| 1811 EXPECT_EQ(panel_index, model_observer_->last_index()); | 1769 EXPECT_EQ(panel_index, model_observer_->last_index()); |
| 1812 EXPECT_EQ(1, model_observer_->added()); | 1770 EXPECT_EQ(1, model_observer_->added()); |
| 1813 model_observer_->clear_counts(); | 1771 model_observer_->clear_counts(); |
| 1814 | 1772 |
| 1815 launcher_controller_->CloseLauncherItem(launcher_id2); | 1773 launcher_controller_->CloseLauncherItem(launcher_id2); |
| 1816 launcher_controller_->CloseLauncherItem(launcher_id1); | 1774 launcher_controller_->CloseLauncherItem(launcher_id1); |
| 1817 EXPECT_EQ(2, model_observer_->removed()); | 1775 EXPECT_EQ(2, model_observer_->removed()); |
| 1818 } | 1776 } |
| 1819 | 1777 |
| 1820 // Tests that the Gmail extension matches more then the app itself claims with | 1778 // Tests that the Gmail extension matches more then the app itself claims with |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 | 1863 |
| 1906 // Move browser shortcut item from index 1 to index 3. | 1864 // Move browser shortcut item from index 1 to index 3. |
| 1907 model_->Move(1, 3); | 1865 model_->Move(1, 3); |
| 1908 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 1866 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
| 1909 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 1867 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 1910 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 1868 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 1911 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 1869 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |
| 1912 | 1870 |
| 1913 launcher_controller_.reset(); | 1871 launcher_controller_.reset(); |
| 1914 model_.reset(new ash::LauncherModel); | 1872 model_.reset(new ash::LauncherModel); |
| 1915 | |
| 1916 // Clear already registered LauncherItemDelegate. | |
| 1917 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); | |
| 1918 test.RemoveAllLauncherItemDelegateForTest(); | |
| 1919 | |
| 1920 AddAppListLauncherItem(); | |
| 1921 launcher_controller_.reset( | 1873 launcher_controller_.reset( |
| 1922 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 1874 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
| 1923 app_tab_helper = new TestAppTabHelperImpl; | 1875 app_tab_helper = new TestAppTabHelperImpl; |
| 1924 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 1876 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 1925 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 1877 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |
| 1926 SetAppTabHelper(app_tab_helper); | 1878 SetAppTabHelper(app_tab_helper); |
| 1927 if (!ash::Shell::HasInstance()) | 1879 AddAppListLauncherItem(); |
| 1928 SetLauncherItemDelegateManager(item_delegate_manager_); | |
| 1929 launcher_controller_->Init(); | 1880 launcher_controller_->Init(); |
| 1930 | 1881 |
| 1931 // Check LauncherItems are restored after resetting ChromeLauncherController. | 1882 // Check LauncherItems are restored after resetting ChromeLauncherController. |
| 1932 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 1883 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
| 1933 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 1884 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 1934 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 1885 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 1935 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 1886 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |
| 1936 } | 1887 } |
| 1937 | 1888 |
| 1938 // Verifies pinned apps are persisted and restored. | 1889 // Verifies pinned apps are persisted and restored. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1955 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); | 1906 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); |
| 1956 int app_index = model_->ItemIndexByID(id); | 1907 int app_index = model_->ItemIndexByID(id); |
| 1957 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1908 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 1958 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1909 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 1959 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1910 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 1960 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1911 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 1961 EXPECT_EQ(initial_size + 1, model_->items().size()); | 1912 EXPECT_EQ(initial_size + 1, model_->items().size()); |
| 1962 | 1913 |
| 1963 launcher_controller_.reset(); | 1914 launcher_controller_.reset(); |
| 1964 model_.reset(new ash::LauncherModel); | 1915 model_.reset(new ash::LauncherModel); |
| 1965 | |
| 1966 // Clear already registered LauncherItemDelegate. | |
| 1967 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); | |
| 1968 test.RemoveAllLauncherItemDelegateForTest(); | |
| 1969 | |
| 1970 AddAppListLauncherItem(); | 1916 AddAppListLauncherItem(); |
| 1971 launcher_controller_.reset( | 1917 launcher_controller_.reset( |
| 1972 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 1918 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
| 1973 app_tab_helper = new TestAppTabHelperImpl; | 1919 app_tab_helper = new TestAppTabHelperImpl; |
| 1974 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 1920 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 1975 SetAppTabHelper(app_tab_helper); | 1921 SetAppTabHelper(app_tab_helper); |
| 1976 app_icon_loader = new TestAppIconLoaderImpl; | 1922 app_icon_loader = new TestAppIconLoaderImpl; |
| 1977 SetAppIconLoader(app_icon_loader); | 1923 SetAppIconLoader(app_icon_loader); |
| 1978 if (!ash::Shell::HasInstance()) | |
| 1979 SetLauncherItemDelegateManager(item_delegate_manager_); | |
| 1980 launcher_controller_->Init(); | 1924 launcher_controller_->Init(); |
| 1981 | 1925 |
| 1982 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1926 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 1983 ASSERT_EQ(initial_size + 1, model_->items().size()); | 1927 ASSERT_EQ(initial_size + 1, model_->items().size()); |
| 1984 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1928 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 1985 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1929 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 1986 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1930 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 1987 | 1931 |
| 1988 launcher_controller_->UnpinAppWithID("1"); | 1932 launcher_controller_->UnpinAppWithID("1"); |
| 1989 ASSERT_EQ(initial_size, model_->items().size()); | 1933 ASSERT_EQ(initial_size, model_->items().size()); |
| 1990 } | 1934 } |
| OLD | NEW |