| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/test/test_shortcut_win.h" | 10 #include "base/test/test_shortcut_win.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 class ProfileShortcutManagerTest : public testing::Test { | 57 class ProfileShortcutManagerTest : public testing::Test { |
| 58 protected: | 58 protected: |
| 59 ProfileShortcutManagerTest() | 59 ProfileShortcutManagerTest() |
| 60 : ui_thread_(BrowserThread::UI, &message_loop_), | 60 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 61 file_thread_(BrowserThread::FILE, &message_loop_) { | 61 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() { |
| 65 // Mock the user's Desktop into a temp directory. | |
| 66 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); | |
| 67 ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP, | |
| 68 fake_user_desktop_.path())); | |
| 69 | |
| 70 TestingBrowserProcess* browser_process = | 65 TestingBrowserProcess* browser_process = |
| 71 static_cast<TestingBrowserProcess*>(g_browser_process); | 66 static_cast<TestingBrowserProcess*>(g_browser_process); |
| 72 profile_manager_.reset(new TestingProfileManager(browser_process)); | 67 profile_manager_.reset(new TestingProfileManager(browser_process)); |
| 73 ASSERT_TRUE(profile_manager_->SetUp()); | 68 ASSERT_TRUE(profile_manager_->SetUp()); |
| 74 | 69 |
| 75 dest_path_ = profile_manager_->profile_info_cache()->GetUserDataDir(); | 70 dest_path_ = profile_manager_->profile_info_cache()->GetUserDataDir(); |
| 76 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); | 71 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); |
| 77 file_util::CreateDirectoryW(dest_path_); | 72 file_util::CreateDirectoryW(dest_path_); |
| 78 profile_name_ = ASCIIToUTF16("My profile"); | 73 profile_name_ = ASCIIToUTF16("My profile"); |
| 79 | 74 |
| 80 second_dest_path_ = | 75 second_dest_path_ = |
| 81 profile_manager_->profile_info_cache()->GetUserDataDir(); | 76 profile_manager_->profile_info_cache()->GetUserDataDir(); |
| 82 second_dest_path_ = | 77 second_dest_path_ = |
| 83 second_dest_path_.Append(FILE_PATH_LITERAL("My profile 2")); | 78 second_dest_path_.Append(FILE_PATH_LITERAL("My profile 2")); |
| 84 file_util::CreateDirectoryW(second_dest_path_); | 79 file_util::CreateDirectoryW(second_dest_path_); |
| 85 second_profile_name_ = ASCIIToUTF16("My profile 2"); | 80 second_profile_name_ = ASCIIToUTF16("My profile 2"); |
| 86 } | 81 } |
| 87 | 82 |
| 88 virtual void TearDown() OVERRIDE { | 83 virtual void TearDown() { |
| 89 message_loop_.RunAllPending(); | 84 message_loop_.RunAllPending(); |
| 90 | 85 |
| 91 int num_profiles = | 86 int num_profiles = |
| 92 profile_manager_->profile_info_cache()->GetNumberOfProfiles(); | 87 profile_manager_->profile_info_cache()->GetNumberOfProfiles(); |
| 93 | 88 |
| 94 // Remove all shortcuts except the last (since it will no longer have | 89 // Remove all shortcuts except the last (since it will no longer have |
| 95 // an appended name). | 90 // an appended name). |
| 96 for (int i = 0; i < num_profiles; ++i) { | 91 for (int i = 0; i < num_profiles; ++i) { |
| 97 const FilePath profile_path = | 92 const FilePath profile_path = |
| 98 profile_manager_->profile_info_cache()->GetPathOfProfileAtIndex(0); | 93 profile_manager_->profile_info_cache()->GetPathOfProfileAtIndex(0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 141 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
| 147 VerifyProfileShortcut(profile_name_)); | 142 VerifyProfileShortcut(profile_name_)); |
| 148 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 143 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
| 149 VerifyProfileShortcut(second_profile_name_)); | 144 VerifyProfileShortcut(second_profile_name_)); |
| 150 } | 145 } |
| 151 | 146 |
| 152 MessageLoopForUI message_loop_; | 147 MessageLoopForUI message_loop_; |
| 153 content::TestBrowserThread ui_thread_; | 148 content::TestBrowserThread ui_thread_; |
| 154 content::TestBrowserThread file_thread_; | 149 content::TestBrowserThread file_thread_; |
| 155 scoped_ptr<TestingProfileManager> profile_manager_; | 150 scoped_ptr<TestingProfileManager> profile_manager_; |
| 156 ScopedTempDir fake_user_desktop_; | |
| 157 FilePath dest_path_; | 151 FilePath dest_path_; |
| 158 string16 profile_name_; | 152 string16 profile_name_; |
| 159 FilePath second_dest_path_; | 153 FilePath second_dest_path_; |
| 160 string16 second_profile_name_; | 154 string16 second_profile_name_; |
| 161 }; | 155 }; |
| 162 | 156 |
| 163 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { | 157 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { |
| 164 if (!profile_manager_->profile_manager()->profile_shortcut_manager()) | 158 if (!profile_manager_->profile_manager()->profile_shortcut_manager()) |
| 165 return; | 159 return; |
| 166 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 160 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 VerifyProfileShortcut(second_profile_name_)); | 258 VerifyProfileShortcut(second_profile_name_)); |
| 265 | 259 |
| 266 // Verify that the original shortcut received the profile's name | 260 // Verify that the original shortcut received the profile's name |
| 267 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 261 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
| 268 VerifyProfileShortcut(profile_name_)); | 262 VerifyProfileShortcut(profile_name_)); |
| 269 // Verify that a default shortcut no longer exists | 263 // Verify that a default shortcut no longer exists |
| 270 EXPECT_EQ(base::win::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND, | 264 EXPECT_EQ(base::win::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND, |
| 271 VerifyProfileShortcut(string16())); | 265 VerifyProfileShortcut(string16())); |
| 272 } | 266 } |
| 273 | 267 |
| OLD | NEW |