| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, | 95 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, |
| 96 fake_common_start_menu_.path())); | 96 fake_common_start_menu_.path())); |
| 97 | 97 |
| 98 base::FilePath icon_path; | 98 base::FilePath icon_path; |
| 99 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); | 99 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); |
| 100 test_properties_.set_target(chrome_exe_); | 100 test_properties_.set_target(chrome_exe_); |
| 101 test_properties_.set_arguments(L"--test --chrome"); | 101 test_properties_.set_arguments(L"--test --chrome"); |
| 102 test_properties_.set_description(L"Makes polar bears dance."); | 102 test_properties_.set_description(L"Makes polar bears dance."); |
| 103 test_properties_.set_icon(icon_path, 7); | 103 test_properties_.set_icon(icon_path, 7); |
| 104 test_properties_.set_app_id(L"Polar.Bear"); | 104 test_properties_.set_app_id(L"Polar.Bear"); |
| 105 test_properties_.set_dual_mode(true); | |
| 106 } | 105 } |
| 107 | 106 |
| 108 // Returns the expected path of a test shortcut. Returns an empty FilePath on | 107 // Returns the expected path of a test shortcut. Returns an empty FilePath on |
| 109 // failure. | 108 // failure. |
| 110 base::FilePath GetExpectedShortcutPath( | 109 base::FilePath GetExpectedShortcutPath( |
| 111 ShellUtil::ShortcutLocation location, | 110 ShellUtil::ShortcutLocation location, |
| 112 BrowserDistribution* dist, | 111 BrowserDistribution* dist, |
| 113 const ShellUtil::ShortcutProperties& properties) { | 112 const ShellUtil::ShortcutProperties& properties) { |
| 114 base::FilePath expected_path; | 113 base::FilePath expected_path; |
| 115 switch (location) { | 114 switch (location) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 expected_properties.set_icon(chrome_exe_, icon_index); | 179 expected_properties.set_icon(chrome_exe_, icon_index); |
| 181 } | 180 } |
| 182 | 181 |
| 183 if (properties.has_app_id()) { | 182 if (properties.has_app_id()) { |
| 184 expected_properties.set_app_id(properties.app_id); | 183 expected_properties.set_app_id(properties.app_id); |
| 185 } else { | 184 } else { |
| 186 // Tests are always seen as user-level installs in ShellUtil. | 185 // Tests are always seen as user-level installs in ShellUtil. |
| 187 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); | 186 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
| 188 } | 187 } |
| 189 | 188 |
| 190 if (properties.has_dual_mode()) | |
| 191 expected_properties.set_dual_mode(properties.dual_mode); | |
| 192 else | |
| 193 expected_properties.set_dual_mode(false); | |
| 194 | |
| 195 base::win::ValidateShortcut(expected_path, expected_properties); | 189 base::win::ValidateShortcut(expected_path, expected_properties); |
| 196 } | 190 } |
| 197 | 191 |
| 198 BrowserDistribution* dist_; | 192 BrowserDistribution* dist_; |
| 199 scoped_ptr<installer::Product> product_; | 193 scoped_ptr<installer::Product> product_; |
| 200 | 194 |
| 201 // A ShellUtil::ShortcutProperties object with common properties set already. | 195 // A ShellUtil::ShortcutProperties object with common properties set already. |
| 202 ShellUtil::ShortcutProperties test_properties_; | 196 ShellUtil::ShortcutProperties test_properties_; |
| 203 | 197 |
| 204 base::ScopedTempDir temp_dir_; | 198 base::ScopedTempDir temp_dir_; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 new_properties.set_arguments(L"--new-arguments"); | 314 new_properties.set_arguments(L"--new-arguments"); |
| 321 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 315 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 322 ShellUtil::SHORTCUT_LOCATION_DESKTOP, | 316 ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 323 dist_, new_properties, | 317 dist_, new_properties, |
| 324 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING)); | 318 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING)); |
| 325 | 319 |
| 326 // Expect the properties set in |new_properties| to be set as above and | 320 // Expect the properties set in |new_properties| to be set as above and |
| 327 // properties that don't have a default value to be set back to their default | 321 // properties that don't have a default value to be set back to their default |
| 328 // (as validated in ValidateChromeShortcut()) or unset if they don't . | 322 // (as validated in ValidateChromeShortcut()) or unset if they don't . |
| 329 ShellUtil::ShortcutProperties expected_properties(new_properties); | 323 ShellUtil::ShortcutProperties expected_properties(new_properties); |
| 330 expected_properties.set_dual_mode(false); | |
| 331 | 324 |
| 332 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 325 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 333 expected_properties); | 326 expected_properties); |
| 334 } | 327 } |
| 335 | 328 |
| 336 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) { | 329 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) { |
| 337 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 330 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 338 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 331 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
| 339 dist_, test_properties_, | 332 dist_, test_properties_, |
| 340 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 333 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
| 341 | 334 |
| 342 // Only changing one property, don't need all the defaults. | 335 // Only changing one property, don't need all the defaults. |
| 343 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 336 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); |
| 344 updated_properties.set_arguments(L"--updated --arguments"); | 337 updated_properties.set_arguments(L"--updated --arguments"); |
| 345 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 338 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 346 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 339 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
| 347 dist_, updated_properties, | 340 dist_, updated_properties, |
| 348 ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); | 341 ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); |
| 349 | 342 |
| 350 // Expect the properties set in |updated_properties| to be set as above and | 343 // Expect the properties set in |updated_properties| to be set as above and |
| 351 // all other properties to remain unchanged. | 344 // all other properties to remain unchanged. |
| 352 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 345 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
| 353 expected_properties.set_arguments(updated_properties.arguments); | 346 expected_properties.set_arguments(updated_properties.arguments); |
| 354 | 347 |
| 355 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 348 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
| 356 expected_properties); | 349 expected_properties); |
| 357 } | 350 } |
| 358 | 351 |
| 359 TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) { | |
| 360 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | |
| 361 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); | |
| 362 ASSERT_TRUE( | |
| 363 ShellUtil::CreateOrUpdateShortcut( | |
| 364 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist_, | |
| 365 properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
| 366 | |
| 367 ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER); | |
| 368 added_properties.set_dual_mode(true); | |
| 369 ASSERT_TRUE( | |
| 370 ShellUtil::CreateOrUpdateShortcut( | |
| 371 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist_, | |
| 372 added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING)); | |
| 373 | |
| 374 ShellUtil::ShortcutProperties expected_properties(properties); | |
| 375 expected_properties.set_dual_mode(true); | |
| 376 | |
| 377 ValidateChromeShortcut( | |
| 378 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, | |
| 379 dist_, expected_properties); | |
| 380 } | |
| 381 | |
| 382 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { | 352 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { |
| 383 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
| 384 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
| 385 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 355 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
| 386 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 356 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
| 387 test_properties_); | 357 test_properties_); |
| 388 } | 358 } |
| 389 | 359 |
| 390 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { | 360 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { |
| 391 base::string16 shortcut_name( | 361 base::string16 shortcut_name( |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 | 1019 |
| 1050 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 1020 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
| 1051 L"MZXW6YTB", L"MZXW6YTBOI"}; | 1021 L"MZXW6YTB", L"MZXW6YTBOI"}; |
| 1052 | 1022 |
| 1053 // Run the tests, with one more letter in the input every pass. | 1023 // Run the tests, with one more letter in the input every pass. |
| 1054 for (size_t i = 0; i < arraysize(expected); ++i) { | 1024 for (size_t i = 0; i < arraysize(expected); ++i) { |
| 1055 ASSERT_EQ(expected[i], | 1025 ASSERT_EQ(expected[i], |
| 1056 ShellUtil::ByteArrayToBase32(test_array, i)); | 1026 ShellUtil::ByteArrayToBase32(test_array, i)); |
| 1057 } | 1027 } |
| 1058 } | 1028 } |
| OLD | NEW |