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

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

Issue 13864015: Move app launcher and chrome apps shortcut strings into the installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_app_id_fix
Patch Set: fix linux Created 7 years, 2 months 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
OLDNEW
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 "chrome/installer/util/shell_util.h" 5 #include "chrome/installer/util/shell_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/base_paths_win.h" 10 #include "base/base_paths_win.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 switch (location) { 94 switch (location) {
95 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 95 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
96 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 96 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
97 fake_user_desktop_.path() : fake_common_desktop_.path(); 97 fake_user_desktop_.path() : fake_common_desktop_.path();
98 break; 98 break;
99 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 99 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
101 fake_user_quick_launch_.path() : 101 fake_user_quick_launch_.path() :
102 fake_default_user_quick_launch_.path(); 102 fake_default_user_quick_launch_.path();
103 break; 103 break;
104 case ShellUtil::SHORTCUT_LOCATION_START_MENU: 104 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
105 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? 105 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
106 fake_start_menu_.path() : fake_common_start_menu_.path(); 106 fake_start_menu_.path() : fake_common_start_menu_.path();
107 expected_path = expected_path.Append( 107 expected_path = expected_path.Append(
108 dist_->GetStartMenuShortcutSubfolder( 108 dist_->GetStartMenuShortcutSubfolder(
109 BrowserDistribution::SUBFOLDER_CHROME)); 109 BrowserDistribution::SUBFOLDER_CHROME));
110 break; 110 break;
111 default: 111 default:
112 ADD_FAILURE() << "Unknown location"; 112 ADD_FAILURE() << "Unknown location";
113 return; 113 return;
114 } 114 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 EXPECT_EQ(fake_common_desktop_.path(), path); 200 EXPECT_EQ(fake_common_desktop_.path(), path);
201 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, 201 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_,
202 ShellUtil::CURRENT_USER, &path); 202 ShellUtil::CURRENT_USER, &path);
203 EXPECT_EQ(fake_user_quick_launch_.path(), path); 203 EXPECT_EQ(fake_user_quick_launch_.path(), path);
204 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, 204 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_,
205 ShellUtil::SYSTEM_LEVEL, &path); 205 ShellUtil::SYSTEM_LEVEL, &path);
206 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); 206 EXPECT_EQ(fake_default_user_quick_launch_.path(), path);
207 string16 start_menu_subfolder = 207 string16 start_menu_subfolder =
208 dist_->GetStartMenuShortcutSubfolder( 208 dist_->GetStartMenuShortcutSubfolder(
209 BrowserDistribution::SUBFOLDER_CHROME); 209 BrowserDistribution::SUBFOLDER_CHROME);
210 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 210 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
211 ShellUtil::CURRENT_USER, &path); 211 dist_, ShellUtil::CURRENT_USER, &path);
212 EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder), 212 EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder),
213 path); 213 path);
214 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 214 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
215 ShellUtil::SYSTEM_LEVEL, &path); 215 dist_, ShellUtil::SYSTEM_LEVEL, &path);
216 EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder), 216 EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder),
217 path); 217 path);
218 } 218 }
219 219
220 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { 220 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) {
221 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); 221 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
222 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); 222 product_->AddDefaultShortcutProperties(chrome_exe_, &properties);
223 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 223 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
224 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, 224 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties,
225 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 225 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
226 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 226 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
227 properties); 227 properties);
228 } 228 }
229 229
230 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { 230 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) {
231 test_properties_.set_shortcut_name(L"Bobo le shortcut"); 231 test_properties_.set_shortcut_name(L"Bobo le shortcut");
232 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 232 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
233 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 233 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
234 ShellUtil::SHORTCUT_LOCATION_START_MENU, 234 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
235 dist_, test_properties_, 235 dist_, test_properties_,
236 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 236 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
237 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 237 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
238 test_properties_); 238 dist_, test_properties_);
239 } 239 }
240 240
241 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) { 241 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) {
242 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 242 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
243 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 243 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
244 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, 244 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
245 dist_, test_properties_, 245 dist_, test_properties_,
246 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 246 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
247 247
248 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); 248 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 expected_properties.set_arguments(updated_properties.arguments); 284 expected_properties.set_arguments(updated_properties.arguments);
285 285
286 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, 286 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_,
287 expected_properties); 287 expected_properties);
288 } 288 }
289 289
290 TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) { 290 TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) {
291 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); 291 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
292 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); 292 product_->AddDefaultShortcutProperties(chrome_exe_, &properties);
293 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 293 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
294 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, properties, 294 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
295 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 295 properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
296 296
297 ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER); 297 ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER);
298 added_properties.set_dual_mode(true); 298 added_properties.set_dual_mode(true);
299 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 299 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
300 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 300 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
301 added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); 301 added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING));
302 302
303 ShellUtil::ShortcutProperties expected_properties(properties); 303 ShellUtil::ShortcutProperties expected_properties(properties);
304 expected_properties.set_dual_mode(true); 304 expected_properties.set_dual_mode(true);
305 305
306 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 306 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
307 expected_properties); 307 dist_, expected_properties);
308 } 308 }
309 309
310 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { 310 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) {
311 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 311 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
312 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 312 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
313 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); 313 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
314 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 314 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
315 test_properties_); 315 test_properties_);
316 } 316 }
317 317
(...skipping 12 matching lines...) Expand all
330 test_properties_.level = ShellUtil::CURRENT_USER; 330 test_properties_.level = ShellUtil::CURRENT_USER;
331 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 331 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
332 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 332 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
333 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); 333 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
334 ASSERT_FALSE(base::PathExists( 334 ASSERT_FALSE(base::PathExists(
335 fake_user_desktop_.path().Append(shortcut_name))); 335 fake_user_desktop_.path().Append(shortcut_name)));
336 } 336 }
337 337
338 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { 338 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) {
339 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 339 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
340 ShellUtil::SHORTCUT_LOCATION_START_MENU, 340 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
341 dist_, test_properties_, 341 dist_, test_properties_,
342 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); 342 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
343 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, 343 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
344 test_properties_); 344 dist_, test_properties_);
345 } 345 }
346 346
347 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { 347 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) {
348 string16 shortcut_name( 348 string16 shortcut_name(
349 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 349 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
350 installer::kLnkExt); 350 installer::kLnkExt);
351 351
352 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 352 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
530 expected_properties1); 530 expected_properties1);
531 // Verify shortcut 2. 531 // Verify shortcut 2.
532 expected_properties2.set_target(new_exe); 532 expected_properties2.set_target(new_exe);
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
534 expected_properties2); 534 expected_properties2);
535 } 535 }
536 536
537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
539 ShellUtil::SHORTCUT_LOCATION_START_MENU, 539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
540 dist_, test_properties_, 540 dist_, test_properties_,
541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
542 test_properties_.set_shortcut_name(L"A second shortcut"); 542 test_properties_.set_shortcut_name(L"A second shortcut");
543 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 543 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
544 ShellUtil::SHORTCUT_LOCATION_START_MENU, 544 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
545 dist_, test_properties_, 545 dist_, test_properties_,
546 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 546 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
547 547
548 base::FilePath shortcut_folder( 548 base::FilePath shortcut_folder(
549 fake_start_menu_.path().Append( 549 fake_start_menu_.path().Append(
550 dist_->GetStartMenuShortcutSubfolder( 550 dist_->GetStartMenuShortcutSubfolder(
551 BrowserDistribution::SUBFOLDER_CHROME))); 551 BrowserDistribution::SUBFOLDER_CHROME)));
552 base::FileEnumerator file_counter(shortcut_folder, false, 552 base::FileEnumerator file_counter(shortcut_folder, false,
553 base::FileEnumerator::FILES); 553 base::FileEnumerator::FILES);
554 int count = 0; 554 int count = 0;
555 while (!file_counter.Next().empty()) 555 while (!file_counter.Next().empty())
556 ++count; 556 ++count;
557 EXPECT_EQ(2, count); 557 EXPECT_EQ(2, count);
558 558
559 ASSERT_TRUE(base::PathExists(shortcut_folder)); 559 ASSERT_TRUE(base::PathExists(shortcut_folder));
560 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 560 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
561 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, 561 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
562 chrome_exe_)); 562 ShellUtil::CURRENT_USER, chrome_exe_));
563 ASSERT_FALSE(base::PathExists(shortcut_folder)); 563 ASSERT_FALSE(base::PathExists(shortcut_folder));
gab 2013/10/17 15:13:31 Also make sure we have, or add one if not, a test
564 } 564 }
565 565
566 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { 566 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) {
567 base::ScopedTempDir other_exe_dir; 567 base::ScopedTempDir other_exe_dir;
568 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); 568 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir());
569 base::FilePath other_chrome_exe = 569 base::FilePath other_chrome_exe =
570 other_exe_dir.path().Append(installer::kChromeExe); 570 other_exe_dir.path().Append(installer::kChromeExe);
571 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); 571 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0));
572 572
573 test_properties_.set_target(other_chrome_exe); 573 test_properties_.set_target(other_chrome_exe);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 662
663 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 663 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
664 L"MZXW6YTB", L"MZXW6YTBOI"}; 664 L"MZXW6YTB", L"MZXW6YTBOI"};
665 665
666 // Run the tests, with one more letter in the input every pass. 666 // Run the tests, with one more letter in the input every pass.
667 for (int i = 0; i < arraysize(expected); ++i) { 667 for (int i = 0; i < arraysize(expected); ++i) {
668 ASSERT_EQ(expected[i], 668 ASSERT_EQ(expected[i],
669 ShellUtil::ByteArrayToBase32(test_array, i)); 669 ShellUtil::ByteArrayToBase32(test_array, i));
670 } 670 }
671 } 671 }
OLDNEW
« chrome/installer/util/shell_util.h ('K') | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698