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

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,62 @@
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
+ // Failed to get IShellLink
gab 2012/08/08 16:24:27 Remove these "Failed *" comments (here and below),
Halli 2012/08/08 18:59:13 Done.
+ if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
+ CLSCTX_INPROC_SERVER)))
gab 2012/08/08 16:24:27 nit: indentation
Halli 2012/08/08 18:59:13 Done.
+ return false;
+
+ // Query IShellLink for the IPersistFile interface
+ // Failed to get IPersistFile
+ if (FAILED(i_persist_file.QueryFrom(i_shell_link)))
+ return false;
+
+ // Failed to load shortcut
+ 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};
+
+ // Failed to get long and short path names
+ if (((::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0) ||
gab 2012/08/08 16:24:27 In the conditionals all the way from here to the b
Halli 2012/08/08 18:59:13 Done.
+ (::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0)))
gab 2012/08/08 16:24:27 nit: indentation
Halli 2012/08/08 18:59:13 Done.
+ return false;
+
+ wchar_t file_path[MAX_PATH] = {0};
+
+ // File path did not match exe path
+ if (((FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL,
+ SLGP_UNCPRIORITY))) ||
gab 2012/08/08 16:24:27 nit: indentation
Halli 2012/08/08 18:59:13 Done.
+ ((FilePath(file_path) != FilePath(long_path)) &&
gab 2012/08/08 16:24:27 nit: indentation
Halli 2012/08/08 18:59:13 Done.
+ (FilePath(file_path) != FilePath(short_path)))))
+ return false;
+
+ wchar_t desc[MAX_PATH] = {0};
+
+ // Description did not match shortcut's description
+ 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,
gab 2012/08/08 16:24:27 Thinking more about it (and chatting with robert)
Halli 2012/08/08 18:59:13 How is this different from returning true or false
gab 2012/08/08 19:17:08 I don't want a different one for the getters (i.e.
Halli 2012/08/08 20:28:09 Hopefully this is what you meant (: On 2012/08/08
+ &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