| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/sync/test/integration/sync_arc_package_helper.h" | 5 #include "chrome/browser/sync/test/integration/sync_arc_package_helper.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | |
| 14 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" | |
| 15 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
| 16 #include "chrome/browser/chromeos/arc/arc_util.h" | 13 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
| 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 15 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 22 #include "chrome/browser/sync/test/integration/sync_test.h" | 16 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 23 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 17 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | |
| 25 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h" | 18 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h" |
| 26 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/arc/arc_bridge_service.h" | |
| 28 #include "components/arc/test/fake_app_instance.h" | 20 #include "components/arc/test/fake_app_instance.h" |
| 29 | 21 |
| 30 namespace arc { | 22 namespace arc { |
| 31 | 23 |
| 32 namespace { | 24 namespace { |
| 33 | 25 |
| 34 std::string GetTestPackageName(size_t id) { | 26 std::string GetTestPackageName(size_t id) { |
| 35 return "testarcpackage" + base::SizeTToString(id); | 27 return "testarcpackage" + base::SizeTToString(id); |
| 36 } | 28 } |
| 37 | 29 |
| 38 chromeos::FakeChromeUserManager* GetUserManager() { | |
| 39 return static_cast<chromeos::FakeChromeUserManager*>( | |
| 40 user_manager::UserManager::Get()); | |
| 41 } | |
| 42 | |
| 43 const user_manager::User* CreateUserAndLogin(Profile* profile, size_t id) { | |
| 44 std::string gaia_id = "1234567890" + base::SizeTToString(id); | |
| 45 const AccountId account_id( | |
| 46 AccountId::FromUserEmailGaiaId(profile->GetProfileUserName(), gaia_id)); | |
| 47 const user_manager::User* user = GetUserManager()->AddUser(account_id); | |
| 48 GetUserManager()->LoginUser(account_id); | |
| 49 return user; | |
| 50 } | |
| 51 | |
| 52 } // namespace | 30 } // namespace |
| 53 | 31 |
| 54 SyncArcPackageHelper* SyncArcPackageHelper::GetInstance() { | 32 SyncArcPackageHelper* SyncArcPackageHelper::GetInstance() { |
| 55 SyncArcPackageHelper* instance = base::Singleton<SyncArcPackageHelper>::get(); | 33 SyncArcPackageHelper* instance = base::Singleton<SyncArcPackageHelper>::get(); |
| 56 DCHECK(sync_datatype_helper::test()); | 34 DCHECK(sync_datatype_helper::test()); |
| 57 instance->SetupTest(sync_datatype_helper::test()); | 35 instance->SetupTest(sync_datatype_helper::test()); |
| 58 return instance; | 36 return instance; |
| 59 } | 37 } |
| 60 | 38 |
| 61 SyncArcPackageHelper::SyncArcPackageHelper() | 39 SyncArcPackageHelper::SyncArcPackageHelper() |
| 62 : test_(nullptr), setup_completed_(false), user_manager_enabler_(nullptr) {} | 40 : test_(nullptr), setup_completed_(false) {} |
| 63 | 41 |
| 64 SyncArcPackageHelper::~SyncArcPackageHelper() {} | 42 SyncArcPackageHelper::~SyncArcPackageHelper() {} |
| 65 | 43 |
| 66 void SyncArcPackageHelper::SetupTest(SyncTest* test) { | 44 void SyncArcPackageHelper::SetupTest(SyncTest* test) { |
| 67 if (setup_completed_) { | 45 if (setup_completed_) { |
| 68 DCHECK_EQ(test, test_); | 46 DCHECK_EQ(test, test_); |
| 69 return; | 47 return; |
| 70 } | 48 } |
| 71 test_ = test; | 49 test_ = test; |
| 72 | 50 |
| 73 user_manager_enabler_ = base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | |
| 74 new chromeos::FakeChromeUserManager()); | |
| 75 ArcAppListPrefsFactory::SetFactoryForSyncTest(); | |
| 76 size_t id = 0; | |
| 77 for (auto* profile : test_->GetAllProfiles()) | 51 for (auto* profile : test_->GetAllProfiles()) |
| 78 SetupArcService(profile, id++); | 52 SetupArcService(profile); |
| 79 setup_completed_ = true; | 53 setup_completed_ = true; |
| 80 } | 54 } |
| 81 | 55 |
| 82 void SyncArcPackageHelper::CleanUp() { | |
| 83 ArcSessionManager::Get()->Shutdown(); | |
| 84 user_manager_enabler_.reset(); | |
| 85 } | |
| 86 | |
| 87 void SyncArcPackageHelper::InstallPackageWithIndex(Profile* profile, | 56 void SyncArcPackageHelper::InstallPackageWithIndex(Profile* profile, |
| 88 size_t id) { | 57 size_t id) { |
| 89 std::string package_name = GetTestPackageName(id); | 58 std::string package_name = GetTestPackageName(id); |
| 90 | 59 |
| 91 mojom::ArcPackageInfo package; | 60 mojom::ArcPackageInfo package; |
| 92 package.package_name = package_name; | 61 package.package_name = package_name; |
| 93 package.package_version = id; | 62 package.package_version = id; |
| 94 package.last_backup_android_id = id; | 63 package.last_backup_android_id = id; |
| 95 package.last_backup_time = id; | 64 package.last_backup_time = id; |
| 96 package.sync = true; | 65 package.sync = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 !ArcPackageDetailsMatch(profiles.front(), profile)) { | 106 !ArcPackageDetailsMatch(profiles.front(), profile)) { |
| 138 DVLOG(1) << "Profile1: " << ArcPackageSyncableService::Get(profile); | 107 DVLOG(1) << "Profile1: " << ArcPackageSyncableService::Get(profile); |
| 139 DVLOG(1) << "Profile2: " | 108 DVLOG(1) << "Profile2: " |
| 140 << ArcPackageSyncableService::Get(profiles.front()); | 109 << ArcPackageSyncableService::Get(profiles.front()); |
| 141 return false; | 110 return false; |
| 142 } | 111 } |
| 143 } | 112 } |
| 144 return true; | 113 return true; |
| 145 } | 114 } |
| 146 | 115 |
| 147 void SyncArcPackageHelper::SetupArcService(Profile* profile, size_t id) { | 116 void SyncArcPackageHelper::SetupArcService(Profile* profile) { |
| 148 DCHECK(profile); | 117 DCHECK(profile); |
| 149 const user_manager::User* user = CreateUserAndLogin(profile, id); | |
| 150 // Have the user-to-profile mapping ready to avoid using the real profile | |
| 151 // manager (which is null). | |
| 152 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | |
| 153 profile); | |
| 154 | |
| 155 ArcSessionManager::DisableUIForTesting(); | |
| 156 ArcAuthNotification::DisableForTesting(); | |
| 157 arc::ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile); | |
| 158 arc::SetArcPlayStoreEnabledForProfile(profile, true); | 118 arc::SetArcPlayStoreEnabledForProfile(profile, true); |
| 159 | 119 |
| 160 ArcAppListPrefs* arc_app_list_prefs = ArcAppListPrefs::Get(profile); | 120 ArcAppListPrefs* arc_app_list_prefs = ArcAppListPrefs::Get(profile); |
| 161 DCHECK(arc_app_list_prefs); | 121 DCHECK(arc_app_list_prefs); |
| 162 | 122 |
| 163 base::RunLoop run_loop; | 123 base::RunLoop run_loop; |
| 164 arc_app_list_prefs->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); | 124 arc_app_list_prefs->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); |
| 165 run_loop.Run(); | 125 run_loop.Run(); |
| 166 | 126 |
| 167 instance_map_[profile] = | 127 instance_map_[profile] = |
| 168 base::MakeUnique<FakeAppInstance>(arc_app_list_prefs); | 128 base::MakeUnique<FakeAppInstance>(arc_app_list_prefs); |
| 169 DCHECK(instance_map_[profile].get()); | 129 DCHECK(instance_map_[profile].get()); |
| 130 arc_app_list_prefs->app_instance_holder()->SetInstance(nullptr); |
| 170 arc_app_list_prefs->app_instance_holder()->SetInstance( | 131 arc_app_list_prefs->app_instance_holder()->SetInstance( |
| 171 instance_map_[profile].get()); | 132 instance_map_[profile].get()); |
| 172 // OnPackageListRefreshed will be called when AppInstance is ready. | 133 // OnPackageListRefreshed will be called when AppInstance is ready. |
| 173 // For fakeAppInstance we use SendRefreshPackageList to make sure that | 134 // For fakeAppInstance we use SendRefreshPackageList to make sure that |
| 174 // OnPackageListRefreshed will be called. | 135 // OnPackageListRefreshed will be called. |
| 175 instance_map_[profile]->SendRefreshPackageList( | 136 instance_map_[profile]->SendRefreshPackageList( |
| 176 std::vector<arc::mojom::ArcPackageInfo>()); | 137 std::vector<arc::mojom::ArcPackageInfo>()); |
| 177 } | 138 } |
| 178 | 139 |
| 179 void SyncArcPackageHelper::InstallPackage( | 140 void SyncArcPackageHelper::InstallPackage( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if (package1_info->last_backup_android_id != | 207 if (package1_info->last_backup_android_id != |
| 247 package2_info->last_backup_android_id) | 208 package2_info->last_backup_android_id) |
| 248 return false; | 209 return false; |
| 249 if (package1_info->last_backup_time != package2_info->last_backup_time) | 210 if (package1_info->last_backup_time != package2_info->last_backup_time) |
| 250 return false; | 211 return false; |
| 251 } | 212 } |
| 252 return true; | 213 return true; |
| 253 } | 214 } |
| 254 | 215 |
| 255 } // namespace arc | 216 } // namespace arc |
| OLD | NEW |