| 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_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.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 21 matching lines...) Expand all Loading... |
| 32 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 33 #include "base/threading/thread_task_runner_handle.h" | 33 #include "base/threading/thread_task_runner_handle.h" |
| 34 #include "base/values.h" | 34 #include "base/values.h" |
| 35 #include "build/build_config.h" | 35 #include "build/build_config.h" |
| 36 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 36 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 37 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 37 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 38 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 38 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 39 #include "chrome/browser/extensions/extension_service.h" | 39 #include "chrome/browser/extensions/extension_service.h" |
| 40 #include "chrome/browser/extensions/test_extension_system.h" | 40 #include "chrome/browser/extensions/test_extension_system.h" |
| 41 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 41 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 42 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 42 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 43 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 43 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 44 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 44 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 45 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 45 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 46 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 46 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 47 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 48 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 48 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 49 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 49 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" | 50 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" |
| 50 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 51 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| 51 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 52 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 78 #include "components/user_manager/fake_user_manager.h" | 79 #include "components/user_manager/fake_user_manager.h" |
| 79 #include "content/public/browser/web_contents.h" | 80 #include "content/public/browser/web_contents.h" |
| 80 #include "content/public/browser/web_contents_observer.h" | 81 #include "content/public/browser/web_contents_observer.h" |
| 81 #include "content/public/test/test_utils.h" | 82 #include "content/public/test/test_utils.h" |
| 82 #include "content/public/test/web_contents_tester.h" | 83 #include "content/public/test/web_contents_tester.h" |
| 83 #include "extensions/browser/app_window/app_window_contents.h" | 84 #include "extensions/browser/app_window/app_window_contents.h" |
| 84 #include "extensions/browser/app_window/app_window_registry.h" | 85 #include "extensions/browser/app_window/app_window_registry.h" |
| 85 #include "extensions/browser/app_window/native_app_window.h" | 86 #include "extensions/browser/app_window/native_app_window.h" |
| 86 #include "extensions/common/extension.h" | 87 #include "extensions/common/extension.h" |
| 87 #include "extensions/common/manifest_constants.h" | 88 #include "extensions/common/manifest_constants.h" |
| 89 #include "sync/api/fake_sync_change_processor.h" |
| 90 #include "sync/api/sync_error_factory_mock.h" |
| 91 #include "sync/protocol/sync.pb.h" |
| 88 #include "testing/gtest/include/gtest/gtest.h" | 92 #include "testing/gtest/include/gtest/gtest.h" |
| 89 #include "ui/aura/client/window_tree_client.h" | 93 #include "ui/aura/client/window_tree_client.h" |
| 90 #include "ui/aura/window.h" | 94 #include "ui/aura/window.h" |
| 91 #include "ui/base/models/menu_model.h" | 95 #include "ui/base/models/menu_model.h" |
| 92 #include "ui/views/widget/widget.h" | 96 #include "ui/views/widget/widget.h" |
| 93 | 97 |
| 94 using base::ASCIIToUTF16; | 98 using base::ASCIIToUTF16; |
| 95 using extensions::Extension; | 99 using extensions::Extension; |
| 96 using extensions::Manifest; | 100 using extensions::Manifest; |
| 97 using extensions::UnloadedExtensionInfo; | 101 using extensions::UnloadedExtensionInfo; |
| 98 | 102 |
| 99 namespace { | 103 namespace { |
| 100 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; | 104 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; |
| 101 const char* gmail_url = "https://mail.google.com/mail/u"; | 105 const char* gmail_url = "https://mail.google.com/mail/u"; |
| 102 const char* kGmailLaunchURL = "https://mail.google.com/mail/ca"; | 106 const char* kGmailLaunchURL = "https://mail.google.com/mail/ca"; |
| 103 | 107 |
| 104 // An extension prefix. | 108 // An extension prefix. |
| 105 const char kCrxAppPrefix[] = "_crx_"; | 109 const char kCrxAppPrefix[] = "_crx_"; |
| 106 | 110 |
| 111 // Dummy app id is used to put at least one pin record to prevent initializing |
| 112 // pin model with default apps that can affect some tests. |
| 113 const char kDummyAppId[] = "dummyappid_dummyappid_dummyappid"; |
| 114 |
| 107 // ShelfModelObserver implementation that tracks what messages are invoked. | 115 // ShelfModelObserver implementation that tracks what messages are invoked. |
| 108 class TestShelfModelObserver : public ash::ShelfModelObserver { | 116 class TestShelfModelObserver : public ash::ShelfModelObserver { |
| 109 public: | 117 public: |
| 110 TestShelfModelObserver() | 118 TestShelfModelObserver() |
| 111 : added_(0), | 119 : added_(0), |
| 112 removed_(0), | 120 removed_(0), |
| 113 changed_(0) { | 121 changed_(0) { |
| 114 } | 122 } |
| 115 | 123 |
| 116 ~TestShelfModelObserver() override {} | 124 ~TestShelfModelObserver() override {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 int clear_count_ = 0; | 191 int clear_count_ = 0; |
| 184 std::set<std::string> supported_apps_; | 192 std::set<std::string> supported_apps_; |
| 185 | 193 |
| 186 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); | 194 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); |
| 187 }; | 195 }; |
| 188 | 196 |
| 189 // Test implementation of LauncherControllerHelper. | 197 // Test implementation of LauncherControllerHelper. |
| 190 class TestLauncherControllerHelper : public LauncherControllerHelper { | 198 class TestLauncherControllerHelper : public LauncherControllerHelper { |
| 191 public: | 199 public: |
| 192 TestLauncherControllerHelper() : LauncherControllerHelper(nullptr) {} | 200 TestLauncherControllerHelper() : LauncherControllerHelper(nullptr) {} |
| 201 explicit TestLauncherControllerHelper(Profile* profile) |
| 202 : LauncherControllerHelper(profile) {} |
| 193 ~TestLauncherControllerHelper() override {} | 203 ~TestLauncherControllerHelper() override {} |
| 194 | 204 |
| 195 // Sets the id for the specified tab. | 205 // Sets the id for the specified tab. |
| 196 void SetAppID(content::WebContents* tab, const std::string& id) { | 206 void SetAppID(content::WebContents* tab, const std::string& id) { |
| 197 tab_id_map_[tab] = id; | 207 tab_id_map_[tab] = id; |
| 198 } | 208 } |
| 199 | 209 |
| 200 // Returns true if there is an id registered for |tab|. | 210 // Returns true if there is an id registered for |tab|. |
| 201 bool HasAppID(content::WebContents* tab) const { | 211 bool HasAppID(content::WebContents* tab) const { |
| 202 return tab_id_map_.find(tab) != tab_id_map_.end(); | 212 return tab_id_map_.find(tab) != tab_id_map_.end(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { | 294 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { |
| 285 protected: | 295 protected: |
| 286 ChromeLauncherControllerImplTest() | 296 ChromeLauncherControllerImplTest() |
| 287 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false), | 297 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false), |
| 288 test_controller_(NULL), | 298 test_controller_(NULL), |
| 289 extension_service_(NULL) {} | 299 extension_service_(NULL) {} |
| 290 | 300 |
| 291 ~ChromeLauncherControllerImplTest() override {} | 301 ~ChromeLauncherControllerImplTest() override {} |
| 292 | 302 |
| 293 void SetUp() override { | 303 void SetUp() override { |
| 304 app_list::AppListSyncableServiceFactory::SetUseInTesting(); |
| 305 |
| 294 BrowserWithTestWindowTest::SetUp(); | 306 BrowserWithTestWindowTest::SetUp(); |
| 295 | 307 |
| 308 if (!profile_manager_) { |
| 309 profile_manager_.reset( |
| 310 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 311 ASSERT_TRUE(profile_manager_->SetUp()); |
| 312 } |
| 313 |
| 296 model_.reset(new ash::ShelfModel); | 314 model_.reset(new ash::ShelfModel); |
| 297 model_observer_.reset(new TestShelfModelObserver); | 315 model_observer_.reset(new TestShelfModelObserver); |
| 298 model_->AddObserver(model_observer_.get()); | 316 model_->AddObserver(model_observer_.get()); |
| 299 | 317 |
| 300 if (ash::Shell::HasInstance()) { | 318 if (ash::Shell::HasInstance()) { |
| 301 item_delegate_manager_ = | 319 item_delegate_manager_ = |
| 302 ash::Shell::GetInstance()->shelf_item_delegate_manager(); | 320 ash::Shell::GetInstance()->shelf_item_delegate_manager(); |
| 303 } else { | 321 } else { |
| 304 item_delegate_manager_ = | 322 item_delegate_manager_ = |
| 305 new ash::ShelfItemDelegateManager(model_.get()); | 323 new ash::ShelfItemDelegateManager(model_.get()); |
| 306 } | 324 } |
| 307 | 325 |
| 308 base::DictionaryValue manifest; | 326 base::DictionaryValue manifest; |
| 309 manifest.SetString(extensions::manifest_keys::kName, | 327 manifest.SetString(extensions::manifest_keys::kName, |
| 310 "launcher controller test extension"); | 328 "launcher controller test extension"); |
| 311 manifest.SetString(extensions::manifest_keys::kVersion, "1"); | 329 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| 312 manifest.SetString(extensions::manifest_keys::kDescription, | 330 manifest.SetString(extensions::manifest_keys::kDescription, |
| 313 "for testing pinned apps"); | 331 "for testing pinned apps"); |
| 314 | 332 |
| 315 extensions::TestExtensionSystem* extension_system( | 333 extensions::TestExtensionSystem* extension_system( |
| 316 static_cast<extensions::TestExtensionSystem*>( | 334 static_cast<extensions::TestExtensionSystem*>( |
| 317 extensions::ExtensionSystem::Get(profile()))); | 335 extensions::ExtensionSystem::Get(profile()))); |
| 318 extension_service_ = extension_system->CreateExtensionService( | 336 extension_service_ = extension_system->CreateExtensionService( |
| 319 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); | 337 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 338 extension_service_->Init(); |
| 339 |
| 340 app_service_ = |
| 341 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); |
| 342 StartAppSyncService(syncer::SyncDataList()); |
| 320 | 343 |
| 321 std::string error; | 344 std::string error; |
| 322 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 345 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
| 323 manifest, | 346 manifest, |
| 324 Extension::NO_FLAGS, | 347 Extension::NO_FLAGS, |
| 325 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | 348 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 326 &error); | 349 &error); |
| 327 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 350 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
| 328 manifest, | 351 manifest, |
| 329 Extension::NO_FLAGS, | 352 Extension::NO_FLAGS, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 model_->item_count(), | 408 model_->item_count(), |
| 386 ash::TYPE_PLATFORM_APP); | 409 ash::TYPE_PLATFORM_APP); |
| 387 DCHECK(id); | 410 DCHECK(id); |
| 388 // Change the created launcher controller into a V2 app controller. | 411 // Change the created launcher controller into a V2 app controller. |
| 389 test_controller_ = new TestV2AppLauncherItemController(app_id, | 412 test_controller_ = new TestV2AppLauncherItemController(app_id, |
| 390 launcher_controller_.get()); | 413 launcher_controller_.get()); |
| 391 launcher_controller_->SetItemController(id, test_controller_); | 414 launcher_controller_->SetItemController(id, test_controller_); |
| 392 } | 415 } |
| 393 | 416 |
| 394 // Sets the stage for a multi user test. | 417 // Sets the stage for a multi user test. |
| 395 virtual void SetUpMultiUserScenario(base::ListValue* user_a, | 418 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a, |
| 396 base::ListValue* user_b) { | 419 syncer::SyncChangeList* user_b) { |
| 397 InitLauncherController(); | 420 InitLauncherController(); |
| 398 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 421 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 399 | 422 |
| 400 // Set an empty pinned pref to begin with. | 423 // Set an empty pinned pref to begin with. |
| 401 base::ListValue no_user; | 424 syncer::SyncChangeList sync_list; |
| 402 SetShelfChromeIconIndex(0); | 425 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId); |
| 403 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 426 SendPinChanges(sync_list, true); |
| 404 no_user.DeepCopy()); | |
| 405 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 427 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 406 | 428 |
| 407 // Assume all applications have been added already. | 429 // Assume all applications have been added already. |
| 408 extension_service_->AddExtension(extension1_.get()); | 430 extension_service_->AddExtension(extension1_.get()); |
| 409 extension_service_->AddExtension(extension2_.get()); | 431 extension_service_->AddExtension(extension2_.get()); |
| 410 extension_service_->AddExtension(extension3_.get()); | 432 extension_service_->AddExtension(extension3_.get()); |
| 411 extension_service_->AddExtension(extension4_.get()); | 433 extension_service_->AddExtension(extension4_.get()); |
| 412 extension_service_->AddExtension(extension5_.get()); | 434 extension_service_->AddExtension(extension5_.get()); |
| 413 extension_service_->AddExtension(extension6_.get()); | 435 extension_service_->AddExtension(extension6_.get()); |
| 414 extension_service_->AddExtension(extension7_.get()); | 436 extension_service_->AddExtension(extension7_.get()); |
| 415 extension_service_->AddExtension(extension8_.get()); | 437 extension_service_->AddExtension(extension8_.get()); |
| 416 // There should be nothing in the list by now. | 438 // There should be nothing in the list by now. |
| 417 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 439 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 418 | 440 |
| 419 // Set user a preferences. | 441 // Set user a preferences. |
| 420 InsertPrefValue(user_a, 0, extension1_->id()); | 442 InsertAddPinChange(user_a, 0, extension1_->id()); |
| 421 InsertPrefValue(user_a, 1, extension2_->id()); | 443 InsertAddPinChange(user_a, 1, extension2_->id()); |
| 422 InsertPrefValue(user_a, 2, extension3_->id()); | 444 InsertAddPinChange(user_a, 2, extension3_->id()); |
| 423 InsertPrefValue(user_a, 3, extension4_->id()); | 445 InsertAddPinChange(user_a, 3, extension4_->id()); |
| 424 InsertPrefValue(user_a, 4, extension5_->id()); | 446 InsertAddPinChange(user_a, 4, extension5_->id()); |
| 425 InsertPrefValue(user_a, 5, extension6_->id()); | 447 InsertAddPinChange(user_a, 5, extension6_->id()); |
| 448 InsertAddPinChange(user_a, 6, extension_misc::kChromeAppId); |
| 426 | 449 |
| 427 // Set user b preferences. | 450 // Set user b preferences. |
| 428 InsertPrefValue(user_b, 0, extension7_->id()); | 451 InsertAddPinChange(user_b, 0, extension7_->id()); |
| 429 InsertPrefValue(user_b, 1, extension8_->id()); | 452 InsertAddPinChange(user_b, 1, extension8_->id()); |
| 453 InsertAddPinChange(user_b, 2, extension_misc::kChromeAppId); |
| 430 } | 454 } |
| 431 | 455 |
| 432 void TearDown() override { | 456 void TearDown() override { |
| 433 arc_test_.TearDown(); | 457 arc_test_.TearDown(); |
| 434 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr); | 458 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr); |
| 435 model_->RemoveObserver(model_observer_.get()); | 459 model_->RemoveObserver(model_observer_.get()); |
| 436 model_observer_.reset(); | 460 model_observer_.reset(); |
| 437 launcher_controller_.reset(); | 461 launcher_controller_.reset(); |
| 438 | 462 |
| 439 // item_delegate_manager_ must be deleted after launch_controller_, | 463 // item_delegate_manager_ must be deleted after launch_controller_, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 SetShelfItemDelegateManager(item_delegate_manager_); | 497 SetShelfItemDelegateManager(item_delegate_manager_); |
| 474 launcher_controller_->Init(); | 498 launcher_controller_->Init(); |
| 475 } | 499 } |
| 476 | 500 |
| 477 void InitLauncherControllerWithBrowser() { | 501 void InitLauncherControllerWithBrowser() { |
| 478 InitLauncherController(); | 502 InitLauncherController(); |
| 479 chrome::NewTab(browser()); | 503 chrome::NewTab(browser()); |
| 480 browser()->window()->Show(); | 504 browser()->window()->Show(); |
| 481 } | 505 } |
| 482 | 506 |
| 507 void RecreateChromeLauncher() { |
| 508 model_.reset(new ash::ShelfModel); |
| 509 AddAppListLauncherItem(); |
| 510 launcher_controller_.reset( |
| 511 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); |
| 512 launcher_controller_->Init(); |
| 513 } |
| 514 |
| 515 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { |
| 516 app_service_->MergeDataAndStartSyncing( |
| 517 syncer::APP_LIST, init_sync_list, |
| 518 base::WrapUnique(new syncer::FakeSyncChangeProcessor()), |
| 519 base::WrapUnique(new syncer::SyncErrorFactoryMock())); |
| 520 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); |
| 521 } |
| 522 |
| 523 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); } |
| 524 |
| 483 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) { | 525 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) { |
| 484 std::vector<std::unique_ptr<AppIconLoader>> loaders; | 526 std::vector<std::unique_ptr<AppIconLoader>> loaders; |
| 485 loaders.push_back(std::move(loader)); | 527 loaders.push_back(std::move(loader)); |
| 486 launcher_controller_->SetAppIconLoadersForTest(loaders); | 528 launcher_controller_->SetAppIconLoadersForTest(loaders); |
| 487 } | 529 } |
| 488 | 530 |
| 489 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, | 531 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, |
| 490 std::unique_ptr<AppIconLoader> loader2) { | 532 std::unique_ptr<AppIconLoader> loader2) { |
| 491 std::vector<std::unique_ptr<AppIconLoader>> loaders; | 533 std::vector<std::unique_ptr<AppIconLoader>> loaders; |
| 492 loaders.push_back(std::move(loader1)); | 534 loaders.push_back(std::move(loader1)); |
| 493 loaders.push_back(std::move(loader2)); | 535 loaders.push_back(std::move(loader2)); |
| 494 launcher_controller_->SetAppIconLoadersForTest(loaders); | 536 launcher_controller_->SetAppIconLoadersForTest(loaders); |
| 495 } | 537 } |
| 496 | 538 |
| 497 void SetLauncherControllerHelper(LauncherControllerHelper* helper) { | 539 void SetLauncherControllerHelper(LauncherControllerHelper* helper) { |
| 498 launcher_controller_->SetLauncherControllerHelperForTest(helper); | 540 launcher_controller_->SetLauncherControllerHelperForTest(helper); |
| 499 } | 541 } |
| 500 | 542 |
| 501 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { | 543 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { |
| 502 launcher_controller_->SetShelfItemDelegateManagerForTest(manager); | 544 launcher_controller_->SetShelfItemDelegateManagerForTest(manager); |
| 503 } | 545 } |
| 504 | 546 |
| 505 void InsertPrefValue(base::ListValue* pref_value, | 547 void InsertPrefValue(base::ListValue* pref_value, |
| 506 int index, | 548 int index, |
| 507 const std::string& extension_id) { | 549 const std::string& extension_id) { |
| 508 base::DictionaryValue* entry = new base::DictionaryValue(); | 550 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 509 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); | 551 entry->SetString(ash::launcher::kPinnedAppsPrefAppIDPath, extension_id); |
| 510 pref_value->Insert(index, entry); | 552 pref_value->Insert(index, entry); |
| 511 } | 553 } |
| 512 | 554 |
| 555 void InsertRemoveAllPinsChange(syncer::SyncChangeList* list) { |
| 556 for (const auto& sync_peer : app_service_->sync_items()) { |
| 557 sync_pb::EntitySpecifics specifics; |
| 558 sync_pb::AppListSpecifics* app_list_specifics = |
| 559 specifics.mutable_app_list(); |
| 560 app_list_specifics->set_item_id(sync_peer.first); |
| 561 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP); |
| 562 syncer::SyncData sync_data = |
| 563 syncer::SyncData::CreateLocalData(sync_peer.first, "Test", specifics); |
| 564 list->push_back(syncer::SyncChange( |
| 565 FROM_HERE, syncer::SyncChange::ACTION_DELETE, sync_data)); |
| 566 } |
| 567 } |
| 568 |
| 569 syncer::StringOrdinal GeneratePinPosition(int position) { |
| 570 syncer::StringOrdinal ordinal_position = |
| 571 syncer::StringOrdinal::CreateInitialOrdinal(); |
| 572 for (int i = 0; i < position; ++i) |
| 573 ordinal_position = ordinal_position.CreateAfter(); |
| 574 return ordinal_position; |
| 575 } |
| 576 |
| 577 void InsertPinChange(syncer::SyncChangeList* list, |
| 578 int position, |
| 579 bool add_pin_change, |
| 580 const std::string& app_id, |
| 581 syncer::SyncChange::SyncChangeType type) { |
| 582 sync_pb::EntitySpecifics specifics; |
| 583 sync_pb::AppListSpecifics* app_list_specifics = |
| 584 specifics.mutable_app_list(); |
| 585 app_list_specifics->set_item_id(app_id); |
| 586 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP); |
| 587 if (add_pin_change) { |
| 588 if (position >= 0) { |
| 589 app_list_specifics->set_item_pin_ordinal( |
| 590 GeneratePinPosition(position).ToInternalValue()); |
| 591 } else { |
| 592 app_list_specifics->set_item_pin_ordinal(std::string()); |
| 593 } |
| 594 } |
| 595 syncer::SyncData sync_data = |
| 596 syncer::SyncData::CreateLocalData(app_id, "Test", specifics); |
| 597 list->push_back(syncer::SyncChange(FROM_HERE, type, sync_data)); |
| 598 } |
| 599 |
| 600 void InsertAddPinChange(syncer::SyncChangeList* list, |
| 601 int position, |
| 602 const std::string& app_id) { |
| 603 InsertPinChange(list, position, true, app_id, |
| 604 syncer::SyncChange::ACTION_ADD); |
| 605 } |
| 606 |
| 607 void InsertUpdatePinChange(syncer::SyncChangeList* list, |
| 608 int position, |
| 609 const std::string& app_id) { |
| 610 InsertPinChange(list, position, true, app_id, |
| 611 syncer::SyncChange::ACTION_UPDATE); |
| 612 } |
| 613 |
| 614 void InsertRemovePinChange(syncer::SyncChangeList* list, |
| 615 const std::string& app_id) { |
| 616 InsertPinChange(list, -1, true, app_id, syncer::SyncChange::ACTION_UPDATE); |
| 617 } |
| 618 |
| 619 void InsertLegacyPinChange(syncer::SyncChangeList* list, |
| 620 const std::string& app_id) { |
| 621 InsertPinChange(list, -1, false, app_id, syncer::SyncChange::ACTION_UPDATE); |
| 622 } |
| 623 |
| 624 void ResetPinModel() { |
| 625 syncer::SyncChangeList sync_list; |
| 626 InsertRemoveAllPinsChange(&sync_list); |
| 627 InsertAddPinChange(&sync_list, 0, kDummyAppId); |
| 628 app_service_->ProcessSyncChanges(FROM_HERE, sync_list); |
| 629 } |
| 630 |
| 631 void SendPinChanges(const syncer::SyncChangeList& sync_list, |
| 632 bool reset_pin_model) { |
| 633 if (!reset_pin_model) { |
| 634 app_service_->ProcessSyncChanges(FROM_HERE, sync_list); |
| 635 } else { |
| 636 syncer::SyncChangeList combined_sync_list; |
| 637 InsertRemoveAllPinsChange(&combined_sync_list); |
| 638 combined_sync_list.insert(combined_sync_list.end(), sync_list.begin(), |
| 639 sync_list.end()); |
| 640 app_service_->ProcessSyncChanges(FROM_HERE, combined_sync_list); |
| 641 } |
| 642 } |
| 643 |
| 644 // Set the index at which the chrome icon should be. |
| 645 void SetShelfChromeIconIndex(int index) { |
| 646 DCHECK( |
| 647 app_service_->GetPinPosition(extension_misc::kChromeAppId).IsValid()); |
| 648 syncer::StringOrdinal chrome_position; |
| 649 chrome_position = index == 0 ? GeneratePinPosition(0).CreateBefore() |
| 650 : GeneratePinPosition(index - 1).CreateBetween( |
| 651 GeneratePinPosition(index)); |
| 652 |
| 653 syncer::SyncChangeList sync_list; |
| 654 sync_pb::EntitySpecifics specifics; |
| 655 sync_pb::AppListSpecifics* app_list_specifics = |
| 656 specifics.mutable_app_list(); |
| 657 app_list_specifics->set_item_id(extension_misc::kChromeAppId); |
| 658 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP); |
| 659 app_list_specifics->set_item_pin_ordinal(chrome_position.ToInternalValue()); |
| 660 syncer::SyncData sync_data = syncer::SyncData::CreateLocalData( |
| 661 extension_misc::kChromeAppId, "Test", specifics); |
| 662 sync_list.push_back(syncer::SyncChange( |
| 663 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data)); |
| 664 app_service_->ProcessSyncChanges(FROM_HERE, sync_list); |
| 665 } |
| 666 |
| 513 // Gets the currently configured app launchers from the controller. | 667 // Gets the currently configured app launchers from the controller. |
| 514 void GetAppLaunchers(ChromeLauncherControllerImpl* controller, | 668 void GetAppLaunchers(ChromeLauncherControllerImpl* controller, |
| 515 std::vector<std::string>* launchers) { | 669 std::vector<std::string>* launchers) { |
| 516 launchers->clear(); | 670 launchers->clear(); |
| 517 for (ash::ShelfItems::const_iterator iter(model_->items().begin()); | 671 for (ash::ShelfItems::const_iterator iter(model_->items().begin()); |
| 518 iter != model_->items().end(); ++iter) { | 672 iter != model_->items().end(); ++iter) { |
| 519 ChromeLauncherControllerImpl::IDToItemControllerMap::const_iterator entry( | 673 ChromeLauncherControllerImpl::IDToItemControllerMap::const_iterator entry( |
| 520 controller->id_to_item_controller_map_.find(iter->id)); | 674 controller->id_to_item_controller_map_.find(iter->id)); |
| 521 if (iter->type == ash::TYPE_APP_SHORTCUT && | 675 if (iter->type == ash::TYPE_APP_SHORTCUT && |
| 522 entry != controller->id_to_item_controller_map_.end()) { | 676 entry != controller->id_to_item_controller_map_.end()) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id())); | 752 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id())); |
| 599 } else if (app == extension6_->id()) { | 753 } else if (app == extension6_->id()) { |
| 600 result += "App6"; | 754 result += "App6"; |
| 601 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); | 755 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); |
| 602 } else if (app == extension7_->id()) { | 756 } else if (app == extension7_->id()) { |
| 603 result += "App7"; | 757 result += "App7"; |
| 604 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); | 758 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); |
| 605 } else if (app == extension8_->id()) { | 759 } else if (app == extension8_->id()) { |
| 606 result += "App8"; | 760 result += "App8"; |
| 607 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); | 761 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); |
| 608 } else if (app == ArcAppTest::GetAppId(arc_test_.fake_apps()[0])) { | |
| 609 result += arc_test_.fake_apps()[0].name; | |
| 610 } else { | 762 } else { |
| 611 result += "unknown"; | 763 bool arc_app_found = false; |
| 764 for (const auto& arc_app : arc_test_.fake_apps()) { |
| 765 if (app == ArcAppTest::GetAppId(arc_app)) { |
| 766 result += arc_app.name; |
| 767 arc_app_found = true; |
| 768 break; |
| 769 } |
| 770 } |
| 771 if (!arc_app_found) |
| 772 result += "unknown"; |
| 612 } | 773 } |
| 613 break; | 774 break; |
| 614 } | 775 } |
| 615 case ash::TYPE_BROWSER_SHORTCUT: | 776 case ash::TYPE_BROWSER_SHORTCUT: |
| 616 result += "Chrome"; | 777 result += "Chrome"; |
| 617 break; | 778 break; |
| 618 case ash::TYPE_APP_LIST: | 779 case ash::TYPE_APP_LIST: |
| 619 result += "AppList"; | 780 result += "AppList"; |
| 620 break; | 781 break; |
| 621 default: | 782 default: |
| 622 result += "Unknown"; | 783 result += "Unknown"; |
| 623 break; | 784 break; |
| 624 } | 785 } |
| 625 } | 786 } |
| 626 return result; | 787 return result; |
| 627 } | 788 } |
| 628 | 789 |
| 629 // Set the index at which the chrome icon should be. | |
| 630 void SetShelfChromeIconIndex(int index) { | |
| 631 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, | |
| 632 index); | |
| 633 } | |
| 634 | |
| 635 // Remember the order of unpinned but running applications for the current | 790 // Remember the order of unpinned but running applications for the current |
| 636 // user. | 791 // user. |
| 637 void RememberUnpinnedRunningApplicationOrder() { | 792 void RememberUnpinnedRunningApplicationOrder() { |
| 638 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); | 793 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); |
| 639 } | 794 } |
| 640 | 795 |
| 641 // Restore the order of running but unpinned applications for a given user. | 796 // Restore the order of running but unpinned applications for a given user. |
| 642 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) { | 797 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) { |
| 643 launcher_controller_->RestoreUnpinnedRunningApplicationOrder( | 798 launcher_controller_->RestoreUnpinnedRunningApplicationOrder( |
| 644 account_id.GetUserEmail()); | 799 account_id.GetUserEmail()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 scoped_refptr<Extension> extension4_; | 838 scoped_refptr<Extension> extension4_; |
| 684 scoped_refptr<Extension> extension5_; | 839 scoped_refptr<Extension> extension5_; |
| 685 scoped_refptr<Extension> extension6_; | 840 scoped_refptr<Extension> extension6_; |
| 686 scoped_refptr<Extension> extension7_; | 841 scoped_refptr<Extension> extension7_; |
| 687 scoped_refptr<Extension> extension8_; | 842 scoped_refptr<Extension> extension8_; |
| 688 | 843 |
| 689 ArcAppTest arc_test_; | 844 ArcAppTest arc_test_; |
| 690 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_; | 845 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_; |
| 691 std::unique_ptr<TestShelfModelObserver> model_observer_; | 846 std::unique_ptr<TestShelfModelObserver> model_observer_; |
| 692 std::unique_ptr<ash::ShelfModel> model_; | 847 std::unique_ptr<ash::ShelfModel> model_; |
| 848 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 693 | 849 |
| 694 // |item_delegate_manager_| owns |test_controller_|. | 850 // |item_delegate_manager_| owns |test_controller_|. |
| 695 LauncherItemController* test_controller_; | 851 LauncherItemController* test_controller_; |
| 696 | 852 |
| 697 ExtensionService* extension_service_; | 853 ExtensionService* extension_service_; |
| 698 | 854 |
| 855 app_list::AppListSyncableService* app_service_; |
| 856 |
| 699 ash::ShelfItemDelegateManager* item_delegate_manager_; | 857 ash::ShelfItemDelegateManager* item_delegate_manager_; |
| 700 | 858 |
| 701 private: | 859 private: |
| 702 TestBrowserWindow* CreateTestBrowserWindowAura() { | 860 TestBrowserWindow* CreateTestBrowserWindowAura() { |
| 703 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 861 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
| 704 window->set_id(0); | 862 window->set_id(0); |
| 705 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 863 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 706 window->Init(ui::LAYER_TEXTURED); | 864 window->Init(ui::LAYER_TEXTURED); |
| 707 aura::client::ParentWindowWithContext(window.get(), GetContext(), | 865 aura::client::ParentWindowWithContext(window.get(), GetContext(), |
| 708 gfx::Rect(200, 200)); | 866 gfx::Rect(200, 200)); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 1129 |
| 972 private: | 1130 private: |
| 973 typedef std::map<Profile*, std::string> ProfileToNameMap; | 1131 typedef std::map<Profile*, std::string> ProfileToNameMap; |
| 974 TestingProfileManager* profile_manager() { return profile_manager_.get(); } | 1132 TestingProfileManager* profile_manager() { return profile_manager_.get(); } |
| 975 | 1133 |
| 976 chromeos::FakeChromeUserManager* GetFakeUserManager() { | 1134 chromeos::FakeChromeUserManager* GetFakeUserManager() { |
| 977 return static_cast<chromeos::FakeChromeUserManager*>( | 1135 return static_cast<chromeos::FakeChromeUserManager*>( |
| 978 user_manager::UserManager::Get()); | 1136 user_manager::UserManager::Get()); |
| 979 } | 1137 } |
| 980 | 1138 |
| 981 std::unique_ptr<TestingProfileManager> profile_manager_; | |
| 982 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 1139 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 983 | 1140 |
| 984 ash::test::TestShellDelegate* shell_delegate_; | 1141 ash::test::TestShellDelegate* shell_delegate_; |
| 985 | 1142 |
| 986 ProfileToNameMap created_profiles_; | 1143 ProfileToNameMap created_profiles_; |
| 987 | 1144 |
| 988 DISALLOW_COPY_AND_ASSIGN( | 1145 DISALLOW_COPY_AND_ASSIGN( |
| 989 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); | 1146 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); |
| 990 }; | 1147 }; |
| 991 | 1148 |
| 992 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) { | 1149 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) { |
| 993 InitLauncherController(); | 1150 InitLauncherController(); |
| 994 // Model should only contain the browser shortcut and app list items. | 1151 // Model should only contain the browser shortcut and app list items. |
| 995 EXPECT_EQ(2, model_->item_count()); | 1152 EXPECT_EQ(2, model_->item_count()); |
| 996 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1153 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 997 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1154 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 998 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1155 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 999 | 1156 |
| 1000 // Installing |extension3_| should add it to the launcher - behind the | 1157 // Installing |extension3_| should add it to the launcher - behind the |
| 1001 // chrome icon. | 1158 // chrome icon. |
| 1002 extension_service_->AddExtension(extension3_.get()); | 1159 extension_service_->AddExtension(extension3_.get()); |
| 1003 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); | 1160 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); |
| 1004 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1161 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1005 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1162 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1006 } | 1163 } |
| 1007 | 1164 |
| 1165 TEST_F(ChromeLauncherControllerImplTest, ArcAppPinCrossPlatformWorkflow) { |
| 1166 // Work on Arc-disabled platform first. |
| 1167 arc_test_.SetUp(profile()); |
| 1168 |
| 1169 const std::string arc_app_id1 = |
| 1170 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]); |
| 1171 const std::string arc_app_id2 = |
| 1172 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]); |
| 1173 const std::string arc_app_id3 = |
| 1174 ArcAppTest::GetAppId(arc_test_.fake_apps()[2]); |
| 1175 |
| 1176 InitLauncherController(); |
| 1177 |
| 1178 extension_service_->AddExtension(extension1_.get()); |
| 1179 extension_service_->AddExtension(extension2_.get()); |
| 1180 extension_service_->AddExtension(extension3_.get()); |
| 1181 |
| 1182 // extension 1, 3 are pinned by user |
| 1183 syncer::SyncChangeList sync_list; |
| 1184 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1185 InsertAddPinChange(&sync_list, 1, arc_app_id1); |
| 1186 InsertAddPinChange(&sync_list, 2, extension2_->id()); |
| 1187 InsertAddPinChange(&sync_list, 3, arc_app_id2); |
| 1188 InsertAddPinChange(&sync_list, 4, extension3_->id()); |
| 1189 SendPinChanges(sync_list, true); |
| 1190 SetShelfChromeIconIndex(1); |
| 1191 |
| 1192 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1193 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1)); |
| 1194 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1195 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2)); |
| 1196 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1197 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); |
| 1198 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); |
| 1199 |
| 1200 // Persist pin state, we don't have active pin for Arc apps yet, but pin |
| 1201 // model should have it. |
| 1202 syncer::SyncDataList copy_sync_list = |
| 1203 app_service_->GetAllSyncData(syncer::APP_LIST); |
| 1204 |
| 1205 launcher_controller_.reset(); |
| 1206 SendPinChanges(syncer::SyncChangeList(), true); |
| 1207 StopAppSyncService(); |
| 1208 EXPECT_EQ(0U, app_service_->sync_items().size()); |
| 1209 |
| 1210 // Move to Arc-enabled platform, restart syncing with stored data. |
| 1211 StartAppSyncService(copy_sync_list); |
| 1212 RecreateChromeLauncher(); |
| 1213 |
| 1214 // Pins must be automatically updated. |
| 1215 SendListOfArcApps(); |
| 1216 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1217 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1)); |
| 1218 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1219 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); |
| 1220 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1221 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); |
| 1222 |
| 1223 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3", |
| 1224 GetPinnedAppStatus()); |
| 1225 |
| 1226 // Now move pins on Arc-enabled platform. |
| 1227 model_->Move(1, 4); |
| 1228 model_->Move(3, 1); |
| 1229 model_->Move(3, 5); |
| 1230 model_->Move(4, 2); |
| 1231 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3", |
| 1232 GetPinnedAppStatus()); |
| 1233 |
| 1234 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST); |
| 1235 |
| 1236 launcher_controller_.reset(); |
| 1237 ResetPinModel(); |
| 1238 |
| 1239 SendPinChanges(syncer::SyncChangeList(), true); |
| 1240 StopAppSyncService(); |
| 1241 EXPECT_EQ(0U, app_service_->sync_items().size()); |
| 1242 |
| 1243 // Move back to Arc-disabled platform. |
| 1244 EnableArc(false); |
| 1245 StartAppSyncService(copy_sync_list); |
| 1246 RecreateChromeLauncher(); |
| 1247 |
| 1248 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1249 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1)); |
| 1250 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1251 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2)); |
| 1252 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1253 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); |
| 1254 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus()); |
| 1255 |
| 1256 // Now move/remove pins on Arc-disabled platform. |
| 1257 model_->Move(4, 2); |
| 1258 launcher_controller_->UnpinAppWithID(extension2_->id()); |
| 1259 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus()); |
| 1260 EnableArc(true); |
| 1261 |
| 1262 SendListOfArcApps(); |
| 1263 |
| 1264 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1265 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1)); |
| 1266 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1267 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); |
| 1268 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1269 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); |
| 1270 EXPECT_EQ("AppList, Fake App 1, App3, Chrome, App1, Fake App 0", |
| 1271 GetPinnedAppStatus()); |
| 1272 } |
| 1273 |
| 1008 /* | 1274 /* |
| 1009 * Test ChromeLauncherControllerImpl correctly merges policy pinned apps | 1275 * Test ChromeLauncherControllerImpl correctly merges policy pinned apps |
| 1010 * and user pinned apps | 1276 * and user pinned apps |
| 1011 */ | 1277 */ |
| 1012 TEST_F(ChromeLauncherControllerImplTest, MergePolicyAndUserPrefPinnedApps) { | 1278 TEST_F(ChromeLauncherControllerImplTest, MergePolicyAndUserPrefPinnedApps) { |
| 1013 InitLauncherController(); | 1279 InitLauncherController(); |
| 1014 | 1280 |
| 1015 base::ListValue user_pref_value; | |
| 1016 extension_service_->AddExtension(extension1_.get()); | 1281 extension_service_->AddExtension(extension1_.get()); |
| 1017 extension_service_->AddExtension(extension3_.get()); | 1282 extension_service_->AddExtension(extension3_.get()); |
| 1018 extension_service_->AddExtension(extension4_.get()); | 1283 extension_service_->AddExtension(extension4_.get()); |
| 1019 extension_service_->AddExtension(extension5_.get()); | 1284 extension_service_->AddExtension(extension5_.get()); |
| 1020 // extension 1, 3 are pinned by user | 1285 // extension 1, 3 are pinned by user |
| 1021 InsertPrefValue(&user_pref_value, 0, extension1_->id()); | 1286 syncer::SyncChangeList sync_list; |
| 1022 InsertPrefValue(&user_pref_value, 1, extension3_->id()); | 1287 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1023 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1288 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId); |
| 1024 user_pref_value.DeepCopy()); | 1289 InsertAddPinChange(&sync_list, 2, extension3_->id()); |
| 1290 SendPinChanges(sync_list, true); |
| 1025 | 1291 |
| 1026 base::ListValue policy_value; | 1292 base::ListValue policy_value; |
| 1027 // extension 2 4 are pinned by policy | 1293 // extension 2 4 are pinned by policy |
| 1028 InsertPrefValue(&policy_value, 0, extension2_->id()); | 1294 InsertPrefValue(&policy_value, 0, extension2_->id()); |
| 1029 InsertPrefValue(&policy_value, 1, extension4_->id()); | 1295 InsertPrefValue(&policy_value, 1, extension4_->id()); |
| 1030 profile()->GetTestingPrefService()->SetManagedPref( | 1296 profile()->GetTestingPrefService()->SetManagedPref( |
| 1031 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); | 1297 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); |
| 1032 | 1298 |
| 1033 SetShelfChromeIconIndex(1); | |
| 1034 | |
| 1035 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 1299 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1036 // 2 is not pinned as it's not installed | 1300 // 2 is not pinned as it's not installed |
| 1037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1301 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1038 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 1302 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1039 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); | 1303 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); |
| 1040 // install extension 2 and check | 1304 // install extension 2 and check |
| 1041 extension_service_->AddExtension(extension2_.get()); | 1305 extension_service_->AddExtension(extension2_.get()); |
| 1042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); | 1306 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1043 | 1307 |
| 1044 // Check user can manually pin or unpin these apps | 1308 // Check user can manually pin or unpin these apps |
| 1045 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, | 1309 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, |
| 1046 launcher_controller_->GetPinnable(extension1_->id())); | 1310 launcher_controller_->GetPinnable(extension1_->id())); |
| 1047 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, | 1311 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, |
| 1048 launcher_controller_->GetPinnable(extension2_->id())); | 1312 launcher_controller_->GetPinnable(extension2_->id())); |
| 1049 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, | 1313 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, |
| 1050 launcher_controller_->GetPinnable(extension3_->id())); | 1314 launcher_controller_->GetPinnable(extension3_->id())); |
| 1051 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, | 1315 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, |
| 1052 launcher_controller_->GetPinnable(extension4_->id())); | 1316 launcher_controller_->GetPinnable(extension4_->id())); |
| 1053 | 1317 |
| 1054 // Check the order of shelf pinned apps | 1318 // Check the order of shelf pinned apps |
| 1055 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus()); | 1319 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus()); |
| 1056 } | 1320 } |
| 1057 | 1321 |
| 1058 // Check that the restauration of launcher items is happening in the same order | 1322 // Check that the restauration of launcher items is happening in the same order |
| 1059 // as the user has pinned them (on another system) when they are synced reverse | 1323 // as the user has pinned them (on another system) when they are synced reverse |
| 1060 // order. | 1324 // order. |
| 1061 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsReverseOrder) { | 1325 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsReverseOrder) { |
| 1062 InitLauncherController(); | 1326 InitLauncherController(); |
| 1063 | 1327 |
| 1064 base::ListValue policy_value; | 1328 syncer::SyncChangeList sync_list; |
| 1065 InsertPrefValue(&policy_value, 0, extension1_->id()); | 1329 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1066 InsertPrefValue(&policy_value, 1, extension2_->id()); | 1330 InsertAddPinChange(&sync_list, 1, extension2_->id()); |
| 1067 InsertPrefValue(&policy_value, 2, extension3_->id()); | 1331 InsertAddPinChange(&sync_list, 2, extension3_->id()); |
| 1068 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1332 SendPinChanges(sync_list, true); |
| 1069 policy_value.DeepCopy()); | 1333 |
| 1070 SetShelfChromeIconIndex(0); | |
| 1071 // Model should only contain the browser shortcut and app list items. | 1334 // Model should only contain the browser shortcut and app list items. |
| 1072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1335 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1073 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1336 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1074 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1337 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1075 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 1338 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 1076 | 1339 |
| 1077 // Installing |extension3_| should add it to the shelf - behind the | 1340 // Installing |extension3_| should add it to the shelf - behind the |
| 1078 // chrome icon. | 1341 // chrome icon. |
| 1079 ash::ShelfItem item; | 1342 ash::ShelfItem item; |
| 1080 extension_service_->AddExtension(extension3_.get()); | 1343 extension_service_->AddExtension(extension3_.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1093 extension_service_->AddExtension(extension1_.get()); | 1356 extension_service_->AddExtension(extension1_.get()); |
| 1094 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); | 1357 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); |
| 1095 } | 1358 } |
| 1096 | 1359 |
| 1097 // Check that the restauration of launcher items is happening in the same order | 1360 // Check that the restauration of launcher items is happening in the same order |
| 1098 // as the user has pinned them (on another system) when they are synced random | 1361 // as the user has pinned them (on another system) when they are synced random |
| 1099 // order. | 1362 // order. |
| 1100 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsRandomOrder) { | 1363 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsRandomOrder) { |
| 1101 InitLauncherController(); | 1364 InitLauncherController(); |
| 1102 | 1365 |
| 1103 base::ListValue policy_value; | 1366 syncer::SyncChangeList sync_list; |
| 1104 InsertPrefValue(&policy_value, 0, extension1_->id()); | 1367 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1105 InsertPrefValue(&policy_value, 1, extension2_->id()); | 1368 InsertAddPinChange(&sync_list, 1, extension2_->id()); |
| 1106 InsertPrefValue(&policy_value, 2, extension3_->id()); | 1369 InsertAddPinChange(&sync_list, 2, extension3_->id()); |
| 1370 SendPinChanges(sync_list, true); |
| 1107 | 1371 |
| 1108 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1109 policy_value.DeepCopy()); | |
| 1110 SetShelfChromeIconIndex(0); | |
| 1111 // Model should only contain the browser shortcut and app list items. | 1372 // Model should only contain the browser shortcut and app list items. |
| 1112 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1373 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1113 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1374 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1114 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1375 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1115 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 1376 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 1116 | 1377 |
| 1117 // Installing |extension2_| should add it to the launcher - behind the | 1378 // Installing |extension2_| should add it to the launcher - behind the |
| 1118 // chrome icon. | 1379 // chrome icon. |
| 1119 extension_service_->AddExtension(extension2_.get()); | 1380 extension_service_->AddExtension(extension2_.get()); |
| 1120 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1381 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1133 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); | 1394 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); |
| 1134 } | 1395 } |
| 1135 | 1396 |
| 1136 // Check that the restauration of launcher items is happening in the same order | 1397 // Check that the restauration of launcher items is happening in the same order |
| 1137 // as the user has pinned / moved them (on another system) when they are synced | 1398 // as the user has pinned / moved them (on another system) when they are synced |
| 1138 // random order - including the chrome icon. | 1399 // random order - including the chrome icon. |
| 1139 TEST_F(ChromeLauncherControllerImplTest, | 1400 TEST_F(ChromeLauncherControllerImplTest, |
| 1140 RestoreDefaultAppsRandomOrderChromeMoved) { | 1401 RestoreDefaultAppsRandomOrderChromeMoved) { |
| 1141 InitLauncherController(); | 1402 InitLauncherController(); |
| 1142 | 1403 |
| 1143 base::ListValue policy_value; | 1404 syncer::SyncChangeList sync_list; |
| 1144 InsertPrefValue(&policy_value, 0, extension1_->id()); | 1405 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1145 InsertPrefValue(&policy_value, 1, extension2_->id()); | 1406 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId); |
| 1146 InsertPrefValue(&policy_value, 2, extension3_->id()); | 1407 InsertAddPinChange(&sync_list, 2, extension2_->id()); |
| 1147 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1408 InsertAddPinChange(&sync_list, 3, extension3_->id()); |
| 1148 policy_value.DeepCopy()); | 1409 SendPinChanges(sync_list, true); |
| 1149 SetShelfChromeIconIndex(1); | 1410 |
| 1150 // Model should only contain the browser shortcut and app list items. | 1411 // Model should only contain the browser shortcut and app list items. |
| 1151 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1412 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 1413 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 1153 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1414 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1154 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 1415 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 1155 | 1416 |
| 1156 // Installing |extension2_| should add it to the shelf - behind the | 1417 // Installing |extension2_| should add it to the shelf - behind the |
| 1157 // chrome icon. | 1418 // chrome icon. |
| 1158 ash::ShelfItem item; | 1419 ash::ShelfItem item; |
| 1159 extension_service_->AddExtension(extension2_.get()); | 1420 extension_service_->AddExtension(extension2_.get()); |
| 1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1421 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 1161 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1422 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1162 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); | 1423 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); |
| 1163 | 1424 |
| 1164 // Installing |extension1_| should add it to the launcher - behind the | 1425 // Installing |extension1_| should add it to the launcher - behind the |
| 1165 // chrome icon, but in first location. | 1426 // chrome icon, but in first location. |
| 1166 extension_service_->AddExtension(extension1_.get()); | 1427 extension_service_->AddExtension(extension1_.get()); |
| 1167 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 1428 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 1168 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); | 1429 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); |
| 1169 | 1430 |
| 1170 // Installing |extension3_| should add it to the launcher - behind the | 1431 // Installing |extension3_| should add it to the launcher - behind the |
| 1171 // chrome icon, but in first location. | 1432 // chrome icon, but in first location. |
| 1172 extension_service_->AddExtension(extension3_.get()); | 1433 extension_service_->AddExtension(extension3_.get()); |
| 1173 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); | 1434 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); |
| 1174 } | 1435 } |
| 1175 | 1436 |
| 1176 // Check that syncing to a different state does the correct thing. | 1437 // Check that syncing to a different state does the correct thing. |
| 1177 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsResyncOrder) { | 1438 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsResyncOrder) { |
| 1178 InitLauncherController(); | 1439 InitLauncherController(); |
| 1179 base::ListValue policy_value; | 1440 |
| 1180 InsertPrefValue(&policy_value, 0, extension1_->id()); | 1441 syncer::SyncChangeList sync_list0; |
| 1181 InsertPrefValue(&policy_value, 1, extension2_->id()); | 1442 InsertAddPinChange(&sync_list0, 0, extension1_->id()); |
| 1182 InsertPrefValue(&policy_value, 2, extension3_->id()); | 1443 InsertAddPinChange(&sync_list0, 1, extension2_->id()); |
| 1183 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1444 InsertAddPinChange(&sync_list0, 2, extension3_->id()); |
| 1184 policy_value.DeepCopy()); | 1445 SendPinChanges(sync_list0, true); |
| 1446 |
| 1185 // The shelf layout has always one static item at the beginning (App List). | 1447 // The shelf layout has always one static item at the beginning (App List). |
| 1186 SetShelfChromeIconIndex(0); | |
| 1187 extension_service_->AddExtension(extension2_.get()); | 1448 extension_service_->AddExtension(extension2_.get()); |
| 1188 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); | 1449 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); |
| 1189 extension_service_->AddExtension(extension1_.get()); | 1450 extension_service_->AddExtension(extension1_.get()); |
| 1190 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); | 1451 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); |
| 1191 extension_service_->AddExtension(extension3_.get()); | 1452 extension_service_->AddExtension(extension3_.get()); |
| 1192 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); | 1453 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); |
| 1193 | 1454 |
| 1194 // Change the order with increasing chrome position and decreasing position. | 1455 // Change the order with increasing chrome position and decreasing position. |
| 1195 base::ListValue policy_value1; | 1456 syncer::SyncChangeList sync_list1; |
| 1196 InsertPrefValue(&policy_value1, 0, extension3_->id()); | 1457 InsertAddPinChange(&sync_list1, 0, extension3_->id()); |
| 1197 InsertPrefValue(&policy_value1, 1, extension1_->id()); | 1458 InsertAddPinChange(&sync_list1, 1, extension1_->id()); |
| 1198 InsertPrefValue(&policy_value1, 2, extension2_->id()); | 1459 InsertAddPinChange(&sync_list1, 2, extension2_->id()); |
| 1199 SetShelfChromeIconIndex(3); | 1460 InsertAddPinChange(&sync_list1, 3, extension_misc::kChromeAppId); |
| 1200 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1461 SendPinChanges(sync_list1, true); |
| 1201 policy_value1.DeepCopy()); | |
| 1202 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); | 1462 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); |
| 1203 base::ListValue policy_value2; | 1463 |
| 1204 InsertPrefValue(&policy_value2, 0, extension2_->id()); | 1464 syncer::SyncChangeList sync_list2; |
| 1205 InsertPrefValue(&policy_value2, 1, extension3_->id()); | 1465 InsertAddPinChange(&sync_list2, 0, extension2_->id()); |
| 1206 InsertPrefValue(&policy_value2, 2, extension1_->id()); | 1466 InsertAddPinChange(&sync_list2, 1, extension3_->id()); |
| 1207 SetShelfChromeIconIndex(2); | 1467 InsertAddPinChange(&sync_list2, 2, extension_misc::kChromeAppId); |
| 1208 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 1468 InsertAddPinChange(&sync_list2, 3, extension1_->id()); |
| 1209 policy_value2.DeepCopy()); | 1469 SendPinChanges(sync_list2, true); |
| 1210 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); | 1470 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); |
| 1211 | 1471 |
| 1212 // Check that the chrome icon can also be at the first possible location. | 1472 // Check that the chrome icon can also be at the first possible location. |
| 1213 SetShelfChromeIconIndex(0); | 1473 syncer::SyncChangeList sync_list3; |
| 1214 base::ListValue policy_value3; | 1474 InsertAddPinChange(&sync_list3, 0, extension3_->id()); |
| 1215 InsertPrefValue(&policy_value3, 0, extension3_->id()); | 1475 InsertAddPinChange(&sync_list3, 1, extension2_->id()); |
| 1216 InsertPrefValue(&policy_value3, 1, extension2_->id()); | 1476 InsertAddPinChange(&sync_list3, 2, extension1_->id()); |
| 1217 InsertPrefValue(&policy_value3, 2, extension1_->id()); | 1477 SendPinChanges(sync_list3, true); |
| 1218 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1219 policy_value3.DeepCopy()); | |
| 1220 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); | 1478 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); |
| 1221 | 1479 |
| 1222 // Check that unloading of extensions works as expected. | 1480 // Check that unloading of extensions works as expected. |
| 1223 extension_service_->UnloadExtension(extension1_->id(), | 1481 extension_service_->UnloadExtension(extension1_->id(), |
| 1224 UnloadedExtensionInfo::REASON_UNINSTALL); | 1482 UnloadedExtensionInfo::REASON_UNINSTALL); |
| 1225 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); | 1483 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); |
| 1226 | 1484 |
| 1227 extension_service_->UnloadExtension(extension2_->id(), | 1485 extension_service_->UnloadExtension(extension2_->id(), |
| 1228 UnloadedExtensionInfo::REASON_UNINSTALL); | 1486 UnloadedExtensionInfo::REASON_UNINSTALL); |
| 1229 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); | 1487 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 RestoreUnpinnedRunningApplicationOrder(current_account_id); | 1686 RestoreUnpinnedRunningApplicationOrder(current_account_id); |
| 1429 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); | 1687 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); |
| 1430 launcher_controller_->UnlockV1AppWithID(extension3_->id()); | 1688 launcher_controller_->UnlockV1AppWithID(extension3_->id()); |
| 1431 RestoreUnpinnedRunningApplicationOrder(current_account_id); | 1689 RestoreUnpinnedRunningApplicationOrder(current_account_id); |
| 1432 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); | 1690 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); |
| 1433 } | 1691 } |
| 1434 | 1692 |
| 1435 TEST_F(ChromeLauncherControllerImplTest, ArcDeferredLaunch) { | 1693 TEST_F(ChromeLauncherControllerImplTest, ArcDeferredLaunch) { |
| 1436 arc_test_.SetUp(profile()); | 1694 arc_test_.SetUp(profile()); |
| 1437 | 1695 |
| 1438 launcher_controller_.reset( | 1696 RecreateChromeLauncher(); |
| 1439 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); | |
| 1440 launcher_controller_->Init(); | |
| 1441 | 1697 |
| 1442 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0]; | 1698 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0]; |
| 1443 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1]; | 1699 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1]; |
| 1444 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2]; | 1700 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2]; |
| 1445 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1); | 1701 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1); |
| 1446 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2); | 1702 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2); |
| 1447 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3); | 1703 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3); |
| 1448 | 1704 |
| 1449 SendListOfArcApps(); | 1705 SendListOfArcApps(); |
| 1450 | 1706 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 | 2057 |
| 1802 EXPECT_EQ(2, model_->item_count()); | 2058 EXPECT_EQ(2, model_->item_count()); |
| 1803 } | 2059 } |
| 1804 | 2060 |
| 1805 // Check that a locked (windowed V1 application) will be properly converted | 2061 // Check that a locked (windowed V1 application) will be properly converted |
| 1806 // between locked and pinned when the order gets changed through a profile / | 2062 // between locked and pinned when the order gets changed through a profile / |
| 1807 // policy change. | 2063 // policy change. |
| 1808 TEST_F(ChromeLauncherControllerImplTest, | 2064 TEST_F(ChromeLauncherControllerImplTest, |
| 1809 RestoreDefaultAndLockedAppsResyncOrder) { | 2065 RestoreDefaultAndLockedAppsResyncOrder) { |
| 1810 InitLauncherController(); | 2066 InitLauncherController(); |
| 1811 base::ListValue policy_value0; | 2067 |
| 1812 InsertPrefValue(&policy_value0, 0, extension1_->id()); | 2068 syncer::SyncChangeList sync_list; |
| 1813 InsertPrefValue(&policy_value0, 1, extension3_->id()); | 2069 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 1814 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2070 InsertAddPinChange(&sync_list, 1, extension3_->id()); |
| 1815 policy_value0.DeepCopy()); | 2071 SendPinChanges(sync_list, true); |
| 2072 |
| 1816 // The shelf layout has always one static item at the beginning (App List). | 2073 // The shelf layout has always one static item at the beginning (App List). |
| 1817 SetShelfChromeIconIndex(0); | |
| 1818 extension_service_->AddExtension(extension1_.get()); | 2074 extension_service_->AddExtension(extension1_.get()); |
| 1819 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 2075 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
| 1820 extension_service_->AddExtension(extension2_.get()); | 2076 extension_service_->AddExtension(extension2_.get()); |
| 1821 // No new app icon will be generated. | 2077 // No new app icon will be generated. |
| 1822 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 2078 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
| 2079 |
| 1823 // Add the app as locked app which will add it (un-pinned). | 2080 // Add the app as locked app which will add it (un-pinned). |
| 1824 launcher_controller_->LockV1AppWithID(extension2_->id()); | 2081 launcher_controller_->LockV1AppWithID(extension2_->id()); |
| 1825 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); | 2082 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); |
| 1826 extension_service_->AddExtension(extension3_.get()); | 2083 extension_service_->AddExtension(extension3_.get()); |
| 1827 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); | 2084 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); |
| 1828 | 2085 |
| 1829 // Now request to pin all items which should convert the locked item into a | 2086 // Now request to pin all items which should convert the locked item into a |
| 1830 // pinned item. | 2087 // pinned item. |
| 1831 base::ListValue policy_value1; | 2088 syncer::SyncChangeList sync_list1; |
| 1832 InsertPrefValue(&policy_value1, 0, extension3_->id()); | 2089 InsertAddPinChange(&sync_list1, 0, extension3_->id()); |
| 1833 InsertPrefValue(&policy_value1, 1, extension2_->id()); | 2090 InsertAddPinChange(&sync_list1, 1, extension2_->id()); |
| 1834 InsertPrefValue(&policy_value1, 2, extension1_->id()); | 2091 InsertAddPinChange(&sync_list1, 2, extension1_->id()); |
| 1835 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2092 SendPinChanges(sync_list1, true); |
| 1836 policy_value1.DeepCopy()); | |
| 1837 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); | 2093 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); |
| 1838 | 2094 |
| 1839 // Going back to a status where there is no requirement for app 2 to be pinned | 2095 // Going back to a status where there is no requirement for app 2 to be pinned |
| 1840 // should convert it back to locked but not pinned and state. The position | 2096 // should convert it back to locked but not pinned and state. The position |
| 1841 // is determined by the |ShelfModel|'s weight system and since running | 2097 // is determined by the |ShelfModel|'s weight system and since running |
| 1842 // applications are not allowed to be mixed with shortcuts, it should show up | 2098 // applications are not allowed to be mixed with shortcuts, it should show up |
| 1843 // at the end of the list. | 2099 // at the end of the list. |
| 1844 base::ListValue policy_value2; | 2100 syncer::SyncChangeList sync_list2; |
| 1845 InsertPrefValue(&policy_value2, 0, extension3_->id()); | 2101 InsertAddPinChange(&sync_list2, 0, extension3_->id()); |
| 1846 InsertPrefValue(&policy_value2, 1, extension1_->id()); | 2102 InsertAddPinChange(&sync_list2, 1, extension1_->id()); |
| 1847 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2103 SendPinChanges(sync_list2, true); |
| 1848 policy_value2.DeepCopy()); | |
| 1849 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); | 2104 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); |
| 1850 | 2105 |
| 1851 // Removing an item should simply close it and everything should shift. | 2106 // Removing an item should simply close it and everything should shift. |
| 1852 base::ListValue policy_value3; | 2107 SendPinChanges(syncer::SyncChangeList(), true); |
| 1853 InsertPrefValue(&policy_value3, 0, extension3_->id()); | |
| 1854 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1855 policy_value3.DeepCopy()); | |
| 1856 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus()); | 2108 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus()); |
| 1857 } | 2109 } |
| 1858 | 2110 |
| 1859 // Check that a running and not pinned V2 application will be properly converted | 2111 // Check that a running and not pinned V2 application will be properly converted |
| 1860 // between locked and pinned when the order gets changed through a profile / | 2112 // between locked and pinned when the order gets changed through a profile / |
| 1861 // policy change. | 2113 // policy change. |
| 1862 TEST_F(ChromeLauncherControllerImplTest, | 2114 TEST_F(ChromeLauncherControllerImplTest, |
| 1863 RestoreDefaultAndRunningV2AppsResyncOrder) { | 2115 RestoreDefaultAndRunningV2AppsResyncOrder) { |
| 1864 InitLauncherController(); | 2116 InitLauncherController(); |
| 1865 base::ListValue policy_value0; | 2117 syncer::SyncChangeList sync_list0; |
| 1866 InsertPrefValue(&policy_value0, 0, extension1_->id()); | 2118 InsertAddPinChange(&sync_list0, 0, extension1_->id()); |
| 1867 InsertPrefValue(&policy_value0, 1, extension3_->id()); | 2119 InsertAddPinChange(&sync_list0, 1, extension3_->id()); |
| 1868 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2120 SendPinChanges(sync_list0, true); |
| 1869 policy_value0.DeepCopy()); | |
| 1870 // The shelf layout has always one static item at the beginning (app List). | 2121 // The shelf layout has always one static item at the beginning (app List). |
| 1871 SetShelfChromeIconIndex(0); | |
| 1872 extension_service_->AddExtension(extension1_.get()); | 2122 extension_service_->AddExtension(extension1_.get()); |
| 1873 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 2123 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
| 1874 extension_service_->AddExtension(extension2_.get()); | 2124 extension_service_->AddExtension(extension2_.get()); |
| 1875 // No new app icon will be generated. | 2125 // No new app icon will be generated. |
| 1876 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 2126 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
| 1877 // Add the app as an unpinned but running V2 app. | 2127 // Add the app as an unpinned but running V2 app. |
| 1878 CreateRunningV2App(extension2_->id()); | 2128 CreateRunningV2App(extension2_->id()); |
| 1879 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); | 2129 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); |
| 1880 extension_service_->AddExtension(extension3_.get()); | 2130 extension_service_->AddExtension(extension3_.get()); |
| 1881 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); | 2131 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); |
| 1882 | 2132 |
| 1883 // Now request to pin all items which should convert the locked item into a | 2133 // Now request to pin all items which should convert the locked item into a |
| 1884 // pinned item. | 2134 // pinned item. |
| 1885 base::ListValue policy_value1; | 2135 syncer::SyncChangeList sync_list1; |
| 1886 InsertPrefValue(&policy_value1, 0, extension3_->id()); | 2136 InsertAddPinChange(&sync_list1, 0, extension3_->id()); |
| 1887 InsertPrefValue(&policy_value1, 1, extension2_->id()); | 2137 InsertAddPinChange(&sync_list1, 1, extension2_->id()); |
| 1888 InsertPrefValue(&policy_value1, 2, extension1_->id()); | 2138 InsertAddPinChange(&sync_list1, 2, extension1_->id()); |
| 1889 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2139 SendPinChanges(sync_list1, true); |
| 1890 policy_value1.DeepCopy()); | |
| 1891 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); | 2140 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); |
| 1892 | 2141 |
| 1893 // Going back to a status where there is no requirement for app 2 to be pinned | 2142 // Going back to a status where there is no requirement for app 2 to be pinned |
| 1894 // should convert it back to running V2 app. Since the position is determined | 2143 // should convert it back to running V2 app. Since the position is determined |
| 1895 // by the |ShelfModel|'s weight system, it will be after last pinned item. | 2144 // by the |ShelfModel|'s weight system, it will be after last pinned item. |
| 1896 base::ListValue policy_value2; | 2145 syncer::SyncChangeList sync_list2; |
| 1897 InsertPrefValue(&policy_value2, 0, extension3_->id()); | 2146 InsertAddPinChange(&sync_list2, 0, extension3_->id()); |
| 1898 InsertPrefValue(&policy_value2, 1, extension1_->id()); | 2147 InsertAddPinChange(&sync_list2, 1, extension1_->id()); |
| 1899 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2148 SendPinChanges(sync_list2, true); |
| 1900 policy_value2.DeepCopy()); | |
| 1901 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); | 2149 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); |
| 1902 | 2150 |
| 1903 // Removing an item should simply close it and everything should shift. | 2151 // Removing an item should simply close it and everything should shift. |
| 1904 base::ListValue policy_value3; | 2152 syncer::SyncChangeList sync_list3; |
| 1905 InsertPrefValue(&policy_value3, 0, extension3_->id()); | 2153 InsertAddPinChange(&sync_list3, 0, extension3_->id()); |
| 1906 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2154 SendPinChanges(sync_list3, true); |
| 1907 policy_value3.DeepCopy()); | |
| 1908 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); | 2155 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); |
| 1909 } | 2156 } |
| 1910 | 2157 |
| 1911 // Each user has a different set of applications pinned. Check that when | 2158 // Each user has a different set of applications pinned. Check that when |
| 1912 // switching between the two users, the state gets properly set. | 2159 // switching between the two users, the state gets properly set. |
| 1913 TEST_F(ChromeLauncherControllerImplTest, UserSwitchIconRestore) { | 2160 TEST_F(ChromeLauncherControllerImplTest, UserSwitchIconRestore) { |
| 1914 base::ListValue user_a; | 2161 syncer::SyncChangeList user_a; |
| 1915 base::ListValue user_b; | 2162 syncer::SyncChangeList user_b; |
| 2163 |
| 1916 SetUpMultiUserScenario(&user_a, &user_b); | 2164 SetUpMultiUserScenario(&user_a, &user_b); |
| 2165 |
| 1917 // Show user 1. | 2166 // Show user 1. |
| 1918 SetShelfChromeIconIndex(6); | 2167 SendPinChanges(user_a, true); |
| 1919 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1920 user_a.DeepCopy()); | |
| 1921 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", | 2168 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", |
| 1922 GetPinnedAppStatus()); | 2169 GetPinnedAppStatus()); |
| 1923 | 2170 |
| 1924 // Show user 2. | 2171 // Show user 2. |
| 1925 SetShelfChromeIconIndex(4); | 2172 SendPinChanges(user_b, true); |
| 1926 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1927 user_b.DeepCopy()); | |
| 1928 | |
| 1929 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); | 2173 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); |
| 1930 | 2174 |
| 1931 // Switch back to 1. | 2175 // Switch back to 1. |
| 1932 SetShelfChromeIconIndex(8); | 2176 SendPinChanges(user_a, true); |
| 1933 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1934 user_a.DeepCopy()); | |
| 1935 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", | 2177 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", |
| 1936 GetPinnedAppStatus()); | 2178 GetPinnedAppStatus()); |
| 1937 | 2179 |
| 1938 // Switch back to 2. | 2180 // Switch back to 2. |
| 1939 SetShelfChromeIconIndex(4); | 2181 SendPinChanges(user_b, true); |
| 1940 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1941 user_b.DeepCopy()); | |
| 1942 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); | 2182 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); |
| 1943 } | 2183 } |
| 1944 | 2184 |
| 1945 // Each user has a different set of applications pinned, and one user has an | 2185 // Each user has a different set of applications pinned, and one user has an |
| 1946 // application running. Check that when switching between the two users, the | 2186 // application running. Check that when switching between the two users, the |
| 1947 // state gets properly set. | 2187 // state gets properly set. |
| 1948 TEST_F(ChromeLauncherControllerImplTest, | 2188 TEST_F(ChromeLauncherControllerImplTest, |
| 1949 UserSwitchIconRestoreWithRunningV2App) { | 2189 UserSwitchIconRestoreWithRunningV2App) { |
| 1950 base::ListValue user_a; | 2190 syncer::SyncChangeList user_a; |
| 1951 base::ListValue user_b; | 2191 syncer::SyncChangeList user_b; |
| 2192 |
| 1952 SetUpMultiUserScenario(&user_a, &user_b); | 2193 SetUpMultiUserScenario(&user_a, &user_b); |
| 1953 | 2194 |
| 1954 // Run App1 and assume that it is a V2 app. | 2195 // Run App1 and assume that it is a V2 app. |
| 1955 CreateRunningV2App(extension1_->id()); | 2196 CreateRunningV2App(extension1_->id()); |
| 1956 | 2197 |
| 1957 // Show user 1. | 2198 // Show user 1. |
| 1958 SetShelfChromeIconIndex(6); | 2199 SendPinChanges(user_a, true); |
| 1959 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1960 user_a.DeepCopy()); | |
| 1961 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", | 2200 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", |
| 1962 GetPinnedAppStatus()); | 2201 GetPinnedAppStatus()); |
| 1963 | 2202 |
| 1964 // Show user 2. | 2203 // Show user 2. |
| 1965 SetShelfChromeIconIndex(4); | 2204 SendPinChanges(user_b, true); |
| 1966 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1967 user_b.DeepCopy()); | |
| 1968 | |
| 1969 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); | 2205 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); |
| 1970 | 2206 |
| 1971 // Switch back to 1. | 2207 // Switch back to 1. |
| 1972 SetShelfChromeIconIndex(8); | 2208 SendPinChanges(user_a, true); |
| 1973 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1974 user_a.DeepCopy()); | |
| 1975 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", | 2209 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", |
| 1976 GetPinnedAppStatus()); | 2210 GetPinnedAppStatus()); |
| 1977 | 2211 |
| 1978 // Switch back to 2. | 2212 // Switch back to 2. |
| 1979 SetShelfChromeIconIndex(4); | 2213 SendPinChanges(user_b, true); |
| 1980 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 1981 user_b.DeepCopy()); | |
| 1982 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); | 2214 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); |
| 1983 } | 2215 } |
| 1984 | 2216 |
| 1985 // Each user has a different set of applications pinned, and one user has an | 2217 // Each user has a different set of applications pinned, and one user has an |
| 1986 // application running. The chrome icon is not the last item in the list. | 2218 // application running. The chrome icon is not the last item in the list. |
| 1987 // Check that when switching between the two users, the state gets properly set. | 2219 // Check that when switching between the two users, the state gets properly set. |
| 1988 // There was once a bug associated with this. | 2220 // There was once a bug associated with this. |
| 1989 TEST_F(ChromeLauncherControllerImplTest, | 2221 TEST_F(ChromeLauncherControllerImplTest, |
| 1990 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { | 2222 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { |
| 1991 base::ListValue user_a; | 2223 syncer::SyncChangeList user_a; |
| 1992 base::ListValue user_b; | 2224 syncer::SyncChangeList user_b; |
| 1993 SetUpMultiUserScenario(&user_a, &user_b); | 2225 SetUpMultiUserScenario(&user_a, &user_b); |
| 1994 | 2226 |
| 1995 // Run App1 and assume that it is a V2 app. | 2227 // Run App1 and assume that it is a V2 app. |
| 1996 CreateRunningV2App(extension1_->id()); | 2228 CreateRunningV2App(extension1_->id()); |
| 1997 | 2229 |
| 1998 // Show user 1. | 2230 // Show user 1. |
| 2231 SendPinChanges(user_a, true); |
| 1999 SetShelfChromeIconIndex(5); | 2232 SetShelfChromeIconIndex(5); |
| 2000 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2001 user_a.DeepCopy()); | |
| 2002 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", | 2233 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", |
| 2003 GetPinnedAppStatus()); | 2234 GetPinnedAppStatus()); |
| 2004 | 2235 |
| 2005 // Show user 2. | 2236 // Show user 2. |
| 2237 SendPinChanges(user_b, true); |
| 2006 SetShelfChromeIconIndex(4); | 2238 SetShelfChromeIconIndex(4); |
| 2007 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2008 user_b.DeepCopy()); | |
| 2009 | |
| 2010 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); | 2239 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); |
| 2011 | 2240 |
| 2012 // Switch back to 1. | 2241 // Switch back to 1. |
| 2242 SendPinChanges(user_a, true); |
| 2013 SetShelfChromeIconIndex(5); | 2243 SetShelfChromeIconIndex(5); |
| 2014 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2015 user_a.DeepCopy()); | |
| 2016 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", | 2244 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", |
| 2017 GetPinnedAppStatus()); | 2245 GetPinnedAppStatus()); |
| 2018 } | 2246 } |
| 2019 | 2247 |
| 2020 TEST_F(ChromeLauncherControllerImplTest, Policy) { | 2248 TEST_F(ChromeLauncherControllerImplTest, Policy) { |
| 2021 extension_service_->AddExtension(extension1_.get()); | 2249 extension_service_->AddExtension(extension1_.get()); |
| 2022 extension_service_->AddExtension(extension3_.get()); | 2250 extension_service_->AddExtension(extension3_.get()); |
| 2023 | 2251 |
| 2252 InitLauncherController(); |
| 2253 |
| 2254 syncer::SyncChangeList sync_list; |
| 2255 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId); |
| 2256 SendPinChanges(sync_list, true); |
| 2257 |
| 2024 base::ListValue policy_value; | 2258 base::ListValue policy_value; |
| 2025 InsertPrefValue(&policy_value, 0, extension1_->id()); | 2259 InsertPrefValue(&policy_value, 0, extension1_->id()); |
| 2026 InsertPrefValue(&policy_value, 1, extension2_->id()); | 2260 InsertPrefValue(&policy_value, 1, extension2_->id()); |
| 2027 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 2261 profile()->GetTestingPrefService()->SetManagedPref( |
| 2028 policy_value.DeepCopy()); | 2262 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); |
| 2029 | 2263 |
| 2030 // Only |extension1_| should get pinned. |extension2_| is specified but not | 2264 // Only |extension1_| should get pinned. |extension2_| is specified but not |
| 2031 // installed, and |extension3_| is part of the default set, but that shouldn't | 2265 // installed, and |extension3_| is part of the default set, but that shouldn't |
| 2032 // take effect when the policy override is in place. | 2266 // take effect when the policy override is in place. |
| 2033 InitLauncherController(); | 2267 ASSERT_EQ(3, model_->item_count()); |
| 2034 EXPECT_EQ(3, model_->item_count()); | 2268 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 2035 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | |
| 2036 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 2269 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 2037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 2270 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 2038 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 2271 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 2039 | 2272 |
| 2040 // Installing |extension2_| should add it to the launcher. | 2273 // Installing |extension2_| should add it to the launcher. |
| 2041 extension_service_->AddExtension(extension2_.get()); | 2274 extension_service_->AddExtension(extension2_.get()); |
| 2042 EXPECT_EQ(4, model_->item_count()); | 2275 ASSERT_EQ(4, model_->item_count()); |
| 2276 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
| 2043 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 2277 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 2044 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); | |
| 2045 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 2278 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 2046 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); | 2279 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 2047 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 2280 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 2048 | 2281 |
| 2049 // Removing |extension1_| from the policy should be reflected in the launcher. | 2282 // Removing |extension1_| from the policy should not be reflected in the |
| 2283 // launcher and pin will exist. |
| 2050 policy_value.Remove(0, NULL); | 2284 policy_value.Remove(0, NULL); |
| 2051 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 2285 profile()->GetTestingPrefService()->SetManagedPref( |
| 2052 policy_value.DeepCopy()); | 2286 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); |
| 2053 EXPECT_EQ(3, model_->item_count()); | 2287 EXPECT_EQ(4, model_->item_count()); |
| 2054 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 2288 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
| 2055 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 2289 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
| 2056 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); | 2290 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
| 2057 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 2291 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 2058 } | 2292 } |
| 2059 | 2293 |
| 2060 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) { | 2294 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) { |
| 2061 extension_service_->AddExtension(extension3_.get()); | 2295 extension_service_->AddExtension(extension3_.get()); |
| 2062 extension_service_->AddExtension(extension4_.get()); | 2296 extension_service_->AddExtension(extension4_.get()); |
| 2063 | 2297 |
| 2064 InitLauncherController(); | 2298 InitLauncherController(); |
| 2065 | 2299 |
| 2066 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 2300 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 2067 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); | 2301 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); |
| 2068 | 2302 |
| 2069 extension_service_->UnloadExtension(extension3_->id(), | 2303 extension_service_->UnloadExtension(extension3_->id(), |
| 2070 UnloadedExtensionInfo::REASON_UNINSTALL); | 2304 UnloadedExtensionInfo::REASON_UNINSTALL); |
| 2071 | 2305 |
| 2072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); | 2306 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); |
| 2073 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); | 2307 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); |
| 2074 } | 2308 } |
| 2075 | 2309 |
| 2076 TEST_F(ChromeLauncherControllerImplTest, PrefUpdates) { | 2310 TEST_F(ChromeLauncherControllerImplTest, SyncUpdates) { |
| 2077 extension_service_->AddExtension(extension2_.get()); | 2311 extension_service_->AddExtension(extension2_.get()); |
| 2078 extension_service_->AddExtension(extension3_.get()); | 2312 extension_service_->AddExtension(extension3_.get()); |
| 2079 extension_service_->AddExtension(extension4_.get()); | 2313 extension_service_->AddExtension(extension4_.get()); |
| 2080 | 2314 |
| 2081 InitLauncherController(); | 2315 InitLauncherController(); |
| 2082 | 2316 |
| 2317 syncer::SyncChangeList sync_list; |
| 2318 InsertAddPinChange(&sync_list, 10, extension_misc::kChromeAppId); |
| 2319 SendPinChanges(sync_list, true); |
| 2320 |
| 2083 std::vector<std::string> expected_launchers; | 2321 std::vector<std::string> expected_launchers; |
| 2084 std::vector<std::string> actual_launchers; | 2322 std::vector<std::string> actual_launchers; |
| 2085 base::ListValue pref_value; | |
| 2086 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2087 pref_value.DeepCopy()); | |
| 2088 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2323 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2089 EXPECT_EQ(expected_launchers, actual_launchers); | 2324 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2090 | 2325 |
| 2091 // Unavailable extensions don't create launcher items. | 2326 // Unavailable extensions don't create launcher items. |
| 2092 InsertPrefValue(&pref_value, 0, extension1_->id()); | 2327 sync_list.clear(); |
| 2093 InsertPrefValue(&pref_value, 1, extension2_->id()); | 2328 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 2094 InsertPrefValue(&pref_value, 2, extension4_->id()); | 2329 InsertAddPinChange(&sync_list, 1, extension2_->id()); |
| 2095 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2330 InsertAddPinChange(&sync_list, 3, extension4_->id()); |
| 2096 pref_value.DeepCopy()); | 2331 SendPinChanges(sync_list, false); |
| 2332 |
| 2097 expected_launchers.push_back(extension2_->id()); | 2333 expected_launchers.push_back(extension2_->id()); |
| 2098 expected_launchers.push_back(extension4_->id()); | 2334 expected_launchers.push_back(extension4_->id()); |
| 2099 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2335 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2100 EXPECT_EQ(expected_launchers, actual_launchers); | 2336 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2101 | 2337 |
| 2102 // Redundant pref entries show up only once. | 2338 sync_list.clear(); |
| 2103 InsertPrefValue(&pref_value, 2, extension3_->id()); | 2339 InsertAddPinChange(&sync_list, 2, extension3_->id()); |
| 2104 InsertPrefValue(&pref_value, 2, extension3_->id()); | 2340 SendPinChanges(sync_list, false); |
| 2105 InsertPrefValue(&pref_value, 5, extension3_->id()); | |
| 2106 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2107 pref_value.DeepCopy()); | |
| 2108 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id()); | 2341 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id()); |
| 2109 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2342 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2110 EXPECT_EQ(expected_launchers, actual_launchers); | 2343 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2111 | 2344 |
| 2112 // Order changes are reflected correctly. | 2345 sync_list.clear(); |
| 2113 pref_value.Clear(); | 2346 InsertUpdatePinChange(&sync_list, 0, extension4_->id()); |
| 2114 InsertPrefValue(&pref_value, 0, extension4_->id()); | 2347 InsertUpdatePinChange(&sync_list, 1, extension3_->id()); |
| 2115 InsertPrefValue(&pref_value, 1, extension3_->id()); | 2348 InsertUpdatePinChange(&sync_list, 2, extension2_->id()); |
| 2116 InsertPrefValue(&pref_value, 2, extension2_->id()); | 2349 SendPinChanges(sync_list, false); |
| 2117 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
| 2118 pref_value.DeepCopy()); | |
| 2119 std::reverse(expected_launchers.begin(), expected_launchers.end()); | 2350 std::reverse(expected_launchers.begin(), expected_launchers.end()); |
| 2120 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2351 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2121 EXPECT_EQ(expected_launchers, actual_launchers); | 2352 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2122 | 2353 |
| 2123 // Clearing works. | 2354 // Sending legacy sync change without pin info should not affect pin model. |
| 2124 pref_value.Clear(); | 2355 sync_list.clear(); |
| 2125 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2356 InsertLegacyPinChange(&sync_list, extension4_->id()); |
| 2126 pref_value.DeepCopy()); | 2357 SendPinChanges(sync_list, false); |
| 2358 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2359 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2360 |
| 2361 sync_list.clear(); |
| 2362 InsertRemovePinChange(&sync_list, extension4_->id()); |
| 2363 SendPinChanges(sync_list, false); |
| 2364 expected_launchers.erase(expected_launchers.begin()); |
| 2365 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2366 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2367 |
| 2368 sync_list.clear(); |
| 2369 InsertRemovePinChange(&sync_list, extension3_->id()); |
| 2370 InsertRemovePinChange(&sync_list, extension2_->id()); |
| 2371 SendPinChanges(sync_list, false); |
| 2127 expected_launchers.clear(); | 2372 expected_launchers.clear(); |
| 2128 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2373 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2129 EXPECT_EQ(expected_launchers, actual_launchers); | 2374 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2130 } | 2375 } |
| 2131 | 2376 |
| 2377 TEST_F(ChromeLauncherControllerImplTest, ImportLegacyPin) { |
| 2378 extension_service_->AddExtension(extension2_.get()); |
| 2379 extension_service_->AddExtension(extension3_.get()); |
| 2380 extension_service_->AddExtension(extension4_.get()); |
| 2381 |
| 2382 // Initially pins are imported from legacy pref based model. |
| 2383 base::ListValue value; |
| 2384 InsertPrefValue(&value, 0, extension4_->id()); |
| 2385 InsertPrefValue(&value, 1, extension2_->id()); |
| 2386 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
| 2387 policy_value.DeepCopy()); |
| 2388 |
| 2389 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", |
| 2390 GetPinnedAppStatus()); |
| 2391 |
| 2392 // At this point changing old pref based model does not affect pin model. |
| 2393 InsertPrefValue(&value, 2, extension3_->id()); |
| 2394 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
| 2395 policy_value.DeepCopy()); |
| 2396 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", |
| 2397 GetPinnedAppStatus()); |
| 2398 RecreateChromeLauncher(); |
| 2399 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", |
| 2400 GetPinnedAppStatus()); |
| 2401 } |
| 2402 |
| 2132 TEST_F(ChromeLauncherControllerImplTest, PendingInsertionOrder) { | 2403 TEST_F(ChromeLauncherControllerImplTest, PendingInsertionOrder) { |
| 2133 extension_service_->AddExtension(extension1_.get()); | 2404 extension_service_->AddExtension(extension1_.get()); |
| 2134 extension_service_->AddExtension(extension3_.get()); | 2405 extension_service_->AddExtension(extension3_.get()); |
| 2135 | 2406 |
| 2136 InitLauncherController(); | 2407 InitLauncherController(); |
| 2137 | 2408 |
| 2138 base::ListValue pref_value; | 2409 syncer::SyncChangeList sync_list; |
| 2139 InsertPrefValue(&pref_value, 0, extension1_->id()); | 2410 InsertAddPinChange(&sync_list, 0, extension1_->id()); |
| 2140 InsertPrefValue(&pref_value, 1, extension2_->id()); | 2411 InsertAddPinChange(&sync_list, 1, extension2_->id()); |
| 2141 InsertPrefValue(&pref_value, 2, extension3_->id()); | 2412 InsertAddPinChange(&sync_list, 2, extension3_->id()); |
| 2142 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | 2413 SendPinChanges(sync_list, true); |
| 2143 pref_value.DeepCopy()); | |
| 2144 | 2414 |
| 2145 std::vector<std::string> expected_launchers; | 2415 std::vector<std::string> expected_launchers; |
| 2146 expected_launchers.push_back(extension1_->id()); | 2416 expected_launchers.push_back(extension1_->id()); |
| 2147 expected_launchers.push_back(extension3_->id()); | 2417 expected_launchers.push_back(extension3_->id()); |
| 2148 std::vector<std::string> actual_launchers; | 2418 std::vector<std::string> actual_launchers; |
| 2149 | 2419 |
| 2150 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); | 2420 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); |
| 2151 EXPECT_EQ(expected_launchers, actual_launchers); | 2421 EXPECT_EQ(expected_launchers, actual_launchers); |
| 2152 | 2422 |
| 2153 // Install |extension2| and verify it shows up between the other two. | 2423 // Install |extension2| and verify it shows up between the other two. |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2891 } else { | 3161 } else { |
| 2892 // Clear already registered ShelfItemDelegate. | 3162 // Clear already registered ShelfItemDelegate. |
| 2893 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); | 3163 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |
| 2894 test.RemoveAllShelfItemDelegateForTest(); | 3164 test.RemoveAllShelfItemDelegateForTest(); |
| 2895 } | 3165 } |
| 2896 model_.reset(new ash::ShelfModel); | 3166 model_.reset(new ash::ShelfModel); |
| 2897 | 3167 |
| 2898 AddAppListLauncherItem(); | 3168 AddAppListLauncherItem(); |
| 2899 launcher_controller_.reset( | 3169 launcher_controller_.reset( |
| 2900 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); | 3170 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); |
| 2901 helper = new TestLauncherControllerHelper; | 3171 helper = new TestLauncherControllerHelper(profile()); |
| 2902 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 3172 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 2903 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 3173 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |
| 2904 SetLauncherControllerHelper(helper); | 3174 SetLauncherControllerHelper(helper); |
| 2905 if (!ash::Shell::HasInstance()) { | 3175 if (!ash::Shell::HasInstance()) { |
| 2906 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); | 3176 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |
| 2907 SetShelfItemDelegateManager(item_delegate_manager_); | 3177 SetShelfItemDelegateManager(item_delegate_manager_); |
| 2908 } | 3178 } |
| 2909 launcher_controller_->Init(); | 3179 launcher_controller_->Init(); |
| 2910 | 3180 |
| 2911 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. | 3181 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2949 } else { | 3219 } else { |
| 2950 // Clear already registered ShelfItemDelegate. | 3220 // Clear already registered ShelfItemDelegate. |
| 2951 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); | 3221 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); |
| 2952 test.RemoveAllShelfItemDelegateForTest(); | 3222 test.RemoveAllShelfItemDelegateForTest(); |
| 2953 } | 3223 } |
| 2954 model_.reset(new ash::ShelfModel); | 3224 model_.reset(new ash::ShelfModel); |
| 2955 | 3225 |
| 2956 AddAppListLauncherItem(); | 3226 AddAppListLauncherItem(); |
| 2957 launcher_controller_.reset( | 3227 launcher_controller_.reset( |
| 2958 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); | 3228 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); |
| 2959 helper = new TestLauncherControllerHelper; | 3229 helper = new TestLauncherControllerHelper(profile()); |
| 2960 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 3230 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
| 2961 SetLauncherControllerHelper(helper); | 3231 SetLauncherControllerHelper(helper); |
| 2962 // app_icon_loader is owned by ChromeLauncherControllerImpl. | 3232 // app_icon_loader is owned by ChromeLauncherControllerImpl. |
| 2963 app_icon_loader = new TestAppIconLoaderImpl; | 3233 app_icon_loader = new TestAppIconLoaderImpl; |
| 2964 app_icon_loader->AddSupportedApp("1"); | 3234 app_icon_loader->AddSupportedApp("1"); |
| 2965 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 3235 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |
| 2966 if (!ash::Shell::HasInstance()) { | 3236 if (!ash::Shell::HasInstance()) { |
| 2967 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); | 3237 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); |
| 2968 SetShelfItemDelegateManager(item_delegate_manager_); | 3238 SetShelfItemDelegateManager(item_delegate_manager_); |
| 2969 } | 3239 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 // by hash we can determine that appropriate package was set by policy. | 3341 // by hash we can determine that appropriate package was set by policy. |
| 3072 base::ListValue policy_value; | 3342 base::ListValue policy_value; |
| 3073 InsertPrefValue(&policy_value, 0, appinfo.package_name); | 3343 InsertPrefValue(&policy_value, 0, appinfo.package_name); |
| 3074 profile()->GetTestingPrefService()->SetManagedPref( | 3344 profile()->GetTestingPrefService()->SetManagedPref( |
| 3075 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); | 3345 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); |
| 3076 | 3346 |
| 3077 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); | 3347 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); |
| 3078 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, | 3348 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, |
| 3079 launcher_controller_->GetPinnable(app_id)); | 3349 launcher_controller_->GetPinnable(app_id)); |
| 3080 } | 3350 } |
| OLD | NEW |