OLD | NEW |
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::RemoveShortcut( |
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::RemoveShortcut( |
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 | 396 |
397 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 397 ASSERT_TRUE(ShellUtil::RemoveShortcutWithName( |
398 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, | 398 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
399 ShellUtil::CURRENT_USER, &string16(kSpecialName))); | 399 chrome_exe_, string16(kSpecialName))); |
400 ASSERT_FALSE(file_util::PathExists(shortcut_path)); | 400 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
401 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); | 401 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
402 } | 402 } |
403 | 403 |
404 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { | 404 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { |
405 const wchar_t kShortcutName1[] = L"Chrome 1"; | 405 const wchar_t kShortcutName1[] = L"Chrome 1"; |
406 const wchar_t kShortcutName2[] = L"Chrome 2"; | 406 const wchar_t kShortcutName2[] = L"Chrome 2"; |
407 | 407 |
408 test_properties_->set_shortcut_name(kShortcutName1); | 408 test_properties_->set_shortcut_name(kShortcutName1); |
409 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 409 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
(...skipping 11 matching lines...) Expand all Loading... |
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
423 *test_properties_, | 423 *test_properties_, |
424 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 424 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
425 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | 425 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); |
426 base::FilePath shortcut2_path( | 426 base::FilePath shortcut2_path( |
427 fake_user_desktop_.path().Append(shortcut2_name)); | 427 fake_user_desktop_.path().Append(shortcut2_name)); |
428 ASSERT_TRUE(file_util::PathExists(shortcut2_path)); | 428 ASSERT_TRUE(file_util::PathExists(shortcut2_path)); |
429 | 429 |
430 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 430 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
431 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, | 431 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
432 ShellUtil::CURRENT_USER, NULL)); | 432 chrome_exe_)); |
433 ASSERT_FALSE(file_util::PathExists(shortcut1_path)); | 433 ASSERT_FALSE(file_util::PathExists(shortcut1_path)); |
434 ASSERT_FALSE(file_util::PathExists(shortcut2_path)); | 434 ASSERT_FALSE(file_util::PathExists(shortcut2_path)); |
435 ASSERT_TRUE(file_util::PathExists(shortcut1_path.DirName())); | 435 ASSERT_TRUE(file_util::PathExists(shortcut1_path.DirName())); |
436 } | 436 } |
437 | 437 |
| 438 TEST_F(ShellUtilShortcutTest, MigrateChromeShortcut) { |
| 439 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 440 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 441 *test_properties_, |
| 442 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 443 |
| 444 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
| 445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 446 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 447 |
| 448 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe"); |
| 449 ASSERT_TRUE(ShellUtil::MigrateShortcut( |
| 450 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 451 chrome_exe_, new_exe)); |
| 452 base::FilePath target_path; |
| 453 ASSERT_TRUE(base::win::ResolveShortcut(shortcut_path, &target_path, NULL)); |
| 454 ASSERT_EQ(new_exe, target_path); |
| 455 } |
| 456 |
| 457 TEST_F(ShellUtilShortcutTest, MigrateSystemLevelChromeShortcut) { |
| 458 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
| 459 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 460 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 461 *test_properties_, |
| 462 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 463 |
| 464 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
| 465 base::FilePath shortcut_path( |
| 466 fake_common_desktop_.path().Append(shortcut_name)); |
| 467 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 468 |
| 469 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe"); |
| 470 ASSERT_TRUE(ShellUtil::MigrateShortcut( |
| 471 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
| 472 chrome_exe_, new_exe)); |
| 473 base::FilePath target_path; |
| 474 ASSERT_TRUE(base::win::ResolveShortcut(shortcut_path, &target_path, NULL)); |
| 475 ASSERT_EQ(new_exe, target_path); |
| 476 } |
| 477 |
| 478 TEST_F(ShellUtilShortcutTest, MigrateMultipleChromeShortcuts) { |
| 479 const wchar_t kShortcutName1[] = L"Chrome 1"; |
| 480 const wchar_t kShortcutName2[] = L"Chrome 2"; |
| 481 |
| 482 test_properties_->set_shortcut_name(kShortcutName1); |
| 483 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 484 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 485 *test_properties_, |
| 486 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 487 string16 shortcut1_name( |
| 488 string16(kShortcutName1).append(installer::kLnkExt)); |
| 489 base::FilePath shortcut1_path( |
| 490 fake_user_desktop_.path().Append(shortcut1_name)); |
| 491 |
| 492 test_properties_->set_shortcut_name(kShortcutName2); |
| 493 test_properties_->set_arguments(L"--profile-directory=\"Profile 2\""); |
| 494 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 495 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 496 *test_properties_, |
| 497 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 498 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); |
| 499 base::FilePath shortcut2_path( |
| 500 fake_user_desktop_.path().Append(shortcut2_name)); |
| 501 ASSERT_TRUE(file_util::PathExists(shortcut2_path)); |
| 502 |
| 503 base::FilePath new_exe = temp_dir_.path().Append(L"manganese.exe"); |
| 504 ASSERT_TRUE(ShellUtil::MigrateShortcut( |
| 505 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 506 chrome_exe_, new_exe)); |
| 507 |
| 508 base::FilePath target_path1; |
| 509 ASSERT_TRUE(base::win::ResolveShortcut(shortcut1_path, &target_path1, NULL)); |
| 510 ASSERT_EQ(new_exe, target_path1); |
| 511 base::FilePath target_path2; |
| 512 ASSERT_TRUE(base::win::ResolveShortcut(shortcut2_path, &target_path2, NULL)); |
| 513 ASSERT_EQ(new_exe, target_path2); |
| 514 } |
| 515 |
438 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 516 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
439 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 517 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
440 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 518 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
441 dist_, *test_properties_, | 519 dist_, *test_properties_, |
442 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 520 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
443 test_properties_->set_shortcut_name(L"A second shortcut"); | 521 test_properties_->set_shortcut_name(L"A second shortcut"); |
444 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 522 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
445 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 523 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
446 dist_, *test_properties_, | 524 dist_, *test_properties_, |
447 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 525 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
448 | 526 |
449 base::FilePath shortcut_folder( | 527 base::FilePath shortcut_folder( |
450 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); | 528 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); |
451 file_util::FileEnumerator file_counter(shortcut_folder, false, | 529 file_util::FileEnumerator file_counter(shortcut_folder, false, |
452 file_util::FileEnumerator::FILES); | 530 file_util::FileEnumerator::FILES); |
453 int count = 0; | 531 int count = 0; |
454 while (!file_counter.Next().empty()) | 532 while (!file_counter.Next().empty()) |
455 ++count; | 533 ++count; |
456 EXPECT_EQ(2, count); | 534 EXPECT_EQ(2, count); |
457 | 535 |
458 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); | 536 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); |
459 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 537 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
460 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_, | 538 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, |
461 ShellUtil::CURRENT_USER, NULL)); | 539 chrome_exe_)); |
462 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); | 540 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); |
463 } | 541 } |
464 | 542 |
465 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 543 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
466 base::ScopedTempDir other_exe_dir; | 544 base::ScopedTempDir other_exe_dir; |
467 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 545 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
468 base::FilePath other_chrome_exe = | 546 base::FilePath other_chrome_exe = |
469 other_exe_dir.path().Append(installer::kChromeExe); | 547 other_exe_dir.path().Append(installer::kChromeExe); |
470 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 548 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
471 | 549 |
472 test_properties_->set_target(other_chrome_exe); | 550 test_properties_->set_target(other_chrome_exe); |
473 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 551 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
474 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 552 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
475 *test_properties_, | 553 *test_properties_, |
476 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 554 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
477 | 555 |
478 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 556 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
479 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 557 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
480 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 558 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
481 | 559 |
482 // The shortcut shouldn't be removed as it was installed pointing to | 560 // The shortcut shouldn't be removed as it was installed pointing to |
483 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the | 561 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the |
484 // removed shortcut should point to |chrome_exe_|. | 562 // removed shortcut should point to |chrome_exe_|. |
485 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 563 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
486 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, | 564 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
487 ShellUtil::CURRENT_USER, NULL)); | 565 chrome_exe_)); |
488 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 566 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
489 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); | 567 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
490 } | 568 } |
491 | 569 |
492 TEST(ShellUtilTest, BuildAppModelIdBasic) { | 570 TEST(ShellUtilTest, BuildAppModelIdBasic) { |
493 std::vector<string16> components; | 571 std::vector<string16> components; |
494 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 572 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
495 const string16 base_app_id(dist->GetBaseAppId()); | 573 const string16 base_app_id(dist->GetBaseAppId()); |
496 components.push_back(base_app_id); | 574 components.push_back(base_app_id); |
497 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 575 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 | 638 |
561 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 639 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
562 L"MZXW6YTB", L"MZXW6YTBOI"}; | 640 L"MZXW6YTB", L"MZXW6YTBOI"}; |
563 | 641 |
564 // Run the tests, with one more letter in the input every pass. | 642 // Run the tests, with one more letter in the input every pass. |
565 for (int i = 0; i < arraysize(expected); ++i) { | 643 for (int i = 0; i < arraysize(expected); ++i) { |
566 ASSERT_EQ(expected[i], | 644 ASSERT_EQ(expected[i], |
567 ShellUtil::ByteArrayToBase32(test_array, i)); | 645 ShellUtil::ByteArrayToBase32(test_array, i)); |
568 } | 646 } |
569 } | 647 } |
OLD | NEW |