| Index: chrome/installer/util/shell_util_unittest.cc
|
| diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc
|
| index a73452a643bf413f4d3e5864f677d5492431ad2c..3c665ba9ede92700c456c59f7ba50b2b859a24ac 100644
|
| --- a/chrome/installer/util/shell_util_unittest.cc
|
| +++ b/chrome/installer/util/shell_util_unittest.cc
|
| @@ -2,310 +2,91 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include <shlobj.h>
|
| -
|
| -#include <fstream>
|
| #include <vector>
|
|
|
| +#include "base/file_path.h"
|
| #include "base/file_util.h"
|
| -#include "base/path_service.h"
|
| #include "base/md5.h"
|
| #include "base/scoped_temp_dir.h"
|
| #include "base/string16.h"
|
| #include "base/string_util.h"
|
| -#include "base/win/windows_version.h"
|
| #include "chrome/installer/util/browser_distribution.h"
|
| -#include "chrome/installer/util/master_preferences.h"
|
| #include "chrome/installer/util/shell_util.h"
|
| -#include "chrome/installer/util/util_constants.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
|
|
| -class ShellUtilTestWithDirAndDist : public testing::Test {
|
| +class ShellUtilShortcutTest : public testing::Test {
|
| protected:
|
| virtual void SetUp() {
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| - dist_ = BrowserDistribution::GetDistribution();
|
| - ASSERT_TRUE(dist_ != NULL);
|
| + user_level_shortcut =
|
| + FilePath(temp_dir_.path().Append(L"user shortcut.lnk"));
|
| + system_level_shortcut =
|
| + FilePath(temp_dir_.path().Append(L"system shortcut.lnk"));
|
| }
|
|
|
| - BrowserDistribution* dist_;
|
| -
|
| ScopedTempDir temp_dir_;
|
| + FilePath user_level_shortcut;
|
| + FilePath system_level_shortcut;
|
| };
|
|
|
| -}
|
| -
|
| -// Test that we can open archives successfully.
|
| -TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) {
|
| - // Create an executable in test path by copying ourself to it.
|
| - wchar_t exe_full_path_str[MAX_PATH];
|
| - EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
|
| - FilePath exe_full_path(exe_full_path_str);
|
| -
|
| - FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
|
| - EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
|
| -
|
| - FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk");
|
| - const string16 description(L"dummy description");
|
| - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - shortcut_path.value(),
|
| - L"",
|
| - description,
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), shortcut_path.value(), description, 0));
|
| +} // namespace
|
|
|
| - // Now specify an icon index in master prefs and make sure it works.
|
| - FilePath prefs_path = temp_dir_.path().AppendASCII(
|
| - installer::kDefaultMasterPrefs);
|
| - std::ofstream file;
|
| - file.open(prefs_path.value().c_str());
|
| - ASSERT_TRUE(file.is_open());
|
| - file <<
|
| -"{"
|
| -" \"distribution\":{"
|
| -" \"chrome_shortcut_icon_index\" : 1"
|
| -" }"
|
| -"}";
|
| - file.close();
|
| - ASSERT_TRUE(file_util::Delete(shortcut_path, false));
|
| - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - shortcut_path.value(),
|
| - L"",
|
| - description,
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), shortcut_path.value(), description, 1));
|
| -
|
| - // Now change only description to update shortcut and make sure icon index
|
| - // doesn't change.
|
| - const string16 description2(L"dummy description 2");
|
| - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_,
|
| - exe_path.value(),
|
| - shortcut_path.value(),
|
| - L"",
|
| - description2,
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), shortcut_path.value(), description2, 1));
|
| +TEST_F(ShellUtilShortcutTest,
|
| + DetermineShortcutPathToCreateFromOptionsUserLevel) {
|
| + EXPECT_EQ(user_level_shortcut,
|
| + ShellUtil::DetermineShortcutPathToCreateFromOptions(
|
| + user_level_shortcut, system_level_shortcut,
|
| + ShellUtil::SHORTCUT_NO_OPTIONS));
|
| }
|
|
|
| -TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) {
|
| - // Run this test on Vista+ only if we are running elevated.
|
| - if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) {
|
| - LOG(ERROR) << "Must be admin to run this test on Vista+";
|
| - return;
|
| - }
|
| -
|
| - // Create an executable in test path by copying ourself to it.
|
| - wchar_t exe_full_path_str[MAX_PATH];
|
| - EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
|
| - FilePath exe_full_path(exe_full_path_str);
|
| -
|
| - FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
|
| - EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
|
| -
|
| - const string16 description(L"dummy description");
|
| -
|
| - FilePath user_desktop_path;
|
| - EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path));
|
| - FilePath system_desktop_path;
|
| - EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path));
|
| -
|
| - string16 shortcut_name;
|
| - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"",
|
| - &shortcut_name));
|
| -
|
| - string16 default_profile_shortcut_name;
|
| - const string16 default_profile_user_name = L"Minsk";
|
| - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false,
|
| - default_profile_user_name,
|
| - &default_profile_shortcut_name));
|
| -
|
| - string16 second_profile_shortcut_name;
|
| - const string16 second_profile_user_name = L"Pinsk";
|
| - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false,
|
| - second_profile_user_name,
|
| - &second_profile_shortcut_name));
|
| -
|
| - FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name);
|
| - FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name);
|
| - FilePath default_profile_shortcut_path = user_desktop_path.Append(
|
| - default_profile_shortcut_name);
|
| - FilePath second_profile_shortcut_path = user_desktop_path.Append(
|
| - second_profile_shortcut_name);
|
| -
|
| - // Test simple creation of a user-level shortcut.
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), user_shortcut_path.value(), description, 0));
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
|
| - dist_,
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| -
|
| - // Test simple creation of a system-level shortcut.
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), system_shortcut_path.value(), description,
|
| - 0));
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
|
| - dist_,
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| +TEST_F(ShellUtilShortcutTest,
|
| + DetermineShortcutPathToCreateFromOptionsUserLevelSystemLevelEmpty) {
|
| + EXPECT_EQ(user_level_shortcut,
|
| + ShellUtil::DetermineShortcutPathToCreateFromOptions(
|
| + user_level_shortcut, FilePath(),
|
| + ShellUtil::SHORTCUT_NO_OPTIONS));
|
| +}
|
|
|
| - // Test creation of a user-level shortcut when a system-level shortcut
|
| - // is already present (should fail).
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), system_shortcut_path.value(), description,
|
| - 0));
|
| - EXPECT_FALSE(file_util::PathExists(user_shortcut_path));
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
|
| - dist_,
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| +TEST_F(ShellUtilShortcutTest,
|
| + DetermineShortcutPathToCreateFromOptionsUserLevelSystemLevelPresent) {
|
| + file_util::WriteFile(system_level_shortcut, "", 0);
|
| + EXPECT_EQ(FilePath(),
|
| + ShellUtil::DetermineShortcutPathToCreateFromOptions(
|
| + user_level_shortcut, system_level_shortcut,
|
| + ShellUtil::SHORTCUT_NO_OPTIONS));
|
| +}
|
|
|
| - // Test creation of a system-level shortcut when a user-level shortcut
|
| - // is already present (should succeed).
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - L"",
|
| - L"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), user_shortcut_path.value(), description, 0));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), system_shortcut_path.value(), description,
|
| - 0));
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
|
| - dist_,
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
|
| - dist_,
|
| - ShellUtil::SYSTEM_LEVEL,
|
| - ShellUtil::SHORTCUT_NO_OPTIONS));
|
| +TEST_F(ShellUtilShortcutTest,
|
| + DetermineShortcutPathToCreateFromOptionsSystemLevel) {
|
| + EXPECT_EQ(system_level_shortcut,
|
| + ShellUtil::DetermineShortcutPathToCreateFromOptions(
|
| + user_level_shortcut, system_level_shortcut,
|
| + ShellUtil::SHORTCUT_SYSTEM_LEVEL));
|
| +}
|
|
|
| - // Test creation of two profile-specific shortcuts (these are always
|
| - // user-level).
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - default_profile_user_name,
|
| - L"--profile-directory=\"Default\"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), default_profile_shortcut_path.value(),
|
| - description, 0));
|
| - EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
|
| - dist_,
|
| - exe_path.value(),
|
| - description,
|
| - second_profile_user_name,
|
| - L"--profile-directory=\"Profile 1\"",
|
| - exe_path.value(),
|
| - dist_->GetIconIndex(),
|
| - ShellUtil::CURRENT_USER,
|
| - ShellUtil::SHORTCUT_CREATE_ALWAYS));
|
| - EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
|
| - ShellUtil::VerifyChromeShortcut(
|
| - exe_path.value(), second_profile_shortcut_path.value(),
|
| - description, 0));
|
| - std::vector<string16> profile_names;
|
| - profile_names.push_back(default_profile_shortcut_name);
|
| - profile_names.push_back(second_profile_shortcut_name);
|
| - EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
|
| - profile_names));
|
| +TEST_F(ShellUtilShortcutTest,
|
| + DetermineShortcutPathToCreateFromOptionsSystemLevelUserLevelPresent) {
|
| + file_util::WriteFile(user_level_shortcut, "", 0);
|
| + EXPECT_EQ(system_level_shortcut,
|
| + ShellUtil::DetermineShortcutPathToCreateFromOptions(
|
| + user_level_shortcut, system_level_shortcut,
|
| + ShellUtil::SHORTCUT_SYSTEM_LEVEL));
|
| }
|
|
|
| -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) {
|
| +TEST(ShellUtilTest, BuildAppModelIdBasic) {
|
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution();
|
| std::vector<string16> components;
|
| - const string16 base_app_id(dist_->GetBaseAppId());
|
| + const string16 base_app_id(dist->GetBaseAppId());
|
| components.push_back(base_app_id);
|
| ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components));
|
| }
|
|
|
| -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) {
|
| +TEST(ShellUtilTest, BuildAppModelIdManySmall) {
|
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution();
|
| std::vector<string16> components;
|
| - const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab"));
|
| + const string16 suffixed_app_id(dist->GetBaseAppId().append(L".gab"));
|
| components.push_back(suffixed_app_id);
|
| components.push_back(L"Default");
|
| components.push_back(L"Test");
|
| @@ -313,7 +94,7 @@ TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) {
|
| ShellUtil::BuildAppModelId(components));
|
| }
|
|
|
| -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) {
|
| +TEST(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) {
|
| std::vector<string16> components;
|
| const string16 long_appname(
|
| L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_"
|
| @@ -324,7 +105,7 @@ TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) {
|
| ShellUtil::BuildAppModelId(components));
|
| }
|
|
|
| -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) {
|
| +TEST(ShellUtilTest, BuildAppModelIdLongEverything) {
|
| std::vector<string16> components;
|
| const string16 long_appname(
|
| L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_"
|
|
|