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