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

Side by Side Diff: chrome/installer/util/shell_util_unittest.cc

Issue 10826188: Sharing shell_util_unittest code to verify shortcuts (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <windows.h>
6 #include <shellapi.h>
7 #include <shlobj.h> 5 #include <shlobj.h>
8 6
9 #include <fstream> 7 #include <fstream>
10 #include <vector> 8 #include <vector>
11 9
12 #include "base/file_util.h" 10 #include "base/file_util.h"
13 #include "base/path_service.h" 11 #include "base/path_service.h"
14 #include "base/md5.h" 12 #include "base/md5.h"
15 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
16 #include "base/string16.h" 14 #include "base/string16.h"
17 #include "base/string_util.h" 15 #include "base/string_util.h"
18 #include "base/win/scoped_comptr.h"
19 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
20 #include "chrome/installer/util/browser_distribution.h" 17 #include "chrome/installer/util/browser_distribution.h"
21 #include "chrome/installer/util/master_preferences.h" 18 #include "chrome/installer/util/master_preferences.h"
22 #include "chrome/installer/util/shell_util.h" 19 #include "chrome/installer/util/shell_util.h"
23 #include "chrome/installer/util/util_constants.h" 20 #include "chrome/installer/util/util_constants.h"
24 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
25 22
26 namespace { 23 namespace {
27 bool VerifyChromeShortcut(const std::wstring& exe_path,
28 const std::wstring& shortcut,
29 const std::wstring& description,
30 int icon_index) {
31 base::win::ScopedComPtr<IShellLink> i_shell_link;
32 base::win::ScopedComPtr<IPersistFile> i_persist_file;
33
34 // Get pointer to the IShellLink interface
35 bool failed = FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
36 CLSCTX_INPROC_SERVER));
37 EXPECT_FALSE(failed) << "Failed to get IShellLink";
38 if (failed)
39 return false;
40
41 // Query IShellLink for the IPersistFile interface
42 failed = FAILED(i_persist_file.QueryFrom(i_shell_link));
43 EXPECT_FALSE(failed) << "Failed to get IPersistFile";
44 if (failed)
45 return false;
46
47 failed = FAILED(i_persist_file->Load(shortcut.c_str(), 0));
48 EXPECT_FALSE(failed) << "Failed to load shortcut " << shortcut.c_str();
49 if (failed)
50 return false;
51
52 wchar_t long_path[MAX_PATH] = {0};
53 wchar_t short_path[MAX_PATH] = {0};
54 failed = ((::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0) ||
55 (::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0));
56 EXPECT_FALSE(failed) << "Failed to get long and short path names for "
57 << exe_path;
58 if (failed)
59 return false;
60
61 wchar_t file_path[MAX_PATH] = {0};
62 failed = ((FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL,
63 SLGP_UNCPRIORITY))) ||
64 ((FilePath(file_path) != FilePath(long_path)) &&
65 (FilePath(file_path) != FilePath(short_path))));
66 EXPECT_FALSE(failed) << "File path " << file_path << " did not match with "
67 << exe_path;
68 if (failed)
69 return false;
70
71 wchar_t desc[MAX_PATH] = {0};
72 failed = ((FAILED(i_shell_link->GetDescription(desc, MAX_PATH))) ||
73 (std::wstring(desc) != std::wstring(description)));
74 EXPECT_FALSE(failed) << "Description " << desc << " did not match with "
75 << description;
76 if (failed)
77 return false;
78
79 wchar_t icon_path[MAX_PATH] = {0};
80 int index = 0;
81 failed = ((FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH,
82 &index))) ||
83 ((FilePath(file_path) != FilePath(long_path)) &&
84 (FilePath(file_path) != FilePath(short_path))) ||
85 (index != icon_index));
86 EXPECT_FALSE(failed);
87 if (failed)
88 return false;
89
90 return true;
91 }
92 24
93 class ShellUtilTestWithDirAndDist : public testing::Test { 25 class ShellUtilTestWithDirAndDist : public testing::Test {
94 protected: 26 protected:
95 virtual void SetUp() { 27 virtual void SetUp() {
96 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
97 dist_ = BrowserDistribution::GetDistribution(); 29 dist_ = BrowserDistribution::GetDistribution();
98 ASSERT_TRUE(dist_ != NULL); 30 ASSERT_TRUE(dist_ != NULL);
99 } 31 }
100 32
101 BrowserDistribution* dist_; 33 BrowserDistribution* dist_;
102 34
103 ScopedTempDir temp_dir_; 35 ScopedTempDir temp_dir_;
104 }; 36 };
105 }; 37
38 }
106 39
107 // Test that we can open archives successfully. 40 // Test that we can open archives successfully.
108 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { 41 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) {
109 // Create an executable in test path by copying ourself to it. 42 // Create an executable in test path by copying ourself to it.
110 wchar_t exe_full_path_str[MAX_PATH]; 43 wchar_t exe_full_path_str[MAX_PATH];
111 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 44 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
112 FilePath exe_full_path(exe_full_path_str); 45 FilePath exe_full_path(exe_full_path_str);
113 46
114 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 47 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
115 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 48 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
116 49
117 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); 50 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk");
118 const std::wstring description(L"dummy description"); 51 const string16 description(L"dummy description");
119 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( 52 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(
120 dist_, 53 dist_,
121 exe_path.value(), 54 exe_path.value(),
122 shortcut_path.value(), 55 shortcut_path.value(),
123 L"", 56 L"",
124 description, 57 description,
125 exe_path.value(), 58 exe_path.value(),
126 dist_->GetIconIndex(), 59 dist_->GetIconIndex(),
127 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 60 ShellUtil::SHORTCUT_CREATE_ALWAYS));
128 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 61 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
129 shortcut_path.value(), 62 ShellUtil::VerifyChromeShortcut(
130 description, 0)); 63 exe_path.value(), shortcut_path.value(), description, 0));
131 64
132 // Now specify an icon index in master prefs and make sure it works. 65 // Now specify an icon index in master prefs and make sure it works.
133 FilePath prefs_path = temp_dir_.path().AppendASCII( 66 FilePath prefs_path = temp_dir_.path().AppendASCII(
134 installer::kDefaultMasterPrefs); 67 installer::kDefaultMasterPrefs);
135 std::ofstream file; 68 std::ofstream file;
136 file.open(prefs_path.value().c_str()); 69 file.open(prefs_path.value().c_str());
137 ASSERT_TRUE(file.is_open()); 70 ASSERT_TRUE(file.is_open());
138 file << 71 file <<
139 "{" 72 "{"
140 " \"distribution\":{" 73 " \"distribution\":{"
141 " \"chrome_shortcut_icon_index\" : 1" 74 " \"chrome_shortcut_icon_index\" : 1"
142 " }" 75 " }"
143 "}"; 76 "}";
144 file.close(); 77 file.close();
145 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); 78 ASSERT_TRUE(file_util::Delete(shortcut_path, false));
146 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( 79 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(
147 dist_, 80 dist_,
148 exe_path.value(), 81 exe_path.value(),
149 shortcut_path.value(), 82 shortcut_path.value(),
150 L"", 83 L"",
151 description, 84 description,
152 exe_path.value(), 85 exe_path.value(),
153 dist_->GetIconIndex(), 86 dist_->GetIconIndex(),
154 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 87 ShellUtil::SHORTCUT_CREATE_ALWAYS));
155 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 88 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
156 shortcut_path.value(), 89 ShellUtil::VerifyChromeShortcut(
157 description, 1)); 90 exe_path.value(), shortcut_path.value(), description, 1));
158 91
159 // Now change only description to update shortcut and make sure icon index 92 // Now change only description to update shortcut and make sure icon index
160 // doesn't change. 93 // doesn't change.
161 const std::wstring description2(L"dummy description 2"); 94 const string16 description2(L"dummy description 2");
162 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, 95 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_,
163 exe_path.value(), 96 exe_path.value(),
164 shortcut_path.value(), 97 shortcut_path.value(),
165 L"", 98 L"",
166 description2, 99 description2,
167 exe_path.value(), 100 exe_path.value(),
168 dist_->GetIconIndex(), 101 dist_->GetIconIndex(),
169 ShellUtil::SHORTCUT_NO_OPTIONS)); 102 ShellUtil::SHORTCUT_NO_OPTIONS));
170 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 103 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
171 shortcut_path.value(), 104 ShellUtil::VerifyChromeShortcut(
172 description2, 1)); 105 exe_path.value(), shortcut_path.value(), description2, 1));
173 } 106 }
174 107
175 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { 108 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) {
176 // Run this test on Vista+ only if we are running elevated. 109 // Run this test on Vista+ only if we are running elevated.
177 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { 110 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) {
178 LOG(ERROR) << "Must be admin to run this test on Vista+"; 111 LOG(ERROR) << "Must be admin to run this test on Vista+";
179 return; 112 return;
180 } 113 }
181 114
182 // Create an executable in test path by copying ourself to it. 115 // Create an executable in test path by copying ourself to it.
183 wchar_t exe_full_path_str[MAX_PATH]; 116 wchar_t exe_full_path_str[MAX_PATH];
184 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 117 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
185 FilePath exe_full_path(exe_full_path_str); 118 FilePath exe_full_path(exe_full_path_str);
186 119
187 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 120 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
188 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 121 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
189 122
190 const std::wstring description(L"dummy description"); 123 const string16 description(L"dummy description");
191 124
192 FilePath user_desktop_path; 125 FilePath user_desktop_path;
193 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); 126 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path));
194 FilePath system_desktop_path; 127 FilePath system_desktop_path;
195 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); 128 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path));
196 129
197 std::wstring shortcut_name; 130 string16 shortcut_name;
198 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"", 131 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"",
199 &shortcut_name)); 132 &shortcut_name));
200 133
201 std::wstring default_profile_shortcut_name; 134 string16 default_profile_shortcut_name;
202 const std::wstring default_profile_user_name = L"Minsk"; 135 const string16 default_profile_user_name = L"Minsk";
203 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, 136 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false,
204 default_profile_user_name, 137 default_profile_user_name,
205 &default_profile_shortcut_name)); 138 &default_profile_shortcut_name));
206 139
207 std::wstring second_profile_shortcut_name; 140 string16 second_profile_shortcut_name;
208 const std::wstring second_profile_user_name = L"Pinsk"; 141 const string16 second_profile_user_name = L"Pinsk";
209 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, 142 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false,
210 second_profile_user_name, 143 second_profile_user_name,
211 &second_profile_shortcut_name)); 144 &second_profile_shortcut_name));
212 145
213 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); 146 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name);
214 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); 147 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name);
215 FilePath default_profile_shortcut_path = user_desktop_path.Append( 148 FilePath default_profile_shortcut_path = user_desktop_path.Append(
216 default_profile_shortcut_name); 149 default_profile_shortcut_name);
217 FilePath second_profile_shortcut_path = user_desktop_path.Append( 150 FilePath second_profile_shortcut_path = user_desktop_path.Append(
218 second_profile_shortcut_name); 151 second_profile_shortcut_name);
219 152
220 // Test simple creation of a user-level shortcut. 153 // Test simple creation of a user-level shortcut.
221 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 154 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
222 dist_, 155 dist_,
223 exe_path.value(), 156 exe_path.value(),
224 description, 157 description,
225 L"", 158 L"",
226 L"", 159 L"",
227 exe_path.value(), 160 exe_path.value(),
228 dist_->GetIconIndex(), 161 dist_->GetIconIndex(),
229 ShellUtil::CURRENT_USER, 162 ShellUtil::CURRENT_USER,
230 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 163 ShellUtil::SHORTCUT_CREATE_ALWAYS));
231 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 164 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
232 user_shortcut_path.value(), 165 ShellUtil::VerifyChromeShortcut(
233 description, 166 exe_path.value(), user_shortcut_path.value(), description, 0));
234 0));
235 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 167 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
236 dist_, 168 dist_,
237 ShellUtil::CURRENT_USER, 169 ShellUtil::CURRENT_USER,
238 ShellUtil::SHORTCUT_NO_OPTIONS)); 170 ShellUtil::SHORTCUT_NO_OPTIONS));
239 171
240 // Test simple creation of a system-level shortcut. 172 // Test simple creation of a system-level shortcut.
241 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 173 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
242 dist_, 174 dist_,
243 exe_path.value(), 175 exe_path.value(),
244 description, 176 description,
245 L"", 177 L"",
246 L"", 178 L"",
247 exe_path.value(), 179 exe_path.value(),
248 dist_->GetIconIndex(), 180 dist_->GetIconIndex(),
249 ShellUtil::SYSTEM_LEVEL, 181 ShellUtil::SYSTEM_LEVEL,
250 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 182 ShellUtil::SHORTCUT_CREATE_ALWAYS));
251 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 183 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
252 system_shortcut_path.value(), 184 ShellUtil::VerifyChromeShortcut(
253 description, 185 exe_path.value(), system_shortcut_path.value(), description,
254 0)); 186 0));
255 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 187 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
256 dist_, 188 dist_,
257 ShellUtil::SYSTEM_LEVEL, 189 ShellUtil::SYSTEM_LEVEL,
258 ShellUtil::SHORTCUT_NO_OPTIONS)); 190 ShellUtil::SHORTCUT_NO_OPTIONS));
259 191
260 // Test creation of a user-level shortcut when a system-level shortcut 192 // Test creation of a user-level shortcut when a system-level shortcut
261 // is already present (should fail). 193 // is already present (should fail).
262 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 194 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
263 dist_, 195 dist_,
264 exe_path.value(), 196 exe_path.value(),
265 description, 197 description,
266 L"", 198 L"",
267 L"", 199 L"",
268 exe_path.value(), 200 exe_path.value(),
269 dist_->GetIconIndex(), 201 dist_->GetIconIndex(),
270 ShellUtil::SYSTEM_LEVEL, 202 ShellUtil::SYSTEM_LEVEL,
271 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 203 ShellUtil::SHORTCUT_CREATE_ALWAYS));
272 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( 204 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(
273 dist_, 205 dist_,
274 exe_path.value(), 206 exe_path.value(),
275 description, 207 description,
276 L"", 208 L"",
277 L"", 209 L"",
278 exe_path.value(), 210 exe_path.value(),
279 dist_->GetIconIndex(), 211 dist_->GetIconIndex(),
280 ShellUtil::CURRENT_USER, 212 ShellUtil::CURRENT_USER,
281 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 213 ShellUtil::SHORTCUT_CREATE_ALWAYS));
282 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 214 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
283 system_shortcut_path.value(), 215 ShellUtil::VerifyChromeShortcut(
284 description, 216 exe_path.value(), system_shortcut_path.value(), description,
285 0)); 217 0));
286 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); 218 EXPECT_FALSE(file_util::PathExists(user_shortcut_path));
287 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 219 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
288 dist_, 220 dist_,
289 ShellUtil::SYSTEM_LEVEL, 221 ShellUtil::SYSTEM_LEVEL,
290 ShellUtil::SHORTCUT_NO_OPTIONS)); 222 ShellUtil::SHORTCUT_NO_OPTIONS));
291 223
292 // Test creation of a system-level shortcut when a user-level shortcut 224 // Test creation of a system-level shortcut when a user-level shortcut
293 // is already present (should succeed). 225 // is already present (should succeed).
294 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 226 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
295 dist_, 227 dist_,
296 exe_path.value(), 228 exe_path.value(),
297 description, 229 description,
298 L"", 230 L"",
299 L"", 231 L"",
300 exe_path.value(), 232 exe_path.value(),
301 dist_->GetIconIndex(), 233 dist_->GetIconIndex(),
302 ShellUtil::CURRENT_USER, 234 ShellUtil::CURRENT_USER,
303 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 235 ShellUtil::SHORTCUT_CREATE_ALWAYS));
304 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 236 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
305 dist_, 237 dist_,
306 exe_path.value(), 238 exe_path.value(),
307 description, 239 description,
308 L"", 240 L"",
309 L"", 241 L"",
310 exe_path.value(), 242 exe_path.value(),
311 dist_->GetIconIndex(), 243 dist_->GetIconIndex(),
312 ShellUtil::SYSTEM_LEVEL, 244 ShellUtil::SYSTEM_LEVEL,
313 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 245 ShellUtil::SHORTCUT_CREATE_ALWAYS));
314 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 246 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
315 user_shortcut_path.value(), 247 ShellUtil::VerifyChromeShortcut(
316 description, 248 exe_path.value(), user_shortcut_path.value(), description, 0));
317 0)); 249 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
318 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 250 ShellUtil::VerifyChromeShortcut(
319 system_shortcut_path.value(), 251 exe_path.value(), system_shortcut_path.value(), description,
320 description, 252 0));
321 0));
322 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 253 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
323 dist_, 254 dist_,
324 ShellUtil::CURRENT_USER, 255 ShellUtil::CURRENT_USER,
325 ShellUtil::SHORTCUT_NO_OPTIONS)); 256 ShellUtil::SHORTCUT_NO_OPTIONS));
326 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 257 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
327 dist_, 258 dist_,
328 ShellUtil::SYSTEM_LEVEL, 259 ShellUtil::SYSTEM_LEVEL,
329 ShellUtil::SHORTCUT_NO_OPTIONS)); 260 ShellUtil::SHORTCUT_NO_OPTIONS));
330 261
331 // Test creation of two profile-specific shortcuts (these are always 262 // Test creation of two profile-specific shortcuts (these are always
332 // user-level). 263 // user-level).
333 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 264 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
334 dist_, 265 dist_,
335 exe_path.value(), 266 exe_path.value(),
336 description, 267 description,
337 default_profile_user_name, 268 default_profile_user_name,
338 L"--profile-directory=\"Default\"", 269 L"--profile-directory=\"Default\"",
339 exe_path.value(), 270 exe_path.value(),
340 dist_->GetIconIndex(), 271 dist_->GetIconIndex(),
341 ShellUtil::CURRENT_USER, 272 ShellUtil::CURRENT_USER,
342 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 273 ShellUtil::SHORTCUT_CREATE_ALWAYS));
343 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 274 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
344 default_profile_shortcut_path.value(), 275 ShellUtil::VerifyChromeShortcut(
345 description, 276 exe_path.value(), default_profile_shortcut_path.value(),
346 0)); 277 description, 0));
347 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 278 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
348 dist_, 279 dist_,
349 exe_path.value(), 280 exe_path.value(),
350 description, 281 description,
351 second_profile_user_name, 282 second_profile_user_name,
352 L"--profile-directory=\"Profile 1\"", 283 L"--profile-directory=\"Profile 1\"",
353 exe_path.value(), 284 exe_path.value(),
354 dist_->GetIconIndex(), 285 dist_->GetIconIndex(),
355 ShellUtil::CURRENT_USER, 286 ShellUtil::CURRENT_USER,
356 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 287 ShellUtil::SHORTCUT_CREATE_ALWAYS));
357 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), 288 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
358 second_profile_shortcut_path.value(), 289 ShellUtil::VerifyChromeShortcut(
359 description, 290 exe_path.value(), second_profile_shortcut_path.value(),
360 0)); 291 description, 0));
361 std::vector<string16> profile_names; 292 std::vector<string16> profile_names;
362 profile_names.push_back(default_profile_shortcut_name); 293 profile_names.push_back(default_profile_shortcut_name);
363 profile_names.push_back(second_profile_shortcut_name); 294 profile_names.push_back(second_profile_shortcut_name);
364 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( 295 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
365 profile_names)); 296 profile_names));
366 } 297 }
367 298
368 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { 299 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) {
369 std::vector<string16> components; 300 std::vector<string16> components;
370 const string16 base_app_id(dist_->GetBaseAppId()); 301 const string16 base_app_id(dist_->GetBaseAppId());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 365
435 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 366 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
436 L"MZXW6YTB", L"MZXW6YTBOI"}; 367 L"MZXW6YTB", L"MZXW6YTBOI"};
437 368
438 // Run the tests, with one more letter in the input every pass. 369 // Run the tests, with one more letter in the input every pass.
439 for (int i = 0; i < arraysize(expected); ++i) { 370 for (int i = 0; i < arraysize(expected); ++i) {
440 ASSERT_EQ(expected[i], 371 ASSERT_EQ(expected[i],
441 ShellUtil::ByteArrayToBase32(test_array, i)); 372 ShellUtil::ByteArrayToBase32(test_array, i));
442 } 373 }
443 } 374 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698