Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: chrome/installer/util/shell_util_unittest.cc

Issue 8785006: Badge Windows profile shortcuts with multi-user avatar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merged to TOT. Fixed cpu's nits. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | ui/gfx/icon_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 112 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist,
113 exe_path.value(), 113 exe_path.value(),
114 shortcut_path.value(), 114 shortcut_path.value(),
115 L"", 115 L"",
116 description, 116 description,
117 exe_path.value(),
118 dist->GetIconIndex(),
117 true)); 119 true));
118 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 120 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
119 shortcut_path.value(), 121 shortcut_path.value(),
120 description, 0)); 122 description, 0));
121 123
122 // Now specify an icon index in master prefs and make sure it works. 124 // Now specify an icon index in master prefs and make sure it works.
123 FilePath prefs_path = temp_dir_.path().AppendASCII( 125 FilePath prefs_path = temp_dir_.path().AppendASCII(
124 installer::kDefaultMasterPrefs); 126 installer::kDefaultMasterPrefs);
125 std::ofstream file; 127 std::ofstream file;
126 file.open(prefs_path.value().c_str()); 128 file.open(prefs_path.value().c_str());
127 ASSERT_TRUE(file.is_open()); 129 ASSERT_TRUE(file.is_open());
128 file << 130 file <<
129 "{" 131 "{"
130 " \"distribution\":{" 132 " \"distribution\":{"
131 " \"chrome_shortcut_icon_index\" : 1" 133 " \"chrome_shortcut_icon_index\" : 1"
132 " }" 134 " }"
133 "}"; 135 "}";
134 file.close(); 136 file.close();
135 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); 137 ASSERT_TRUE(file_util::Delete(shortcut_path, false));
136 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, 138 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist,
137 exe_path.value(), 139 exe_path.value(),
138 shortcut_path.value(), 140 shortcut_path.value(),
139 L"", 141 L"",
140 description, 142 description,
143 exe_path.value(),
144 dist->GetIconIndex(),
141 true)); 145 true));
142 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 146 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
143 shortcut_path.value(), 147 shortcut_path.value(),
144 description, 1)); 148 description, 1));
145 149
146 // Now change only description to update shortcut and make sure icon index 150 // Now change only description to update shortcut and make sure icon index
147 // doesn't change. 151 // doesn't change.
148 const std::wstring description2(L"dummy description 2"); 152 const std::wstring description2(L"dummy description 2");
149 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, 153 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist,
150 exe_path.value(), 154 exe_path.value(),
151 shortcut_path.value(), 155 shortcut_path.value(),
152 L"", 156 L"",
153 description2, 157 description2,
158 exe_path.value(),
159 dist->GetIconIndex(),
154 false)); 160 false));
155 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 161 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
156 shortcut_path.value(), 162 shortcut_path.value(),
157 description2, 1)); 163 description2, 1));
158 } 164 }
159 165
160 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { 166 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) {
161 // Run this test on Vista+ only if we are running elevated. 167 // Run this test on Vista+ only if we are running elevated.
162 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { 168 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) {
163 LOG(ERROR) << "Must be admin to run this test on Vista+"; 169 LOG(ERROR) << "Must be admin to run this test on Vista+";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 default_profile_shortcut_name); 209 default_profile_shortcut_name);
204 FilePath second_profile_shortcut_path = user_desktop_path.Append( 210 FilePath second_profile_shortcut_path = user_desktop_path.Append(
205 second_profile_shortcut_name); 211 second_profile_shortcut_name);
206 212
207 // Test simple creation of a user-level shortcut. 213 // Test simple creation of a user-level shortcut.
208 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, 214 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist,
209 exe_path.value(), 215 exe_path.value(),
210 description, 216 description,
211 L"", 217 L"",
212 L"", 218 L"",
219 exe_path.value(),
220 dist->GetIconIndex(),
213 ShellUtil::CURRENT_USER, 221 ShellUtil::CURRENT_USER,
214 false, 222 false,
215 true)); 223 true));
216 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 224 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
217 user_shortcut_path.value(), 225 user_shortcut_path.value(),
218 description, 226 description,
219 0)); 227 0));
220 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, 228 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist,
221 ShellUtil::CURRENT_USER, 229 ShellUtil::CURRENT_USER,
222 false)); 230 false));
223 231
224 // Test simple creation of a system-level shortcut. 232 // Test simple creation of a system-level shortcut.
225 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, 233 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist,
226 exe_path.value(), 234 exe_path.value(),
227 description, 235 description,
228 L"", 236 L"",
229 L"", 237 L"",
238 exe_path.value(),
239 dist->GetIconIndex(),
230 ShellUtil::SYSTEM_LEVEL, 240 ShellUtil::SYSTEM_LEVEL,
231 false, 241 false,
232 true)); 242 true));
233 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 243 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
234 system_shortcut_path.value(), 244 system_shortcut_path.value(),
235 description, 245 description,
236 0)); 246 0));
237 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, 247 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist,
238 ShellUtil::SYSTEM_LEVEL, 248 ShellUtil::SYSTEM_LEVEL,
239 false)); 249 false));
240 250
241 // Test creation of a user-level shortcut when a system-level shortcut 251 // Test creation of a user-level shortcut when a system-level shortcut
242 // is already present (should fail). 252 // is already present (should fail).
243 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, 253 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist,
244 exe_path.value(), 254 exe_path.value(),
245 description, 255 description,
246 L"", 256 L"",
247 L"", 257 L"",
258 exe_path.value(),
259 dist->GetIconIndex(),
248 ShellUtil::SYSTEM_LEVEL, 260 ShellUtil::SYSTEM_LEVEL,
249 false, 261 false,
250 true)); 262 true));
251 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist, 263 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist,
252 exe_path.value(), 264 exe_path.value(),
253 description, 265 description,
254 L"", 266 L"",
255 L"", 267 L"",
268 exe_path.value(),
269 dist->GetIconIndex(),
256 ShellUtil::CURRENT_USER, 270 ShellUtil::CURRENT_USER,
257 false, 271 false,
258 true)); 272 true));
259 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 273 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
260 system_shortcut_path.value(), 274 system_shortcut_path.value(),
261 description, 275 description,
262 0)); 276 0));
263 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); 277 EXPECT_FALSE(file_util::PathExists(user_shortcut_path));
264 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, 278 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist,
265 ShellUtil::SYSTEM_LEVEL, 279 ShellUtil::SYSTEM_LEVEL,
266 false)); 280 false));
267 281
268 // Test creation of a system-level shortcut when a user-level shortcut 282 // Test creation of a system-level shortcut when a user-level shortcut
269 // is already present (should succeed). 283 // is already present (should succeed).
270 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, 284 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist,
271 exe_path.value(), 285 exe_path.value(),
272 description, 286 description,
273 L"", 287 L"",
274 L"", 288 L"",
289 exe_path.value(),
290 dist->GetIconIndex(),
275 ShellUtil::CURRENT_USER, 291 ShellUtil::CURRENT_USER,
276 false, 292 false,
277 true)); 293 true));
278 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, 294 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist,
279 exe_path.value(), 295 exe_path.value(),
280 description, 296 description,
281 L"", 297 L"",
282 L"", 298 L"",
299 exe_path.value(),
300 dist->GetIconIndex(),
283 ShellUtil::SYSTEM_LEVEL, 301 ShellUtil::SYSTEM_LEVEL,
284 false, 302 false,
285 true)); 303 true));
286 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 304 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
287 user_shortcut_path.value(), 305 user_shortcut_path.value(),
288 description, 306 description,
289 0)); 307 0));
290 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 308 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
291 system_shortcut_path.value(), 309 system_shortcut_path.value(),
292 description, 310 description,
293 0)); 311 0));
294 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, 312 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist,
295 ShellUtil::CURRENT_USER, 313 ShellUtil::CURRENT_USER,
296 false)); 314 false));
297 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, 315 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist,
298 ShellUtil::SYSTEM_LEVEL, 316 ShellUtil::SYSTEM_LEVEL,
299 false)); 317 false));
300 318
301 // Test creation of two profile-specific shortcuts (these are always 319 // Test creation of two profile-specific shortcuts (these are always
302 // user-level). 320 // user-level).
303 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 321 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
304 dist, 322 dist,
305 exe_path.value(), 323 exe_path.value(),
306 description, 324 description,
307 default_profile_user_name, 325 default_profile_user_name,
308 L"--profile-directory=\"Default\"", 326 L"--profile-directory=\"Default\"",
327 exe_path.value(),
328 dist->GetIconIndex(),
309 ShellUtil::CURRENT_USER, 329 ShellUtil::CURRENT_USER,
310 false, 330 false,
311 true)); 331 true));
312 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 332 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
313 default_profile_shortcut_path.value(), 333 default_profile_shortcut_path.value(),
314 description, 334 description,
315 0)); 335 0));
316 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 336 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
317 dist, 337 dist,
318 exe_path.value(), 338 exe_path.value(),
319 description, 339 description,
320 second_profile_user_name, 340 second_profile_user_name,
321 L"--profile-directory=\"Profile 1\"", 341 L"--profile-directory=\"Profile 1\"",
342 exe_path.value(),
343 dist->GetIconIndex(),
322 ShellUtil::CURRENT_USER, 344 ShellUtil::CURRENT_USER,
323 false, 345 false,
324 true)); 346 true));
325 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 347 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(),
326 second_profile_shortcut_path.value(), 348 second_profile_shortcut_path.value(),
327 description, 349 description,
328 0)); 350 0));
329 std::vector<string16> profile_names; 351 std::vector<string16> profile_names;
330 profile_names.push_back(default_profile_shortcut_name); 352 profile_names.push_back(default_profile_shortcut_name);
331 profile_names.push_back(second_profile_shortcut_name); 353 profile_names.push_back(second_profile_shortcut_name);
332 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( 354 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
333 profile_names)); 355 profile_names));
334 } 356 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | ui/gfx/icon_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698