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

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

Issue 14287008: Refactoring installer shortcut deletion; adding dedicated shortcut update feature. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fixes; cleanups. Created 7 years, 7 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { 349 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
350 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 350 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
351 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 351 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
352 *test_properties_, 352 *test_properties_,
353 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 353 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
354 354
355 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); 355 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
356 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); 356 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
357 ASSERT_TRUE(file_util::PathExists(shortcut_path)); 357 ASSERT_TRUE(file_util::PathExists(shortcut_path));
358 358
359 ASSERT_TRUE(ShellUtil::RemoveShortcut( 359 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
360 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, 360 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
361 ShellUtil::CURRENT_USER, NULL)); 361 chrome_exe_));
362 ASSERT_FALSE(file_util::PathExists(shortcut_path)); 362 ASSERT_FALSE(file_util::PathExists(shortcut_path));
363 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); 363 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
364 } 364 }
365 365
366 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { 366 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) {
367 test_properties_->level = ShellUtil::SYSTEM_LEVEL; 367 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
370 *test_properties_, 370 *test_properties_,
371 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 371 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
372 372
373 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); 373 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
374 base::FilePath shortcut_path( 374 base::FilePath shortcut_path(
375 fake_common_desktop_.path().Append(shortcut_name)); 375 fake_common_desktop_.path().Append(shortcut_name));
376 ASSERT_TRUE(file_util::PathExists(shortcut_path)); 376 ASSERT_TRUE(file_util::PathExists(shortcut_path));
377 377
378 ASSERT_TRUE(ShellUtil::RemoveShortcut( 378 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, 379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
380 ShellUtil::SYSTEM_LEVEL, NULL)); 380 chrome_exe_));
381 ASSERT_FALSE(file_util::PathExists(shortcut_path)); 381 ASSERT_FALSE(file_util::PathExists(shortcut_path));
382 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); 382 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
383 } 383 }
384 384
385 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) { 385 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) {
386 static const wchar_t kSpecialName[] = L"I'm special"; 386 static const wchar_t kSpecialName[] = L"I'm special";
387 test_properties_->set_shortcut_name(kSpecialName); 387 test_properties_->set_shortcut_name(kSpecialName);
388 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 388 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
389 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 389 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
390 *test_properties_, 390 *test_properties_,
391 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 391 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
392 392
393 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt)); 393 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt));
394 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); 394 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
395 ASSERT_TRUE(file_util::PathExists(shortcut_path)); 395 ASSERT_TRUE(file_util::PathExists(shortcut_path));
396
397 ASSERT_TRUE(ShellUtil::RemoveShortcut(
398 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_,
399 ShellUtil::CURRENT_USER, &string16(kSpecialName)));
400 ASSERT_FALSE(file_util::PathExists(shortcut_path));
401 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
402 } 396 }
403 397
404 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { 398 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) {
405 const wchar_t kShortcutName1[] = L"Chrome 1"; 399 const wchar_t kShortcutName1[] = L"Chrome 1";
406 const wchar_t kShortcutName2[] = L"Chrome 2"; 400 const wchar_t kShortcutName2[] = L"Chrome 2";
407 401
408 test_properties_->set_shortcut_name(kShortcutName1); 402 test_properties_->set_shortcut_name(kShortcutName1);
409 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 403 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
410 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 404 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
411 *test_properties_, 405 *test_properties_,
412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 406 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
413 string16 shortcut1_name( 407 string16 shortcut1_name(
414 string16(kShortcutName1).append(installer::kLnkExt)); 408 string16(kShortcutName1).append(installer::kLnkExt));
415 base::FilePath shortcut1_path( 409 base::FilePath shortcut1_path(
416 fake_user_desktop_.path().Append(shortcut1_name)); 410 fake_user_desktop_.path().Append(shortcut1_name));
417 ASSERT_TRUE(file_util::PathExists(shortcut1_path)); 411 ASSERT_TRUE(file_util::PathExists(shortcut1_path));
418 412
419 test_properties_->set_shortcut_name(kShortcutName2); 413 test_properties_->set_shortcut_name(kShortcutName2);
420 test_properties_->set_arguments(L"--profile-directory=\"Profile 2\""); 414 test_properties_->set_arguments(L"--profile-directory=\"Profile 2\"");
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 415 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 416 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
423 *test_properties_, 417 *test_properties_,
424 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 418 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
425 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); 419 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt));
426 base::FilePath shortcut2_path( 420 base::FilePath shortcut2_path(
427 fake_user_desktop_.path().Append(shortcut2_name)); 421 fake_user_desktop_.path().Append(shortcut2_name));
428 ASSERT_TRUE(file_util::PathExists(shortcut2_path)); 422 ASSERT_TRUE(file_util::PathExists(shortcut2_path));
429 423
430 ASSERT_TRUE(ShellUtil::RemoveShortcut( 424 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
431 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, 425 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
432 ShellUtil::CURRENT_USER, NULL)); 426 chrome_exe_));
433 ASSERT_FALSE(file_util::PathExists(shortcut1_path)); 427 ASSERT_FALSE(file_util::PathExists(shortcut1_path));
434 ASSERT_FALSE(file_util::PathExists(shortcut2_path)); 428 ASSERT_FALSE(file_util::PathExists(shortcut2_path));
435 ASSERT_TRUE(file_util::PathExists(shortcut1_path.DirName())); 429 ASSERT_TRUE(file_util::PathExists(shortcut1_path.DirName()));
436 } 430 }
437 431
432 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcut) {
433 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
434 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
435 *test_properties_,
436 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
437
438 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
439 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
440 ASSERT_TRUE(file_util::PathExists(shortcut_path));
441
442 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe");
443 ASSERT_TRUE(ShellUtil::RetargetShortcuts(
444 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
445 chrome_exe_, new_exe));
446 base::FilePath target_path;
447 ASSERT_TRUE(base::win::ResolveShortcut(shortcut_path, &target_path, NULL));
448 ASSERT_EQ(new_exe, target_path);
449 }
450
451 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcut) {
452 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
453 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
454 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
455 *test_properties_,
456 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
457
458 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
459 base::FilePath shortcut_path(
460 fake_common_desktop_.path().Append(shortcut_name));
461 ASSERT_TRUE(file_util::PathExists(shortcut_path));
462
463 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe");
464 ASSERT_TRUE(ShellUtil::RetargetShortcuts(
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
466 chrome_exe_, new_exe));
467 base::FilePath target_path;
468 ASSERT_TRUE(base::win::ResolveShortcut(shortcut_path, &target_path, NULL));
469 ASSERT_EQ(new_exe, target_path);
470 }
471
472 TEST_F(ShellUtilShortcutTest, RetargetMultipleChromeShortcuts) {
473 const wchar_t kShortcutName1[] = L"Chrome 1";
474 const wchar_t kShortcutName2[] = L"Chrome 2";
475
476 test_properties_->set_shortcut_name(kShortcutName1);
477 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
478 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
479 *test_properties_,
480 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
481 string16 shortcut1_name(
482 string16(kShortcutName1).append(installer::kLnkExt));
483 base::FilePath shortcut1_path(
484 fake_user_desktop_.path().Append(shortcut1_name));
485
486 test_properties_->set_shortcut_name(kShortcutName2);
487 test_properties_->set_arguments(L"--profile-directory=\"Profile 2\"");
488 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
489 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
490 *test_properties_,
491 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
492 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt));
493 base::FilePath shortcut2_path(
494 fake_user_desktop_.path().Append(shortcut2_name));
495 ASSERT_TRUE(file_util::PathExists(shortcut2_path));
496
497 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe");
498 ASSERT_TRUE(ShellUtil::RetargetShortcuts(
499 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
500 chrome_exe_, new_exe));
501
502 base::FilePath target_path1;
503 ASSERT_TRUE(base::win::ResolveShortcut(shortcut1_path, &target_path1, NULL));
504 ASSERT_EQ(new_exe, target_path1);
505 base::FilePath target_path2;
506 ASSERT_TRUE(base::win::ResolveShortcut(shortcut2_path, &target_path2, NULL));
507 ASSERT_EQ(new_exe, target_path2);
508 }
509
438 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 510 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
439 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 511 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
440 ShellUtil::SHORTCUT_LOCATION_START_MENU, 512 ShellUtil::SHORTCUT_LOCATION_START_MENU,
441 dist_, *test_properties_, 513 dist_, *test_properties_,
442 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 514 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
443 test_properties_->set_shortcut_name(L"A second shortcut"); 515 test_properties_->set_shortcut_name(L"A second shortcut");
444 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 516 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
445 ShellUtil::SHORTCUT_LOCATION_START_MENU, 517 ShellUtil::SHORTCUT_LOCATION_START_MENU,
446 dist_, *test_properties_, 518 dist_, *test_properties_,
447 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 519 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
448 520
449 base::FilePath shortcut_folder( 521 base::FilePath shortcut_folder(
450 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); 522 fake_start_menu_.path().Append(dist_->GetAppShortCutName()));
451 file_util::FileEnumerator file_counter(shortcut_folder, false, 523 file_util::FileEnumerator file_counter(shortcut_folder, false,
452 file_util::FileEnumerator::FILES); 524 file_util::FileEnumerator::FILES);
453 int count = 0; 525 int count = 0;
454 while (!file_counter.Next().empty()) 526 while (!file_counter.Next().empty())
455 ++count; 527 ++count;
456 EXPECT_EQ(2, count); 528 EXPECT_EQ(2, count);
457 529
458 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); 530 ASSERT_TRUE(file_util::PathExists(shortcut_folder));
459 ASSERT_TRUE(ShellUtil::RemoveShortcut( 531 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
460 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_, 532 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER,
461 ShellUtil::CURRENT_USER, NULL)); 533 chrome_exe_));
462 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); 534 ASSERT_FALSE(file_util::PathExists(shortcut_folder));
463 } 535 }
464 536
465 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { 537 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) {
466 base::ScopedTempDir other_exe_dir; 538 base::ScopedTempDir other_exe_dir;
467 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); 539 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir());
468 base::FilePath other_chrome_exe = 540 base::FilePath other_chrome_exe =
469 other_exe_dir.path().Append(installer::kChromeExe); 541 other_exe_dir.path().Append(installer::kChromeExe);
470 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); 542 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0));
471 543
472 test_properties_->set_target(other_chrome_exe); 544 test_properties_->set_target(other_chrome_exe);
473 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 545 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
474 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 546 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
475 *test_properties_, 547 *test_properties_,
476 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 548 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
477 549
478 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); 550 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
479 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); 551 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
480 ASSERT_TRUE(file_util::PathExists(shortcut_path)); 552 ASSERT_TRUE(file_util::PathExists(shortcut_path));
481 553
482 // The shortcut shouldn't be removed as it was installed pointing to 554 // The shortcut shouldn't be removed as it was installed pointing to
483 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the 555 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the
484 // removed shortcut should point to |chrome_exe_|. 556 // removed shortcut should point to |chrome_exe_|.
485 ASSERT_TRUE(ShellUtil::RemoveShortcut( 557 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
486 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, 558 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
487 ShellUtil::CURRENT_USER, NULL)); 559 chrome_exe_));
488 ASSERT_TRUE(file_util::PathExists(shortcut_path)); 560 ASSERT_TRUE(file_util::PathExists(shortcut_path));
489 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); 561 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
490 } 562 }
491 563
492 TEST(ShellUtilTest, BuildAppModelIdBasic) { 564 TEST(ShellUtilTest, BuildAppModelIdBasic) {
493 std::vector<string16> components; 565 std::vector<string16> components;
494 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 566 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
495 const string16 base_app_id(dist->GetBaseAppId()); 567 const string16 base_app_id(dist->GetBaseAppId());
496 components.push_back(base_app_id); 568 components.push_back(base_app_id);
497 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); 569 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 632
561 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 633 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
562 L"MZXW6YTB", L"MZXW6YTBOI"}; 634 L"MZXW6YTB", L"MZXW6YTBOI"};
563 635
564 // Run the tests, with one more letter in the input every pass. 636 // Run the tests, with one more letter in the input every pass.
565 for (int i = 0; i < arraysize(expected); ++i) { 637 for (int i = 0; i < arraysize(expected); ++i) {
566 ASSERT_EQ(expected[i], 638 ASSERT_EQ(expected[i],
567 ShellUtil::ByteArrayToBase32(test_array, i)); 639 ShellUtil::ByteArrayToBase32(test_array, i));
568 } 640 }
569 } 641 }
OLDNEW
« chrome/installer/util/shell_util.cc ('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