| 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/ui/app_list/arc/arc_app_test.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 11 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 11 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 12 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 16 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 16 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | 17 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| 17 #include "chromeos/chromeos_switches.h" | 18 #include "chromeos/chromeos_switches.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "components/arc/arc_bridge_service.h" | 20 #include "components/arc/arc_bridge_service.h" |
| 21 #include "components/arc/arc_service_manager.h" |
| 20 #include "components/arc/test/fake_app_instance.h" | 22 #include "components/arc/test/fake_app_instance.h" |
| 21 #include "components/arc/test/fake_arc_bridge_service.h" | 23 #include "components/arc/test/fake_arc_bridge_service.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 constexpr char kPackageName1[] = "fake.package.name1"; | 28 constexpr char kPackageName1[] = "fake.package.name1"; |
| 27 constexpr char kPackageName2[] = "fake.package.name2"; | 29 constexpr char kPackageName2[] = "fake.package.name2"; |
| 28 constexpr char kPackageName3[] = "fake.package.name3"; | 30 constexpr char kPackageName3[] = "fake.package.name3"; |
| 29 } | 31 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | 71 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
| 70 profile_); | 72 profile_); |
| 71 | 73 |
| 72 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and the | 74 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and the |
| 73 // Arc auth service. | 75 // Arc auth service. |
| 74 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | 76 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 75 if (!arc_app_list_pref_) { | 77 if (!arc_app_list_pref_) { |
| 76 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | 78 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| 77 profile_); | 79 profile_); |
| 78 } | 80 } |
| 79 bridge_service_.reset(new arc::FakeArcBridgeService()); | 81 arc::ArcServiceManager::SetArcBridgeServiceForTesting( |
| 80 | 82 base::MakeUnique<arc::FakeArcBridgeService>()); |
| 81 arc_session_manager_.reset(new arc::ArcSessionManager(bridge_service_.get())); | 83 arc_service_manager_ = base::MakeUnique<arc::ArcServiceManager>(nullptr); |
| 84 arc_session_manager_ = base::MakeUnique<arc::ArcSessionManager>( |
| 85 arc_service_manager_->arc_bridge_service()); |
| 82 DCHECK(arc::ArcSessionManager::Get()); | 86 DCHECK(arc::ArcSessionManager::Get()); |
| 83 arc::ArcSessionManager::DisableUIForTesting(); | 87 arc::ArcSessionManager::DisableUIForTesting(); |
| 84 arc_session_manager_->OnPrimaryUserProfilePrepared(profile_); | 88 arc_session_manager_->OnPrimaryUserProfilePrepared(profile_); |
| 85 | 89 |
| 86 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | 90 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 87 DCHECK(arc_app_list_pref_); | 91 DCHECK(arc_app_list_pref_); |
| 88 base::RunLoop run_loop; | 92 base::RunLoop run_loop; |
| 89 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); | 93 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); |
| 90 run_loop.Run(); | 94 run_loop.Run(); |
| 91 | 95 |
| 92 arc_session_manager_->EnableArc(); | 96 arc_session_manager_->EnableArc(); |
| 93 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 97 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 94 bridge_service_->app()->SetInstance(app_instance_.get()); | 98 arc_service_manager_->arc_bridge_service()->app()->SetInstance( |
| 99 app_instance_.get()); |
| 95 | 100 |
| 96 // Check initial conditions. | 101 // Check initial conditions. |
| 97 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); | 102 EXPECT_FALSE(arc_service_manager_->arc_bridge_service()->ready()); |
| 98 EXPECT_FALSE(arc::ArcBridgeService::Get()->ready()); | |
| 99 } | 103 } |
| 100 | 104 |
| 101 void ArcAppTest::CreateFakeAppsAndPackages() { | 105 void ArcAppTest::CreateFakeAppsAndPackages() { |
| 102 arc::mojom::AppInfo app; | 106 arc::mojom::AppInfo app; |
| 103 // Make sure we have enough data for test. | 107 // Make sure we have enough data for test. |
| 104 for (int i = 0; i < 3; ++i) { | 108 for (int i = 0; i < 3; ++i) { |
| 105 app.name = base::StringPrintf("Fake App %d", i); | 109 app.name = base::StringPrintf("Fake App %d", i); |
| 106 app.package_name = base::StringPrintf("fake.app.%d", i); | 110 app.package_name = base::StringPrintf("fake.app.%d", i); |
| 107 app.activity = base::StringPrintf("fake.app.%d.activity", i); | 111 app.activity = base::StringPrintf("fake.app.%d.activity", i); |
| 108 app.sticky = false; | 112 app.sticky = false; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 base::StringPrintf("#Intent;fake.shortcut.%d.intent_uri", i); | 158 base::StringPrintf("#Intent;fake.shortcut.%d.intent_uri", i); |
| 155 shortcut_info.icon_resource_id = | 159 shortcut_info.icon_resource_id = |
| 156 base::StringPrintf("fake.shortcut.%d.icon_resource_id", i); | 160 base::StringPrintf("fake.shortcut.%d.icon_resource_id", i); |
| 157 fake_shortcuts_.push_back(shortcut_info); | 161 fake_shortcuts_.push_back(shortcut_info); |
| 158 } | 162 } |
| 159 } | 163 } |
| 160 | 164 |
| 161 void ArcAppTest::TearDown() { | 165 void ArcAppTest::TearDown() { |
| 162 app_instance_.reset(); | 166 app_instance_.reset(); |
| 163 arc_session_manager_.reset(); | 167 arc_session_manager_.reset(); |
| 164 bridge_service_.reset(); | 168 arc_service_manager_.reset(); |
| 165 if (dbus_thread_manager_initialized_) { | 169 if (dbus_thread_manager_initialized_) { |
| 166 // DBusThreadManager may be initialized from other testing utility, | 170 // DBusThreadManager may be initialized from other testing utility, |
| 167 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when | 171 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when |
| 168 // it is initialized in ArcAppTest::SetUp(). | 172 // it is initialized in ArcAppTest::SetUp(). |
| 169 chromeos::DBusThreadManager::Shutdown(); | 173 chromeos::DBusThreadManager::Shutdown(); |
| 170 dbus_thread_manager_initialized_ = false; | 174 dbus_thread_manager_initialized_ = false; |
| 171 } | 175 } |
| 172 profile_ = nullptr; | 176 profile_ = nullptr; |
| 173 } | 177 } |
| 174 | 178 |
| 175 void ArcAppTest::StopArcInstance() { | 179 void ArcAppTest::StopArcInstance() { |
| 176 bridge_service_->app()->SetInstance(nullptr); | 180 arc_service_manager_->arc_bridge_service()->app()->SetInstance(nullptr); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void ArcAppTest::RestartArcInstance() { | 183 void ArcAppTest::RestartArcInstance() { |
| 180 bridge_service_->app()->SetInstance(nullptr); | 184 auto* bridge_service = arc_service_manager_->arc_bridge_service(); |
| 181 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 185 bridge_service->app()->SetInstance(nullptr); |
| 182 bridge_service_->app()->SetInstance(app_instance_.get()); | 186 app_instance_ = base::MakeUnique<arc::FakeAppInstance>(arc_app_list_pref_); |
| 187 bridge_service->app()->SetInstance(app_instance_.get()); |
| 183 } | 188 } |
| 184 | 189 |
| 185 const user_manager::User* ArcAppTest::CreateUserAndLogin() { | 190 const user_manager::User* ArcAppTest::CreateUserAndLogin() { |
| 186 const AccountId account_id(AccountId::FromUserEmailGaiaId( | 191 const AccountId account_id(AccountId::FromUserEmailGaiaId( |
| 187 profile_->GetProfileUserName(), "1234567890")); | 192 profile_->GetProfileUserName(), "1234567890")); |
| 188 const user_manager::User* user = GetUserManager()->AddUser(account_id); | 193 const user_manager::User* user = GetUserManager()->AddUser(account_id); |
| 189 GetUserManager()->LoginUser(account_id); | 194 GetUserManager()->LoginUser(account_id); |
| 190 return user; | 195 return user; |
| 191 } | 196 } |
| 192 | 197 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 205 } | 210 } |
| 206 } | 211 } |
| 207 | 212 |
| 208 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 213 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
| 209 for (auto fake_package : fake_packages_) { | 214 for (auto fake_package : fake_packages_) { |
| 210 if (package.package_name == fake_package.package_name) | 215 if (package.package_name == fake_package.package_name) |
| 211 return true; | 216 return true; |
| 212 } | 217 } |
| 213 return false; | 218 return false; |
| 214 } | 219 } |
| OLD | NEW |