Sharing shell_util_unittest code to verify shortcuts for creation of profile...

Sharing shell_util_unittest code to verify shortcuts for creation of profile shortcuts for Windows. profile_manager_unittest needs to be able to verify shortcuts created as well. 

BUG=NONE
TEST=installer_util_unittests --gtest_filter=ShellUtilTest*

Review URL: https://chromiumcodereview.appspot.com/10826188

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151091 0039d316-1c4b-4281-b951-d872f2087c98
parent 9160e2aa
......@@ -1657,6 +1657,45 @@ bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist,
ConvertShellUtilShortcutOptionsToFileUtil(options));
}
ShellUtil::VerifyShortcutStatus ShellUtil::VerifyChromeShortcut(
const string16& exe_path, const string16& shortcut,
const string16& description, int icon_index) {
base::win::ScopedComPtr<IShellLink> i_shell_link;
base::win::ScopedComPtr<IPersistFile> i_persist_file;
wchar_t long_path[MAX_PATH] = {0};
wchar_t short_path[MAX_PATH] = {0};
wchar_t file_path[MAX_PATH] = {0};
wchar_t icon_path[MAX_PATH] = {0};
wchar_t desc[MAX_PATH] = {0};
int index = 0;
// Get the shortcut's properties.
if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER)) ||
FAILED(i_persist_file.QueryFrom(i_shell_link)) ||
FAILED(i_persist_file->Load(shortcut.c_str(), 0)) ||
::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0 ||
::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0 ||
FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL,
SLGP_UNCPRIORITY)) ||
FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH, &index)) ||
FAILED(i_shell_link->GetDescription(desc, MAX_PATH)) ||
FAILED(i_shell_link->GetDescription(desc, MAX_PATH)))
return VERIFY_SHORTCUT_FAILURE_UNEXPECTED;
FilePath path(file_path);
if (path != FilePath(long_path) && path != FilePath(short_path))
return VERIFY_SHORTCUT_FAILURE_PATH;
if (string16(desc) != string16(description))
return VERIFY_SHORTCUT_FAILURE_DESCRIPTION;
if (index != icon_index)
return VERIFY_SHORTCUT_FAILURE_ICON_INDEX;
return VERIFY_SHORTCUT_SUCCESS;
}
bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) {
// Use a thread-safe cache for the user's suffix.
static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance =
......
......@@ -35,6 +35,14 @@ class ShellUtil {
SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level
};
enum VerifyShortcutStatus {
VERIFY_SHORTCUT_SUCCESS = 0,
VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
VERIFY_SHORTCUT_FAILURE_PATH,
VERIFY_SHORTCUT_FAILURE_DESCRIPTION,
VERIFY_SHORTCUT_FAILURE_ICON_INDEX,
};
// Relative path of the URL Protocol registry entry (prefixed with '\').
static const wchar_t* kRegURLProtocol;
......@@ -412,6 +420,16 @@ class ShellUtil {
int icon_index,
uint32 options);
// Verify that a shortcut exists with the expected information.
// |exe_path| The shortcut's exe.
// |shortcut| The path to the shortcut.
// |description| The shortcut's description.
// |icon_index| The icon's index in the exe.
static VerifyShortcutStatus VerifyChromeShortcut(const string16& exe_path,
const string16& shortcut,
const string16& description,
int icon_index);
// Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid
// preceded by a dot.
// This is guaranteed to be unique on the machine and 27 characters long
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment