Chromium Code Reviews| 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_session_manager.h" | |
| 14 #include "chrome/browser/chromeos/arc/arc_util.h" | 13 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
| 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 15 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 20 #include "chrome/browser/sync/test/integration/sync_test.h" | 16 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 21 #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" |
| 22 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | |
| 23 #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" |
| 24 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 25 #include "components/arc/arc_bridge_service.h" | |
| 26 #include "components/arc/test/fake_app_instance.h" | 20 #include "components/arc/test/fake_app_instance.h" |
| 27 | 21 |
| 28 namespace arc { | 22 namespace arc { |
| 29 | 23 |
| 30 namespace { | 24 namespace { |
| 31 | 25 |
| 32 std::string GetTestPackageName(size_t id) { | 26 std::string GetTestPackageName(size_t id) { |
| 33 return "testarcpackage" + base::SizeTToString(id); | 27 return "testarcpackage" + base::SizeTToString(id); |
| 34 } | 28 } |
| 35 | 29 |
| 36 chromeos::FakeChromeUserManager* GetUserManager() { | |
| 37 return static_cast<chromeos::FakeChromeUserManager*>( | |
| 38 user_manager::UserManager::Get()); | |
| 39 } | |
| 40 | |
| 41 const user_manager::User* CreateUserAndLogin(Profile* profile, size_t id) { | |
| 42 std::string gaia_id = "1234567890" + base::SizeTToString(id); | |
| 43 const AccountId account_id( | |
| 44 AccountId::FromUserEmailGaiaId(profile->GetProfileUserName(), gaia_id)); | |
| 45 const user_manager::User* user = GetUserManager()->AddUser(account_id); | |
| 46 GetUserManager()->LoginUser(account_id); | |
| 47 return user; | |
| 48 } | |
| 49 | |
| 50 } // namespace | 30 } // namespace |
| 51 | 31 |
| 52 SyncArcPackageHelper* SyncArcPackageHelper::GetInstance() { | 32 SyncArcPackageHelper* SyncArcPackageHelper::GetInstance() { |
| 53 SyncArcPackageHelper* instance = base::Singleton<SyncArcPackageHelper>::get(); | 33 SyncArcPackageHelper* instance = base::Singleton<SyncArcPackageHelper>::get(); |
| 54 DCHECK(sync_datatype_helper::test()); | 34 DCHECK(sync_datatype_helper::test()); |
| 55 instance->SetupTest(sync_datatype_helper::test()); | 35 instance->SetupTest(sync_datatype_helper::test()); |
| 56 return instance; | 36 return instance; |
| 57 } | 37 } |
| 58 | 38 |
| 59 SyncArcPackageHelper::SyncArcPackageHelper() | 39 SyncArcPackageHelper::SyncArcPackageHelper() |
| 60 : test_(nullptr), setup_completed_(false), user_manager_enabler_(nullptr) {} | 40 : test_(nullptr), setup_completed_(false) {} |
| 61 | 41 |
| 62 SyncArcPackageHelper::~SyncArcPackageHelper() {} | 42 SyncArcPackageHelper::~SyncArcPackageHelper() {} |
| 63 | 43 |
| 64 void SyncArcPackageHelper::SetupTest(SyncTest* test) { | 44 void SyncArcPackageHelper::SetupTest(SyncTest* test) { |
| 65 if (setup_completed_) { | 45 if (setup_completed_) { |
| 66 DCHECK_EQ(test, test_); | 46 DCHECK_EQ(test, test_); |
| 67 return; | 47 return; |
| 68 } | 48 } |
| 69 test_ = test; | 49 test_ = test; |
| 70 | 50 |
| 71 user_manager_enabler_ = base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | |
| 72 new chromeos::FakeChromeUserManager()); | |
| 73 ArcAppListPrefsFactory::SetFactoryForSyncTest(); | |
| 74 size_t id = 0; | |
| 75 for (auto* profile : test_->GetAllProfiles()) | 51 for (auto* profile : test_->GetAllProfiles()) |
| 76 SetupArcService(profile, id++); | 52 SetupArcService(profile); |
| 77 setup_completed_ = true; | 53 setup_completed_ = true; |
| 78 } | 54 } |
| 79 | 55 |
| 80 void SyncArcPackageHelper::CleanUp() { | |
| 81 ArcSessionManager::Get()->Shutdown(); | |
| 82 user_manager_enabler_.reset(); | |
| 83 } | |
| 84 | |
| 85 void SyncArcPackageHelper::InstallPackageWithIndex(Profile* profile, | 56 void SyncArcPackageHelper::InstallPackageWithIndex(Profile* profile, |
| 86 size_t id) { | 57 size_t id) { |
| 87 std::string package_name = GetTestPackageName(id); | 58 std::string package_name = GetTestPackageName(id); |
| 88 | 59 |
| 89 mojom::ArcPackageInfo package; | 60 mojom::ArcPackageInfo package; |
| 90 package.package_name = package_name; | 61 package.package_name = package_name; |
| 91 package.package_version = id; | 62 package.package_version = id; |
| 92 package.last_backup_android_id = id; | 63 package.last_backup_android_id = id; |
| 93 package.last_backup_time = id; | 64 package.last_backup_time = id; |
| 94 package.sync = true; | 65 package.sync = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 !ArcPackageDetailsMatch(profiles.front(), profile)) { | 106 !ArcPackageDetailsMatch(profiles.front(), profile)) { |
| 136 DVLOG(1) << "Profile1: " << ArcPackageSyncableService::Get(profile); | 107 DVLOG(1) << "Profile1: " << ArcPackageSyncableService::Get(profile); |
| 137 DVLOG(1) << "Profile2: " | 108 DVLOG(1) << "Profile2: " |
| 138 << ArcPackageSyncableService::Get(profiles.front()); | 109 << ArcPackageSyncableService::Get(profiles.front()); |
| 139 return false; | 110 return false; |
| 140 } | 111 } |
| 141 } | 112 } |
| 142 return true; | 113 return true; |
| 143 } | 114 } |
| 144 | 115 |
| 145 void SyncArcPackageHelper::SetupArcService(Profile* profile, size_t id) { | 116 void SyncArcPackageHelper::SetupArcService(Profile* profile) { |
| 146 DCHECK(profile); | 117 DCHECK(profile); |
| 147 const user_manager::User* user = CreateUserAndLogin(profile, id); | |
| 148 // Have the user-to-profile mapping ready to avoid using the real profile | |
| 149 // manager (which is null). | |
| 150 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | |
| 151 profile); | |
| 152 | |
| 153 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); | |
| 154 DCHECK(arc_session_manager); | |
| 155 ArcSessionManager::DisableUIForTesting(); | |
| 156 arc_session_manager->SetProfile(profile); | |
| 157 arc_session_manager->StartPreferenceHandler(); | |
|
skym
2017/03/03 19:44:58
So much deleted setup code, awesome!
| |
| 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); | |
|
skym
2017/03/03 19:44:58
Why does this need to be nulled out first?
lgcheng
2017/03/03 21:13:01
This is due to the logic in instance_holder that d
| |
| 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 |