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

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

Powered by Google App Engine
This is Rietveld 408576698