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/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/location.h" | 9 #include "base/location.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/test/scoped_path_override.h" | 12 #include "base/test/scoped_path_override.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/test/test_shortcut_win.h" | 14 #include "base/test/test_shortcut_win.h" |
14 #include "base/win/shortcut.h" | 15 #include "base/win/shortcut.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
28 using content::BrowserThread; | 29 using content::BrowserThread; |
29 | 30 |
30 class ProfileShortcutManagerTest : public testing::Test { | 31 class ProfileShortcutManagerTest : public testing::Test { |
31 protected: | 32 protected: |
32 ProfileShortcutManagerTest() | 33 ProfileShortcutManagerTest() |
33 : distribution_(NULL), | 34 : distribution_(NULL), |
34 ui_thread_(BrowserThread::UI, &message_loop_), | 35 ui_thread_(BrowserThread::UI, &message_loop_), |
35 file_thread_(BrowserThread::FILE, &message_loop_), | 36 file_thread_(BrowserThread::FILE, &message_loop_), |
36 profile_shortcut_manager_(NULL), | 37 profile_shortcut_manager_(NULL), |
37 profile_info_cache_(NULL), | 38 profile_info_cache_(NULL), |
38 fake_user_desktop_(base::DIR_USER_DESKTOP) { | 39 fake_user_desktop_(base::DIR_USER_DESKTOP), |
40 fake_system_desktop_(base::DIR_COMMON_DESKTOP) { | |
39 } | 41 } |
40 | 42 |
41 virtual void SetUp() OVERRIDE { | 43 virtual void SetUp() OVERRIDE { |
42 CoInitialize(NULL); | 44 CoInitialize(NULL); |
43 distribution_ = BrowserDistribution::GetDistribution(); | 45 distribution_ = BrowserDistribution::GetDistribution(); |
44 ASSERT_TRUE(distribution_ != NULL); | 46 ASSERT_TRUE(distribution_ != NULL); |
45 | 47 |
46 TestingBrowserProcess* browser_process = | 48 TestingBrowserProcess* browser_process = |
47 TestingBrowserProcess::GetGlobal(); | 49 TestingBrowserProcess::GetGlobal(); |
48 profile_manager_.reset(new TestingProfileManager(browser_process)); | 50 profile_manager_.reset(new TestingProfileManager(browser_process)); |
49 ASSERT_TRUE(profile_manager_->SetUp()); | 51 ASSERT_TRUE(profile_manager_->SetUp()); |
50 profile_info_cache_ = profile_manager_->profile_info_cache(); | 52 profile_info_cache_ = profile_manager_->profile_info_cache(); |
51 profile_shortcut_manager_.reset( | 53 profile_shortcut_manager_.reset( |
52 ProfileShortcutManager::Create(profile_manager_->profile_manager())); | 54 ProfileShortcutManager::Create(profile_manager_->profile_manager())); |
53 | 55 |
54 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); | 56 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); |
55 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 57 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
56 distribution_, | 58 distribution_, |
57 ShellUtil::CURRENT_USER, | 59 ShellUtil::CURRENT_USER, |
58 &shortcuts_directory_)); | 60 &shortcuts_directory_)); |
59 | 61 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
62 distribution_, | |
63 ShellUtil::SYSTEM_LEVEL, | |
64 &system_shortcuts_directory_)); | |
60 profile_1_name_ = L"My profile"; | 65 profile_1_name_ = L"My profile"; |
61 profile_1_path_ = CreateProfileDirectory(profile_1_name_); | 66 profile_1_path_ = CreateProfileDirectory(profile_1_name_); |
62 profile_2_name_ = L"My profile 2"; | 67 profile_2_name_ = L"My profile 2"; |
63 profile_2_path_ = CreateProfileDirectory(profile_2_name_); | 68 profile_2_path_ = CreateProfileDirectory(profile_2_name_); |
64 profile_3_name_ = L"My profile 3"; | 69 profile_3_name_ = L"My profile 3"; |
65 profile_3_path_ = CreateProfileDirectory(profile_3_name_); | 70 profile_3_path_ = CreateProfileDirectory(profile_3_name_); |
66 } | 71 } |
67 | 72 |
68 virtual void TearDown() OVERRIDE { | 73 virtual void TearDown() OVERRIDE { |
69 message_loop_.RunUntilIdle(); | 74 message_loop_.RunUntilIdle(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 product.AddDefaultShortcutProperties(exe_path_, &properties); | 214 product.AddDefaultShortcutProperties(exe_path_, &properties); |
210 properties.set_shortcut_name(shortcut_name); | 215 properties.set_shortcut_name(shortcut_name); |
211 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 216 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
212 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, | 217 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, |
213 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); | 218 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); |
214 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); | 219 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
215 | 220 |
216 return shortcut_path; | 221 return shortcut_path; |
217 } | 222 } |
218 | 223 |
224 FilePath CreateRegularSystemLevelShortcut( | |
225 const tracked_objects::Location& location) { | |
226 installer::Product product(distribution_); | |
227 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); | |
228 product.AddDefaultShortcutProperties(exe_path_, &properties); | |
229 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | |
230 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, | |
231 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); | |
232 const FilePath system_level_shortcut_path = | |
233 system_shortcuts_directory_.Append(distribution_->GetAppShortCutName() + | |
234 installer::kLnkExt); | |
235 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)) | |
236 << location.ToString(); | |
237 return system_level_shortcut_path; | |
238 } | |
239 | |
219 void RenameProfile(const tracked_objects::Location& location, | 240 void RenameProfile(const tracked_objects::Location& location, |
220 const FilePath& profile_path, | 241 const FilePath& profile_path, |
221 const string16& new_profile_name) { | 242 const string16& new_profile_name) { |
222 const size_t profile_index = | 243 const size_t profile_index = |
223 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); | 244 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); |
224 ASSERT_NE(std::string::npos, profile_index); | 245 ASSERT_NE(std::string::npos, profile_index); |
225 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), | 246 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), |
226 new_profile_name); | 247 new_profile_name); |
227 profile_info_cache_->SetNameOfProfileAtIndex(profile_index, | 248 profile_info_cache_->SetNameOfProfileAtIndex(profile_index, |
228 new_profile_name); | 249 new_profile_name); |
229 RunPendingTasks(); | 250 RunPendingTasks(); |
230 } | 251 } |
231 | 252 |
232 BrowserDistribution* distribution_; | 253 BrowserDistribution* distribution_; |
233 MessageLoopForUI message_loop_; | 254 MessageLoopForUI message_loop_; |
234 content::TestBrowserThread ui_thread_; | 255 content::TestBrowserThread ui_thread_; |
235 content::TestBrowserThread file_thread_; | 256 content::TestBrowserThread file_thread_; |
236 scoped_ptr<TestingProfileManager> profile_manager_; | 257 scoped_ptr<TestingProfileManager> profile_manager_; |
237 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; | 258 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
238 ProfileInfoCache* profile_info_cache_; | 259 ProfileInfoCache* profile_info_cache_; |
260 FilePath exe_path_; | |
239 base::ScopedPathOverride fake_user_desktop_; | 261 base::ScopedPathOverride fake_user_desktop_; |
240 FilePath exe_path_; | |
241 FilePath shortcuts_directory_; | 262 FilePath shortcuts_directory_; |
263 base::ScopedPathOverride fake_system_desktop_; | |
264 FilePath system_shortcuts_directory_; | |
242 string16 profile_1_name_; | 265 string16 profile_1_name_; |
243 FilePath profile_1_path_; | 266 FilePath profile_1_path_; |
244 string16 profile_2_name_; | 267 string16 profile_2_name_; |
245 FilePath profile_2_path_; | 268 FilePath profile_2_path_; |
246 string16 profile_3_name_; | 269 string16 profile_3_name_; |
247 FilePath profile_3_path_; | 270 FilePath profile_3_path_; |
248 }; | 271 }; |
249 | 272 |
250 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { | 273 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { |
251 const string16 kProfileName = L"Harry"; | 274 const string16 kProfileName = L"Harry"; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | 405 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); |
383 RunPendingTasks(); | 406 RunPendingTasks(); |
384 | 407 |
385 // Verify that the remaining shortcut does not have a profile name. | 408 // Verify that the remaining shortcut does not have a profile name. |
386 ValidateNonProfileShortcut(FROM_HERE); | 409 ValidateNonProfileShortcut(FROM_HERE); |
387 // Verify that shortcuts with profile names do not exist. | 410 // Verify that shortcuts with profile names do not exist. |
388 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | 411 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); |
389 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 412 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
390 } | 413 } |
391 | 414 |
392 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { | 415 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { |
gab
2013/01/15 23:09:14
Is this really the desired outcome (i.e. that if t
Alexei Svitkine (slow)
2013/01/15 23:34:43
If there's *three* (or more) profiles and only one
gab
2013/01/16 17:44:00
Ah, awesome :)!
| |
393 SetupAndCreateTwoShortcuts(FROM_HERE); | 416 SetupAndCreateTwoShortcuts(FROM_HERE); |
394 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_); | 417 CreateProfileWithShortcut(FROM_HERE, profile_3_name_, profile_3_path_); |
395 | 418 |
396 const FilePath non_profile_shortcut_path = | 419 const FilePath non_profile_shortcut_path = |
397 GetDefaultShortcutPathForProfile(string16()); | 420 GetDefaultShortcutPathForProfile(string16()); |
398 const FilePath profile_1_shortcut_path = | 421 const FilePath profile_1_shortcut_path = |
399 GetDefaultShortcutPathForProfile(profile_1_name_); | 422 GetDefaultShortcutPathForProfile(profile_1_name_); |
400 const FilePath profile_2_shortcut_path = | 423 const FilePath profile_2_shortcut_path = |
401 GetDefaultShortcutPathForProfile(profile_2_name_); | 424 GetDefaultShortcutPathForProfile(profile_2_name_); |
402 const FilePath profile_3_shortcut_path = | 425 const FilePath profile_3_shortcut_path = |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 | 645 |
623 // Delete the shortcut and check that the function returns false. | 646 // Delete the shortcut and check that the function returns false. |
624 const FilePath profile_2_shortcut_path = | 647 const FilePath profile_2_shortcut_path = |
625 GetDefaultShortcutPathForProfile(profile_2_name_); | 648 GetDefaultShortcutPathForProfile(profile_2_name_); |
626 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); | 649 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); |
627 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 650 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
628 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); | 651 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
629 RunPendingTasks(); | 652 RunPendingTasks(); |
630 EXPECT_FALSE(result.has_shortcuts); | 653 EXPECT_FALSE(result.has_shortcuts); |
631 } | 654 } |
655 | |
656 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { | |
657 const FilePath system_level_shortcut_path = | |
658 CreateRegularSystemLevelShortcut(FROM_HERE); | |
659 | |
660 // Create the initial profile. | |
661 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, | |
662 string16(), 0, false); | |
663 RunPendingTasks(); | |
664 ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); | |
665 | |
666 // Ensure system level continues to exist and user level was not created. | |
gab
2013/01/15 23:09:14
nit: We tend to write "system-level" with a dash a
Alexei Svitkine (slow)
2013/01/16 16:11:44
Done.
| |
667 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
668 EXPECT_FALSE(file_util::PathExists( | |
669 GetDefaultShortcutPathForProfile(string16()))); | |
670 | |
671 // Create another profile with a shortcut and ensure both profiles receive | |
672 // user level profile shortcuts and the system level one still exists. | |
673 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | |
674 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); | |
675 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); | |
676 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
677 } | |
678 | |
679 TEST_F(ProfileShortcutManagerTest, | |
680 DeleteSecondToLastProfileWithSystemLevelShortcut) { | |
681 SetupAndCreateTwoShortcuts(FROM_HERE); | |
682 | |
683 const FilePath system_level_shortcut_path = | |
684 CreateRegularSystemLevelShortcut(FROM_HERE); | |
685 | |
686 // Delete a profile and verify that only the system level shortcut still | |
687 // exists. | |
688 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); | |
689 RunPendingTasks(); | |
690 | |
691 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
692 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); | |
693 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); | |
694 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); | |
695 } | |
696 | |
697 TEST_F(ProfileShortcutManagerTest, | |
698 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) { | |
699 SetupAndCreateTwoShortcuts(FROM_HERE); | |
700 | |
701 const FilePath profile_1_shortcut_path = | |
702 GetDefaultShortcutPathForProfile(profile_1_name_); | |
703 const FilePath profile_2_shortcut_path = | |
704 GetDefaultShortcutPathForProfile(profile_2_name_); | |
705 | |
706 // Delete the shortcut for the first profile, but keep the one for the 2nd. | |
707 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); | |
708 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
709 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | |
710 | |
711 const FilePath system_level_shortcut_path = | |
712 CreateRegularSystemLevelShortcut(FROM_HERE); | |
713 | |
714 // Delete the profile that has a shortcut, which will exercise the non-profile | |
715 // shortcut creation path in |DeleteDesktopShortcutsAndIconFile()|, which is | |
716 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. | |
717 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | |
718 RunPendingTasks(); | |
719 | |
720 // Verify that only the system level shortcut still exists. | |
721 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
722 EXPECT_FALSE(file_util::PathExists( | |
723 GetDefaultShortcutPathForProfile(string16()))); | |
724 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
725 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | |
726 } | |
OLD | NEW |