| 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 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 // ShelfModelObserver implementation that tracks what messages are invoked. | 88 // ShelfModelObserver implementation that tracks what messages are invoked. |
| 89 class TestShelfModelObserver : public ash::ShelfModelObserver { | 89 class TestShelfModelObserver : public ash::ShelfModelObserver { |
| 90 public: | 90 public: |
| 91 TestShelfModelObserver() | 91 TestShelfModelObserver() |
| 92 : added_(0), | 92 : added_(0), |
| 93 removed_(0), | 93 removed_(0), |
| 94 changed_(0) { | 94 changed_(0) { |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual ~TestShelfModelObserver() { | 97 ~TestShelfModelObserver() override {} |
| 98 } | |
| 99 | 98 |
| 100 // Overridden from ash::ShelfModelObserver: | 99 // Overridden from ash::ShelfModelObserver: |
| 101 virtual void ShelfItemAdded(int index) override { | 100 void ShelfItemAdded(int index) override { |
| 102 ++added_; | 101 ++added_; |
| 103 last_index_ = index; | 102 last_index_ = index; |
| 104 } | 103 } |
| 105 | 104 |
| 106 virtual void ShelfItemRemoved(int index, ash::ShelfID id) override { | 105 void ShelfItemRemoved(int index, ash::ShelfID id) override { |
| 107 ++removed_; | 106 ++removed_; |
| 108 last_index_ = index; | 107 last_index_ = index; |
| 109 } | 108 } |
| 110 | 109 |
| 111 virtual void ShelfItemChanged(int index, | 110 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override { |
| 112 const ash::ShelfItem& old_item) override { | |
| 113 ++changed_; | 111 ++changed_; |
| 114 last_index_ = index; | 112 last_index_ = index; |
| 115 } | 113 } |
| 116 | 114 |
| 117 virtual void ShelfItemMoved(int start_index, int target_index) override { | 115 void ShelfItemMoved(int start_index, int target_index) override { |
| 118 last_index_ = target_index; | 116 last_index_ = target_index; |
| 119 } | 117 } |
| 120 | 118 |
| 121 virtual void ShelfStatusChanged() override { | 119 void ShelfStatusChanged() override {} |
| 122 } | |
| 123 | 120 |
| 124 void clear_counts() { | 121 void clear_counts() { |
| 125 added_ = 0; | 122 added_ = 0; |
| 126 removed_ = 0; | 123 removed_ = 0; |
| 127 changed_ = 0; | 124 changed_ = 0; |
| 128 last_index_ = 0; | 125 last_index_ = 0; |
| 129 } | 126 } |
| 130 | 127 |
| 131 int added() const { return added_; } | 128 int added() const { return added_; } |
| 132 int removed() const { return removed_; } | 129 int removed() const { return removed_; } |
| 133 int changed() const { return changed_; } | 130 int changed() const { return changed_; } |
| 134 int last_index() const { return last_index_; } | 131 int last_index() const { return last_index_; } |
| 135 | 132 |
| 136 private: | 133 private: |
| 137 int added_; | 134 int added_; |
| 138 int removed_; | 135 int removed_; |
| 139 int changed_; | 136 int changed_; |
| 140 int last_index_; | 137 int last_index_; |
| 141 | 138 |
| 142 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); | 139 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); |
| 143 }; | 140 }; |
| 144 | 141 |
| 145 // Test implementation of AppIconLoader. | 142 // Test implementation of AppIconLoader. |
| 146 class TestAppIconLoaderImpl : public extensions::AppIconLoader { | 143 class TestAppIconLoaderImpl : public extensions::AppIconLoader { |
| 147 public: | 144 public: |
| 148 TestAppIconLoaderImpl() : fetch_count_(0) { | 145 TestAppIconLoaderImpl() : fetch_count_(0) { |
| 149 } | 146 } |
| 150 | 147 |
| 151 virtual ~TestAppIconLoaderImpl() { | 148 ~TestAppIconLoaderImpl() override {} |
| 152 } | |
| 153 | 149 |
| 154 // AppIconLoader implementation: | 150 // AppIconLoader implementation: |
| 155 virtual void FetchImage(const std::string& id) override { | 151 void FetchImage(const std::string& id) override { ++fetch_count_; } |
| 156 ++fetch_count_; | |
| 157 } | |
| 158 | 152 |
| 159 virtual void ClearImage(const std::string& id) override { | 153 void ClearImage(const std::string& id) override {} |
| 160 } | |
| 161 | 154 |
| 162 virtual void UpdateImage(const std::string& id) override { | 155 void UpdateImage(const std::string& id) override {} |
| 163 } | |
| 164 | 156 |
| 165 int fetch_count() const { return fetch_count_; } | 157 int fetch_count() const { return fetch_count_; } |
| 166 | 158 |
| 167 private: | 159 private: |
| 168 int fetch_count_; | 160 int fetch_count_; |
| 169 | 161 |
| 170 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); | 162 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); |
| 171 }; | 163 }; |
| 172 | 164 |
| 173 // Test implementation of AppTabHelper. | 165 // Test implementation of AppTabHelper. |
| 174 class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { | 166 class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { |
| 175 public: | 167 public: |
| 176 TestAppTabHelperImpl() {} | 168 TestAppTabHelperImpl() {} |
| 177 virtual ~TestAppTabHelperImpl() {} | 169 ~TestAppTabHelperImpl() override {} |
| 178 | 170 |
| 179 // Sets the id for the specified tab. The id is removed if Remove() is | 171 // Sets the id for the specified tab. The id is removed if Remove() is |
| 180 // invoked. | 172 // invoked. |
| 181 void SetAppID(content::WebContents* tab, const std::string& id) { | 173 void SetAppID(content::WebContents* tab, const std::string& id) { |
| 182 tab_id_map_[tab] = id; | 174 tab_id_map_[tab] = id; |
| 183 } | 175 } |
| 184 | 176 |
| 185 // Returns true if there is an id registered for |tab|. | 177 // Returns true if there is an id registered for |tab|. |
| 186 bool HasAppID(content::WebContents* tab) const { | 178 bool HasAppID(content::WebContents* tab) const { |
| 187 return tab_id_map_.find(tab) != tab_id_map_.end(); | 179 return tab_id_map_.find(tab) != tab_id_map_.end(); |
| 188 } | 180 } |
| 189 | 181 |
| 190 // AppTabHelper implementation: | 182 // AppTabHelper implementation: |
| 191 virtual std::string GetAppID(content::WebContents* tab) override { | 183 std::string GetAppID(content::WebContents* tab) override { |
| 192 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : | 184 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : |
| 193 std::string(); | 185 std::string(); |
| 194 } | 186 } |
| 195 | 187 |
| 196 virtual bool IsValidIDForCurrentUser(const std::string& id) override { | 188 bool IsValidIDForCurrentUser(const std::string& id) override { |
| 197 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); | 189 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); |
| 198 i != tab_id_map_.end(); ++i) { | 190 i != tab_id_map_.end(); ++i) { |
| 199 if (i->second == id) | 191 if (i->second == id) |
| 200 return true; | 192 return true; |
| 201 } | 193 } |
| 202 return false; | 194 return false; |
| 203 } | 195 } |
| 204 | 196 |
| 205 virtual void SetCurrentUser(Profile* profile) override { | 197 void SetCurrentUser(Profile* profile) override { |
| 206 // We can ignore this for now. | 198 // We can ignore this for now. |
| 207 } | 199 } |
| 208 | 200 |
| 209 private: | 201 private: |
| 210 typedef std::map<content::WebContents*, std::string> TabToStringMap; | 202 typedef std::map<content::WebContents*, std::string> TabToStringMap; |
| 211 | 203 |
| 212 TabToStringMap tab_id_map_; | 204 TabToStringMap tab_id_map_; |
| 213 | 205 |
| 214 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); | 206 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); |
| 215 }; | 207 }; |
| 216 | 208 |
| 217 // Test implementation of a V2 app launcher item controller. | 209 // Test implementation of a V2 app launcher item controller. |
| 218 class TestV2AppLauncherItemController : public LauncherItemController { | 210 class TestV2AppLauncherItemController : public LauncherItemController { |
| 219 public: | 211 public: |
| 220 TestV2AppLauncherItemController(const std::string& app_id, | 212 TestV2AppLauncherItemController(const std::string& app_id, |
| 221 ChromeLauncherController* controller) | 213 ChromeLauncherController* controller) |
| 222 : LauncherItemController(LauncherItemController::TYPE_APP, | 214 : LauncherItemController(LauncherItemController::TYPE_APP, |
| 223 app_id, | 215 app_id, |
| 224 controller) { | 216 controller) { |
| 225 } | 217 } |
| 226 | 218 |
| 227 virtual ~TestV2AppLauncherItemController() {} | 219 ~TestV2AppLauncherItemController() override {} |
| 228 | 220 |
| 229 // Override for LauncherItemController: | 221 // Override for LauncherItemController: |
| 230 virtual bool IsOpen() const override { return true; } | 222 bool IsOpen() const override { return true; } |
| 231 virtual bool IsVisible() const override { return true; } | 223 bool IsVisible() const override { return true; } |
| 232 virtual void Launch(ash::LaunchSource source, int event_flags) override {} | 224 void Launch(ash::LaunchSource source, int event_flags) override {} |
| 233 virtual bool Activate(ash::LaunchSource source) override { return false; } | 225 bool Activate(ash::LaunchSource source) override { return false; } |
| 234 virtual void Close() override {} | 226 void Close() override {} |
| 235 virtual bool ItemSelected(const ui::Event& event) override { return false; } | 227 bool ItemSelected(const ui::Event& event) override { return false; } |
| 236 virtual base::string16 GetTitle() override { return base::string16(); } | 228 base::string16 GetTitle() override { return base::string16(); } |
| 237 virtual ChromeLauncherAppMenuItems GetApplicationList( | 229 ChromeLauncherAppMenuItems GetApplicationList(int event_flags) override { |
| 238 int event_flags) override { | |
| 239 ChromeLauncherAppMenuItems items; | 230 ChromeLauncherAppMenuItems items; |
| 240 items.push_back( | 231 items.push_back( |
| 241 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); | 232 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); |
| 242 items.push_back( | 233 items.push_back( |
| 243 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); | 234 new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); |
| 244 return items.Pass(); | 235 return items.Pass(); |
| 245 } | 236 } |
| 246 virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) override { | 237 ui::MenuModel* CreateContextMenu(aura::Window* root_window) override { |
| 247 return NULL; | 238 return NULL; |
| 248 } | 239 } |
| 249 virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override { | 240 ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override { |
| 250 return NULL; | 241 return NULL; |
| 251 } | 242 } |
| 252 virtual bool IsDraggable() override { return false; } | 243 bool IsDraggable() override { return false; } |
| 253 virtual bool ShouldShowTooltip() override { return false; } | 244 bool ShouldShowTooltip() override { return false; } |
| 254 | 245 |
| 255 private: | 246 private: |
| 256 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | 247 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); |
| 257 }; | 248 }; |
| 258 | 249 |
| 259 } // namespace | 250 } // namespace |
| 260 | 251 |
| 261 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { | 252 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { |
| 262 protected: | 253 protected: |
| 263 ChromeLauncherControllerTest() | 254 ChromeLauncherControllerTest() |
| 264 : BrowserWithTestWindowTest( | 255 : BrowserWithTestWindowTest( |
| 265 Browser::TYPE_TABBED, | 256 Browser::TYPE_TABBED, |
| 266 chrome::HOST_DESKTOP_TYPE_ASH, | 257 chrome::HOST_DESKTOP_TYPE_ASH, |
| 267 false), | 258 false), |
| 268 test_controller_(NULL), | 259 test_controller_(NULL), |
| 269 extension_service_(NULL) { | 260 extension_service_(NULL) { |
| 270 } | 261 } |
| 271 | 262 |
| 272 virtual ~ChromeLauncherControllerTest() { | 263 ~ChromeLauncherControllerTest() override {} |
| 273 } | |
| 274 | 264 |
| 275 virtual void SetUp() override { | 265 void SetUp() override { |
| 276 BrowserWithTestWindowTest::SetUp(); | 266 BrowserWithTestWindowTest::SetUp(); |
| 277 | 267 |
| 278 model_.reset(new ash::ShelfModel); | 268 model_.reset(new ash::ShelfModel); |
| 279 model_observer_.reset(new TestShelfModelObserver); | 269 model_observer_.reset(new TestShelfModelObserver); |
| 280 model_->AddObserver(model_observer_.get()); | 270 model_->AddObserver(model_observer_.get()); |
| 281 | 271 |
| 282 if (ash::Shell::HasInstance()) { | 272 if (ash::Shell::HasInstance()) { |
| 283 item_delegate_manager_ = | 273 item_delegate_manager_ = |
| 284 ash::Shell::GetInstance()->shelf_item_delegate_manager(); | 274 ash::Shell::GetInstance()->shelf_item_delegate_manager(); |
| 285 } else { | 275 } else { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 InsertPrefValue(user_a, 2, extension3_->id()); | 394 InsertPrefValue(user_a, 2, extension3_->id()); |
| 405 InsertPrefValue(user_a, 3, extension4_->id()); | 395 InsertPrefValue(user_a, 3, extension4_->id()); |
| 406 InsertPrefValue(user_a, 4, extension5_->id()); | 396 InsertPrefValue(user_a, 4, extension5_->id()); |
| 407 InsertPrefValue(user_a, 5, extension6_->id()); | 397 InsertPrefValue(user_a, 5, extension6_->id()); |
| 408 | 398 |
| 409 // Set user b preferences. | 399 // Set user b preferences. |
| 410 InsertPrefValue(user_b, 0, extension7_->id()); | 400 InsertPrefValue(user_b, 0, extension7_->id()); |
| 411 InsertPrefValue(user_b, 1, extension8_->id()); | 401 InsertPrefValue(user_b, 1, extension8_->id()); |
| 412 } | 402 } |
| 413 | 403 |
| 414 virtual void TearDown() override { | 404 void TearDown() override { |
| 415 if (!ash::Shell::HasInstance()) | 405 if (!ash::Shell::HasInstance()) |
| 416 delete item_delegate_manager_; | 406 delete item_delegate_manager_; |
| 417 model_->RemoveObserver(model_observer_.get()); | 407 model_->RemoveObserver(model_observer_.get()); |
| 418 model_observer_.reset(); | 408 model_observer_.reset(); |
| 419 launcher_controller_.reset(); | 409 launcher_controller_.reset(); |
| 420 model_.reset(); | 410 model_.reset(); |
| 421 | 411 |
| 422 BrowserWithTestWindowTest::TearDown(); | 412 BrowserWithTestWindowTest::TearDown(); |
| 423 } | 413 } |
| 424 | 414 |
| (...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2686 | 2676 |
| 2687 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 2677 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 2688 ASSERT_EQ(initial_size + 1, model_->items().size()); | 2678 ASSERT_EQ(initial_size + 1, model_->items().size()); |
| 2689 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 2679 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 2690 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 2680 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 2691 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 2681 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 2692 | 2682 |
| 2693 launcher_controller_->UnpinAppWithID("1"); | 2683 launcher_controller_->UnpinAppWithID("1"); |
| 2694 ASSERT_EQ(initial_size, model_->items().size()); | 2684 ASSERT_EQ(initial_size, model_->items().size()); |
| 2695 } | 2685 } |
| OLD | NEW |