| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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: |
| 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(dist_->GetAppShortCutName()); | 107 expected_path = expected_path.Append( |
| 108 dist_->GetStartMenuShortcutSubfolder( |
| 109 BrowserDistribution::SUBFOLDER_CHROME)); |
| 108 break; | 110 break; |
| 109 default: | 111 default: |
| 110 ADD_FAILURE() << "Unknown location"; | 112 ADD_FAILURE() << "Unknown location"; |
| 111 return; | 113 return; |
| 112 } | 114 } |
| 113 | 115 |
| 114 string16 shortcut_name; | 116 string16 shortcut_name; |
| 115 if (properties.has_shortcut_name()) | 117 if (properties.has_shortcut_name()) { |
| 116 shortcut_name = properties.shortcut_name; | 118 shortcut_name = properties.shortcut_name; |
| 117 else | 119 } else { |
| 118 shortcut_name = dist_->GetAppShortCutName(); | 120 shortcut_name = |
| 121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); |
| 122 } |
| 119 shortcut_name.append(installer::kLnkExt); | 123 shortcut_name.append(installer::kLnkExt); |
| 120 expected_path = expected_path.Append(shortcut_name); | 124 expected_path = expected_path.Append(shortcut_name); |
| 121 | 125 |
| 122 base::win::ShortcutProperties expected_properties; | 126 base::win::ShortcutProperties expected_properties; |
| 123 if (properties.has_target()) { | 127 if (properties.has_target()) { |
| 124 expected_properties.set_target(properties.target); | 128 expected_properties.set_target(properties.target); |
| 125 expected_properties.set_working_dir(properties.target.DirName()); | 129 expected_properties.set_working_dir(properties.target.DirName()); |
| 126 } else { | 130 } else { |
| 127 expected_properties.set_target(chrome_exe_); | 131 expected_properties.set_target(chrome_exe_); |
| 128 expected_properties.set_working_dir(chrome_exe_.DirName()); | 132 expected_properties.set_working_dir(chrome_exe_.DirName()); |
| 129 } | 133 } |
| 130 | 134 |
| 131 if (properties.has_arguments()) | 135 if (properties.has_arguments()) |
| 132 expected_properties.set_arguments(properties.arguments); | 136 expected_properties.set_arguments(properties.arguments); |
| 133 else | 137 else |
| 134 expected_properties.set_arguments(string16()); | 138 expected_properties.set_arguments(string16()); |
| 135 | 139 |
| 136 if (properties.has_description()) | 140 if (properties.has_description()) |
| 137 expected_properties.set_description(properties.description); | 141 expected_properties.set_description(properties.description); |
| 138 else | 142 else |
| 139 expected_properties.set_description(dist->GetAppDescription()); | 143 expected_properties.set_description(dist->GetAppDescription()); |
| 140 | 144 |
| 141 if (properties.has_icon()) { | 145 if (properties.has_icon()) { |
| 142 expected_properties.set_icon(properties.icon, 0); | 146 expected_properties.set_icon(properties.icon, 0); |
| 143 } else { | 147 } else { |
| 144 int icon_index = dist->GetIconIndex(); | 148 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); |
| 145 expected_properties.set_icon(chrome_exe_, icon_index); | 149 expected_properties.set_icon(chrome_exe_, icon_index); |
| 146 } | 150 } |
| 147 | 151 |
| 148 if (properties.has_app_id()) { | 152 if (properties.has_app_id()) { |
| 149 expected_properties.set_app_id(properties.app_id); | 153 expected_properties.set_app_id(properties.app_id); |
| 150 } else { | 154 } else { |
| 151 // Tests are always seen as user-level installs in ShellUtil. | 155 // Tests are always seen as user-level installs in ShellUtil. |
| 152 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); | 156 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
| 153 } | 157 } |
| 154 | 158 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 EXPECT_EQ(fake_user_desktop_.path(), path); | 197 EXPECT_EQ(fake_user_desktop_.path(), path); |
| 194 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 198 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 195 ShellUtil::SYSTEM_LEVEL, &path); | 199 ShellUtil::SYSTEM_LEVEL, &path); |
| 196 EXPECT_EQ(fake_common_desktop_.path(), path); | 200 EXPECT_EQ(fake_common_desktop_.path(), path); |
| 197 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 201 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
| 198 ShellUtil::CURRENT_USER, &path); | 202 ShellUtil::CURRENT_USER, &path); |
| 199 EXPECT_EQ(fake_user_quick_launch_.path(), path); | 203 EXPECT_EQ(fake_user_quick_launch_.path(), path); |
| 200 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 204 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
| 201 ShellUtil::SYSTEM_LEVEL, &path); | 205 ShellUtil::SYSTEM_LEVEL, &path); |
| 202 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); | 206 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); |
| 207 string16 start_menu_subfolder = |
| 208 dist_->GetStartMenuShortcutSubfolder( |
| 209 BrowserDistribution::SUBFOLDER_CHROME); |
| 203 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 210 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, |
| 204 ShellUtil::CURRENT_USER, &path); | 211 ShellUtil::CURRENT_USER, &path); |
| 205 EXPECT_EQ(fake_start_menu_.path().Append(dist_->GetAppShortCutName()), path); | 212 EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder), |
| 213 path); |
| 206 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 214 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, |
| 207 ShellUtil::SYSTEM_LEVEL, &path); | 215 ShellUtil::SYSTEM_LEVEL, &path); |
| 208 EXPECT_EQ(fake_common_start_menu_.path().Append(dist_->GetAppShortCutName()), | 216 EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder), |
| 209 path); | 217 path); |
| 210 } | 218 } |
| 211 | 219 |
| 212 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { | 220 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { |
| 213 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 221 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
| 214 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); | 222 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); |
| 215 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 223 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 216 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, | 224 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, |
| 217 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 225 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 218 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 226 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 309 |
| 302 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { | 310 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { |
| 303 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 311 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 304 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 312 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 305 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 313 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
| 306 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 314 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 307 test_properties_); | 315 test_properties_); |
| 308 } | 316 } |
| 309 | 317 |
| 310 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { | 318 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { |
| 311 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 319 string16 shortcut_name( |
| 320 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 321 installer::kLnkExt); |
| 312 | 322 |
| 313 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 323 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
| 314 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 324 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 315 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 325 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 316 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 326 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 317 ASSERT_TRUE(base::PathExists( | 327 ASSERT_TRUE(base::PathExists( |
| 318 fake_common_desktop_.path().Append(shortcut_name))); | 328 fake_common_desktop_.path().Append(shortcut_name))); |
| 319 | 329 |
| 320 test_properties_.level = ShellUtil::CURRENT_USER; | 330 test_properties_.level = ShellUtil::CURRENT_USER; |
| 321 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 331 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 322 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 332 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 323 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 333 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
| 324 ASSERT_FALSE(base::PathExists( | 334 ASSERT_FALSE(base::PathExists( |
| 325 fake_user_desktop_.path().Append(shortcut_name))); | 335 fake_user_desktop_.path().Append(shortcut_name))); |
| 326 } | 336 } |
| 327 | 337 |
| 328 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { | 338 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { |
| 329 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 339 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 330 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 340 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
| 331 dist_, test_properties_, | 341 dist_, test_properties_, |
| 332 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 342 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
| 333 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, | 343 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, |
| 334 test_properties_); | 344 test_properties_); |
| 335 } | 345 } |
| 336 | 346 |
| 337 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { | 347 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { |
| 338 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 348 string16 shortcut_name( |
| 349 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 350 installer::kLnkExt); |
| 339 | 351 |
| 340 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 352 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
| 341 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 342 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 343 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 355 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 344 ASSERT_TRUE(base::PathExists( | 356 ASSERT_TRUE(base::PathExists( |
| 345 fake_common_desktop_.path().Append(shortcut_name))); | 357 fake_common_desktop_.path().Append(shortcut_name))); |
| 346 | 358 |
| 347 test_properties_.level = ShellUtil::CURRENT_USER; | 359 test_properties_.level = ShellUtil::CURRENT_USER; |
| 348 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 360 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 349 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 361 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 350 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 362 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 351 ASSERT_TRUE(base::PathExists( | 363 ASSERT_TRUE(base::PathExists( |
| 352 fake_user_desktop_.path().Append(shortcut_name))); | 364 fake_user_desktop_.path().Append(shortcut_name))); |
| 353 } | 365 } |
| 354 | 366 |
| 355 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { | 367 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { |
| 356 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 357 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 358 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 370 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 359 | 371 |
| 360 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 372 string16 shortcut_name( |
| 373 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 374 installer::kLnkExt); |
| 361 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 375 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 362 ASSERT_TRUE(base::PathExists(shortcut_path)); | 376 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| 363 | 377 |
| 364 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 378 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
| 365 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 366 chrome_exe_)); | 380 chrome_exe_)); |
| 367 ASSERT_FALSE(base::PathExists(shortcut_path)); | 381 ASSERT_FALSE(base::PathExists(shortcut_path)); |
| 368 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 382 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
| 369 } | 383 } |
| 370 | 384 |
| 371 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { | 385 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { |
| 372 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 386 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
| 373 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 374 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 375 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 389 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 376 | 390 |
| 377 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 391 string16 shortcut_name( |
| 392 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 393 installer::kLnkExt); |
| 378 base::FilePath shortcut_path( | 394 base::FilePath shortcut_path( |
| 379 fake_common_desktop_.path().Append(shortcut_name)); | 395 fake_common_desktop_.path().Append(shortcut_name)); |
| 380 ASSERT_TRUE(base::PathExists(shortcut_path)); | 396 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| 381 | 397 |
| 382 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 398 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
| 383 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 399 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
| 384 chrome_exe_)); | 400 chrome_exe_)); |
| 385 ASSERT_FALSE(base::PathExists(shortcut_path)); | 401 ASSERT_FALSE(base::PathExists(shortcut_path)); |
| 386 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 402 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
| 387 } | 403 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 416 ASSERT_FALSE(base::PathExists(shortcut1_path)); | 432 ASSERT_FALSE(base::PathExists(shortcut1_path)); |
| 417 ASSERT_FALSE(base::PathExists(shortcut2_path)); | 433 ASSERT_FALSE(base::PathExists(shortcut2_path)); |
| 418 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); | 434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); |
| 419 } | 435 } |
| 420 | 436 |
| 421 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { | 437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { |
| 422 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 423 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 424 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 425 | 441 |
| 426 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 442 string16 shortcut_name( |
| 443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 444 installer::kLnkExt); |
| 427 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 428 ASSERT_TRUE(base::PathExists(shortcut_path)); | 446 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| 429 | 447 |
| 430 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
| 431 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
| 432 updated_properties.set_target(new_exe); | 450 updated_properties.set_target(new_exe); |
| 433 | 451 |
| 434 ASSERT_TRUE(ShellUtil::UpdateShortcuts( | 452 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
| 435 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 436 chrome_exe_, updated_properties)); | 454 chrome_exe_, updated_properties)); |
| 437 | 455 |
| 438 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 456 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
| 439 expected_properties.set_target(new_exe); | 457 expected_properties.set_target(new_exe); |
| 440 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 441 expected_properties); | 459 expected_properties); |
| 442 } | 460 } |
| 443 | 461 |
| 444 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcut) { | 462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcut) { |
| 445 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
| 446 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 447 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 448 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 449 | 467 |
| 450 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 468 string16 shortcut_name( |
| 469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 470 installer::kLnkExt); |
| 451 base::FilePath shortcut_path( | 471 base::FilePath shortcut_path( |
| 452 fake_common_desktop_.path().Append(shortcut_name)); | 472 fake_common_desktop_.path().Append(shortcut_name)); |
| 453 ASSERT_TRUE(base::PathExists(shortcut_path)); | 473 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| 454 | 474 |
| 455 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
| 456 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
| 457 updated_properties.set_target(new_exe); | 477 updated_properties.set_target(new_exe); |
| 458 | 478 |
| 459 ASSERT_TRUE(ShellUtil::UpdateShortcuts( | 479 ASSERT_TRUE(ShellUtil::UpdateShortcuts( |
| 460 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 538 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
| 519 dist_, test_properties_, | 539 dist_, test_properties_, |
| 520 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 540 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 521 test_properties_.set_shortcut_name(L"A second shortcut"); | 541 test_properties_.set_shortcut_name(L"A second shortcut"); |
| 522 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 523 ShellUtil::SHORTCUT_LOCATION_START_MENU, | 543 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
| 524 dist_, test_properties_, | 544 dist_, test_properties_, |
| 525 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 526 | 546 |
| 527 base::FilePath shortcut_folder( | 547 base::FilePath shortcut_folder( |
| 528 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); | 548 fake_start_menu_.path().Append( |
| 549 dist_->GetStartMenuShortcutSubfolder( |
| 550 BrowserDistribution::SUBFOLDER_CHROME))); |
| 529 base::FileEnumerator file_counter(shortcut_folder, false, | 551 base::FileEnumerator file_counter(shortcut_folder, false, |
| 530 base::FileEnumerator::FILES); | 552 base::FileEnumerator::FILES); |
| 531 int count = 0; | 553 int count = 0; |
| 532 while (!file_counter.Next().empty()) | 554 while (!file_counter.Next().empty()) |
| 533 ++count; | 555 ++count; |
| 534 EXPECT_EQ(2, count); | 556 EXPECT_EQ(2, count); |
| 535 | 557 |
| 536 ASSERT_TRUE(base::PathExists(shortcut_folder)); | 558 ASSERT_TRUE(base::PathExists(shortcut_folder)); |
| 537 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 559 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
| 538 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, | 560 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, ShellUtil::CURRENT_USER, |
| 539 chrome_exe_)); | 561 chrome_exe_)); |
| 540 ASSERT_FALSE(base::PathExists(shortcut_folder)); | 562 ASSERT_FALSE(base::PathExists(shortcut_folder)); |
| 541 } | 563 } |
| 542 | 564 |
| 543 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 565 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
| 544 base::ScopedTempDir other_exe_dir; | 566 base::ScopedTempDir other_exe_dir; |
| 545 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 567 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
| 546 base::FilePath other_chrome_exe = | 568 base::FilePath other_chrome_exe = |
| 547 other_exe_dir.path().Append(installer::kChromeExe); | 569 other_exe_dir.path().Append(installer::kChromeExe); |
| 548 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 570 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
| 549 | 571 |
| 550 test_properties_.set_target(other_chrome_exe); | 572 test_properties_.set_target(other_chrome_exe); |
| 551 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 573 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 552 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 574 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 553 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 575 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 554 | 576 |
| 555 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); | 577 string16 shortcut_name( |
| 578 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 579 installer::kLnkExt); |
| 556 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 580 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
| 557 ASSERT_TRUE(base::PathExists(shortcut_path)); | 581 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| 558 | 582 |
| 559 // The shortcut shouldn't be removed as it was installed pointing to | 583 // The shortcut shouldn't be removed as it was installed pointing to |
| 560 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the | 584 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the |
| 561 // removed shortcut should point to |chrome_exe_|. | 585 // removed shortcut should point to |chrome_exe_|. |
| 562 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 586 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
| 563 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 587 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
| 564 chrome_exe_)); | 588 chrome_exe_)); |
| 565 ASSERT_TRUE(base::PathExists(shortcut_path)); | 589 ASSERT_TRUE(base::PathExists(shortcut_path)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 | 661 |
| 638 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", |
| 639 L"MZXW6YTB", L"MZXW6YTBOI"}; | 663 L"MZXW6YTB", L"MZXW6YTBOI"}; |
| 640 | 664 |
| 641 // 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. |
| 642 for (int i = 0; i < arraysize(expected); ++i) { | 666 for (int i = 0; i < arraysize(expected); ++i) { |
| 643 ASSERT_EQ(expected[i], | 667 ASSERT_EQ(expected[i], |
| 644 ShellUtil::ByteArrayToBase32(test_array, i)); | 668 ShellUtil::ByteArrayToBase32(test_array, i)); |
| 645 } | 669 } |
| 646 } | 670 } |
| OLD | NEW |