| 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/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 11 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 14 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 14 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | 15 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| 15 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
| 17 #include "components/arc/arc_bridge_service.h" | 18 #include "components/arc/arc_bridge_service.h" |
| 18 #include "components/arc/test/fake_app_instance.h" | 19 #include "components/arc/test/fake_app_instance.h" |
| 19 #include "components/arc/test/fake_arc_bridge_service.h" | 20 #include "components/arc/test/fake_arc_bridge_service.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 constexpr char kPackageName1[] = "fake.package.name1"; | 25 constexpr char kPackageName1[] = "fake.package.name1"; |
| 25 constexpr char kPackageName2[] = "fake.package.name2"; | 26 constexpr char kPackageName2[] = "fake.package.name2"; |
| 26 constexpr char kPackageName3[] = "fake.package.name3"; | 27 constexpr char kPackageName3[] = "fake.package.name3"; |
| 27 } | 28 } |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 std::string ArcAppTest::GetAppId(const arc::mojom::AppInfo& app_info) { | 31 std::string ArcAppTest::GetAppId(const arc::mojom::AppInfo& app_info) { |
| 31 return ArcAppListPrefs::GetAppId(app_info.package_name, app_info.activity); | 32 return ArcAppListPrefs::GetAppId(app_info.package_name, app_info.activity); |
| 32 } | 33 } |
| 33 | 34 |
| 35 // static |
| 34 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { | 36 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { |
| 35 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); | 37 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); |
| 36 } | 38 } |
| 37 | 39 |
| 38 ArcAppTest::ArcAppTest() { | 40 ArcAppTest::ArcAppTest() { |
| 39 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | 41 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
| 40 new chromeos::FakeChromeUserManager())); | 42 new chromeos::FakeChromeUserManager())); |
| 41 } | 43 } |
| 42 | 44 |
| 43 ArcAppTest::~ArcAppTest() { | 45 ArcAppTest::~ArcAppTest() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 chromeos::switches::kEnableArc); | 59 chromeos::switches::kEnableArc); |
| 58 DCHECK(!profile_); | 60 DCHECK(!profile_); |
| 59 profile_ = profile; | 61 profile_ = profile; |
| 60 const user_manager::User* user = CreateUserAndLogin(); | 62 const user_manager::User* user = CreateUserAndLogin(); |
| 61 | 63 |
| 62 // If for any reason the garbage collector kicks in while we are waiting for | 64 // If for any reason the garbage collector kicks in while we are waiting for |
| 63 // an icon, have the user-to-profile mapping ready to avoid using the real | 65 // an icon, have the user-to-profile mapping ready to avoid using the real |
| 64 // profile manager (which is null). | 66 // profile manager (which is null). |
| 65 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | 67 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
| 66 profile_); | 68 profile_); |
| 67 | 69 arc::mojom::AppInfo app; |
| 68 // Make sure we have enough data for test. | 70 // Make sure we have enough data for test. |
| 69 for (int i = 0; i < 3; ++i) { | 71 for (int i = 0; i < 3; ++i) { |
| 70 arc::mojom::AppInfo app; | |
| 71 app.name = base::StringPrintf("Fake App %d", i); | 72 app.name = base::StringPrintf("Fake App %d", i); |
| 72 app.package_name = base::StringPrintf("fake.app.%d", i); | 73 app.package_name = base::StringPrintf("fake.app.%d", i); |
| 73 app.activity = base::StringPrintf("fake.app.%d.activity", i); | 74 app.activity = base::StringPrintf("fake.app.%d.activity", i); |
| 74 app.sticky = false; | 75 app.sticky = false; |
| 75 fake_apps_.push_back(app); | 76 fake_apps_.push_back(app); |
| 76 } | 77 } |
| 77 fake_apps_[0].sticky = true; | 78 fake_apps_[0].sticky = true; |
| 78 | 79 |
| 80 app.name = "TestApp1"; |
| 81 app.package_name = "test.app1"; |
| 82 app.activity = "test.app1.activity"; |
| 83 app.sticky = true; |
| 84 fake_default_apps_.push_back(app); |
| 85 |
| 86 app.name = "TestApp2"; |
| 87 app.package_name = "test.app2"; |
| 88 app.activity = "test.app2.activity"; |
| 89 app.sticky = true; |
| 90 fake_default_apps_.push_back(app); |
| 91 |
| 79 arc::mojom::ArcPackageInfo package1; | 92 arc::mojom::ArcPackageInfo package1; |
| 80 package1.package_name = kPackageName1; | 93 package1.package_name = kPackageName1; |
| 81 package1.package_version = 1; | 94 package1.package_version = 1; |
| 82 package1.last_backup_android_id = 1; | 95 package1.last_backup_android_id = 1; |
| 83 package1.last_backup_time = 1; | 96 package1.last_backup_time = 1; |
| 84 package1.sync = false; | 97 package1.sync = false; |
| 85 fake_packages_.push_back(package1); | 98 fake_packages_.push_back(package1); |
| 86 | 99 |
| 87 arc::mojom::ArcPackageInfo package2; | 100 arc::mojom::ArcPackageInfo package2; |
| 88 package2.package_name = kPackageName2; | 101 package2.package_name = kPackageName2; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 if (!arc_app_list_pref_) { | 130 if (!arc_app_list_pref_) { |
| 118 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | 131 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| 119 profile_); | 132 profile_); |
| 120 } | 133 } |
| 121 bridge_service_.reset(new arc::FakeArcBridgeService()); | 134 bridge_service_.reset(new arc::FakeArcBridgeService()); |
| 122 | 135 |
| 123 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); | 136 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); |
| 124 DCHECK(arc::ArcAuthService::Get()); | 137 DCHECK(arc::ArcAuthService::Get()); |
| 125 arc::ArcAuthService::DisableUIForTesting(); | 138 arc::ArcAuthService::DisableUIForTesting(); |
| 126 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); | 139 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); |
| 127 auth_service_->EnableArc(); | |
| 128 | 140 |
| 129 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | 141 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
| 130 DCHECK(arc_app_list_pref_); | 142 DCHECK(arc_app_list_pref_); |
| 143 base::RunLoop run_loop; |
| 144 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); |
| 145 run_loop.Run(); |
| 131 | 146 |
| 147 auth_service_->EnableArc(); |
| 132 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 148 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
| 133 bridge_service_->app()->SetInstance(app_instance_.get()); | 149 bridge_service_->app()->SetInstance(app_instance_.get()); |
| 134 | 150 |
| 135 // Check initial conditions. | 151 // Check initial conditions. |
| 136 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); | 152 EXPECT_EQ(bridge_service_.get(), arc::ArcBridgeService::Get()); |
| 137 EXPECT_FALSE(arc::ArcBridgeService::Get()->ready()); | 153 EXPECT_FALSE(arc::ArcBridgeService::Get()->ready()); |
| 138 } | 154 } |
| 139 | 155 |
| 140 void ArcAppTest::TearDown() { | 156 void ArcAppTest::TearDown() { |
| 141 auth_service_.reset(); | 157 auth_service_.reset(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 197 } |
| 182 } | 198 } |
| 183 | 199 |
| 184 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 200 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
| 185 for (auto fake_package : fake_packages_) { | 201 for (auto fake_package : fake_packages_) { |
| 186 if (package.package_name == fake_package.package_name) | 202 if (package.package_name == fake_package.package_name) |
| 187 return true; | 203 return true; |
| 188 } | 204 } |
| 189 return false; | 205 return false; |
| 190 } | 206 } |
| OLD | NEW |