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

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

Issue 23581012: Restricting scope of ShellUtil's shortcut update feature for its specific usage in Chrome self-dest… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using VLOG(ERROR) for one change. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | 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) 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 ASSERT_TRUE(base::PathExists(shortcut2_path)); 427 ASSERT_TRUE(base::PathExists(shortcut2_path));
428 428
429 ASSERT_TRUE(ShellUtil::RemoveShortcuts( 429 ASSERT_TRUE(ShellUtil::RemoveShortcuts(
430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
431 chrome_exe_)); 431 chrome_exe_));
432 ASSERT_FALSE(base::PathExists(shortcut1_path)); 432 ASSERT_FALSE(base::PathExists(shortcut1_path));
433 ASSERT_FALSE(base::PathExists(shortcut2_path)); 433 ASSERT_FALSE(base::PathExists(shortcut2_path));
434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); 434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName()));
435 } 435 }
436 436
437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { 437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) {
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
441 441
442 string16 shortcut_name( 442 string16 shortcut_name(
443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
444 installer::kLnkExt); 444 installer::kLnkExt);
445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); 445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
446 ASSERT_TRUE(base::PathExists(shortcut_path)); 446 ASSERT_TRUE(base::PathExists(shortcut_path));
447 447
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
450 updated_properties.set_target(new_exe); 450 updated_properties.set_target(new_exe);
451 451 // |updated_properties| has arguments.
452 ASSERT_TRUE(ShellUtil::UpdateShortcuts( 452 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
454 chrome_exe_, false, updated_properties)); 454 chrome_exe_, updated_properties));
455 455
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); 456 ShellUtil::ShortcutProperties expected_properties(test_properties_);
457 expected_properties.set_target(new_exe); 457 expected_properties.set_target(new_exe);
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
459 expected_properties); 459 expected_properties);
460 } 460 }
461 461
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcut) { 462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) {
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; 463 test_properties_.level = ShellUtil::SYSTEM_LEVEL;
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
467 467
468 string16 shortcut_name( 468 string16 shortcut_name(
469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
470 installer::kLnkExt); 470 installer::kLnkExt);
471 base::FilePath shortcut_path( 471 base::FilePath shortcut_path(
472 fake_common_desktop_.path().Append(shortcut_name)); 472 fake_common_desktop_.path().Append(shortcut_name));
473 ASSERT_TRUE(base::PathExists(shortcut_path)); 473 ASSERT_TRUE(base::PathExists(shortcut_path));
474 474
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
477 updated_properties.set_target(new_exe); 477 updated_properties.set_target(new_exe);
478 478 // |updated_properties| has arguments.
479 ASSERT_TRUE(ShellUtil::UpdateShortcuts( 479 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, 480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL,
481 chrome_exe_, false, updated_properties)); 481 chrome_exe_, updated_properties));
482 482
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); 483 ShellUtil::ShortcutProperties expected_properties(test_properties_);
484 expected_properties.set_target(new_exe); 484 expected_properties.set_target(new_exe);
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
486 expected_properties); 486 expected_properties);
487 } 487 }
488 488
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcuts) { 489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) {
490 const wchar_t kShortcutName1[] = L"Chrome 1"; 490 const wchar_t kShortcutName1[] = L"Chrome 1";
491 const wchar_t kShortcutName2[] = L"Chrome 2"; 491 const wchar_t kShortcutName2[] = L"Chrome 2";
492 492
493 // Setup shortcut 1, which has empty arguments. 493 // Setup shortcut 1, which has empty arguments.
494 test_properties_.set_shortcut_name(kShortcutName1); 494 test_properties_.set_shortcut_name(kShortcutName1);
495 test_properties_.set_arguments(L""); 495 test_properties_.set_arguments(L"");
496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, 497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_,
498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); 499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt));
(...skipping 12 matching lines...) Expand all
512 base::FilePath shortcut2_path( 512 base::FilePath shortcut2_path(
513 fake_user_desktop_.path().Append(shortcut2_name)); 513 fake_user_desktop_.path().Append(shortcut2_name));
514 ASSERT_TRUE(base::PathExists(shortcut2_path)); 514 ASSERT_TRUE(base::PathExists(shortcut2_path));
515 ShellUtil::ShortcutProperties expected_properties2(test_properties_); 515 ShellUtil::ShortcutProperties expected_properties2(test_properties_);
516 516
517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". 517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe".
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); 518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe);
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); 519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER);
520 updated_properties.set_target(new_exe); 520 updated_properties.set_target(new_exe);
521 521
522 // |require_args| = true, so only changing shrotcuts that have non-empty 522 // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2.
523 // arguments; only shortcut 2 is updated. 523 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs(
524 ASSERT_TRUE(ShellUtil::UpdateShortcuts(
525 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, 524 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
526 chrome_exe_, /*require_args*/ true, updated_properties)); 525 chrome_exe_, updated_properties));
527 // Verify shortcut 1. 526 // Verify shortcut 1.
528 // |expected_properties1| was unchanged and still targets "chrome.exe", since 527 // |expected_properties1| was unchanged and still targets "chrome.exe", since
529 // it has empty target, yet we passed |require_args| = true. 528 // it has empty target, yet we passed |require_args| = true.
530 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
531 expected_properties1); 530 expected_properties1);
532 // Verify shortcut 2. 531 // Verify shortcut 2.
533 expected_properties2.set_target(new_exe); 532 expected_properties2.set_target(new_exe);
534 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, 533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
535 expected_properties2); 534 expected_properties2);
536
537 // |require_args| = false, now both shortcuts are updated.
538 ASSERT_TRUE(ShellUtil::UpdateShortcuts(
539 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER,
540 chrome_exe_, /*require_args*/ false, updated_properties));
541 // Verify shortcut 1.
542 expected_properties1.set_target(new_exe);
543 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
544 expected_properties1);
545 // Verify shortcut 2.
546 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
547 expected_properties2);
548 } 535 }
549 536
550 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { 537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
551 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
552 ShellUtil::SHORTCUT_LOCATION_START_MENU, 539 ShellUtil::SHORTCUT_LOCATION_START_MENU,
553 dist_, test_properties_, 540 dist_, test_properties_,
554 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); 541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
555 test_properties_.set_shortcut_name(L"A second shortcut"); 542 test_properties_.set_shortcut_name(L"A second shortcut");
556 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( 543 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
557 ShellUtil::SHORTCUT_LOCATION_START_MENU, 544 ShellUtil::SHORTCUT_LOCATION_START_MENU,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 662
676 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",
677 L"MZXW6YTB", L"MZXW6YTBOI"}; 664 L"MZXW6YTB", L"MZXW6YTBOI"};
678 665
679 // 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.
680 for (int i = 0; i < arraysize(expected); ++i) { 667 for (int i = 0; i < arraysize(expected); ++i) {
681 ASSERT_EQ(expected[i], 668 ASSERT_EQ(expected[i],
682 ShellUtil::ByteArrayToBase32(test_array, i)); 669 ShellUtil::ByteArrayToBase32(test_array, i));
683 } 670 }
684 } 671 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698