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/win/shortcut.h" | 5 #include "base/win/shortcut.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <objbase.h> | 8 #include <objbase.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) { | 116 TEST_F(ShortcutTest, CreateShortcutWithOnlySomeProperties) { |
117 base::win::ShortcutProperties target_and_args_properties; | 117 base::win::ShortcutProperties target_and_args_properties; |
118 target_and_args_properties.set_target(link_properties_.target); | 118 target_and_args_properties.set_target(link_properties_.target); |
119 target_and_args_properties.set_arguments(link_properties_.arguments); | 119 target_and_args_properties.set_arguments(link_properties_.arguments); |
120 | 120 |
121 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 121 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
122 link_file_, target_and_args_properties, | 122 link_file_, target_and_args_properties, |
123 base::win::SHORTCUT_CREATE_ALWAYS)); | 123 base::win::SHORTCUT_CREATE_ALWAYS)); |
124 | 124 |
125 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 125 base::win::ValidateShortcut(link_file_, target_and_args_properties); |
126 base::win::VerifyShortcut(link_file_, target_and_args_properties)); | |
127 } | 126 } |
128 | 127 |
129 TEST_F(ShortcutTest, CreateShortcutVerifyProperties) { | 128 TEST_F(ShortcutTest, CreateShortcutVerifyProperties) { |
130 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 129 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
131 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); | 130 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); |
132 | 131 |
133 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 132 base::win::ValidateShortcut(link_file_, link_properties_); |
134 base::win::VerifyShortcut(link_file_, link_properties_)); | |
135 } | 133 } |
136 | 134 |
137 TEST_F(ShortcutTest, UpdateShortcutVerifyProperties) { | 135 TEST_F(ShortcutTest, UpdateShortcutVerifyProperties) { |
138 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 136 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
139 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); | 137 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); |
140 | 138 |
141 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 139 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
142 link_file_, link_properties_2_, base::win::SHORTCUT_UPDATE_EXISTING)); | 140 link_file_, link_properties_2_, base::win::SHORTCUT_UPDATE_EXISTING)); |
143 | 141 |
144 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 142 base::win::ValidateShortcut(link_file_, link_properties_2_); |
145 base::win::VerifyShortcut(link_file_, link_properties_2_)); | |
146 } | 143 } |
147 | 144 |
148 TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) { | 145 TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) { |
149 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 146 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
150 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); | 147 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); |
151 | 148 |
152 base::win::ShortcutProperties update_only_target_properties; | 149 base::win::ShortcutProperties update_only_target_properties; |
153 update_only_target_properties.set_target(link_properties_2_.target); | 150 update_only_target_properties.set_target(link_properties_2_.target); |
154 | 151 |
155 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 152 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
156 link_file_, update_only_target_properties, | 153 link_file_, update_only_target_properties, |
157 base::win::SHORTCUT_UPDATE_EXISTING)); | 154 base::win::SHORTCUT_UPDATE_EXISTING)); |
158 | 155 |
159 base::win::ShortcutProperties expected_properties = link_properties_; | 156 base::win::ShortcutProperties expected_properties = link_properties_; |
160 expected_properties.set_target(link_properties_2_.target); | 157 expected_properties.set_target(link_properties_2_.target); |
161 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 158 base::win::ValidateShortcut(link_file_, expected_properties); |
162 base::win::VerifyShortcut(link_file_, expected_properties)); | |
163 | 159 |
164 FilePath resolved_name; | 160 FilePath resolved_name; |
165 EXPECT_TRUE(base::win::ResolveShortcut(link_file_, &resolved_name, NULL)); | 161 EXPECT_TRUE(base::win::ResolveShortcut(link_file_, &resolved_name, NULL)); |
166 | 162 |
167 char read_contents[arraysize(kFileContents2)]; | 163 char read_contents[arraysize(kFileContents2)]; |
168 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); | 164 file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); |
169 EXPECT_STREQ(kFileContents2, read_contents); | 165 EXPECT_STREQ(kFileContents2, read_contents); |
170 } | 166 } |
171 | 167 |
172 TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) { | 168 TEST_F(ShortcutTest, UpdateShortcutMakeDualMode) { |
173 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 169 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
174 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); | 170 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); |
175 | 171 |
176 base::win::ShortcutProperties make_dual_mode_properties; | 172 base::win::ShortcutProperties make_dual_mode_properties; |
177 make_dual_mode_properties.set_dual_mode(true); | 173 make_dual_mode_properties.set_dual_mode(true); |
178 | 174 |
179 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 175 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
180 link_file_, make_dual_mode_properties, | 176 link_file_, make_dual_mode_properties, |
181 base::win::SHORTCUT_UPDATE_EXISTING)); | 177 base::win::SHORTCUT_UPDATE_EXISTING)); |
182 | 178 |
183 base::win::ShortcutProperties expected_properties = link_properties_; | 179 base::win::ShortcutProperties expected_properties = link_properties_; |
184 expected_properties.set_dual_mode(true); | 180 expected_properties.set_dual_mode(true); |
185 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 181 base::win::ValidateShortcut(link_file_, expected_properties); |
186 base::win::VerifyShortcut(link_file_, expected_properties)); | |
187 } | 182 } |
188 | 183 |
189 TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) { | 184 TEST_F(ShortcutTest, UpdateShortcutRemoveDualMode) { |
190 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 185 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
191 link_file_, link_properties_2_, base::win::SHORTCUT_CREATE_ALWAYS)); | 186 link_file_, link_properties_2_, base::win::SHORTCUT_CREATE_ALWAYS)); |
192 | 187 |
193 base::win::ShortcutProperties remove_dual_mode_properties; | 188 base::win::ShortcutProperties remove_dual_mode_properties; |
194 remove_dual_mode_properties.set_dual_mode(false); | 189 remove_dual_mode_properties.set_dual_mode(false); |
195 | 190 |
196 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 191 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
197 link_file_, remove_dual_mode_properties, | 192 link_file_, remove_dual_mode_properties, |
198 base::win::SHORTCUT_UPDATE_EXISTING)); | 193 base::win::SHORTCUT_UPDATE_EXISTING)); |
199 | 194 |
200 base::win::ShortcutProperties expected_properties = link_properties_2_; | 195 base::win::ShortcutProperties expected_properties = link_properties_2_; |
201 expected_properties.set_dual_mode(false); | 196 expected_properties.set_dual_mode(false); |
202 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 197 base::win::ValidateShortcut(link_file_, expected_properties); |
203 base::win::VerifyShortcut(link_file_, expected_properties)); | |
204 } | 198 } |
205 | 199 |
206 TEST_F(ShortcutTest, UpdateShortcutClearArguments) { | 200 TEST_F(ShortcutTest, UpdateShortcutClearArguments) { |
207 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 201 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
208 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); | 202 link_file_, link_properties_, base::win::SHORTCUT_CREATE_ALWAYS)); |
209 | 203 |
210 base::win::ShortcutProperties clear_arguments_properties; | 204 base::win::ShortcutProperties clear_arguments_properties; |
211 clear_arguments_properties.set_arguments(string16()); | 205 clear_arguments_properties.set_arguments(string16()); |
212 | 206 |
213 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 207 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
214 link_file_, clear_arguments_properties, | 208 link_file_, clear_arguments_properties, |
215 base::win::SHORTCUT_UPDATE_EXISTING)); | 209 base::win::SHORTCUT_UPDATE_EXISTING)); |
216 | 210 |
217 base::win::ShortcutProperties expected_properties = link_properties_; | 211 base::win::ShortcutProperties expected_properties = link_properties_; |
218 expected_properties.set_arguments(string16()); | 212 expected_properties.set_arguments(string16()); |
219 ASSERT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 213 base::win::ValidateShortcut(link_file_, expected_properties); |
220 base::win::VerifyShortcut(link_file_, expected_properties)); | |
221 } | 214 } |
OLD | NEW |