| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 // 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. |
| 263 base::string16 non_default_profile_extension_app_id_; | 263 base::string16 non_default_profile_extension_app_id_; |
| 264 | 264 |
| 265 private: | 265 private: |
| 266 DISALLOW_COPY_AND_ASSIGN(ShellIntegrationWinMigrateShortcutTest); | 266 DISALLOW_COPY_AND_ASSIGN(ShellIntegrationWinMigrateShortcutTest); |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 } // namespace | 269 } // namespace |
| 270 | 270 |
| 271 // Test migration when not clearing dual mode. | 271 TEST_F(ShellIntegrationWinMigrateShortcutTest, ClearDualModeAndAdjustAppIds) { |
| 272 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontClearDualMode) { | |
| 273 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
| 274 return; | |
| 275 | |
| 276 EXPECT_EQ(9, | |
| 277 ShellIntegration::MigrateShortcutsInPathInternal( | |
| 278 chrome_exe_, temp_dir_.path(), false)); | |
| 279 | |
| 280 // Only shortcut 1, 3, 4, 5, 6, 7, 8, 9, and 10 should have been migrated. | |
| 281 shortcuts_[1].properties.set_app_id(chrome_app_id_); | |
| 282 shortcuts_[3].properties.set_app_id(chrome_app_id_); | |
| 283 shortcuts_[4].properties.set_app_id(chrome_app_id_); | |
| 284 shortcuts_[5].properties.set_app_id(chrome_app_id_); | |
| 285 shortcuts_[6].properties.set_app_id(non_default_profile_chrome_app_id_); | |
| 286 shortcuts_[7].properties.set_app_id(non_default_user_data_dir_chrome_app_id_); | |
| 287 shortcuts_[8].properties.set_app_id( | |
| 288 non_default_user_data_dir_and_profile_chrome_app_id_); | |
| 289 shortcuts_[9].properties.set_app_id(extension_app_id_); | |
| 290 shortcuts_[10].properties.set_app_id(non_default_profile_extension_app_id_); | |
| 291 | |
| 292 // Explicitly set the dual_mode expectations on all shortcuts that didn't have | |
| 293 // it to ensure ValidateShortcut verifies it. Those that had it should remain | |
| 294 // unchanged per |clear_dual_mode| being false above. | |
| 295 for (size_t i = 0; i < shortcuts_.size(); ++i) { | |
| 296 if (!(shortcuts_[i].properties.options & | |
| 297 base::win::ShortcutProperties::PROPERTIES_DUAL_MODE)) { | |
| 298 shortcuts_[i].properties.set_dual_mode(false); | |
| 299 } | |
| 300 } | |
| 301 | |
| 302 for (size_t i = 0; i < shortcuts_.size(); ++i) { | |
| 303 SCOPED_TRACE(i); | |
| 304 base::win::ValidateShortcut(shortcuts_[i].path, shortcuts_[i].properties); | |
| 305 } | |
| 306 | |
| 307 // Make sure shortcuts are not re-migrated. | |
| 308 EXPECT_EQ(0, | |
| 309 ShellIntegration::MigrateShortcutsInPathInternal( | |
| 310 chrome_exe_, temp_dir_.path(), false)); | |
| 311 } | |
| 312 | |
| 313 // Test migration when also clearing dual mode. | |
| 314 TEST_F(ShellIntegrationWinMigrateShortcutTest, ClearDualMode) { | |
| 315 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 272 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 316 return; | 273 return; |
| 317 | 274 |
| 318 // 9 shortcuts should have their app id updated below and shortcut 11 should | 275 // 9 shortcuts should have their app id updated below and shortcut 11 should |
| 319 // be migrated away from dual_mode for a total of 10 shortcuts migrated. | 276 // be migrated away from dual_mode for a total of 10 shortcuts migrated. |
| 320 EXPECT_EQ(10, ShellIntegration::MigrateShortcutsInPathInternal( | 277 EXPECT_EQ(10, ShellIntegration::MigrateShortcutsInPathInternal( |
| 321 chrome_exe_, temp_dir_.path(), true)); | 278 chrome_exe_, temp_dir_.path())); |
| 322 | 279 |
| 323 // Shortcut 1, 3, 4, 5, 6, 7, 8, 9, and 10 should have had their app_id fixed. | 280 // Shortcut 1, 3, 4, 5, 6, 7, 8, 9, and 10 should have had their app_id fixed. |
| 324 shortcuts_[1].properties.set_app_id(chrome_app_id_); | 281 shortcuts_[1].properties.set_app_id(chrome_app_id_); |
| 325 shortcuts_[3].properties.set_app_id(chrome_app_id_); | 282 shortcuts_[3].properties.set_app_id(chrome_app_id_); |
| 326 shortcuts_[4].properties.set_app_id(chrome_app_id_); | 283 shortcuts_[4].properties.set_app_id(chrome_app_id_); |
| 327 shortcuts_[5].properties.set_app_id(chrome_app_id_); | 284 shortcuts_[5].properties.set_app_id(chrome_app_id_); |
| 328 shortcuts_[6].properties.set_app_id(non_default_profile_chrome_app_id_); | 285 shortcuts_[6].properties.set_app_id(non_default_profile_chrome_app_id_); |
| 329 shortcuts_[7].properties.set_app_id(non_default_user_data_dir_chrome_app_id_); | 286 shortcuts_[7].properties.set_app_id(non_default_user_data_dir_chrome_app_id_); |
| 330 shortcuts_[8].properties.set_app_id( | 287 shortcuts_[8].properties.set_app_id( |
| 331 non_default_user_data_dir_and_profile_chrome_app_id_); | 288 non_default_user_data_dir_and_profile_chrome_app_id_); |
| 332 shortcuts_[9].properties.set_app_id(extension_app_id_); | 289 shortcuts_[9].properties.set_app_id(extension_app_id_); |
| 333 shortcuts_[10].properties.set_app_id(non_default_profile_extension_app_id_); | 290 shortcuts_[10].properties.set_app_id(non_default_profile_extension_app_id_); |
| 334 | 291 |
| 335 // No shortcut should still have the dual_mode property. | 292 // No shortcut should still have the dual_mode property. |
| 336 for (size_t i = 0; i < shortcuts_.size(); ++i) | 293 for (size_t i = 0; i < shortcuts_.size(); ++i) |
| 337 shortcuts_[i].properties.set_dual_mode(false); | 294 shortcuts_[i].properties.set_dual_mode(false); |
| 338 | 295 |
| 339 for (size_t i = 0; i < shortcuts_.size(); ++i) { | 296 for (size_t i = 0; i < shortcuts_.size(); ++i) { |
| 340 SCOPED_TRACE(i); | 297 SCOPED_TRACE(i); |
| 341 base::win::ValidateShortcut(shortcuts_[i].path, shortcuts_[i].properties); | 298 base::win::ValidateShortcut(shortcuts_[i].path, shortcuts_[i].properties); |
| 342 } | 299 } |
| 343 | 300 |
| 344 // Make sure shortcuts are not re-migrated. | 301 // Make sure shortcuts are not re-migrated. |
| 345 EXPECT_EQ(0, | 302 EXPECT_EQ(0, ShellIntegration::MigrateShortcutsInPathInternal( |
| 346 ShellIntegration::MigrateShortcutsInPathInternal( | 303 chrome_exe_, temp_dir_.path())); |
| 347 chrome_exe_, temp_dir_.path(), false)); | |
| 348 } | 304 } |
| 349 | 305 |
| 350 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { | 306 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { |
| 351 const base::string16 base_app_id( | 307 const base::string16 base_app_id( |
| 352 BrowserDistribution::GetDistribution()->GetBaseAppId()); | 308 BrowserDistribution::GetDistribution()->GetBaseAppId()); |
| 353 | 309 |
| 354 // Empty profile path should get chrome::kBrowserAppID | 310 // Empty profile path should get chrome::kBrowserAppID |
| 355 base::FilePath empty_path; | 311 base::FilePath empty_path; |
| 356 EXPECT_EQ(base_app_id, | 312 EXPECT_EQ(base_app_id, |
| 357 ShellIntegration::GetAppModelIdForProfile(base_app_id, empty_path)); | 313 ShellIntegration::GetAppModelIdForProfile(base_app_id, empty_path)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 default_profile_path)); | 351 default_profile_path)); |
| 396 | 352 |
| 397 // Non-default profile path should get chrome::kBrowserAppID + AppList joined | 353 // Non-default profile path should get chrome::kBrowserAppID + AppList joined |
| 398 // with profile info. | 354 // with profile info. |
| 399 base::FilePath profile_path(FILE_PATH_LITERAL("root")); | 355 base::FilePath profile_path(FILE_PATH_LITERAL("root")); |
| 400 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | 356 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
| 401 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | 357 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
| 402 EXPECT_EQ(base_app_id + L".udd.UserDataTest", | 358 EXPECT_EQ(base_app_id + L".udd.UserDataTest", |
| 403 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); | 359 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); |
| 404 } | 360 } |
| OLD | NEW |