OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 // Delete all profiles and ensure their shortcuts got removed. | 70 // Delete all profiles and ensure their shortcuts got removed. |
71 const size_t num_profiles = | 71 const size_t num_profiles = |
72 profile_attributes_storage_->GetNumberOfProfiles(); | 72 profile_attributes_storage_->GetNumberOfProfiles(); |
73 for (size_t i = 0; i < num_profiles; ++i) { | 73 for (size_t i = 0; i < num_profiles; ++i) { |
74 ProfileAttributesEntry* entry = | 74 ProfileAttributesEntry* entry = |
75 profile_attributes_storage_->GetAllProfilesAttributes().front(); | 75 profile_attributes_storage_->GetAllProfilesAttributes().front(); |
76 const base::FilePath profile_path = entry->GetPath(); | 76 const base::FilePath profile_path = entry->GetPath(); |
77 base::string16 profile_name = entry->GetName(); | 77 base::string16 profile_name = entry->GetName(); |
78 profile_attributes_storage_->RemoveProfile(profile_path); | 78 profile_attributes_storage_->RemoveProfile(profile_path); |
79 RunPendingTasks(); | 79 base::RunLoop().RunUntilIdle(); |
80 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); | 80 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); |
81 // The icon file is not deleted until the profile directory is deleted. | 81 // The icon file is not deleted until the profile directory is deleted. |
82 const base::FilePath icon_path = | 82 const base::FilePath icon_path = |
83 profiles::internal::GetProfileIconPath(profile_path); | 83 profiles::internal::GetProfileIconPath(profile_path); |
84 ASSERT_TRUE(base::PathExists(icon_path)); | 84 ASSERT_TRUE(base::PathExists(icon_path)); |
85 } | 85 } |
86 scoped_com_.reset(); | 86 scoped_com_.reset(); |
87 } | 87 } |
88 | 88 |
89 base::FilePath CreateProfileDirectory(const base::string16& profile_name) { | 89 base::FilePath CreateProfileDirectory(const base::string16& profile_name) { |
90 const base::FilePath profile_path = | 90 const base::FilePath profile_path = |
91 profile_manager_->profiles_dir().Append(profile_name); | 91 profile_manager_->profiles_dir().Append(profile_name); |
92 base::CreateDirectory(profile_path); | 92 base::CreateDirectory(profile_path); |
93 return profile_path; | 93 return profile_path; |
94 } | 94 } |
95 | 95 |
96 void RunPendingTasks() { | |
97 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
98 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
99 base::MessageLoop::current()->Run(); | |
100 } | |
101 | |
102 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { | 96 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { |
103 ASSERT_EQ(0u, profile_attributes_storage_->GetNumberOfProfiles()) | 97 ASSERT_EQ(0u, profile_attributes_storage_->GetNumberOfProfiles()) |
104 << location.ToString(); | 98 << location.ToString(); |
105 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) | 99 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) |
106 << location.ToString(); | 100 << location.ToString(); |
107 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_, | 101 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_, |
108 std::string(), base::string16(), 0, | 102 std::string(), base::string16(), 0, |
109 std::string()); | 103 std::string()); |
110 // Also create a non-badged shortcut for Chrome, which is conveniently done | 104 // Also create a non-badged shortcut for Chrome, which is conveniently done |
111 // by |CreateProfileShortcut()| since there is only one profile. | 105 // by |CreateProfileShortcut()| since there is only one profile. |
112 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_); | 106 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_); |
113 RunPendingTasks(); | 107 base::RunLoop().RunUntilIdle(); |
114 // Verify that there's now a shortcut with no profile information. | 108 // Verify that there's now a shortcut with no profile information. |
115 ValidateNonProfileShortcut(location); | 109 ValidateNonProfileShortcut(location); |
116 } | 110 } |
117 | 111 |
118 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { | 112 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { |
119 SetupDefaultProfileShortcut(location); | 113 SetupDefaultProfileShortcut(location); |
120 CreateProfileWithShortcut(location, profile_2_name_, profile_2_path_); | 114 CreateProfileWithShortcut(location, profile_2_name_, profile_2_path_); |
121 ValidateProfileShortcut(location, profile_1_name_, profile_1_path_); | 115 ValidateProfileShortcut(location, profile_1_name_, profile_1_path_); |
122 } | 116 } |
123 | 117 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 184 |
191 void CreateProfileWithShortcut(const tracked_objects::Location& location, | 185 void CreateProfileWithShortcut(const tracked_objects::Location& location, |
192 const base::string16& profile_name, | 186 const base::string16& profile_name, |
193 const base::FilePath& profile_path) { | 187 const base::FilePath& profile_path) { |
194 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) | 188 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) |
195 << location.ToString(); | 189 << location.ToString(); |
196 profile_attributes_storage_->AddProfile(profile_path, profile_name, | 190 profile_attributes_storage_->AddProfile(profile_path, profile_name, |
197 std::string(), base::string16(), 0, | 191 std::string(), base::string16(), 0, |
198 std::string()); | 192 std::string()); |
199 profile_shortcut_manager_->CreateProfileShortcut(profile_path); | 193 profile_shortcut_manager_->CreateProfileShortcut(profile_path); |
200 RunPendingTasks(); | 194 base::RunLoop().RunUntilIdle(); |
201 ValidateProfileShortcut(location, profile_name, profile_path); | 195 ValidateProfileShortcut(location, profile_name, profile_path); |
202 } | 196 } |
203 | 197 |
204 // Creates a regular (non-profile) desktop shortcut with the given name and | 198 // Creates a regular (non-profile) desktop shortcut with the given name and |
205 // returns its path. Fails the test if an error occurs. | 199 // returns its path. Fails the test if an error occurs. |
206 base::FilePath CreateRegularShortcutWithName( | 200 base::FilePath CreateRegularShortcutWithName( |
207 const tracked_objects::Location& location, | 201 const tracked_objects::Location& location, |
208 const base::string16& shortcut_name) { | 202 const base::string16& shortcut_name) { |
209 const base::FilePath shortcut_path = | 203 const base::FilePath shortcut_path = |
210 GetUserShortcutsDirectory().Append(shortcut_name + installer::kLnkExt); | 204 GetUserShortcutsDirectory().Append(shortcut_name + installer::kLnkExt); |
(...skipping 29 matching lines...) Expand all Loading... |
240 } | 234 } |
241 | 235 |
242 void RenameProfile(const tracked_objects::Location& location, | 236 void RenameProfile(const tracked_objects::Location& location, |
243 const base::FilePath& profile_path, | 237 const base::FilePath& profile_path, |
244 const base::string16& new_profile_name) { | 238 const base::string16& new_profile_name) { |
245 ProfileAttributesEntry* entry; | 239 ProfileAttributesEntry* entry; |
246 ASSERT_TRUE(profile_attributes_storage_-> | 240 ASSERT_TRUE(profile_attributes_storage_-> |
247 GetProfileAttributesWithPath(profile_path, &entry)); | 241 GetProfileAttributesWithPath(profile_path, &entry)); |
248 ASSERT_NE(entry->GetName(), new_profile_name); | 242 ASSERT_NE(entry->GetName(), new_profile_name); |
249 entry->SetName(new_profile_name); | 243 entry->SetName(new_profile_name); |
250 RunPendingTasks(); | 244 base::RunLoop().RunUntilIdle(); |
251 } | 245 } |
252 | 246 |
253 BrowserDistribution* GetDistribution() { | 247 BrowserDistribution* GetDistribution() { |
254 return BrowserDistribution::GetDistribution(); | 248 return BrowserDistribution::GetDistribution(); |
255 } | 249 } |
256 | 250 |
257 base::FilePath GetExePath() { | 251 base::FilePath GetExePath() { |
258 base::FilePath exe_path; | 252 base::FilePath exe_path; |
259 EXPECT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 253 EXPECT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
260 return exe_path; | 254 return exe_path; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 355 |
362 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) { | 356 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) { |
363 SetupDefaultProfileShortcut(FROM_HERE); | 357 SetupDefaultProfileShortcut(FROM_HERE); |
364 // Assert that a shortcut without a profile name exists. | 358 // Assert that a shortcut without a profile name exists. |
365 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 359 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
366 | 360 |
367 // Create a second profile without a shortcut. | 361 // Create a second profile without a shortcut. |
368 profile_attributes_storage_->AddProfile(profile_2_path_, profile_2_name_, | 362 profile_attributes_storage_->AddProfile(profile_2_path_, profile_2_name_, |
369 std::string(), base::string16(), 0, | 363 std::string(), base::string16(), 0, |
370 std::string()); | 364 std::string()); |
371 RunPendingTasks(); | 365 base::RunLoop().RunUntilIdle(); |
372 | 366 |
373 // Ensure that the second profile doesn't have a shortcut and that the first | 367 // Ensure that the second profile doesn't have a shortcut and that the first |
374 // profile's shortcut got renamed and badged. | 368 // profile's shortcut got renamed and badged. |
375 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 369 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
376 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 370 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
377 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 371 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
378 } | 372 } |
379 | 373 |
380 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { | 374 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { |
381 SetupAndCreateTwoShortcuts(FROM_HERE); | 375 SetupAndCreateTwoShortcuts(FROM_HERE); |
382 | 376 |
383 // Delete one shortcut. | 377 // Delete one shortcut. |
384 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 378 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
385 RunPendingTasks(); | 379 base::RunLoop().RunUntilIdle(); |
386 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 380 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
387 | 381 |
388 // Verify that the profile name has been removed from the remaining shortcut. | 382 // Verify that the profile name has been removed from the remaining shortcut. |
389 ValidateNonProfileShortcut(FROM_HERE); | 383 ValidateNonProfileShortcut(FROM_HERE); |
390 // Verify that an additional shortcut, with the default profile's name does | 384 // Verify that an additional shortcut, with the default profile's name does |
391 // not exist. | 385 // not exist. |
392 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); | 386 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); |
393 } | 387 } |
394 | 388 |
395 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) { | 389 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) { |
396 SetupAndCreateTwoShortcuts(FROM_HERE); | 390 SetupAndCreateTwoShortcuts(FROM_HERE); |
397 | 391 |
398 const base::FilePath profile_1_shortcut_path = | 392 const base::FilePath profile_1_shortcut_path = |
399 GetDefaultShortcutPathForProfile(profile_1_name_); | 393 GetDefaultShortcutPathForProfile(profile_1_name_); |
400 const base::FilePath profile_2_shortcut_path = | 394 const base::FilePath profile_2_shortcut_path = |
401 GetDefaultShortcutPathForProfile(profile_2_name_); | 395 GetDefaultShortcutPathForProfile(profile_2_name_); |
402 | 396 |
403 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 397 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
404 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); | 398 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); |
405 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 399 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
406 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); | 400 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); |
407 | 401 |
408 // Delete the profile that doesn't have a shortcut. | 402 // Delete the profile that doesn't have a shortcut. |
409 profile_attributes_storage_->RemoveProfile(profile_1_path_); | 403 profile_attributes_storage_->RemoveProfile(profile_1_path_); |
410 RunPendingTasks(); | 404 base::RunLoop().RunUntilIdle(); |
411 | 405 |
412 // Verify that the remaining shortcut does not have a profile name. | 406 // Verify that the remaining shortcut does not have a profile name. |
413 ValidateNonProfileShortcut(FROM_HERE); | 407 ValidateNonProfileShortcut(FROM_HERE); |
414 // Verify that shortcuts with profile names do not exist. | 408 // Verify that shortcuts with profile names do not exist. |
415 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); | 409 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); |
416 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); | 410 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); |
417 } | 411 } |
418 | 412 |
419 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) { | 413 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) { |
420 SetupAndCreateTwoShortcuts(FROM_HERE); | 414 SetupAndCreateTwoShortcuts(FROM_HERE); |
421 | 415 |
422 const base::FilePath profile_1_shortcut_path = | 416 const base::FilePath profile_1_shortcut_path = |
423 GetDefaultShortcutPathForProfile(profile_1_name_); | 417 GetDefaultShortcutPathForProfile(profile_1_name_); |
424 const base::FilePath profile_2_shortcut_path = | 418 const base::FilePath profile_2_shortcut_path = |
425 GetDefaultShortcutPathForProfile(profile_2_name_); | 419 GetDefaultShortcutPathForProfile(profile_2_name_); |
426 | 420 |
427 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 421 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
428 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); | 422 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); |
429 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 423 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
430 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); | 424 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); |
431 | 425 |
432 // Delete the profile that has a shortcut. | 426 // Delete the profile that has a shortcut. |
433 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 427 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
434 RunPendingTasks(); | 428 base::RunLoop().RunUntilIdle(); |
435 | 429 |
436 // Verify that the remaining shortcut does not have a profile name. | 430 // Verify that the remaining shortcut does not have a profile name. |
437 ValidateNonProfileShortcut(FROM_HERE); | 431 ValidateNonProfileShortcut(FROM_HERE); |
438 // Verify that shortcuts with profile names do not exist. | 432 // Verify that shortcuts with profile names do not exist. |
439 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); | 433 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); |
440 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); | 434 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); |
441 } | 435 } |
442 | 436 |
443 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { | 437 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { |
444 SetupAndCreateTwoShortcuts(FROM_HERE); | 438 SetupAndCreateTwoShortcuts(FROM_HERE); |
(...skipping 14 matching lines...) Expand all Loading... |
459 | 453 |
460 // Only the shortcut to the third profile should exist. | 454 // Only the shortcut to the third profile should exist. |
461 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 455 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
462 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); | 456 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); |
463 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); | 457 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); |
464 ASSERT_TRUE(base::PathExists(profile_3_shortcut_path)); | 458 ASSERT_TRUE(base::PathExists(profile_3_shortcut_path)); |
465 | 459 |
466 // Delete the third profile and check that its shortcut is gone and no | 460 // Delete the third profile and check that its shortcut is gone and no |
467 // shortcuts have been re-created. | 461 // shortcuts have been re-created. |
468 profile_attributes_storage_->RemoveProfile(profile_3_path_); | 462 profile_attributes_storage_->RemoveProfile(profile_3_path_); |
469 RunPendingTasks(); | 463 base::RunLoop().RunUntilIdle(); |
470 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 464 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
471 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); | 465 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); |
472 ASSERT_FALSE(base::PathExists(profile_3_shortcut_path)); | 466 ASSERT_FALSE(base::PathExists(profile_3_shortcut_path)); |
473 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); | 467 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); |
474 } | 468 } |
475 | 469 |
476 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { | 470 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { |
477 SetupAndCreateTwoShortcuts(FROM_HERE); | 471 SetupAndCreateTwoShortcuts(FROM_HERE); |
478 | 472 |
479 // Delete one shortcut. | 473 // Delete one shortcut. |
480 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 474 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
481 RunPendingTasks(); | 475 base::RunLoop().RunUntilIdle(); |
482 | 476 |
483 // Verify that a default shortcut exists (no profile name/avatar). | 477 // Verify that a default shortcut exists (no profile name/avatar). |
484 ValidateNonProfileShortcut(FROM_HERE); | 478 ValidateNonProfileShortcut(FROM_HERE); |
485 // Verify that an additional shortcut, with the first profile's name does | 479 // Verify that an additional shortcut, with the first profile's name does |
486 // not exist. | 480 // not exist. |
487 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); | 481 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); |
488 | 482 |
489 // Create a second profile and shortcut. | 483 // Create a second profile and shortcut. |
490 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 484 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
491 | 485 |
492 // Verify that the original shortcut received the profile's name. | 486 // Verify that the original shortcut received the profile's name. |
493 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 487 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
494 // Verify that a default shortcut no longer exists. | 488 // Verify that a default shortcut no longer exists. |
495 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 489 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
496 } | 490 } |
497 | 491 |
498 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { | 492 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { |
499 SetupAndCreateTwoShortcuts(FROM_HERE); | 493 SetupAndCreateTwoShortcuts(FROM_HERE); |
500 | 494 |
501 const base::FilePath profile_2_shortcut_path_1 = | 495 const base::FilePath profile_2_shortcut_path_1 = |
502 GetDefaultShortcutPathForProfile(profile_2_name_); | 496 GetDefaultShortcutPathForProfile(profile_2_name_); |
503 const base::FilePath profile_2_shortcut_path_2 = | 497 const base::FilePath profile_2_shortcut_path_2 = |
504 GetUserShortcutsDirectory().Append(L"MyChrome.lnk"); | 498 GetUserShortcutsDirectory().Append(L"MyChrome.lnk"); |
505 ASSERT_TRUE(base::Move(profile_2_shortcut_path_1, | 499 ASSERT_TRUE(base::Move(profile_2_shortcut_path_1, |
506 profile_2_shortcut_path_2)); | 500 profile_2_shortcut_path_2)); |
507 | 501 |
508 // Ensure that a new shortcut does not get made if the old one was renamed. | 502 // Ensure that a new shortcut does not get made if the old one was renamed. |
509 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); | 503 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); |
510 RunPendingTasks(); | 504 base::RunLoop().RunUntilIdle(); |
511 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 505 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
512 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, | 506 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
513 profile_2_path_); | 507 profile_2_path_); |
514 | 508 |
515 // Delete the renamed shortcut and try to create it again, which should work. | 509 // Delete the renamed shortcut and try to create it again, which should work. |
516 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path_2, false)); | 510 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path_2, false)); |
517 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2)); | 511 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2)); |
518 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); | 512 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); |
519 RunPendingTasks(); | 513 base::RunLoop().RunUntilIdle(); |
520 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 514 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
521 } | 515 } |
522 | 516 |
523 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { | 517 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { |
524 SetupAndCreateTwoShortcuts(FROM_HERE); | 518 SetupAndCreateTwoShortcuts(FROM_HERE); |
525 | 519 |
526 const base::FilePath profile_2_shortcut_path_1 = | 520 const base::FilePath profile_2_shortcut_path_1 = |
527 GetDefaultShortcutPathForProfile(profile_2_name_); | 521 GetDefaultShortcutPathForProfile(profile_2_name_); |
528 const base::FilePath profile_2_shortcut_path_2 = | 522 const base::FilePath profile_2_shortcut_path_2 = |
529 GetUserShortcutsDirectory().Append(L"MyChrome.lnk"); | 523 GetUserShortcutsDirectory().Append(L"MyChrome.lnk"); |
530 // Make a copy of the shortcut. | 524 // Make a copy of the shortcut. |
531 ASSERT_TRUE(base::CopyFile(profile_2_shortcut_path_1, | 525 ASSERT_TRUE(base::CopyFile(profile_2_shortcut_path_1, |
532 profile_2_shortcut_path_2)); | 526 profile_2_shortcut_path_2)); |
533 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, | 527 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, |
534 profile_2_path_); | 528 profile_2_path_); |
535 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, | 529 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
536 profile_2_path_); | 530 profile_2_path_); |
537 | 531 |
538 // Also, copy the shortcut for the first user and ensure it gets preserved. | 532 // Also, copy the shortcut for the first user and ensure it gets preserved. |
539 const base::FilePath preserved_profile_1_shortcut_path = | 533 const base::FilePath preserved_profile_1_shortcut_path = |
540 GetUserShortcutsDirectory().Append(L"Preserved.lnk"); | 534 GetUserShortcutsDirectory().Append(L"Preserved.lnk"); |
541 ASSERT_TRUE(base::CopyFile( | 535 ASSERT_TRUE(base::CopyFile( |
542 GetDefaultShortcutPathForProfile(profile_1_name_), | 536 GetDefaultShortcutPathForProfile(profile_1_name_), |
543 preserved_profile_1_shortcut_path)); | 537 preserved_profile_1_shortcut_path)); |
544 EXPECT_TRUE(base::PathExists(preserved_profile_1_shortcut_path)); | 538 EXPECT_TRUE(base::PathExists(preserved_profile_1_shortcut_path)); |
545 | 539 |
546 // Delete the profile and ensure both shortcuts were also deleted. | 540 // Delete the profile and ensure both shortcuts were also deleted. |
547 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 541 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
548 RunPendingTasks(); | 542 base::RunLoop().RunUntilIdle(); |
549 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_1)); | 543 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_1)); |
550 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2)); | 544 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2)); |
551 ValidateNonProfileShortcutAtPath(FROM_HERE, | 545 ValidateNonProfileShortcutAtPath(FROM_HERE, |
552 preserved_profile_1_shortcut_path); | 546 preserved_profile_1_shortcut_path); |
553 } | 547 } |
554 | 548 |
555 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { | 549 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { |
556 SetupAndCreateTwoShortcuts(FROM_HERE); | 550 SetupAndCreateTwoShortcuts(FROM_HERE); |
557 | 551 |
558 const base::FilePath profile_2_shortcut_path_1 = | 552 const base::FilePath profile_2_shortcut_path_1 = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 ASSERT_TRUE(base::CopyFile(profile_2_shortcut_path_1, | 630 ASSERT_TRUE(base::CopyFile(profile_2_shortcut_path_1, |
637 profile_2_shortcut_path_2)); | 631 profile_2_shortcut_path_2)); |
638 ValidateProfileShortcutAtPath(FROM_HERE, profile_1_shortcut_path_2, | 632 ValidateProfileShortcutAtPath(FROM_HERE, profile_1_shortcut_path_2, |
639 profile_1_path_); | 633 profile_1_path_); |
640 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, | 634 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
641 profile_2_path_); | 635 profile_2_path_); |
642 | 636 |
643 // Delete shortcuts for profile 1 and ensure that they got deleted while the | 637 // Delete shortcuts for profile 1 and ensure that they got deleted while the |
644 // shortcuts for profile 2 were kept. | 638 // shortcuts for profile 2 were kept. |
645 profile_shortcut_manager_->RemoveProfileShortcuts(profile_1_path_); | 639 profile_shortcut_manager_->RemoveProfileShortcuts(profile_1_path_); |
646 RunPendingTasks(); | 640 base::RunLoop().RunUntilIdle(); |
647 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path_1)); | 641 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path_1)); |
648 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path_2)); | 642 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path_2)); |
649 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, | 643 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, |
650 profile_2_path_); | 644 profile_2_path_); |
651 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, | 645 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
652 profile_2_path_); | 646 profile_2_path_); |
653 } | 647 } |
654 | 648 |
655 TEST_F(ProfileShortcutManagerTest, HasProfileShortcuts) { | 649 TEST_F(ProfileShortcutManagerTest, HasProfileShortcuts) { |
656 SetupAndCreateTwoShortcuts(FROM_HERE); | 650 SetupAndCreateTwoShortcuts(FROM_HERE); |
657 | 651 |
658 struct HasShortcutsResult { | 652 struct HasShortcutsResult { |
659 bool has_shortcuts; | 653 bool has_shortcuts; |
660 void set_has_shortcuts(bool value) { has_shortcuts = value; } | 654 void set_has_shortcuts(bool value) { has_shortcuts = value; } |
661 } result = { false }; | 655 } result = { false }; |
662 | 656 |
663 const base::Callback<void(bool)> callback = | 657 const base::Callback<void(bool)> callback = |
664 base::Bind(&HasShortcutsResult::set_has_shortcuts, | 658 base::Bind(&HasShortcutsResult::set_has_shortcuts, |
665 base::Unretained(&result)); | 659 base::Unretained(&result)); |
666 | 660 |
667 // Profile 2 should have a shortcut initially. | 661 // Profile 2 should have a shortcut initially. |
668 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); | 662 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
669 RunPendingTasks(); | 663 base::RunLoop().RunUntilIdle(); |
670 EXPECT_TRUE(result.has_shortcuts); | 664 EXPECT_TRUE(result.has_shortcuts); |
671 | 665 |
672 // Delete the shortcut and check that the function returns false. | 666 // Delete the shortcut and check that the function returns false. |
673 const base::FilePath profile_2_shortcut_path = | 667 const base::FilePath profile_2_shortcut_path = |
674 GetDefaultShortcutPathForProfile(profile_2_name_); | 668 GetDefaultShortcutPathForProfile(profile_2_name_); |
675 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path, false)); | 669 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path, false)); |
676 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); | 670 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); |
677 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); | 671 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
678 RunPendingTasks(); | 672 base::RunLoop().RunUntilIdle(); |
679 EXPECT_FALSE(result.has_shortcuts); | 673 EXPECT_FALSE(result.has_shortcuts); |
680 } | 674 } |
681 | 675 |
682 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { | 676 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { |
683 const base::FilePath system_level_shortcut_path = | 677 const base::FilePath system_level_shortcut_path = |
684 CreateRegularSystemLevelShortcut(FROM_HERE); | 678 CreateRegularSystemLevelShortcut(FROM_HERE); |
685 | 679 |
686 // Create the initial profile. | 680 // Create the initial profile. |
687 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_, | 681 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_, |
688 std::string(), base::string16(), 0, | 682 std::string(), base::string16(), 0, |
689 std::string()); | 683 std::string()); |
690 RunPendingTasks(); | 684 base::RunLoop().RunUntilIdle(); |
691 ASSERT_EQ(1u, profile_attributes_storage_->GetNumberOfProfiles()); | 685 ASSERT_EQ(1u, profile_attributes_storage_->GetNumberOfProfiles()); |
692 | 686 |
693 // Ensure system-level continues to exist and user-level was not created. | 687 // Ensure system-level continues to exist and user-level was not created. |
694 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 688 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
695 EXPECT_FALSE(base::PathExists( | 689 EXPECT_FALSE(base::PathExists( |
696 GetDefaultShortcutPathForProfile(base::string16()))); | 690 GetDefaultShortcutPathForProfile(base::string16()))); |
697 | 691 |
698 // Create another profile with a shortcut and ensure both profiles receive | 692 // Create another profile with a shortcut and ensure both profiles receive |
699 // user-level profile shortcuts and the system-level one still exists. | 693 // user-level profile shortcuts and the system-level one still exists. |
700 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 694 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
701 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 695 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
702 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 696 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
703 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 697 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
704 | 698 |
705 // Create a third profile without a shortcut and ensure it doesn't get one. | 699 // Create a third profile without a shortcut and ensure it doesn't get one. |
706 profile_attributes_storage_->AddProfile(profile_3_path_, profile_3_name_, | 700 profile_attributes_storage_->AddProfile(profile_3_path_, profile_3_name_, |
707 std::string(), base::string16(), 0, | 701 std::string(), base::string16(), 0, |
708 std::string()); | 702 std::string()); |
709 RunPendingTasks(); | 703 base::RunLoop().RunUntilIdle(); |
710 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); | 704 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); |
711 | 705 |
712 // Ensure that changing the avatar icon and the name does not result in a | 706 // Ensure that changing the avatar icon and the name does not result in a |
713 // shortcut being created. | 707 // shortcut being created. |
714 ProfileAttributesEntry* entry_3; | 708 ProfileAttributesEntry* entry_3; |
715 ASSERT_TRUE(profile_attributes_storage_-> | 709 ASSERT_TRUE(profile_attributes_storage_-> |
716 GetProfileAttributesWithPath(profile_3_path_, &entry_3)); | 710 GetProfileAttributesWithPath(profile_3_path_, &entry_3)); |
717 entry_3->SetAvatarIconIndex(3u); | 711 entry_3->SetAvatarIconIndex(3u); |
718 RunPendingTasks(); | 712 base::RunLoop().RunUntilIdle(); |
719 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); | 713 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); |
720 | 714 |
721 const base::string16 new_profile_3_name = L"New Name 3"; | 715 const base::string16 new_profile_3_name = L"New Name 3"; |
722 entry_3->SetName(new_profile_3_name); | 716 entry_3->SetName(new_profile_3_name); |
723 RunPendingTasks(); | 717 base::RunLoop().RunUntilIdle(); |
724 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); | 718 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); |
725 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name)); | 719 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name)); |
726 | 720 |
727 // Rename the second profile and ensure its shortcut got renamed. | 721 // Rename the second profile and ensure its shortcut got renamed. |
728 const base::string16 new_profile_2_name = L"New Name 2"; | 722 const base::string16 new_profile_2_name = L"New Name 2"; |
729 ProfileAttributesEntry* entry_2; | 723 ProfileAttributesEntry* entry_2; |
730 ASSERT_TRUE(profile_attributes_storage_-> | 724 ASSERT_TRUE(profile_attributes_storage_-> |
731 GetProfileAttributesWithPath(profile_2_path_, &entry_2)); | 725 GetProfileAttributesWithPath(profile_2_path_, &entry_2)); |
732 entry_2->SetName(new_profile_2_name); | 726 entry_2->SetName(new_profile_2_name); |
733 RunPendingTasks(); | 727 base::RunLoop().RunUntilIdle(); |
734 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 728 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
735 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); | 729 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); |
736 } | 730 } |
737 | 731 |
738 TEST_F(ProfileShortcutManagerTest, | 732 TEST_F(ProfileShortcutManagerTest, |
739 DeleteSecondToLastProfileWithSystemLevelShortcut) { | 733 DeleteSecondToLastProfileWithSystemLevelShortcut) { |
740 SetupAndCreateTwoShortcuts(FROM_HERE); | 734 SetupAndCreateTwoShortcuts(FROM_HERE); |
741 | 735 |
742 const base::FilePath system_level_shortcut_path = | 736 const base::FilePath system_level_shortcut_path = |
743 CreateRegularSystemLevelShortcut(FROM_HERE); | 737 CreateRegularSystemLevelShortcut(FROM_HERE); |
744 | 738 |
745 // Delete a profile and verify that only the system-level shortcut still | 739 // Delete a profile and verify that only the system-level shortcut still |
746 // exists. | 740 // exists. |
747 profile_attributes_storage_->RemoveProfile(profile_1_path_); | 741 profile_attributes_storage_->RemoveProfile(profile_1_path_); |
748 RunPendingTasks(); | 742 base::RunLoop().RunUntilIdle(); |
749 | 743 |
750 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 744 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
751 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 745 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
752 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); | 746 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); |
753 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 747 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
754 } | 748 } |
755 | 749 |
756 TEST_F(ProfileShortcutManagerTest, | 750 TEST_F(ProfileShortcutManagerTest, |
757 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) { | 751 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) { |
758 SetupAndCreateTwoShortcuts(FROM_HERE); | 752 SetupAndCreateTwoShortcuts(FROM_HERE); |
759 | 753 |
760 const base::FilePath profile_1_shortcut_path = | 754 const base::FilePath profile_1_shortcut_path = |
761 GetDefaultShortcutPathForProfile(profile_1_name_); | 755 GetDefaultShortcutPathForProfile(profile_1_name_); |
762 const base::FilePath profile_2_shortcut_path = | 756 const base::FilePath profile_2_shortcut_path = |
763 GetDefaultShortcutPathForProfile(profile_2_name_); | 757 GetDefaultShortcutPathForProfile(profile_2_name_); |
764 | 758 |
765 // Delete the shortcut for the first profile, but keep the one for the 2nd. | 759 // Delete the shortcut for the first profile, but keep the one for the 2nd. |
766 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); | 760 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); |
767 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); | 761 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); |
768 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); | 762 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); |
769 | 763 |
770 const base::FilePath system_level_shortcut_path = | 764 const base::FilePath system_level_shortcut_path = |
771 CreateRegularSystemLevelShortcut(FROM_HERE); | 765 CreateRegularSystemLevelShortcut(FROM_HERE); |
772 | 766 |
773 // Delete the profile that has a shortcut, which will exercise the non-profile | 767 // Delete the profile that has a shortcut, which will exercise the non-profile |
774 // shortcut creation path in |DeleteDesktopShortcuts()|, which is | 768 // shortcut creation path in |DeleteDesktopShortcuts()|, which is |
775 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | 769 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. |
776 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 770 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
777 RunPendingTasks(); | 771 base::RunLoop().RunUntilIdle(); |
778 | 772 |
779 // Verify that only the system-level shortcut still exists. | 773 // Verify that only the system-level shortcut still exists. |
780 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 774 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
781 EXPECT_FALSE(base::PathExists( | 775 EXPECT_FALSE(base::PathExists( |
782 GetDefaultShortcutPathForProfile(base::string16()))); | 776 GetDefaultShortcutPathForProfile(base::string16()))); |
783 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); | 777 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); |
784 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); | 778 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); |
785 } | 779 } |
786 | 780 |
787 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) { | 781 TEST_F(ProfileShortcutManagerTest, CreateProfileIcon) { |
788 SetupDefaultProfileShortcut(FROM_HERE); | 782 SetupDefaultProfileShortcut(FROM_HERE); |
789 | 783 |
790 const base::FilePath icon_path = | 784 const base::FilePath icon_path = |
791 profiles::internal::GetProfileIconPath(profile_1_path_); | 785 profiles::internal::GetProfileIconPath(profile_1_path_); |
792 | 786 |
793 EXPECT_TRUE(base::PathExists(icon_path)); | 787 EXPECT_TRUE(base::PathExists(icon_path)); |
794 EXPECT_TRUE(base::DeleteFile(icon_path, false)); | 788 EXPECT_TRUE(base::DeleteFile(icon_path, false)); |
795 EXPECT_FALSE(base::PathExists(icon_path)); | 789 EXPECT_FALSE(base::PathExists(icon_path)); |
796 | 790 |
797 profile_shortcut_manager_->CreateOrUpdateProfileIcon(profile_1_path_); | 791 profile_shortcut_manager_->CreateOrUpdateProfileIcon(profile_1_path_); |
798 RunPendingTasks(); | 792 base::RunLoop().RunUntilIdle(); |
799 EXPECT_TRUE(base::PathExists(icon_path)); | 793 EXPECT_TRUE(base::PathExists(icon_path)); |
800 } | 794 } |
801 | 795 |
802 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) { | 796 TEST_F(ProfileShortcutManagerTest, UnbadgeProfileIconOnDeletion) { |
803 SetupDefaultProfileShortcut(FROM_HERE); | 797 SetupDefaultProfileShortcut(FROM_HERE); |
804 const base::FilePath icon_path_1 = | 798 const base::FilePath icon_path_1 = |
805 profiles::internal::GetProfileIconPath(profile_1_path_); | 799 profiles::internal::GetProfileIconPath(profile_1_path_); |
806 const base::FilePath icon_path_2 = | 800 const base::FilePath icon_path_2 = |
807 profiles::internal::GetProfileIconPath(profile_2_path_); | 801 profiles::internal::GetProfileIconPath(profile_2_path_); |
808 | 802 |
(...skipping 10 matching lines...) Expand all Loading... |
819 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); | 813 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); |
820 std::string badged_icon_2; | 814 std::string badged_icon_2; |
821 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); | 815 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); |
822 | 816 |
823 EXPECT_NE(badged_icon_1, unbadged_icon_1); | 817 EXPECT_NE(badged_icon_1, unbadged_icon_1); |
824 EXPECT_EQ(badged_icon_1, badged_icon_2); | 818 EXPECT_EQ(badged_icon_1, badged_icon_2); |
825 | 819 |
826 // Deleting the default profile will unbadge the new profile's icon and should | 820 // Deleting the default profile will unbadge the new profile's icon and should |
827 // result in an icon that is identical to the unbadged default profile icon. | 821 // result in an icon that is identical to the unbadged default profile icon. |
828 profile_attributes_storage_->RemoveProfile(profile_1_path_); | 822 profile_attributes_storage_->RemoveProfile(profile_1_path_); |
829 RunPendingTasks(); | 823 base::RunLoop().RunUntilIdle(); |
830 | 824 |
831 std::string unbadged_icon_2; | 825 std::string unbadged_icon_2; |
832 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &unbadged_icon_2)); | 826 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &unbadged_icon_2)); |
833 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); | 827 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); |
834 } | 828 } |
835 | 829 |
836 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { | 830 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { |
837 SetupAndCreateTwoShortcuts(FROM_HERE); | 831 SetupAndCreateTwoShortcuts(FROM_HERE); |
838 const base::FilePath icon_path_1 = | 832 const base::FilePath icon_path_1 = |
839 profiles::internal::GetProfileIconPath(profile_1_path_); | 833 profiles::internal::GetProfileIconPath(profile_1_path_); |
840 const base::FilePath icon_path_2 = | 834 const base::FilePath icon_path_2 = |
841 profiles::internal::GetProfileIconPath(profile_2_path_); | 835 profiles::internal::GetProfileIconPath(profile_2_path_); |
842 | 836 |
843 std::string badged_icon_1; | 837 std::string badged_icon_1; |
844 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); | 838 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); |
845 std::string badged_icon_2; | 839 std::string badged_icon_2; |
846 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); | 840 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); |
847 | 841 |
848 // Profile 1 and 2 are created with the same icon. | 842 // Profile 1 and 2 are created with the same icon. |
849 EXPECT_EQ(badged_icon_1, badged_icon_2); | 843 EXPECT_EQ(badged_icon_1, badged_icon_2); |
850 | 844 |
851 // Change profile 1's icon. | 845 // Change profile 1's icon. |
852 ProfileAttributesEntry* entry_1; | 846 ProfileAttributesEntry* entry_1; |
853 ASSERT_TRUE(profile_attributes_storage_-> | 847 ASSERT_TRUE(profile_attributes_storage_-> |
854 GetProfileAttributesWithPath(profile_1_path_, &entry_1)); | 848 GetProfileAttributesWithPath(profile_1_path_, &entry_1)); |
855 entry_1->SetAvatarIconIndex(1u); | 849 entry_1->SetAvatarIconIndex(1u); |
856 RunPendingTasks(); | 850 base::RunLoop().RunUntilIdle(); |
857 | 851 |
858 std::string new_badged_icon_1; | 852 std::string new_badged_icon_1; |
859 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &new_badged_icon_1)); | 853 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &new_badged_icon_1)); |
860 EXPECT_NE(new_badged_icon_1, badged_icon_1); | 854 EXPECT_NE(new_badged_icon_1, badged_icon_1); |
861 | 855 |
862 // Ensure the new icon is not the unbadged icon. | 856 // Ensure the new icon is not the unbadged icon. |
863 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 857 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
864 RunPendingTasks(); | 858 base::RunLoop().RunUntilIdle(); |
865 | 859 |
866 std::string unbadged_icon_1; | 860 std::string unbadged_icon_1; |
867 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1)); | 861 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1)); |
868 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); | 862 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); |
869 | 863 |
870 // Ensure the icon doesn't change on avatar change without 2 profiles. | 864 // Ensure the icon doesn't change on avatar change without 2 profiles. |
871 entry_1->SetAvatarIconIndex(1u); | 865 entry_1->SetAvatarIconIndex(1u); |
872 RunPendingTasks(); | 866 base::RunLoop().RunUntilIdle(); |
873 | 867 |
874 std::string unbadged_icon_1_a; | 868 std::string unbadged_icon_1_a; |
875 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); | 869 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); |
876 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); | 870 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); |
877 } | 871 } |
878 | 872 |
879 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameUniquified) { | 873 TEST_F(ProfileShortcutManagerTest, ShortcutFilenameUniquified) { |
880 const auto suffix = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | 874 const auto suffix = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
881 std::set<base::FilePath> excludes; | 875 std::set<base::FilePath> excludes; |
882 | 876 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 RenameProfile(FROM_HERE, profile_1_path_, new_profile_1_name); | 1002 RenameProfile(FROM_HERE, profile_1_path_, new_profile_1_name); |
1009 ValidateProfileShortcut(FROM_HERE, new_profile_1_name, profile_1_path_); | 1003 ValidateProfileShortcut(FROM_HERE, new_profile_1_name, profile_1_path_); |
1010 // Check that nothing is changed for profile2 and profile3. | 1004 // Check that nothing is changed for profile2 and profile3. |
1011 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 1005 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
1012 ValidateProfileShortcutAtPath(FROM_HERE, | 1006 ValidateProfileShortcutAtPath(FROM_HERE, |
1013 profile_3_shortcut_path, | 1007 profile_3_shortcut_path, |
1014 profile_3_path_); | 1008 profile_3_path_); |
1015 | 1009 |
1016 // Delete profile1. | 1010 // Delete profile1. |
1017 profile_attributes_storage_->RemoveProfile(profile_1_path_); | 1011 profile_attributes_storage_->RemoveProfile(profile_1_path_); |
1018 RunPendingTasks(); | 1012 base::RunLoop().RunUntilIdle(); |
1019 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_1_name)); | 1013 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_1_name)); |
1020 // Check that nothing is changed for profile2 and profile3. | 1014 // Check that nothing is changed for profile2 and profile3. |
1021 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 1015 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
1022 ValidateProfileShortcutAtPath(FROM_HERE, | 1016 ValidateProfileShortcutAtPath(FROM_HERE, |
1023 profile_3_shortcut_path, | 1017 profile_3_shortcut_path, |
1024 profile_3_path_); | 1018 profile_3_path_); |
1025 | 1019 |
1026 // Delete profile2. | 1020 // Delete profile2. |
1027 EXPECT_TRUE(base::PathExists( | 1021 EXPECT_TRUE(base::PathExists( |
1028 GetDefaultShortcutPathForProfile(profile_2_name_))); | 1022 GetDefaultShortcutPathForProfile(profile_2_name_))); |
1029 EXPECT_TRUE(base::PathExists(profile_3_shortcut_path)); | 1023 EXPECT_TRUE(base::PathExists(profile_3_shortcut_path)); |
1030 profile_attributes_storage_->RemoveProfile(profile_2_path_); | 1024 profile_attributes_storage_->RemoveProfile(profile_2_path_); |
1031 RunPendingTasks(); | 1025 base::RunLoop().RunUntilIdle(); |
1032 EXPECT_FALSE(base::PathExists( | 1026 EXPECT_FALSE(base::PathExists( |
1033 GetDefaultShortcutPathForProfile(profile_2_name_))); | 1027 GetDefaultShortcutPathForProfile(profile_2_name_))); |
1034 // Only profile3 exists. There should be non-profile shortcut only. | 1028 // Only profile3 exists. There should be non-profile shortcut only. |
1035 EXPECT_FALSE(base::PathExists(profile_3_shortcut_path)); | 1029 EXPECT_FALSE(base::PathExists(profile_3_shortcut_path)); |
1036 ValidateNonProfileShortcut(FROM_HERE); | 1030 ValidateNonProfileShortcut(FROM_HERE); |
1037 } | 1031 } |
OLD | NEW |