| 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 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 356 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_.value(), | 360 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, |
| 361 ShellUtil::CURRENT_USER, NULL)); | 361 ShellUtil::CURRENT_USER, NULL)); |
| 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 FilePath shortcut_path(fake_common_desktop_.path().Append(shortcut_name)); | 374 FilePath shortcut_path(fake_common_desktop_.path().Append(shortcut_name)); |
| 375 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 375 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 376 | 376 |
| 377 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 377 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
| 378 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_.value(), | 378 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, |
| 379 ShellUtil::SYSTEM_LEVEL, NULL)); | 379 ShellUtil::SYSTEM_LEVEL, NULL)); |
| 380 ASSERT_FALSE(file_util::PathExists(shortcut_path)); | 380 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
| 381 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); | 381 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
| 382 } | 382 } |
| 383 | 383 |
| 384 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) { | 384 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) { |
| 385 static const wchar_t kSpecialName[] = L"I'm special"; | 385 static const wchar_t kSpecialName[] = L"I'm special"; |
| 386 test_properties_->set_shortcut_name(kSpecialName); | 386 test_properties_->set_shortcut_name(kSpecialName); |
| 387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 389 *test_properties_, | 389 *test_properties_, |
| 390 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 390 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 391 | 391 |
| 392 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt)); | 392 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt)); |
| 393 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 393 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 394 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 394 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 395 | 395 |
| 396 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 396 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
| 397 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_.value(), | 397 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, |
| 398 ShellUtil::CURRENT_USER, &string16(kSpecialName))); | 398 ShellUtil::CURRENT_USER, &string16(kSpecialName))); |
| 399 ASSERT_FALSE(file_util::PathExists(shortcut_path)); | 399 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
| 400 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); | 400 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { |
| 404 const wchar_t kShortcutName1[] = L"Chrome 1"; |
| 405 const wchar_t kShortcutName2[] = L"Chrome 2"; |
| 406 |
| 407 test_properties_->set_shortcut_name(kShortcutName1); |
| 408 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 409 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 410 *test_properties_, |
| 411 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 412 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); |
| 413 FilePath shortcut1_path(fake_user_desktop_.path().Append(shortcut1_name)); |
| 414 ASSERT_TRUE(file_util::PathExists(shortcut1_path)); |
| 415 |
| 416 test_properties_->set_shortcut_name(kShortcutName2); |
| 417 test_properties_->set_arguments(L"--profile-directory=\"Profile 2\""); |
| 418 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 419 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 420 *test_properties_, |
| 421 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 422 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); |
| 423 FilePath shortcut2_path(fake_user_desktop_.path().Append(shortcut2_name)); |
| 424 ASSERT_TRUE(file_util::PathExists(shortcut2_path)); |
| 425 |
| 426 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
| 427 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, |
| 428 ShellUtil::CURRENT_USER, NULL)); |
| 429 ASSERT_FALSE(file_util::PathExists(shortcut1_path)); |
| 430 ASSERT_FALSE(file_util::PathExists(shortcut2_path)); |
| 431 ASSERT_TRUE(file_util::PathExists(shortcut1_path.DirName())); |
| 432 } |
| 433 |
| 403 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 434 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
| 404 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 435 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 405 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 436 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
| 406 dist_, *test_properties_, | 437 dist_, *test_properties_, |
| 407 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 438 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 408 test_properties_->set_shortcut_name(L"A second shortcut"); | 439 test_properties_->set_shortcut_name(L"A second shortcut"); |
| 409 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 440 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 410 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 441 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
| 411 dist_, *test_properties_, | 442 dist_, *test_properties_, |
| 412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 443 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 413 | 444 |
| 414 FilePath shortcut_folder( | 445 FilePath shortcut_folder( |
| 415 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); | 446 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); |
| 416 file_util::FileEnumerator file_counter (shortcut_folder, false, | 447 file_util::FileEnumerator file_counter(shortcut_folder, false, |
| 417 file_util::FileEnumerator::FILES); | 448 file_util::FileEnumerator::FILES); |
| 418 int count = 0; | 449 int count = 0; |
| 419 while (!file_counter.Next().empty()) | 450 while (!file_counter.Next().empty()) |
| 420 ++count; | 451 ++count; |
| 421 EXPECT_EQ(2, count); | 452 EXPECT_EQ(2, count); |
| 422 | 453 |
| 423 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); | 454 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); |
| 424 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 455 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
| 425 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_.value(), | 456 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_, |
| 426 ShellUtil::CURRENT_USER, NULL)); | 457 ShellUtil::CURRENT_USER, NULL)); |
| 427 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); | 458 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); |
| 428 } | 459 } |
| 429 | 460 |
| 430 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 461 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
| 431 base::ScopedTempDir other_exe_dir; | 462 base::ScopedTempDir other_exe_dir; |
| 432 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 463 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
| 433 FilePath other_chrome_exe = | 464 FilePath other_chrome_exe = |
| 434 other_exe_dir.path().Append(installer::kChromeExe); | 465 other_exe_dir.path().Append(installer::kChromeExe); |
| 435 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 466 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
| 436 | 467 |
| 437 test_properties_->set_target(other_chrome_exe); | 468 test_properties_->set_target(other_chrome_exe); |
| 438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 469 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 470 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 440 *test_properties_, | 471 *test_properties_, |
| 441 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 472 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 442 | 473 |
| 443 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 474 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
| 444 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 475 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 445 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 476 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 446 | 477 |
| 447 // The shortcut shouldn't be removed as it was installed pointing to | 478 // The shortcut shouldn't be removed as it was installed pointing to |
| 448 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the | 479 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the |
| 449 // removed shortcut should point to |chrome_exe_|. | 480 // removed shortcut should point to |chrome_exe_|. |
| 450 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 481 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
| 451 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 482 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, chrome_exe_, |
| 452 chrome_exe_.value(), ShellUtil::CURRENT_USER, NULL)); | 483 ShellUtil::CURRENT_USER, NULL)); |
| 453 ASSERT_TRUE(file_util::PathExists(shortcut_path)); | 484 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
| 454 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); | 485 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
| 455 } | 486 } |
| 456 | 487 |
| 457 TEST(ShellUtilTest, BuildAppModelIdBasic) { | 488 TEST(ShellUtilTest, BuildAppModelIdBasic) { |
| 458 std::vector<string16> components; | 489 std::vector<string16> components; |
| 459 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 490 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 460 const string16 base_app_id(dist->GetBaseAppId()); | 491 const string16 base_app_id(dist->GetBaseAppId()); |
| 461 components.push_back(base_app_id); | 492 components.push_back(base_app_id); |
| 462 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 493 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 556 |
| 526 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 557 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
| 527 L"MZXW6YTB", L"MZXW6YTBOI"}; | 558 L"MZXW6YTB", L"MZXW6YTBOI"}; |
| 528 | 559 |
| 529 // Run the tests, with one more letter in the input every pass. | 560 // Run the tests, with one more letter in the input every pass. |
| 530 for (int i = 0; i < arraysize(expected); ++i) { | 561 for (int i = 0; i < arraysize(expected); ++i) { |
| 531 ASSERT_EQ(expected[i], | 562 ASSERT_EQ(expected[i], |
| 532 ShellUtil::ByteArrayToBase32(test_array, i)); | 563 ShellUtil::ByteArrayToBase32(test_array, i)); |
| 533 } | 564 } |
| 534 } | 565 } |
| OLD | NEW |