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

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc

Issue 11280240: Add additional profile shortcut manager tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <objbase.h> // For CoInitialize(). 5 #include <objbase.h> // For CoInitialize().
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 GetDefaultShortcutPathForProfile(profile_name)); 134 GetDefaultShortcutPathForProfile(profile_name));
135 } 135 }
136 136
137 // Calls base::win::ValidateShortcut() with expected properties for the 137 // Calls base::win::ValidateShortcut() with expected properties for the
138 // shortcut at |shortcut_path| for the profile at |profile_path|. 138 // shortcut at |shortcut_path| for the profile at |profile_path|.
139 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location, 139 void ValidateProfileShortcutAtPath(const tracked_objects::Location& location,
140 const FilePath& shortcut_path, 140 const FilePath& shortcut_path,
141 const FilePath& profile_path) { 141 const FilePath& profile_path) {
142 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); 142 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString();
143 143
144 // TODO(asvitkine): With this new struct method for VerifyShortcut you can 144 // Ensure that the corresponding icon exists.
145 // now test more properties like: arguments, icon, icon_index, and app_id. 145 const FilePath icon_path =
146 profile_path.AppendASCII(profiles::internal::kProfileIconFileName);
147 EXPECT_TRUE(file_util::PathExists(icon_path)) << location.ToString();
148
146 base::win::ShortcutProperties expected_properties; 149 base::win::ShortcutProperties expected_properties;
147 expected_properties.set_target(exe_path_); 150 expected_properties.set_target(exe_path_);
148 expected_properties.set_description(distribution_->GetAppDescription()); 151 expected_properties.set_description(distribution_->GetAppDescription());
149 expected_properties.set_dual_mode(false); 152 expected_properties.set_dual_mode(false);
150 expected_properties.set_arguments( 153 expected_properties.set_arguments(
151 profiles::internal::CreateProfileShortcutFlags(profile_path)); 154 profiles::internal::CreateProfileShortcutFlags(profile_path));
155 expected_properties.set_icon(icon_path, 0);
152 base::win::ValidateShortcut(shortcut_path, expected_properties); 156 base::win::ValidateShortcut(shortcut_path, expected_properties);
153 } 157 }
154 158
155 // Calls base::win::ValidateShortcut() with expected properties for 159 // Calls base::win::ValidateShortcut() with expected properties for
156 // |profile_name|'s shortcut. 160 // |profile_name|'s shortcut.
157 void ValidateProfileShortcut(const tracked_objects::Location& location, 161 void ValidateProfileShortcut(const tracked_objects::Location& location,
158 const string16& profile_name, 162 const string16& profile_name,
159 const FilePath& profile_path) { 163 const FilePath& profile_path) {
160 ValidateProfileShortcutAtPath( 164 ValidateProfileShortcutAtPath(
161 location, GetDefaultShortcutPathForProfile(profile_name), profile_path); 165 location, GetDefaultShortcutPathForProfile(profile_name), profile_path);
(...skipping 25 matching lines...) Expand all
187 product.AddDefaultShortcutProperties(exe_path_, &properties); 191 product.AddDefaultShortcutProperties(exe_path_, &properties);
188 properties.set_shortcut_name(shortcut_name); 192 properties.set_shortcut_name(shortcut_name);
189 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( 193 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut(
190 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, 194 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties,
191 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); 195 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString();
192 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); 196 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString();
193 197
194 return shortcut_path; 198 return shortcut_path;
195 } 199 }
196 200
201 void RenameProfile(const tracked_objects::Location& location,
202 const FilePath& profile_path,
203 const string16& new_profile_name) {
204 const size_t profile_index =
205 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_);
206 ASSERT_NE(std::string::npos, profile_index);
207 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index),
208 new_profile_name);
209 profile_info_cache_->SetNameOfProfileAtIndex(profile_index,
210 new_profile_name);
211 RunPendingTasks();
212 }
213
197 BrowserDistribution* distribution_; 214 BrowserDistribution* distribution_;
198 MessageLoopForUI message_loop_; 215 MessageLoopForUI message_loop_;
199 content::TestBrowserThread ui_thread_; 216 content::TestBrowserThread ui_thread_;
200 content::TestBrowserThread file_thread_; 217 content::TestBrowserThread file_thread_;
201 scoped_ptr<TestingProfileManager> profile_manager_; 218 scoped_ptr<TestingProfileManager> profile_manager_;
202 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; 219 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
203 ProfileInfoCache* profile_info_cache_; 220 ProfileInfoCache* profile_info_cache_;
204 base::ScopedPathOverride fake_user_desktop_; 221 base::ScopedPathOverride fake_user_desktop_;
205 FilePath exe_path_; 222 FilePath exe_path_;
206 FilePath shortcuts_directory_; 223 FilePath shortcuts_directory_;
(...skipping 11 matching lines...) Expand all
218 profiles::internal::GetShortcutFilenameForProfile(kProfileName, 235 profiles::internal::GetShortcutFilenameForProfile(kProfileName,
219 distribution_)); 236 distribution_));
220 } 237 }
221 238
222 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { 239 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) {
223 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, 240 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt,
224 profiles::internal::GetShortcutFilenameForProfile(string16(), 241 profiles::internal::GetShortcutFilenameForProfile(string16(),
225 distribution_)); 242 distribution_));
226 } 243 }
227 244
245 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) {
246 const string16 kProfileName = L"MyProfileX";
247 const FilePath profile_path =
248 profile_info_cache_->GetUserDataDir().Append(kProfileName);
249 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"",
250 profiles::internal::CreateProfileShortcutFlags(profile_path));
251 }
252
228 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { 253 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
229 SetupDefaultProfileShortcut(FROM_HERE); 254 SetupDefaultProfileShortcut(FROM_HERE);
255 // Validation is done by |ValidateProfileShortcutAtPath()| which is called
256 // by |CreateProfileWithShortcut()|.
230 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 257 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
231 // We now have 2 profiles, so we expect a new shortcut with profile
232 // information for this 2nd profile.
233 const FilePath icon_path =
234 profile_2_path_.AppendASCII(profiles::internal::kProfileIconFileName);
235 ASSERT_TRUE(file_util::PathExists(icon_path));
236 } 258 }
237 259
238 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { 260 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
239 SetupDefaultProfileShortcut(FROM_HERE); 261 SetupDefaultProfileShortcut(FROM_HERE);
240 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 262 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
241 263
242 // Cause an update in ProfileShortcutManager by modifying the profile info 264 // Cause an update in ProfileShortcutManager by modifying the profile info
243 // cache. 265 // cache.
244 const string16 new_profile_name = L"New Profile Name"; 266 const string16 new_profile_2_name = L"New Profile Name";
245 profile_info_cache_->SetNameOfProfileAtIndex( 267 RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name);
246 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_), 268 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
247 new_profile_name); 269 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
270 }
271
272 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) {
273 SetupDefaultProfileShortcut(FROM_HERE);
274 // Assert that a shortcut without a profile name exists.
275 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(string16()));
276
277 // Create a second profile without a shortcut.
278 profile_info_cache_->AddProfileToCache(profile_2_path_, profile_2_name_,
279 string16(), 0);
248 RunPendingTasks(); 280 RunPendingTasks();
281
282 // Ensure that the second profile doesn't have a shortcut and that the first
283 // profile's shortcut got renamed and badged.
249 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 284 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
250 ValidateProfileShortcut(FROM_HERE, new_profile_name, profile_2_path_); 285 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16()));
286 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
251 } 287 }
252 288
253 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { 289 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) {
254 SetupAndCreateTwoShortcuts(FROM_HERE); 290 SetupAndCreateTwoShortcuts(FROM_HERE);
255 291
256 // Delete one shortcut. 292 // Delete one shortcut.
257 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 293 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
258 RunPendingTasks(); 294 RunPendingTasks();
259 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 295 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
260 296
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Make a copy of the shortcut. 390 // Make a copy of the shortcut.
355 ASSERT_TRUE(file_util::CopyFile(profile_2_shortcut_path_1, 391 ASSERT_TRUE(file_util::CopyFile(profile_2_shortcut_path_1,
356 profile_2_shortcut_path_2)); 392 profile_2_shortcut_path_2));
357 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, 393 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1,
358 profile_2_path_); 394 profile_2_path_);
359 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, 395 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2,
360 profile_2_path_); 396 profile_2_path_);
361 397
362 // Now, rename the profile. 398 // Now, rename the profile.
363 const string16 new_profile_2_name = L"New profile"; 399 const string16 new_profile_2_name = L"New profile";
364 ASSERT_NE(profile_2_name_, new_profile_2_name); 400 RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name);
365 profile_info_cache_->SetNameOfProfileAtIndex(
366 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_),
367 new_profile_2_name);
368 RunPendingTasks();
369 401
370 // The original shortcut should be renamed but the copied shortcut should 402 // The original shortcut should be renamed but the copied shortcut should
371 // keep its name. 403 // keep its name.
372 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_1)); 404 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_1));
373 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, 405 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2,
374 profile_2_path_); 406 profile_2_path_);
375 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); 407 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
376 } 408 }
377 409
378 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { 410 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) {
(...skipping 28 matching lines...) Expand all
407 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); 439 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome");
408 440
409 // Add another profile and check that one shortcut was renamed and that the 441 // Add another profile and check that one shortcut was renamed and that the
410 // other shortcut was updated but kept the same name. 442 // other shortcut was updated but kept the same name.
411 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 443 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
412 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); 444 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
413 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, 445 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path,
414 profile_1_path_); 446 profile_1_path_);
415 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 447 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
416 } 448 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698