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

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

Issue 16950028: Move file_util::Delete to the base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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
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/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) { 385 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) {
386 SetupAndCreateTwoShortcuts(FROM_HERE); 386 SetupAndCreateTwoShortcuts(FROM_HERE);
387 387
388 const base::FilePath profile_1_shortcut_path = 388 const base::FilePath profile_1_shortcut_path =
389 GetDefaultShortcutPathForProfile(profile_1_name_); 389 GetDefaultShortcutPathForProfile(profile_1_name_);
390 const base::FilePath profile_2_shortcut_path = 390 const base::FilePath profile_2_shortcut_path =
391 GetDefaultShortcutPathForProfile(profile_2_name_); 391 GetDefaultShortcutPathForProfile(profile_2_name_);
392 392
393 // Delete the shortcut for the first profile, but keep the one for the 2nd. 393 // Delete the shortcut for the first profile, but keep the one for the 2nd.
394 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); 394 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false));
395 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 395 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path));
396 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); 396 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path));
397 397
398 // Delete the profile that doesn't have a shortcut. 398 // Delete the profile that doesn't have a shortcut.
399 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); 399 profile_info_cache_->DeleteProfileFromCache(profile_1_path_);
400 RunPendingTasks(); 400 RunPendingTasks();
401 401
402 // Verify that the remaining shortcut does not have a profile name. 402 // Verify that the remaining shortcut does not have a profile name.
403 ValidateNonProfileShortcut(FROM_HERE); 403 ValidateNonProfileShortcut(FROM_HERE);
404 // Verify that shortcuts with profile names do not exist. 404 // Verify that shortcuts with profile names do not exist.
405 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 405 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path));
406 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 406 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
407 } 407 }
408 408
409 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) { 409 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) {
410 SetupAndCreateTwoShortcuts(FROM_HERE); 410 SetupAndCreateTwoShortcuts(FROM_HERE);
411 411
412 const base::FilePath profile_1_shortcut_path = 412 const base::FilePath profile_1_shortcut_path =
413 GetDefaultShortcutPathForProfile(profile_1_name_); 413 GetDefaultShortcutPathForProfile(profile_1_name_);
414 const base::FilePath profile_2_shortcut_path = 414 const base::FilePath profile_2_shortcut_path =
415 GetDefaultShortcutPathForProfile(profile_2_name_); 415 GetDefaultShortcutPathForProfile(profile_2_name_);
416 416
417 // Delete the shortcut for the first profile, but keep the one for the 2nd. 417 // Delete the shortcut for the first profile, but keep the one for the 2nd.
418 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); 418 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false));
419 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 419 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path));
420 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); 420 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path));
421 421
422 // Delete the profile that has a shortcut. 422 // Delete the profile that has a shortcut.
423 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 423 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
424 RunPendingTasks(); 424 RunPendingTasks();
425 425
426 // Verify that the remaining shortcut does not have a profile name. 426 // Verify that the remaining shortcut does not have a profile name.
427 ValidateNonProfileShortcut(FROM_HERE); 427 ValidateNonProfileShortcut(FROM_HERE);
428 // Verify that shortcuts with profile names do not exist. 428 // Verify that shortcuts with profile names do not exist.
429 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 429 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path));
430 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 430 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
431 } 431 }
432 432
433 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { 433 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) {
434 SetupAndCreateTwoShortcuts(FROM_HERE); 434 SetupAndCreateTwoShortcuts(FROM_HERE);
435 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_); 435 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_);
436 436
437 const base::FilePath non_profile_shortcut_path = 437 const base::FilePath non_profile_shortcut_path =
438 GetDefaultShortcutPathForProfile(string16()); 438 GetDefaultShortcutPathForProfile(string16());
439 const base::FilePath profile_1_shortcut_path = 439 const base::FilePath profile_1_shortcut_path =
440 GetDefaultShortcutPathForProfile(profile_1_name_); 440 GetDefaultShortcutPathForProfile(profile_1_name_);
441 const base::FilePath profile_2_shortcut_path = 441 const base::FilePath profile_2_shortcut_path =
442 GetDefaultShortcutPathForProfile(profile_2_name_); 442 GetDefaultShortcutPathForProfile(profile_2_name_);
443 const base::FilePath profile_3_shortcut_path = 443 const base::FilePath profile_3_shortcut_path =
444 GetDefaultShortcutPathForProfile(profile_3_name_); 444 GetDefaultShortcutPathForProfile(profile_3_name_);
445 445
446 // Delete shortcuts for the first two profiles. 446 // Delete shortcuts for the first two profiles.
447 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); 447 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false));
448 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); 448 ASSERT_TRUE(base::Delete(profile_2_shortcut_path, false));
449 449
450 // Only the shortcut to the third profile should exist. 450 // Only the shortcut to the third profile should exist.
451 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 451 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path));
452 ASSERT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 452 ASSERT_FALSE(file_util::PathExists(profile_2_shortcut_path));
453 ASSERT_FALSE(file_util::PathExists(non_profile_shortcut_path)); 453 ASSERT_FALSE(file_util::PathExists(non_profile_shortcut_path));
454 ASSERT_TRUE(file_util::PathExists(profile_3_shortcut_path)); 454 ASSERT_TRUE(file_util::PathExists(profile_3_shortcut_path));
455 455
456 // Delete the third profile and check that its shortcut is gone and no 456 // Delete the third profile and check that its shortcut is gone and no
457 // shortcuts have been re-created. 457 // shortcuts have been re-created.
458 profile_info_cache_->DeleteProfileFromCache(profile_3_path_); 458 profile_info_cache_->DeleteProfileFromCache(profile_3_path_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 profile_2_shortcut_path_2)); 496 profile_2_shortcut_path_2));
497 497
498 // Ensure that a new shortcut does not get made if the old one was renamed. 498 // Ensure that a new shortcut does not get made if the old one was renamed.
499 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); 499 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_);
500 RunPendingTasks(); 500 RunPendingTasks();
501 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 501 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
502 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, 502 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2,
503 profile_2_path_); 503 profile_2_path_);
504 504
505 // Delete the renamed shortcut and try to create it again, which should work. 505 // Delete the renamed shortcut and try to create it again, which should work.
506 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path_2, false)); 506 ASSERT_TRUE(base::Delete(profile_2_shortcut_path_2, false));
507 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_2)); 507 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path_2));
508 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_); 508 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_);
509 RunPendingTasks(); 509 RunPendingTasks();
510 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 510 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
511 } 511 }
512 512
513 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { 513 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) {
514 SetupAndCreateTwoShortcuts(FROM_HERE); 514 SetupAndCreateTwoShortcuts(FROM_HERE);
515 515
516 const base::FilePath profile_2_shortcut_path_1 = 516 const base::FilePath profile_2_shortcut_path_1 =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, 567 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2,
568 profile_2_path_); 568 profile_2_path_);
569 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); 569 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
570 } 570 }
571 571
572 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) { 572 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) {
573 SetupDefaultProfileShortcut(FROM_HERE); 573 SetupDefaultProfileShortcut(FROM_HERE);
574 574
575 // Delete the shortcut that got created for this profile and instead make 575 // Delete the shortcut that got created for this profile and instead make
576 // a new one without any command-line flags. 576 // a new one without any command-line flags.
577 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), 577 ASSERT_TRUE(base::Delete(GetDefaultShortcutPathForProfile(string16()),
578 false)); 578 false));
579 const base::FilePath regular_shortcut_path = 579 const base::FilePath regular_shortcut_path =
580 CreateRegularShortcutWithName(FROM_HERE, 580 CreateRegularShortcutWithName(FROM_HERE,
581 GetDistribution()->GetAppShortCutName()); 581 GetDistribution()->GetAppShortCutName());
582 582
583 // Add another profile and check that the shortcut was replaced with 583 // Add another profile and check that the shortcut was replaced with
584 // a badged shortcut with the right command line for the profile 584 // a badged shortcut with the right command line for the profile
585 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 585 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
586 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); 586 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
587 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 587 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
588 } 588 }
589 589
590 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) { 590 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) {
591 SetupDefaultProfileShortcut(FROM_HERE); 591 SetupDefaultProfileShortcut(FROM_HERE);
592 592
593 // Delete the shortcut that got created for this profile and instead make 593 // Delete the shortcut that got created for this profile and instead make
594 // two new ones without any command-line flags. 594 // two new ones without any command-line flags.
595 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()), 595 ASSERT_TRUE(base::Delete(GetDefaultShortcutPathForProfile(string16()),
596 false)); 596 false));
597 const base::FilePath regular_shortcut_path = 597 const base::FilePath regular_shortcut_path =
598 CreateRegularShortcutWithName(FROM_HERE, 598 CreateRegularShortcutWithName(FROM_HERE,
599 GetDistribution()->GetAppShortCutName()); 599 GetDistribution()->GetAppShortCutName());
600 const base::FilePath customized_regular_shortcut_path = 600 const base::FilePath customized_regular_shortcut_path =
601 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); 601 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome");
602 602
603 // Add another profile and check that one shortcut was renamed and that the 603 // Add another profile and check that one shortcut was renamed and that the
604 // other shortcut was updated but kept the same name. 604 // other shortcut was updated but kept the same name.
605 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 605 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 base::Unretained(&result)); 657 base::Unretained(&result));
658 658
659 // Profile 2 should have a shortcut initially. 659 // Profile 2 should have a shortcut initially.
660 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); 660 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback);
661 RunPendingTasks(); 661 RunPendingTasks();
662 EXPECT_TRUE(result.has_shortcuts); 662 EXPECT_TRUE(result.has_shortcuts);
663 663
664 // Delete the shortcut and check that the function returns false. 664 // Delete the shortcut and check that the function returns false.
665 const base::FilePath profile_2_shortcut_path = 665 const base::FilePath profile_2_shortcut_path =
666 GetDefaultShortcutPathForProfile(profile_2_name_); 666 GetDefaultShortcutPathForProfile(profile_2_name_);
667 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); 667 ASSERT_TRUE(base::Delete(profile_2_shortcut_path, false));
668 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 668 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
669 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); 669 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback);
670 RunPendingTasks(); 670 RunPendingTasks();
671 EXPECT_FALSE(result.has_shortcuts); 671 EXPECT_FALSE(result.has_shortcuts);
672 } 672 }
673 673
674 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { 674 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) {
675 const base::FilePath system_level_shortcut_path = 675 const base::FilePath system_level_shortcut_path =
676 CreateRegularSystemLevelShortcut(FROM_HERE); 676 CreateRegularSystemLevelShortcut(FROM_HERE);
677 677
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 TEST_F(ProfileShortcutManagerTest, 745 TEST_F(ProfileShortcutManagerTest,
746 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) { 746 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) {
747 SetupAndCreateTwoShortcuts(FROM_HERE); 747 SetupAndCreateTwoShortcuts(FROM_HERE);
748 748
749 const base::FilePath profile_1_shortcut_path = 749 const base::FilePath profile_1_shortcut_path =
750 GetDefaultShortcutPathForProfile(profile_1_name_); 750 GetDefaultShortcutPathForProfile(profile_1_name_);
751 const base::FilePath profile_2_shortcut_path = 751 const base::FilePath profile_2_shortcut_path =
752 GetDefaultShortcutPathForProfile(profile_2_name_); 752 GetDefaultShortcutPathForProfile(profile_2_name_);
753 753
754 // Delete the shortcut for the first profile, but keep the one for the 2nd. 754 // Delete the shortcut for the first profile, but keep the one for the 2nd.
755 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); 755 ASSERT_TRUE(base::Delete(profile_1_shortcut_path, false));
756 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 756 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path));
757 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); 757 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path));
758 758
759 const base::FilePath system_level_shortcut_path = 759 const base::FilePath system_level_shortcut_path =
760 CreateRegularSystemLevelShortcut(FROM_HERE); 760 CreateRegularSystemLevelShortcut(FROM_HERE);
761 761
762 // Delete the profile that has a shortcut, which will exercise the non-profile 762 // Delete the profile that has a shortcut, which will exercise the non-profile
763 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is 763 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is
764 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. 764 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test.
765 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 765 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
766 RunPendingTasks(); 766 RunPendingTasks();
767 767
768 // Verify that only the system-level shortcut still exists. 768 // Verify that only the system-level shortcut still exists.
769 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); 769 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path));
770 EXPECT_FALSE(file_util::PathExists( 770 EXPECT_FALSE(file_util::PathExists(
771 GetDefaultShortcutPathForProfile(string16()))); 771 GetDefaultShortcutPathForProfile(string16())));
772 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); 772 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path));
773 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); 773 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path));
774 } 774 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/profiles/profile_shortcut_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698