| 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 <stddef.h> |     7 #include <stddef.h> | 
|     8  |     8  | 
|     9 #include <algorithm> |     9 #include <algorithm> | 
|    10 #include <memory> |    10 #include <memory> | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|    26 #include "base/memory/ptr_util.h" |    26 #include "base/memory/ptr_util.h" | 
|    27 #include "base/message_loop/message_loop.h" |    27 #include "base/message_loop/message_loop.h" | 
|    28 #include "base/strings/utf_string_conversions.h" |    28 #include "base/strings/utf_string_conversions.h" | 
|    29 #include "base/values.h" |    29 #include "base/values.h" | 
|    30 #include "build/build_config.h" |    30 #include "build/build_config.h" | 
|    31 #include "chrome/browser/extensions/extension_service.h" |    31 #include "chrome/browser/extensions/extension_service.h" | 
|    32 #include "chrome/browser/extensions/test_extension_system.h" |    32 #include "chrome/browser/extensions/test_extension_system.h" | 
|    33 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |    33 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 
|    34 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
      roller.h" |    34 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
      roller.h" | 
|    35 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |    35 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 
 |    36 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 
|    36 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |    37 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 
|    37 #include "chrome/browser/ui/browser.h" |    38 #include "chrome/browser/ui/browser.h" | 
|    38 #include "chrome/browser/ui/browser_commands.h" |    39 #include "chrome/browser/ui/browser_commands.h" | 
|    39 #include "chrome/browser/ui/browser_finder.h" |    40 #include "chrome/browser/ui/browser_finder.h" | 
|    40 #include "chrome/browser/ui/browser_list.h" |    41 #include "chrome/browser/ui/browser_list.h" | 
|    41 #include "chrome/browser/ui/browser_tabstrip.h" |    42 #include "chrome/browser/ui/browser_tabstrip.h" | 
|    42 #include "chrome/browser/ui/tabs/tab_strip_model.h" |    43 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
|    43 #include "chrome/common/extensions/extension_constants.h" |    44 #include "chrome/common/extensions/extension_constants.h" | 
|    44 #include "chrome/common/pref_names.h" |    45 #include "chrome/common/pref_names.h" | 
|    45 #include "chrome/test/base/browser_with_test_window_test.h" |    46 #include "chrome/test/base/browser_with_test_window_test.h" | 
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   183   int clear_count() const { return clear_count_; } |   184   int clear_count() const { return clear_count_; } | 
|   184  |   185  | 
|   185  private: |   186  private: | 
|   186   int fetch_count_ = 0; |   187   int fetch_count_ = 0; | 
|   187   int clear_count_ = 0; |   188   int clear_count_ = 0; | 
|   188   std::set<std::string> supported_apps_; |   189   std::set<std::string> supported_apps_; | 
|   189  |   190  | 
|   190   DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); |   191   DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); | 
|   191 }; |   192 }; | 
|   192  |   193  | 
|   193 // Test implementation of AppTabHelper. |   194 // Test implementation of LauncherControllerHelper. | 
|   194 class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { |   195 class TestLauncherControllerHelper : public LauncherControllerHelper { | 
|   195  public: |   196  public: | 
|   196   TestAppTabHelperImpl() {} |   197   TestLauncherControllerHelper() : LauncherControllerHelper(nullptr) {} | 
|   197   ~TestAppTabHelperImpl() override {} |   198   ~TestLauncherControllerHelper() override {} | 
|   198  |   199  | 
|   199   // Sets the id for the specified tab. The id is removed if Remove() is |   200   // Sets the id for the specified tab. | 
|   200   // invoked. |  | 
|   201   void SetAppID(content::WebContents* tab, const std::string& id) { |   201   void SetAppID(content::WebContents* tab, const std::string& id) { | 
|   202     tab_id_map_[tab] = id; |   202     tab_id_map_[tab] = id; | 
|   203   } |   203   } | 
|   204  |   204  | 
|   205   // Returns true if there is an id registered for |tab|. |   205   // Returns true if there is an id registered for |tab|. | 
|   206   bool HasAppID(content::WebContents* tab) const { |   206   bool HasAppID(content::WebContents* tab) const { | 
|   207     return tab_id_map_.find(tab) != tab_id_map_.end(); |   207     return tab_id_map_.find(tab) != tab_id_map_.end(); | 
|   208   } |   208   } | 
|   209  |   209  | 
|   210   // AppTabHelper implementation: |   210   // LauncherControllerHelper: | 
|   211   std::string GetAppID(content::WebContents* tab) override { |   211   std::string GetAppID(content::WebContents* tab) override { | 
|   212     return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : |   212     return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : | 
|   213         std::string(); |   213         std::string(); | 
|   214   } |   214   } | 
|   215  |   215  | 
|   216   bool IsValidIDForCurrentUser(const std::string& id) override { |   216   bool IsValidIDForCurrentUser(const std::string& id) override { | 
|   217     for (TabToStringMap::const_iterator i = tab_id_map_.begin(); |   217     for (TabToStringMap::const_iterator i = tab_id_map_.begin(); | 
|   218          i != tab_id_map_.end(); ++i) { |   218          i != tab_id_map_.end(); ++i) { | 
|   219       if (i->second == id) |   219       if (i->second == id) | 
|   220         return true; |   220         return true; | 
|   221     } |   221     } | 
|   222     return false; |   222     return false; | 
|   223   } |   223   } | 
|   224  |   224  | 
|   225   void SetCurrentUser(Profile* profile) override { |   225   void SetCurrentUser(Profile* profile) override { | 
|   226     // We can ignore this for now. |   226     // We can ignore this for now. | 
|   227   } |   227   } | 
|   228  |   228  | 
|   229  private: |   229  private: | 
|   230   typedef std::map<content::WebContents*, std::string> TabToStringMap; |   230   typedef std::map<content::WebContents*, std::string> TabToStringMap; | 
|   231  |   231  | 
|   232   TabToStringMap tab_id_map_; |   232   TabToStringMap tab_id_map_; | 
|   233  |   233  | 
|   234   DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); |   234   DISALLOW_COPY_AND_ASSIGN(TestLauncherControllerHelper); | 
|   235 }; |   235 }; | 
|   236  |   236  | 
|   237 // Test implementation of a V2 app launcher item controller. |   237 // Test implementation of a V2 app launcher item controller. | 
|   238 class TestV2AppLauncherItemController : public LauncherItemController { |   238 class TestV2AppLauncherItemController : public LauncherItemController { | 
|   239  public: |   239  public: | 
|   240   TestV2AppLauncherItemController(const std::string& app_id, |   240   TestV2AppLauncherItemController(const std::string& app_id, | 
|   241                                   ChromeLauncherController* controller) |   241                                   ChromeLauncherController* controller) | 
|   242       : LauncherItemController(LauncherItemController::TYPE_APP, |   242       : LauncherItemController(LauncherItemController::TYPE_APP, | 
|   243                                app_id, |   243                                app_id, | 
|   244                                controller) { |   244                                controller) { | 
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   494   } |   494   } | 
|   495  |   495  | 
|   496   void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, |   496   void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, | 
|   497                          std::unique_ptr<AppIconLoader> loader2) { |   497                          std::unique_ptr<AppIconLoader> loader2) { | 
|   498     std::vector<std::unique_ptr<AppIconLoader>> loaders; |   498     std::vector<std::unique_ptr<AppIconLoader>> loaders; | 
|   499     loaders.push_back(std::move(loader1)); |   499     loaders.push_back(std::move(loader1)); | 
|   500     loaders.push_back(std::move(loader2)); |   500     loaders.push_back(std::move(loader2)); | 
|   501     launcher_controller_->SetAppIconLoadersForTest(loaders); |   501     launcher_controller_->SetAppIconLoadersForTest(loaders); | 
|   502   } |   502   } | 
|   503  |   503  | 
|   504   void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { |   504   void SetLauncherControllerHelper(LauncherControllerHelper* helper) { | 
|   505     launcher_controller_->SetAppTabHelperForTest(helper); |   505     launcher_controller_->SetLauncherControllerHelperForTest(helper); | 
|   506   } |   506   } | 
|   507  |   507  | 
|   508   void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { |   508   void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { | 
|   509     launcher_controller_->SetShelfItemDelegateManagerForTest(manager); |   509     launcher_controller_->SetShelfItemDelegateManagerForTest(manager); | 
|   510   } |   510   } | 
|   511  |   511  | 
|   512   void InsertPrefValue(base::ListValue* pref_value, |   512   void InsertPrefValue(base::ListValue* pref_value, | 
|   513                        int index, |   513                        int index, | 
|   514                        const std::string& extension_id) { |   514                        const std::string& extension_id) { | 
|   515     base::DictionaryValue* entry = new base::DictionaryValue(); |   515     base::DictionaryValue* entry = new base::DictionaryValue(); | 
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   933         CreateBrowserWithTestWindowForProfile(profile)); |   933         CreateBrowserWithTestWindowForProfile(profile)); | 
|   934     chrome::NewTab(browser.get()); |   934     chrome::NewTab(browser.get()); | 
|   935  |   935  | 
|   936     browser->window()->Show(); |   936     browser->window()->Show(); | 
|   937     NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url), |   937     NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url), | 
|   938                                         ASCIIToUTF16(title)); |   938                                         ASCIIToUTF16(title)); | 
|   939     return browser; |   939     return browser; | 
|   940   } |   940   } | 
|   941  |   941  | 
|   942   // Creates a running V1 application. |   942   // Creates a running V1 application. | 
|   943   // Note that with the use of the app_tab_helper as done below, this is only |   943   // Note that with the use of the launcher_controller_helper as done below, | 
|   944   // usable with a single v1 application. |   944   // this is only usable with a single v1 application. | 
|   945   V1App* CreateRunningV1App(Profile* profile, |   945   V1App* CreateRunningV1App(Profile* profile, | 
|   946                             const std::string& app_name, |   946                             const std::string& app_name, | 
|   947                             const std::string& url) { |   947                             const std::string& url) { | 
|   948     V1App* v1_app = new V1App(profile, app_name); |   948     V1App* v1_app = new V1App(profile, app_name); | 
|   949     // Create a new app tab helper and assign it to the launcher so that this |   949     // Create a new launcher controller helper and assign it to the launcher so | 
|   950     // app gets properly detected. |   950     // that this app gets properly detected. | 
|   951     // TODO(skuhne): Create a more intelligent app tab helper which is able to |   951     // TODO(skuhne): Create a more intelligent launcher contrller helper that is | 
|   952     // detect all running apps properly. |   952     // able to detect all running apps properly. | 
|   953     TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; |   953     TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; | 
|   954     app_tab_helper->SetAppID( |   954     helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), | 
|   955         v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), |   955                      app_name); | 
|   956         app_name); |   956     SetLauncherControllerHelper(helper); | 
|   957     SetAppTabHelper(app_tab_helper); |  | 
|   958  |   957  | 
|   959     NavigateAndCommitActiveTabWithTitle( |   958     NavigateAndCommitActiveTabWithTitle( | 
|   960         v1_app->browser(), GURL(url), ASCIIToUTF16("")); |   959         v1_app->browser(), GURL(url), ASCIIToUTF16("")); | 
|   961     return v1_app; |   960     return v1_app; | 
|   962   } |   961   } | 
|   963  |   962  | 
|   964   ash::test::TestSessionStateDelegate* session_delegate() { |   963   ash::test::TestSessionStateDelegate* session_delegate() { | 
|   965     return static_cast<ash::test::TestSessionStateDelegate*>( |   964     return static_cast<ash::test::TestSessionStateDelegate*>( | 
|   966         ash::Shell::GetInstance()->session_state_delegate()); |   965         ash::Shell::GetInstance()->session_state_delegate()); | 
|   967   } |   966   } | 
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1583   } |  1582   } | 
|  1584   SwitchActiveUser(account_id2); |  1583   SwitchActiveUser(account_id2); | 
|  1585   EXPECT_EQ(2, model_->item_count()); |  1584   EXPECT_EQ(2, model_->item_count()); | 
|  1586 } |  1585 } | 
|  1587  |  1586  | 
|  1588 // Check edge cases with multi profile V1 apps in the shelf. |  1587 // Check edge cases with multi profile V1 apps in the shelf. | 
|  1589 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, |  1588 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, | 
|  1590        V1AppUpdateOnUserSwitchEdgecases2) { |  1589        V1AppUpdateOnUserSwitchEdgecases2) { | 
|  1591   // Create a browser item in the LauncherController. |  1590   // Create a browser item in the LauncherController. | 
|  1592   InitLauncherController(); |  1591   InitLauncherController(); | 
|  1593   TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; |  1592   SetLauncherControllerHelper(new TestLauncherControllerHelper); | 
|  1594   SetAppTabHelper(app_tab_helper); |  | 
|  1595  |  1593  | 
|  1596   // First test: Create an app when the user is not active. |  1594   // First test: Create an app when the user is not active. | 
|  1597   std::string user2 = "user2"; |  1595   std::string user2 = "user2"; | 
|  1598   TestingProfile* profile2 = CreateMultiUserProfile(user2); |  1596   TestingProfile* profile2 = CreateMultiUserProfile(user2); | 
|  1599   const AccountId account_id( |  1597   const AccountId account_id( | 
|  1600       multi_user_util::GetAccountIdFromProfile(profile())); |  1598       multi_user_util::GetAccountIdFromProfile(profile())); | 
|  1601   const AccountId account_id2( |  1599   const AccountId account_id2( | 
|  1602       multi_user_util::GetAccountIdFromProfile(profile2)); |  1600       multi_user_util::GetAccountIdFromProfile(profile2)); | 
|  1603   SwitchActiveUser(account_id2); |  1601   SwitchActiveUser(account_id2); | 
|  1604   { |  1602   { | 
| (...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2746   EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |  2744   EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 
|  2747  |  2745  | 
|  2748   // The content should not be able to be handled by the app. |  2746   // The content should not be able to be handled by the app. | 
|  2749   EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); |  2747   EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); | 
|  2750 } |  2748 } | 
|  2751  |  2749  | 
|  2752 // Verify that the launcher item positions are persisted and restored. |  2750 // Verify that the launcher item positions are persisted and restored. | 
|  2753 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { |  2751 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { | 
|  2754   InitLauncherController(); |  2752   InitLauncherController(); | 
|  2755  |  2753  | 
|  2756   TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; |  2754   TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; | 
|  2757   SetAppTabHelper(app_tab_helper); |  2755   SetLauncherControllerHelper(helper); | 
|  2758  |  2756  | 
|  2759   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |  2757   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 
|  2760   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); |  2758   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); | 
|  2761  |  2759  | 
|  2762   TabStripModel* tab_strip_model = browser()->tab_strip_model(); |  2760   TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 
|  2763   EXPECT_EQ(0, tab_strip_model->count()); |  2761   EXPECT_EQ(0, tab_strip_model->count()); | 
|  2764   chrome::NewTab(browser()); |  2762   chrome::NewTab(browser()); | 
|  2765   chrome::NewTab(browser()); |  2763   chrome::NewTab(browser()); | 
|  2766   EXPECT_EQ(2, tab_strip_model->count()); |  2764   EXPECT_EQ(2, tab_strip_model->count()); | 
|  2767   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |  2765   helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 
|  2768   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |  2766   helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 
|  2769  |  2767  | 
|  2770   EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); |  2768   EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); | 
|  2771   launcher_controller_->PinAppWithID("1"); |  2769   launcher_controller_->PinAppWithID("1"); | 
|  2772   EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |  2770   EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 
|  2773   launcher_controller_->PinAppWithID("2"); |  2771   launcher_controller_->PinAppWithID("2"); | 
|  2774  |  2772  | 
|  2775   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |  2773   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 
|  2776   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); |  2774   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); | 
|  2777   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |  2775   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 
|  2778   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); |  2776   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  2791   } else { |  2789   } else { | 
|  2792     // Clear already registered ShelfItemDelegate. |  2790     // Clear already registered ShelfItemDelegate. | 
|  2793     ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |  2791     ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); | 
|  2794     test.RemoveAllShelfItemDelegateForTest(); |  2792     test.RemoveAllShelfItemDelegateForTest(); | 
|  2795   } |  2793   } | 
|  2796   model_.reset(new ash::ShelfModel); |  2794   model_.reset(new ash::ShelfModel); | 
|  2797  |  2795  | 
|  2798   AddAppListLauncherItem(); |  2796   AddAppListLauncherItem(); | 
|  2799   launcher_controller_.reset( |  2797   launcher_controller_.reset( | 
|  2800       ChromeLauncherController::CreateInstance(profile(), model_.get())); |  2798       ChromeLauncherController::CreateInstance(profile(), model_.get())); | 
|  2801   app_tab_helper = new TestAppTabHelperImpl; |  2799   helper = new TestLauncherControllerHelper; | 
|  2802   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |  2800   helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 
|  2803   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |  2801   helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 
|  2804   SetAppTabHelper(app_tab_helper); |  2802   SetLauncherControllerHelper(helper); | 
|  2805   if (!ash::Shell::HasInstance()) { |  2803   if (!ash::Shell::HasInstance()) { | 
|  2806     item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |  2804     item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); | 
|  2807     SetShelfItemDelegateManager(item_delegate_manager_); |  2805     SetShelfItemDelegateManager(item_delegate_manager_); | 
|  2808   } |  2806   } | 
|  2809   launcher_controller_->Init(); |  2807   launcher_controller_->Init(); | 
|  2810  |  2808  | 
|  2811   // Check ShelfItems are restored after resetting ChromeLauncherController. |  2809   // Check ShelfItems are restored after resetting ChromeLauncherController. | 
|  2812   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |  2810   EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 
|  2813   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |  2811   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 
|  2814   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |  2812   EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 
|  2815   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |  2813   EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 
|  2816 } |  2814 } | 
|  2817  |  2815  | 
|  2818 // Verifies pinned apps are persisted and restored. |  2816 // Verifies pinned apps are persisted and restored. | 
|  2819 TEST_F(ChromeLauncherControllerTest, PersistPinned) { |  2817 TEST_F(ChromeLauncherControllerTest, PersistPinned) { | 
|  2820   InitLauncherControllerWithBrowser(); |  2818   InitLauncherControllerWithBrowser(); | 
|  2821   size_t initial_size = model_->items().size(); |  2819   size_t initial_size = model_->items().size(); | 
|  2822  |  2820  | 
|  2823   TabStripModel* tab_strip_model = browser()->tab_strip_model(); |  2821   TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 
|  2824   EXPECT_EQ(1, tab_strip_model->count()); |  2822   EXPECT_EQ(1, tab_strip_model->count()); | 
|  2825  |  2823  | 
|  2826   TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; |  2824   TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; | 
|  2827   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |  2825   helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 
|  2828   SetAppTabHelper(app_tab_helper); |  2826   SetLauncherControllerHelper(helper); | 
|  2829  |  2827  | 
|  2830   // app_icon_loader is owned by ChromeLauncherController. |  2828   // app_icon_loader is owned by ChromeLauncherController. | 
|  2831   TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; |  2829   TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; | 
|  2832   app_icon_loader->AddSupportedApp("1"); |  2830   app_icon_loader->AddSupportedApp("1"); | 
|  2833   SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |  2831   SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 
|  2834   EXPECT_EQ(0, app_icon_loader->fetch_count()); |  2832   EXPECT_EQ(0, app_icon_loader->fetch_count()); | 
|  2835  |  2833  | 
|  2836   launcher_controller_->PinAppWithID("1"); |  2834   launcher_controller_->PinAppWithID("1"); | 
|  2837   ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1"); |  2835   ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1"); | 
|  2838   int app_index = model_->ItemIndexByID(id); |  2836   int app_index = model_->ItemIndexByID(id); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  2849   } else { |  2847   } else { | 
|  2850     // Clear already registered ShelfItemDelegate. |  2848     // Clear already registered ShelfItemDelegate. | 
|  2851     ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |  2849     ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); | 
|  2852     test.RemoveAllShelfItemDelegateForTest(); |  2850     test.RemoveAllShelfItemDelegateForTest(); | 
|  2853   } |  2851   } | 
|  2854   model_.reset(new ash::ShelfModel); |  2852   model_.reset(new ash::ShelfModel); | 
|  2855  |  2853  | 
|  2856   AddAppListLauncherItem(); |  2854   AddAppListLauncherItem(); | 
|  2857   launcher_controller_.reset( |  2855   launcher_controller_.reset( | 
|  2858       ChromeLauncherController::CreateInstance(profile(), model_.get())); |  2856       ChromeLauncherController::CreateInstance(profile(), model_.get())); | 
|  2859   app_tab_helper = new TestAppTabHelperImpl; |  2857   helper = new TestLauncherControllerHelper; | 
|  2860   app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |  2858   helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 
|  2861   SetAppTabHelper(app_tab_helper); |  2859   SetLauncherControllerHelper(helper); | 
|  2862   // app_icon_loader is owned by ChromeLauncherController. |  2860   // app_icon_loader is owned by ChromeLauncherController. | 
|  2863   app_icon_loader = new TestAppIconLoaderImpl; |  2861   app_icon_loader = new TestAppIconLoaderImpl; | 
|  2864   app_icon_loader->AddSupportedApp("1"); |  2862   app_icon_loader->AddSupportedApp("1"); | 
|  2865   SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |  2863   SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 
|  2866   if (!ash::Shell::HasInstance()) { |  2864   if (!ash::Shell::HasInstance()) { | 
|  2867     item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |  2865     item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); | 
|  2868     SetShelfItemDelegateManager(item_delegate_manager_); |  2866     SetShelfItemDelegateManager(item_delegate_manager_); | 
|  2869   } |  2867   } | 
|  2870   launcher_controller_->Init(); |  2868   launcher_controller_->Init(); | 
|  2871  |  2869  | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2940   EXPECT_EQ(1, app_icon_loader1->clear_count()); |  2938   EXPECT_EQ(1, app_icon_loader1->clear_count()); | 
|  2941   EXPECT_EQ(1, app_icon_loader2->fetch_count()); |  2939   EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 
|  2942   EXPECT_EQ(1, app_icon_loader2->clear_count()); |  2940   EXPECT_EQ(1, app_icon_loader2->clear_count()); | 
|  2943  |  2941  | 
|  2944   launcher_controller_->CloseLauncherItem(shelfId3); |  2942   launcher_controller_->CloseLauncherItem(shelfId3); | 
|  2945   EXPECT_EQ(1, app_icon_loader1->fetch_count()); |  2943   EXPECT_EQ(1, app_icon_loader1->fetch_count()); | 
|  2946   EXPECT_EQ(1, app_icon_loader1->clear_count()); |  2944   EXPECT_EQ(1, app_icon_loader1->clear_count()); | 
|  2947   EXPECT_EQ(1, app_icon_loader2->fetch_count()); |  2945   EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 
|  2948   EXPECT_EQ(1, app_icon_loader2->clear_count()); |  2946   EXPECT_EQ(1, app_icon_loader2->clear_count()); | 
|  2949 } |  2947 } | 
| OLD | NEW |