| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 base::FilePath user_alternate_desktop_shortcut_; | 208 base::FilePath user_alternate_desktop_shortcut_; |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 } // namespace | 211 } // namespace |
| 212 | 212 |
| 213 // Test that VisualElementsManifest.xml is not created when VisualElements are | 213 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 214 // not present. | 214 // not present. |
| 215 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 215 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 216 ASSERT_TRUE( | 216 ASSERT_TRUE( |
| 217 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); | 217 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| 218 ASSERT_FALSE(file_util::PathExists(manifest_path_)); | 218 ASSERT_FALSE(base::PathExists(manifest_path_)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // Test that VisualElementsManifest.xml is created with the correct content when | 221 // Test that VisualElementsManifest.xml is created with the correct content when |
| 222 // VisualElements are present. | 222 // VisualElements are present. |
| 223 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { | 223 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { |
| 224 ASSERT_TRUE(file_util::CreateDirectory( | 224 ASSERT_TRUE(file_util::CreateDirectory( |
| 225 version_dir_.Append(installer::kVisualElements))); | 225 version_dir_.Append(installer::kVisualElements))); |
| 226 ASSERT_TRUE( | 226 ASSERT_TRUE( |
| 227 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); | 227 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
| 228 ASSERT_TRUE(file_util::PathExists(manifest_path_)); | 228 ASSERT_TRUE(base::PathExists(manifest_path_)); |
| 229 | 229 |
| 230 std::string read_manifest; | 230 std::string read_manifest; |
| 231 ASSERT_TRUE(file_util::ReadFileToString(manifest_path_, &read_manifest)); | 231 ASSERT_TRUE(file_util::ReadFileToString(manifest_path_, &read_manifest)); |
| 232 | 232 |
| 233 static const char kExpectedManifest[] = | 233 static const char kExpectedManifest[] = |
| 234 "<Application>\r\n" | 234 "<Application>\r\n" |
| 235 " <VisualElements\r\n" | 235 " <VisualElements\r\n" |
| 236 " DisplayName='Google Chrome'\r\n" | 236 " DisplayName='Google Chrome'\r\n" |
| 237 " Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" | 237 " Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" |
| 238 " SmallLogo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" | 238 " SmallLogo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 base::win::ValidateShortcut(user_start_menu_shortcut_, | 282 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 283 expected_start_menu_properties_); | 283 expected_start_menu_properties_); |
| 284 } | 284 } |
| 285 | 285 |
| 286 TEST_F(InstallShortcutTest, CreateAllShortcutsButDesktopShortcut) { | 286 TEST_F(InstallShortcutTest, CreateAllShortcutsButDesktopShortcut) { |
| 287 scoped_ptr<installer::MasterPreferences> prefs_no_desktop( | 287 scoped_ptr<installer::MasterPreferences> prefs_no_desktop( |
| 288 GetFakeMasterPrefs(true, false, false)); | 288 GetFakeMasterPrefs(true, false, false)); |
| 289 installer::CreateOrUpdateShortcuts( | 289 installer::CreateOrUpdateShortcuts( |
| 290 chrome_exe_, *product_, *prefs_no_desktop, installer::CURRENT_USER, | 290 chrome_exe_, *product_, *prefs_no_desktop, installer::CURRENT_USER, |
| 291 installer::INSTALL_SHORTCUT_CREATE_ALL); | 291 installer::INSTALL_SHORTCUT_CREATE_ALL); |
| 292 ASSERT_FALSE(file_util::PathExists(user_desktop_shortcut_)); | 292 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); |
| 293 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 293 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 294 expected_properties_); | 294 expected_properties_); |
| 295 base::win::ValidateShortcut(user_start_menu_shortcut_, | 295 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 296 expected_start_menu_properties_); | 296 expected_start_menu_properties_); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(InstallShortcutTest, CreateAllShortcutsButQuickLaunchShortcut) { | 299 TEST_F(InstallShortcutTest, CreateAllShortcutsButQuickLaunchShortcut) { |
| 300 scoped_ptr<installer::MasterPreferences> prefs_no_ql( | 300 scoped_ptr<installer::MasterPreferences> prefs_no_ql( |
| 301 GetFakeMasterPrefs(false, true, false)); | 301 GetFakeMasterPrefs(false, true, false)); |
| 302 installer::CreateOrUpdateShortcuts( | 302 installer::CreateOrUpdateShortcuts( |
| 303 chrome_exe_, *product_, *prefs_no_ql, installer::CURRENT_USER, | 303 chrome_exe_, *product_, *prefs_no_ql, installer::CURRENT_USER, |
| 304 installer::INSTALL_SHORTCUT_CREATE_ALL); | 304 installer::INSTALL_SHORTCUT_CREATE_ALL); |
| 305 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 305 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 306 ASSERT_FALSE(file_util::PathExists(user_quick_launch_shortcut_)); | 306 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
| 307 base::win::ValidateShortcut(user_start_menu_shortcut_, | 307 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 308 expected_start_menu_properties_); | 308 expected_start_menu_properties_); |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST_F(InstallShortcutTest, ReplaceAll) { | 311 TEST_F(InstallShortcutTest, ReplaceAll) { |
| 312 base::win::ShortcutProperties dummy_properties; | 312 base::win::ShortcutProperties dummy_properties; |
| 313 base::FilePath dummy_target; | 313 base::FilePath dummy_target; |
| 314 ASSERT_TRUE( | 314 ASSERT_TRUE( |
| 315 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 315 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
| 316 dummy_properties.set_target(dummy_target); | 316 dummy_properties.set_target(dummy_target); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 352 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 353 user_desktop_shortcut_, dummy_properties, | 353 user_desktop_shortcut_, dummy_properties, |
| 354 base::win::SHORTCUT_CREATE_ALWAYS)); | 354 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 355 ASSERT_TRUE(file_util::CreateDirectory(user_start_menu_shortcut_.DirName())); | 355 ASSERT_TRUE(file_util::CreateDirectory(user_start_menu_shortcut_.DirName())); |
| 356 | 356 |
| 357 installer::CreateOrUpdateShortcuts( | 357 installer::CreateOrUpdateShortcuts( |
| 358 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 358 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 359 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); | 359 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); |
| 360 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 360 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 361 ASSERT_FALSE(file_util::PathExists(user_quick_launch_shortcut_)); | 361 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
| 362 ASSERT_FALSE(file_util::PathExists(user_start_menu_shortcut_)); | 362 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { | 365 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { |
| 366 base::win::ShortcutProperties dummy_properties; | 366 base::win::ShortcutProperties dummy_properties; |
| 367 base::FilePath dummy_target; | 367 base::FilePath dummy_target; |
| 368 ASSERT_TRUE( | 368 ASSERT_TRUE( |
| 369 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 369 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
| 370 dummy_properties.set_target(dummy_target); | 370 dummy_properties.set_target(dummy_target); |
| 371 | 371 |
| 372 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 372 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 373 system_desktop_shortcut_, dummy_properties, | 373 system_desktop_shortcut_, dummy_properties, |
| 374 base::win::SHORTCUT_CREATE_ALWAYS)); | 374 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 375 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 375 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 376 system_quick_launch_shortcut_, dummy_properties, | 376 system_quick_launch_shortcut_, dummy_properties, |
| 377 base::win::SHORTCUT_CREATE_ALWAYS)); | 377 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 378 ASSERT_TRUE(file_util::CreateDirectory( | 378 ASSERT_TRUE(file_util::CreateDirectory( |
| 379 system_start_menu_shortcut_.DirName())); | 379 system_start_menu_shortcut_.DirName())); |
| 380 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 380 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 381 system_start_menu_shortcut_, dummy_properties, | 381 system_start_menu_shortcut_, dummy_properties, |
| 382 base::win::SHORTCUT_CREATE_ALWAYS)); | 382 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 383 | 383 |
| 384 installer::CreateOrUpdateShortcuts( | 384 installer::CreateOrUpdateShortcuts( |
| 385 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 385 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 386 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); | 386 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); |
| 387 ASSERT_FALSE(file_util::PathExists(user_desktop_shortcut_)); | 387 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); |
| 388 ASSERT_FALSE(file_util::PathExists(user_quick_launch_shortcut_)); | 388 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
| 389 ASSERT_FALSE(file_util::PathExists(user_start_menu_shortcut_)); | 389 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); |
| 390 } | 390 } |
| 391 | 391 |
| 392 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelNoSystemShortcutsExist) { | 392 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelNoSystemShortcutsExist) { |
| 393 installer::CreateOrUpdateShortcuts( | 393 installer::CreateOrUpdateShortcuts( |
| 394 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 394 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 395 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); | 395 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); |
| 396 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 396 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 397 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 397 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 398 expected_properties_); | 398 expected_properties_); |
| 399 base::win::ValidateShortcut(user_start_menu_shortcut_, | 399 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 400 expected_start_menu_properties_); | 400 expected_start_menu_properties_); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelSomeSystemShortcutsExist) { | 403 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelSomeSystemShortcutsExist) { |
| 404 base::win::ShortcutProperties dummy_properties; | 404 base::win::ShortcutProperties dummy_properties; |
| 405 base::FilePath dummy_target; | 405 base::FilePath dummy_target; |
| 406 ASSERT_TRUE( | 406 ASSERT_TRUE( |
| 407 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 407 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
| 408 dummy_properties.set_target(dummy_target); | 408 dummy_properties.set_target(dummy_target); |
| 409 | 409 |
| 410 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 410 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
| 411 system_desktop_shortcut_, dummy_properties, | 411 system_desktop_shortcut_, dummy_properties, |
| 412 base::win::SHORTCUT_CREATE_ALWAYS)); | 412 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 413 | 413 |
| 414 installer::CreateOrUpdateShortcuts( | 414 installer::CreateOrUpdateShortcuts( |
| 415 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 415 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 416 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); | 416 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); |
| 417 ASSERT_FALSE(file_util::PathExists(user_desktop_shortcut_)); | 417 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); |
| 418 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 418 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 419 expected_properties_); | 419 expected_properties_); |
| 420 base::win::ValidateShortcut(user_start_menu_shortcut_, | 420 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| 421 expected_start_menu_properties_); | 421 expected_start_menu_properties_); |
| 422 } | 422 } |
| 423 | 423 |
| 424 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { | 424 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { |
| 425 string16 val(L"This has 'crazy' \"chars\" && < and > signs."); | 425 string16 val(L"This has 'crazy' \"chars\" && < and > signs."); |
| 426 static const wchar_t kExpectedEscapedVal[] = | 426 static const wchar_t kExpectedEscapedVal[] = |
| 427 L"This has 'crazy' \"chars\" && < and > signs."; | 427 L"This has 'crazy' \"chars\" && < and > signs."; |
| 428 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 428 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 429 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 429 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 430 } | 430 } |
| 431 | 431 |
| 432 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 432 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 433 string16 val(L"Google Chrome"); | 433 string16 val(L"Google Chrome"); |
| 434 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 434 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 435 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 435 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 436 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 436 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 437 } | 437 } |
| OLD | NEW |