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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); | 355 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); |
349 | 356 |
350 installer::CreateOrUpdateShortcuts( | 357 installer::CreateOrUpdateShortcuts( |
351 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 358 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
352 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); | 359 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); |
353 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 360 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
354 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); | 361 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
355 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); | 362 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); |
356 } | 363 } |
357 | 364 |
| 365 class MigrateShortcutTest : public InstallShortcutTest, |
| 366 public testing::WithParamInterface< |
| 367 testing::tuple< |
| 368 installer::InstallShortcutOperation, |
| 369 installer::InstallShortcutLevel>> { |
| 370 public: |
| 371 MigrateShortcutTest() : shortcut_operation_(testing::get<0>(GetParam())), |
| 372 shortcut_level_(testing::get<1>(GetParam())) {} |
| 373 |
| 374 protected: |
| 375 const installer::InstallShortcutOperation shortcut_operation_; |
| 376 const installer::InstallShortcutLevel shortcut_level_; |
| 377 |
| 378 private: |
| 379 DISALLOW_COPY_AND_ASSIGN(MigrateShortcutTest); |
| 380 }; |
| 381 |
| 382 TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) { |
| 383 base::win::ShortcutProperties dummy_properties; |
| 384 base::FilePath dummy_target; |
| 385 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
| 386 dummy_properties.set_target(expected_properties_.target); |
| 387 dummy_properties.set_working_dir(fake_user_desktop_.path()); |
| 388 dummy_properties.set_arguments(L"--dummy --args"); |
| 389 dummy_properties.set_app_id(L"El.Dummiest"); |
| 390 |
| 391 base::FilePath start_menu_shortcut; |
| 392 base::FilePath start_menu_subdir_shortcut; |
| 393 if (shortcut_level_ == installer::CURRENT_USER) { |
| 394 start_menu_shortcut = user_start_menu_shortcut_; |
| 395 start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_; |
| 396 } else { |
| 397 start_menu_shortcut = system_start_menu_shortcut_; |
| 398 start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_; |
| 399 } |
| 400 |
| 401 ASSERT_TRUE(base::CreateDirectory(start_menu_subdir_shortcut.DirName())); |
| 402 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); |
| 403 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 404 start_menu_subdir_shortcut, dummy_properties, |
| 405 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 406 ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut)); |
| 407 ASSERT_FALSE(base::PathExists(start_menu_shortcut)); |
| 408 |
| 409 installer::CreateOrUpdateShortcuts(chrome_exe_, *product_, *prefs_, |
| 410 shortcut_level_, shortcut_operation_); |
| 411 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); |
| 412 ASSERT_TRUE(base::PathExists(start_menu_shortcut)); |
| 413 } |
| 414 |
| 415 // Verify that any installer operation for any installation level triggers |
| 416 // the migration from sub-folder to root of start-menu. |
| 417 INSTANTIATE_TEST_CASE_P( |
| 418 MigrateShortcutTests, MigrateShortcutTest, |
| 419 testing::Combine( |
| 420 testing::Values( |
| 421 installer::INSTALL_SHORTCUT_REPLACE_EXISTING, |
| 422 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL, |
| 423 installer::INSTALL_SHORTCUT_CREATE_ALL), |
| 424 testing::Values( |
| 425 installer::CURRENT_USER, |
| 426 installer::ALL_USERS))); |
| 427 |
358 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { | 428 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { |
359 base::win::ShortcutProperties dummy_properties; | 429 base::win::ShortcutProperties dummy_properties; |
360 base::FilePath dummy_target; | 430 base::FilePath dummy_target; |
361 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 431 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
362 dummy_properties.set_target(dummy_target); | 432 dummy_properties.set_target(dummy_target); |
363 | 433 |
364 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 434 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
365 system_desktop_shortcut_, dummy_properties, | 435 system_desktop_shortcut_, dummy_properties, |
366 base::win::SHORTCUT_CREATE_ALWAYS)); | 436 base::win::SHORTCUT_CREATE_ALWAYS)); |
367 ASSERT_TRUE(base::CreateDirectory( | 437 ASSERT_TRUE(base::CreateDirectory( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 488 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
419 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 489 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
420 } | 490 } |
421 | 491 |
422 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 492 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
423 base::string16 val(L"Google Chrome"); | 493 base::string16 val(L"Google Chrome"); |
424 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 494 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
425 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 495 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
426 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 496 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
427 } | 497 } |
OLD | NEW |