OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 #include <shellapi.h> | 6 #include <shellapi.h> |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include <fstream> | 9 #include <fstream> |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Create an executable in test path by copying ourself to it. | 102 // Create an executable in test path by copying ourself to it. |
103 wchar_t exe_full_path_str[MAX_PATH]; | 103 wchar_t exe_full_path_str[MAX_PATH]; |
104 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 104 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
105 FilePath exe_full_path(exe_full_path_str); | 105 FilePath exe_full_path(exe_full_path_str); |
106 | 106 |
107 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 107 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
108 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 108 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
109 | 109 |
110 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 110 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
111 const std::wstring description(L"dummy description"); | 111 const std::wstring description(L"dummy description"); |
112 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), | 112 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, |
| 113 exe_path.value(), |
113 shortcut_path.value(), | 114 shortcut_path.value(), |
114 description, true)); | 115 L"", |
| 116 description, |
| 117 true)); |
115 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 118 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
116 shortcut_path.value(), | 119 shortcut_path.value(), |
117 description, 0)); | 120 description, 0)); |
118 | 121 |
119 // Now specify an icon index in master prefs and make sure it works. | 122 // Now specify an icon index in master prefs and make sure it works. |
120 FilePath prefs_path = temp_dir_.path().AppendASCII( | 123 FilePath prefs_path = temp_dir_.path().AppendASCII( |
121 installer::kDefaultMasterPrefs); | 124 installer::kDefaultMasterPrefs); |
122 std::ofstream file; | 125 std::ofstream file; |
123 file.open(prefs_path.value().c_str()); | 126 file.open(prefs_path.value().c_str()); |
124 ASSERT_TRUE(file.is_open()); | 127 ASSERT_TRUE(file.is_open()); |
125 file << | 128 file << |
126 "{" | 129 "{" |
127 " \"distribution\":{" | 130 " \"distribution\":{" |
128 " \"chrome_shortcut_icon_index\" : 1" | 131 " \"chrome_shortcut_icon_index\" : 1" |
129 " }" | 132 " }" |
130 "}"; | 133 "}"; |
131 file.close(); | 134 file.close(); |
132 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); | 135 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); |
133 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), | 136 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, |
| 137 exe_path.value(), |
134 shortcut_path.value(), | 138 shortcut_path.value(), |
135 description, true)); | 139 L"", |
| 140 description, |
| 141 true)); |
136 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 142 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
137 shortcut_path.value(), | 143 shortcut_path.value(), |
138 description, 1)); | 144 description, 1)); |
139 | 145 |
140 // Now change only description to update shortcut and make sure icon index | 146 // Now change only description to update shortcut and make sure icon index |
141 // doesn't change. | 147 // doesn't change. |
142 const std::wstring description2(L"dummy description 2"); | 148 const std::wstring description2(L"dummy description 2"); |
143 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), | 149 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, |
| 150 exe_path.value(), |
144 shortcut_path.value(), | 151 shortcut_path.value(), |
145 description2, false)); | 152 L"", |
| 153 description2, |
| 154 false)); |
146 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 155 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
147 shortcut_path.value(), | 156 shortcut_path.value(), |
148 description2, 1)); | 157 description2, 1)); |
149 } | 158 } |
150 | 159 |
151 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { | 160 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { |
152 // Run this test on Vista+ only if we are running elevated. | 161 // Run this test on Vista+ only if we are running elevated. |
153 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | 162 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { |
154 LOG(ERROR) << "Must be admin to run this test on Vista+"; | 163 LOG(ERROR) << "Must be admin to run this test on Vista+"; |
155 return; | 164 return; |
(...skipping 10 matching lines...) Expand all Loading... |
166 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 175 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
167 | 176 |
168 const std::wstring description(L"dummy description"); | 177 const std::wstring description(L"dummy description"); |
169 | 178 |
170 FilePath user_desktop_path; | 179 FilePath user_desktop_path; |
171 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); | 180 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); |
172 FilePath system_desktop_path; | 181 FilePath system_desktop_path; |
173 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); | 182 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); |
174 | 183 |
175 std::wstring shortcut_name; | 184 std::wstring shortcut_name; |
176 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)); | 185 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, L"", |
| 186 &shortcut_name)); |
| 187 |
| 188 std::wstring default_profile_shortcut_name; |
| 189 const std::wstring default_profile_user_name = L"Minsk"; |
| 190 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, |
| 191 default_profile_user_name, |
| 192 &default_profile_shortcut_name)); |
| 193 |
| 194 std::wstring second_profile_shortcut_name; |
| 195 const std::wstring second_profile_user_name = L"Pinsk"; |
| 196 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, |
| 197 second_profile_user_name, |
| 198 &second_profile_shortcut_name)); |
177 | 199 |
178 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); | 200 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); |
179 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); | 201 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); |
| 202 FilePath default_profile_shortcut_path = user_desktop_path.Append( |
| 203 default_profile_shortcut_name); |
| 204 FilePath second_profile_shortcut_path = user_desktop_path.Append( |
| 205 second_profile_shortcut_name); |
180 | 206 |
181 // Test simple creation of a user-level shortcut. | 207 // Test simple creation of a user-level shortcut. |
182 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, | 208 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, |
183 exe_path.value(), | 209 exe_path.value(), |
184 description, | 210 description, |
| 211 L"", |
| 212 L"", |
185 ShellUtil::CURRENT_USER, | 213 ShellUtil::CURRENT_USER, |
186 false, | 214 false, |
187 true)); | 215 true)); |
188 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 216 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
189 user_shortcut_path.value(), | 217 user_shortcut_path.value(), |
190 description, | 218 description, |
191 0)); | 219 0)); |
192 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, | 220 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, |
193 ShellUtil::CURRENT_USER, | 221 ShellUtil::CURRENT_USER, |
194 false)); | 222 false)); |
195 | 223 |
196 // Test simple creation of a system-level shortcut. | 224 // Test simple creation of a system-level shortcut. |
197 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, | 225 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, |
198 exe_path.value(), | 226 exe_path.value(), |
199 description, | 227 description, |
| 228 L"", |
| 229 L"", |
200 ShellUtil::SYSTEM_LEVEL, | 230 ShellUtil::SYSTEM_LEVEL, |
201 false, | 231 false, |
202 true)); | 232 true)); |
203 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 233 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
204 system_shortcut_path.value(), | 234 system_shortcut_path.value(), |
205 description, | 235 description, |
206 0)); | 236 0)); |
207 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, | 237 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, |
208 ShellUtil::SYSTEM_LEVEL, | 238 ShellUtil::SYSTEM_LEVEL, |
209 false)); | 239 false)); |
210 | 240 |
211 // Test creation of a user-level shortcut when a system-level shortcut | 241 // Test creation of a user-level shortcut when a system-level shortcut |
212 // is already present (should fail). | 242 // is already present (should fail). |
213 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, | 243 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, |
214 exe_path.value(), | 244 exe_path.value(), |
215 description, | 245 description, |
| 246 L"", |
| 247 L"", |
216 ShellUtil::SYSTEM_LEVEL, | 248 ShellUtil::SYSTEM_LEVEL, |
217 false, | 249 false, |
218 true)); | 250 true)); |
219 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist, | 251 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist, |
220 exe_path.value(), | 252 exe_path.value(), |
221 description, | 253 description, |
| 254 L"", |
| 255 L"", |
222 ShellUtil::CURRENT_USER, | 256 ShellUtil::CURRENT_USER, |
223 false, | 257 false, |
224 true)); | 258 true)); |
225 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 259 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
226 system_shortcut_path.value(), | 260 system_shortcut_path.value(), |
227 description, | 261 description, |
228 0)); | 262 0)); |
229 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); | 263 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); |
230 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, | 264 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, |
231 ShellUtil::SYSTEM_LEVEL, | 265 ShellUtil::SYSTEM_LEVEL, |
232 false)); | 266 false)); |
233 | 267 |
234 // Test creation of a system-level shortcut when a user-level shortcut | 268 // Test creation of a system-level shortcut when a user-level shortcut |
235 // is already present (should succeed). | 269 // is already present (should succeed). |
236 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, | 270 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, |
237 exe_path.value(), | 271 exe_path.value(), |
238 description, | 272 description, |
| 273 L"", |
| 274 L"", |
239 ShellUtil::CURRENT_USER, | 275 ShellUtil::CURRENT_USER, |
240 false, | 276 false, |
241 true)); | 277 true)); |
242 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, | 278 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, |
243 exe_path.value(), | 279 exe_path.value(), |
244 description, | 280 description, |
| 281 L"", |
| 282 L"", |
245 ShellUtil::SYSTEM_LEVEL, | 283 ShellUtil::SYSTEM_LEVEL, |
246 false, | 284 false, |
247 true)); | 285 true)); |
248 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 286 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
249 user_shortcut_path.value(), | 287 user_shortcut_path.value(), |
250 description, | 288 description, |
251 0)); | 289 0)); |
252 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 290 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
253 system_shortcut_path.value(), | 291 system_shortcut_path.value(), |
254 description, | 292 description, |
255 0)); | 293 0)); |
256 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, | 294 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, |
257 ShellUtil::CURRENT_USER, | 295 ShellUtil::CURRENT_USER, |
258 false)); | 296 false)); |
259 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, | 297 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, |
260 ShellUtil::SYSTEM_LEVEL, | 298 ShellUtil::SYSTEM_LEVEL, |
261 false)); | 299 false)); |
| 300 |
| 301 // Test creation of two profile-specific shortcuts (these are always |
| 302 // user-level). |
| 303 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 304 dist, |
| 305 exe_path.value(), |
| 306 description, |
| 307 default_profile_user_name, |
| 308 L"--profile-directory=\"Default\"", |
| 309 ShellUtil::CURRENT_USER, |
| 310 false, |
| 311 true)); |
| 312 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 313 default_profile_shortcut_path.value(), |
| 314 description, |
| 315 0)); |
| 316 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 317 dist, |
| 318 exe_path.value(), |
| 319 description, |
| 320 second_profile_user_name, |
| 321 L"--profile-directory=\"Profile 1\"", |
| 322 ShellUtil::CURRENT_USER, |
| 323 false, |
| 324 true)); |
| 325 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 326 second_profile_shortcut_path.value(), |
| 327 description, |
| 328 0)); |
| 329 std::vector<string16> profile_names; |
| 330 profile_names.push_back(default_profile_shortcut_name); |
| 331 profile_names.push_back(second_profile_shortcut_name); |
| 332 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
| 333 profile_names)); |
262 } | 334 } |
OLD | NEW |