| 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" |
| 15 #include "base/win/scoped_propvariant.h" |
| 16 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 // propsys.lib is required for PropvariantTo*(). | |
| 20 #pragma comment(lib, "propsys.lib") | |
| 21 | |
| 22 namespace base { | 19 namespace base { |
| 23 namespace win { | 20 namespace win { |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // Validates |actual_path|'s LongPathName case-insensitively matches | 24 // Validates |actual_path|'s LongPathName case-insensitively matches |
| 28 // |expected_path|'s LongPathName. | 25 // |expected_path|'s LongPathName. |
| 29 void ValidatePathsAreEqual(const FilePath& expected_path, | 26 void ValidatePathsAreEqual(const FilePath& expected_path, |
| 30 const FilePath& actual_path) { | 27 const FilePath& actual_path) { |
| 31 wchar_t long_expected_path_chars[MAX_PATH] = {0}; | 28 wchar_t long_expected_path_chars[MAX_PATH] = {0}; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 110 |
| 114 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { | 111 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { |
| 115 EXPECT_TRUE(SUCCEEDED( | 112 EXPECT_TRUE(SUCCEEDED( |
| 116 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); | 113 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); |
| 117 ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); | 114 ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); |
| 118 EXPECT_EQ(properties.icon_index, read_icon_index); | 115 EXPECT_EQ(properties.icon_index, read_icon_index); |
| 119 } | 116 } |
| 120 | 117 |
| 121 if (GetVersion() >= VERSION_WIN7) { | 118 if (GetVersion() >= VERSION_WIN7) { |
| 122 ScopedComPtr<IPropertyStore> property_store; | 119 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))); | 120 EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link))); |
| 128 if (FAILED(hr)) | 121 if (FAILED(hr)) |
| 129 return; | 122 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 | 123 |
| 134 // Note, as mentioned on MSDN at | 124 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) { |
| 135 // http://msdn.microsoft.com/library/windows/desktop/bb776559.aspx, if | 125 ScopedPropVariant pv_app_id; |
| 136 // |pv_app_id| is a VT_EMPTY it is successfully converted to the empty | 126 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID, |
| 137 // string as desired. | 127 &pv_app_id)); |
| 138 wchar_t read_app_id[MAX_PATH] = {0}; | 128 switch (pv_app_id->vt) { |
| 139 PropVariantToString(pv_app_id, read_app_id, MAX_PATH); | 129 case VT_EMPTY: |
| 140 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) | 130 EXPECT_TRUE(properties.app_id.empty()); |
| 141 EXPECT_EQ(properties.app_id, read_app_id); | 131 break; |
| 132 case VT_LPWSTR: |
| 133 EXPECT_EQ(properties.app_id, pv_app_id->pwszVal); |
| 134 break; |
| 135 default: |
| 136 ADD_FAILURE() << "Unexpected variant type: " << pv_app_id->vt; |
| 137 } |
| 138 } |
| 142 | 139 |
| 143 // Note, as mentioned on MSDN at | 140 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) { |
| 144 // http://msdn.microsoft.com/library/windows/desktop/bb776531.aspx, if | 141 ScopedPropVariant pv_dual_mode; |
| 145 // |pv_dual_mode| is a VT_EMPTY it is successfully converted to false as | 142 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
| 146 // desired. | 143 &pv_dual_mode)); |
| 147 BOOL read_dual_mode; | 144 switch (pv_dual_mode->vt) { |
| 148 PropVariantToBoolean(pv_dual_mode, &read_dual_mode); | 145 case VT_EMPTY: |
| 149 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) | 146 EXPECT_FALSE(properties.dual_mode); |
| 150 EXPECT_EQ(properties.dual_mode, static_cast<bool>(read_dual_mode)); | 147 break; |
| 148 case VT_BOOL: |
| 149 EXPECT_EQ(properties.dual_mode, |
| 150 static_cast<bool>(pv_dual_mode->boolVal)); |
| 151 break; |
| 152 default: |
| 153 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode->vt; |
| 154 } |
| 155 } |
| 151 } | 156 } |
| 152 } | 157 } |
| 153 | 158 |
| 154 } // namespace win | 159 } // namespace win |
| 155 } // namespace base | 160 } // namespace base |
| OLD | NEW |