Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_unittest.cc

Issue 2055553004: arc: Support pinned apps across Arc-enabled and Arc-disabled platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome_mash_shelf_controller.cc update due namespace renaming Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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
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 // Destroy controller first if it exists.
509 launcher_controller_.reset();
510 model_.reset(new ash::ShelfModel);
511 AddAppListLauncherItem();
512 launcher_controller_.reset(
513 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get()));
514 launcher_controller_->Init();
515 }
516
517 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
518 app_service_->MergeDataAndStartSyncing(
519 syncer::APP_LIST, init_sync_list,
520 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
521 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
522 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
523 }
524
525 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); }
526
483 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) { 527 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) {
484 std::vector<std::unique_ptr<AppIconLoader>> loaders; 528 std::vector<std::unique_ptr<AppIconLoader>> loaders;
485 loaders.push_back(std::move(loader)); 529 loaders.push_back(std::move(loader));
486 launcher_controller_->SetAppIconLoadersForTest(loaders); 530 launcher_controller_->SetAppIconLoadersForTest(loaders);
487 } 531 }
488 532
489 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, 533 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1,
490 std::unique_ptr<AppIconLoader> loader2) { 534 std::unique_ptr<AppIconLoader> loader2) {
491 std::vector<std::unique_ptr<AppIconLoader>> loaders; 535 std::vector<std::unique_ptr<AppIconLoader>> loaders;
492 loaders.push_back(std::move(loader1)); 536 loaders.push_back(std::move(loader1));
493 loaders.push_back(std::move(loader2)); 537 loaders.push_back(std::move(loader2));
494 launcher_controller_->SetAppIconLoadersForTest(loaders); 538 launcher_controller_->SetAppIconLoadersForTest(loaders);
495 } 539 }
496 540
497 void SetLauncherControllerHelper(LauncherControllerHelper* helper) { 541 void SetLauncherControllerHelper(LauncherControllerHelper* helper) {
498 launcher_controller_->SetLauncherControllerHelperForTest(helper); 542 launcher_controller_->SetLauncherControllerHelperForTest(helper);
499 } 543 }
500 544
501 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { 545 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) {
502 launcher_controller_->SetShelfItemDelegateManagerForTest(manager); 546 launcher_controller_->SetShelfItemDelegateManagerForTest(manager);
503 } 547 }
504 548
505 void InsertPrefValue(base::ListValue* pref_value, 549 void InsertPrefValue(base::ListValue* pref_value,
506 int index, 550 int index,
507 const std::string& extension_id) { 551 const std::string& extension_id) {
508 base::DictionaryValue* entry = new base::DictionaryValue(); 552 base::DictionaryValue* entry = new base::DictionaryValue();
509 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 553 entry->SetString(ash::launcher::kPinnedAppsPrefAppIDPath, extension_id);
510 pref_value->Insert(index, entry); 554 pref_value->Insert(index, entry);
511 } 555 }
512 556
557 void InsertRemoveAllPinsChange(syncer::SyncChangeList* list) {
558 for (const auto& sync_peer : app_service_->sync_items()) {
559 sync_pb::EntitySpecifics specifics;
560 sync_pb::AppListSpecifics* app_list_specifics =
561 specifics.mutable_app_list();
562 app_list_specifics->set_item_id(sync_peer.first);
563 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
564 syncer::SyncData sync_data =
565 syncer::SyncData::CreateLocalData(sync_peer.first, "Test", specifics);
566 list->push_back(syncer::SyncChange(
567 FROM_HERE, syncer::SyncChange::ACTION_DELETE, sync_data));
568 }
569 }
570
571 syncer::StringOrdinal GeneratePinPosition(int position) {
572 syncer::StringOrdinal ordinal_position =
573 syncer::StringOrdinal::CreateInitialOrdinal();
574 for (int i = 0; i < position; ++i)
575 ordinal_position = ordinal_position.CreateAfter();
576 return ordinal_position;
577 }
578
579 void InsertPinChange(syncer::SyncChangeList* list,
580 int position,
581 bool add_pin_change,
582 const std::string& app_id,
583 syncer::SyncChange::SyncChangeType type) {
584 sync_pb::EntitySpecifics specifics;
585 sync_pb::AppListSpecifics* app_list_specifics =
586 specifics.mutable_app_list();
587 app_list_specifics->set_item_id(app_id);
588 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
589 if (add_pin_change) {
590 if (position >= 0) {
591 app_list_specifics->set_item_pin_ordinal(
592 GeneratePinPosition(position).ToInternalValue());
593 } else {
594 app_list_specifics->set_item_pin_ordinal(std::string());
595 }
596 }
597 syncer::SyncData sync_data =
598 syncer::SyncData::CreateLocalData(app_id, "Test", specifics);
599 list->push_back(syncer::SyncChange(FROM_HERE, type, sync_data));
600 }
601
602 void InsertAddPinChange(syncer::SyncChangeList* list,
603 int position,
604 const std::string& app_id) {
605 InsertPinChange(list, position, true, app_id,
606 syncer::SyncChange::ACTION_ADD);
607 }
608
609 void InsertUpdatePinChange(syncer::SyncChangeList* list,
610 int position,
611 const std::string& app_id) {
612 InsertPinChange(list, position, true, app_id,
613 syncer::SyncChange::ACTION_UPDATE);
614 }
615
616 void InsertRemovePinChange(syncer::SyncChangeList* list,
617 const std::string& app_id) {
618 InsertPinChange(list, -1, true, app_id, syncer::SyncChange::ACTION_UPDATE);
619 }
620
621 void InsertLegacyPinChange(syncer::SyncChangeList* list,
622 const std::string& app_id) {
623 InsertPinChange(list, -1, false, app_id, syncer::SyncChange::ACTION_UPDATE);
624 }
625
626 void ResetPinModel() {
627 syncer::SyncChangeList sync_list;
628 InsertRemoveAllPinsChange(&sync_list);
629 InsertAddPinChange(&sync_list, 0, kDummyAppId);
630 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
631 }
632
633 void SendPinChanges(const syncer::SyncChangeList& sync_list,
634 bool reset_pin_model) {
635 if (!reset_pin_model) {
636 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
637 } else {
638 syncer::SyncChangeList combined_sync_list;
639 InsertRemoveAllPinsChange(&combined_sync_list);
640 combined_sync_list.insert(combined_sync_list.end(), sync_list.begin(),
641 sync_list.end());
642 app_service_->ProcessSyncChanges(FROM_HERE, combined_sync_list);
643 }
644 }
645
646 // Set the index at which the chrome icon should be.
647 void SetShelfChromeIconIndex(int index) {
648 DCHECK(
649 app_service_->GetPinPosition(extension_misc::kChromeAppId).IsValid());
650 syncer::StringOrdinal chrome_position;
651 chrome_position = index == 0 ? GeneratePinPosition(0).CreateBefore()
652 : GeneratePinPosition(index - 1).CreateBetween(
653 GeneratePinPosition(index));
654
655 syncer::SyncChangeList sync_list;
656 sync_pb::EntitySpecifics specifics;
657 sync_pb::AppListSpecifics* app_list_specifics =
658 specifics.mutable_app_list();
659 app_list_specifics->set_item_id(extension_misc::kChromeAppId);
660 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
661 app_list_specifics->set_item_pin_ordinal(chrome_position.ToInternalValue());
662 syncer::SyncData sync_data = syncer::SyncData::CreateLocalData(
663 extension_misc::kChromeAppId, "Test", specifics);
664 sync_list.push_back(syncer::SyncChange(
665 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data));
666 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
667 }
668
513 // Gets the currently configured app launchers from the controller. 669 // Gets the currently configured app launchers from the controller.
514 void GetAppLaunchers(ChromeLauncherControllerImpl* controller, 670 void GetAppLaunchers(ChromeLauncherControllerImpl* controller,
515 std::vector<std::string>* launchers) { 671 std::vector<std::string>* launchers) {
516 launchers->clear(); 672 launchers->clear();
517 for (ash::ShelfItems::const_iterator iter(model_->items().begin()); 673 for (ash::ShelfItems::const_iterator iter(model_->items().begin());
518 iter != model_->items().end(); ++iter) { 674 iter != model_->items().end(); ++iter) {
519 ChromeLauncherControllerImpl::IDToItemControllerMap::const_iterator entry( 675 ChromeLauncherControllerImpl::IDToItemControllerMap::const_iterator entry(
520 controller->id_to_item_controller_map_.find(iter->id)); 676 controller->id_to_item_controller_map_.find(iter->id));
521 if (iter->type == ash::TYPE_APP_SHORTCUT && 677 if (iter->type == ash::TYPE_APP_SHORTCUT &&
522 entry != controller->id_to_item_controller_map_.end()) { 678 entry != controller->id_to_item_controller_map_.end()) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id())); 754 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id()));
599 } else if (app == extension6_->id()) { 755 } else if (app == extension6_->id()) {
600 result += "App6"; 756 result += "App6";
601 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); 757 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id()));
602 } else if (app == extension7_->id()) { 758 } else if (app == extension7_->id()) {
603 result += "App7"; 759 result += "App7";
604 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); 760 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id()));
605 } else if (app == extension8_->id()) { 761 } else if (app == extension8_->id()) {
606 result += "App8"; 762 result += "App8";
607 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); 763 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 { 764 } else {
611 result += "unknown"; 765 bool arc_app_found = false;
766 for (const auto& arc_app : arc_test_.fake_apps()) {
767 if (app == ArcAppTest::GetAppId(arc_app)) {
768 result += arc_app.name;
769 arc_app_found = true;
770 break;
771 }
772 }
773 if (!arc_app_found)
774 result += "unknown";
612 } 775 }
613 break; 776 break;
614 } 777 }
615 case ash::TYPE_BROWSER_SHORTCUT: 778 case ash::TYPE_BROWSER_SHORTCUT:
616 result += "Chrome"; 779 result += "Chrome";
617 break; 780 break;
618 case ash::TYPE_APP_LIST: 781 case ash::TYPE_APP_LIST:
619 result += "AppList"; 782 result += "AppList";
620 break; 783 break;
621 default: 784 default:
622 result += "Unknown"; 785 result += "Unknown";
623 break; 786 break;
624 } 787 }
625 } 788 }
626 return result; 789 return result;
627 } 790 }
628 791
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 792 // Remember the order of unpinned but running applications for the current
636 // user. 793 // user.
637 void RememberUnpinnedRunningApplicationOrder() { 794 void RememberUnpinnedRunningApplicationOrder() {
638 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); 795 launcher_controller_->RememberUnpinnedRunningApplicationOrder();
639 } 796 }
640 797
641 // Restore the order of running but unpinned applications for a given user. 798 // Restore the order of running but unpinned applications for a given user.
642 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) { 799 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) {
643 launcher_controller_->RestoreUnpinnedRunningApplicationOrder( 800 launcher_controller_->RestoreUnpinnedRunningApplicationOrder(
644 account_id.GetUserEmail()); 801 account_id.GetUserEmail());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 scoped_refptr<Extension> extension4_; 840 scoped_refptr<Extension> extension4_;
684 scoped_refptr<Extension> extension5_; 841 scoped_refptr<Extension> extension5_;
685 scoped_refptr<Extension> extension6_; 842 scoped_refptr<Extension> extension6_;
686 scoped_refptr<Extension> extension7_; 843 scoped_refptr<Extension> extension7_;
687 scoped_refptr<Extension> extension8_; 844 scoped_refptr<Extension> extension8_;
688 845
689 ArcAppTest arc_test_; 846 ArcAppTest arc_test_;
690 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_; 847 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_;
691 std::unique_ptr<TestShelfModelObserver> model_observer_; 848 std::unique_ptr<TestShelfModelObserver> model_observer_;
692 std::unique_ptr<ash::ShelfModel> model_; 849 std::unique_ptr<ash::ShelfModel> model_;
850 std::unique_ptr<TestingProfileManager> profile_manager_;
693 851
694 // |item_delegate_manager_| owns |test_controller_|. 852 // |item_delegate_manager_| owns |test_controller_|.
695 LauncherItemController* test_controller_; 853 LauncherItemController* test_controller_;
696 854
697 ExtensionService* extension_service_; 855 ExtensionService* extension_service_;
698 856
857 app_list::AppListSyncableService* app_service_;
858
699 ash::ShelfItemDelegateManager* item_delegate_manager_; 859 ash::ShelfItemDelegateManager* item_delegate_manager_;
700 860
701 private: 861 private:
702 TestBrowserWindow* CreateTestBrowserWindowAura() { 862 TestBrowserWindow* CreateTestBrowserWindowAura() {
703 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); 863 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
704 window->set_id(0); 864 window->set_id(0);
705 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 865 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
706 window->Init(ui::LAYER_TEXTURED); 866 window->Init(ui::LAYER_TEXTURED);
707 aura::client::ParentWindowWithContext(window.get(), GetContext(), 867 aura::client::ParentWindowWithContext(window.get(), GetContext(),
708 gfx::Rect(200, 200)); 868 gfx::Rect(200, 200));
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 1131
972 private: 1132 private:
973 typedef std::map<Profile*, std::string> ProfileToNameMap; 1133 typedef std::map<Profile*, std::string> ProfileToNameMap;
974 TestingProfileManager* profile_manager() { return profile_manager_.get(); } 1134 TestingProfileManager* profile_manager() { return profile_manager_.get(); }
975 1135
976 chromeos::FakeChromeUserManager* GetFakeUserManager() { 1136 chromeos::FakeChromeUserManager* GetFakeUserManager() {
977 return static_cast<chromeos::FakeChromeUserManager*>( 1137 return static_cast<chromeos::FakeChromeUserManager*>(
978 user_manager::UserManager::Get()); 1138 user_manager::UserManager::Get());
979 } 1139 }
980 1140
981 std::unique_ptr<TestingProfileManager> profile_manager_;
982 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 1141 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
983 1142
984 ash::test::TestShellDelegate* shell_delegate_; 1143 ash::test::TestShellDelegate* shell_delegate_;
985 1144
986 ProfileToNameMap created_profiles_; 1145 ProfileToNameMap created_profiles_;
987 1146
988 DISALLOW_COPY_AND_ASSIGN( 1147 DISALLOW_COPY_AND_ASSIGN(
989 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); 1148 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest);
990 }; 1149 };
991 1150
992 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) { 1151 TEST_F(ChromeLauncherControllerImplTest, DefaultApps) {
993 InitLauncherController(); 1152 InitLauncherController();
994 // Model should only contain the browser shortcut and app list items. 1153 // Model should only contain the browser shortcut and app list items.
995 EXPECT_EQ(2, model_->item_count()); 1154 EXPECT_EQ(2, model_->item_count());
996 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1155 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
997 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1156 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
998 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1157 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
999 1158
1000 // Installing |extension3_| should add it to the launcher - behind the 1159 // Installing |extension3_| should add it to the launcher - behind the
1001 // chrome icon. 1160 // chrome icon.
1002 extension_service_->AddExtension(extension3_.get()); 1161 extension_service_->AddExtension(extension3_.get());
1003 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1162 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1004 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1163 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1005 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1164 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1006 } 1165 }
1007 1166
1167 TEST_F(ChromeLauncherControllerImplTest, ArcAppPinCrossPlatformWorkflow) {
1168 // Work on Arc-disabled platform first.
1169 arc_test_.SetUp(profile());
1170
1171 const std::string arc_app_id1 =
1172 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]);
1173 const std::string arc_app_id2 =
1174 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]);
1175 const std::string arc_app_id3 =
1176 ArcAppTest::GetAppId(arc_test_.fake_apps()[2]);
1177
1178 InitLauncherController();
1179
1180 extension_service_->AddExtension(extension1_.get());
1181 extension_service_->AddExtension(extension2_.get());
1182 extension_service_->AddExtension(extension3_.get());
1183
1184 // extension 1, 3 are pinned by user
1185 syncer::SyncChangeList sync_list;
1186 InsertAddPinChange(&sync_list, 0, extension1_->id());
1187 InsertAddPinChange(&sync_list, 1, arc_app_id1);
1188 InsertAddPinChange(&sync_list, 2, extension2_->id());
1189 InsertAddPinChange(&sync_list, 3, arc_app_id2);
1190 InsertAddPinChange(&sync_list, 4, extension3_->id());
1191 SendPinChanges(sync_list, true);
1192 SetShelfChromeIconIndex(1);
1193
1194 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1195 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1196 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1197 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1198 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1199 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1200 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1201
1202 // Persist pin state, we don't have active pin for Arc apps yet, but pin
1203 // model should have it.
1204 syncer::SyncDataList copy_sync_list =
1205 app_service_->GetAllSyncData(syncer::APP_LIST);
1206
1207 launcher_controller_.reset();
1208 SendPinChanges(syncer::SyncChangeList(), true);
1209 StopAppSyncService();
1210 EXPECT_EQ(0U, app_service_->sync_items().size());
1211
1212 // Move to Arc-enabled platform, restart syncing with stored data.
1213 StartAppSyncService(copy_sync_list);
1214 RecreateChromeLauncher();
1215
1216 // Pins must be automatically updated.
1217 SendListOfArcApps();
1218 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1219 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1220 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1221 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1222 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1223 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1224
1225 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3",
1226 GetPinnedAppStatus());
1227
1228 // Now move pins on Arc-enabled platform.
1229 model_->Move(1, 4);
1230 model_->Move(3, 1);
1231 model_->Move(3, 5);
1232 model_->Move(4, 2);
1233 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3",
1234 GetPinnedAppStatus());
1235
1236 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST);
1237
1238 launcher_controller_.reset();
1239 ResetPinModel();
1240
1241 SendPinChanges(syncer::SyncChangeList(), true);
1242 StopAppSyncService();
1243 EXPECT_EQ(0U, app_service_->sync_items().size());
1244
1245 // Move back to Arc-disabled platform.
1246 EnableArc(false);
1247 StartAppSyncService(copy_sync_list);
1248 RecreateChromeLauncher();
1249
1250 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1251 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1252 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1253 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1254 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1255 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1256 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus());
1257
1258 // Now move/remove pins on Arc-disabled platform.
1259 model_->Move(4, 2);
1260 launcher_controller_->UnpinAppWithID(extension2_->id());
1261 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus());
1262 EnableArc(true);
1263
1264 SendListOfArcApps();
1265
1266 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1267 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1268 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1269 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1270 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1271 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1272 EXPECT_EQ("AppList, Fake App 1, App3, Chrome, App1, Fake App 0",
1273 GetPinnedAppStatus());
1274 }
1275
1008 /* 1276 /*
1009 * Test ChromeLauncherControllerImpl correctly merges policy pinned apps 1277 * Test ChromeLauncherControllerImpl correctly merges policy pinned apps
1010 * and user pinned apps 1278 * and user pinned apps
1011 */ 1279 */
1012 TEST_F(ChromeLauncherControllerImplTest, MergePolicyAndUserPrefPinnedApps) { 1280 TEST_F(ChromeLauncherControllerImplTest, MergePolicyAndUserPrefPinnedApps) {
1013 InitLauncherController(); 1281 InitLauncherController();
1014 1282
1015 base::ListValue user_pref_value;
1016 extension_service_->AddExtension(extension1_.get()); 1283 extension_service_->AddExtension(extension1_.get());
1017 extension_service_->AddExtension(extension3_.get()); 1284 extension_service_->AddExtension(extension3_.get());
1018 extension_service_->AddExtension(extension4_.get()); 1285 extension_service_->AddExtension(extension4_.get());
1019 extension_service_->AddExtension(extension5_.get()); 1286 extension_service_->AddExtension(extension5_.get());
1020 // extension 1, 3 are pinned by user 1287 // extension 1, 3 are pinned by user
1021 InsertPrefValue(&user_pref_value, 0, extension1_->id()); 1288 syncer::SyncChangeList sync_list;
1022 InsertPrefValue(&user_pref_value, 1, extension3_->id()); 1289 InsertAddPinChange(&sync_list, 0, extension1_->id());
1023 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1290 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId);
1024 user_pref_value.DeepCopy()); 1291 InsertAddPinChange(&sync_list, 2, extension3_->id());
1292 SendPinChanges(sync_list, true);
1025 1293
1026 base::ListValue policy_value; 1294 base::ListValue policy_value;
1027 // extension 2 4 are pinned by policy 1295 // extension 2 4 are pinned by policy
1028 InsertPrefValue(&policy_value, 0, extension2_->id()); 1296 InsertPrefValue(&policy_value, 0, extension2_->id());
1029 InsertPrefValue(&policy_value, 1, extension4_->id()); 1297 InsertPrefValue(&policy_value, 1, extension4_->id());
1030 profile()->GetTestingPrefService()->SetManagedPref( 1298 profile()->GetTestingPrefService()->SetManagedPref(
1031 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 1299 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
1032 1300
1033 SetShelfChromeIconIndex(1);
1034
1035 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1301 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1036 // 2 is not pinned as it's not installed 1302 // 2 is not pinned as it's not installed
1037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1303 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1038 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1304 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1039 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 1305 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
1040 // install extension 2 and check 1306 // install extension 2 and check
1041 extension_service_->AddExtension(extension2_.get()); 1307 extension_service_->AddExtension(extension2_.get());
1042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1308 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1043 1309
1044 // Check user can manually pin or unpin these apps 1310 // Check user can manually pin or unpin these apps
1045 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1311 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1046 launcher_controller_->GetPinnable(extension1_->id())); 1312 launcher_controller_->GetPinnable(extension1_->id()));
1047 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1313 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1048 launcher_controller_->GetPinnable(extension2_->id())); 1314 launcher_controller_->GetPinnable(extension2_->id()));
1049 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1315 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1050 launcher_controller_->GetPinnable(extension3_->id())); 1316 launcher_controller_->GetPinnable(extension3_->id()));
1051 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1317 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1052 launcher_controller_->GetPinnable(extension4_->id())); 1318 launcher_controller_->GetPinnable(extension4_->id()));
1053 1319
1054 // Check the order of shelf pinned apps 1320 // Check the order of shelf pinned apps
1055 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus()); 1321 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus());
1056 } 1322 }
1057 1323
1058 // Check that the restauration of launcher items is happening in the same order 1324 // 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 1325 // as the user has pinned them (on another system) when they are synced reverse
1060 // order. 1326 // order.
1061 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsReverseOrder) { 1327 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsReverseOrder) {
1062 InitLauncherController(); 1328 InitLauncherController();
1063 1329
1064 base::ListValue policy_value; 1330 syncer::SyncChangeList sync_list;
1065 InsertPrefValue(&policy_value, 0, extension1_->id()); 1331 InsertAddPinChange(&sync_list, 0, extension1_->id());
1066 InsertPrefValue(&policy_value, 1, extension2_->id()); 1332 InsertAddPinChange(&sync_list, 1, extension2_->id());
1067 InsertPrefValue(&policy_value, 2, extension3_->id()); 1333 InsertAddPinChange(&sync_list, 2, extension3_->id());
1068 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1334 SendPinChanges(sync_list, true);
1069 policy_value.DeepCopy()); 1335
1070 SetShelfChromeIconIndex(0);
1071 // Model should only contain the browser shortcut and app list items. 1336 // Model should only contain the browser shortcut and app list items.
1072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1337 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1073 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1338 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1074 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1339 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1075 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1340 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1076 1341
1077 // Installing |extension3_| should add it to the shelf - behind the 1342 // Installing |extension3_| should add it to the shelf - behind the
1078 // chrome icon. 1343 // chrome icon.
1079 ash::ShelfItem item; 1344 ash::ShelfItem item;
1080 extension_service_->AddExtension(extension3_.get()); 1345 extension_service_->AddExtension(extension3_.get());
(...skipping 12 matching lines...) Expand all
1093 extension_service_->AddExtension(extension1_.get()); 1358 extension_service_->AddExtension(extension1_.get());
1094 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1359 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1095 } 1360 }
1096 1361
1097 // Check that the restauration of launcher items is happening in the same order 1362 // 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 1363 // as the user has pinned them (on another system) when they are synced random
1099 // order. 1364 // order.
1100 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsRandomOrder) { 1365 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsRandomOrder) {
1101 InitLauncherController(); 1366 InitLauncherController();
1102 1367
1103 base::ListValue policy_value; 1368 syncer::SyncChangeList sync_list;
1104 InsertPrefValue(&policy_value, 0, extension1_->id()); 1369 InsertAddPinChange(&sync_list, 0, extension1_->id());
1105 InsertPrefValue(&policy_value, 1, extension2_->id()); 1370 InsertAddPinChange(&sync_list, 1, extension2_->id());
1106 InsertPrefValue(&policy_value, 2, extension3_->id()); 1371 InsertAddPinChange(&sync_list, 2, extension3_->id());
1372 SendPinChanges(sync_list, true);
1107 1373
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. 1374 // Model should only contain the browser shortcut and app list items.
1112 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1375 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1113 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1376 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1114 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1377 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1115 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1378 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1116 1379
1117 // Installing |extension2_| should add it to the launcher - behind the 1380 // Installing |extension2_| should add it to the launcher - behind the
1118 // chrome icon. 1381 // chrome icon.
1119 extension_service_->AddExtension(extension2_.get()); 1382 extension_service_->AddExtension(extension2_.get());
1120 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1383 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 12 matching lines...) Expand all
1133 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1396 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1134 } 1397 }
1135 1398
1136 // Check that the restauration of launcher items is happening in the same order 1399 // 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 1400 // as the user has pinned / moved them (on another system) when they are synced
1138 // random order - including the chrome icon. 1401 // random order - including the chrome icon.
1139 TEST_F(ChromeLauncherControllerImplTest, 1402 TEST_F(ChromeLauncherControllerImplTest,
1140 RestoreDefaultAppsRandomOrderChromeMoved) { 1403 RestoreDefaultAppsRandomOrderChromeMoved) {
1141 InitLauncherController(); 1404 InitLauncherController();
1142 1405
1143 base::ListValue policy_value; 1406 syncer::SyncChangeList sync_list;
1144 InsertPrefValue(&policy_value, 0, extension1_->id()); 1407 InsertAddPinChange(&sync_list, 0, extension1_->id());
1145 InsertPrefValue(&policy_value, 1, extension2_->id()); 1408 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId);
1146 InsertPrefValue(&policy_value, 2, extension3_->id()); 1409 InsertAddPinChange(&sync_list, 2, extension2_->id());
1147 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1410 InsertAddPinChange(&sync_list, 3, extension3_->id());
1148 policy_value.DeepCopy()); 1411 SendPinChanges(sync_list, true);
1149 SetShelfChromeIconIndex(1); 1412
1150 // Model should only contain the browser shortcut and app list items. 1413 // Model should only contain the browser shortcut and app list items.
1151 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1414 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1415 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1153 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1416 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1154 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1417 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1155 1418
1156 // Installing |extension2_| should add it to the shelf - behind the 1419 // Installing |extension2_| should add it to the shelf - behind the
1157 // chrome icon. 1420 // chrome icon.
1158 ash::ShelfItem item; 1421 ash::ShelfItem item;
1159 extension_service_->AddExtension(extension2_.get()); 1422 extension_service_->AddExtension(extension2_.get());
1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1423 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1161 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1424 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1162 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1425 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1163 1426
1164 // Installing |extension1_| should add it to the launcher - behind the 1427 // Installing |extension1_| should add it to the launcher - behind the
1165 // chrome icon, but in first location. 1428 // chrome icon, but in first location.
1166 extension_service_->AddExtension(extension1_.get()); 1429 extension_service_->AddExtension(extension1_.get());
1167 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1430 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1168 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); 1431 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus());
1169 1432
1170 // Installing |extension3_| should add it to the launcher - behind the 1433 // Installing |extension3_| should add it to the launcher - behind the
1171 // chrome icon, but in first location. 1434 // chrome icon, but in first location.
1172 extension_service_->AddExtension(extension3_.get()); 1435 extension_service_->AddExtension(extension3_.get());
1173 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 1436 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1174 } 1437 }
1175 1438
1176 // Check that syncing to a different state does the correct thing. 1439 // Check that syncing to a different state does the correct thing.
1177 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsResyncOrder) { 1440 TEST_F(ChromeLauncherControllerImplTest, RestoreDefaultAppsResyncOrder) {
1178 InitLauncherController(); 1441 InitLauncherController();
1179 base::ListValue policy_value; 1442
1180 InsertPrefValue(&policy_value, 0, extension1_->id()); 1443 syncer::SyncChangeList sync_list0;
1181 InsertPrefValue(&policy_value, 1, extension2_->id()); 1444 InsertAddPinChange(&sync_list0, 0, extension1_->id());
1182 InsertPrefValue(&policy_value, 2, extension3_->id()); 1445 InsertAddPinChange(&sync_list0, 1, extension2_->id());
1183 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1446 InsertAddPinChange(&sync_list0, 2, extension3_->id());
1184 policy_value.DeepCopy()); 1447 SendPinChanges(sync_list0, true);
1448
1185 // The shelf layout has always one static item at the beginning (App List). 1449 // The shelf layout has always one static item at the beginning (App List).
1186 SetShelfChromeIconIndex(0);
1187 extension_service_->AddExtension(extension2_.get()); 1450 extension_service_->AddExtension(extension2_.get());
1188 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1451 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1189 extension_service_->AddExtension(extension1_.get()); 1452 extension_service_->AddExtension(extension1_.get());
1190 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 1453 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
1191 extension_service_->AddExtension(extension3_.get()); 1454 extension_service_->AddExtension(extension3_.get());
1192 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1455 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1193 1456
1194 // Change the order with increasing chrome position and decreasing position. 1457 // Change the order with increasing chrome position and decreasing position.
1195 base::ListValue policy_value1; 1458 syncer::SyncChangeList sync_list1;
1196 InsertPrefValue(&policy_value1, 0, extension3_->id()); 1459 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1197 InsertPrefValue(&policy_value1, 1, extension1_->id()); 1460 InsertAddPinChange(&sync_list1, 1, extension1_->id());
1198 InsertPrefValue(&policy_value1, 2, extension2_->id()); 1461 InsertAddPinChange(&sync_list1, 2, extension2_->id());
1199 SetShelfChromeIconIndex(3); 1462 InsertAddPinChange(&sync_list1, 3, extension_misc::kChromeAppId);
1200 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1463 SendPinChanges(sync_list1, true);
1201 policy_value1.DeepCopy());
1202 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); 1464 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus());
1203 base::ListValue policy_value2; 1465
1204 InsertPrefValue(&policy_value2, 0, extension2_->id()); 1466 syncer::SyncChangeList sync_list2;
1205 InsertPrefValue(&policy_value2, 1, extension3_->id()); 1467 InsertAddPinChange(&sync_list2, 0, extension2_->id());
1206 InsertPrefValue(&policy_value2, 2, extension1_->id()); 1468 InsertAddPinChange(&sync_list2, 1, extension3_->id());
1207 SetShelfChromeIconIndex(2); 1469 InsertAddPinChange(&sync_list2, 2, extension_misc::kChromeAppId);
1208 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1470 InsertAddPinChange(&sync_list2, 3, extension1_->id());
1209 policy_value2.DeepCopy()); 1471 SendPinChanges(sync_list2, true);
1210 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); 1472 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus());
1211 1473
1212 // Check that the chrome icon can also be at the first possible location. 1474 // Check that the chrome icon can also be at the first possible location.
1213 SetShelfChromeIconIndex(0); 1475 syncer::SyncChangeList sync_list3;
1214 base::ListValue policy_value3; 1476 InsertAddPinChange(&sync_list3, 0, extension3_->id());
1215 InsertPrefValue(&policy_value3, 0, extension3_->id()); 1477 InsertAddPinChange(&sync_list3, 1, extension2_->id());
1216 InsertPrefValue(&policy_value3, 1, extension2_->id()); 1478 InsertAddPinChange(&sync_list3, 2, extension1_->id());
1217 InsertPrefValue(&policy_value3, 2, extension1_->id()); 1479 SendPinChanges(sync_list3, true);
1218 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1219 policy_value3.DeepCopy());
1220 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 1480 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1221 1481
1222 // Check that unloading of extensions works as expected. 1482 // Check that unloading of extensions works as expected.
1223 extension_service_->UnloadExtension(extension1_->id(), 1483 extension_service_->UnloadExtension(extension1_->id(),
1224 UnloadedExtensionInfo::REASON_UNINSTALL); 1484 UnloadedExtensionInfo::REASON_UNINSTALL);
1225 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); 1485 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus());
1226 1486
1227 extension_service_->UnloadExtension(extension2_->id(), 1487 extension_service_->UnloadExtension(extension2_->id(),
1228 UnloadedExtensionInfo::REASON_UNINSTALL); 1488 UnloadedExtensionInfo::REASON_UNINSTALL);
1229 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1489 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1688 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1429 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1689 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1430 launcher_controller_->UnlockV1AppWithID(extension3_->id()); 1690 launcher_controller_->UnlockV1AppWithID(extension3_->id());
1431 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1691 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1432 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1692 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1433 } 1693 }
1434 1694
1435 TEST_F(ChromeLauncherControllerImplTest, ArcDeferredLaunch) { 1695 TEST_F(ChromeLauncherControllerImplTest, ArcDeferredLaunch) {
1436 arc_test_.SetUp(profile()); 1696 arc_test_.SetUp(profile());
1437 1697
1438 launcher_controller_.reset( 1698 RecreateChromeLauncher();
1439 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get()));
1440 launcher_controller_->Init();
1441 1699
1442 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0]; 1700 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0];
1443 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1]; 1701 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1];
1444 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2]; 1702 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2];
1445 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1); 1703 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1);
1446 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2); 1704 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2);
1447 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3); 1705 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3);
1448 1706
1449 SendListOfArcApps(); 1707 SendListOfArcApps();
1450 1708
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 2059
1802 EXPECT_EQ(2, model_->item_count()); 2060 EXPECT_EQ(2, model_->item_count());
1803 } 2061 }
1804 2062
1805 // Check that a locked (windowed V1 application) will be properly converted 2063 // Check that a locked (windowed V1 application) will be properly converted
1806 // between locked and pinned when the order gets changed through a profile / 2064 // between locked and pinned when the order gets changed through a profile /
1807 // policy change. 2065 // policy change.
1808 TEST_F(ChromeLauncherControllerImplTest, 2066 TEST_F(ChromeLauncherControllerImplTest,
1809 RestoreDefaultAndLockedAppsResyncOrder) { 2067 RestoreDefaultAndLockedAppsResyncOrder) {
1810 InitLauncherController(); 2068 InitLauncherController();
1811 base::ListValue policy_value0; 2069
1812 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2070 syncer::SyncChangeList sync_list;
1813 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2071 InsertAddPinChange(&sync_list, 0, extension1_->id());
1814 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2072 InsertAddPinChange(&sync_list, 1, extension3_->id());
1815 policy_value0.DeepCopy()); 2073 SendPinChanges(sync_list, true);
2074
1816 // The shelf layout has always one static item at the beginning (App List). 2075 // The shelf layout has always one static item at the beginning (App List).
1817 SetShelfChromeIconIndex(0);
1818 extension_service_->AddExtension(extension1_.get()); 2076 extension_service_->AddExtension(extension1_.get());
1819 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2077 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1820 extension_service_->AddExtension(extension2_.get()); 2078 extension_service_->AddExtension(extension2_.get());
1821 // No new app icon will be generated. 2079 // No new app icon will be generated.
1822 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2080 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
2081
1823 // Add the app as locked app which will add it (un-pinned). 2082 // Add the app as locked app which will add it (un-pinned).
1824 launcher_controller_->LockV1AppWithID(extension2_->id()); 2083 launcher_controller_->LockV1AppWithID(extension2_->id());
1825 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); 2084 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus());
1826 extension_service_->AddExtension(extension3_.get()); 2085 extension_service_->AddExtension(extension3_.get());
1827 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); 2086 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus());
1828 2087
1829 // Now request to pin all items which should convert the locked item into a 2088 // Now request to pin all items which should convert the locked item into a
1830 // pinned item. 2089 // pinned item.
1831 base::ListValue policy_value1; 2090 syncer::SyncChangeList sync_list1;
1832 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2091 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1833 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2092 InsertAddPinChange(&sync_list1, 1, extension2_->id());
1834 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2093 InsertAddPinChange(&sync_list1, 2, extension1_->id());
1835 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2094 SendPinChanges(sync_list1, true);
1836 policy_value1.DeepCopy());
1837 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2095 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1838 2096
1839 // Going back to a status where there is no requirement for app 2 to be pinned 2097 // 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 2098 // 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 2099 // 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 2100 // applications are not allowed to be mixed with shortcuts, it should show up
1843 // at the end of the list. 2101 // at the end of the list.
1844 base::ListValue policy_value2; 2102 syncer::SyncChangeList sync_list2;
1845 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2103 InsertAddPinChange(&sync_list2, 0, extension3_->id());
1846 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2104 InsertAddPinChange(&sync_list2, 1, extension1_->id());
1847 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2105 SendPinChanges(sync_list2, true);
1848 policy_value2.DeepCopy());
1849 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); 2106 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus());
1850 2107
1851 // Removing an item should simply close it and everything should shift. 2108 // Removing an item should simply close it and everything should shift.
1852 base::ListValue policy_value3; 2109 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()); 2110 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus());
1857 } 2111 }
1858 2112
1859 // Check that a running and not pinned V2 application will be properly converted 2113 // 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 / 2114 // between locked and pinned when the order gets changed through a profile /
1861 // policy change. 2115 // policy change.
1862 TEST_F(ChromeLauncherControllerImplTest, 2116 TEST_F(ChromeLauncherControllerImplTest,
1863 RestoreDefaultAndRunningV2AppsResyncOrder) { 2117 RestoreDefaultAndRunningV2AppsResyncOrder) {
1864 InitLauncherController(); 2118 InitLauncherController();
1865 base::ListValue policy_value0; 2119 syncer::SyncChangeList sync_list0;
1866 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2120 InsertAddPinChange(&sync_list0, 0, extension1_->id());
1867 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2121 InsertAddPinChange(&sync_list0, 1, extension3_->id());
1868 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2122 SendPinChanges(sync_list0, true);
1869 policy_value0.DeepCopy());
1870 // The shelf layout has always one static item at the beginning (app List). 2123 // The shelf layout has always one static item at the beginning (app List).
1871 SetShelfChromeIconIndex(0);
1872 extension_service_->AddExtension(extension1_.get()); 2124 extension_service_->AddExtension(extension1_.get());
1873 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2125 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1874 extension_service_->AddExtension(extension2_.get()); 2126 extension_service_->AddExtension(extension2_.get());
1875 // No new app icon will be generated. 2127 // No new app icon will be generated.
1876 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2128 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1877 // Add the app as an unpinned but running V2 app. 2129 // Add the app as an unpinned but running V2 app.
1878 CreateRunningV2App(extension2_->id()); 2130 CreateRunningV2App(extension2_->id());
1879 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); 2131 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus());
1880 extension_service_->AddExtension(extension3_.get()); 2132 extension_service_->AddExtension(extension3_.get());
1881 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); 2133 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus());
1882 2134
1883 // Now request to pin all items which should convert the locked item into a 2135 // Now request to pin all items which should convert the locked item into a
1884 // pinned item. 2136 // pinned item.
1885 base::ListValue policy_value1; 2137 syncer::SyncChangeList sync_list1;
1886 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2138 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1887 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2139 InsertAddPinChange(&sync_list1, 1, extension2_->id());
1888 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2140 InsertAddPinChange(&sync_list1, 2, extension1_->id());
1889 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2141 SendPinChanges(sync_list1, true);
1890 policy_value1.DeepCopy());
1891 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2142 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1892 2143
1893 // Going back to a status where there is no requirement for app 2 to be pinned 2144 // 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 2145 // 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. 2146 // by the |ShelfModel|'s weight system, it will be after last pinned item.
1896 base::ListValue policy_value2; 2147 syncer::SyncChangeList sync_list2;
1897 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2148 InsertAddPinChange(&sync_list2, 0, extension3_->id());
1898 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2149 InsertAddPinChange(&sync_list2, 1, extension1_->id());
1899 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2150 SendPinChanges(sync_list2, true);
1900 policy_value2.DeepCopy());
1901 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); 2151 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus());
1902 2152
1903 // Removing an item should simply close it and everything should shift. 2153 // Removing an item should simply close it and everything should shift.
1904 base::ListValue policy_value3; 2154 syncer::SyncChangeList sync_list3;
1905 InsertPrefValue(&policy_value3, 0, extension3_->id()); 2155 InsertAddPinChange(&sync_list3, 0, extension3_->id());
1906 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2156 SendPinChanges(sync_list3, true);
1907 policy_value3.DeepCopy());
1908 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); 2157 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus());
1909 } 2158 }
1910 2159
1911 // Each user has a different set of applications pinned. Check that when 2160 // Each user has a different set of applications pinned. Check that when
1912 // switching between the two users, the state gets properly set. 2161 // switching between the two users, the state gets properly set.
1913 TEST_F(ChromeLauncherControllerImplTest, UserSwitchIconRestore) { 2162 TEST_F(ChromeLauncherControllerImplTest, UserSwitchIconRestore) {
1914 base::ListValue user_a; 2163 syncer::SyncChangeList user_a;
1915 base::ListValue user_b; 2164 syncer::SyncChangeList user_b;
2165
1916 SetUpMultiUserScenario(&user_a, &user_b); 2166 SetUpMultiUserScenario(&user_a, &user_b);
2167
1917 // Show user 1. 2168 // Show user 1.
1918 SetShelfChromeIconIndex(6); 2169 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", 2170 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1922 GetPinnedAppStatus()); 2171 GetPinnedAppStatus());
1923 2172
1924 // Show user 2. 2173 // Show user 2.
1925 SetShelfChromeIconIndex(4); 2174 SendPinChanges(user_b, true);
1926 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1927 user_b.DeepCopy());
1928
1929 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2175 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1930 2176
1931 // Switch back to 1. 2177 // Switch back to 1.
1932 SetShelfChromeIconIndex(8); 2178 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", 2179 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1936 GetPinnedAppStatus()); 2180 GetPinnedAppStatus());
1937 2181
1938 // Switch back to 2. 2182 // Switch back to 2.
1939 SetShelfChromeIconIndex(4); 2183 SendPinChanges(user_b, true);
1940 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1941 user_b.DeepCopy());
1942 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2184 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1943 } 2185 }
1944 2186
1945 // Each user has a different set of applications pinned, and one user has an 2187 // 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 2188 // application running. Check that when switching between the two users, the
1947 // state gets properly set. 2189 // state gets properly set.
1948 TEST_F(ChromeLauncherControllerImplTest, 2190 TEST_F(ChromeLauncherControllerImplTest,
1949 UserSwitchIconRestoreWithRunningV2App) { 2191 UserSwitchIconRestoreWithRunningV2App) {
1950 base::ListValue user_a; 2192 syncer::SyncChangeList user_a;
1951 base::ListValue user_b; 2193 syncer::SyncChangeList user_b;
2194
1952 SetUpMultiUserScenario(&user_a, &user_b); 2195 SetUpMultiUserScenario(&user_a, &user_b);
1953 2196
1954 // Run App1 and assume that it is a V2 app. 2197 // Run App1 and assume that it is a V2 app.
1955 CreateRunningV2App(extension1_->id()); 2198 CreateRunningV2App(extension1_->id());
1956 2199
1957 // Show user 1. 2200 // Show user 1.
1958 SetShelfChromeIconIndex(6); 2201 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", 2202 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1962 GetPinnedAppStatus()); 2203 GetPinnedAppStatus());
1963 2204
1964 // Show user 2. 2205 // Show user 2.
1965 SetShelfChromeIconIndex(4); 2206 SendPinChanges(user_b, true);
1966 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1967 user_b.DeepCopy());
1968
1969 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2207 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1970 2208
1971 // Switch back to 1. 2209 // Switch back to 1.
1972 SetShelfChromeIconIndex(8); 2210 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", 2211 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1976 GetPinnedAppStatus()); 2212 GetPinnedAppStatus());
1977 2213
1978 // Switch back to 2. 2214 // Switch back to 2.
1979 SetShelfChromeIconIndex(4); 2215 SendPinChanges(user_b, true);
1980 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1981 user_b.DeepCopy());
1982 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2216 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1983 } 2217 }
1984 2218
1985 // Each user has a different set of applications pinned, and one user has an 2219 // 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. 2220 // 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. 2221 // Check that when switching between the two users, the state gets properly set.
1988 // There was once a bug associated with this. 2222 // There was once a bug associated with this.
1989 TEST_F(ChromeLauncherControllerImplTest, 2223 TEST_F(ChromeLauncherControllerImplTest,
1990 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { 2224 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) {
1991 base::ListValue user_a; 2225 syncer::SyncChangeList user_a;
1992 base::ListValue user_b; 2226 syncer::SyncChangeList user_b;
1993 SetUpMultiUserScenario(&user_a, &user_b); 2227 SetUpMultiUserScenario(&user_a, &user_b);
1994 2228
1995 // Run App1 and assume that it is a V2 app. 2229 // Run App1 and assume that it is a V2 app.
1996 CreateRunningV2App(extension1_->id()); 2230 CreateRunningV2App(extension1_->id());
1997 2231
1998 // Show user 1. 2232 // Show user 1.
2233 SendPinChanges(user_a, true);
1999 SetShelfChromeIconIndex(5); 2234 SetShelfChromeIconIndex(5);
2000 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2001 user_a.DeepCopy());
2002 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2235 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2003 GetPinnedAppStatus()); 2236 GetPinnedAppStatus());
2004 2237
2005 // Show user 2. 2238 // Show user 2.
2239 SendPinChanges(user_b, true);
2006 SetShelfChromeIconIndex(4); 2240 SetShelfChromeIconIndex(4);
2007 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2008 user_b.DeepCopy());
2009
2010 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2241 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
2011 2242
2012 // Switch back to 1. 2243 // Switch back to 1.
2244 SendPinChanges(user_a, true);
2013 SetShelfChromeIconIndex(5); 2245 SetShelfChromeIconIndex(5);
2014 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2015 user_a.DeepCopy());
2016 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2246 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2017 GetPinnedAppStatus()); 2247 GetPinnedAppStatus());
2018 } 2248 }
2019 2249
2020 TEST_F(ChromeLauncherControllerImplTest, Policy) { 2250 TEST_F(ChromeLauncherControllerImplTest, Policy) {
2021 extension_service_->AddExtension(extension1_.get()); 2251 extension_service_->AddExtension(extension1_.get());
2022 extension_service_->AddExtension(extension3_.get()); 2252 extension_service_->AddExtension(extension3_.get());
2023 2253
2254 InitLauncherController();
2255
2256 syncer::SyncChangeList sync_list;
2257 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId);
2258 SendPinChanges(sync_list, true);
2259
2024 base::ListValue policy_value; 2260 base::ListValue policy_value;
2025 InsertPrefValue(&policy_value, 0, extension1_->id()); 2261 InsertPrefValue(&policy_value, 0, extension1_->id());
2026 InsertPrefValue(&policy_value, 1, extension2_->id()); 2262 InsertPrefValue(&policy_value, 1, extension2_->id());
2027 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2263 profile()->GetTestingPrefService()->SetManagedPref(
2028 policy_value.DeepCopy()); 2264 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2029 2265
2030 // Only |extension1_| should get pinned. |extension2_| is specified but not 2266 // Only |extension1_| should get pinned. |extension2_| is specified but not
2031 // installed, and |extension3_| is part of the default set, but that shouldn't 2267 // installed, and |extension3_| is part of the default set, but that shouldn't
2032 // take effect when the policy override is in place. 2268 // take effect when the policy override is in place.
2033 InitLauncherController(); 2269 ASSERT_EQ(3, model_->item_count());
2034 EXPECT_EQ(3, model_->item_count()); 2270 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())); 2271 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2272 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2038 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2273 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2039 2274
2040 // Installing |extension2_| should add it to the launcher. 2275 // Installing |extension2_| should add it to the launcher.
2041 extension_service_->AddExtension(extension2_.get()); 2276 extension_service_->AddExtension(extension2_.get());
2042 EXPECT_EQ(4, model_->item_count()); 2277 ASSERT_EQ(4, model_->item_count());
2278 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
2043 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2279 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())); 2280 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2046 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2281 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2047 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2282 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2048 2283
2049 // Removing |extension1_| from the policy should be reflected in the launcher. 2284 // Removing |extension1_| from the policy should not be reflected in the
2285 // launcher and pin will exist.
2050 policy_value.Remove(0, NULL); 2286 policy_value.Remove(0, NULL);
2051 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2287 profile()->GetTestingPrefService()->SetManagedPref(
2052 policy_value.DeepCopy()); 2288 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2053 EXPECT_EQ(3, model_->item_count()); 2289 EXPECT_EQ(4, model_->item_count());
2054 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2290 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2055 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 2291 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2056 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2292 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2057 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2293 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2058 } 2294 }
2059 2295
2060 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) { 2296 TEST_F(ChromeLauncherControllerImplTest, UnpinWithUninstall) {
2061 extension_service_->AddExtension(extension3_.get()); 2297 extension_service_->AddExtension(extension3_.get());
2062 extension_service_->AddExtension(extension4_.get()); 2298 extension_service_->AddExtension(extension4_.get());
2063 2299
2064 InitLauncherController(); 2300 InitLauncherController();
2065 2301
2066 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2302 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2067 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2303 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2068 2304
2069 extension_service_->UnloadExtension(extension3_->id(), 2305 extension_service_->UnloadExtension(extension3_->id(),
2070 UnloadedExtensionInfo::REASON_UNINSTALL); 2306 UnloadedExtensionInfo::REASON_UNINSTALL);
2071 2307
2072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2308 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2073 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2309 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2074 } 2310 }
2075 2311
2076 TEST_F(ChromeLauncherControllerImplTest, PrefUpdates) { 2312 TEST_F(ChromeLauncherControllerImplTest, SyncUpdates) {
2077 extension_service_->AddExtension(extension2_.get()); 2313 extension_service_->AddExtension(extension2_.get());
2078 extension_service_->AddExtension(extension3_.get()); 2314 extension_service_->AddExtension(extension3_.get());
2079 extension_service_->AddExtension(extension4_.get()); 2315 extension_service_->AddExtension(extension4_.get());
2080 2316
2081 InitLauncherController(); 2317 InitLauncherController();
2082 2318
2319 syncer::SyncChangeList sync_list;
2320 InsertAddPinChange(&sync_list, 10, extension_misc::kChromeAppId);
2321 SendPinChanges(sync_list, true);
2322
2083 std::vector<std::string> expected_launchers; 2323 std::vector<std::string> expected_launchers;
2084 std::vector<std::string> actual_launchers; 2324 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); 2325 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2089 EXPECT_EQ(expected_launchers, actual_launchers); 2326 EXPECT_EQ(expected_launchers, actual_launchers);
2090 2327
2091 // Unavailable extensions don't create launcher items. 2328 // Unavailable extensions don't create launcher items.
2092 InsertPrefValue(&pref_value, 0, extension1_->id()); 2329 sync_list.clear();
2093 InsertPrefValue(&pref_value, 1, extension2_->id()); 2330 InsertAddPinChange(&sync_list, 0, extension1_->id());
2094 InsertPrefValue(&pref_value, 2, extension4_->id()); 2331 InsertAddPinChange(&sync_list, 1, extension2_->id());
2095 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2332 InsertAddPinChange(&sync_list, 3, extension4_->id());
2096 pref_value.DeepCopy()); 2333 SendPinChanges(sync_list, false);
2334
2097 expected_launchers.push_back(extension2_->id()); 2335 expected_launchers.push_back(extension2_->id());
2098 expected_launchers.push_back(extension4_->id()); 2336 expected_launchers.push_back(extension4_->id());
2099 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2337 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2100 EXPECT_EQ(expected_launchers, actual_launchers); 2338 EXPECT_EQ(expected_launchers, actual_launchers);
2101 2339
2102 // Redundant pref entries show up only once. 2340 sync_list.clear();
2103 InsertPrefValue(&pref_value, 2, extension3_->id()); 2341 InsertAddPinChange(&sync_list, 2, extension3_->id());
2104 InsertPrefValue(&pref_value, 2, extension3_->id()); 2342 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()); 2343 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id());
2109 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2344 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2110 EXPECT_EQ(expected_launchers, actual_launchers); 2345 EXPECT_EQ(expected_launchers, actual_launchers);
2111 2346
2112 // Order changes are reflected correctly. 2347 sync_list.clear();
2113 pref_value.Clear(); 2348 InsertUpdatePinChange(&sync_list, 0, extension4_->id());
2114 InsertPrefValue(&pref_value, 0, extension4_->id()); 2349 InsertUpdatePinChange(&sync_list, 1, extension3_->id());
2115 InsertPrefValue(&pref_value, 1, extension3_->id()); 2350 InsertUpdatePinChange(&sync_list, 2, extension2_->id());
2116 InsertPrefValue(&pref_value, 2, extension2_->id()); 2351 SendPinChanges(sync_list, false);
2117 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2118 pref_value.DeepCopy());
2119 std::reverse(expected_launchers.begin(), expected_launchers.end()); 2352 std::reverse(expected_launchers.begin(), expected_launchers.end());
2120 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2353 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2121 EXPECT_EQ(expected_launchers, actual_launchers); 2354 EXPECT_EQ(expected_launchers, actual_launchers);
2122 2355
2123 // Clearing works. 2356 // Sending legacy sync change without pin info should not affect pin model.
2124 pref_value.Clear(); 2357 sync_list.clear();
2125 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2358 InsertLegacyPinChange(&sync_list, extension4_->id());
2126 pref_value.DeepCopy()); 2359 SendPinChanges(sync_list, false);
2360 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2361 EXPECT_EQ(expected_launchers, actual_launchers);
2362
2363 sync_list.clear();
2364 InsertRemovePinChange(&sync_list, extension4_->id());
2365 SendPinChanges(sync_list, false);
2366 expected_launchers.erase(expected_launchers.begin());
2367 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2368 EXPECT_EQ(expected_launchers, actual_launchers);
2369
2370 sync_list.clear();
2371 InsertRemovePinChange(&sync_list, extension3_->id());
2372 InsertRemovePinChange(&sync_list, extension2_->id());
2373 SendPinChanges(sync_list, false);
2127 expected_launchers.clear(); 2374 expected_launchers.clear();
2128 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2375 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2129 EXPECT_EQ(expected_launchers, actual_launchers); 2376 EXPECT_EQ(expected_launchers, actual_launchers);
2130 } 2377 }
2131 2378
2379 TEST_F(ChromeLauncherControllerImplTest, ImportLegacyPin) {
2380 extension_service_->AddExtension(extension2_.get());
2381 extension_service_->AddExtension(extension3_.get());
2382 extension_service_->AddExtension(extension4_.get());
2383
2384 // Initially pins are imported from legacy pref based model.
2385 base::ListValue value;
2386 InsertPrefValue(&value, 0, extension4_->id());
2387 InsertPrefValue(&value, 1, extension2_->id());
2388 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
2389 value.DeepCopy());
2390
2391 InitLauncherController();
2392
2393 EXPECT_EQ("AppList, Chrome, App4, App2", GetPinnedAppStatus());
2394
2395 // At this point changing old pref based model does not affect pin model.
2396 InsertPrefValue(&value, 2, extension3_->id());
2397 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
2398 value.DeepCopy());
2399 EXPECT_EQ("AppList, Chrome, App4, App2", GetPinnedAppStatus());
2400 RecreateChromeLauncher();
2401 EXPECT_EQ("AppList, Chrome, App4, App2", GetPinnedAppStatus());
2402 }
2403
2132 TEST_F(ChromeLauncherControllerImplTest, PendingInsertionOrder) { 2404 TEST_F(ChromeLauncherControllerImplTest, PendingInsertionOrder) {
2133 extension_service_->AddExtension(extension1_.get()); 2405 extension_service_->AddExtension(extension1_.get());
2134 extension_service_->AddExtension(extension3_.get()); 2406 extension_service_->AddExtension(extension3_.get());
2135 2407
2136 InitLauncherController(); 2408 InitLauncherController();
2137 2409
2138 base::ListValue pref_value; 2410 syncer::SyncChangeList sync_list;
2139 InsertPrefValue(&pref_value, 0, extension1_->id()); 2411 InsertAddPinChange(&sync_list, 0, extension1_->id());
2140 InsertPrefValue(&pref_value, 1, extension2_->id()); 2412 InsertAddPinChange(&sync_list, 1, extension2_->id());
2141 InsertPrefValue(&pref_value, 2, extension3_->id()); 2413 InsertAddPinChange(&sync_list, 2, extension3_->id());
2142 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2414 SendPinChanges(sync_list, true);
2143 pref_value.DeepCopy());
2144 2415
2145 std::vector<std::string> expected_launchers; 2416 std::vector<std::string> expected_launchers;
2146 expected_launchers.push_back(extension1_->id()); 2417 expected_launchers.push_back(extension1_->id());
2147 expected_launchers.push_back(extension3_->id()); 2418 expected_launchers.push_back(extension3_->id());
2148 std::vector<std::string> actual_launchers; 2419 std::vector<std::string> actual_launchers;
2149 2420
2150 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2421 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2151 EXPECT_EQ(expected_launchers, actual_launchers); 2422 EXPECT_EQ(expected_launchers, actual_launchers);
2152 2423
2153 // Install |extension2| and verify it shows up between the other two. 2424 // Install |extension2| and verify it shows up between the other two.
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 } else { 3164 } else {
2894 // Clear already registered ShelfItemDelegate. 3165 // Clear already registered ShelfItemDelegate.
2895 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3166 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2896 test.RemoveAllShelfItemDelegateForTest(); 3167 test.RemoveAllShelfItemDelegateForTest();
2897 } 3168 }
2898 model_.reset(new ash::ShelfModel); 3169 model_.reset(new ash::ShelfModel);
2899 3170
2900 AddAppListLauncherItem(); 3171 AddAppListLauncherItem();
2901 launcher_controller_.reset( 3172 launcher_controller_.reset(
2902 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); 3173 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get()));
2903 helper = new TestLauncherControllerHelper; 3174 helper = new TestLauncherControllerHelper(profile());
2904 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3175 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2905 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3176 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
2906 SetLauncherControllerHelper(helper); 3177 SetLauncherControllerHelper(helper);
2907 if (!ash::Shell::HasInstance()) { 3178 if (!ash::Shell::HasInstance()) {
2908 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3179 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2909 SetShelfItemDelegateManager(item_delegate_manager_); 3180 SetShelfItemDelegateManager(item_delegate_manager_);
2910 } 3181 }
2911 launcher_controller_->Init(); 3182 launcher_controller_->Init();
2912 3183
2913 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. 3184 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2951 } else { 3222 } else {
2952 // Clear already registered ShelfItemDelegate. 3223 // Clear already registered ShelfItemDelegate.
2953 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3224 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2954 test.RemoveAllShelfItemDelegateForTest(); 3225 test.RemoveAllShelfItemDelegateForTest();
2955 } 3226 }
2956 model_.reset(new ash::ShelfModel); 3227 model_.reset(new ash::ShelfModel);
2957 3228
2958 AddAppListLauncherItem(); 3229 AddAppListLauncherItem();
2959 launcher_controller_.reset( 3230 launcher_controller_.reset(
2960 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get())); 3231 ChromeLauncherControllerImpl::CreateInstance(profile(), model_.get()));
2961 helper = new TestLauncherControllerHelper; 3232 helper = new TestLauncherControllerHelper(profile());
2962 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3233 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2963 SetLauncherControllerHelper(helper); 3234 SetLauncherControllerHelper(helper);
2964 // app_icon_loader is owned by ChromeLauncherControllerImpl. 3235 // app_icon_loader is owned by ChromeLauncherControllerImpl.
2965 app_icon_loader = new TestAppIconLoaderImpl; 3236 app_icon_loader = new TestAppIconLoaderImpl;
2966 app_icon_loader->AddSupportedApp("1"); 3237 app_icon_loader->AddSupportedApp("1");
2967 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3238 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
2968 if (!ash::Shell::HasInstance()) { 3239 if (!ash::Shell::HasInstance()) {
2969 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3240 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2970 SetShelfItemDelegateManager(item_delegate_manager_); 3241 SetShelfItemDelegateManager(item_delegate_manager_);
2971 } 3242 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 // by hash we can determine that appropriate package was set by policy. 3344 // by hash we can determine that appropriate package was set by policy.
3074 base::ListValue policy_value; 3345 base::ListValue policy_value;
3075 InsertPrefValue(&policy_value, 0, appinfo.package_name); 3346 InsertPrefValue(&policy_value, 0, appinfo.package_name);
3076 profile()->GetTestingPrefService()->SetManagedPref( 3347 profile()->GetTestingPrefService()->SetManagedPref(
3077 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 3348 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
3078 3349
3079 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 3350 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
3080 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 3351 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
3081 launcher_controller_->GetPinnable(app_id)); 3352 launcher_controller_->GetPinnable(app_id));
3082 } 3353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698