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

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

Issue 2520173002: arc: Fix duplicate icons in app launcher in case of crash. (Closed)
Patch Set: clean up 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/arc/arc_session_manager.h" 10 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
(...skipping 23 matching lines...) Expand all
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
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() {
158 arc_session_manager_.reset(); 162 arc_session_manager_.reset();
159 if (dbus_thread_manager_initialized_) { 163 if (dbus_thread_manager_initialized_) {
160 // DBusThreadManager may be initialized from other testing utility, 164 // DBusThreadManager may be initialized from other testing utility,
161 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when 165 // such as ash::test::AshTestHelper::SetUp(), so Shutdown() only when
162 // it is initialized in ArcAppTest::SetUp(). 166 // it is initialized in ArcAppTest::SetUp().
163 chromeos::DBusThreadManager::Shutdown(); 167 chromeos::DBusThreadManager::Shutdown();
164 dbus_thread_manager_initialized_ = false; 168 dbus_thread_manager_initialized_ = false;
165 } 169 }
170 arc_session_manager_.reset();
Luis Héctor Chávez 2016/11/22 17:14:14 This was already destroyed a few lines above.
khmel 2016/11/22 18:43:05 Done.
171 app_instance_.reset();
Luis Héctor Chávez 2016/11/22 17:14:14 You should try to delete stuff in the reverse orde
khmel 2016/11/22 18:43:05 Done.
172 bridge_service_.reset();
Luis Héctor Chávez 2016/11/22 17:14:14 And this should be the second line.
khmel 2016/11/22 18:43:05 Done, As I see this is third line, arc_session_man
173 profile_ = nullptr;
166 } 174 }
167 175
168 void ArcAppTest::StopArcInstance() { 176 void ArcAppTest::StopArcInstance() {
169 bridge_service_->app()->SetInstance(nullptr); 177 bridge_service_->app()->SetInstance(nullptr);
170 } 178 }
171 179
172 void ArcAppTest::RestartArcInstance() { 180 void ArcAppTest::RestartArcInstance() {
173 bridge_service_->app()->SetInstance(nullptr); 181 bridge_service_->app()->SetInstance(nullptr);
174 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_)); 182 app_instance_.reset(new arc::FakeAppInstance(arc_app_list_pref_));
175 bridge_service_->app()->SetInstance(app_instance_.get()); 183 bridge_service_->app()->SetInstance(app_instance_.get());
(...skipping 22 matching lines...) Expand all
198 } 206 }
199 } 207 }
200 208
201 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) { 209 bool ArcAppTest::FindPackage(const arc::mojom::ArcPackageInfo& package) {
202 for (auto fake_package : fake_packages_) { 210 for (auto fake_package : fake_packages_) {
203 if (package.package_name == fake_package.package_name) 211 if (package.package_name == fake_package.package_name)
204 return true; 212 return true;
205 } 213 }
206 return false; 214 return false;
207 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698