Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: chrome/installer/setup/install_unittest.cc

Issue 1803383002: Don't update Canary shortcuts from Dev/Beta/Stable installer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Normalize file paths. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/setup/install.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <stddef.h> 6 #include <stddef.h>
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/test/scoped_path_override.h" 19 #include "base/test/scoped_path_override.h"
19 #include "base/test/test_shortcut_win.h" 20 #include "base/test/test_shortcut_win.h"
20 #include "base/version.h" 21 #include "base/version.h"
21 #include "base/win/shortcut.h" 22 #include "base/win/shortcut.h"
22 #include "chrome/installer/setup/install.h" 23 #include "chrome/installer/setup/install.h"
23 #include "chrome/installer/setup/install_worker.h" 24 #include "chrome/installer/setup/install_worker.h"
24 #include "chrome/installer/setup/setup_constants.h" 25 #include "chrome/installer/setup/setup_constants.h"
25 #include "chrome/installer/util/browser_distribution.h" 26 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/install_util.h" 27 #include "chrome/installer/util/install_util.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 198
198 base::FilePath user_desktop_shortcut_; 199 base::FilePath user_desktop_shortcut_;
199 base::FilePath user_quick_launch_shortcut_; 200 base::FilePath user_quick_launch_shortcut_;
200 base::FilePath user_start_menu_shortcut_; 201 base::FilePath user_start_menu_shortcut_;
201 base::FilePath user_start_menu_subdir_shortcut_; 202 base::FilePath user_start_menu_subdir_shortcut_;
202 base::FilePath system_desktop_shortcut_; 203 base::FilePath system_desktop_shortcut_;
203 base::FilePath system_start_menu_shortcut_; 204 base::FilePath system_start_menu_shortcut_;
204 base::FilePath system_start_menu_subdir_shortcut_; 205 base::FilePath system_start_menu_subdir_shortcut_;
205 }; 206 };
206 207
208 base::FilePath GetNormalizedFilePath(const base::FilePath& path) {
209 base::FilePath normalized_path;
210 base::NormalizeFilePath(path, &normalized_path);
211 return normalized_path;
212 }
213
207 } // namespace 214 } // namespace
208 215
209 // Test that VisualElementsManifest.xml is not created when VisualElements are 216 // Test that VisualElementsManifest.xml is not created when VisualElements are
210 // not present. 217 // not present.
211 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { 218 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) {
212 ASSERT_TRUE( 219 ASSERT_TRUE(
213 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); 220 installer::CreateVisualElementsManifest(test_dir_.path(), version_));
214 ASSERT_FALSE(base::PathExists(manifest_path_)); 221 ASSERT_FALSE(base::PathExists(manifest_path_));
215 } 222 }
216 223
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 installer::CreateOrUpdateShortcuts( 459 installer::CreateOrUpdateShortcuts(
453 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 460 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
454 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 461 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
455 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); 462 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_));
456 base::win::ValidateShortcut(user_quick_launch_shortcut_, 463 base::win::ValidateShortcut(user_quick_launch_shortcut_,
457 expected_properties_); 464 expected_properties_);
458 base::win::ValidateShortcut(user_start_menu_shortcut_, 465 base::win::ValidateShortcut(user_start_menu_shortcut_,
459 expected_start_menu_properties_); 466 expected_start_menu_properties_);
460 } 467 }
461 468
469 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) {
470 static const struct TestCase {
471 const base::FilePath::CharType* relative_target_path;
472 bool should_update;
473 } kTargetPathsToUpdate[] = {
474 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
475 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
476 false},
477 {FILE_PATH_LITERAL(
478 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"),
479 false},
480 {FILE_PATH_LITERAL(
481 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"),
482 false},
483 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
484 "SxS\\Application\\something_else.exe"),
485 false},
486 {FILE_PATH_LITERAL(
487 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"),
488 true},
489 {FILE_PATH_LITERAL(
490 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
491 true},
492 {FILE_PATH_LITERAL(
493 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
494 true},
495 {FILE_PATH_LITERAL(
496 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"),
497 false},
498 {FILE_PATH_LITERAL("something_else.exe"), false},
499 };
500
501 // Create shortcuts.
502 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
503 const base::FilePath target_path =
504 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path);
505 ASSERT_TRUE(base::CreateDirectory(target_path.DirName()));
506 base::File file(target_path, base::File::FLAG_CREATE);
507 ASSERT_TRUE(file.IsValid());
508
509 base::win::ShortcutProperties properties;
510 properties.set_target(target_path);
511 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
512 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)),
513 properties, base::win::SHORTCUT_CREATE_ALWAYS));
514 }
515
516 // Update shortcuts.
517 const base::FilePath new_target_path =
518 temp_dir_.path().Append(FILE_PATH_LITERAL(
519 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"));
520 installer::UpdatePerUserShortcutsInLocation(
521 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
522 new_target_path.DirName().DirName(), new_target_path.BaseName(),
523 new_target_path);
524
525 // Verify that shortcuts were updated correctly.
526 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
527 base::FilePath target_path;
528 ASSERT_TRUE(base::win::ResolveShortcut(
529 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)),
530 &target_path, nullptr));
531
532 if (kTargetPathsToUpdate[i].should_update) {
533 EXPECT_EQ(GetNormalizedFilePath(new_target_path),
534 GetNormalizedFilePath(target_path));
535 } else {
536 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append(
537 kTargetPathsToUpdate[i].relative_target_path)),
538 GetNormalizedFilePath(target_path));
539 }
540 }
541 }
542
543 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) {
544 static const struct TestCase {
545 const base::FilePath::CharType* relative_target_path;
546 bool should_update;
547 } kTargetPathsToUpdate[] = {
548 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
549 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
550 true},
551 {FILE_PATH_LITERAL(
552 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"),
553 true},
554 {FILE_PATH_LITERAL(
555 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"),
556 true},
557 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
558 "SxS\\Application\\something_else.exe"),
559 false},
560 {FILE_PATH_LITERAL(
561 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"),
562 false},
563 {FILE_PATH_LITERAL(
564 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
565 false},
566 {FILE_PATH_LITERAL(
567 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
568 false},
569 {FILE_PATH_LITERAL(
570 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"),
571 false},
572 {FILE_PATH_LITERAL("something_else.exe"), false},
573 };
574
575 // Create shortcuts.
576 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
577 const base::FilePath target_path =
578 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path);
579 ASSERT_TRUE(base::CreateDirectory(target_path.DirName()));
580 base::File file(target_path, base::File::FLAG_CREATE);
581 ASSERT_TRUE(file.IsValid());
582
583 base::win::ShortcutProperties properties;
584 properties.set_target(target_path);
585 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
586 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)),
587 properties, base::win::SHORTCUT_CREATE_ALWAYS));
588 }
589
590 // Update shortcuts.
591 const base::FilePath new_target_path =
592 temp_dir_.path().Append(FILE_PATH_LITERAL(
593 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"));
594 installer::UpdatePerUserShortcutsInLocation(
595 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
596 new_target_path.DirName().DirName(), new_target_path.BaseName(),
597 new_target_path);
598
599 // Verify that shortcuts were updated correctly.
600 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
601 base::FilePath target_path;
602 ASSERT_TRUE(base::win::ResolveShortcut(
603 user_desktop_shortcut_.InsertBeforeExtension(base::SizeTToString16(i)),
604 &target_path, nullptr));
605
606 if (kTargetPathsToUpdate[i].should_update) {
607 EXPECT_EQ(GetNormalizedFilePath(new_target_path),
608 GetNormalizedFilePath(target_path));
609 } else {
610 EXPECT_EQ(GetNormalizedFilePath(temp_dir_.path().Append(
611 kTargetPathsToUpdate[i].relative_target_path)),
612 GetNormalizedFilePath(target_path));
613 }
614 }
615 }
616
462 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { 617 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) {
463 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); 618 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs.");
464 static const wchar_t kExpectedEscapedVal[] = 619 static const wchar_t kExpectedEscapedVal[] =
465 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs."; 620 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs.";
466 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 621 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
467 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 622 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
468 } 623 }
469 624
470 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 625 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
471 base::string16 val(L"Google Chrome"); 626 base::string16 val(L"Google Chrome");
472 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 627 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
473 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 628 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
474 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 629 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
475 } 630 }
OLDNEW
« no previous file with comments | « chrome/installer/setup/install.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698