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

Side by Side Diff: base/test/test_shortcut_win.cc

Issue 2909943003: Removing useless Win7 checks + standardize its use (Closed)
Patch Set: Fix reversed conditionnal Created 3 years, 6 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 #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 <objbase.h> 8 #include <objbase.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <propkey.h> 10 #include <propkey.h>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_propvariant.h" 16 #include "base/win/scoped_propvariant.h"
17 #include "base/win/windows_version.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace base { 19 namespace base {
21 namespace win { 20 namespace win {
22 21
23 void ValidatePathsAreEqual(const base::FilePath& expected_path, 22 void ValidatePathsAreEqual(const base::FilePath& expected_path,
24 const base::FilePath& actual_path) { 23 const base::FilePath& actual_path) {
25 wchar_t long_expected_path_chars[MAX_PATH] = {0}; 24 wchar_t long_expected_path_chars[MAX_PATH] = {0};
26 wchar_t long_actual_path_chars[MAX_PATH] = {0}; 25 wchar_t long_actual_path_chars[MAX_PATH] = {0};
27 26
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 EXPECT_EQ(properties.description, read_description); 105 EXPECT_EQ(properties.description, read_description);
107 } 106 }
108 107
109 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { 108 if (properties.options & ShortcutProperties::PROPERTIES_ICON) {
110 EXPECT_TRUE(SUCCEEDED( 109 EXPECT_TRUE(SUCCEEDED(
111 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); 110 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index)));
112 ValidatePathsAreEqual(properties.icon, base::FilePath(read_icon)); 111 ValidatePathsAreEqual(properties.icon, base::FilePath(read_icon));
113 EXPECT_EQ(properties.icon_index, read_icon_index); 112 EXPECT_EQ(properties.icon_index, read_icon_index);
114 } 113 }
115 114
116 if (GetVersion() >= VERSION_WIN7) { 115 ScopedComPtr<IPropertyStore> property_store;
117 ScopedComPtr<IPropertyStore> property_store; 116 EXPECT_TRUE(
118 EXPECT_TRUE( 117 SUCCEEDED(hr = i_shell_link.CopyTo(property_store.GetAddressOf())));
119 SUCCEEDED(hr = i_shell_link.CopyTo(property_store.GetAddressOf()))); 118 if (FAILED(hr))
120 if (FAILED(hr)) 119 return;
121 return;
122 120
123 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) { 121 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) {
124 ScopedPropVariant pv_app_id; 122 ScopedPropVariant pv_app_id;
125 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID, 123 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID,
126 pv_app_id.Receive())); 124 pv_app_id.Receive()));
127 switch (pv_app_id.get().vt) { 125 switch (pv_app_id.get().vt) {
128 case VT_EMPTY: 126 case VT_EMPTY:
129 EXPECT_TRUE(properties.app_id.empty()); 127 EXPECT_TRUE(properties.app_id.empty());
130 break; 128 break;
131 case VT_LPWSTR: 129 case VT_LPWSTR:
132 EXPECT_EQ(properties.app_id, pv_app_id.get().pwszVal); 130 EXPECT_EQ(properties.app_id, pv_app_id.get().pwszVal);
133 break; 131 break;
134 default: 132 default:
135 ADD_FAILURE() << "Unexpected variant type: " << pv_app_id.get().vt; 133 ADD_FAILURE() << "Unexpected variant type: " << pv_app_id.get().vt;
136 }
137 } 134 }
135 }
138 136
139 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) { 137 if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) {
140 ScopedPropVariant pv_dual_mode; 138 ScopedPropVariant pv_dual_mode;
141 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode, 139 EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode,
142 pv_dual_mode.Receive())); 140 pv_dual_mode.Receive()));
143 switch (pv_dual_mode.get().vt) { 141 switch (pv_dual_mode.get().vt) {
144 case VT_EMPTY: 142 case VT_EMPTY:
145 EXPECT_FALSE(properties.dual_mode); 143 EXPECT_FALSE(properties.dual_mode);
146 break; 144 break;
147 case VT_BOOL: 145 case VT_BOOL:
148 EXPECT_EQ(properties.dual_mode, 146 EXPECT_EQ(properties.dual_mode,
149 static_cast<bool>(pv_dual_mode.get().boolVal)); 147 static_cast<bool>(pv_dual_mode.get().boolVal));
150 break; 148 break;
151 default: 149 default:
152 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode.get().vt; 150 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode.get().vt;
153 }
154 } 151 }
155 } 152 }
156 } 153 }
157 154
158 } // namespace win 155 } // namespace win
159 } // namespace base 156 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698