| 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/browser/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 struct ShortcutTestObject { | 32 struct ShortcutTestObject { |
| 33 base::FilePath path; | 33 base::FilePath path; |
| 34 base::win::ShortcutProperties properties; | 34 base::win::ShortcutProperties properties; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 class ShellIntegrationWinMigrateShortcutTest : public testing::Test { | 37 class ShellIntegrationWinMigrateShortcutTest : public testing::Test { |
| 38 protected: | 38 protected: |
| 39 ShellIntegrationWinMigrateShortcutTest() | 39 ShellIntegrationWinMigrateShortcutTest() {} |
| 40 : desired_dual_mode_for_os_version( | |
| 41 InstallUtil::ShouldInstallMetroProperties()) {} | |
| 42 | 40 |
| 43 void SetUp() override { | 41 void SetUp() override { |
| 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 45 | 43 |
| 46 // A path to a random target. | 44 // A path to a random target. |
| 47 base::CreateTemporaryFileInDir(temp_dir_.path(), &other_target_); | 45 base::CreateTemporaryFileInDir(temp_dir_.path(), &other_target_); |
| 48 | 46 |
| 49 // This doesn't need to actually have a base name of "chrome.exe". | 47 // This doesn't need to actually have a base name of "chrome.exe". |
| 50 base::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_); | 48 base::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_); |
| 51 | 49 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 255 |
| 258 // An example extension id of an example app. | 256 // An example extension id of an example app. |
| 259 base::string16 extension_id_; | 257 base::string16 extension_id_; |
| 260 | 258 |
| 261 // The app id of the example app for the default profile and user data dir. | 259 // The app id of the example app for the default profile and user data dir. |
| 262 base::string16 extension_app_id_; | 260 base::string16 extension_app_id_; |
| 263 | 261 |
| 264 // The app id of the example app for the non-default profile. | 262 // The app id of the example app for the non-default profile. |
| 265 base::string16 non_default_profile_extension_app_id_; | 263 base::string16 non_default_profile_extension_app_id_; |
| 266 | 264 |
| 267 // True if the dual mode property should be set for the default chrome | |
| 268 // shortcut on the current OS version. | |
| 269 const bool desired_dual_mode_for_os_version; | |
| 270 | |
| 271 private: | 265 private: |
| 272 DISALLOW_COPY_AND_ASSIGN(ShellIntegrationWinMigrateShortcutTest); | 266 DISALLOW_COPY_AND_ASSIGN(ShellIntegrationWinMigrateShortcutTest); |
| 273 }; | 267 }; |
| 274 | 268 |
| 275 } // namespace | 269 } // namespace |
| 276 | 270 |
| 277 // Test migration when not checking for dual mode. | 271 // Test migration when not checking for dual mode. |
| 278 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { | 272 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { |
| 279 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 273 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 280 return; | 274 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 chrome_exe_, temp_dir_.path(), false)); | 309 chrome_exe_, temp_dir_.path(), false)); |
| 316 } | 310 } |
| 317 | 311 |
| 318 // Test migration when also checking for dual mode. | 312 // Test migration when also checking for dual mode. |
| 319 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { | 313 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { |
| 320 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 314 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 321 return; | 315 return; |
| 322 | 316 |
| 323 // 9 shortcuts should have their app id updated below. | 317 // 9 shortcuts should have their app id updated below. |
| 324 | 318 |
| 325 // If |desired_dual_mode_for_os_version| is true: shortcut 2 and 13 should | 319 // shortcut 11 should be migrate away from dual_mode for a total of 10 |
| 326 // also be migrated to dual_mode for a total of 11 shortcuts migrated. | 320 // shortcuts migrated. |
| 327 // If |desired_dual_mode_for_os_version| is false: shortcut 11 should | 321 EXPECT_EQ(10, ShellIntegration::MigrateShortcutsInPathInternal( |
| 328 // be migrate away from dual_mode for a total of 10 shortcuts migrated. | 322 chrome_exe_, temp_dir_.path(), true)); |
| 329 EXPECT_EQ(desired_dual_mode_for_os_version ? 11 : 10, | |
| 330 ShellIntegration::MigrateShortcutsInPathInternal( | |
| 331 chrome_exe_, temp_dir_.path(), true)); | |
| 332 | 323 |
| 333 // Shortcut 1, 3, 4, 5, 6, 7, 8, 9, and 10 should have had both their app_id | 324 // Shortcut 1, 3, 4, 5, 6, 7, 8, 9, and 10 should have had both their app_id |
| 334 // fixed and shortcut 1, 2, 3, 4, and 5 should also have had their dual_mode | 325 // fixed and shortcut 1, 2, 3, 4, and 5 should also have had their dual_mode |
| 335 // property added if it is desired (or 11 should have had it removed if it is | 326 // property added if it is desired (or 11 should have had it removed if it is |
| 336 // not). | 327 // not). |
| 337 shortcuts_[1].properties.set_app_id(chrome_app_id_); | 328 shortcuts_[1].properties.set_app_id(chrome_app_id_); |
| 338 shortcuts_[3].properties.set_app_id(chrome_app_id_); | 329 shortcuts_[3].properties.set_app_id(chrome_app_id_); |
| 339 shortcuts_[4].properties.set_app_id(chrome_app_id_); | 330 shortcuts_[4].properties.set_app_id(chrome_app_id_); |
| 340 shortcuts_[5].properties.set_app_id(chrome_app_id_); | 331 shortcuts_[5].properties.set_app_id(chrome_app_id_); |
| 341 shortcuts_[6].properties.set_app_id(non_default_profile_chrome_app_id_); | 332 shortcuts_[6].properties.set_app_id(non_default_profile_chrome_app_id_); |
| 342 shortcuts_[7].properties.set_app_id(non_default_user_data_dir_chrome_app_id_); | 333 shortcuts_[7].properties.set_app_id(non_default_user_data_dir_chrome_app_id_); |
| 343 shortcuts_[8].properties.set_app_id( | 334 shortcuts_[8].properties.set_app_id( |
| 344 non_default_user_data_dir_and_profile_chrome_app_id_); | 335 non_default_user_data_dir_and_profile_chrome_app_id_); |
| 345 shortcuts_[9].properties.set_app_id(extension_app_id_); | 336 shortcuts_[9].properties.set_app_id(extension_app_id_); |
| 346 shortcuts_[10].properties.set_app_id(non_default_profile_extension_app_id_); | 337 shortcuts_[10].properties.set_app_id(non_default_profile_extension_app_id_); |
| 347 | 338 |
| 348 // Explicitly flag the expected dual_mode properties. | 339 // Explicitly flag the expected dual_mode properties. |
| 349 shortcuts_[0].properties.set_dual_mode(false); | 340 shortcuts_[0].properties.set_dual_mode(false); |
| 350 if (desired_dual_mode_for_os_version) { | 341 shortcuts_[11].properties.set_dual_mode(false); |
| 351 shortcuts_[1].properties.set_dual_mode(true); | |
| 352 shortcuts_[2].properties.set_dual_mode(true); | |
| 353 shortcuts_[3].properties.set_dual_mode(true); | |
| 354 shortcuts_[4].properties.set_dual_mode(true); | |
| 355 shortcuts_[5].properties.set_dual_mode(true); | |
| 356 shortcuts_[12].properties.set_dual_mode(true); | |
| 357 } else { | |
| 358 shortcuts_[11].properties.set_dual_mode(false); | |
| 359 } | |
| 360 shortcuts_[6].properties.set_dual_mode(false); | 342 shortcuts_[6].properties.set_dual_mode(false); |
| 361 shortcuts_[7].properties.set_dual_mode(false); | 343 shortcuts_[7].properties.set_dual_mode(false); |
| 362 shortcuts_[8].properties.set_dual_mode(false); | 344 shortcuts_[8].properties.set_dual_mode(false); |
| 363 shortcuts_[9].properties.set_dual_mode(false); | 345 shortcuts_[9].properties.set_dual_mode(false); |
| 364 shortcuts_[10].properties.set_dual_mode(false); | 346 shortcuts_[10].properties.set_dual_mode(false); |
| 365 | 347 |
| 366 for (size_t i = 0; i < shortcuts_.size(); ++i) { | 348 for (size_t i = 0; i < shortcuts_.size(); ++i) { |
| 367 SCOPED_TRACE(i); | 349 SCOPED_TRACE(i); |
| 368 base::win::ValidateShortcut(shortcuts_[i].path, shortcuts_[i].properties); | 350 base::win::ValidateShortcut(shortcuts_[i].path, shortcuts_[i].properties); |
| 369 } | 351 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 default_profile_path)); | 404 default_profile_path)); |
| 423 | 405 |
| 424 // Non-default profile path should get chrome::kBrowserAppID + AppList joined | 406 // Non-default profile path should get chrome::kBrowserAppID + AppList joined |
| 425 // with profile info. | 407 // with profile info. |
| 426 base::FilePath profile_path(FILE_PATH_LITERAL("root")); | 408 base::FilePath profile_path(FILE_PATH_LITERAL("root")); |
| 427 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | 409 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
| 428 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | 410 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
| 429 EXPECT_EQ(base_app_id + L".udd.UserDataTest", | 411 EXPECT_EQ(base_app_id + L".udd.UserDataTest", |
| 430 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); | 412 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); |
| 431 } | 413 } |
| OLD | NEW |