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

Side by Side 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 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 // This file defines functions that integrate Chrome in Windows shell. These 5 // This file defines functions that integrate Chrome in Windows shell. These
6 // functions can be used by Chrome as well as Chrome installer. All of the 6 // functions can be used by Chrome as well as Chrome installer. All of the
7 // work is done by the local functions defined in anonymous namespace in 7 // work is done by the local functions defined in anonymous namespace in
8 // this class. 8 // this class.
9 9
10 #include "chrome/installer/util/shell_util.h" 10 #include "chrome/installer/util/shell_util.h"
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 // are any left...). 1672 // are any left...).
1673 if (free_bits >= 8 && next_byte_index < size) { 1673 if (free_bits >= 8 && next_byte_index < size) {
1674 free_bits -= 8; 1674 free_bits -= 8;
1675 bit_stream += bytes[next_byte_index++] << free_bits; 1675 bit_stream += bytes[next_byte_index++] << free_bits;
1676 } 1676 }
1677 } 1677 }
1678 1678
1679 DCHECK_EQ(ret.length(), encoded_length); 1679 DCHECK_EQ(ret.length(), encoded_length);
1680 return ret; 1680 return ret;
1681 } 1681 }
1682
1683 bool ShellUtil::VerifyChromeShortcut(const std::wstring& exe_path,
1684 const std::wstring& shortcut,
1685 const std::wstring& description,
1686 int icon_index) {
1687 base::win::ScopedComPtr<IShellLink> i_shell_link;
gab 2012/08/07 19:18:25 #include "base/win/scoped_comptr.h"
Halli 2012/08/07 20:52:16 This is included already.
gab 2012/08/08 16:24:26 No, scoped_ptr.h is not scoped_comptr.h, it might
Halli 2012/08/08 18:59:13 Line 34 (: On 2012/08/08 16:24:26, gab wrote:
1688 base::win::ScopedComPtr<IPersistFile> i_persist_file;
gab 2012/08/07 19:18:25 IPersistFile is said to come from ObjIdl.h by MSDN
gab 2012/08/08 17:01:24 Discussed with robert offline, although we like in
1689
1690 // Get pointer to the IShellLink interface
1691 bool failed = FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
gab 2012/08/07 19:18:25 The value of this variable is never used except in
Halli 2012/08/07 20:52:16 Done.
1692 CLSCTX_INPROC_SERVER));
1693 LOG_IF(ERROR, failed) << "Failed to get IShellLink";
1694 if (failed)
1695 return false;
1696
1697 // Query IShellLink for the IPersistFile interface
1698 failed = FAILED(i_persist_file.QueryFrom(i_shell_link));
1699 LOG_IF(ERROR, failed) << "Failed to get IPersistFile";
1700 if (failed)
1701 return false;
1702
1703 failed = FAILED(i_persist_file->Load(shortcut.c_str(), 0));
1704 LOG_IF(ERROR, failed) << "Failed to load shortcut " << shortcut.c_str();
1705 if (failed)
1706 return false;
1707
1708 wchar_t long_path[MAX_PATH] = {0};
1709 wchar_t short_path[MAX_PATH] = {0};
1710 failed = ((::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0) ||
1711 (::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0));
1712 LOG_IF(ERROR, failed) << "Failed to get long and short path names for "
1713 << exe_path;
1714 if (failed)
1715 return false;
1716
1717 wchar_t file_path[MAX_PATH] = {0};
1718 failed = ((FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL,
1719 SLGP_UNCPRIORITY))) ||
1720 ((FilePath(file_path) != FilePath(long_path)) &&
1721 (FilePath(file_path) != FilePath(short_path))));
1722 LOG_IF(ERROR, failed) << "File path " << file_path << " did not match with "
1723 << exe_path;
1724 if (failed)
1725 return false;
1726
1727 wchar_t desc[MAX_PATH] = {0};
1728 failed = ((FAILED(i_shell_link->GetDescription(desc, MAX_PATH))) ||
1729 (std::wstring(desc) != std::wstring(description)));
1730 LOG_IF(ERROR, failed) << "Description " << desc << " did not match with "
1731 << description;
1732 if (failed)
1733 return false;
1734
1735 wchar_t icon_path[MAX_PATH] = {0};
1736 int index = 0;
1737 failed = ((FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH,
1738 &index))) ||
1739 ((FilePath(file_path) != FilePath(long_path)) &&
1740 (FilePath(file_path) != FilePath(short_path))) ||
1741 (index != icon_index));
1742 LOG_IF(ERROR, failed);
1743 if (failed)
1744 return false;
1745
1746 return true;
1747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698