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/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | 14 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
14 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "components/arc/arc_bridge_service.h" | 17 #include "components/arc/arc_bridge_service.h" |
17 #include "components/arc/test/fake_app_instance.h" | 18 #include "components/arc/test/fake_app_instance.h" |
18 #include "components/arc/test/fake_arc_bridge_service.h" | 19 #include "components/arc/test/fake_arc_bridge_service.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 constexpr char kPackageName1[] = "fake.package.name1"; | 24 constexpr char kPackageName1[] = "fake.package.name1"; |
24 constexpr char kPackageName2[] = "fake.package.name2"; | 25 constexpr char kPackageName2[] = "fake.package.name2"; |
25 constexpr char kPackageName3[] = "fake.package.name3"; | 26 constexpr char kPackageName3[] = "fake.package.name3"; |
26 } | 27 } |
27 | 28 |
28 // static | 29 // static |
29 std::string ArcAppTest::GetAppId(const arc::mojom::AppInfo& app_info) { | 30 std::string ArcAppTest::GetAppId(const arc::mojom::AppInfo& app_info) { |
30 return ArcAppListPrefs::GetAppId(app_info.package_name, app_info.activity); | 31 return ArcAppListPrefs::GetAppId(app_info.package_name, app_info.activity); |
31 } | 32 } |
32 | 33 |
| 34 // static |
33 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { | 35 std::string ArcAppTest::GetAppId(const arc::mojom::ShortcutInfo& shortcut) { |
34 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); | 36 return ArcAppListPrefs::GetAppId(shortcut.package_name, shortcut.intent_uri); |
35 } | 37 } |
36 | 38 |
37 ArcAppTest::ArcAppTest() { | 39 ArcAppTest::ArcAppTest() { |
38 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | 40 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
39 new chromeos::FakeChromeUserManager())); | 41 new chromeos::FakeChromeUserManager())); |
40 } | 42 } |
41 | 43 |
42 ArcAppTest::~ArcAppTest() { | 44 ArcAppTest::~ArcAppTest() { |
43 } | 45 } |
44 | 46 |
45 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { | 47 chromeos::FakeChromeUserManager* ArcAppTest::GetUserManager() { |
46 return static_cast<chromeos::FakeChromeUserManager*>( | 48 return static_cast<chromeos::FakeChromeUserManager*>( |
47 user_manager::UserManager::Get()); | 49 user_manager::UserManager::Get()); |
48 } | 50 } |
49 | 51 |
50 void ArcAppTest::SetUp(Profile* profile) { | 52 void ArcAppTest::SetUp(Profile* profile) { |
51 if (!chromeos::DBusThreadManager::IsInitialized()) { | 53 if (!chromeos::DBusThreadManager::IsInitialized()) { |
52 chromeos::DBusThreadManager::Initialize(); | 54 chromeos::DBusThreadManager::Initialize(); |
53 dbus_thread_manager_initialized_ = true; | 55 dbus_thread_manager_initialized_ = true; |
54 } | 56 } |
55 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 57 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
56 chromeos::switches::kEnableArc); | 58 chromeos::switches::kEnableArc); |
57 DCHECK(!profile_); | 59 DCHECK(!profile_); |
58 profile_ = profile; | 60 profile_ = profile; |
59 CreateUserAndLogin(); | 61 CreateUserAndLogin(); |
60 | 62 |
| 63 arc::mojom::AppInfo app; |
61 // Make sure we have enough data for test. | 64 // Make sure we have enough data for test. |
62 for (int i = 0; i < 3; ++i) { | 65 for (int i = 0; i < 3; ++i) { |
63 arc::mojom::AppInfo app; | |
64 app.name = base::StringPrintf("Fake App %d", i); | 66 app.name = base::StringPrintf("Fake App %d", i); |
65 app.package_name = base::StringPrintf("fake.app.%d", i); | 67 app.package_name = base::StringPrintf("fake.app.%d", i); |
66 app.activity = base::StringPrintf("fake.app.%d.activity", i); | 68 app.activity = base::StringPrintf("fake.app.%d.activity", i); |
67 app.sticky = false; | 69 app.sticky = false; |
68 fake_apps_.push_back(app); | 70 fake_apps_.push_back(app); |
69 } | 71 } |
70 fake_apps_[0].sticky = true; | 72 fake_apps_[0].sticky = true; |
71 | 73 |
| 74 app.name = "TestApp1"; |
| 75 app.package_name = "test.app1"; |
| 76 app.activity = "test.app1.activity"; |
| 77 app.sticky = true; |
| 78 fake_default_apps_.push_back(app); |
| 79 |
| 80 app.name = "TestApp2"; |
| 81 app.package_name = "test.app2"; |
| 82 app.activity = "test.app2.activity"; |
| 83 app.sticky = true; |
| 84 fake_default_apps_.push_back(app); |
| 85 |
72 arc::mojom::ArcPackageInfo package1; | 86 arc::mojom::ArcPackageInfo package1; |
73 package1.package_name = kPackageName1; | 87 package1.package_name = kPackageName1; |
74 package1.package_version = 1; | 88 package1.package_version = 1; |
75 package1.last_backup_android_id = 1; | 89 package1.last_backup_android_id = 1; |
76 package1.last_backup_time = 1; | 90 package1.last_backup_time = 1; |
77 package1.sync = false; | 91 package1.sync = false; |
78 fake_packages_.push_back(package1); | 92 fake_packages_.push_back(package1); |
79 | 93 |
80 arc::mojom::ArcPackageInfo package2; | 94 arc::mojom::ArcPackageInfo package2; |
81 package2.package_name = kPackageName2; | 95 package2.package_name = kPackageName2; |
(...skipping 28 matching lines...) Expand all Loading... |
110 if (!arc_app_list_pref_) { | 124 if (!arc_app_list_pref_) { |
111 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | 125 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
112 profile_); | 126 profile_); |
113 } | 127 } |
114 bridge_service_.reset(new arc::FakeArcBridgeService()); | 128 bridge_service_.reset(new arc::FakeArcBridgeService()); |
115 | 129 |
116 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); | 130 auth_service_.reset(new arc::ArcAuthService(bridge_service_.get())); |
117 DCHECK(arc::ArcAuthService::Get()); | 131 DCHECK(arc::ArcAuthService::Get()); |
118 arc::ArcAuthService::DisableUIForTesting(); | 132 arc::ArcAuthService::DisableUIForTesting(); |
119 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); | 133 arc_auth_service()->OnPrimaryUserProfilePrepared(profile_); |
120 auth_service_->EnableArc(); | |
121 | 134 |
122 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); | 135 arc_app_list_pref_ = ArcAppListPrefs::Get(profile_); |
123 DCHECK(arc_app_list_pref_); | 136 DCHECK(arc_app_list_pref_); |
| 137 base::RunLoop run_loop; |
| 138 arc_app_list_pref_->SetDefaltAppsReadyCallback(run_loop.QuitClosure()); |
| 139 run_loop.Run(); |
124 | 140 |
| 141 auth_service_->EnableArc(); |
125 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); | 142 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); |
126 bridge_service_->app()->SetInstance(app_instance_.get()); | 143 bridge_service_->app()->SetInstance(app_instance_.get()); |
127 } | 144 } |
128 | 145 |
129 void ArcAppTest::TearDown() { | 146 void ArcAppTest::TearDown() { |
130 auth_service_.reset(); | 147 auth_service_.reset(); |
131 if (dbus_thread_manager_initialized_) { | 148 if (dbus_thread_manager_initialized_) { |
132 // DBusThreadManager may be initialized from other testing utility, | 149 // DBusThreadManager may be initialized from other testing utility, |
133 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when | 150 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when |
134 // it is initialized in ArcAppTest::SetUp(). | 151 // it is initialized in ArcAppTest::SetUp(). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 186 } |
170 } | 187 } |
171 | 188 |
172 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { | 189 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { |
173 for (auto fake_package : fake_packages_) { | 190 for (auto fake_package : fake_packages_) { |
174 if (package.package_name == fake_package.package_name) | 191 if (package.package_name == fake_package.package_name) |
175 return true; | 192 return true; |
176 } | 193 } |
177 return false; | 194 return false; |
178 } | 195 } |
OLD | NEW |