| 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/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 10 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 // static | 36 // static |
| 37 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { | 37 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { |
| 38 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); | 38 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); |
| 39 } | 39 } |
| 40 | 40 |
| 41 ArcAppTest::ArcAppTest() { | 41 ArcAppTest::ArcAppTest() { |
| 42 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | 42 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
| 43 new chromeos::FakeChromeUserManager())); | 43 new chromeos::FakeChromeUserManager())); |
| 44 CreateFakeAppsAndPackages(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 ArcAppTest::~ArcAppTest() { | 47 ArcAppTest::~ArcAppTest() { |
| 47 } | 48 } |
| 48 | 49 |
| 49 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { | 50 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { |
| 50 return static_cast<chromeos::FakeChromeUserManager*>( | 51 return static_cast<chromeos::FakeChromeUserManager*>( |
| 51 user_manager::UserManager::Get()); | 52 user_manager::UserManager::Get()); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void ArcAppTest::SetUp(Profile* profile) { | 55 void ArcAppTest::SetUp(Profile* profile) { |
| 55 if (!chromeos::DBusThreadManager::IsInitialized()) { | 56 if (!chromeos::DBusThreadManager::IsInitialized()) { |
| 56 chromeos::DBusThreadManager::Initialize(); | 57 chromeos::DBusThreadManager::Initialize(); |
| 57 dbus_thread_manager_initialized_ = true; | 58 dbus_thread_manager_initialized_ = true; |
| 58 } | 59 } |
| 59 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 60 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 60 chromeos::switches::kEnableArc); | 61 chromeos::switches::kEnableArc); |
| 61 DCHECK(!profile_); | 62 DCHECK(!profile_); |
| 62 profile_ = profile; | 63 profile_ = profile; |
| 63 const user_manager::User* user = CreateUserAndLogin(); | 64 const user_manager::User* user = CreateUserAndLogin(); |
| 64 | 65 |
| 65 // If for any reason the garbage collector kicks in while we are waiting for | 66 // If for any reason the garbage collector kicks in while we are waiting for |
| 66 // an icon, have the user-to-profile mapping ready to avoid using the real | 67 // an icon, have the user-to-profile mapping ready to avoid using the real |
| 67 // profile manager (which is null). | 68 // profile manager (which is null). |
| 68 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | 69 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
| 69 profile_); | 70 profile_); |
| 71 |
| 72 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and the |
| 73 // Arc auth service. |
| 74 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 75 if (!arc_app_list_pref_) { |
| 76 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| 77 profile_); |
| 78 } |
| 79 bridge_service_.reset(new arc::FakeArcBridgeService()); |
| 80 |
| 81 arc_session_manager_.reset(new arc::ArcSessionManager(bridge_service_.get())); |
| 82 DCHECK(arc::ArcSessionManager::Get()); |
| 83 arc::ArcSessionManager::DisableUIForTesting(); |
| 84 arc_session_manager_->OnPrimaryUserProfilePrepared(profile_); |
| 85 |
| 86 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 87 DCHECK(arc_app_list_pref_); |
| 88 base::RunLoop run_loop; |
| 89 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); |
| 90 run_loop.Run(); |
| 91 |
| 92 arc_session_manager_->EnableArc(); |
| 93 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 94 bridge_service_->app()->SetInstance(app_instance_.get()); |
| 95 |
| 96 // Check initial conditions. |
| 97 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); |
| 98 EXPECT_FALSE(arc::ArcBridgeService::Get()->ready()); |
| 99 } |
| 100 |
| 101 void ArcAppTest::CreateFakeAppsAndPackages() { |
| 70 arc::mojom::AppInfo app; | 102 arc::mojom::AppInfo app; |
| 71 // Make sure we have enough data for test. | 103 // Make sure we have enough data for test. |
| 72 for (int i = 0; i < 3; ++i) { | 104 for (int i = 0; i < 3; ++i) { |
| 73 app.name = base::StringPrintf("Fake App %d", i); | 105 app.name = base::StringPrintf("Fake App %d", i); |
| 74 app.package_name = base::StringPrintf("fake.app.%d", i); | 106 app.package_name = base::StringPrintf("fake.app.%d", i); |
| 75 app.activity = base::StringPrintf("fake.app.%d.activity", i); | 107 app.activity = base::StringPrintf("fake.app.%d.activity", i); |
| 76 app.sticky = false; | 108 app.sticky = false; |
| 77 fake_apps_.push_back(app); | 109 fake_apps_.push_back(app); |
| 78 } | 110 } |
| 79 fake_apps_[0].sticky = true; | 111 fake_apps_[0].sticky = true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 for (int i = 0; i < 3; ++i) { | 149 for (int i = 0; i < 3; ++i) { |
| 118 arc::mojom::ShortcutInfo shortcutInfo; | 150 arc::mojom::ShortcutInfo shortcutInfo; |
| 119 shortcutInfo.name = base::StringPrintf("Fake Shortcut %d", i); | 151 shortcutInfo.name = base::StringPrintf("Fake Shortcut %d", i); |
| 120 shortcutInfo.package_name = base::StringPrintf("fake.shortcut.%d", i); | 152 shortcutInfo.package_name = base::StringPrintf("fake.shortcut.%d", i); |
| 121 shortcutInfo.intent_uri = | 153 shortcutInfo.intent_uri = |
| 122 base::StringPrintf("fake.shortcut.%d.intent_uri", i); | 154 base::StringPrintf("fake.shortcut.%d.intent_uri", i); |
| 123 shortcutInfo.icon_resource_id = | 155 shortcutInfo.icon_resource_id = |
| 124 base::StringPrintf("fake.shortcut.%d.icon_resource_id", i); | 156 base::StringPrintf("fake.shortcut.%d.icon_resource_id", i); |
| 125 fake_shortcuts_.push_back(shortcutInfo); | 157 fake_shortcuts_.push_back(shortcutInfo); |
| 126 } | 158 } |
| 127 | |
| 128 // A valid |arc_app_list_prefs_| is needed for the Arc bridge service and the | |
| 129 // Arc auth service. | |
| 130 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | |
| 131 if (!arc_app_list_pref_) { | |
| 132 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 133 profile_); | |
| 134 } | |
| 135 bridge_service_.reset(new arc::FakeArcBridgeService()); | |
| 136 | |
| 137 arc_session_manager_.reset(new arc::ArcSessionManager(bridge_service_.get())); | |
| 138 DCHECK(arc::ArcSessionManager::Get()); | |
| 139 arc::ArcSessionManager::DisableUIForTesting(); | |
| 140 arc_session_manager_->OnPrimaryUserProfilePrepared(profile_); | |
| 141 | |
| 142 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | |
| 143 DCHECK(arc_app_list_pref_); | |
| 144 base::RunLoop run_loop; | |
| 145 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); | |
| 146 run_loop.Run(); | |
| 147 | |
| 148 arc_session_manager_->EnableArc(); | |
| 149 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | |
| 150 bridge_service_->app()->SetInstance(app_instance_.get()); | |
| 151 | |
| 152 // Check initial conditions. | |
| 153 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); | |
| 154 EXPECT_FALSE(arc::ArcBridgeService::Get()->ready()); | |
| 155 } | 159 } |
| 156 | 160 |
| 157 void ArcAppTest::TearDown() { | 161 void ArcAppTest::TearDown() { |
| 162 app_instance_.reset(); |
| 158 arc_session_manager_.reset(); | 163 arc_session_manager_.reset(); |
| 164 bridge_service_.reset(); |
| 159 if (dbus_thread_manager_initialized_) { | 165 if (dbus_thread_manager_initialized_) { |
| 160 // DBusThreadManager may be initialized from other testing utility, | 166 // DBusThreadManager may be initialized from other testing utility, |
| 161 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when | 167 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when |
| 162 // it is initialized in ArcAppTest::SetUp(). | 168 // it is initialized in ArcAppTest::SetUp(). |
| 163 chromeos::DBusThreadManager::Shutdown(); | 169 chromeos::DBusThreadManager::Shutdown(); |
| 164 dbus_thread_manager_initialized_ = false; | 170 dbus_thread_manager_initialized_ = false; |
| 165 } | 171 } |
| 172 profile_ = nullptr; |
| 166 } | 173 } |
| 167 | 174 |
| 168 void ArcAppTest::StopArcInstance() { | 175 void ArcAppTest::StopArcInstance() { |
| 169 bridge_service_->app()->SetInstance(nullptr); | 176 bridge_service_->app()->SetInstance(nullptr); |
| 170 } | 177 } |
| 171 | 178 |
| 172 void ArcAppTest::RestartArcInstance() { | 179 void ArcAppTest::RestartArcInstance() { |
| 173 bridge_service_->app()->SetInstance(nullptr); | 180 bridge_service_->app()->SetInstance(nullptr); |
| 174 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 181 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 175 bridge_service_->app()->SetInstance(app_instance_.get()); | 182 bridge_service_->app()->SetInstance(app_instance_.get()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 } | 205 } |
| 199 } | 206 } |
| 200 | 207 |
| 201 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 208 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
| 202 for (auto fake_package : fake_packages_) { | 209 for (auto fake_package : fake_packages_) { |
| 203 if (package.package_name == fake_package.package_name) | 210 if (package.package_name == fake_package.package_name) |
| 204 return true; | 211 return true; |
| 205 } | 212 } |
| 206 return false; | 213 return false; |
| 207 } | 214 } |
| OLD | NEW |