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

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: rebased, comments addressed, removed item_pinned_by_policy 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();
xiyuan 2016/06/14 21:42:50 Line 338-340 could be just extension_service_->In
khmel 2016/06/15 17:01:20 Absolutely :)
341
342 app_service_ =
343 app_list::AppListSyncableServiceFactory::GetForProfile(profile());
344 StartAppSyncService(syncer::SyncDataList());
320 345
321 std::string error; 346 std::string error;
322 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 347 extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
323 manifest, 348 manifest,
324 Extension::NO_FLAGS, 349 Extension::NO_FLAGS,
325 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 350 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
326 &error); 351 &error);
327 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 352 extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
328 manifest, 353 manifest,
329 Extension::NO_FLAGS, 354 Extension::NO_FLAGS,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 model_->item_count(), 410 model_->item_count(),
386 ash::TYPE_PLATFORM_APP); 411 ash::TYPE_PLATFORM_APP);
387 DCHECK(id); 412 DCHECK(id);
388 // Change the created launcher controller into a V2 app controller. 413 // Change the created launcher controller into a V2 app controller.
389 test_controller_ = new TestV2AppLauncherItemController(app_id, 414 test_controller_ = new TestV2AppLauncherItemController(app_id,
390 launcher_controller_.get()); 415 launcher_controller_.get());
391 launcher_controller_->SetItemController(id, test_controller_); 416 launcher_controller_->SetItemController(id, test_controller_);
392 } 417 }
393 418
394 // Sets the stage for a multi user test. 419 // Sets the stage for a multi user test.
395 virtual void SetUpMultiUserScenario(base::ListValue* user_a, 420 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a,
396 base::ListValue* user_b) { 421 syncer::SyncChangeList* user_b) {
397 InitLauncherController(); 422 InitLauncherController();
398 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 423 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
399 424
400 // Set an empty pinned pref to begin with. 425 // Set an empty pinned pref to begin with.
401 base::ListValue no_user; 426 syncer::SyncChangeList sync_list;
402 SetShelfChromeIconIndex(0); 427 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId);
403 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 428 SendPinChanges(sync_list, true);
404 no_user.DeepCopy());
405 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 429 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
406 430
407 // Assume all applications have been added already. 431 // Assume all applications have been added already.
408 extension_service_->AddExtension(extension1_.get()); 432 extension_service_->AddExtension(extension1_.get());
409 extension_service_->AddExtension(extension2_.get()); 433 extension_service_->AddExtension(extension2_.get());
410 extension_service_->AddExtension(extension3_.get()); 434 extension_service_->AddExtension(extension3_.get());
411 extension_service_->AddExtension(extension4_.get()); 435 extension_service_->AddExtension(extension4_.get());
412 extension_service_->AddExtension(extension5_.get()); 436 extension_service_->AddExtension(extension5_.get());
413 extension_service_->AddExtension(extension6_.get()); 437 extension_service_->AddExtension(extension6_.get());
414 extension_service_->AddExtension(extension7_.get()); 438 extension_service_->AddExtension(extension7_.get());
415 extension_service_->AddExtension(extension8_.get()); 439 extension_service_->AddExtension(extension8_.get());
416 // There should be nothing in the list by now. 440 // There should be nothing in the list by now.
417 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 441 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
418 442
419 // Set user a preferences. 443 // Set user a preferences.
420 InsertPrefValue(user_a, 0, extension1_->id()); 444 InsertAddPinChange(user_a, 0, extension1_->id());
421 InsertPrefValue(user_a, 1, extension2_->id()); 445 InsertAddPinChange(user_a, 1, extension2_->id());
422 InsertPrefValue(user_a, 2, extension3_->id()); 446 InsertAddPinChange(user_a, 2, extension3_->id());
423 InsertPrefValue(user_a, 3, extension4_->id()); 447 InsertAddPinChange(user_a, 3, extension4_->id());
424 InsertPrefValue(user_a, 4, extension5_->id()); 448 InsertAddPinChange(user_a, 4, extension5_->id());
425 InsertPrefValue(user_a, 5, extension6_->id()); 449 InsertAddPinChange(user_a, 5, extension6_->id());
450 InsertAddPinChange(user_a, 6, extension_misc::kChromeAppId);
426 451
427 // Set user b preferences. 452 // Set user b preferences.
428 InsertPrefValue(user_b, 0, extension7_->id()); 453 InsertAddPinChange(user_b, 0, extension7_->id());
429 InsertPrefValue(user_b, 1, extension8_->id()); 454 InsertAddPinChange(user_b, 1, extension8_->id());
455 InsertAddPinChange(user_b, 2, extension_misc::kChromeAppId);
430 } 456 }
431 457
432 void TearDown() override { 458 void TearDown() override {
433 arc_test_.TearDown(); 459 arc_test_.TearDown();
434 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr); 460 launcher_controller_->SetShelfItemDelegateManagerForTest(nullptr);
435 model_->RemoveObserver(model_observer_.get()); 461 model_->RemoveObserver(model_observer_.get());
436 model_observer_.reset(); 462 model_observer_.reset();
437 launcher_controller_.reset(); 463 launcher_controller_.reset();
438 464
439 // item_delegate_manager_ must be deleted after launch_controller_, 465 // item_delegate_manager_ must be deleted after launch_controller_,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 SetShelfItemDelegateManager(item_delegate_manager_); 499 SetShelfItemDelegateManager(item_delegate_manager_);
474 launcher_controller_->Init(); 500 launcher_controller_->Init();
475 } 501 }
476 502
477 void InitLauncherControllerWithBrowser() { 503 void InitLauncherControllerWithBrowser() {
478 InitLauncherController(); 504 InitLauncherController();
479 chrome::NewTab(browser()); 505 chrome::NewTab(browser());
480 browser()->window()->Show(); 506 browser()->window()->Show();
481 } 507 }
482 508
509 void RecreateChromeLauncher() {
510 model_.reset(new ash::ShelfModel);
511 AddAppListLauncherItem();
512 launcher_controller_.reset(
513 ChromeLauncherController::CreateInstance(profile(), model_.get()));
514 launcher_controller_->Init();
515 }
516
517 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
518 app_service_->MergeDataAndStartSyncing(
519 syncer::APP_LIST, init_sync_list,
520 base::WrapUnique(new syncer::FakeSyncChangeProcessor()),
521 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
522 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
523 }
524
525 void StopAppSyncService() { app_service_->StopSyncing(syncer::APP_LIST); }
526
483 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) { 527 void SetAppIconLoader(std::unique_ptr<AppIconLoader> loader) {
484 std::vector<std::unique_ptr<AppIconLoader>> loaders; 528 std::vector<std::unique_ptr<AppIconLoader>> loaders;
485 loaders.push_back(std::move(loader)); 529 loaders.push_back(std::move(loader));
486 launcher_controller_->SetAppIconLoadersForTest(loaders); 530 launcher_controller_->SetAppIconLoadersForTest(loaders);
487 } 531 }
488 532
489 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1, 533 void SetAppIconLoaders(std::unique_ptr<AppIconLoader> loader1,
490 std::unique_ptr<AppIconLoader> loader2) { 534 std::unique_ptr<AppIconLoader> loader2) {
491 std::vector<std::unique_ptr<AppIconLoader>> loaders; 535 std::vector<std::unique_ptr<AppIconLoader>> loaders;
492 loaders.push_back(std::move(loader1)); 536 loaders.push_back(std::move(loader1));
493 loaders.push_back(std::move(loader2)); 537 loaders.push_back(std::move(loader2));
494 launcher_controller_->SetAppIconLoadersForTest(loaders); 538 launcher_controller_->SetAppIconLoadersForTest(loaders);
495 } 539 }
496 540
497 void SetLauncherControllerHelper(LauncherControllerHelper* helper) { 541 void SetLauncherControllerHelper(LauncherControllerHelper* helper) {
498 launcher_controller_->SetLauncherControllerHelperForTest(helper); 542 launcher_controller_->SetLauncherControllerHelperForTest(helper);
499 } 543 }
500 544
501 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { 545 void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) {
502 launcher_controller_->SetShelfItemDelegateManagerForTest(manager); 546 launcher_controller_->SetShelfItemDelegateManagerForTest(manager);
503 } 547 }
504 548
505 void InsertPrefValue(base::ListValue* pref_value, 549 void InsertPrefValue(base::ListValue* pref_value,
506 int index, 550 int index,
507 const std::string& extension_id) { 551 const std::string& extension_id) {
508 base::DictionaryValue* entry = new base::DictionaryValue(); 552 base::DictionaryValue* entry = new base::DictionaryValue();
509 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 553 entry->SetString(ash::launcher::kPinnedAppsPrefAppIDPath, extension_id);
510 pref_value->Insert(index, entry); 554 pref_value->Insert(index, entry);
511 } 555 }
512 556
557 void InsertRemoveAllPinsChange(syncer::SyncChangeList* list) {
558 for (const auto& sync_peer : app_service_->sync_items()) {
559 sync_pb::EntitySpecifics specifics;
560 sync_pb::AppListSpecifics* app_list_specifics =
561 specifics.mutable_app_list();
562 app_list_specifics->set_item_id(sync_peer.first);
563 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
564 syncer::SyncData sync_data =
565 syncer::SyncData::CreateLocalData(sync_peer.first, "Test", specifics);
566 list->push_back(syncer::SyncChange(
567 FROM_HERE, syncer::SyncChange::ACTION_DELETE, sync_data));
568 }
569 }
570
571 syncer::StringOrdinal GeneratePinPosition(int position) {
572 syncer::StringOrdinal ordinal_position =
573 syncer::StringOrdinal::CreateInitialOrdinal();
574 for (int i = 0; i < position; ++i)
575 ordinal_position = ordinal_position.CreateAfter();
576 return ordinal_position;
577 }
578
579 void InsertPinChange(syncer::SyncChangeList* list,
580 int position,
581 const std::string& app_id,
582 syncer::SyncChange::SyncChangeType type) {
583 sync_pb::EntitySpecifics specifics;
584 sync_pb::AppListSpecifics* app_list_specifics =
585 specifics.mutable_app_list();
586 app_list_specifics->set_item_id(app_id);
587 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
588 if (position >= 0) {
589 app_list_specifics->set_item_pin_ordinal(
590 GeneratePinPosition(position).ToInternalValue());
591 }
592 syncer::SyncData sync_data =
593 syncer::SyncData::CreateLocalData(app_id, "Test", specifics);
594 list->push_back(syncer::SyncChange(FROM_HERE, type, sync_data));
595 }
596
597 void InsertAddPinChange(syncer::SyncChangeList* list,
598 int position,
599 const std::string& app_id) {
600 InsertPinChange(list, position, app_id, syncer::SyncChange::ACTION_ADD);
601 }
602
603 void InsertUpdatePinChange(syncer::SyncChangeList* list,
604 int position,
605 const std::string& app_id) {
606 InsertPinChange(list, position, app_id, syncer::SyncChange::ACTION_UPDATE);
607 }
608
609 void InsertRemovePinChange(syncer::SyncChangeList* list,
610 const std::string& app_id) {
611 InsertPinChange(list, -1, app_id, syncer::SyncChange::ACTION_UPDATE);
612 }
613
614 void ResetPinModel() {
615 syncer::SyncChangeList sync_list;
616 InsertRemoveAllPinsChange(&sync_list);
617 InsertAddPinChange(&sync_list, 0, kDummyAppId);
618 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
619 }
620
621 void SendPinChanges(const syncer::SyncChangeList& sync_list,
622 bool reset_pin_model) {
623 if (!reset_pin_model) {
624 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
625 } else {
626 syncer::SyncChangeList combined_sync_list;
627 InsertRemoveAllPinsChange(&combined_sync_list);
628 combined_sync_list.insert(combined_sync_list.end(), sync_list.begin(),
629 sync_list.end());
630 app_service_->ProcessSyncChanges(FROM_HERE, combined_sync_list);
631 }
632 }
633
634 // Set the index at which the chrome icon should be.
635 void SetShelfChromeIconIndex(int index) {
636 DCHECK(
637 app_service_->GetPinPosition(extension_misc::kChromeAppId).IsValid());
638 syncer::StringOrdinal chrome_position;
639 chrome_position = index == 0 ? GeneratePinPosition(0).CreateBefore()
640 : GeneratePinPosition(index - 1).CreateBetween(
641 GeneratePinPosition(index));
642
643 syncer::SyncChangeList sync_list;
644 sync_pb::EntitySpecifics specifics;
645 sync_pb::AppListSpecifics* app_list_specifics =
646 specifics.mutable_app_list();
647 app_list_specifics->set_item_id(extension_misc::kChromeAppId);
648 app_list_specifics->set_item_type(sync_pb::AppListSpecifics::TYPE_APP);
649 app_list_specifics->set_item_pin_ordinal(chrome_position.ToInternalValue());
650 syncer::SyncData sync_data = syncer::SyncData::CreateLocalData(
651 extension_misc::kChromeAppId, "Test", specifics);
652 sync_list.push_back(syncer::SyncChange(
653 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data));
654 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
655 }
656
513 // Gets the currently configured app launchers from the controller. 657 // Gets the currently configured app launchers from the controller.
514 void GetAppLaunchers(ChromeLauncherController* controller, 658 void GetAppLaunchers(ChromeLauncherController* controller,
515 std::vector<std::string>* launchers) { 659 std::vector<std::string>* launchers) {
516 launchers->clear(); 660 launchers->clear();
517 for (ash::ShelfItems::const_iterator iter(model_->items().begin()); 661 for (ash::ShelfItems::const_iterator iter(model_->items().begin());
518 iter != model_->items().end(); ++iter) { 662 iter != model_->items().end(); ++iter) {
519 ChromeLauncherController::IDToItemControllerMap::const_iterator 663 ChromeLauncherController::IDToItemControllerMap::const_iterator
520 entry(controller->id_to_item_controller_map_.find(iter->id)); 664 entry(controller->id_to_item_controller_map_.find(iter->id));
521 if (iter->type == ash::TYPE_APP_SHORTCUT && 665 if (iter->type == ash::TYPE_APP_SHORTCUT &&
522 entry != controller->id_to_item_controller_map_.end()) { 666 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())); 742 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id()));
599 } else if (app == extension6_->id()) { 743 } else if (app == extension6_->id()) {
600 result += "App6"; 744 result += "App6";
601 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); 745 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id()));
602 } else if (app == extension7_->id()) { 746 } else if (app == extension7_->id()) {
603 result += "App7"; 747 result += "App7";
604 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); 748 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id()));
605 } else if (app == extension8_->id()) { 749 } else if (app == extension8_->id()) {
606 result += "App8"; 750 result += "App8";
607 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); 751 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 { 752 } else {
611 result += "unknown"; 753 bool arc_app_found = false;
754 for (const auto& arc_app : arc_test_.fake_apps()) {
755 if (app == ArcAppTest::GetAppId(arc_app)) {
756 result += arc_app.name;
757 arc_app_found = true;
758 break;
759 }
760 }
761 if (!arc_app_found)
762 result += "unknown";
612 } 763 }
613 break; 764 break;
614 } 765 }
615 case ash::TYPE_BROWSER_SHORTCUT: 766 case ash::TYPE_BROWSER_SHORTCUT:
616 result += "Chrome"; 767 result += "Chrome";
617 break; 768 break;
618 case ash::TYPE_APP_LIST: 769 case ash::TYPE_APP_LIST:
619 result += "AppList"; 770 result += "AppList";
620 break; 771 break;
621 default: 772 default:
622 result += "Unknown"; 773 result += "Unknown";
623 break; 774 break;
624 } 775 }
625 } 776 }
626 return result; 777 return result;
627 } 778 }
628 779
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 780 // Remember the order of unpinned but running applications for the current
636 // user. 781 // user.
637 void RememberUnpinnedRunningApplicationOrder() { 782 void RememberUnpinnedRunningApplicationOrder() {
638 launcher_controller_->RememberUnpinnedRunningApplicationOrder(); 783 launcher_controller_->RememberUnpinnedRunningApplicationOrder();
639 } 784 }
640 785
641 // Restore the order of running but unpinned applications for a given user. 786 // Restore the order of running but unpinned applications for a given user.
642 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) { 787 void RestoreUnpinnedRunningApplicationOrder(const AccountId& account_id) {
643 launcher_controller_->RestoreUnpinnedRunningApplicationOrder( 788 launcher_controller_->RestoreUnpinnedRunningApplicationOrder(
644 account_id.GetUserEmail()); 789 account_id.GetUserEmail());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 scoped_refptr<Extension> extension4_; 828 scoped_refptr<Extension> extension4_;
684 scoped_refptr<Extension> extension5_; 829 scoped_refptr<Extension> extension5_;
685 scoped_refptr<Extension> extension6_; 830 scoped_refptr<Extension> extension6_;
686 scoped_refptr<Extension> extension7_; 831 scoped_refptr<Extension> extension7_;
687 scoped_refptr<Extension> extension8_; 832 scoped_refptr<Extension> extension8_;
688 833
689 ArcAppTest arc_test_; 834 ArcAppTest arc_test_;
690 std::unique_ptr<ChromeLauncherController> launcher_controller_; 835 std::unique_ptr<ChromeLauncherController> launcher_controller_;
691 std::unique_ptr<TestShelfModelObserver> model_observer_; 836 std::unique_ptr<TestShelfModelObserver> model_observer_;
692 std::unique_ptr<ash::ShelfModel> model_; 837 std::unique_ptr<ash::ShelfModel> model_;
838 std::unique_ptr<TestingProfileManager> profile_manager_;
693 839
694 // |item_delegate_manager_| owns |test_controller_|. 840 // |item_delegate_manager_| owns |test_controller_|.
695 LauncherItemController* test_controller_; 841 LauncherItemController* test_controller_;
696 842
697 ExtensionService* extension_service_; 843 ExtensionService* extension_service_;
698 844
845 app_list::AppListSyncableService* app_service_;
846
699 ash::ShelfItemDelegateManager* item_delegate_manager_; 847 ash::ShelfItemDelegateManager* item_delegate_manager_;
700 848
701 private: 849 private:
702 TestBrowserWindow* CreateTestBrowserWindowAura() { 850 TestBrowserWindow* CreateTestBrowserWindowAura() {
703 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); 851 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
704 window->set_id(0); 852 window->set_id(0);
705 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 853 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
706 window->Init(ui::LAYER_TEXTURED); 854 window->Init(ui::LAYER_TEXTURED);
707 aura::client::ParentWindowWithContext(window.get(), GetContext(), 855 aura::client::ParentWindowWithContext(window.get(), GetContext(),
708 gfx::Rect(200, 200)); 856 gfx::Rect(200, 200));
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 1119
972 private: 1120 private:
973 typedef std::map<Profile*, std::string> ProfileToNameMap; 1121 typedef std::map<Profile*, std::string> ProfileToNameMap;
974 TestingProfileManager* profile_manager() { return profile_manager_.get(); } 1122 TestingProfileManager* profile_manager() { return profile_manager_.get(); }
975 1123
976 chromeos::FakeChromeUserManager* GetFakeUserManager() { 1124 chromeos::FakeChromeUserManager* GetFakeUserManager() {
977 return static_cast<chromeos::FakeChromeUserManager*>( 1125 return static_cast<chromeos::FakeChromeUserManager*>(
978 user_manager::UserManager::Get()); 1126 user_manager::UserManager::Get());
979 } 1127 }
980 1128
981 std::unique_ptr<TestingProfileManager> profile_manager_;
982 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 1129 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
983 1130
984 ash::test::TestShellDelegate* shell_delegate_; 1131 ash::test::TestShellDelegate* shell_delegate_;
985 1132
986 ProfileToNameMap created_profiles_; 1133 ProfileToNameMap created_profiles_;
987 1134
988 DISALLOW_COPY_AND_ASSIGN( 1135 DISALLOW_COPY_AND_ASSIGN(
989 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest); 1136 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest);
990 }; 1137 };
991 1138
992 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 1139 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
993 InitLauncherController(); 1140 InitLauncherController();
994 // Model should only contain the browser shortcut and app list items. 1141 // Model should only contain the browser shortcut and app list items.
995 EXPECT_EQ(2, model_->item_count()); 1142 EXPECT_EQ(2, model_->item_count());
996 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1143 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
997 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1144 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
998 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1145 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
999 1146
1000 // Installing |extension3_| should add it to the launcher - behind the 1147 // Installing |extension3_| should add it to the launcher - behind the
1001 // chrome icon. 1148 // chrome icon.
1002 extension_service_->AddExtension(extension3_.get()); 1149 extension_service_->AddExtension(extension3_.get());
1003 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1150 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1004 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1151 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1005 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1006 } 1153 }
1007 1154
1155 TEST_F(ChromeLauncherControllerTest, ArcAppPinCrossPlatformWorkflow) {
1156 // Work on Arc-disabled platform first.
1157 arc_test_.SetUp(profile());
1158
1159 const std::string arc_app_id1 =
1160 ArcAppTest::GetAppId(arc_test_.fake_apps()[0]);
1161 const std::string arc_app_id2 =
1162 ArcAppTest::GetAppId(arc_test_.fake_apps()[1]);
1163 const std::string arc_app_id3 =
1164 ArcAppTest::GetAppId(arc_test_.fake_apps()[2]);
1165
1166 InitLauncherController();
1167
1168 extension_service_->AddExtension(extension1_.get());
1169 extension_service_->AddExtension(extension2_.get());
1170 extension_service_->AddExtension(extension3_.get());
1171
1172 // extension 1, 3 are pinned by user
1173 syncer::SyncChangeList sync_list;
1174 InsertAddPinChange(&sync_list, 0, extension1_->id());
1175 InsertAddPinChange(&sync_list, 1, arc_app_id1);
1176 InsertAddPinChange(&sync_list, 2, extension2_->id());
1177 InsertAddPinChange(&sync_list, 3, arc_app_id2);
1178 InsertAddPinChange(&sync_list, 4, extension3_->id());
1179 SendPinChanges(sync_list, true);
1180 SetShelfChromeIconIndex(1);
1181
1182 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1183 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1184 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1185 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1186 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1187 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1188 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1189
1190 // Persist pin state, we don't have active pin for Arc apps yet, but pin
1191 // model should have it.
1192 syncer::SyncDataList copy_sync_list =
1193 app_service_->GetAllSyncData(syncer::APP_LIST);
1194
1195 launcher_controller_.reset();
1196 SendPinChanges(syncer::SyncChangeList(), true);
1197 StopAppSyncService();
1198 EXPECT_EQ(0U, app_service_->sync_items().size());
1199
1200 // Move to Arc-enabled platform, restart syncing with stored data.
1201 StartAppSyncService(copy_sync_list);
1202 RecreateChromeLauncher();
1203
1204 // Pins must be automatically updated.
1205 SendListOfArcApps();
1206 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1207 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1208 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1209 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1210 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1211 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1212
1213 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3",
1214 GetPinnedAppStatus());
1215
1216 // Now move pins on Arc-enabled platform.
1217 model_->Move(1, 4);
1218 model_->Move(3, 1);
1219 model_->Move(3, 5);
1220 model_->Move(4, 2);
1221 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3",
1222 GetPinnedAppStatus());
1223
1224 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST);
1225
1226 launcher_controller_.reset();
1227 ResetPinModel();
1228
1229 SendPinChanges(syncer::SyncChangeList(), true);
1230 StopAppSyncService();
1231 EXPECT_EQ(0U, app_service_->sync_items().size());
1232
1233 // Move back to Arc-disabled platform.
1234 EnableArc(false);
1235 StartAppSyncService(copy_sync_list);
1236 RecreateChromeLauncher();
1237
1238 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1239 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1240 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1241 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1242 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1243 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1244 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus());
1245
1246 // Now move/remove pins on Arc-disabled platform.
1247 model_->Move(4, 2);
1248 launcher_controller_->UnpinAppWithID(extension2_->id());
1249 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus());
1250 EnableArc(true);
1251
1252 SendListOfArcApps();
1253
1254 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1255 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1256 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1257 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1258 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1259 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1260 EXPECT_EQ("AppList, Fake App 1, App3, Chrome, App1, Fake App 0",
1261 GetPinnedAppStatus());
1262 }
1263
1008 /* 1264 /*
1009 * Test ChromeLauncherController correctly merges policy pinned apps 1265 * Test ChromeLauncherController correctly merges policy pinned apps
1010 * and user pinned apps 1266 * and user pinned apps
1011 */ 1267 */
1012 TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) { 1268 TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) {
1013 InitLauncherController(); 1269 InitLauncherController();
1014 1270
1015 base::ListValue user_pref_value;
1016 extension_service_->AddExtension(extension1_.get()); 1271 extension_service_->AddExtension(extension1_.get());
1017 extension_service_->AddExtension(extension3_.get()); 1272 extension_service_->AddExtension(extension3_.get());
1018 extension_service_->AddExtension(extension4_.get()); 1273 extension_service_->AddExtension(extension4_.get());
1019 extension_service_->AddExtension(extension5_.get()); 1274 extension_service_->AddExtension(extension5_.get());
1020 // extension 1, 3 are pinned by user 1275 // extension 1, 3 are pinned by user
1021 InsertPrefValue(&user_pref_value, 0, extension1_->id()); 1276 syncer::SyncChangeList sync_list;
1022 InsertPrefValue(&user_pref_value, 1, extension3_->id()); 1277 InsertAddPinChange(&sync_list, 0, extension1_->id());
1023 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1278 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId);
1024 user_pref_value.DeepCopy()); 1279 InsertAddPinChange(&sync_list, 2, extension3_->id());
1280 SendPinChanges(sync_list, true);
1025 1281
1026 base::ListValue policy_value; 1282 base::ListValue policy_value;
1027 // extension 2 4 are pinned by policy 1283 // extension 2 4 are pinned by policy
1028 InsertPrefValue(&policy_value, 0, extension2_->id()); 1284 InsertPrefValue(&policy_value, 0, extension2_->id());
1029 InsertPrefValue(&policy_value, 1, extension4_->id()); 1285 InsertPrefValue(&policy_value, 1, extension4_->id());
1030 profile()->GetTestingPrefService()->SetManagedPref( 1286 profile()->GetTestingPrefService()->SetManagedPref(
1031 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 1287 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
1032 1288
1033 SetShelfChromeIconIndex(1);
1034
1035 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1289 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1036 // 2 is not pinned as it's not installed 1290 // 2 is not pinned as it's not installed
1037 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1291 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1038 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1292 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1039 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 1293 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
1040 // install extension 2 and check 1294 // install extension 2 and check
1041 extension_service_->AddExtension(extension2_.get()); 1295 extension_service_->AddExtension(extension2_.get());
1042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1296 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1043 1297
1044 // Check user can manually pin or unpin these apps 1298 // Check user can manually pin or unpin these apps
1045 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1299 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1046 launcher_controller_->GetPinnable(extension1_->id())); 1300 launcher_controller_->GetPinnable(extension1_->id()));
1047 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1301 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1048 launcher_controller_->GetPinnable(extension2_->id())); 1302 launcher_controller_->GetPinnable(extension2_->id()));
1049 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE, 1303 EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
1050 launcher_controller_->GetPinnable(extension3_->id())); 1304 launcher_controller_->GetPinnable(extension3_->id()));
1051 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 1305 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
1052 launcher_controller_->GetPinnable(extension4_->id())); 1306 launcher_controller_->GetPinnable(extension4_->id()));
1053 1307
1054 // Check the order of shelf pinned apps 1308 // Check the order of shelf pinned apps
1055 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus()); 1309 EXPECT_EQ("AppList, App2, App4, App1, Chrome, App3", GetPinnedAppStatus());
1056 } 1310 }
1057 1311
1058 // Check that the restauration of launcher items is happening in the same order 1312 // 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 1313 // as the user has pinned them (on another system) when they are synced reverse
1060 // order. 1314 // order.
1061 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { 1315 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
1062 InitLauncherController(); 1316 InitLauncherController();
1063 1317
1064 base::ListValue policy_value; 1318 syncer::SyncChangeList sync_list;
1065 InsertPrefValue(&policy_value, 0, extension1_->id()); 1319 InsertAddPinChange(&sync_list, 0, extension1_->id());
1066 InsertPrefValue(&policy_value, 1, extension2_->id()); 1320 InsertAddPinChange(&sync_list, 1, extension2_->id());
1067 InsertPrefValue(&policy_value, 2, extension3_->id()); 1321 InsertAddPinChange(&sync_list, 2, extension3_->id());
1068 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1322 SendPinChanges(sync_list, true);
1069 policy_value.DeepCopy()); 1323
1070 SetShelfChromeIconIndex(0);
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 InsertAddPinChange(&sync_list, 0, extension1_->id());
1105 InsertPrefValue(&policy_value, 1, extension2_->id()); 1358 InsertAddPinChange(&sync_list, 1, extension2_->id());
1106 InsertPrefValue(&policy_value, 2, extension3_->id()); 1359 InsertAddPinChange(&sync_list, 2, extension3_->id());
1360 SendPinChanges(sync_list, true);
1107 1361
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. 1362 // Model should only contain the browser shortcut and app list items.
1112 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1363 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1113 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1364 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1114 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1365 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1115 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1366 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1116 1367
1117 // Installing |extension2_| should add it to the launcher - behind the 1368 // Installing |extension2_| should add it to the launcher - behind the
1118 // chrome icon. 1369 // chrome icon.
1119 extension_service_->AddExtension(extension2_.get()); 1370 extension_service_->AddExtension(extension2_.get());
1120 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1371 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 11 matching lines...) Expand all
1132 extension_service_->AddExtension(extension3_.get()); 1383 extension_service_->AddExtension(extension3_.get());
1133 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1384 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1134 } 1385 }
1135 1386
1136 // Check that the restauration of launcher items is happening in the same order 1387 // 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 1388 // as the user has pinned / moved them (on another system) when they are synced
1138 // random order - including the chrome icon. 1389 // random order - including the chrome icon.
1139 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) { 1390 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) {
1140 InitLauncherController(); 1391 InitLauncherController();
1141 1392
1142 base::ListValue policy_value; 1393 syncer::SyncChangeList sync_list;
1143 InsertPrefValue(&policy_value, 0, extension1_->id()); 1394 InsertAddPinChange(&sync_list, 0, extension1_->id());
1144 InsertPrefValue(&policy_value, 1, extension2_->id()); 1395 InsertAddPinChange(&sync_list, 1, extension_misc::kChromeAppId);
1145 InsertPrefValue(&policy_value, 2, extension3_->id()); 1396 InsertAddPinChange(&sync_list, 2, extension2_->id());
1146 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1397 InsertAddPinChange(&sync_list, 3, extension3_->id());
1147 policy_value.DeepCopy()); 1398 SendPinChanges(sync_list, true);
1148 SetShelfChromeIconIndex(1); 1399
1149 // Model should only contain the browser shortcut and app list items. 1400 // Model should only contain the browser shortcut and app list items.
1150 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1401 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1151 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1402 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1403 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1153 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1404 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1154 1405
1155 // Installing |extension2_| should add it to the shelf - behind the 1406 // Installing |extension2_| should add it to the shelf - behind the
1156 // chrome icon. 1407 // chrome icon.
1157 ash::ShelfItem item; 1408 ash::ShelfItem item;
1158 extension_service_->AddExtension(extension2_.get()); 1409 extension_service_->AddExtension(extension2_.get());
1159 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1410 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1411 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1161 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1412 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1162 1413
1163 // Installing |extension1_| should add it to the launcher - behind the 1414 // Installing |extension1_| should add it to the launcher - behind the
1164 // chrome icon, but in first location. 1415 // chrome icon, but in first location.
1165 extension_service_->AddExtension(extension1_.get()); 1416 extension_service_->AddExtension(extension1_.get());
1166 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1417 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1167 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); 1418 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus());
1168 1419
1169 // Installing |extension3_| should add it to the launcher - behind the 1420 // Installing |extension3_| should add it to the launcher - behind the
1170 // chrome icon, but in first location. 1421 // chrome icon, but in first location.
1171 extension_service_->AddExtension(extension3_.get()); 1422 extension_service_->AddExtension(extension3_.get());
1172 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 1423 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
1173 } 1424 }
1174 1425
1175 // Check that syncing to a different state does the correct thing. 1426 // Check that syncing to a different state does the correct thing.
1176 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) { 1427 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) {
1177 InitLauncherController(); 1428 InitLauncherController();
1178 base::ListValue policy_value; 1429
1179 InsertPrefValue(&policy_value, 0, extension1_->id()); 1430 syncer::SyncChangeList sync_list0;
1180 InsertPrefValue(&policy_value, 1, extension2_->id()); 1431 InsertAddPinChange(&sync_list0, 0, extension1_->id());
1181 InsertPrefValue(&policy_value, 2, extension3_->id()); 1432 InsertAddPinChange(&sync_list0, 1, extension2_->id());
1182 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1433 InsertAddPinChange(&sync_list0, 2, extension3_->id());
1183 policy_value.DeepCopy()); 1434 SendPinChanges(sync_list0, true);
1435
1184 // The shelf layout has always one static item at the beginning (App List). 1436 // The shelf layout has always one static item at the beginning (App List).
1185 SetShelfChromeIconIndex(0);
1186 extension_service_->AddExtension(extension2_.get()); 1437 extension_service_->AddExtension(extension2_.get());
1187 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1438 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1188 extension_service_->AddExtension(extension1_.get()); 1439 extension_service_->AddExtension(extension1_.get());
1189 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 1440 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
1190 extension_service_->AddExtension(extension3_.get()); 1441 extension_service_->AddExtension(extension3_.get());
1191 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 1442 EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
1192 1443
1193 // Change the order with increasing chrome position and decreasing position. 1444 // Change the order with increasing chrome position and decreasing position.
1194 base::ListValue policy_value1; 1445 syncer::SyncChangeList sync_list1;
1195 InsertPrefValue(&policy_value1, 0, extension3_->id()); 1446 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1196 InsertPrefValue(&policy_value1, 1, extension1_->id()); 1447 InsertAddPinChange(&sync_list1, 1, extension1_->id());
1197 InsertPrefValue(&policy_value1, 2, extension2_->id()); 1448 InsertAddPinChange(&sync_list1, 2, extension2_->id());
1198 SetShelfChromeIconIndex(3); 1449 InsertAddPinChange(&sync_list1, 3, extension_misc::kChromeAppId);
1199 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1450 SendPinChanges(sync_list1, true);
1200 policy_value1.DeepCopy());
1201 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); 1451 EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus());
1202 base::ListValue policy_value2; 1452
1203 InsertPrefValue(&policy_value2, 0, extension2_->id()); 1453 syncer::SyncChangeList sync_list2;
1204 InsertPrefValue(&policy_value2, 1, extension3_->id()); 1454 InsertAddPinChange(&sync_list2, 0, extension2_->id());
1205 InsertPrefValue(&policy_value2, 2, extension1_->id()); 1455 InsertAddPinChange(&sync_list2, 1, extension3_->id());
1206 SetShelfChromeIconIndex(2); 1456 InsertAddPinChange(&sync_list2, 2, extension_misc::kChromeAppId);
1207 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1457 InsertAddPinChange(&sync_list2, 3, extension1_->id());
1208 policy_value2.DeepCopy()); 1458 SendPinChanges(sync_list2, true);
1209 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); 1459 EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus());
1210 1460
1211 // Check that the chrome icon can also be at the first possible location. 1461 // Check that the chrome icon can also be at the first possible location.
1212 SetShelfChromeIconIndex(0); 1462 syncer::SyncChangeList sync_list3;
1213 base::ListValue policy_value3; 1463 InsertAddPinChange(&sync_list3, 0, extension3_->id());
1214 InsertPrefValue(&policy_value3, 0, extension3_->id()); 1464 InsertAddPinChange(&sync_list3, 1, extension2_->id());
1215 InsertPrefValue(&policy_value3, 1, extension2_->id()); 1465 InsertAddPinChange(&sync_list3, 2, extension1_->id());
1216 InsertPrefValue(&policy_value3, 2, extension1_->id()); 1466 SendPinChanges(sync_list3, true);
1217 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1218 policy_value3.DeepCopy());
1219 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 1467 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1220 1468
1221 // Check that unloading of extensions works as expected. 1469 // Check that unloading of extensions works as expected.
1222 extension_service_->UnloadExtension(extension1_->id(), 1470 extension_service_->UnloadExtension(extension1_->id(),
1223 UnloadedExtensionInfo::REASON_UNINSTALL); 1471 UnloadedExtensionInfo::REASON_UNINSTALL);
1224 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); 1472 EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus());
1225 1473
1226 extension_service_->UnloadExtension(extension2_->id(), 1474 extension_service_->UnloadExtension(extension2_->id(),
1227 UnloadedExtensionInfo::REASON_UNINSTALL); 1475 UnloadedExtensionInfo::REASON_UNINSTALL);
1228 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1476 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1675 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1428 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1676 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1429 launcher_controller_->UnlockV1AppWithID(extension3_->id()); 1677 launcher_controller_->UnlockV1AppWithID(extension3_->id());
1430 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1678 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1431 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1679 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1432 } 1680 }
1433 1681
1434 TEST_F(ChromeLauncherControllerTest, ArcDeferredLaunch) { 1682 TEST_F(ChromeLauncherControllerTest, ArcDeferredLaunch) {
1435 arc_test_.SetUp(profile()); 1683 arc_test_.SetUp(profile());
1436 1684
1437 launcher_controller_.reset( 1685 RecreateChromeLauncher();
1438 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1439 launcher_controller_->Init();
1440 1686
1441 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0]; 1687 const arc::mojom::AppInfo& app1 = arc_test_.fake_apps()[0];
1442 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1]; 1688 const arc::mojom::AppInfo& app2 = arc_test_.fake_apps()[1];
1443 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2]; 1689 const arc::mojom::AppInfo& app3 = arc_test_.fake_apps()[2];
1444 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1); 1690 const std::string arc_app_id1 = ArcAppTest::GetAppId(app1);
1445 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2); 1691 const std::string arc_app_id2 = ArcAppTest::GetAppId(app2);
1446 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3); 1692 const std::string arc_app_id3 = ArcAppTest::GetAppId(app3);
1447 1693
1448 SendListOfArcApps(); 1694 SendListOfArcApps();
1449 1695
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 launcher_controller_->UnpinAppWithID(extension1_->id()); 2045 launcher_controller_->UnpinAppWithID(extension1_->id());
1800 2046
1801 EXPECT_EQ(2, model_->item_count()); 2047 EXPECT_EQ(2, model_->item_count());
1802 } 2048 }
1803 2049
1804 // Check that a locked (windowed V1 application) will be properly converted 2050 // Check that a locked (windowed V1 application) will be properly converted
1805 // between locked and pinned when the order gets changed through a profile / 2051 // between locked and pinned when the order gets changed through a profile /
1806 // policy change. 2052 // policy change.
1807 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) { 2053 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) {
1808 InitLauncherController(); 2054 InitLauncherController();
1809 base::ListValue policy_value0; 2055
1810 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2056 syncer::SyncChangeList sync_list;
1811 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2057 InsertAddPinChange(&sync_list, 0, extension1_->id());
1812 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2058 InsertAddPinChange(&sync_list, 1, extension3_->id());
1813 policy_value0.DeepCopy()); 2059 SendPinChanges(sync_list, true);
2060
1814 // The shelf layout has always one static item at the beginning (App List). 2061 // The shelf layout has always one static item at the beginning (App List).
1815 SetShelfChromeIconIndex(0);
1816 extension_service_->AddExtension(extension1_.get()); 2062 extension_service_->AddExtension(extension1_.get());
1817 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2063 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1818 extension_service_->AddExtension(extension2_.get()); 2064 extension_service_->AddExtension(extension2_.get());
1819 // No new app icon will be generated. 2065 // No new app icon will be generated.
1820 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2066 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
2067
1821 // Add the app as locked app which will add it (un-pinned). 2068 // Add the app as locked app which will add it (un-pinned).
1822 launcher_controller_->LockV1AppWithID(extension2_->id()); 2069 launcher_controller_->LockV1AppWithID(extension2_->id());
1823 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); 2070 EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus());
1824 extension_service_->AddExtension(extension3_.get()); 2071 extension_service_->AddExtension(extension3_.get());
1825 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); 2072 EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus());
1826 2073
1827 // Now request to pin all items which should convert the locked item into a 2074 // Now request to pin all items which should convert the locked item into a
1828 // pinned item. 2075 // pinned item.
1829 base::ListValue policy_value1; 2076 syncer::SyncChangeList sync_list1;
1830 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2077 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1831 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2078 InsertAddPinChange(&sync_list1, 1, extension2_->id());
1832 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2079 InsertAddPinChange(&sync_list1, 2, extension1_->id());
1833 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2080 SendPinChanges(sync_list1, true);
1834 policy_value1.DeepCopy());
1835 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2081 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1836 2082
1837 // Going back to a status where there is no requirement for app 2 to be pinned 2083 // 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 2084 // 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 2085 // 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 2086 // applications are not allowed to be mixed with shortcuts, it should show up
1841 // at the end of the list. 2087 // at the end of the list.
1842 base::ListValue policy_value2; 2088 syncer::SyncChangeList sync_list2;
1843 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2089 InsertAddPinChange(&sync_list2, 0, extension3_->id());
1844 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2090 InsertAddPinChange(&sync_list2, 1, extension1_->id());
1845 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2091 SendPinChanges(sync_list2, true);
1846 policy_value2.DeepCopy());
1847 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); 2092 EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus());
1848 2093
1849 // Removing an item should simply close it and everything should shift. 2094 // Removing an item should simply close it and everything should shift.
1850 base::ListValue policy_value3; 2095 SendPinChanges(syncer::SyncChangeList(), true);
1851 InsertPrefValue(&policy_value3, 0, extension3_->id());
1852 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1853 policy_value3.DeepCopy());
1854 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus()); 2096 EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus());
1855 } 2097 }
1856 2098
1857 // Check that a running and not pinned V2 application will be properly converted 2099 // 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 / 2100 // between locked and pinned when the order gets changed through a profile /
1859 // policy change. 2101 // policy change.
1860 TEST_F(ChromeLauncherControllerTest, 2102 TEST_F(ChromeLauncherControllerTest,
1861 RestoreDefaultAndRunningV2AppsResyncOrder) { 2103 RestoreDefaultAndRunningV2AppsResyncOrder) {
1862 InitLauncherController(); 2104 InitLauncherController();
1863 base::ListValue policy_value0; 2105 syncer::SyncChangeList sync_list0;
1864 InsertPrefValue(&policy_value0, 0, extension1_->id()); 2106 InsertAddPinChange(&sync_list0, 0, extension1_->id());
1865 InsertPrefValue(&policy_value0, 1, extension3_->id()); 2107 InsertAddPinChange(&sync_list0, 1, extension3_->id());
1866 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2108 SendPinChanges(sync_list0, true);
1867 policy_value0.DeepCopy());
1868 // The shelf layout has always one static item at the beginning (app List). 2109 // The shelf layout has always one static item at the beginning (app List).
1869 SetShelfChromeIconIndex(0);
1870 extension_service_->AddExtension(extension1_.get()); 2110 extension_service_->AddExtension(extension1_.get());
1871 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2111 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1872 extension_service_->AddExtension(extension2_.get()); 2112 extension_service_->AddExtension(extension2_.get());
1873 // No new app icon will be generated. 2113 // No new app icon will be generated.
1874 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 2114 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
1875 // Add the app as an unpinned but running V2 app. 2115 // Add the app as an unpinned but running V2 app.
1876 CreateRunningV2App(extension2_->id()); 2116 CreateRunningV2App(extension2_->id());
1877 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); 2117 EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus());
1878 extension_service_->AddExtension(extension3_.get()); 2118 extension_service_->AddExtension(extension3_.get());
1879 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); 2119 EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus());
1880 2120
1881 // Now request to pin all items which should convert the locked item into a 2121 // Now request to pin all items which should convert the locked item into a
1882 // pinned item. 2122 // pinned item.
1883 base::ListValue policy_value1; 2123 syncer::SyncChangeList sync_list1;
1884 InsertPrefValue(&policy_value1, 0, extension3_->id()); 2124 InsertAddPinChange(&sync_list1, 0, extension3_->id());
1885 InsertPrefValue(&policy_value1, 1, extension2_->id()); 2125 InsertAddPinChange(&sync_list1, 1, extension2_->id());
1886 InsertPrefValue(&policy_value1, 2, extension1_->id()); 2126 InsertAddPinChange(&sync_list1, 2, extension1_->id());
1887 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2127 SendPinChanges(sync_list1, true);
1888 policy_value1.DeepCopy());
1889 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 2128 EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
1890 2129
1891 // Going back to a status where there is no requirement for app 2 to be pinned 2130 // 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 2131 // 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. 2132 // by the |ShelfModel|'s weight system, it will be after last pinned item.
1894 base::ListValue policy_value2; 2133 syncer::SyncChangeList sync_list2;
1895 InsertPrefValue(&policy_value2, 0, extension3_->id()); 2134 InsertAddPinChange(&sync_list2, 0, extension3_->id());
1896 InsertPrefValue(&policy_value2, 1, extension1_->id()); 2135 InsertAddPinChange(&sync_list2, 1, extension1_->id());
1897 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2136 SendPinChanges(sync_list2, true);
1898 policy_value2.DeepCopy());
1899 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); 2137 EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus());
1900 2138
1901 // Removing an item should simply close it and everything should shift. 2139 // Removing an item should simply close it and everything should shift.
1902 base::ListValue policy_value3; 2140 syncer::SyncChangeList sync_list3;
1903 InsertPrefValue(&policy_value3, 0, extension3_->id()); 2141 InsertAddPinChange(&sync_list3, 0, extension3_->id());
1904 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2142 SendPinChanges(sync_list3, true);
1905 policy_value3.DeepCopy());
1906 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); 2143 EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus());
1907 } 2144 }
1908 2145
1909 // Each user has a different set of applications pinned. Check that when 2146 // Each user has a different set of applications pinned. Check that when
1910 // switching between the two users, the state gets properly set. 2147 // switching between the two users, the state gets properly set.
1911 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) { 2148 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) {
1912 base::ListValue user_a; 2149 syncer::SyncChangeList user_a;
1913 base::ListValue user_b; 2150 syncer::SyncChangeList user_b;
1914 SetUpMultiUserScenario(&user_a, &user_b); 2151 SetUpMultiUserScenario(&user_a, &user_b);
2152
1915 // Show user 1. 2153 // Show user 1.
1916 SetShelfChromeIconIndex(6); 2154 SendPinChanges(user_a, true);
1917 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1918 user_a.DeepCopy());
1919 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2155 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1920 GetPinnedAppStatus()); 2156 GetPinnedAppStatus());
1921 2157
1922 // Show user 2. 2158 // Show user 2.
1923 SetShelfChromeIconIndex(4); 2159 SendPinChanges(user_b, true);
1924 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1925 user_b.DeepCopy());
1926
1927 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2160 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1928 2161
1929 // Switch back to 1. 2162 // Switch back to 1.
1930 SetShelfChromeIconIndex(8); 2163 SendPinChanges(user_a, true);
1931 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1932 user_a.DeepCopy());
1933 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2164 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1934 GetPinnedAppStatus()); 2165 GetPinnedAppStatus());
1935 2166
1936 // Switch back to 2. 2167 // Switch back to 2.
1937 SetShelfChromeIconIndex(4); 2168 SendPinChanges(user_b, true);
1938 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1939 user_b.DeepCopy());
1940 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 2169 EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
1941 } 2170 }
1942 2171
1943 // Each user has a different set of applications pinned, and one user has an 2172 // 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 2173 // application running. Check that when switching between the two users, the
1945 // state gets properly set. 2174 // state gets properly set.
1946 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) { 2175 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) {
1947 base::ListValue user_a; 2176 syncer::SyncChangeList user_a;
1948 base::ListValue user_b; 2177 syncer::SyncChangeList user_b;
1949 SetUpMultiUserScenario(&user_a, &user_b); 2178 SetUpMultiUserScenario(&user_a, &user_b);
1950 2179
1951 // Run App1 and assume that it is a V2 app. 2180 // Run App1 and assume that it is a V2 app.
1952 CreateRunningV2App(extension1_->id()); 2181 CreateRunningV2App(extension1_->id());
1953 2182
1954 // Show user 1. 2183 // Show user 1.
1955 SetShelfChromeIconIndex(6); 2184 SendPinChanges(user_a, true);
1956 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1957 user_a.DeepCopy());
1958 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2185 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1959 GetPinnedAppStatus()); 2186 GetPinnedAppStatus());
1960 2187
1961 // Show user 2. 2188 // Show user 2.
1962 SetShelfChromeIconIndex(4); 2189 SendPinChanges(user_b, true);
1963 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1964 user_b.DeepCopy());
1965
1966 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2190 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1967 2191
1968 // Switch back to 1. 2192 // Switch back to 1.
1969 SetShelfChromeIconIndex(8); 2193 SendPinChanges(user_a, true);
1970 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1971 user_a.DeepCopy());
1972 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 2194 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
1973 GetPinnedAppStatus()); 2195 GetPinnedAppStatus());
1974 2196
1975 // Switch back to 2. 2197 // Switch back to 2.
1976 SetShelfChromeIconIndex(4); 2198 SendPinChanges(user_b, true);
1977 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1978 user_b.DeepCopy());
1979 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2199 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
1980 } 2200 }
1981 2201
1982 // Each user has a different set of applications pinned, and one user has an 2202 // 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. 2203 // 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. 2204 // Check that when switching between the two users, the state gets properly set.
1985 // There was once a bug associated with this. 2205 // There was once a bug associated with this.
1986 TEST_F(ChromeLauncherControllerTest, 2206 TEST_F(ChromeLauncherControllerTest,
1987 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { 2207 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) {
1988 base::ListValue user_a; 2208 syncer::SyncChangeList user_a;
1989 base::ListValue user_b; 2209 syncer::SyncChangeList user_b;
1990 SetUpMultiUserScenario(&user_a, &user_b); 2210 SetUpMultiUserScenario(&user_a, &user_b);
1991 2211
1992 // Run App1 and assume that it is a V2 app. 2212 // Run App1 and assume that it is a V2 app.
1993 CreateRunningV2App(extension1_->id()); 2213 CreateRunningV2App(extension1_->id());
1994 2214
1995 // Show user 1. 2215 // Show user 1.
2216 SendPinChanges(user_a, true);
1996 SetShelfChromeIconIndex(5); 2217 SetShelfChromeIconIndex(5);
1997 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1998 user_a.DeepCopy());
1999 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2218 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2000 GetPinnedAppStatus()); 2219 GetPinnedAppStatus());
2001 2220
2002 // Show user 2. 2221 // Show user 2.
2222 SendPinChanges(user_b, true);
2003 SetShelfChromeIconIndex(4); 2223 SetShelfChromeIconIndex(4);
2004 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2005 user_b.DeepCopy());
2006
2007 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 2224 EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
2008 2225
2009 // Switch back to 1. 2226 // Switch back to 1.
2227 SendPinChanges(user_a, true);
2010 SetShelfChromeIconIndex(5); 2228 SetShelfChromeIconIndex(5);
2011 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2012 user_a.DeepCopy());
2013 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 2229 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
2014 GetPinnedAppStatus()); 2230 GetPinnedAppStatus());
2015 } 2231 }
2016 2232
2017 TEST_F(ChromeLauncherControllerTest, Policy) { 2233 TEST_F(ChromeLauncherControllerTest, Policy) {
2018 extension_service_->AddExtension(extension1_.get()); 2234 extension_service_->AddExtension(extension1_.get());
2019 extension_service_->AddExtension(extension3_.get()); 2235 extension_service_->AddExtension(extension3_.get());
2020 2236
2237 InitLauncherController();
2238
2239 syncer::SyncChangeList sync_list;
2240 InsertAddPinChange(&sync_list, 0, extension_misc::kChromeAppId);
2241 SendPinChanges(sync_list, true);
2242
2021 base::ListValue policy_value; 2243 base::ListValue policy_value;
2022 InsertPrefValue(&policy_value, 0, extension1_->id()); 2244 InsertPrefValue(&policy_value, 0, extension1_->id());
2023 InsertPrefValue(&policy_value, 1, extension2_->id()); 2245 InsertPrefValue(&policy_value, 1, extension2_->id());
2024 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2246 profile()->GetTestingPrefService()->SetManagedPref(
2025 policy_value.DeepCopy()); 2247 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2026 2248
2027 // Only |extension1_| should get pinned. |extension2_| is specified but not 2249 // Only |extension1_| should get pinned. |extension2_| is specified but not
2028 // installed, and |extension3_| is part of the default set, but that shouldn't 2250 // installed, and |extension3_| is part of the default set, but that shouldn't
2029 // take effect when the policy override is in place. 2251 // take effect when the policy override is in place.
2030 InitLauncherController(); 2252 ASSERT_EQ(3, model_->item_count());
2031 EXPECT_EQ(3, model_->item_count());
2032 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2253 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2033 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2254 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2034 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2255 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2035 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2256 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2036 2257
2037 // Installing |extension2_| should add it to the launcher. 2258 // Installing |extension2_| should add it to the launcher.
2038 extension_service_->AddExtension(extension2_.get()); 2259 extension_service_->AddExtension(extension2_.get());
2039 EXPECT_EQ(4, model_->item_count()); 2260 ASSERT_EQ(4, model_->item_count());
2040 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2261 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2041 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); 2262 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type);
2042 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2263 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2043 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2264 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2044 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2265 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2045 2266
2046 // Removing |extension1_| from the policy should be reflected in the launcher. 2267 // Removing |extension1_| from the policy should not be reflected in the
2268 // launcher and pin will exist.
2047 policy_value.Remove(0, NULL); 2269 policy_value.Remove(0, NULL);
2048 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 2270 profile()->GetTestingPrefService()->SetManagedPref(
2049 policy_value.DeepCopy()); 2271 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
2050 EXPECT_EQ(3, model_->item_count()); 2272 EXPECT_EQ(4, model_->item_count());
2051 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2273 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2052 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 2274 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2053 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2275 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2054 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2276 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2055 } 2277 }
2056 2278
2057 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { 2279 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
2058 extension_service_->AddExtension(extension3_.get()); 2280 extension_service_->AddExtension(extension3_.get());
2059 extension_service_->AddExtension(extension4_.get()); 2281 extension_service_->AddExtension(extension4_.get());
2060 2282
2061 InitLauncherController(); 2283 InitLauncherController();
2062 2284
2063 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2285 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2064 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2286 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2065 2287
2066 extension_service_->UnloadExtension(extension3_->id(), 2288 extension_service_->UnloadExtension(extension3_->id(),
2067 UnloadedExtensionInfo::REASON_UNINSTALL); 2289 UnloadedExtensionInfo::REASON_UNINSTALL);
2068 2290
2069 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2291 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2070 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 2292 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
2071 } 2293 }
2072 2294
2073 TEST_F(ChromeLauncherControllerTest, PrefUpdates) { 2295 TEST_F(ChromeLauncherControllerTest, SyncUpdates) {
2074 extension_service_->AddExtension(extension2_.get()); 2296 extension_service_->AddExtension(extension2_.get());
2075 extension_service_->AddExtension(extension3_.get()); 2297 extension_service_->AddExtension(extension3_.get());
2076 extension_service_->AddExtension(extension4_.get()); 2298 extension_service_->AddExtension(extension4_.get());
2077 2299
2078 InitLauncherController(); 2300 InitLauncherController();
2079 2301
2302 syncer::SyncChangeList sync_list;
2303 InsertAddPinChange(&sync_list, 10, extension_misc::kChromeAppId);
2304 SendPinChanges(sync_list, true);
2305
2080 std::vector<std::string> expected_launchers; 2306 std::vector<std::string> expected_launchers;
2081 std::vector<std::string> actual_launchers; 2307 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); 2308 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2086 EXPECT_EQ(expected_launchers, actual_launchers); 2309 EXPECT_EQ(expected_launchers, actual_launchers);
2087 2310
2088 // Unavailable extensions don't create launcher items. 2311 // Unavailable extensions don't create launcher items.
2089 InsertPrefValue(&pref_value, 0, extension1_->id()); 2312 sync_list.clear();
2090 InsertPrefValue(&pref_value, 1, extension2_->id()); 2313 InsertAddPinChange(&sync_list, 0, extension1_->id());
2091 InsertPrefValue(&pref_value, 2, extension4_->id()); 2314 InsertAddPinChange(&sync_list, 1, extension2_->id());
2092 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2315 InsertAddPinChange(&sync_list, 3, extension4_->id());
2093 pref_value.DeepCopy()); 2316 SendPinChanges(sync_list, false);
2317
2094 expected_launchers.push_back(extension2_->id()); 2318 expected_launchers.push_back(extension2_->id());
2095 expected_launchers.push_back(extension4_->id()); 2319 expected_launchers.push_back(extension4_->id());
2096 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2320 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2097 EXPECT_EQ(expected_launchers, actual_launchers); 2321 EXPECT_EQ(expected_launchers, actual_launchers);
2098 2322
2099 // Redundant pref entries show up only once. 2323 sync_list.clear();
2100 InsertPrefValue(&pref_value, 2, extension3_->id()); 2324 InsertAddPinChange(&sync_list, 2, extension3_->id());
2101 InsertPrefValue(&pref_value, 2, extension3_->id()); 2325 SendPinChanges(sync_list, false);
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()); 2326 expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id());
2106 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2327 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2107 EXPECT_EQ(expected_launchers, actual_launchers); 2328 EXPECT_EQ(expected_launchers, actual_launchers);
2108 2329
2109 // Order changes are reflected correctly. 2330 sync_list.clear();
2110 pref_value.Clear(); 2331 InsertUpdatePinChange(&sync_list, 0, extension4_->id());
2111 InsertPrefValue(&pref_value, 0, extension4_->id()); 2332 InsertUpdatePinChange(&sync_list, 1, extension3_->id());
2112 InsertPrefValue(&pref_value, 1, extension3_->id()); 2333 InsertUpdatePinChange(&sync_list, 2, extension2_->id());
2113 InsertPrefValue(&pref_value, 2, extension2_->id()); 2334 SendPinChanges(sync_list, false);
2114 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
2115 pref_value.DeepCopy());
2116 std::reverse(expected_launchers.begin(), expected_launchers.end()); 2335 std::reverse(expected_launchers.begin(), expected_launchers.end());
2117 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2336 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2118 EXPECT_EQ(expected_launchers, actual_launchers); 2337 EXPECT_EQ(expected_launchers, actual_launchers);
2119 2338
2120 // Clearing works. 2339 sync_list.clear();
2121 pref_value.Clear(); 2340 InsertRemovePinChange(&sync_list, extension4_->id());
2122 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2341 SendPinChanges(sync_list, false);
2123 pref_value.DeepCopy()); 2342
2343 expected_launchers.erase(expected_launchers.begin());
2344 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2345 EXPECT_EQ(expected_launchers, actual_launchers);
2346
2347 sync_list.clear();
2348 InsertRemovePinChange(&sync_list, extension3_->id());
2349 InsertRemovePinChange(&sync_list, extension2_->id());
2350 SendPinChanges(sync_list, false);
2124 expected_launchers.clear(); 2351 expected_launchers.clear();
2125 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2352 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2126 EXPECT_EQ(expected_launchers, actual_launchers); 2353 EXPECT_EQ(expected_launchers, actual_launchers);
2127 } 2354 }
2128 2355
2129 TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) { 2356 TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) {
2130 extension_service_->AddExtension(extension1_.get()); 2357 extension_service_->AddExtension(extension1_.get());
2131 extension_service_->AddExtension(extension3_.get()); 2358 extension_service_->AddExtension(extension3_.get());
2132 2359
2133 InitLauncherController(); 2360 InitLauncherController();
2134 2361
2135 base::ListValue pref_value; 2362 syncer::SyncChangeList sync_list;
2136 InsertPrefValue(&pref_value, 0, extension1_->id()); 2363 InsertAddPinChange(&sync_list, 0, extension1_->id());
2137 InsertPrefValue(&pref_value, 1, extension2_->id()); 2364 InsertAddPinChange(&sync_list, 1, extension2_->id());
2138 InsertPrefValue(&pref_value, 2, extension3_->id()); 2365 InsertAddPinChange(&sync_list, 2, extension3_->id());
2139 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 2366 SendPinChanges(sync_list, true);
2140 pref_value.DeepCopy());
2141 2367
2142 std::vector<std::string> expected_launchers; 2368 std::vector<std::string> expected_launchers;
2143 expected_launchers.push_back(extension1_->id()); 2369 expected_launchers.push_back(extension1_->id());
2144 expected_launchers.push_back(extension3_->id()); 2370 expected_launchers.push_back(extension3_->id());
2145 std::vector<std::string> actual_launchers; 2371 std::vector<std::string> actual_launchers;
2146 2372
2147 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2373 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2148 EXPECT_EQ(expected_launchers, actual_launchers); 2374 EXPECT_EQ(expected_launchers, actual_launchers);
2149 2375
2150 // Install |extension2| and verify it shows up between the other two. 2376 // Install |extension2| and verify it shows up between the other two.
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2888 } else { 3114 } else {
2889 // Clear already registered ShelfItemDelegate. 3115 // Clear already registered ShelfItemDelegate.
2890 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3116 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2891 test.RemoveAllShelfItemDelegateForTest(); 3117 test.RemoveAllShelfItemDelegateForTest();
2892 } 3118 }
2893 model_.reset(new ash::ShelfModel); 3119 model_.reset(new ash::ShelfModel);
2894 3120
2895 AddAppListLauncherItem(); 3121 AddAppListLauncherItem();
2896 launcher_controller_.reset( 3122 launcher_controller_.reset(
2897 ChromeLauncherController::CreateInstance(profile(), model_.get())); 3123 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2898 helper = new TestLauncherControllerHelper; 3124 helper = new TestLauncherControllerHelper(profile());
2899 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3125 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2900 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3126 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
2901 SetLauncherControllerHelper(helper); 3127 SetLauncherControllerHelper(helper);
2902 if (!ash::Shell::HasInstance()) { 3128 if (!ash::Shell::HasInstance()) {
2903 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3129 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2904 SetShelfItemDelegateManager(item_delegate_manager_); 3130 SetShelfItemDelegateManager(item_delegate_manager_);
2905 } 3131 }
2906 launcher_controller_->Init(); 3132 launcher_controller_->Init();
2907 3133
2908 // Check ShelfItems are restored after resetting ChromeLauncherController. 3134 // Check ShelfItems are restored after resetting ChromeLauncherController.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2946 } else { 3172 } else {
2947 // Clear already registered ShelfItemDelegate. 3173 // Clear already registered ShelfItemDelegate.
2948 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 3174 ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
2949 test.RemoveAllShelfItemDelegateForTest(); 3175 test.RemoveAllShelfItemDelegateForTest();
2950 } 3176 }
2951 model_.reset(new ash::ShelfModel); 3177 model_.reset(new ash::ShelfModel);
2952 3178
2953 AddAppListLauncherItem(); 3179 AddAppListLauncherItem();
2954 launcher_controller_.reset( 3180 launcher_controller_.reset(
2955 ChromeLauncherController::CreateInstance(profile(), model_.get())); 3181 ChromeLauncherController::CreateInstance(profile(), model_.get()));
2956 helper = new TestLauncherControllerHelper; 3182 helper = new TestLauncherControllerHelper(profile());
2957 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3183 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2958 SetLauncherControllerHelper(helper); 3184 SetLauncherControllerHelper(helper);
2959 // app_icon_loader is owned by ChromeLauncherController. 3185 // app_icon_loader is owned by ChromeLauncherController.
2960 app_icon_loader = new TestAppIconLoaderImpl; 3186 app_icon_loader = new TestAppIconLoaderImpl;
2961 app_icon_loader->AddSupportedApp("1"); 3187 app_icon_loader->AddSupportedApp("1");
2962 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3188 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
2963 if (!ash::Shell::HasInstance()) { 3189 if (!ash::Shell::HasInstance()) {
2964 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 3190 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2965 SetShelfItemDelegateManager(item_delegate_manager_); 3191 SetShelfItemDelegateManager(item_delegate_manager_);
2966 } 3192 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3068 // by hash we can determine that appropriate package was set by policy. 3294 // by hash we can determine that appropriate package was set by policy.
3069 base::ListValue policy_value; 3295 base::ListValue policy_value;
3070 InsertPrefValue(&policy_value, 0, appinfo.package_name); 3296 InsertPrefValue(&policy_value, 0, appinfo.package_name);
3071 profile()->GetTestingPrefService()->SetManagedPref( 3297 profile()->GetTestingPrefService()->SetManagedPref(
3072 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); 3298 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy());
3073 3299
3074 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 3300 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
3075 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED, 3301 EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
3076 launcher_controller_->GetPinnable(app_id)); 3302 launcher_controller_->GetPinnable(app_id));
3077 } 3303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698