Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "base/test/test_shortcut_win.h" | 5 #include "base/test/test_shortcut_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | |
| 11 | 10 |
| 12 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 13 #include "base/string16.h" | 12 #include "base/string16.h" |
| 14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 15 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
| 16 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 // propsys.lib is required for PropvariantTo*(). | |
| 20 #pragma comment(lib, "propsys.lib") | |
| 21 | |
| 22 namespace base { | 18 namespace base { |
| 23 namespace win { | 19 namespace win { |
| 24 | 20 |
| 25 namespace { | 21 namespace { |
| 26 | 22 |
| 27 // Validates |actual_path|'s LongPathName case-insensitively matches | 23 // Validates |actual_path|'s LongPathName case-insensitively matches |
| 28 // |expected_path|'s LongPathName. | 24 // |expected_path|'s LongPathName. |
| 29 void ValidatePathsAreEqual(const FilePath& expected_path, | 25 void ValidatePathsAreEqual(const FilePath& expected_path, |
| 30 const FilePath& actual_path) { | 26 const FilePath& actual_path) { |
| 31 wchar_t long_expected_path_chars[MAX_PATH] = {0}; | 27 wchar_t long_expected_path_chars[MAX_PATH] = {0}; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 109 |
| 114 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { | 110 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { |
| 115 EXPECT_TRUE(SUCCEEDED( | 111 EXPECT_TRUE(SUCCEEDED( |
| 116 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); | 112 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); |
| 117 ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); | 113 ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); |
| 118 EXPECT_EQ(properties.icon_index, read_icon_index); | 114 EXPECT_EQ(properties.icon_index, read_icon_index); |
| 119 } | 115 } |
| 120 | 116 |
| 121 if (GetVersion() >= VERSION_WIN7) { | 117 if (GetVersion() >= VERSION_WIN7) { |
| 122 ScopedComPtr<IPropertyStore> property_store; | 118 ScopedComPtr<IPropertyStore> property_store; |
| 123 // Note that, as mentioned on MSDN at http://goo.gl/M8h9g, if a property is | |
| 124 // not set, GetValue will return S_OK and the PROPVARIANT will be set to | |
| 125 // VT_EMPTY. | |
| 126 PROPVARIANT pv_app_id, pv_dual_mode; | |
| 127 EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link))); | 119 EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link))); |
| 128 if (FAILED(hr)) | 120 if (FAILED(hr)) |
| 129 return; | 121 return; |
| 130 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id)); | |
| 131 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode, | |
| 132 &pv_dual_mode)); | |
| 133 | 122 |
| 134 // Note, as mentioned on MSDN at | 123 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) { |
| 135 // http://msdn.microsoft.com/library/windows/desktop/bb776559.aspx, if | 124 PROPVARIANT pv_app_id; |
|
grt (UTC plus 2)
2013/01/08 04:21:45
Init+Clear this as in the impl to avoid memory lea
gab
2013/01/08 22:33:23
Done.
| |
| 136 // |pv_app_id| is a VT_EMPTY it is successfully converted to the empty | 125 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID, |
| 137 // string as desired. | 126 &pv_app_id)); |
| 138 wchar_t read_app_id[MAX_PATH] = {0}; | 127 switch (pv_app_id.vt) { |
| 139 PropVariantToString(pv_app_id, read_app_id, MAX_PATH); | 128 case VT_EMPTY: |
| 140 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) | 129 EXPECT_TRUE(properties.app_id.empty()); |
| 141 EXPECT_EQ(properties.app_id, read_app_id); | 130 break; |
| 131 case VT_LPWSTR: | |
| 132 EXPECT_EQ(properties.app_id, pv_app_id.pwszVal); | |
| 133 break; | |
| 134 default: | |
| 135 ADD_FAILURE() << "Unexpected variant type: " << pv_app_id.vt; | |
| 136 } | |
| 137 } | |
| 142 | 138 |
| 143 // Note, as mentioned on MSDN at | 139 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) { |
| 144 // http://msdn.microsoft.com/library/windows/desktop/bb776531.aspx, if | 140 PROPVARIANT pv_dual_mode; |
| 145 // |pv_dual_mode| is a VT_EMPTY it is successfully converted to false as | 141 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
| 146 // desired. | 142 &pv_dual_mode)); |
| 147 BOOL read_dual_mode; | 143 switch (pv_dual_mode.vt) { |
| 148 PropVariantToBoolean(pv_dual_mode, &read_dual_mode); | 144 case VT_EMPTY: |
| 149 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) | 145 EXPECT_FALSE(properties.dual_mode); |
| 150 EXPECT_EQ(properties.dual_mode, static_cast<bool>(read_dual_mode)); | 146 break; |
| 147 case VT_BOOL: | |
| 148 EXPECT_EQ(properties.dual_mode, | |
| 149 static_cast<bool>(pv_dual_mode.boolVal)); | |
| 150 break; | |
| 151 default: | |
| 152 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode.vt; | |
| 153 } | |
| 154 } | |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 | 157 |
| 154 } // namespace win | 158 } // namespace win |
| 155 } // namespace base | 159 } // namespace base |
| OLD | NEW |