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/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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 base::MessageLoop::QuitClosure()); | 91 base::MessageLoop::QuitClosure()); |
92 base::MessageLoop::current()->Run(); | 92 base::MessageLoop::current()->Run(); |
93 } | 93 } |
94 | 94 |
95 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { | 95 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { |
96 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()) | 96 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()) |
97 << location.ToString(); | 97 << location.ToString(); |
98 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) | 98 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) |
99 << location.ToString(); | 99 << location.ToString(); |
100 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, | 100 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, |
101 base::string16(), 0, std::string()); | 101 std::string(), base::string16(), 0, |
| 102 std::string()); |
102 // Also create a non-badged shortcut for Chrome, which is conveniently done | 103 // Also create a non-badged shortcut for Chrome, which is conveniently done |
103 // by |CreateProfileShortcut()| since there is only one profile. | 104 // by |CreateProfileShortcut()| since there is only one profile. |
104 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_); | 105 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_); |
105 RunPendingTasks(); | 106 RunPendingTasks(); |
106 // Verify that there's now a shortcut with no profile information. | 107 // Verify that there's now a shortcut with no profile information. |
107 ValidateNonProfileShortcut(location); | 108 ValidateNonProfileShortcut(location); |
108 } | 109 } |
109 | 110 |
110 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { | 111 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { |
111 SetupDefaultProfileShortcut(location); | 112 SetupDefaultProfileShortcut(location); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 GetDefaultShortcutPathForProfile(base::string16()); | 180 GetDefaultShortcutPathForProfile(base::string16()); |
180 ValidateNonProfileShortcutAtPath(location, shortcut_path); | 181 ValidateNonProfileShortcutAtPath(location, shortcut_path); |
181 } | 182 } |
182 | 183 |
183 void CreateProfileWithShortcut(const tracked_objects::Location& location, | 184 void CreateProfileWithShortcut(const tracked_objects::Location& location, |
184 const base::string16& profile_name, | 185 const base::string16& profile_name, |
185 const base::FilePath& profile_path) { | 186 const base::FilePath& profile_path) { |
186 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) | 187 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) |
187 << location.ToString(); | 188 << location.ToString(); |
188 profile_info_cache_->AddProfileToCache(profile_path, profile_name, | 189 profile_info_cache_->AddProfileToCache(profile_path, profile_name, |
189 base::string16(), 0, std::string()); | 190 std::string(), base::string16(), 0, |
| 191 std::string()); |
190 profile_shortcut_manager_->CreateProfileShortcut(profile_path); | 192 profile_shortcut_manager_->CreateProfileShortcut(profile_path); |
191 RunPendingTasks(); | 193 RunPendingTasks(); |
192 ValidateProfileShortcut(location, profile_name, profile_path); | 194 ValidateProfileShortcut(location, profile_name, profile_path); |
193 } | 195 } |
194 | 196 |
195 // Creates a regular (non-profile) desktop shortcut with the given name and | 197 // Creates a regular (non-profile) desktop shortcut with the given name and |
196 // returns its path. Fails the test if an error occurs. | 198 // returns its path. Fails the test if an error occurs. |
197 base::FilePath CreateRegularShortcutWithName( | 199 base::FilePath CreateRegularShortcutWithName( |
198 const tracked_objects::Location& location, | 200 const tracked_objects::Location& location, |
199 const base::string16& shortcut_name) { | 201 const base::string16& shortcut_name) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); | 359 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); |
358 } | 360 } |
359 | 361 |
360 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) { | 362 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) { |
361 SetupDefaultProfileShortcut(FROM_HERE); | 363 SetupDefaultProfileShortcut(FROM_HERE); |
362 // Assert that a shortcut without a profile name exists. | 364 // Assert that a shortcut without a profile name exists. |
363 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 365 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
364 | 366 |
365 // Create a second profile without a shortcut. | 367 // Create a second profile without a shortcut. |
366 profile_info_cache_->AddProfileToCache(profile_2_path_, profile_2_name_, | 368 profile_info_cache_->AddProfileToCache(profile_2_path_, profile_2_name_, |
367 base::string16(), 0, std::string()); | 369 std::string(), base::string16(), 0, |
| 370 std::string()); |
368 RunPendingTasks(); | 371 RunPendingTasks(); |
369 | 372 |
370 // Ensure that the second profile doesn't have a shortcut and that the first | 373 // Ensure that the second profile doesn't have a shortcut and that the first |
371 // profile's shortcut got renamed and badged. | 374 // profile's shortcut got renamed and badged. |
372 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | 375 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); |
373 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); | 376 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); |
374 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 377 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
375 } | 378 } |
376 | 379 |
377 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { | 380 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 RunPendingTasks(); | 682 RunPendingTasks(); |
680 EXPECT_FALSE(result.has_shortcuts); | 683 EXPECT_FALSE(result.has_shortcuts); |
681 } | 684 } |
682 | 685 |
683 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { | 686 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { |
684 const base::FilePath system_level_shortcut_path = | 687 const base::FilePath system_level_shortcut_path = |
685 CreateRegularSystemLevelShortcut(FROM_HERE); | 688 CreateRegularSystemLevelShortcut(FROM_HERE); |
686 | 689 |
687 // Create the initial profile. | 690 // Create the initial profile. |
688 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, | 691 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, |
689 base::string16(), 0, std::string()); | 692 std::string(), base::string16(), 0, |
| 693 std::string()); |
690 RunPendingTasks(); | 694 RunPendingTasks(); |
691 ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); | 695 ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); |
692 | 696 |
693 // Ensure system-level continues to exist and user-level was not created. | 697 // Ensure system-level continues to exist and user-level was not created. |
694 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 698 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
695 EXPECT_FALSE(base::PathExists( | 699 EXPECT_FALSE(base::PathExists( |
696 GetDefaultShortcutPathForProfile(base::string16()))); | 700 GetDefaultShortcutPathForProfile(base::string16()))); |
697 | 701 |
698 // Create another profile with a shortcut and ensure both profiles receive | 702 // Create another profile with a shortcut and ensure both profiles receive |
699 // user-level profile shortcuts and the system-level one still exists. | 703 // user-level profile shortcuts and the system-level one still exists. |
700 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 704 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
701 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | 705 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); |
702 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | 706 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); |
703 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); | 707 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); |
704 | 708 |
705 // Create a third profile without a shortcut and ensure it doesn't get one. | 709 // Create a third profile without a shortcut and ensure it doesn't get one. |
706 profile_info_cache_->AddProfileToCache(profile_3_path_, profile_3_name_, | 710 profile_info_cache_->AddProfileToCache(profile_3_path_, profile_3_name_, |
707 base::string16(), 0, std::string()); | 711 std::string(), base::string16(), 0, |
| 712 std::string()); |
708 RunPendingTasks(); | 713 RunPendingTasks(); |
709 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); | 714 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); |
710 | 715 |
711 // Ensure that changing the avatar icon and the name does not result in a | 716 // Ensure that changing the avatar icon and the name does not result in a |
712 // shortcut being created. | 717 // shortcut being created. |
713 profile_info_cache_->SetAvatarIconOfProfileAtIndex( | 718 profile_info_cache_->SetAvatarIconOfProfileAtIndex( |
714 profile_info_cache_->GetIndexOfProfileWithPath(profile_3_path_), 3); | 719 profile_info_cache_->GetIndexOfProfileWithPath(profile_3_path_), 3); |
715 RunPendingTasks(); | 720 RunPendingTasks(); |
716 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); | 721 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); |
717 | 722 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); | 870 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); |
866 | 871 |
867 // Ensure the icon doesn't change on avatar change without 2 profiles. | 872 // Ensure the icon doesn't change on avatar change without 2 profiles. |
868 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); | 873 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); |
869 RunPendingTasks(); | 874 RunPendingTasks(); |
870 | 875 |
871 std::string unbadged_icon_1_a; | 876 std::string unbadged_icon_1_a; |
872 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); | 877 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); |
873 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); | 878 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); |
874 } | 879 } |
OLD | NEW |