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 <fstream> | 5 #include <fstream> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 BrowserDistribution* dist_; | 40 BrowserDistribution* dist_; |
41 | 41 |
42 ScopedTempDir temp_dir_; | 42 ScopedTempDir temp_dir_; |
43 | 43 |
44 ScopedTempDir fake_user_desktop_; | 44 ScopedTempDir fake_user_desktop_; |
45 ScopedTempDir fake_common_desktop_; | 45 ScopedTempDir fake_common_desktop_; |
46 }; | 46 }; |
47 | 47 |
48 // Returns the status of a call to base::win::VerifyShorcut for the properties | 48 // Calls base::win::ValidateShortcut for the properties passed in. |
49 // passed in. | |
50 // TODO(gab): This is only temporary while waiting for my upcoming CL that will | 49 // TODO(gab): This is only temporary while waiting for my upcoming CL that will |
51 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't | 50 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't |
52 // want to adapt every test here for this half-changed state as they will change | 51 // want to adapt every test here for this half-changed state as they will change |
53 // again very soon). | 52 // again very soon). |
54 base::win::VerifyShortcutStatus VerifyChromeShortcut( | 53 void ValidateChromeShortcut(const FilePath& exe_path, |
55 const FilePath& exe_path, | 54 const FilePath& shortcut_path, |
56 const FilePath& shortcut_path, | 55 const string16& description, |
57 const string16& description, | 56 int icon_index) { |
58 int icon_index) { | |
59 base::win::ShortcutProperties expected_properties; | 57 base::win::ShortcutProperties expected_properties; |
60 expected_properties.set_target(exe_path); | 58 expected_properties.set_target(exe_path); |
61 expected_properties.set_description(description); | 59 expected_properties.set_description(description); |
62 expected_properties.set_icon(exe_path, icon_index); | 60 expected_properties.set_icon(exe_path, icon_index); |
63 return base::win::VerifyShortcut(shortcut_path, expected_properties); | 61 base::win::ValidateShortcut(shortcut_path, expected_properties); |
64 } | 62 } |
65 | 63 |
66 } | 64 } |
67 | 65 |
68 // Test that we can open archives successfully. | 66 // Test that we can open archives successfully. |
69 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { | 67 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { |
70 // Create an executable in test path by copying ourself to it. | 68 // Create an executable in test path by copying ourself to it. |
71 wchar_t exe_full_path_str[MAX_PATH]; | 69 wchar_t exe_full_path_str[MAX_PATH]; |
72 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 70 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
73 FilePath exe_full_path(exe_full_path_str); | 71 FilePath exe_full_path(exe_full_path_str); |
74 | 72 |
75 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 73 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
76 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 74 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
77 | 75 |
78 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 76 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
79 const string16 description(L"dummy description"); | 77 const string16 description(L"dummy description"); |
80 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 78 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
81 dist_, | 79 dist_, |
82 exe_path.value(), | 80 exe_path.value(), |
83 shortcut_path.value(), | 81 shortcut_path.value(), |
84 string16(), | 82 string16(), |
85 description, | 83 description, |
86 exe_path.value(), | 84 exe_path.value(), |
87 dist_->GetIconIndex(), | 85 dist_->GetIconIndex(), |
88 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 86 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
89 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 87 ValidateChromeShortcut(exe_path, shortcut_path, description, 0); |
90 VerifyChromeShortcut(exe_path, shortcut_path, description, 0)); | |
91 | 88 |
92 // Now specify an icon index in master prefs and make sure it works. | 89 // Now specify an icon index in master prefs and make sure it works. |
93 FilePath prefs_path = temp_dir_.path().AppendASCII( | 90 FilePath prefs_path = temp_dir_.path().AppendASCII( |
94 installer::kDefaultMasterPrefs); | 91 installer::kDefaultMasterPrefs); |
95 std::ofstream file; | 92 std::ofstream file; |
96 file.open(prefs_path.value().c_str()); | 93 file.open(prefs_path.value().c_str()); |
97 ASSERT_TRUE(file.is_open()); | 94 ASSERT_TRUE(file.is_open()); |
98 file << | 95 file << |
99 "{" | 96 "{" |
100 " \"distribution\":{" | 97 " \"distribution\":{" |
101 " \"chrome_shortcut_icon_index\" : 1" | 98 " \"chrome_shortcut_icon_index\" : 1" |
102 " }" | 99 " }" |
103 "}"; | 100 "}"; |
104 file.close(); | 101 file.close(); |
105 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); | 102 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); |
106 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 103 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
107 dist_, | 104 dist_, |
108 exe_path.value(), | 105 exe_path.value(), |
109 shortcut_path.value(), | 106 shortcut_path.value(), |
110 string16(), | 107 string16(), |
111 description, | 108 description, |
112 exe_path.value(), | 109 exe_path.value(), |
113 dist_->GetIconIndex(), | 110 dist_->GetIconIndex(), |
114 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 111 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
115 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 112 ValidateChromeShortcut(exe_path, shortcut_path, description, 1); |
116 VerifyChromeShortcut(exe_path, shortcut_path, description, 1)); | |
117 | 113 |
118 // Now change only description to update shortcut and make sure icon index | 114 // Now change only description to update shortcut and make sure icon index |
119 // doesn't change. | 115 // doesn't change. |
120 const string16 description2(L"dummy description 2"); | 116 const string16 description2(L"dummy description 2"); |
121 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, | 117 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, |
122 exe_path.value(), | 118 exe_path.value(), |
123 shortcut_path.value(), | 119 shortcut_path.value(), |
124 string16(), | 120 string16(), |
125 description2, | 121 description2, |
126 exe_path.value(), | 122 exe_path.value(), |
127 dist_->GetIconIndex(), | 123 dist_->GetIconIndex(), |
128 ShellUtil::SHORTCUT_NO_OPTIONS)); | 124 ShellUtil::SHORTCUT_NO_OPTIONS)); |
129 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 125 ValidateChromeShortcut(exe_path, shortcut_path, description2, 1); |
130 VerifyChromeShortcut(exe_path, shortcut_path, description2, 1)); | |
131 } | 126 } |
132 | 127 |
133 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { | 128 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { |
134 // Create an executable in test path by copying ourself to it. | 129 // Create an executable in test path by copying ourself to it. |
135 wchar_t exe_full_path_str[MAX_PATH]; | 130 wchar_t exe_full_path_str[MAX_PATH]; |
136 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 131 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
137 FilePath exe_full_path(exe_full_path_str); | 132 FilePath exe_full_path(exe_full_path_str); |
138 | 133 |
139 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 134 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
140 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 135 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 168 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
174 dist_, | 169 dist_, |
175 exe_path.value(), | 170 exe_path.value(), |
176 description, | 171 description, |
177 string16(), | 172 string16(), |
178 string16(), | 173 string16(), |
179 exe_path.value(), | 174 exe_path.value(), |
180 dist_->GetIconIndex(), | 175 dist_->GetIconIndex(), |
181 ShellUtil::CURRENT_USER, | 176 ShellUtil::CURRENT_USER, |
182 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 177 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
183 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 178 ValidateChromeShortcut(exe_path, user_shortcut_path, description, 0); |
184 VerifyChromeShortcut(exe_path, user_shortcut_path, description, 0)); | |
185 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 179 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
186 dist_, | 180 dist_, |
187 ShellUtil::CURRENT_USER, | 181 ShellUtil::CURRENT_USER, |
188 ShellUtil::SHORTCUT_NO_OPTIONS)); | 182 ShellUtil::SHORTCUT_NO_OPTIONS)); |
189 | 183 |
190 // Test simple creation of a system-level shortcut. | 184 // Test simple creation of a system-level shortcut. |
191 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 185 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
192 dist_, | 186 dist_, |
193 exe_path.value(), | 187 exe_path.value(), |
194 description, | 188 description, |
195 string16(), | 189 string16(), |
196 string16(), | 190 string16(), |
197 exe_path.value(), | 191 exe_path.value(), |
198 dist_->GetIconIndex(), | 192 dist_->GetIconIndex(), |
199 ShellUtil::SYSTEM_LEVEL, | 193 ShellUtil::SYSTEM_LEVEL, |
200 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 194 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
201 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 195 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); |
202 VerifyChromeShortcut( | |
203 exe_path, system_shortcut_path, description, 0)); | |
204 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 196 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
205 dist_, | 197 dist_, |
206 ShellUtil::SYSTEM_LEVEL, | 198 ShellUtil::SYSTEM_LEVEL, |
207 ShellUtil::SHORTCUT_NO_OPTIONS)); | 199 ShellUtil::SHORTCUT_NO_OPTIONS)); |
208 | 200 |
209 // Test creation of a user-level shortcut when a system-level shortcut | 201 // Test creation of a user-level shortcut when a system-level shortcut |
210 // is already present (should fail). | 202 // is already present (should fail). |
211 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 203 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
212 dist_, | 204 dist_, |
213 exe_path.value(), | 205 exe_path.value(), |
214 description, | 206 description, |
215 string16(), | 207 string16(), |
216 string16(), | 208 string16(), |
217 exe_path.value(), | 209 exe_path.value(), |
218 dist_->GetIconIndex(), | 210 dist_->GetIconIndex(), |
219 ShellUtil::SYSTEM_LEVEL, | 211 ShellUtil::SYSTEM_LEVEL, |
220 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 212 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
221 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( | 213 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( |
222 dist_, | 214 dist_, |
223 exe_path.value(), | 215 exe_path.value(), |
224 description, | 216 description, |
225 string16(), | 217 string16(), |
226 string16(), | 218 string16(), |
227 exe_path.value(), | 219 exe_path.value(), |
228 dist_->GetIconIndex(), | 220 dist_->GetIconIndex(), |
229 ShellUtil::CURRENT_USER, | 221 ShellUtil::CURRENT_USER, |
230 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 222 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
231 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 223 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); |
232 VerifyChromeShortcut( | |
233 exe_path, system_shortcut_path, description, 0)); | |
234 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); | 224 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); |
235 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 225 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
236 dist_, | 226 dist_, |
237 ShellUtil::SYSTEM_LEVEL, | 227 ShellUtil::SYSTEM_LEVEL, |
238 ShellUtil::SHORTCUT_NO_OPTIONS)); | 228 ShellUtil::SHORTCUT_NO_OPTIONS)); |
239 | 229 |
240 // Test creation of a system-level shortcut when a user-level shortcut | 230 // Test creation of a system-level shortcut when a user-level shortcut |
241 // is already present (should succeed). | 231 // is already present (should succeed). |
242 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 232 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
243 dist_, | 233 dist_, |
244 exe_path.value(), | 234 exe_path.value(), |
245 description, | 235 description, |
246 string16(), | 236 string16(), |
247 string16(), | 237 string16(), |
248 exe_path.value(), | 238 exe_path.value(), |
249 dist_->GetIconIndex(), | 239 dist_->GetIconIndex(), |
250 ShellUtil::CURRENT_USER, | 240 ShellUtil::CURRENT_USER, |
251 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 241 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
252 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 242 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
253 dist_, | 243 dist_, |
254 exe_path.value(), | 244 exe_path.value(), |
255 description, | 245 description, |
256 string16(), | 246 string16(), |
257 string16(), | 247 string16(), |
258 exe_path.value(), | 248 exe_path.value(), |
259 dist_->GetIconIndex(), | 249 dist_->GetIconIndex(), |
260 ShellUtil::SYSTEM_LEVEL, | 250 ShellUtil::SYSTEM_LEVEL, |
261 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 251 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
262 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 252 ValidateChromeShortcut(exe_path, user_shortcut_path, description, 0); |
263 VerifyChromeShortcut(exe_path, user_shortcut_path, description, 0)); | 253 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); |
264 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | |
265 VerifyChromeShortcut( | |
266 exe_path, system_shortcut_path, description, 0)); | |
267 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 254 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
268 dist_, | 255 dist_, |
269 ShellUtil::CURRENT_USER, | 256 ShellUtil::CURRENT_USER, |
270 ShellUtil::SHORTCUT_NO_OPTIONS)); | 257 ShellUtil::SHORTCUT_NO_OPTIONS)); |
271 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 258 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
272 dist_, | 259 dist_, |
273 ShellUtil::SYSTEM_LEVEL, | 260 ShellUtil::SYSTEM_LEVEL, |
274 ShellUtil::SHORTCUT_NO_OPTIONS)); | 261 ShellUtil::SHORTCUT_NO_OPTIONS)); |
275 | 262 |
276 // Test creation of two profile-specific shortcuts (these are always | 263 // Test creation of two profile-specific shortcuts (these are always |
277 // user-level). | 264 // user-level). |
278 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 265 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
279 dist_, | 266 dist_, |
280 exe_path.value(), | 267 exe_path.value(), |
281 description, | 268 description, |
282 default_profile_user_name, | 269 default_profile_user_name, |
283 L"--profile-directory=\"Default\"", | 270 L"--profile-directory=\"Default\"", |
284 exe_path.value(), | 271 exe_path.value(), |
285 dist_->GetIconIndex(), | 272 dist_->GetIconIndex(), |
286 ShellUtil::CURRENT_USER, | 273 ShellUtil::CURRENT_USER, |
287 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 274 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
288 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 275 ValidateChromeShortcut(exe_path, default_profile_shortcut_path, description, |
289 VerifyChromeShortcut( | 276 0); |
290 exe_path, default_profile_shortcut_path, description, 0)); | |
291 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 277 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
292 dist_, | 278 dist_, |
293 exe_path.value(), | 279 exe_path.value(), |
294 description, | 280 description, |
295 second_profile_user_name, | 281 second_profile_user_name, |
296 L"--profile-directory=\"Profile 1\"", | 282 L"--profile-directory=\"Profile 1\"", |
297 exe_path.value(), | 283 exe_path.value(), |
298 dist_->GetIconIndex(), | 284 dist_->GetIconIndex(), |
299 ShellUtil::CURRENT_USER, | 285 ShellUtil::CURRENT_USER, |
300 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 286 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
301 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 287 ValidateChromeShortcut(exe_path, second_profile_shortcut_path, description, |
302 VerifyChromeShortcut( | 288 0); |
303 exe_path, second_profile_shortcut_path, description, 0)); | |
304 std::vector<string16> profile_names; | 289 std::vector<string16> profile_names; |
305 profile_names.push_back(default_profile_shortcut_name); | 290 profile_names.push_back(default_profile_shortcut_name); |
306 profile_names.push_back(second_profile_shortcut_name); | 291 profile_names.push_back(second_profile_shortcut_name); |
307 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 292 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
308 profile_names)); | 293 profile_names)); |
309 } | 294 } |
310 | 295 |
311 TEST(ShellUtilTest, BuildAppModelIdBasic) { | 296 TEST(ShellUtilTest, BuildAppModelIdBasic) { |
312 std::vector<string16> components; | 297 std::vector<string16> components; |
313 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 298 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 364 |
380 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 365 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
381 L"MZXW6YTB", L"MZXW6YTBOI"}; | 366 L"MZXW6YTB", L"MZXW6YTBOI"}; |
382 | 367 |
383 // Run the tests, with one more letter in the input every pass. | 368 // Run the tests, with one more letter in the input every pass. |
384 for (int i = 0; i < arraysize(expected); ++i) { | 369 for (int i = 0; i < arraysize(expected); ++i) { |
385 ASSERT_EQ(expected[i], | 370 ASSERT_EQ(expected[i], |
386 ShellUtil::ByteArrayToBase32(test_array, i)); | 371 ShellUtil::ByteArrayToBase32(test_array, i)); |
387 } | 372 } |
388 } | 373 } |
OLD | NEW |