Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698