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 10 matching lines...) Expand all Loading... | |
27 | 28 |
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 } | 39 } |
40 | 40 |
41 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
42 CoInitialize(NULL); | 42 CoInitialize(NULL); |
43 distribution_ = BrowserDistribution::GetDistribution(); | 43 distribution_ = BrowserDistribution::GetDistribution(); |
44 ASSERT_TRUE(distribution_ != NULL); | 44 ASSERT_TRUE(distribution_ != NULL); |
45 | 45 |
46 TestingBrowserProcess* browser_process = | 46 TestingBrowserProcess* browser_process = |
47 TestingBrowserProcess::GetGlobal(); | 47 TestingBrowserProcess::GetGlobal(); |
48 profile_manager_.reset(new TestingProfileManager(browser_process)); | 48 profile_manager_.reset(new TestingProfileManager(browser_process)); |
49 ASSERT_TRUE(profile_manager_->SetUp()); | 49 ASSERT_TRUE(profile_manager_->SetUp()); |
50 profile_info_cache_ = profile_manager_->profile_info_cache(); | 50 profile_info_cache_ = profile_manager_->profile_info_cache(); |
51 profile_shortcut_manager_.reset( | 51 profile_shortcut_manager_.reset( |
52 ProfileShortcutManager::Create(profile_manager_->profile_manager())); | 52 ProfileShortcutManager::Create(profile_manager_->profile_manager())); |
53 | 53 |
54 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); | 54 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); |
55 fake_user_desktop_.reset( | |
sail
2013/01/14 21:45:19
Are you moving this here to ensure that it runs on
Alexei Svitkine (slow)
2013/01/14 22:40:24
Ah, that makes sense. Thanks for letting me know,
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
| |
56 new base::ScopedPathOverride(base::DIR_USER_DESKTOP)); | |
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 fake_system_desktop_.reset( |
sail
2013/01/14 21:45:19
same here
Alexei Svitkine (slow)
2013/01/15 22:03:02
Done.
| |
62 new base::ScopedPathOverride(base::DIR_COMMON_DESKTOP)); | |
63 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, | |
64 distribution_, | |
65 ShellUtil::SYSTEM_LEVEL, | |
66 &system_shortcuts_directory_)); | |
60 profile_1_name_ = L"My profile"; | 67 profile_1_name_ = L"My profile"; |
61 profile_1_path_ = CreateProfileDirectory(profile_1_name_); | 68 profile_1_path_ = CreateProfileDirectory(profile_1_name_); |
62 profile_2_name_ = L"My profile 2"; | 69 profile_2_name_ = L"My profile 2"; |
63 profile_2_path_ = CreateProfileDirectory(profile_2_name_); | 70 profile_2_path_ = CreateProfileDirectory(profile_2_name_); |
64 profile_3_name_ = L"My profile 3"; | 71 profile_3_name_ = L"My profile 3"; |
65 profile_3_path_ = CreateProfileDirectory(profile_3_name_); | 72 profile_3_path_ = CreateProfileDirectory(profile_3_name_); |
66 } | 73 } |
67 | 74 |
68 virtual void TearDown() OVERRIDE { | 75 virtual void TearDown() OVERRIDE { |
69 message_loop_.RunUntilIdle(); | 76 message_loop_.RunUntilIdle(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 product.AddDefaultShortcutProperties(exe_path_, &properties); | 216 product.AddDefaultShortcutProperties(exe_path_, &properties); |
210 properties.set_shortcut_name(shortcut_name); | 217 properties.set_shortcut_name(shortcut_name); |
211 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 218 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
212 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, | 219 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, |
213 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); | 220 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); |
214 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); | 221 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString(); |
215 | 222 |
216 return shortcut_path; | 223 return shortcut_path; |
217 } | 224 } |
218 | 225 |
226 FilePath CreateRegularSystemLevelShortcut( | |
227 const tracked_objects::Location& location) { | |
228 installer::Product product(distribution_); | |
229 ShellUtil::ShortcutProperties properties(ShellUtil::SYSTEM_LEVEL); | |
230 product.AddDefaultShortcutProperties(exe_path_, &properties); | |
231 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut( | |
232 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties, | |
233 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString(); | |
234 const FilePath system_level_shortcut_path = | |
235 system_shortcuts_directory_.Append(distribution_->GetAppShortCutName() + | |
236 installer::kLnkExt); | |
237 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)) | |
238 << location.ToString(); | |
239 return system_level_shortcut_path; | |
240 } | |
241 | |
219 void RenameProfile(const tracked_objects::Location& location, | 242 void RenameProfile(const tracked_objects::Location& location, |
220 const FilePath& profile_path, | 243 const FilePath& profile_path, |
221 const string16& new_profile_name) { | 244 const string16& new_profile_name) { |
222 const size_t profile_index = | 245 const size_t profile_index = |
223 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); | 246 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); |
224 ASSERT_NE(std::string::npos, profile_index); | 247 ASSERT_NE(std::string::npos, profile_index); |
225 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), | 248 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), |
226 new_profile_name); | 249 new_profile_name); |
227 profile_info_cache_->SetNameOfProfileAtIndex(profile_index, | 250 profile_info_cache_->SetNameOfProfileAtIndex(profile_index, |
228 new_profile_name); | 251 new_profile_name); |
229 RunPendingTasks(); | 252 RunPendingTasks(); |
230 } | 253 } |
231 | 254 |
232 BrowserDistribution* distribution_; | 255 BrowserDistribution* distribution_; |
233 MessageLoopForUI message_loop_; | 256 MessageLoopForUI message_loop_; |
234 content::TestBrowserThread ui_thread_; | 257 content::TestBrowserThread ui_thread_; |
235 content::TestBrowserThread file_thread_; | 258 content::TestBrowserThread file_thread_; |
236 scoped_ptr<TestingProfileManager> profile_manager_; | 259 scoped_ptr<TestingProfileManager> profile_manager_; |
237 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; | 260 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
238 ProfileInfoCache* profile_info_cache_; | 261 ProfileInfoCache* profile_info_cache_; |
239 base::ScopedPathOverride fake_user_desktop_; | |
240 FilePath exe_path_; | 262 FilePath exe_path_; |
263 scoped_ptr<base::ScopedPathOverride> fake_user_desktop_; | |
241 FilePath shortcuts_directory_; | 264 FilePath shortcuts_directory_; |
265 scoped_ptr<base::ScopedPathOverride> fake_system_desktop_; | |
266 FilePath system_shortcuts_directory_; | |
sail
2013/01/14 21:45:19
Ideally we shouldn't cache things in member variab
Alexei Svitkine (slow)
2013/01/14 22:40:24
Things are cached in member variables to make the
sail
2013/01/14 22:43:55
It's not too bad, GetFakeUserDesktop(). That's onl
| |
242 string16 profile_1_name_; | 267 string16 profile_1_name_; |
243 FilePath profile_1_path_; | 268 FilePath profile_1_path_; |
244 string16 profile_2_name_; | 269 string16 profile_2_name_; |
245 FilePath profile_2_path_; | 270 FilePath profile_2_path_; |
246 string16 profile_3_name_; | 271 string16 profile_3_name_; |
247 FilePath profile_3_path_; | 272 FilePath profile_3_path_; |
248 }; | 273 }; |
249 | 274 |
250 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { | 275 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { |
251 const string16 kProfileName = L"Harry"; | 276 const string16 kProfileName = L"Harry"; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 | 647 |
623 // Delete the shortcut and check that the function returns false. | 648 // Delete the shortcut and check that the function returns false. |
624 const FilePath profile_2_shortcut_path = | 649 const FilePath profile_2_shortcut_path = |
625 GetDefaultShortcutPathForProfile(profile_2_name_); | 650 GetDefaultShortcutPathForProfile(profile_2_name_); |
626 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); | 651 ASSERT_TRUE(file_util::Delete(profile_2_shortcut_path, false)); |
627 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | 652 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); |
628 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); | 653 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); |
629 RunPendingTasks(); | 654 RunPendingTasks(); |
630 EXPECT_FALSE(result.has_shortcuts); | 655 EXPECT_FALSE(result.has_shortcuts); |
631 } | 656 } |
657 | |
658 TEST_F(ProfileShortcutManagerTest, | |
659 ShortcutNotCreatedWhenSystemLevelShortcutExists) { | |
660 const FilePath system_level_shortcut_path = | |
661 CreateRegularSystemLevelShortcut(FROM_HERE); | |
662 | |
663 // Create the initial profile. | |
664 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, | |
665 string16(), 0, false); | |
666 RunPendingTasks(); | |
667 ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); | |
668 | |
669 // Ensure system level continues to exist and user level was not created. | |
670 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
671 EXPECT_FALSE(file_util::PathExists( | |
672 GetDefaultShortcutPathForProfile(string16()))); | |
673 } | |
674 | |
675 TEST_F(ProfileShortcutManagerTest, | |
676 DeleteSecondToLastProfileWithoutShortcutWhenSystemLevelShortcutExists) { | |
677 SetupAndCreateTwoShortcuts(FROM_HERE); | |
678 | |
679 const FilePath profile_1_shortcut_path = | |
680 GetDefaultShortcutPathForProfile(profile_1_name_); | |
681 const FilePath profile_2_shortcut_path = | |
682 GetDefaultShortcutPathForProfile(profile_2_name_); | |
683 | |
684 // Delete the shortcut for the first profile, but keep the one for the 2nd. | |
gab
2013/01/14 21:49:30
Why is it necessary to delete shortcut 1 first?
I
Alexei Svitkine (slow)
2013/01/14 22:40:24
These two tests are based on the existing tests De
gab
2013/01/14 22:49:55
Right that sgtm.
| |
685 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); | |
686 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
687 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | |
688 | |
689 const FilePath system_level_shortcut_path = | |
690 CreateRegularSystemLevelShortcut(FROM_HERE); | |
691 | |
692 // Delete the profile that doesn't have a shortcut. | |
693 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); | |
694 RunPendingTasks(); | |
695 | |
696 // Verify that only the system level shortcut still exists. | |
697 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
698 EXPECT_FALSE(file_util::PathExists( | |
699 GetDefaultShortcutPathForProfile(string16()))); | |
700 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
701 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | |
702 } | |
703 | |
704 TEST_F(ProfileShortcutManagerTest, | |
705 DeleteSecondToLastProfileWithShortcutWhenSystemShortcutLevelExists) { | |
706 SetupAndCreateTwoShortcuts(FROM_HERE); | |
707 | |
708 const FilePath profile_1_shortcut_path = | |
709 GetDefaultShortcutPathForProfile(profile_1_name_); | |
710 const FilePath profile_2_shortcut_path = | |
711 GetDefaultShortcutPathForProfile(profile_2_name_); | |
712 | |
713 // Delete the shortcut for the first profile, but keep the one for the 2nd. | |
714 ASSERT_TRUE(file_util::Delete(profile_1_shortcut_path, false)); | |
gab
2013/01/14 21:49:30
Same comment about why deleting shortcut 1? It pro
| |
715 ASSERT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
716 ASSERT_TRUE(file_util::PathExists(profile_2_shortcut_path)); | |
717 | |
718 const FilePath system_level_shortcut_path = | |
719 CreateRegularSystemLevelShortcut(FROM_HERE); | |
720 | |
721 // Delete the profile that has a shortcut. | |
722 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); | |
723 RunPendingTasks(); | |
724 | |
725 // Verify that only the system level shortcut still exists. | |
726 EXPECT_TRUE(file_util::PathExists(system_level_shortcut_path)); | |
727 EXPECT_FALSE(file_util::PathExists( | |
728 GetDefaultShortcutPathForProfile(string16()))); | |
729 EXPECT_FALSE(file_util::PathExists(profile_1_shortcut_path)); | |
730 EXPECT_FALSE(file_util::PathExists(profile_2_shortcut_path)); | |
731 } | |
OLD | NEW |