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

Unified Diff: chrome/installer/util/shell_util.cc

Issue 10826188: Sharing shell_util_unittest code to verify shortcuts (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/util/shell_util.cc
===================================================================
--- chrome/installer/util/shell_util.cc (revision 150342)
+++ chrome/installer/util/shell_util.cc (working copy)
@@ -1724,3 +1724,54 @@
DCHECK_EQ(ret.length(), encoded_length);
return ret;
}
+
+bool 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;
+
+ // Get pointer to the IShellLink interface
+ if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
+ CLSCTX_INPROC_SERVER)))
+ return false;
+
+ // Query IShellLink for the IPersistFile interface
+ if (FAILED(i_persist_file.QueryFrom(i_shell_link)))
+ return false;
+
+ if (FAILED(i_persist_file->Load(shortcut.c_str(), 0)))
+ return false;
+
+ wchar_t long_path[MAX_PATH] = {0};
+ wchar_t short_path[MAX_PATH] = {0};
+
+ if (::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0 ||
+ ::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0)
+ return false;
+
+ wchar_t file_path[MAX_PATH] = {0};
+
+ // File path did not match exe path
gab 2012/08/08 19:17:08 nit: remove this comment as well
+ if (FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL,
+ SLGP_UNCPRIORITY)) || FilePath(file_path) != FilePath(long_path) &&
gab 2012/08/08 19:17:08 align SLGP_UNCPRIORITY with file_path above and pu
+ FilePath(file_path) != FilePath(short_path))
+ return false;
+
+ wchar_t desc[MAX_PATH] = {0};
+
+ if (FAILED(i_shell_link->GetDescription(desc, MAX_PATH)) ||
+ string16(desc) != string16(description))
+ return false;
+
+ wchar_t icon_path[MAX_PATH] = {0};
+ int index = 0;
+
+ if (FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH, &index)) ||
+ FilePath(file_path) != FilePath(long_path) &&
+ FilePath(file_path) != FilePath(short_path) || index != icon_index)
+ return false;
+
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698