OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/pref_service_factory.h" | 10 #include "base/prefs/pref_service_factory.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { | 141 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { |
142 EnableAppList(); | 142 EnableAppList(); |
143 profile_store_->RemoveProfile(profile1_.get()); | 143 profile_store_->RemoveProfile(profile1_.get()); |
144 | 144 |
145 // kAppListProfile should have been cleared, and therefore GetProfilePath | 145 // kAppListProfile should have been cleared, and therefore GetProfilePath |
146 // should return the initial profile. | 146 // should return the initial profile. |
147 EXPECT_EQ("", local_state_->GetString(prefs::kAppListProfile)); | 147 EXPECT_EQ("", local_state_->GetString(prefs::kAppListProfile)); |
148 base::FilePath initial_profile_path = | 148 base::FilePath initial_profile_path = |
149 user_data_dir_.AppendASCII(chrome::kInitialProfile); | 149 user_data_dir_.AppendASCII(chrome::kInitialProfile); |
150 EXPECT_EQ(initial_profile_path, | 150 EXPECT_EQ(initial_profile_path, service_->GetProfilePath()); |
151 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
152 } | 151 } |
153 | 152 |
154 TEST_F(AppListServiceUnitTest, | 153 TEST_F(AppListServiceUnitTest, |
155 RemovedProfileResetsToLastUsedProfileIfExists) { | 154 RemovedProfileResetsToLastUsedProfileIfExists) { |
156 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); | 155 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); |
157 EnableAppList(); | 156 EnableAppList(); |
158 profile_store_->RemoveProfile(profile1_.get()); | 157 profile_store_->RemoveProfile(profile1_.get()); |
159 | 158 |
160 // kAppListProfile should have been set to kProfileLastUsed. | 159 // kAppListProfile should have been set to kProfileLastUsed. |
161 EXPECT_EQ("last-used", local_state_->GetString(prefs::kAppListProfile)); | 160 EXPECT_EQ("last-used", local_state_->GetString(prefs::kAppListProfile)); |
162 base::FilePath last_used_profile_path = | 161 base::FilePath last_used_profile_path = |
163 user_data_dir_.AppendASCII("last-used"); | 162 user_data_dir_.AppendASCII("last-used"); |
164 EXPECT_EQ(last_used_profile_path, | 163 EXPECT_EQ(last_used_profile_path, service_->GetProfilePath()); |
165 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
166 | 164 |
167 // For this test, the AppListViewDelegate is not created because the | 165 // For this test, the AppListViewDelegate is not created because the |
168 // app list is never shown, so there is nothing to destroy. | 166 // app list is never shown, so there is nothing to destroy. |
169 EXPECT_EQ(0, service_->destroy_app_list_call_count()); | 167 EXPECT_EQ(0, service_->destroy_app_list_call_count()); |
170 } | 168 } |
171 | 169 |
172 TEST_F(AppListServiceUnitTest, RefusesToLoadGuestAppListProfile) { | 170 TEST_F(AppListServiceUnitTest, RefusesToLoadGuestAppListProfile) { |
173 // Unlikely, but if somehow the user's app_list.profile pref was set to the | 171 // Unlikely, but if somehow the user's app_list.profile pref was set to the |
174 // guest profile, make sure we refuse to load it (or it would crash). | 172 // guest profile, make sure we refuse to load it (or it would crash). |
175 local_state_->SetString( | 173 local_state_->SetString( |
176 prefs::kAppListProfile, | 174 prefs::kAppListProfile, |
177 base::FilePath(chrome::kGuestProfileDir).MaybeAsASCII()); | 175 base::FilePath(chrome::kGuestProfileDir).MaybeAsASCII()); |
178 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); | 176 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); |
179 base::FilePath last_used_profile_path = | 177 base::FilePath last_used_profile_path = |
180 user_data_dir_.AppendASCII("last-used"); | 178 user_data_dir_.AppendASCII("last-used"); |
181 EXPECT_EQ(last_used_profile_path, | 179 EXPECT_EQ(last_used_profile_path, service_->GetProfilePath()); |
182 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
183 } | 180 } |
184 | 181 |
185 TEST_F(AppListServiceUnitTest, RefusesToLoadGuestLastUsedProfile) { | 182 TEST_F(AppListServiceUnitTest, RefusesToLoadGuestLastUsedProfile) { |
186 // If the user's most recent browser session was a guest session, make sure we | 183 // If the user's most recent browser session was a guest session, make sure we |
187 // do not open a guest profile in the launcher (which would crash). | 184 // do not open a guest profile in the launcher (which would crash). |
188 local_state_->SetString( | 185 local_state_->SetString( |
189 prefs::kProfileLastUsed, | 186 prefs::kProfileLastUsed, |
190 base::FilePath(chrome::kGuestProfileDir).MaybeAsASCII()); | 187 base::FilePath(chrome::kGuestProfileDir).MaybeAsASCII()); |
191 base::FilePath initial_profile_path = | 188 base::FilePath initial_profile_path = |
192 user_data_dir_.AppendASCII(chrome::kInitialProfile); | 189 user_data_dir_.AppendASCII(chrome::kInitialProfile); |
193 EXPECT_EQ(initial_profile_path, | 190 EXPECT_EQ(initial_profile_path, service_->GetProfilePath()); |
194 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
195 } | 191 } |
196 | 192 |
197 TEST_F(AppListServiceUnitTest, SwitchingProfilesPersists) { | 193 TEST_F(AppListServiceUnitTest, SwitchingProfilesPersists) { |
198 profile_store_->LoadProfile(profile1_.get()); | 194 profile_store_->LoadProfile(profile1_.get()); |
199 profile_store_->LoadProfile(profile2_.get()); | 195 profile_store_->LoadProfile(profile2_.get()); |
200 EnableAppList(); | 196 EnableAppList(); |
201 service_->SetProfilePath(profile2_->GetPath()); | 197 service_->SetProfilePath(profile2_->GetPath()); |
202 service_->Show(); | 198 service_->Show(); |
203 EXPECT_EQ(profile2_.get(), service_->showing_for_profile()); | 199 EXPECT_EQ(profile2_.get(), service_->showing_for_profile()); |
204 EXPECT_EQ(profile2_->GetPath(), | 200 EXPECT_EQ(profile2_->GetPath(), service_->GetProfilePath()); |
205 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
206 service_->SetProfilePath(profile1_->GetPath()); | 201 service_->SetProfilePath(profile1_->GetPath()); |
207 EXPECT_EQ(profile1_->GetPath(), | 202 EXPECT_EQ(profile1_->GetPath(), service_->GetProfilePath()); |
208 service_->GetProfilePath(profile_store_->GetUserDataDir())); | |
209 } | 203 } |
210 | 204 |
211 TEST_F(AppListServiceUnitTest, EnableViaCommandLineFlag) { | 205 TEST_F(AppListServiceUnitTest, EnableViaCommandLineFlag) { |
212 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 206 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
213 command_line.AppendSwitch(switches::kEnableAppList); | 207 command_line.AppendSwitch(switches::kEnableAppList); |
214 SetupWithCommandLine(command_line); | 208 SetupWithCommandLine(command_line); |
215 service_->PerformStartupChecks(profile1_.get()); | 209 service_->PerformStartupChecks(profile1_.get()); |
216 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); | 210 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); |
217 } | 211 } |
218 | 212 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, | 260 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, |
267 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 261 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
268 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); | 262 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); |
269 | 263 |
270 // An auto-show here should update the enable method to prevent recording it | 264 // An auto-show here should update the enable method to prevent recording it |
271 // as ENABLE_FOR_APP_INSTALL. | 265 // as ENABLE_FOR_APP_INSTALL. |
272 service_->ShowForAppInstall(profile1_.get(), "", false); | 266 service_->ShowForAppInstall(profile1_.get(), "", false); |
273 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, | 267 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, |
274 local_state_->GetInteger(prefs::kAppListEnableMethod)); | 268 local_state_->GetInteger(prefs::kAppListEnableMethod)); |
275 } | 269 } |
OLD | NEW |