| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 expected_properties1); | 528 expected_properties1); |
| 529 | 529 |
| 530 // Verify shortcut 2. | 530 // Verify shortcut 2. |
| 531 expected_properties2.set_target(new_exe); | 531 expected_properties2.set_target(new_exe); |
| 532 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 532 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 533 expected_properties2); | 533 expected_properties2); |
| 534 } | 534 } |
| 535 | 535 |
| 536 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 536 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
| 537 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 537 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 538 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 538 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
| 539 dist_, test_properties_, | 539 dist_, test_properties_, |
| 540 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 540 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 541 test_properties_.set_shortcut_name(L"A second shortcut"); | 541 test_properties_.set_shortcut_name(L"A second shortcut"); |
| 542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 543 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
| 544 dist_, test_properties_, | 544 dist_, test_properties_, |
| 545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 546 | 546 |
| 547 base::FilePath shortcut_folder( | 547 base::FilePath shortcut_folder( |
| 548 fake_start_menu_.path().Append( | 548 fake_start_menu_.path().Append( |
| 549 dist_->GetStartMenuShortcutSubfolder( | 549 dist_->GetStartMenuShortcutSubfolder( |
| 550 BrowserDistribution::SUBFOLDER_CHROME))); | 550 BrowserDistribution::SUBFOLDER_CHROME))); |
| 551 base::FileEnumerator file_counter(shortcut_folder, false, | 551 base::FileEnumerator file_counter(shortcut_folder, false, |
| 552 base::FileEnumerator::FILES); | 552 base::FileEnumerator::FILES); |
| 553 int count = 0; | 553 int count = 0; |
| 554 while (!file_counter.Next().empty()) | 554 while (!file_counter.Next().empty()) |
| 555 ++count; | 555 ++count; |
| 556 EXPECT_EQ(2, count); | 556 EXPECT_EQ(2, count); |
| 557 | 557 |
| 558 ASSERT_TRUE(base::PathExists(shortcut_folder)); | 558 ASSERT_TRUE(base::PathExists(shortcut_folder)); |
| 559 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 559 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
| 560 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, | 560 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_, |
| 561 chrome_exe_)); | 561 ShellUtil::CURRENT_USER, chrome_exe_)); |
| 562 ASSERT_FALSE(base::PathExists(shortcut_folder)); | 562 ASSERT_FALSE(base::PathExists(shortcut_folder)); |
| 563 } | 563 } |
| 564 | 564 |
| 565 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 565 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
| 566 base::ScopedTempDir other_exe_dir; | 566 base::ScopedTempDir other_exe_dir; |
| 567 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 567 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
| 568 base::FilePath other_chrome_exe = | 568 base::FilePath other_chrome_exe = |
| 569 other_exe_dir.path().Append(installer::kChromeExe); | 569 other_exe_dir.path().Append(installer::kChromeExe); |
| 570 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 570 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
| 571 | 571 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 661 |
| 662 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 662 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
| 663 L"MZXW6YTB", L"MZXW6YTBOI"}; | 663 L"MZXW6YTB", L"MZXW6YTBOI"}; |
| 664 | 664 |
| 665 // Run the tests, with one more letter in the input every pass. | 665 // Run the tests, with one more letter in the input every pass. |
| 666 for (int i = 0; i < arraysize(expected); ++i) { | 666 for (int i = 0; i < arraysize(expected); ++i) { |
| 667 ASSERT_EQ(expected[i], | 667 ASSERT_EQ(expected[i], |
| 668 ShellUtil::ByteArrayToBase32(test_array, i)); | 668 ShellUtil::ByteArrayToBase32(test_array, i)); |
| 669 } | 669 } |
| 670 } | 670 } |
| OLD | NEW |