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 <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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); | 560 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome"); |
561 | 561 |
562 // Add another profile and check that one shortcut was renamed and that the | 562 // Add another profile and check that one shortcut was renamed and that the |
563 // other shortcut was updated but kept the same name. | 563 // other shortcut was updated but kept the same name. |
564 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 564 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
565 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); | 565 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path)); |
566 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, | 566 ValidateProfileShortcutAtPath(FROM_HERE, customized_regular_shortcut_path, |
567 profile_1_path_); | 567 profile_1_path_); |
568 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 568 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
569 } | 569 } |
| 570 |
| 571 TEST_F(ProfileShortcutManagerTest, RemoveProfileShortcuts) { |
| 572 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 573 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_); |
| 574 |
| 575 const FilePath profile_1_shortcut_path_1 = |
| 576 GetDefaultShortcutPathForProfile(profile_1_name_); |
| 577 const FilePath profile_2_shortcut_path_1 = |
| 578 GetDefaultShortcutPathForProfile(profile_2_name_); |
| 579 |
| 580 // Make copies of the shortcuts for both profiles. |
| 581 const FilePath profile_1_shortcut_path_2 = |
| 582 shortcuts_directory_.Append(L"Copied1.lnk"); |
| 583 const FilePath profile_2_shortcut_path_2 = |
| 584 shortcuts_directory_.Append(L"Copied2.lnk"); |
| 585 ASSERT_TRUE(file_util::CopyFile(profile_1_shortcut_path_1, |
| 586 profile_1_shortcut_path_2)); |
| 587 ASSERT_TRUE(file_util::CopyFile(profile_2_shortcut_path_1, |
| 588 profile_2_shortcut_path_2)); |
| 589 ValidateProfileShortcutAtPath(FROM_HERE, profile_1_shortcut_path_2, |
| 590 profile_1_path_); |
| 591 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 592 profile_2_path_); |
| 593 |
| 594 // Delete shortcuts for profile 1 and ensure that they got deleted while the |
| 595 // shortcuts for profile 2 were kept. |
| 596 profile_shortcut_manager_->RemoveProfileShortcuts(profile_1_path_); |
| 597 RunPendingTasks(); |
| 598 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path_1)); |
| 599 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path_2)); |
| 600 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_1, |
| 601 profile_2_path_); |
| 602 ValidateProfileShortcutAtPath(FROM_HERE, profile_2_shortcut_path_2, |
| 603 profile_2_path_); |
| 604 } |
| 605 |
| 606 TEST_F(ProfileShortcutManagerTest, HasProfileShortcuts) { |
| 607 SetupAndCreateTwoShortcuts(FROM_HERE); |
| 608 |
| 609 struct HasShortcutsResult { |
| 610 bool has_shortcuts; |
| 611 void set_has_shortcuts(bool value) { has_shortcuts = value; } |
| 612 } result = { false }; |
| 613 |
| 614 const base::Callback<void(bool)> callback = |
| 615 base::Bind(&HasShortcutsResult::set_has_shortcuts, |
| 616 base::Unretained(&result)); |
| 617 |
| 618 // Profile 2 should have a shortcut initially. |
| 619 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
| 620 RunPendingTasks(); |
| 621 EXPECT_TRUE(result.has_shortcuts); |
| 622 |
| 623 // Delete the shortcut and check that the function returns false. |
| 624 const FilePath profile_2_shortcut_path = |
| 625 GetDefaultShortcutPathForProfile(profile_2_name_); |
| 626 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); |
| 627 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
| 628 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
| 629 RunPendingTasks(); |
| 630 EXPECT_FALSE(result.has_shortcuts); |
| 631 } |
OLD | NEW |