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

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: 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
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 installer::CreateOrUpdateShortcuts( 453 installer::CreateOrUpdateShortcuts(
453 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 454 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
454 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL); 455 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL);
455 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_)); 456 ASSERT_FALSE(base::PathExists(user_desktop_shortcut_));
456 base::win::ValidateShortcut(user_quick_launch_shortcut_, 457 base::win::ValidateShortcut(user_quick_launch_shortcut_,
457 expected_properties_); 458 expected_properties_);
458 base::win::ValidateShortcut(user_start_menu_shortcut_, 459 base::win::ValidateShortcut(user_start_menu_shortcut_,
459 expected_start_menu_properties_); 460 expected_start_menu_properties_);
460 } 461 }
461 462
463 TEST_F(InstallShortcutTest, UpdatePerUserShortcuts) {
464 base::FilePath shortcut_path_template;
465 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
466 dist_, ShellUtil::CURRENT_USER,
467 &shortcut_path_template));
468 shortcut_path_template =
469 shortcut_path_template.Append(FILE_PATH_LITERAL("shortcut.lnk"));
gab 2016/03/16 21:57:31 You can use the fixture's |user_desktop_shortcut_|
fdoray 2016/03/17 00:50:34 Done.
470
471 static const struct TestData {
gab 2016/03/16 21:57:30 s/TestData/TestCase/
fdoray 2016/03/17 00:50:34 Done.
472 const base::FilePath::CharType* relative_target_path;
473 bool should_update;
474 } kTargetPathsToUpdate[] = {
475 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
476 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
477 false},
478 {FILE_PATH_LITERAL(
479 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"),
480 false},
481 {FILE_PATH_LITERAL(
482 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"),
483 false},
484 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
485 "SxS\\Application\\something_else.exe"),
486 false},
487 {FILE_PATH_LITERAL(
488 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"),
489 true},
490 {FILE_PATH_LITERAL(
491 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
492 true},
493 {FILE_PATH_LITERAL(
494 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
495 true},
496 {FILE_PATH_LITERAL(
497 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"),
498 false},
499 {FILE_PATH_LITERAL("something_else.exe"), false},
500 };
501
502 // Create shortcuts.
503 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
504 const base::FilePath target_path =
505 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path);
506 ASSERT_TRUE(base::CreateDirectory(target_path.DirName()));
507 base::File file(target_path, base::File::FLAG_CREATE);
508 ASSERT_TRUE(file.IsValid());
509
510 base::win::ShortcutProperties properties;
511 properties.set_target(target_path);
512 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
513 shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)),
514 properties, base::win::SHORTCUT_CREATE_ALWAYS));
515 }
516
517 // Update shortcuts.
518 const base::FilePath new_target_path =
519 temp_dir_.path().Append(FILE_PATH_LITERAL(
520 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"));
521 installer::UpdatePerUserShortcutsInLocation(
522 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
523 new_target_path.DirName().DirName(), new_target_path.BaseName(),
524 new_target_path);
525
526 // Check if shortcuts were updated correctly.
gab 2016/03/16 21:57:31 s/Check if/Verify that/
fdoray 2016/03/17 00:50:34 Done.
527 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
528 base::FilePath target_path;
529 ASSERT_TRUE(base::win::ResolveShortcut(
530 shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)),
531 &target_path, nullptr));
532
533 if (kTargetPathsToUpdate[i].should_update) {
534 EXPECT_EQ(new_target_path, target_path);
535 } else {
536 EXPECT_EQ(
537 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path),
538 target_path);
539 }
540 }
541 }
542
543 TEST_F(InstallShortcutTest, UpdatePerUserShortcutsCanary) {
544 base::FilePath shortcut_path_template;
545 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
546 dist_, ShellUtil::CURRENT_USER,
547 &shortcut_path_template));
548 shortcut_path_template =
549 shortcut_path_template.Append(FILE_PATH_LITERAL("shortcut.lnk"));
550
551 static const struct TestData {
552 const base::FilePath::CharType* relative_target_path;
553 bool should_update;
554 } kTargetPathsToUpdate[] = {
555 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
556 "SxS\\Temp\\scoped_dir\\new_chrome.exe"),
557 true},
558 {FILE_PATH_LITERAL(
559 "AppData\\Local\\Google\\Chrome SxS\\Temp\\scoped_dir\\chrome.exe"),
560 true},
561 {FILE_PATH_LITERAL(
562 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"),
563 true},
564 {FILE_PATH_LITERAL("AppData\\Local\\Google\\Chrome "
565 "SxS\\Application\\something_else.exe"),
566 false},
567 {FILE_PATH_LITERAL(
568 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\new_chrome.exe"),
569 false},
570 {FILE_PATH_LITERAL(
571 "AppData\\Local\\Google\\Chrome\\Temp\\scoped_dir\\chrome.exe"),
572 false},
573 {FILE_PATH_LITERAL(
574 "AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"),
575 false},
576 {FILE_PATH_LITERAL(
577 "AppData\\Local\\Google\\Chrome\\Application\\something_else.exe"),
578 false},
579 {FILE_PATH_LITERAL("something_else.exe"), false},
580 };
581
582 // Create shortcuts.
583 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
584 const base::FilePath target_path =
585 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path);
586 ASSERT_TRUE(base::CreateDirectory(target_path.DirName()));
587 base::File file(target_path, base::File::FLAG_CREATE);
588 ASSERT_TRUE(file.IsValid());
589
590 base::win::ShortcutProperties properties;
591 properties.set_target(target_path);
592 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
593 shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)),
594 properties, base::win::SHORTCUT_CREATE_ALWAYS));
595 }
596
597 // Update shortcuts.
598 const base::FilePath new_target_path =
599 temp_dir_.path().Append(FILE_PATH_LITERAL(
600 "AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"));
601 installer::UpdatePerUserShortcutsInLocation(
602 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_,
603 new_target_path.DirName().DirName(), new_target_path.BaseName(),
604 new_target_path);
605
606 // Check if shortcuts were updated correctly.
607 for (size_t i = 0; i < arraysize(kTargetPathsToUpdate); ++i) {
608 base::FilePath target_path;
609 ASSERT_TRUE(base::win::ResolveShortcut(
610 shortcut_path_template.InsertBeforeExtension(base::SizeTToString16(i)),
611 &target_path, nullptr));
612
613 if (kTargetPathsToUpdate[i].should_update) {
614 EXPECT_EQ(new_target_path, target_path);
615 } else {
616 EXPECT_EQ(
617 temp_dir_.path().Append(kTargetPathsToUpdate[i].relative_target_path),
618 target_path);
619 }
620 }
621 }
622
462 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) { 623 TEST(EscapeXmlAttributeValueTest, EscapeCrazyValue) {
463 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs."); 624 base::string16 val(L"This has 'crazy' \"chars\" && < and > signs.");
464 static const wchar_t kExpectedEscapedVal[] = 625 static const wchar_t kExpectedEscapedVal[] =
465 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs."; 626 L"This has &apos;crazy&apos; \"chars\" &amp;&amp; &lt; and > signs.";
466 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 627 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
467 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 628 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
468 } 629 }
469 630
470 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 631 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
471 base::string16 val(L"Google Chrome"); 632 base::string16 val(L"Google Chrome");
472 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 633 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
473 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 634 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
474 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 635 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
475 } 636 }
OLDNEW
« chrome/installer/setup/install.h ('K') | « chrome/installer/setup/install.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698