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" |
11 #include "base/win/shortcut.h" | 11 #include "base/win/shortcut.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 14 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/installer/util/browser_distribution.h" | 16 #include "chrome/installer/util/browser_distribution.h" |
16 #include "chrome/installer/util/shell_util.h" | 17 #include "chrome/installer/util/shell_util.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_pref_service.h" | 19 #include "chrome/test/base/testing_pref_service.h" |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
(...skipping 30 matching lines...) Expand all Loading... |
55 } // namespace | 56 } // namespace |
56 | 57 |
57 class ProfileShortcutManagerTest : public testing::Test { | 58 class ProfileShortcutManagerTest : public testing::Test { |
58 protected: | 59 protected: |
59 ProfileShortcutManagerTest() | 60 ProfileShortcutManagerTest() |
60 : ui_thread_(BrowserThread::UI, &message_loop_), | 61 : ui_thread_(BrowserThread::UI, &message_loop_), |
61 file_thread_(BrowserThread::FILE, &message_loop_) { | 62 file_thread_(BrowserThread::FILE, &message_loop_) { |
62 } | 63 } |
63 | 64 |
64 virtual void SetUp() { | 65 virtual void SetUp() { |
| 66 // Mock the user's Desktop into a temp directory. |
| 67 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); |
| 68 EXPECT_TRUE(PathService::Override(chrome::DIR_USER_DESKTOP, |
| 69 fake_user_desktop_.path())); |
| 70 |
65 TestingBrowserProcess* browser_process = | 71 TestingBrowserProcess* browser_process = |
66 static_cast<TestingBrowserProcess*>(g_browser_process); | 72 static_cast<TestingBrowserProcess*>(g_browser_process); |
67 profile_manager_.reset(new TestingProfileManager(browser_process)); | 73 profile_manager_.reset(new TestingProfileManager(browser_process)); |
68 ASSERT_TRUE(profile_manager_->SetUp()); | 74 ASSERT_TRUE(profile_manager_->SetUp()); |
69 | 75 |
70 dest_path_ = profile_manager_->profile_info_cache()->GetUserDataDir(); | 76 dest_path_ = profile_manager_->profile_info_cache()->GetUserDataDir(); |
71 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); | 77 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile")); |
72 file_util::CreateDirectoryW(dest_path_); | 78 file_util::CreateDirectoryW(dest_path_); |
73 profile_name_ = ASCIIToUTF16("My profile"); | 79 profile_name_ = ASCIIToUTF16("My profile"); |
74 | 80 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 147 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
142 VerifyProfileShortcut(profile_name_)); | 148 VerifyProfileShortcut(profile_name_)); |
143 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 149 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
144 VerifyProfileShortcut(second_profile_name_)); | 150 VerifyProfileShortcut(second_profile_name_)); |
145 } | 151 } |
146 | 152 |
147 MessageLoopForUI message_loop_; | 153 MessageLoopForUI message_loop_; |
148 content::TestBrowserThread ui_thread_; | 154 content::TestBrowserThread ui_thread_; |
149 content::TestBrowserThread file_thread_; | 155 content::TestBrowserThread file_thread_; |
150 scoped_ptr<TestingProfileManager> profile_manager_; | 156 scoped_ptr<TestingProfileManager> profile_manager_; |
| 157 ScopedTempDir fake_user_desktop_; |
151 FilePath dest_path_; | 158 FilePath dest_path_; |
152 string16 profile_name_; | 159 string16 profile_name_; |
153 FilePath second_dest_path_; | 160 FilePath second_dest_path_; |
154 string16 second_profile_name_; | 161 string16 second_profile_name_; |
155 }; | 162 }; |
156 | 163 |
157 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { | 164 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { |
158 if (!profile_manager_->profile_manager()->profile_shortcut_manager()) | 165 if (!profile_manager_->profile_manager()->profile_shortcut_manager()) |
159 return; | 166 return; |
160 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); | 167 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 VerifyProfileShortcut(second_profile_name_)); | 265 VerifyProfileShortcut(second_profile_name_)); |
259 | 266 |
260 // Verify that the original shortcut received the profile's name | 267 // Verify that the original shortcut received the profile's name |
261 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 268 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
262 VerifyProfileShortcut(profile_name_)); | 269 VerifyProfileShortcut(profile_name_)); |
263 // Verify that a default shortcut no longer exists | 270 // Verify that a default shortcut no longer exists |
264 EXPECT_EQ(base::win::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND, | 271 EXPECT_EQ(base::win::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND, |
265 VerifyProfileShortcut(string16())); | 272 VerifyProfileShortcut(string16())); |
266 } | 273 } |
267 | 274 |
OLD | NEW |