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 <objbase.h> | 5 #include <objbase.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | 118 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + |
| 119 installer::kLnkExt); | 119 installer::kLnkExt); |
| 120 base::string16 alternate_shortcut_name( | 120 base::string16 alternate_shortcut_name( |
| 121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME_ALTERNATE) + | 121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME_ALTERNATE) + |
| 122 installer::kLnkExt); | 122 installer::kLnkExt); |
| 123 | 123 |
| 124 user_desktop_shortcut_ = | 124 user_desktop_shortcut_ = |
| 125 fake_user_desktop_.path().Append(shortcut_name); | 125 fake_user_desktop_.path().Append(shortcut_name); |
| 126 user_quick_launch_shortcut_ = | 126 user_quick_launch_shortcut_ = |
| 127 fake_user_quick_launch_.path().Append(shortcut_name); | 127 fake_user_quick_launch_.path().Append(shortcut_name); |
| 128 user_start_menu_shortcut_ = | 128 user_start_menu_shortcut_ = fake_start_menu_.path().Append(shortcut_name); |
| 129 fake_start_menu_.path().Append( | 129 user_start_menu_subdir_shortcut_ = |
| 130 dist_->GetStartMenuShortcutSubfolder( | 130 fake_start_menu_.path() |
| 131 .Append(dist_->GetStartMenuShortcutSubfolder( | |
| 131 BrowserDistribution::SUBFOLDER_CHROME)) | 132 BrowserDistribution::SUBFOLDER_CHROME)) |
| 132 .Append(shortcut_name); | 133 .Append(shortcut_name); |
| 133 system_desktop_shortcut_ = | 134 system_desktop_shortcut_ = |
| 134 fake_common_desktop_.path().Append(shortcut_name); | 135 fake_common_desktop_.path().Append(shortcut_name); |
| 135 system_start_menu_shortcut_ = | 136 system_start_menu_shortcut_ = |
| 136 fake_common_start_menu_.path().Append( | 137 fake_common_start_menu_.path().Append(shortcut_name); |
| 137 dist_->GetStartMenuShortcutSubfolder( | 138 system_start_menu_subdir_shortcut_ = |
| 139 fake_common_start_menu_.path() | |
| 140 .Append(dist_->GetStartMenuShortcutSubfolder( | |
| 138 BrowserDistribution::SUBFOLDER_CHROME)) | 141 BrowserDistribution::SUBFOLDER_CHROME)) |
| 139 .Append(shortcut_name); | 142 .Append(shortcut_name); |
| 140 user_alternate_desktop_shortcut_ = | 143 user_alternate_desktop_shortcut_ = |
| 141 fake_user_desktop_.path().Append(alternate_shortcut_name); | 144 fake_user_desktop_.path().Append(alternate_shortcut_name); |
| 142 } | 145 } |
| 143 | 146 |
| 144 void TearDown() override { | 147 void TearDown() override { |
| 145 // Try to unpin potentially pinned shortcuts (although pinning isn't tested, | 148 // Try to unpin potentially pinned shortcuts (although pinning isn't tested, |
| 146 // the call itself might still have pinned the Start Menu shortcuts). | 149 // the call itself might still have pinned the Start Menu shortcuts). |
| 147 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_); | 150 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_); |
| 151 base::win::UnpinShortcutFromTaskbar(user_start_menu_subdir_shortcut_); | |
| 148 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); | 152 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); |
| 153 base::win::UnpinShortcutFromTaskbar(system_start_menu_subdir_shortcut_); | |
| 149 CoUninitialize(); | 154 CoUninitialize(); |
| 150 } | 155 } |
| 151 | 156 |
| 152 installer::MasterPreferences* GetFakeMasterPrefs( | 157 installer::MasterPreferences* GetFakeMasterPrefs( |
| 153 bool do_not_create_desktop_shortcut, | 158 bool do_not_create_desktop_shortcut, |
| 154 bool do_not_create_quick_launch_shortcut, | 159 bool do_not_create_quick_launch_shortcut, |
| 155 bool alternate_desktop_shortcut) { | 160 bool alternate_desktop_shortcut) { |
| 156 const struct { | 161 const struct { |
| 157 const char* pref_name; | 162 const char* pref_name; |
| 158 bool is_desired; | 163 bool is_desired; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 base::ScopedTempDir fake_common_start_menu_; | 198 base::ScopedTempDir fake_common_start_menu_; |
| 194 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 199 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
| 195 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 200 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
| 196 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 201 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
| 197 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 202 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
| 198 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 203 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
| 199 | 204 |
| 200 base::FilePath user_desktop_shortcut_; | 205 base::FilePath user_desktop_shortcut_; |
| 201 base::FilePath user_quick_launch_shortcut_; | 206 base::FilePath user_quick_launch_shortcut_; |
| 202 base::FilePath user_start_menu_shortcut_; | 207 base::FilePath user_start_menu_shortcut_; |
| 208 base::FilePath user_start_menu_subdir_shortcut_; | |
| 203 base::FilePath system_desktop_shortcut_; | 209 base::FilePath system_desktop_shortcut_; |
| 204 base::FilePath system_start_menu_shortcut_; | 210 base::FilePath system_start_menu_shortcut_; |
| 211 base::FilePath system_start_menu_subdir_shortcut_; | |
| 205 base::FilePath user_alternate_desktop_shortcut_; | 212 base::FilePath user_alternate_desktop_shortcut_; |
| 206 }; | 213 }; |
| 207 | 214 |
| 208 } // namespace | 215 } // namespace |
| 209 | 216 |
| 210 // Test that VisualElementsManifest.xml is not created when VisualElements are | 217 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 211 // not present. | 218 // not present. |
| 212 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 219 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 213 ASSERT_TRUE( | 220 ASSERT_TRUE( |
| 214 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); | 221 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); | 375 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); |
| 369 | 376 |
| 370 installer::CreateOrUpdateShortcuts( | 377 installer::CreateOrUpdateShortcuts( |
| 371 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 378 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 372 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); | 379 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); |
| 373 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 380 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 374 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); | 381 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
| 375 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); | 382 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); |
| 376 } | 383 } |
| 377 | 384 |
| 385 class MigrateShortcutTest : public InstallShortcutTest, | |
| 386 public testing::WithParamInterface< | |
| 387 testing::tuple< | |
| 388 installer::InstallShortcutOperation, | |
| 389 installer::InstallShortcutLevel>> { | |
| 390 | |
|
gab
2015/10/23 18:00:23
rm empty line
bcwhite
2015/10/23 18:08:31
Done.
| |
| 391 public: | |
| 392 MigrateShortcutTest() : shortcut_operation_(testing::get<0>(GetParam())), | |
| 393 shortcut_level_(testing::get<1>(GetParam())) {} | |
| 394 | |
| 395 protected: | |
| 396 const installer::InstallShortcutOperation shortcut_operation_; | |
| 397 const installer::InstallShortcutLevel shortcut_level_; | |
| 398 | |
| 399 private: | |
| 400 DISALLOW_COPY_AND_ASSIGN(MigrateShortcutTest); | |
| 401 }; | |
| 402 | |
| 403 TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) { | |
| 404 base::win::ShortcutProperties dummy_properties; | |
| 405 base::FilePath dummy_target; | |
| 406 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | |
| 407 dummy_properties.set_target(expected_properties_.target); | |
| 408 dummy_properties.set_working_dir(fake_user_desktop_.path()); | |
| 409 dummy_properties.set_arguments(L"--dummy --args"); | |
| 410 dummy_properties.set_app_id(L"El.Dummiest"); | |
| 411 | |
| 412 base::FilePath start_menu_shortcut; | |
| 413 base::FilePath start_menu_subdir_shortcut; | |
| 414 if (shortcut_level_ == installer::CURRENT_USER) { | |
| 415 start_menu_shortcut = user_start_menu_shortcut_; | |
| 416 start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_; | |
| 417 } else { | |
| 418 start_menu_shortcut = system_start_menu_shortcut_; | |
| 419 start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_; | |
| 420 } | |
| 421 | |
| 422 ASSERT_TRUE(base::CreateDirectory(start_menu_subdir_shortcut.DirName())); | |
| 423 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); | |
| 424 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
| 425 start_menu_subdir_shortcut, dummy_properties, | |
| 426 base::win::SHORTCUT_CREATE_ALWAYS)); | |
| 427 ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut)); | |
| 428 ASSERT_FALSE(base::PathExists(start_menu_shortcut)); | |
| 429 | |
| 430 installer::CreateOrUpdateShortcuts(chrome_exe_, *product_, *prefs_, | |
| 431 shortcut_level_, shortcut_operation_); | |
| 432 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); | |
| 433 ASSERT_TRUE(base::PathExists(start_menu_shortcut)); | |
| 434 } | |
| 435 | |
| 436 // Verify that any installer operation for any installation level triggers | |
| 437 // the migration from sub-folder to root of start-menu. | |
| 438 INSTANTIATE_TEST_CASE_P( | |
| 439 MigrateShortcutTests, MigrateShortcutTest, | |
| 440 testing::Combine( | |
| 441 testing::Values( | |
| 442 installer::INSTALL_SHORTCUT_REPLACE_EXISTING, | |
| 443 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL, | |
| 444 installer::INSTALL_SHORTCUT_CREATE_ALL), | |
| 445 testing::Values( | |
| 446 installer::CURRENT_USER, | |
| 447 installer::ALL_USERS))); | |
| 448 | |
| 378 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { | 449 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { |
| 379 base::win::ShortcutProperties dummy_properties; | 450 base::win::ShortcutProperties dummy_properties; |
| 380 base::FilePath dummy_target; | 451 base::FilePath dummy_target; |
| 381 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 452 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
| 382 dummy_properties.set_target(dummy_target); | 453 dummy_properties.set_target(dummy_target); |
| 383 | 454 |
| 384 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 455 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 385 system_desktop_shortcut_, dummy_properties, | 456 system_desktop_shortcut_, dummy_properties, |
| 386 base::win::SHORTCUT_CREATE_ALWAYS)); | 457 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 387 ASSERT_TRUE(base::CreateDirectory( | 458 ASSERT_TRUE(base::CreateDirectory( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 509 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 439 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 510 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 440 } | 511 } |
| 441 | 512 |
| 442 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 513 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 443 base::string16 val(L"Google Chrome"); | 514 base::string16 val(L"Google Chrome"); |
| 444 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 515 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 445 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 516 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 446 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 517 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 447 } | 518 } |
| OLD | NEW |