| Index: trunk/src/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc
|
| ===================================================================
|
| --- trunk/src/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc (revision 226578)
|
| +++ trunk/src/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc (working copy)
|
| @@ -9,11 +9,9 @@
|
| #include <vector>
|
|
|
| #include "ash/ash_switches.h"
|
| -#include "ash/launcher/launcher_item_delegate_manager.h"
|
| #include "ash/launcher/launcher_model.h"
|
| #include "ash/launcher/launcher_model_observer.h"
|
| #include "ash/shell.h"
|
| -#include "ash/test/launcher_item_delegate_manager_test_api.h"
|
| #include "base/command_line.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/files/file_path.h"
|
| @@ -24,7 +22,6 @@
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/test_extension_system.h"
|
| #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
|
| -#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
|
| #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
|
| #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -197,6 +194,7 @@
|
| virtual ~TestV2AppLauncherItemController() {}
|
|
|
| // Override for LauncherItemController:
|
| + virtual string16 GetTitle() OVERRIDE { return string16(); }
|
| virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE {
|
| return true;
|
| }
|
| @@ -205,8 +203,8 @@
|
| virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {}
|
| virtual void Activate(ash::LaunchSource source) OVERRIDE {}
|
| virtual void Close() OVERRIDE {}
|
| - virtual void ItemSelected(const ui::Event& event) OVERRIDE {}
|
| - virtual string16 GetTitle() OVERRIDE { return string16(); }
|
| + virtual void Clicked(const ui::Event& event) OVERRIDE {}
|
| + virtual void OnRemoved() OVERRIDE {}
|
| virtual ChromeLauncherAppMenuItems GetApplicationList(
|
| int event_flags) OVERRIDE {
|
| ChromeLauncherAppMenuItems items;
|
| @@ -214,12 +212,6 @@
|
| items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false));
|
| return items.Pass();
|
| }
|
| - virtual ui::MenuModel* CreateContextMenu(
|
| - aura::RootWindow* root_window) OVERRIDE { return NULL; }
|
| - virtual ash::LauncherMenuModel* CreateApplicationMenu(
|
| - int event_flags) OVERRIDE { return NULL; }
|
| - virtual bool IsDraggable() OVERRIDE { return false; }
|
| - virtual bool ShouldShowTooltip() OVERRIDE { return false; }
|
|
|
| private:
|
|
|
| @@ -230,8 +222,7 @@
|
|
|
| class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
|
| protected:
|
| - ChromeLauncherControllerTest() : test_controller_(NULL),
|
| - extension_service_(NULL) {
|
| + ChromeLauncherControllerTest() : extension_service_(NULL) {
|
| SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
|
| }
|
|
|
| @@ -245,14 +236,6 @@
|
| model_observer_.reset(new TestLauncherModelObserver);
|
| model_->AddObserver(model_observer_.get());
|
|
|
| - if (ash::Shell::HasInstance()) {
|
| - item_delegate_manager_ =
|
| - ash::Shell::GetInstance()->launcher_item_delegate_manager();
|
| - } else {
|
| - item_delegate_manager_ =
|
| - new ash::LauncherItemDelegateManager(model_.get());
|
| - }
|
| -
|
| DictionaryValue manifest;
|
| manifest.SetString(extensions::manifest_keys::kName,
|
| "launcher controller test extension");
|
| @@ -326,7 +309,7 @@
|
|
|
| // Creates a running V2 app (not pinned) of type |app_id|.
|
| virtual void CreateRunningV2App(const std::string& app_id) {
|
| - DCHECK(!test_controller_);
|
| + DCHECK(!test_controller_.get());
|
| ash::LauncherID id =
|
| launcher_controller_->CreateAppShortcutLauncherItemWithType(
|
| app_id,
|
| @@ -334,9 +317,9 @@
|
| ash::TYPE_PLATFORM_APP);
|
| DCHECK(id);
|
| // Change the created launcher controller into a V2 app controller.
|
| - test_controller_ = new TestV2AppLauncherItemController(app_id,
|
| - launcher_controller_.get());
|
| - launcher_controller_->SetItemController(id, test_controller_);
|
| + test_controller_.reset(new TestV2AppLauncherItemController(app_id,
|
| + launcher_controller_.get()));
|
| + launcher_controller_->SetItemController(id, test_controller_.get());
|
| }
|
|
|
| // Sets the stage for a multi user test.
|
| @@ -378,14 +361,13 @@
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| - if (!ash::Shell::HasInstance())
|
| - delete item_delegate_manager_;
|
| model_->RemoveObserver(model_observer_.get());
|
| model_observer_.reset();
|
| launcher_controller_.reset();
|
| model_.reset();
|
|
|
| BrowserWithTestWindowTest::TearDown();
|
| + test_controller_.reset();
|
| }
|
|
|
| void AddAppListLauncherItem() {
|
| @@ -398,8 +380,6 @@
|
| AddAppListLauncherItem();
|
| launcher_controller_.reset(
|
| new ChromeLauncherController(profile(), model_.get()));
|
| - if (!ash::Shell::HasInstance())
|
| - SetLauncherItemDelegateManager(item_delegate_manager_);
|
| launcher_controller_->Init();
|
| }
|
|
|
| @@ -417,11 +397,6 @@
|
| launcher_controller_->SetAppTabHelperForTest(helper);
|
| }
|
|
|
| - void SetLauncherItemDelegateManager(
|
| - ash::LauncherItemDelegateManager* manager) {
|
| - launcher_controller_->SetLauncherItemDelegateManagerForTest(manager);
|
| - }
|
| -
|
| void InsertPrefValue(base::ListValue* pref_value,
|
| int index,
|
| const std::string& extension_id) {
|
| @@ -562,14 +537,10 @@
|
| scoped_ptr<ChromeLauncherController> launcher_controller_;
|
| scoped_ptr<TestLauncherModelObserver> model_observer_;
|
| scoped_ptr<ash::LauncherModel> model_;
|
| + scoped_ptr<TestV2AppLauncherItemController> test_controller_;
|
|
|
| - // |item_delegate_manager_| owns |test_controller_|.
|
| - LauncherItemController* test_controller_;
|
| -
|
| ExtensionService* extension_service_;
|
|
|
| - ash::LauncherItemDelegateManager* item_delegate_manager_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
|
| };
|
|
|
| @@ -1532,8 +1503,7 @@
|
| }
|
|
|
| scoped_ptr<ash::LauncherMenuModel> menu(
|
| - new LauncherApplicationMenuItemModel(
|
| - controller->GetApplicationList(item, 0)));
|
| + controller->CreateApplicationMenu(item, 0));
|
| // The first element in the menu is a spacing separator. On some systems
|
| // (e.g. Windows) such things do not exist. As such we check the existence
|
| // and adjust dynamically.
|
| @@ -1697,8 +1667,7 @@
|
| // item is per definition already the active tab).
|
| {
|
| scoped_ptr<ash::LauncherMenuModel> menu(
|
| - new LauncherApplicationMenuItemModel(
|
| - launcher_controller_->GetApplicationList(item_gmail, 0)));
|
| + launcher_controller_->CreateApplicationMenu(item_gmail, 0));
|
| // The first element in the menu is a spacing separator. On some systems
|
| // (e.g. Windows) such things do not exist. As such we check the existence
|
| // and adjust dynamically.
|
| @@ -1711,8 +1680,7 @@
|
| // Execute the first item.
|
| {
|
| scoped_ptr<ash::LauncherMenuModel> menu(
|
| - new LauncherApplicationMenuItemModel(
|
| - launcher_controller_->GetApplicationList(item_gmail, 0)));
|
| + launcher_controller_->CreateApplicationMenu(item_gmail, 0));
|
| int first_item =
|
| (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0;
|
| menu->ActivatedAt(first_item + 2);
|
| @@ -1773,14 +1741,11 @@
|
|
|
| // Test adding an app panel
|
| std::string app_id = extension1_->id();
|
| - ShellWindowLauncherItemController* app_panel_controller =
|
| - new ShellWindowLauncherItemController(
|
| - LauncherItemController::TYPE_APP_PANEL,
|
| - "id",
|
| - app_id,
|
| - launcher_controller_.get());
|
| + ShellWindowLauncherItemController app_panel_controller(
|
| + LauncherItemController::TYPE_APP_PANEL, "id", app_id,
|
| + launcher_controller_.get());
|
| ash::LauncherID launcher_id1 = launcher_controller_->CreateAppLauncherItem(
|
| - app_panel_controller, app_id, ash::STATUS_RUNNING);
|
| + &app_panel_controller, app_id, ash::STATUS_RUNNING);
|
| int panel_index = model_observer_->last_index();
|
| EXPECT_EQ(3, model_observer_->added());
|
| EXPECT_EQ(0, model_observer_->changed());
|
| @@ -1791,7 +1756,7 @@
|
| EXPECT_EQ(0, launcher_controller_->GetLauncherIDForAppID(app_id));
|
|
|
| // Setting the app image image should not change the panel if it set its icon
|
| - app_panel_controller->set_image_set_by_controller(true);
|
| + app_panel_controller.set_image_set_by_controller(true);
|
| gfx::ImageSkia image;
|
| launcher_controller_->SetAppImage(app_id, image);
|
| EXPECT_EQ(0, model_observer_->changed());
|
| @@ -1799,15 +1764,8 @@
|
|
|
| // Add a second app panel and verify that it get the same index as the first
|
| // one had, being added to the left of the existing panel.
|
| - ShellWindowLauncherItemController* app_panel_controller2 =
|
| - new ShellWindowLauncherItemController(
|
| - LauncherItemController::TYPE_APP_PANEL,
|
| - "id",
|
| - app_id,
|
| - launcher_controller_.get());
|
| -
|
| ash::LauncherID launcher_id2 = launcher_controller_->CreateAppLauncherItem(
|
| - app_panel_controller2, app_id, ash::STATUS_RUNNING);
|
| + &app_panel_controller, app_id, ash::STATUS_RUNNING);
|
| EXPECT_EQ(panel_index, model_observer_->last_index());
|
| EXPECT_EQ(1, model_observer_->added());
|
| model_observer_->clear_counts();
|
| @@ -1912,20 +1870,13 @@
|
|
|
| launcher_controller_.reset();
|
| model_.reset(new ash::LauncherModel);
|
| -
|
| - // Clear already registered LauncherItemDelegate.
|
| - ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_);
|
| - test.RemoveAllLauncherItemDelegateForTest();
|
| -
|
| - AddAppListLauncherItem();
|
| launcher_controller_.reset(
|
| ChromeLauncherController::CreateInstance(profile(), model_.get()));
|
| app_tab_helper = new TestAppTabHelperImpl;
|
| app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
|
| app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
|
| SetAppTabHelper(app_tab_helper);
|
| - if (!ash::Shell::HasInstance())
|
| - SetLauncherItemDelegateManager(item_delegate_manager_);
|
| + AddAppListLauncherItem();
|
| launcher_controller_->Init();
|
|
|
| // Check LauncherItems are restored after resetting ChromeLauncherController.
|
| @@ -1962,11 +1913,6 @@
|
|
|
| launcher_controller_.reset();
|
| model_.reset(new ash::LauncherModel);
|
| -
|
| - // Clear already registered LauncherItemDelegate.
|
| - ash::test::LauncherItemDelegateManagerTestAPI test(item_delegate_manager_);
|
| - test.RemoveAllLauncherItemDelegateForTest();
|
| -
|
| AddAppListLauncherItem();
|
| launcher_controller_.reset(
|
| ChromeLauncherController::CreateInstance(profile(), model_.get()));
|
| @@ -1975,8 +1921,6 @@
|
| SetAppTabHelper(app_tab_helper);
|
| app_icon_loader = new TestAppIconLoaderImpl;
|
| SetAppIconLoader(app_icon_loader);
|
| - if (!ash::Shell::HasInstance())
|
| - SetLauncherItemDelegateManager(item_delegate_manager_);
|
| launcher_controller_->Init();
|
|
|
| EXPECT_EQ(1, app_icon_loader->fetch_count());
|
|
|