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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_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: 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.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 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 ChromeLauncherControllerTest : public BrowserWithTestWindowTest { 294 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
285 protected: 295 protected:
286 ChromeLauncherControllerTest() 296 ChromeLauncherControllerTest()
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 ~ChromeLauncherControllerTest() override {} 301 ~ChromeLauncherControllerTest() 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 extensions::ExtensionSystem* s =
339 extensions::ExtensionSystem::Get(profile());
340 s->extension_service()->Init();
341
342 app_service_ = app_list::AppListSyncableService::Get(profile());
343 app_service_->MergeDataAndStartSyncing(
344 syncer::APP_LIST, syncer::SyncDataList(),
345 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
346 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
320 347
321 std::string error; 348 std::string error;
322 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 349 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
323 manifest, 350 manifest,
324 Extension::NO_FLAGS, 351 Extension::NO_FLAGS,
325 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 352 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
326 &error); 353 &error);
327 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 354 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
328 manifest, 355 manifest,
329 Extension::NO_FLAGS, 356 Extension::NO_FLAGS,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 model_->item_count(), 412 model_->item_count(),
386 ash::TYPE_PLATFORM_APP); 413 ash::TYPE_PLATFORM_APP);
387 DCHECK(id); 414 DCHECK(id);
388 // Change the created launcher controller into a V2 app controller. 415 // Change the created launcher controller into a V2 app controller.
389 test_controller_ = new TestV2AppLauncherItemController(app_id, 416 test_controller_ = new TestV2AppLauncherItemController(app_id,
390 launcher_controller_.get()); 417 launcher_controller_.get());
391 launcher_controller_->SetItemController(id, test_controller_); 418 launcher_controller_->SetItemController(id, test_controller_);
392 } 419 }
393 420
394 // Sets the stage for a multi user test. 421 // Sets the stage for a multi user test.
395 virtual void SetUpMultiUserScenario(base::ListValue* user_a, 422 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a,
396 base::ListValue* user_b) { 423 syncer::SyncChangeList* user_b) {
397 InitLauncherController(); 424 InitLauncherController();
398 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 425 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
399 426
400 // Set an empty pinned pref to begin with. 427 // Set an empty pinned pref to begin with.
401 base::ListValue no_user; 428 syncer::SyncChangeList sync_list;
402 SetShelfChromeIconIndex(0); 429 InsertRemoveAllPins(&sync_list);
403 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 430 InsertPinValue(&sync_list, 0, extension_misc::kChromeAppId);
404 no_user.DeepCopy()); 431 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
405 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 432 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
406 433
407 // Assume all applications have been added already. 434 // Assume all applications have been added already.
408 extension_service_->AddExtension(extension1_.get()); 435 extension_service_->AddExtension(extension1_.get());
409 extension_service_->AddExtension(extension2_.get()); 436 extension_service_->AddExtension(extension2_.get());
410 extension_service_->AddExtension(extension3_.get()); 437 extension_service_->AddExtension(extension3_.get());
411 extension_service_->AddExtension(extension4_.get()); 438 extension_service_->AddExtension(extension4_.get());
412 extension_service_->AddExtension(extension5_.get()); 439 extension_service_->AddExtension(extension5_.get());
413 extension_service_->AddExtension(extension6_.get()); 440 extension_service_->AddExtension(extension6_.get());
414 extension_service_->AddExtension(extension7_.get()); 441 extension_service_->AddExtension(extension7_.get());
415 extension_service_->AddExtension(extension8_.get()); 442 extension_service_->AddExtension(extension8_.get());
416 // There should be nothing in the list by now. 443 // There should be nothing in the list by now.
417 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 444 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
418 445
419 // Set user a preferences. 446 // Set user a preferences.
420 InsertPrefValue(user_a, 0, extension1_->id()); 447 InsertPinValue(user_a, 0, extension1_->id());
421 InsertPrefValue(user_a, 1, extension2_->id()); 448 InsertPinValue(user_a, 1, extension2_->id());
422 InsertPrefValue(user_a, 2, extension3_->id()); 449 InsertPinValue(user_a, 2, extension3_->id());
423 InsertPrefValue(user_a, 3, extension4_->id()); 450 InsertPinValue(user_a, 3, extension4_->id());
424 InsertPrefValue(user_a, 4, extension5_->id()); 451 InsertPinValue(user_a, 4, extension5_->id());
425 InsertPrefValue(user_a, 5, extension6_->id()); 452 InsertPinValue(user_a, 5, extension6_->id());
453 InsertPinValue(user_a, 6, extension_misc::kChromeAppId);
426 454
427 // Set user b preferences. 455 // Set user b preferences.
428 InsertPrefValue(user_b, 0, extension7_->id()); 456 InsertPinValue(user_b, 0, extension7_->id());
429 InsertPrefValue(user_b, 1, extension8_->id()); 457 InsertPinValue(user_b, 1, extension8_->id());
458 InsertPinValue(user_b, 2, extension_misc::kChromeAppId);
430 } 459 }
431 460
432 void TearDown() override { 461 void TearDown() override {
433 arc_test_.TearDown(); 462 arc_test_.TearDown();
434 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr); 463 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr);
435 model_->RemoveObserver(model_observer_.get()); 464 model_->RemoveObserver(model_observer_.get());
436 model_observer_.reset(); 465 model_observer_.reset();
437 launcher_controller_.reset(); 466 launcher_controller_.reset();
438 467
439 // item_delegate_manager_ must be deleted after launch_controller_, 468 // item_delegate_manager_ must be deleted after launch_controller_,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 532 }
504 533
505 void InsertPrefValue(base::ListValue* pref_value, 534 void InsertPrefValue(base::ListValue* pref_value,
506 int index, 535 int index,
507 const std::string& extension_id) { 536 const std::string& extension_id) {
508 base::DictionaryValue* entry = new base::DictionaryValue(); 537 base::DictionaryValue* entry = new base::DictionaryValue();
509 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 538 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id);
510 pref_value->Insert(index, entry); 539 pref_value->Insert(index, entry);
511 } 540 }
512 541
542 void InsertRemoveAllPins(syncer::SyncChangeList* list) {
543 for (const auto& sync_peer : app_service_->sync_items()) {
544 sync_pb::EntitySpecifics specifics;
545 sync_pb::AppListSpecifics* app_list_specifics =
546 specifics.mutable_app_list();
547 app_list_specifics->set_item_id(sync_peer.first);
548 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
549 syncer::SyncData sync_data =
550 syncer::SyncData::CreateLocalData(sync_peer.first, "Test", specifics);
551 list->push_back(syncer::SyncChange(
552 FROM_HERE, syncer::SyncChange::ACTION_DELETE, sync_data));
553 }
554 }
555
556 syncer::StringOrdinal GetPinPosition(int position) {
557 syncer::StringOrdinal ordinal_position =
558 syncer::StringOrdinal::CreateInitialOrdinal();
559 for (int i = 0; i < position; ++i)
560 ordinal_position = ordinal_position.CreateAfter();
561 return ordinal_position;
562 }
563
564 void GeneratePinValue(syncer::SyncChangeList* list,
565 int position,
566 const std::string& app_id,
567 syncer::SyncChange::SyncChangeType type) {
568 sync_pb::EntitySpecifics specifics;
569 sync_pb::AppListSpecifics* app_list_specifics =
570 specifics.mutable_app_list();
571 app_list_specifics->set_item_id(app_id);
572 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
573 if (position >= 0) {
574 app_list_specifics->set_item_pin_ordinal(
575 GetPinPosition(position).ToInternalValue());
576 }
577 syncer::SyncData sync_data =
578 syncer::SyncData::CreateLocalData(app_id, "Test", specifics);
579 list->push_back(syncer::SyncChange(FROM_HERE, type, sync_data));
580 }
581
582 void InsertPinValue(syncer::SyncChangeList* list,
583 int position,
584 const std::string& app_id) {
585 GeneratePinValue(list, position, app_id, syncer::SyncChange::ACTION_ADD);
586 }
587
588 void UpdatePinValue(syncer::SyncChangeList* list,
589 int position,
590 const std::string& app_id) {
591 GeneratePinValue(list, position, app_id, syncer::SyncChange::ACTION_UPDATE);
592 }
593
594 void RemovePinValue(syncer::SyncChangeList* list, const std::string& app_id) {
595 GeneratePinValue(list, -1, app_id, syncer::SyncChange::ACTION_UPDATE);
596 }
597
598 void ResetAllPins() {
599 syncer::SyncChangeList sync_list;
600 InsertRemoveAllPins(&sync_list);
601 InsertPinValue(&sync_list, 0, kDummyAppId);
602 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
603 }
604
605 // Set the index at which the chrome icon should be.
606 void SetShelfChromeIconIndex(int index) {
607 DCHECK(
608 app_service_->GetPinPosition(extension_misc::kChromeAppId).IsValid());
609 syncer::StringOrdinal chrome_position;
610 chrome_position =
611 index == 0
612 ? GetPinPosition(0).CreateBefore()
613 : GetPinPosition(index - 1).CreateBetween(GetPinPosition(index));
614
615 syncer::SyncChangeList sync_list;
616 sync_pb::EntitySpecifics specifics;
617 sync_pb::AppListSpecifics* app_list_specifics =
618 specifics.mutable_app_list();
619 app_list_specifics->set_item_id(extension_misc::kChromeAppId);
620 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
621 app_list_specifics->set_item_pin_ordinal(chrome_position.ToInternalValue());
622 syncer::SyncData sync_data = syncer::SyncData::CreateLocalData(
623 extension_misc::kChromeAppId, "Test", specifics);
624 sync_list.push_back(syncer::SyncChange(
625 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data));
626 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
627 }
628
513 // Gets the currently configured app launchers from the controller. 629 // Gets the currently configured app launchers from the controller.
514 void GetAppLaunchers(ChromeLauncherController* controller, 630 void GetAppLaunchers(ChromeLauncherController* controller,
515 std::vector<std::string>* launchers) { 631 std::vector<std::string>* launchers) {
516 launchers->clear(); 632 launchers->clear();
517 for (ash::ShelfItems::const_iterator iter(model_->items().begin()); 633 for (ash::ShelfItems::const_iterator iter(model_->items().begin());
518 iter != model_->items().end(); ++iter) { 634 iter != model_->items().end(); ++iter) {
519 ChromeLauncherController::IDToItemControllerMap::const_iterator 635 ChromeLauncherController::IDToItemControllerMap::const_iterator
520 entry(controller->id_to_item_controller_map_.find(iter->id)); 636 entry(controller->id_to_item_controller_map_.find(iter->id));
521 if (iter->type == ash::TYPE_APP_SHORTCUT && 637 if (iter->type == ash::TYPE_APP_SHORTCUT &&
522 entry != controller->id_to_item_controller_map_.end()) { 638 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())); 714 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id()));
599 } else if (app == extension6_->id()) { 715 } else if (app == extension6_->id()) {
600 result += "App6"; 716 result += "App6";
601 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); 717 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id()));
602 } else if (app == extension7_->id()) { 718 } else if (app == extension7_->id()) {
603 result += "App7"; 719 result += "App7";
604 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); 720 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id()));
605 } else if (app == extension8_->id()) { 721 } else if (app == extension8_->id()) {
606 result += "App8"; 722 result += "App8";
607 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); 723 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 { 724 } else {
611 result += "unknown"; 725 bool arc_app_found = false;
726 for (const auto& arc_app : arc_test_.fake_apps()) {
727 if (app == ArcAppTest::GetAppId(arc_app)) {
728 result += arc_app.name;
729 arc_app_found = true;
730 break;
731 }
732 }
733 if (!arc_app_found)
734 result += "unknown";
612 } 735 }
613 break; 736 break;
614 } 737 }
615 case ash::TYPE_BROWSER_SHORTCUT: 738 case ash::TYPE_BROWSER_SHORTCUT:
616 result += "Chrome"; 739 result += "Chrome";
617 break; 740 break;
618 case ash::TYPE_APP_LIST: 741 case ash::TYPE_APP_LIST:
619 result += "AppList"; 742 result += "AppList";
620 break; 743 break;
621 default: 744 default:
622 result += "Unknown"; 745 result += "Unknown";
623 break; 746 break;
624 } 747 }
625 } 748 }
626 return result; 749 return result;
627 } 750 }
628 751
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 752 // Remember the order of unpinned but running applications for the current
636 // user. 753 // user.
637 void RememberUnpinnedRunningApplicationOrder() { 754 void RememberUnpinnedRunningApplicationOrder() {
638 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); 755 launcher_controller_->RememberUnpinnedRunningApplicationOrder();
639 } 756 }
640 757
641 // Restore the order of running but unpinned applications for a given user. 758 // Restore the order of running but unpinned applications for a given user.
642 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) { 759 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) {
643 launcher_controller_->RestoreUnpinnedRunningApplicationOrder( 760 launcher_controller_->RestoreUnpinnedRunningApplicationOrder(
644 account_id.GetUserEmail()); 761 account_id.GetUserEmail());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 scoped_refptr<Extension> extension4_; 800 scoped_refptr<Extension> extension4_;
684 scoped_refptr<Extension> extension5_; 801 scoped_refptr<Extension> extension5_;
685 scoped_refptr<Extension> extension6_; 802 scoped_refptr<Extension> extension6_;
686 scoped_refptr<Extension> extension7_; 803 scoped_refptr<Extension> extension7_;
687 scoped_refptr<Extension> extension8_; 804 scoped_refptr<Extension> extension8_;
688 805
689 ArcAppTest arc_test_; 806 ArcAppTest arc_test_;
690 std::unique_ptr<ChromeLauncherController> launcher_controller_; 807 std::unique_ptr<ChromeLauncherController> launcher_controller_;
691 std::unique_ptr<TestShelfModelObserver> model_observer_; 808 std::unique_ptr<TestShelfModelObserver> model_observer_;
692 std::unique_ptr<ash::ShelfModel> model_; 809 std::unique_ptr<ash::ShelfModel> model_;
810 std::unique_ptr<TestingProfileManager> profile_manager_;
693 811
694 // |item_delegate_manager_| owns |test_controller_|. 812 // |item_delegate_manager_| owns |test_controller_|.
695 LauncherItemController* test_controller_; 813 LauncherItemController* test_controller_;
696 814
697 ExtensionService* extension_service_; 815 ExtensionService* extension_service_;
698 816
817 app_list::AppListSyncableService* app_service_;
818
699 ash::ShelfItemDelegateManager* item_delegate_manager_; 819 ash::ShelfItemDelegateManager* item_delegate_manager_;
700 820
701 private: 821 private:
702 TestBrowserWindow* CreateTestBrowserWindowAura() { 822 TestBrowserWindow* CreateTestBrowserWindowAura() {
703 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); 823 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
704 window->set_id(0); 824 window->set_id(0);
705 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 825 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
706 window->Init(ui::LAYER_TEXTURED); 826 window->Init(ui::LAYER_TEXTURED);
707 aura::client::ParentWindowWithContext(window.get(), GetContext(), 827 aura::client::ParentWindowWithContext(window.get(), GetContext(),
708 gfx::Rect(200, 200)); 828 gfx::Rect(200, 200));
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 1091
972 private: 1092 private:
973 typedef std::map<Profile*, std::string> ProfileToNameMap; 1093 typedef std::map<Profile*, std::string> ProfileToNameMap;
974 TestingProfileManager* profile_manager() { return profile_manager_.get(); } 1094 TestingProfileManager* profile_manager() { return profile_manager_.get(); }
975 1095
976 chromeos::FakeChromeUserManager* GetFakeUserManager() { 1096 chromeos::FakeChromeUserManager* GetFakeUserManager() {
977 return static_cast<chromeos::FakeChromeUserManager*>( 1097 return static_cast<chromeos::FakeChromeUserManager*>(
978 user_manager::UserManager::Get()); 1098 user_manager::UserManager::Get());
979 } 1099 }
980 1100
981 std::unique_ptr<TestingProfileManager> profile_manager_;
982 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 1101 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
983 1102
984 ash::test::TestShellDelegate* shell_delegate_; 1103 ash::test::TestShellDelegate* shell_delegate_;
985 1104
986 ProfileToNameMap created_profiles_; 1105 ProfileToNameMap created_profiles_;
987 1106
988 DISALLOW_COPY_AND_ASSIGN( 1107 DISALLOW_COPY_AND_ASSIGN(
989 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest); 1108 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest);
990 }; 1109 };
991 1110
992 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 1111 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
993 InitLauncherController(); 1112 InitLauncherController();
994 // Model should only contain the browser shortcut and app list items. 1113 // Model should only contain the browser shortcut and app list items.
995 EXPECT_EQ(2, model_->item_count()); 1114 EXPECT_EQ(2, model_->item_count());
996 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1115 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
997 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1116 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
998 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1117 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
999 1118
1000 // Installing |extension3_| should add it to the launcher - behind the 1119 // Installing |extension3_| should add it to the launcher - behind the
1001 // chrome icon. 1120 // chrome icon.
1002 extension_service_->AddExtension(extension3_.get()); 1121 extension_service_->AddExtension(extension3_.get());
1003 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1122 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1004 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1123 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1005 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1124 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1006 } 1125 }
1007 1126
1127 TEST_F(ChromeLauncherControllerTest, ArcAppPinCrossPlatformWorkflow) {
1128 // Work on Arc-disabled platform first.
1129 arc_test_.SetUp(profile());
1130
1131 const std::string arc_app_id1 =
1132 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]);
1133 const std::string arc_app_id2 =
1134 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]);
1135 const std::string arc_app_id3 =
1136 ArcAppTest::GetAppId(arc_test_.fake_apps()[2]);
1137
1138 InitLauncherController();
1139
1140 extension_service_->AddExtension(extension1_.get());
1141 extension_service_->AddExtension(extension2_.get());
1142 extension_service_->AddExtension(extension3_.get());
1143
1144 // extension 1, 3 are pinned by user
1145 syncer::SyncChangeList sync_list;
1146 InsertRemoveAllPins(&sync_list);
1147 InsertPinValue(&sync_list, 0, extension1_->id());
1148 InsertPinValue(&sync_list, 1, arc_app_id1);
1149 InsertPinValue(&sync_list, 2, extension2_->id());
1150 InsertPinValue(&sync_list, 3, arc_app_id2);
1151 InsertPinValue(&sync_list, 4, extension3_->id());
1152 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1153 SetShelfChromeIconIndex(1);
1154
1155 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1156 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1157 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1158 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1159 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1161 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1162
1163 // Persist pin state, we don't have active pin for Arc apps yet, but pin
1164 // model should have it.
1165 syncer::SyncDataList copy_sync_list =
1166 app_service_->GetAllSyncData(syncer::APP_LIST);
1167
1168 launcher_controller_.reset();
1169 ResetAllPins();
1170
1171 sync_list.clear();
1172 InsertRemoveAllPins(&sync_list);
1173 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1174 app_service_->StopSyncing(syncer::APP_LIST);
1175 EXPECT_EQ(0U, app_service_->sync_items().size());
1176
1177 // Move to Arc-enabled platform, restart syncing with stored data.
1178 app_service_->MergeDataAndStartSyncing(
1179 syncer::APP_LIST, copy_sync_list,
1180 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1181 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1182 EXPECT_EQ(copy_sync_list.size(), app_service_->sync_items().size());
1183
1184 model_.reset(new ash::ShelfModel);
1185 AddAppListLauncherItem();
1186 launcher_controller_.reset(
1187 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1188 launcher_controller_->Init();
1189
1190 // Pins must be automatically updated.
1191 SendListOfArcApps();
1192 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1193 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1194 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1195 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1196 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1197 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1198
1199 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3",
1200 GetPinnedAppStatus());
1201
1202 // Now move pins on Arc-enabled platform.
1203 model_->Move(1, 4);
1204 model_->Move(3, 1);
1205 model_->Move(3, 5);
1206 model_->Move(4, 2);
1207 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3",
1208 GetPinnedAppStatus());
1209
1210 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST);
1211
1212 launcher_controller_.reset();
1213 ResetAllPins();
1214
1215 sync_list.clear();
1216 InsertRemoveAllPins(&sync_list);
1217 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1218 app_service_->StopSyncing(syncer::APP_LIST);
1219 EXPECT_EQ(0U, app_service_->sync_items().size());
1220
1221 // Move back to Arc-disabled platform.
1222 EnableArc(false);
1223
1224 app_service_->MergeDataAndStartSyncing(
1225 syncer::APP_LIST, copy_sync_list,
1226 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
1227 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1228 EXPECT_EQ(copy_sync_list.size(), app_service_->sync_items().size());
1229
1230 model_.reset(new ash::ShelfModel);
1231 AddAppListLauncherItem();
1232 launcher_controller_.reset(
1233 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1234 launcher_controller_->Init();
1235
1236 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1237 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1238 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1239 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1240 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1241 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1242 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus());
1243
1244 // Now move/remove pins on Arc-disabled platform.
1245 model_->Move(4, 2);
1246 launcher_controller_->UnpinAppWithID(extension2_->id());
1247 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus());
1248 EnableArc(true);
1249
1250 SendListOfArcApps();
1251
1252 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1253 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1254 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1255 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1256 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1257 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1258 EXPECT_EQ("AppList, Fake App 1, App3, Chrome, App1, Fake App 0",
1259 GetPinnedAppStatus());
1260 }
1261
1008 /* 1262 /*
1009 * Test ChromeLauncherController correctly merges policy pinned apps 1263 * Test ChromeLauncherController correctly merges policy pinned apps
1010 * and user pinned apps 1264 * and user pinned apps
1011 */ 1265 */
1012 TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) { 1266 TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) {
1013 InitLauncherController(); 1267 InitLauncherController();
1014 1268
1015 base::ListValue user_pref_value;
1016 extension_service_->AddExtension(extension1_.get()); 1269 extension_service_->AddExtension(extension1_.get());
1017 extension_service_->AddExtension(extension3_.get()); 1270 extension_service_->AddExtension(extension3_.get());
1018 extension_service_->AddExtension(extension4_.get()); 1271 extension_service_->AddExtension(extension4_.get());
1019 extension_service_->AddExtension(extension5_.get()); 1272 extension_service_->AddExtension(extension5_.get());
1020 // extension 1, 3 are pinned by user 1273 // extension 1, 3 are pinned by user
1021 InsertPrefValue(&user_pref_value, 0, extension1_->id()); 1274 syncer::SyncChangeList sync_list;
1022 InsertPrefValue(&user_pref_value, 1, extension3_->id()); 1275 InsertRemoveAllPins(&sync_list);
1023 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1276 InsertPinValue(&sync_list, 0, extension1_->id());
1024 user_pref_value.DeepCopy()); 1277 InsertPinValue(&sync_list, 1, extension_misc::kChromeAppId);
1278 InsertPinValue(&sync_list, 2, extension3_->id());
1279 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1025 1280
1026 base::ListValue policy_value; 1281 base::ListValue policy_value;
1027 // extension 2 4 are pinned by policy 1282 // extension 2 4 are pinned by policy
1028 InsertPrefValue(&policy_value, 0, extension2_->id()); 1283 InsertPrefValue(&policy_value, 0, extension2_->id());
1029 InsertPrefValue(&policy_value, 1, extension4_->id()); 1284 InsertPrefValue(&policy_value, 1, extension4_->id());
1030 profile()->GetTestingPrefService()->SetManagedPref( 1285 profile()->GetTestingPrefService()->SetManagedPref(
1031 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 1286 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
1032 1287
1033 SetShelfChromeIconIndex(1);
1034
1035 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1288 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1036 // 2 is not pinned as it's not installed 1289 // 2 is not pinned as it's not installed
1037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1290 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1038 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1291 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1039 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 1292 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
1040 // install extension 2 and check 1293 // install extension 2 and check
1041 extension_service_->AddExtension(extension2_.get()); 1294 extension_service_->AddExtension(extension2_.get());
1042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1295 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1043 1296
1044 // Check user can manually pin or unpin these apps 1297 // Check user can manually pin or unpin these apps
1045 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1298 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1046 launcher_controller_->GetPinnable(extension1_->id())); 1299 launcher_controller_->GetPinnable(extension1_->id()));
1047 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1300 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1048 launcher_controller_->GetPinnable(extension2_->id())); 1301 launcher_controller_->GetPinnable(extension2_->id()));
1049 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1302 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1050 launcher_controller_->GetPinnable(extension3_->id())); 1303 launcher_controller_->GetPinnable(extension3_->id()));
1051 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1304 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1052 launcher_controller_->GetPinnable(extension4_->id())); 1305 launcher_controller_->GetPinnable(extension4_->id()));
1053 1306
1054 // Check the order of shelf pinned apps 1307 // Check the order of shelf pinned apps
1055 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus()); 1308 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus());
1056 } 1309 }
1057 1310
1058 // Check that the restauration of launcher items is happening in the same order 1311 // 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 1312 // as the user has pinned them (on another system) when they are synced reverse
1060 // order. 1313 // order.
1061 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { 1314 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
1062 InitLauncherController(); 1315 InitLauncherController();
1063 1316
1064 base::ListValue policy_value; 1317 syncer::SyncChangeList sync_list;
1065 InsertPrefValue(&policy_value, 0, extension1_->id()); 1318 InsertRemoveAllPins(&sync_list);
1066 InsertPrefValue(&policy_value, 1, extension2_->id()); 1319 InsertPinValue(&sync_list, 0, extension1_->id());
1067 InsertPrefValue(&policy_value, 2, extension3_->id()); 1320 InsertPinValue(&sync_list, 1, extension2_->id());
1068 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1321 InsertPinValue(&sync_list, 2, extension3_->id());
1069 policy_value.DeepCopy()); 1322 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1070 SetShelfChromeIconIndex(0); 1323
1071 // Model should only contain the browser shortcut and app list items. 1324 // Model should only contain the browser shortcut and app list items.
1072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1325 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1073 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1326 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1074 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1327 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1075 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1328 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1076 1329
1077 // Installing |extension3_| should add it to the shelf - behind the 1330 // Installing |extension3_| should add it to the shelf - behind the
1078 // chrome icon. 1331 // chrome icon.
1079 ash::ShelfItem item; 1332 ash::ShelfItem item;
1080 extension_service_->AddExtension(extension3_.get()); 1333 extension_service_->AddExtension(extension3_.get());
(...skipping 12 matching lines...) Expand all
1093 extension_service_->AddExtension(extension1_.get()); 1346 extension_service_->AddExtension(extension1_.get());
1094 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1347 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1095 } 1348 }
1096 1349
1097 // Check that the restauration of launcher items is happening in the same order 1350 // 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 1351 // as the user has pinned them (on another system) when they are synced random
1099 // order. 1352 // order.
1100 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) { 1353 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) {
1101 InitLauncherController(); 1354 InitLauncherController();
1102 1355
1103 base::ListValue policy_value; 1356 syncer::SyncChangeList sync_list;
1104 InsertPrefValue(&policy_value, 0, extension1_->id()); 1357 InsertRemoveAllPins(&sync_list);
1105 InsertPrefValue(&policy_value, 1, extension2_->id()); 1358 InsertPinValue(&sync_list, 0, extension1_->id());
1106 InsertPrefValue(&policy_value, 2, extension3_->id()); 1359 InsertPinValue(&sync_list, 1, extension2_->id());
1360 InsertPinValue(&sync_list, 2, extension3_->id());
1361 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1107 1362
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. 1363 // Model should only contain the browser shortcut and app list items.
1112 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1364 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1113 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1365 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1114 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1366 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1115 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1367 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1116 1368
1117 // Installing |extension2_| should add it to the launcher - behind the 1369 // Installing |extension2_| should add it to the launcher - behind the
1118 // chrome icon. 1370 // chrome icon.
1119 extension_service_->AddExtension(extension2_.get()); 1371 extension_service_->AddExtension(extension2_.get());
1120 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1372 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 11 matching lines...) Expand all
1132 extension_service_->AddExtension(extension3_.get()); 1384 extension_service_->AddExtension(extension3_.get());
1133 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1385 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1134 } 1386 }
1135 1387
1136 // Check that the restauration of launcher items is happening in the same order 1388 // 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 1389 // as the user has pinned / moved them (on another system) when they are synced
1138 // random order - including the chrome icon. 1390 // random order - including the chrome icon.
1139 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) { 1391 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) {
1140 InitLauncherController(); 1392 InitLauncherController();
1141 1393
1142 base::ListValue policy_value; 1394 syncer::SyncChangeList sync_list;
1143 InsertPrefValue(&policy_value, 0, extension1_->id()); 1395 InsertRemoveAllPins(&sync_list);
1144 InsertPrefValue(&policy_value, 1, extension2_->id()); 1396 InsertPinValue(&sync_list, 0, extension1_->id());
1145 InsertPrefValue(&policy_value, 2, extension3_->id()); 1397 InsertPinValue(&sync_list, 1, extension_misc::kChromeAppId);
1146 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1398 InsertPinValue(&sync_list, 2, extension2_->id());
1147 policy_value.DeepCopy()); 1399 InsertPinValue(&sync_list, 3, extension3_->id());
1148 SetShelfChromeIconIndex(1); 1400 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
1401
1149 // Model should only contain the browser shortcut and app list items. 1402 // Model should only contain the browser shortcut and app list items.
1150 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1403 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1151 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1404 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1405 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1153 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1406 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1154 1407
1155 // Installing |extension2_| should add it to the shelf - behind the 1408 // Installing |extension2_| should add it to the shelf - behind the
1156 // chrome icon. 1409 // chrome icon.
1157 ash::ShelfItem item; 1410 ash::ShelfItem item;
1158 extension_service_->AddExtension(extension2_.get()); 1411 extension_service_->AddExtension(extension2_.get());
1159 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1412 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1413 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1161 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1414 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1162 1415
1163 // Installing |extension1_| should add it to the launcher - behind the 1416 // Installing |extension1_| should add it to the launcher - behind the
1164 // chrome icon, but in first location. 1417 // chrome icon, but in first location.
1165 extension_service_->AddExtension(extension1_.get()); 1418 extension_service_->AddExtension(extension1_.get());
1166 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1419 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1167 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); 1420 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus());
1168 1421
1169 // Installing |extension3_| should add it to the launcher - behind the 1422 // Installing |extension3_| should add it to the launcher - behind the
1170 // chrome icon, but in first location. 1423 // chrome icon, but in first location.
1171 extension_service_->AddExtension(extension3_.get()); 1424 extension_service_->AddExtension(extension3_.get());
1172 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 1425 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1173 } 1426 }
1174 1427
1175 // Check that syncing to a different state does the correct thing. 1428 // Check that syncing to a different state does the correct thing.
1176 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) { 1429 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) {
1177 InitLauncherController(); 1430 InitLauncherController();
1178 base::ListValue policy_value; 1431
1179 InsertPrefValue(&policy_value, 0, extension1_->id()); 1432 syncer::SyncChangeList sync_list0;
1180 InsertPrefValue(&policy_value, 1, extension2_->id()); 1433 InsertRemoveAllPins(&sync_list0);
1181 InsertPrefValue(&policy_value, 2, extension3_->id()); 1434 InsertPinValue(&sync_list0, 0, extension1_->id());
1182 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1435 InsertPinValue(&sync_list0, 1, extension2_->id());
1183 policy_value.DeepCopy()); 1436 InsertPinValue(&sync_list0, 2, extension3_->id());
1437 app_service_->ProcessSyncChanges(FROM_HERE, sync_list0);
1438
1184 // The shelf layout has always one static item at the beginning (App List). 1439 // The shelf layout has always one static item at the beginning (App List).
1185 SetShelfChromeIconIndex(0);
1186 extension_service_->AddExtension(extension2_.get()); 1440 extension_service_->AddExtension(extension2_.get());
1187 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1441 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1188 extension_service_->AddExtension(extension1_.get()); 1442 extension_service_->AddExtension(extension1_.get());
1189 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 1443 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
1190 extension_service_->AddExtension(extension3_.get()); 1444 extension_service_->AddExtension(extension3_.get());
1191 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1445 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1192 1446
1193 // Change the order with increasing chrome position and decreasing position. 1447 // Change the order with increasing chrome position and decreasing position.
1194 base::ListValue policy_value1; 1448 syncer::SyncChangeList sync_list1;
1195 InsertPrefValue(&policy_value1, 0, extension3_->id()); 1449 InsertRemoveAllPins(&sync_list1);
1196 InsertPrefValue(&policy_value1, 1, extension1_->id()); 1450 InsertPinValue(&sync_list1, 0, extension3_->id());
1197 InsertPrefValue(&policy_value1, 2, extension2_->id()); 1451 InsertPinValue(&sync_list1, 1, extension1_->id());
1198 SetShelfChromeIconIndex(3); 1452 InsertPinValue(&sync_list1, 2, extension2_->id());
1199 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1453 InsertPinValue(&sync_list1, 3, extension_misc::kChromeAppId);
1200 policy_value1.DeepCopy()); 1454 app_service_->ProcessSyncChanges(FROM_HERE, sync_list1);
1201 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); 1455 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus());
1202 base::ListValue policy_value2; 1456
1203 InsertPrefValue(&policy_value2, 0, extension2_->id()); 1457 syncer::SyncChangeList sync_list2;
1204 InsertPrefValue(&policy_value2, 1, extension3_->id()); 1458 InsertRemoveAllPins(&sync_list2);
1205 InsertPrefValue(&policy_value2, 2, extension1_->id()); 1459 InsertPinValue(&sync_list2, 0, extension2_->id());
1206 SetShelfChromeIconIndex(2); 1460 InsertPinValue(&sync_list2, 1, extension3_->id());
1207 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1461 InsertPinValue(&sync_list2, 2, extension_misc::kChromeAppId);
1208 policy_value2.DeepCopy()); 1462 InsertPinValue(&sync_list2, 3, extension1_->id());
1463 app_service_->ProcessSyncChanges(FROM_HERE, sync_list2);
1209 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); 1464 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus());
1210 1465
1211 // Check that the chrome icon can also be at the first possible location. 1466 // Check that the chrome icon can also be at the first possible location.
1212 SetShelfChromeIconIndex(0); 1467 syncer::SyncChangeList sync_list3;
1213 base::ListValue policy_value3; 1468 InsertRemoveAllPins(&sync_list3);
1214 InsertPrefValue(&policy_value3, 0, extension3_->id()); 1469 InsertPinValue(&sync_list3, 0, extension3_->id());
1215 InsertPrefValue(&policy_value3, 1, extension2_->id()); 1470 InsertPinValue(&sync_list3, 1, extension2_->id());
1216 InsertPrefValue(&policy_value3, 2, extension1_->id()); 1471 InsertPinValue(&sync_list3, 2, extension1_->id());
1217 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1472 app_service_->ProcessSyncChanges(FROM_HERE, sync_list3);
1218 policy_value3.DeepCopy());
1219 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 1473 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1220 1474
1221 // Check that unloading of extensions works as expected. 1475 // Check that unloading of extensions works as expected.
1222 extension_service_->UnloadExtension(extension1_->id(), 1476 extension_service_->UnloadExtension(extension1_->id(),
1223 UnloadedExtensionInfo::REASON_UNINSTALL); 1477 UnloadedExtensionInfo::REASON_UNINSTALL);
1224 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); 1478 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus());
1225 1479
1226 extension_service_->UnloadExtension(extension2_->id(), 1480 extension_service_->UnloadExtension(extension2_->id(),
1227 UnloadedExtensionInfo::REASON_UNINSTALL); 1481 UnloadedExtensionInfo::REASON_UNINSTALL);
1228 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1482 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1681 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1428 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1682 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1429 launcher_controller_->UnlockV1AppWithID(extension3_->id()); 1683 launcher_controller_->UnlockV1AppWithID(extension3_->id());
1430 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1684 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1431 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1685 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1432 } 1686 }
1433 1687
1434 TEST_F(ChromeLauncherControllerTest, ArcDeferredLaunch) { 1688 TEST_F(ChromeLauncherControllerTest, ArcDeferredLaunch) {
1435 arc_test_.SetUp(profile()); 1689 arc_test_.SetUp(profile());
1436 1690
1691 model_.reset(new ash::ShelfModel);
1692 AddAppListLauncherItem();
1437 launcher_controller_.reset( 1693 launcher_controller_.reset(
1438 ChromeLauncherController::CreateInstance(profile(), model_.get())); 1694 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1695 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
1439 launcher_controller_->Init(); 1696 launcher_controller_->Init();
1440 1697
1441 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0]; 1698 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0];
1442 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1]; 1699 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1];
1443 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2]; 1700 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2];
1444 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1); 1701 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1);
1445 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2); 1702 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2);
1446 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3); 1703 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3);
1447 1704
1448 SendListOfArcApps(); 1705 SendListOfArcApps();
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 launcher_controller_->UnpinAppWithID(extension1_->id()); 2056 launcher_controller_->UnpinAppWithID(extension1_->id());
1800 2057
1801 EXPECT_EQ(2, model_->item_count()); 2058 EXPECT_EQ(2, model_->item_count());
1802 } 2059 }
1803 2060
1804 // Check that a locked (windowed V1 application) will be properly converted 2061 // Check that a locked (windowed V1 application) will be properly converted
1805 // between locked and pinned when the order gets changed through a profile / 2062 // between locked and pinned when the order gets changed through a profile /
1806 // policy change. 2063 // policy change.
1807 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) { 2064 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) {
1808 InitLauncherController(); 2065 InitLauncherController();
1809 base::ListValue policy_value0; 2066
1810 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2067 syncer::SyncChangeList sync_list;
1811 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2068 InsertRemoveAllPins(&sync_list);
1812 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2069 InsertPinValue(&sync_list, 0, extension1_->id());
1813 policy_value0.DeepCopy()); 2070 InsertPinValue(&sync_list, 1, extension3_->id());
2071 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2072
1814 // The shelf layout has always one static item at the beginning (App List). 2073 // The shelf layout has always one static item at the beginning (App List).
1815 SetShelfChromeIconIndex(0);
1816 extension_service_->AddExtension(extension1_.get()); 2074 extension_service_->AddExtension(extension1_.get());
1817 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2075 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1818 extension_service_->AddExtension(extension2_.get()); 2076 extension_service_->AddExtension(extension2_.get());
1819 // No new app icon will be generated. 2077 // No new app icon will be generated.
1820 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2078 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
2079
1821 // Add the app as locked app which will add it (un-pinned). 2080 // Add the app as locked app which will add it (un-pinned).
1822 launcher_controller_->LockV1AppWithID(extension2_->id()); 2081 launcher_controller_->LockV1AppWithID(extension2_->id());
1823 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); 2082 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus());
1824 extension_service_->AddExtension(extension3_.get()); 2083 extension_service_->AddExtension(extension3_.get());
1825 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); 2084 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus());
1826 2085
1827 // Now request to pin all items which should convert the locked item into a 2086 // Now request to pin all items which should convert the locked item into a
1828 // pinned item. 2087 // pinned item.
1829 base::ListValue policy_value1; 2088 syncer::SyncChangeList sync_list1;
1830 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2089 InsertRemoveAllPins(&sync_list1);
1831 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2090 InsertPinValue(&sync_list1, 0, extension3_->id());
1832 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2091 InsertPinValue(&sync_list1, 1, extension2_->id());
1833 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2092 InsertPinValue(&sync_list1, 2, extension1_->id());
1834 policy_value1.DeepCopy()); 2093 app_service_->ProcessSyncChanges(FROM_HERE, sync_list1);
1835 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2094 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1836 2095
1837 // Going back to a status where there is no requirement for app 2 to be pinned 2096 // Going back to a status where there is no requirement for app 2 to be pinned
1838 // should convert it back to locked but not pinned and state. The position 2097 // should convert it back to locked but not pinned and state. The position
1839 // is determined by the |ShelfModel|'s weight system and since running 2098 // is determined by the |ShelfModel|'s weight system and since running
1840 // applications are not allowed to be mixed with shortcuts, it should show up 2099 // applications are not allowed to be mixed with shortcuts, it should show up
1841 // at the end of the list. 2100 // at the end of the list.
1842 base::ListValue policy_value2; 2101 syncer::SyncChangeList sync_list2;
1843 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2102 InsertRemoveAllPins(&sync_list2);
1844 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2103 InsertPinValue(&sync_list2, 0, extension3_->id());
1845 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2104 InsertPinValue(&sync_list2, 1, extension1_->id());
1846 policy_value2.DeepCopy()); 2105 app_service_->ProcessSyncChanges(FROM_HERE, sync_list2);
1847 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); 2106 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus());
1848 2107
1849 // Removing an item should simply close it and everything should shift. 2108 // Removing an item should simply close it and everything should shift.
1850 base::ListValue policy_value3; 2109 syncer::SyncChangeList sync_list3;
1851 InsertPrefValue(&policy_value3, 0, extension3_->id()); 2110 InsertRemoveAllPins(&sync_list3);
1852 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2111 app_service_->ProcessSyncChanges(FROM_HERE, sync_list3);
1853 policy_value3.DeepCopy());
1854 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus()); 2112 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus());
1855 } 2113 }
1856 2114
1857 // Check that a running and not pinned V2 application will be properly converted 2115 // Check that a running and not pinned V2 application will be properly converted
1858 // between locked and pinned when the order gets changed through a profile / 2116 // between locked and pinned when the order gets changed through a profile /
1859 // policy change. 2117 // policy change.
1860 TEST_F(ChromeLauncherControllerTest, 2118 TEST_F(ChromeLauncherControllerTest,
1861 RestoreDefaultAndRunningV2AppsResyncOrder) { 2119 RestoreDefaultAndRunningV2AppsResyncOrder) {
1862 InitLauncherController(); 2120 InitLauncherController();
1863 base::ListValue policy_value0; 2121 syncer::SyncChangeList sync_list0;
1864 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2122 InsertRemoveAllPins(&sync_list0);
1865 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2123 InsertPinValue(&sync_list0, 0, extension1_->id());
1866 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2124 InsertPinValue(&sync_list0, 1, extension3_->id());
1867 policy_value0.DeepCopy()); 2125 app_service_->ProcessSyncChanges(FROM_HERE, sync_list0);
1868 // The shelf layout has always one static item at the beginning (app List). 2126 // The shelf layout has always one static item at the beginning (app List).
1869 SetShelfChromeIconIndex(0);
1870 extension_service_->AddExtension(extension1_.get()); 2127 extension_service_->AddExtension(extension1_.get());
1871 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2128 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1872 extension_service_->AddExtension(extension2_.get()); 2129 extension_service_->AddExtension(extension2_.get());
1873 // No new app icon will be generated. 2130 // No new app icon will be generated.
1874 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2131 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1875 // Add the app as an unpinned but running V2 app. 2132 // Add the app as an unpinned but running V2 app.
1876 CreateRunningV2App(extension2_->id()); 2133 CreateRunningV2App(extension2_->id());
1877 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); 2134 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus());
1878 extension_service_->AddExtension(extension3_.get()); 2135 extension_service_->AddExtension(extension3_.get());
1879 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); 2136 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus());
1880 2137
1881 // Now request to pin all items which should convert the locked item into a 2138 // Now request to pin all items which should convert the locked item into a
1882 // pinned item. 2139 // pinned item.
1883 base::ListValue policy_value1; 2140 syncer::SyncChangeList sync_list1;
1884 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2141 InsertRemoveAllPins(&sync_list1);
1885 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2142 InsertPinValue(&sync_list1, 0, extension3_->id());
1886 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2143 InsertPinValue(&sync_list1, 1, extension2_->id());
1887 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2144 InsertPinValue(&sync_list1, 2, extension1_->id());
1888 policy_value1.DeepCopy()); 2145 app_service_->ProcessSyncChanges(FROM_HERE, sync_list1);
1889 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2146 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1890 2147
1891 // Going back to a status where there is no requirement for app 2 to be pinned 2148 // Going back to a status where there is no requirement for app 2 to be pinned
1892 // should convert it back to running V2 app. Since the position is determined 2149 // should convert it back to running V2 app. Since the position is determined
1893 // by the |ShelfModel|'s weight system, it will be after last pinned item. 2150 // by the |ShelfModel|'s weight system, it will be after last pinned item.
1894 base::ListValue policy_value2; 2151 syncer::SyncChangeList sync_list2;
1895 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2152 InsertRemoveAllPins(&sync_list2);
1896 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2153 InsertPinValue(&sync_list2, 0, extension3_->id());
1897 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2154 InsertPinValue(&sync_list2, 1, extension1_->id());
1898 policy_value2.DeepCopy()); 2155 app_service_->ProcessSyncChanges(FROM_HERE, sync_list2);
1899 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); 2156 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus());
1900 2157
1901 // Removing an item should simply close it and everything should shift. 2158 // Removing an item should simply close it and everything should shift.
1902 base::ListValue policy_value3; 2159 syncer::SyncChangeList sync_list3;
1903 InsertPrefValue(&policy_value3, 0, extension3_->id()); 2160 InsertRemoveAllPins(&sync_list3);
1904 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2161 InsertPinValue(&sync_list3, 0, extension3_->id());
1905 policy_value3.DeepCopy()); 2162 app_service_->ProcessSyncChanges(FROM_HERE, sync_list3);
1906 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); 2163 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus());
1907 } 2164 }
1908 2165
1909 // Each user has a different set of applications pinned. Check that when 2166 // Each user has a different set of applications pinned. Check that when
1910 // switching between the two users, the state gets properly set. 2167 // switching between the two users, the state gets properly set.
1911 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) { 2168 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) {
1912 base::ListValue user_a; 2169 syncer::SyncChangeList user_a;
1913 base::ListValue user_b; 2170 syncer::SyncChangeList user_b;
1914 SetUpMultiUserScenario(&user_a, &user_b); 2171 SetUpMultiUserScenario(&user_a, &user_b);
2172
1915 // Show user 1. 2173 // Show user 1.
1916 SetShelfChromeIconIndex(6); 2174 ResetAllPins();
1917 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2175 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
1918 user_a.DeepCopy());
1919 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2176 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1920 GetPinnedAppStatus()); 2177 GetPinnedAppStatus());
1921 2178
1922 // Show user 2. 2179 // Show user 2.
1923 SetShelfChromeIconIndex(4); 2180 ResetAllPins();
1924 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2181 app_service_->ProcessSyncChanges(FROM_HERE, user_b);
1925 user_b.DeepCopy());
1926
1927 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2182 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1928 2183
1929 // Switch back to 1. 2184 // Switch back to 1.
1930 SetShelfChromeIconIndex(8); 2185 ResetAllPins();
1931 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2186 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
1932 user_a.DeepCopy());
1933 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2187 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1934 GetPinnedAppStatus()); 2188 GetPinnedAppStatus());
1935 2189
1936 // Switch back to 2. 2190 // Switch back to 2.
1937 SetShelfChromeIconIndex(4); 2191 ResetAllPins();
1938 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2192 app_service_->ProcessSyncChanges(FROM_HERE, user_b);
1939 user_b.DeepCopy());
1940 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2193 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1941 } 2194 }
1942 2195
1943 // Each user has a different set of applications pinned, and one user has an 2196 // Each user has a different set of applications pinned, and one user has an
1944 // application running. Check that when switching between the two users, the 2197 // application running. Check that when switching between the two users, the
1945 // state gets properly set. 2198 // state gets properly set.
1946 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) { 2199 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) {
1947 base::ListValue user_a; 2200 syncer::SyncChangeList user_a;
1948 base::ListValue user_b; 2201 syncer::SyncChangeList user_b;
1949 SetUpMultiUserScenario(&user_a, &user_b); 2202 SetUpMultiUserScenario(&user_a, &user_b);
1950 2203
1951 // Run App1 and assume that it is a V2 app. 2204 // Run App1 and assume that it is a V2 app.
1952 CreateRunningV2App(extension1_->id()); 2205 CreateRunningV2App(extension1_->id());
1953 2206
1954 // Show user 1. 2207 // Show user 1.
1955 SetShelfChromeIconIndex(6); 2208 ResetAllPins();
1956 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2209 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
1957 user_a.DeepCopy());
1958 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2210 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1959 GetPinnedAppStatus()); 2211 GetPinnedAppStatus());
1960 2212
1961 // Show user 2. 2213 // Show user 2.
1962 SetShelfChromeIconIndex(4); 2214 ResetAllPins();
1963 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2215 app_service_->ProcessSyncChanges(FROM_HERE, user_b);
1964 user_b.DeepCopy());
1965
1966 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2216 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1967 2217
1968 // Switch back to 1. 2218 // Switch back to 1.
1969 SetShelfChromeIconIndex(8); 2219 ResetAllPins();
1970 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2220 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
1971 user_a.DeepCopy());
1972 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2221 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1973 GetPinnedAppStatus()); 2222 GetPinnedAppStatus());
1974 2223
1975 // Switch back to 2. 2224 // Switch back to 2.
1976 SetShelfChromeIconIndex(4); 2225 ResetAllPins();
1977 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2226 app_service_->ProcessSyncChanges(FROM_HERE, user_b);
1978 user_b.DeepCopy());
1979 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2227 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1980 } 2228 }
1981 2229
1982 // Each user has a different set of applications pinned, and one user has an 2230 // Each user has a different set of applications pinned, and one user has an
1983 // application running. The chrome icon is not the last item in the list. 2231 // application running. The chrome icon is not the last item in the list.
1984 // Check that when switching between the two users, the state gets properly set. 2232 // Check that when switching between the two users, the state gets properly set.
1985 // There was once a bug associated with this. 2233 // There was once a bug associated with this.
1986 TEST_F(ChromeLauncherControllerTest, 2234 TEST_F(ChromeLauncherControllerTest,
1987 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { 2235 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) {
1988 base::ListValue user_a; 2236 syncer::SyncChangeList user_a;
1989 base::ListValue user_b; 2237 syncer::SyncChangeList user_b;
1990 SetUpMultiUserScenario(&user_a, &user_b); 2238 SetUpMultiUserScenario(&user_a, &user_b);
1991 2239
1992 // Run App1 and assume that it is a V2 app. 2240 // Run App1 and assume that it is a V2 app.
1993 CreateRunningV2App(extension1_->id()); 2241 CreateRunningV2App(extension1_->id());
1994 2242
1995 // Show user 1. 2243 // Show user 1.
2244 ResetAllPins();
2245 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
1996 SetShelfChromeIconIndex(5); 2246 SetShelfChromeIconIndex(5);
1997 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1998 user_a.DeepCopy());
1999 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2247 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2000 GetPinnedAppStatus()); 2248 GetPinnedAppStatus());
2001 2249
2002 // Show user 2. 2250 // Show user 2.
2251 ResetAllPins();
2252 app_service_->ProcessSyncChanges(FROM_HERE, user_b);
2003 SetShelfChromeIconIndex(4); 2253 SetShelfChromeIconIndex(4);
2004 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2005 user_b.DeepCopy());
2006
2007 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2254 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
2008 2255
2009 // Switch back to 1. 2256 // Switch back to 1.
2257 ResetAllPins();
2258 app_service_->ProcessSyncChanges(FROM_HERE, user_a);
2010 SetShelfChromeIconIndex(5); 2259 SetShelfChromeIconIndex(5);
2011 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2012 user_a.DeepCopy());
2013 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2260 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2014 GetPinnedAppStatus()); 2261 GetPinnedAppStatus());
2015 } 2262 }
2016 2263
2017 TEST_F(ChromeLauncherControllerTest, Policy) { 2264 TEST_F(ChromeLauncherControllerTest, Policy) {
2018 extension_service_->AddExtension(extension1_.get()); 2265 extension_service_->AddExtension(extension1_.get());
2019 extension_service_->AddExtension(extension3_.get()); 2266 extension_service_->AddExtension(extension3_.get());
2020 2267
2268 InitLauncherController();
2269
2270 syncer::SyncChangeList sync_list;
2271 InsertRemoveAllPins(&sync_list);
2272 InsertPinValue(&sync_list, 0, extension_misc::kChromeAppId);
2273 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2274
2021 base::ListValue policy_value; 2275 base::ListValue policy_value;
2022 InsertPrefValue(&policy_value, 0, extension1_->id()); 2276 InsertPrefValue(&policy_value, 0, extension1_->id());
2023 InsertPrefValue(&policy_value, 1, extension2_->id()); 2277 InsertPrefValue(&policy_value, 1, extension2_->id());
2024 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2278 profile()->GetTestingPrefService()->SetManagedPref(
2025 policy_value.DeepCopy()); 2279 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2026 2280
2027 // Only |extension1_| should get pinned. |extension2_| is specified but not 2281 // Only |extension1_| should get pinned. |extension2_| is specified but not
2028 // installed, and |extension3_| is part of the default set, but that shouldn't 2282 // installed, and |extension3_| is part of the default set, but that shouldn't
2029 // take effect when the policy override is in place. 2283 // take effect when the policy override is in place.
2030 InitLauncherController(); 2284 ASSERT_EQ(3, model_->item_count());
2031 EXPECT_EQ(3, model_->item_count());
2032 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2285 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2033 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2286 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2034 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2287 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2035 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2288 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2036 2289
2037 // Installing |extension2_| should add it to the launcher. 2290 // Installing |extension2_| should add it to the launcher.
2038 extension_service_->AddExtension(extension2_.get()); 2291 extension_service_->AddExtension(extension2_.get());
2039 EXPECT_EQ(4, model_->item_count()); 2292 ASSERT_EQ(4, model_->item_count());
2040 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2293 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2041 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); 2294 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type);
2042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2295 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2043 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2296 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2044 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2297 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2045 2298
2046 // Removing |extension1_| from the policy should be reflected in the launcher. 2299 // Removing |extension1_| from the policy should be reflected in the launcher.
2047 policy_value.Remove(0, NULL); 2300 policy_value.Remove(0, NULL);
2048 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2301 profile()->GetTestingPrefService()->SetManagedPref(
2049 policy_value.DeepCopy()); 2302 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2050 EXPECT_EQ(3, model_->item_count()); 2303 EXPECT_EQ(3, model_->item_count());
2051 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2304 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2052 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 2305 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
2053 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2306 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2054 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2307 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2055 } 2308 }
2056 2309
2057 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { 2310 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
2058 extension_service_->AddExtension(extension3_.get()); 2311 extension_service_->AddExtension(extension3_.get());
2059 extension_service_->AddExtension(extension4_.get()); 2312 extension_service_->AddExtension(extension4_.get());
2060 2313
2061 InitLauncherController(); 2314 InitLauncherController();
2062 2315
2063 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2316 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2064 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2317 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2065 2318
2066 extension_service_->UnloadExtension(extension3_->id(), 2319 extension_service_->UnloadExtension(extension3_->id(),
2067 UnloadedExtensionInfo::REASON_UNINSTALL); 2320 UnloadedExtensionInfo::REASON_UNINSTALL);
2068 2321
2069 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2322 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2070 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2323 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2071 } 2324 }
2072 2325
2073 TEST_F(ChromeLauncherControllerTest, PrefUpdates) { 2326 TEST_F(ChromeLauncherControllerTest, SyncUpdates) {
2074 extension_service_->AddExtension(extension2_.get()); 2327 extension_service_->AddExtension(extension2_.get());
2075 extension_service_->AddExtension(extension3_.get()); 2328 extension_service_->AddExtension(extension3_.get());
2076 extension_service_->AddExtension(extension4_.get()); 2329 extension_service_->AddExtension(extension4_.get());
2077 2330
2078 InitLauncherController(); 2331 InitLauncherController();
2079 2332
2333 syncer::SyncChangeList sync_list;
2334 InsertRemoveAllPins(&sync_list);
2335 InsertPinValue(&sync_list, 10, extension_misc::kChromeAppId);
2336 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2337
2080 std::vector<std::string> expected_launchers; 2338 std::vector<std::string> expected_launchers;
2081 std::vector<std::string> actual_launchers; 2339 std::vector<std::string> actual_launchers;
2082 base::ListValue pref_value;
2083 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2084 pref_value.DeepCopy());
2085 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2340 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2086 EXPECT_EQ(expected_launchers, actual_launchers); 2341 EXPECT_EQ(expected_launchers, actual_launchers);
2087 2342
2088 // Unavailable extensions don't create launcher items. 2343 // Unavailable extensions don't create launcher items.
2089 InsertPrefValue(&pref_value, 0, extension1_->id()); 2344 sync_list.clear();
2090 InsertPrefValue(&pref_value, 1, extension2_->id()); 2345 InsertPinValue(&sync_list, 0, extension1_->id());
2091 InsertPrefValue(&pref_value, 2, extension4_->id()); 2346 InsertPinValue(&sync_list, 1, extension2_->id());
2092 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2347 InsertPinValue(&sync_list, 3, extension4_->id());
2093 pref_value.DeepCopy()); 2348 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2349
2094 expected_launchers.push_back(extension2_->id()); 2350 expected_launchers.push_back(extension2_->id());
2095 expected_launchers.push_back(extension4_->id()); 2351 expected_launchers.push_back(extension4_->id());
2096 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2352 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2097 EXPECT_EQ(expected_launchers, actual_launchers); 2353 EXPECT_EQ(expected_launchers, actual_launchers);
2098 2354
2099 // Redundant pref entries show up only once. 2355 sync_list.clear();
2100 InsertPrefValue(&pref_value, 2, extension3_->id()); 2356 InsertPinValue(&sync_list, 2, extension3_->id());
2101 InsertPrefValue(&pref_value, 2, extension3_->id()); 2357 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2102 InsertPrefValue(&pref_value, 5, extension3_->id());
2103 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2104 pref_value.DeepCopy());
2105 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id()); 2358 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id());
2106 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2359 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2107 EXPECT_EQ(expected_launchers, actual_launchers); 2360 EXPECT_EQ(expected_launchers, actual_launchers);
2108 2361
2109 // Order changes are reflected correctly. 2362 sync_list.clear();
2110 pref_value.Clear(); 2363 UpdatePinValue(&sync_list, 0, extension4_->id());
2111 InsertPrefValue(&pref_value, 0, extension4_->id()); 2364 UpdatePinValue(&sync_list, 1, extension3_->id());
2112 InsertPrefValue(&pref_value, 1, extension3_->id()); 2365 UpdatePinValue(&sync_list, 2, extension2_->id());
2113 InsertPrefValue(&pref_value, 2, extension2_->id()); 2366 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2114 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2115 pref_value.DeepCopy());
2116 std::reverse(expected_launchers.begin(), expected_launchers.end()); 2367 std::reverse(expected_launchers.begin(), expected_launchers.end());
2117 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2368 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2118 EXPECT_EQ(expected_launchers, actual_launchers); 2369 EXPECT_EQ(expected_launchers, actual_launchers);
2119 2370
2120 // Clearing works. 2371 sync_list.clear();
2121 pref_value.Clear(); 2372 RemovePinValue(&sync_list, extension4_->id());
2122 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2373 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2123 pref_value.DeepCopy()); 2374
2375 expected_launchers.erase(expected_launchers.begin());
2376 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2377 EXPECT_EQ(expected_launchers, actual_launchers);
2378
2379 sync_list.clear();
2380 RemovePinValue(&sync_list, extension3_->id());
2381 RemovePinValue(&sync_list, extension2_->id());
2382 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2124 expected_launchers.clear(); 2383 expected_launchers.clear();
2125 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2384 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2126 EXPECT_EQ(expected_launchers, actual_launchers); 2385 EXPECT_EQ(expected_launchers, actual_launchers);
2127 } 2386 }
2128 2387
2129 TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) { 2388 TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) {
2130 extension_service_->AddExtension(extension1_.get()); 2389 extension_service_->AddExtension(extension1_.get());
2131 extension_service_->AddExtension(extension3_.get()); 2390 extension_service_->AddExtension(extension3_.get());
2132 2391
2133 InitLauncherController(); 2392 InitLauncherController();
2134 2393
2135 base::ListValue pref_value; 2394 syncer::SyncChangeList sync_list;
2136 InsertPrefValue(&pref_value, 0, extension1_->id()); 2395 InsertRemoveAllPins(&sync_list);
2137 InsertPrefValue(&pref_value, 1, extension2_->id()); 2396 InsertPinValue(&sync_list, 0, extension1_->id());
2138 InsertPrefValue(&pref_value, 2, extension3_->id()); 2397 InsertPinValue(&sync_list, 1, extension2_->id());
2139 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2398 InsertPinValue(&sync_list, 2, extension3_->id());
2140 pref_value.DeepCopy()); 2399 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
2141 2400
2142 std::vector<std::string> expected_launchers; 2401 std::vector<std::string> expected_launchers;
2143 expected_launchers.push_back(extension1_->id()); 2402 expected_launchers.push_back(extension1_->id());
2144 expected_launchers.push_back(extension3_->id()); 2403 expected_launchers.push_back(extension3_->id());
2145 std::vector<std::string> actual_launchers; 2404 std::vector<std::string> actual_launchers;
2146 2405
2147 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2406 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2148 EXPECT_EQ(expected_launchers, actual_launchers); 2407 EXPECT_EQ(expected_launchers, actual_launchers);
2149 2408
2150 // Install |extension2| and verify it shows up between the other two. 2409 // Install |extension2| and verify it shows up between the other two.
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2887 } else { 3146 } else {
2888 // Clear already registered ShelfItemDelegate. 3147 // Clear already registered ShelfItemDelegate.
2889 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3148 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2890 test.RemoveAllShelfItemDelegateForTest(); 3149 test.RemoveAllShelfItemDelegateForTest();
2891 } 3150 }
2892 model_.reset(new ash::ShelfModel); 3151 model_.reset(new ash::ShelfModel);
2893 3152
2894 AddAppListLauncherItem(); 3153 AddAppListLauncherItem();
2895 launcher_controller_.reset( 3154 launcher_controller_.reset(
2896 ChromeLauncherController::CreateInstance(profile(), model_.get())); 3155 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2897 helper = new TestLauncherControllerHelper; 3156 helper = new TestLauncherControllerHelper(profile());
2898 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3157 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2899 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3158 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
2900 SetLauncherControllerHelper(helper); 3159 SetLauncherControllerHelper(helper);
2901 if (!ash::Shell::HasInstance()) { 3160 if (!ash::Shell::HasInstance()) {
2902 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3161 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2903 SetShelfItemDelegateManager(item_delegate_manager_); 3162 SetShelfItemDelegateManager(item_delegate_manager_);
2904 } 3163 }
2905 launcher_controller_->Init(); 3164 launcher_controller_->Init();
2906 3165
2907 // Check ShelfItems are restored after resetting ChromeLauncherController. 3166 // Check ShelfItems are restored after resetting ChromeLauncherController.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 } else { 3204 } else {
2946 // Clear already registered ShelfItemDelegate. 3205 // Clear already registered ShelfItemDelegate.
2947 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3206 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2948 test.RemoveAllShelfItemDelegateForTest(); 3207 test.RemoveAllShelfItemDelegateForTest();
2949 } 3208 }
2950 model_.reset(new ash::ShelfModel); 3209 model_.reset(new ash::ShelfModel);
2951 3210
2952 AddAppListLauncherItem(); 3211 AddAppListLauncherItem();
2953 launcher_controller_.reset( 3212 launcher_controller_.reset(
2954 ChromeLauncherController::CreateInstance(profile(), model_.get())); 3213 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2955 helper = new TestLauncherControllerHelper; 3214 helper = new TestLauncherControllerHelper(profile());
2956 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3215 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2957 SetLauncherControllerHelper(helper); 3216 SetLauncherControllerHelper(helper);
2958 // app_icon_loader is owned by ChromeLauncherController. 3217 // app_icon_loader is owned by ChromeLauncherController.
2959 app_icon_loader = new TestAppIconLoaderImpl; 3218 app_icon_loader = new TestAppIconLoaderImpl;
2960 app_icon_loader->AddSupportedApp("1"); 3219 app_icon_loader->AddSupportedApp("1");
2961 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3220 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
2962 if (!ash::Shell::HasInstance()) { 3221 if (!ash::Shell::HasInstance()) {
2963 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3222 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2964 SetShelfItemDelegateManager(item_delegate_manager_); 3223 SetShelfItemDelegateManager(item_delegate_manager_);
2965 } 3224 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 // by hash we can determine that appropriate package was set by policy. 3326 // by hash we can determine that appropriate package was set by policy.
3068 base::ListValue policy_value; 3327 base::ListValue policy_value;
3069 InsertPrefValue(&policy_value, 0, appinfo.package_name); 3328 InsertPrefValue(&policy_value, 0, appinfo.package_name);
3070 profile()->GetTestingPrefService()->SetManagedPref( 3329 profile()->GetTestingPrefService()->SetManagedPref(
3071 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 3330 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
3072 3331
3073 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 3332 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
3074 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 3333 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
3075 launcher_controller_->GetPinnable(app_id)); 3334 launcher_controller_->GetPinnable(app_id));
3076 } 3335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698