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