| 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" | 12 #include "ash/shelf/shelf_item_delegate_manager.h" |
| 13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 14 #include "ash/shelf/shelf_model_observer.h" | 14 #include "ash/shelf/shelf_model_observer.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/test/launcher_item_delegate_manager_test_api.h" | 16 #include "ash/test/shelf_item_delegate_manager_test_api.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/test_extension_system.h" | 25 #include "chrome/browser/extensions/test_extension_system.h" |
| 26 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 26 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 virtual void SetUp() OVERRIDE { | 268 virtual void SetUp() OVERRIDE { |
| 269 BrowserWithTestWindowTest::SetUp(); | 269 BrowserWithTestWindowTest::SetUp(); |
| 270 | 270 |
| 271 model_.reset(new ash::ShelfModel); | 271 model_.reset(new ash::ShelfModel); |
| 272 model_observer_.reset(new TestShelfModelObserver); | 272 model_observer_.reset(new TestShelfModelObserver); |
| 273 model_->AddObserver(model_observer_.get()); | 273 model_->AddObserver(model_observer_.get()); |
| 274 | 274 |
| 275 if (ash::Shell::HasInstance()) { | 275 if (ash::Shell::HasInstance()) { |
| 276 item_delegate_manager_ = | 276 item_delegate_manager_ = |
| 277 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | 277 ash::Shell::GetInstance()->shelf_item_delegate_manager(); |
| 278 } else { | 278 } else { |
| 279 item_delegate_manager_ = | 279 item_delegate_manager_ = |
| 280 new ash::LauncherItemDelegateManager(model_.get()); | 280 new ash::ShelfItemDelegateManager(model_.get()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 DictionaryValue manifest; | 283 DictionaryValue manifest; |
| 284 manifest.SetString(extensions::manifest_keys::kName, | 284 manifest.SetString(extensions::manifest_keys::kName, |
| 285 "launcher controller test extension"); | 285 "launcher controller test extension"); |
| 286 manifest.SetString(extensions::manifest_keys::kVersion, "1"); | 286 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| 287 manifest.SetString(extensions::manifest_keys::kDescription, | 287 manifest.SetString(extensions::manifest_keys::kDescription, |
| 288 "for testing pinned apps"); | 288 "for testing pinned apps"); |
| 289 | 289 |
| 290 extensions::TestExtensionSystem* extension_system( | 290 extensions::TestExtensionSystem* extension_system( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 ash::LauncherItem app_list; | 419 ash::LauncherItem app_list; |
| 420 app_list.type = ash::TYPE_APP_LIST; | 420 app_list.type = ash::TYPE_APP_LIST; |
| 421 model_->Add(app_list); | 421 model_->Add(app_list); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void InitLauncherController() { | 424 void InitLauncherController() { |
| 425 AddAppListLauncherItem(); | 425 AddAppListLauncherItem(); |
| 426 launcher_controller_.reset( | 426 launcher_controller_.reset( |
| 427 new ChromeLauncherController(profile(), model_.get())); | 427 new ChromeLauncherController(profile(), model_.get())); |
| 428 if (!ash::Shell::HasInstance()) | 428 if (!ash::Shell::HasInstance()) |
| 429 SetLauncherItemDelegateManager(item_delegate_manager_); | 429 SetShelfItemDelegateManager(item_delegate_manager_); |
| 430 launcher_controller_->Init(); | 430 launcher_controller_->Init(); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void InitLauncherControllerWithBrowser() { | 433 void InitLauncherControllerWithBrowser() { |
| 434 chrome::NewTab(browser()); | 434 chrome::NewTab(browser()); |
| 435 BrowserList::SetLastActive(browser()); | 435 BrowserList::SetLastActive(browser()); |
| 436 InitLauncherController(); | 436 InitLauncherController(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void SetAppIconLoader(extensions::AppIconLoader* loader) { | 439 void SetAppIconLoader(extensions::AppIconLoader* loader) { |
| 440 launcher_controller_->SetAppIconLoaderForTest(loader); | 440 launcher_controller_->SetAppIconLoaderForTest(loader); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { | 443 void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { |
| 444 launcher_controller_->SetAppTabHelperForTest(helper); | 444 launcher_controller_->SetAppTabHelperForTest(helper); |
| 445 } | 445 } |
| 446 | 446 |
| 447 void SetLauncherItemDelegateManager( | 447 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { |
| 448 ash::LauncherItemDelegateManager* manager) { | 448 launcher_controller_->SetShelfItemDelegateManagerForTest(manager); |
| 449 launcher_controller_->SetLauncherItemDelegateManagerForTest(manager); | |
| 450 } | 449 } |
| 451 | 450 |
| 452 void InsertPrefValue(base::ListValue* pref_value, | 451 void InsertPrefValue(base::ListValue* pref_value, |
| 453 int index, | 452 int index, |
| 454 const std::string& extension_id) { | 453 const std::string& extension_id) { |
| 455 base::DictionaryValue* entry = new DictionaryValue(); | 454 base::DictionaryValue* entry = new DictionaryValue(); |
| 456 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); | 455 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); |
| 457 pref_value->Insert(index, entry); | 456 pref_value->Insert(index, entry); |
| 458 } | 457 } |
| 459 | 458 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 scoped_refptr<Extension> extension8_; | 587 scoped_refptr<Extension> extension8_; |
| 589 scoped_ptr<ChromeLauncherController> launcher_controller_; | 588 scoped_ptr<ChromeLauncherController> launcher_controller_; |
| 590 scoped_ptr<TestShelfModelObserver> model_observer_; | 589 scoped_ptr<TestShelfModelObserver> model_observer_; |
| 591 scoped_ptr<ash::ShelfModel> model_; | 590 scoped_ptr<ash::ShelfModel> model_; |
| 592 | 591 |
| 593 // |item_delegate_manager_| owns |test_controller_|. | 592 // |item_delegate_manager_| owns |test_controller_|. |
| 594 LauncherItemController* test_controller_; | 593 LauncherItemController* test_controller_; |
| 595 | 594 |
| 596 ExtensionService* extension_service_; | 595 ExtensionService* extension_service_; |
| 597 | 596 |
| 598 ash::LauncherItemDelegateManager* item_delegate_manager_; | 597 ash::ShelfItemDelegateManager* item_delegate_manager_; |
| 599 | 598 |
| 600 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 599 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
| 601 }; | 600 }; |
| 602 | 601 |
| 603 // The testing framework to test the legacy shelf layout. | 602 // The testing framework to test the legacy shelf layout. |
| 604 class LegacyShelfLayoutChromeLauncherControllerTest | 603 class LegacyShelfLayoutChromeLauncherControllerTest |
| 605 : public ChromeLauncherControllerTest { | 604 : public ChromeLauncherControllerTest { |
| 606 protected: | 605 protected: |
| 607 LegacyShelfLayoutChromeLauncherControllerTest() { | 606 LegacyShelfLayoutChromeLauncherControllerTest() { |
| 608 } | 607 } |
| (...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 model_->Move(1, 3); | 2632 model_->Move(1, 3); |
| 2634 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 2633 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
| 2635 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 2634 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 2636 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 2635 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 2637 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 2636 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |
| 2638 | 2637 |
| 2639 launcher_controller_.reset(); | 2638 launcher_controller_.reset(); |
| 2640 if (!ash::Shell::HasInstance()) { | 2639 if (!ash::Shell::HasInstance()) { |
| 2641 delete item_delegate_manager_; | 2640 delete item_delegate_manager_; |
| 2642 } else { | 2641 } else { |
| 2643 // Clear already registered LauncherItemDelegate. | 2642 // Clear already registered ShelfItemDelegate. |
| 2644 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); | 2643 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |
| 2645 test.RemoveAllLauncherItemDelegateForTest(); | 2644 test.RemoveAllShelfItemDelegateForTest(); |
| 2646 } | 2645 } |
| 2647 model_.reset(new ash::ShelfModel); | 2646 model_.reset(new ash::ShelfModel); |
| 2648 | 2647 |
| 2649 AddAppListLauncherItem(); | 2648 AddAppListLauncherItem(); |
| 2650 launcher_controller_.reset( | 2649 launcher_controller_.reset( |
| 2651 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 2650 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
| 2652 app_tab_helper = new TestAppTabHelperImpl; | 2651 app_tab_helper = new TestAppTabHelperImpl; |
| 2653 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 2652 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 2654 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 2653 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |
| 2655 SetAppTabHelper(app_tab_helper); | 2654 SetAppTabHelper(app_tab_helper); |
| 2656 if (!ash::Shell::HasInstance()) { | 2655 if (!ash::Shell::HasInstance()) { |
| 2657 item_delegate_manager_ = | 2656 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |
| 2658 new ash::LauncherItemDelegateManager(model_.get()); | 2657 SetShelfItemDelegateManager(item_delegate_manager_); |
| 2659 SetLauncherItemDelegateManager(item_delegate_manager_); | |
| 2660 } | 2658 } |
| 2661 launcher_controller_->Init(); | 2659 launcher_controller_->Init(); |
| 2662 | 2660 |
| 2663 // Check LauncherItems are restored after resetting ChromeLauncherController. | 2661 // Check LauncherItems are restored after resetting ChromeLauncherController. |
| 2664 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 2662 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
| 2665 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 2663 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 2666 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 2664 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 2667 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 2665 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |
| 2668 } | 2666 } |
| 2669 | 2667 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2689 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 2687 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 2690 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 2688 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 2691 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 2689 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 2692 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 2690 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 2693 EXPECT_EQ(initial_size + 1, model_->items().size()); | 2691 EXPECT_EQ(initial_size + 1, model_->items().size()); |
| 2694 | 2692 |
| 2695 launcher_controller_.reset(); | 2693 launcher_controller_.reset(); |
| 2696 if (!ash::Shell::HasInstance()) { | 2694 if (!ash::Shell::HasInstance()) { |
| 2697 delete item_delegate_manager_; | 2695 delete item_delegate_manager_; |
| 2698 } else { | 2696 } else { |
| 2699 // Clear already registered LauncherItemDelegate. | 2697 // Clear already registered ShelfItemDelegate. |
| 2700 ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_); | 2698 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |
| 2701 test.RemoveAllLauncherItemDelegateForTest(); | 2699 test.RemoveAllShelfItemDelegateForTest(); |
| 2702 } | 2700 } |
| 2703 model_.reset(new ash::ShelfModel); | 2701 model_.reset(new ash::ShelfModel); |
| 2704 | 2702 |
| 2705 AddAppListLauncherItem(); | 2703 AddAppListLauncherItem(); |
| 2706 launcher_controller_.reset( | 2704 launcher_controller_.reset( |
| 2707 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 2705 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
| 2708 app_tab_helper = new TestAppTabHelperImpl; | 2706 app_tab_helper = new TestAppTabHelperImpl; |
| 2709 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 2707 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 2710 SetAppTabHelper(app_tab_helper); | 2708 SetAppTabHelper(app_tab_helper); |
| 2711 app_icon_loader = new TestAppIconLoaderImpl; | 2709 app_icon_loader = new TestAppIconLoaderImpl; |
| 2712 SetAppIconLoader(app_icon_loader); | 2710 SetAppIconLoader(app_icon_loader); |
| 2713 if (!ash::Shell::HasInstance()) { | 2711 if (!ash::Shell::HasInstance()) { |
| 2714 item_delegate_manager_ = | 2712 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |
| 2715 new ash::LauncherItemDelegateManager(model_.get()); | 2713 SetShelfItemDelegateManager(item_delegate_manager_); |
| 2716 SetLauncherItemDelegateManager(item_delegate_manager_); | |
| 2717 } | 2714 } |
| 2718 launcher_controller_->Init(); | 2715 launcher_controller_->Init(); |
| 2719 | 2716 |
| 2720 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 2717 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 2721 ASSERT_EQ(initial_size + 1, model_->items().size()); | 2718 ASSERT_EQ(initial_size + 1, model_->items().size()); |
| 2722 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 2719 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 2723 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 2720 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 2724 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 2721 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 2725 | 2722 |
| 2726 launcher_controller_->UnpinAppWithID("1"); | 2723 launcher_controller_->UnpinAppWithID("1"); |
| 2727 ASSERT_EQ(initial_size, model_->items().size()); | 2724 ASSERT_EQ(initial_size, model_->items().size()); |
| 2728 } | 2725 } |
| OLD | NEW |