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

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

Issue 10836247: Refactor ShellUtil shortcut code -- single multi-purpose methods as opposed to many slighlty diffe… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respect microsoft's definition of correct C++ Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | chrome/installer/util/util_constants.h » ('j') | 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 <fstream> 5 #include "chrome/installer/util/shell_util.h"
6
6 #include <vector> 7 #include <vector>
7 8
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/md5.h" 10 #include "base/md5.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/memory/scoped_ptr.h"
14 #include "base/test/test_shortcut_win.h" 16 #include "base/test/test_shortcut_win.h"
15 #include "base/win/shortcut.h" 17 #include "base/win/shortcut.h"
16 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
17 #include "chrome/installer/util/browser_distribution.h" 19 #include "chrome/installer/util/browser_distribution.h"
18 #include "chrome/installer/util/master_preferences.h"
19 #include "chrome/installer/util/shell_util.h"
20 #include "chrome/installer/util/util_constants.h" 20 #include "chrome/installer/util/util_constants.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace { 23 namespace {
24 24
25 class ShellUtilShortcutTest : public testing::Test { 25 class ShellUtilShortcutTest : public testing::Test {
26 protected: 26 protected:
27 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
28 dist_ = BrowserDistribution::GetDistribution(); 28 dist_ = BrowserDistribution::GetDistribution();
29 ASSERT_TRUE(dist_ != NULL); 29 ASSERT_TRUE(dist_ != NULL);
30 30
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe);
33 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0));
34
32 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); 35 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir());
33 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); 36 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir());
37 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir());
38 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir());
39 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir());
40 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir());
34 ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP, 41 ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP,
35 fake_user_desktop_.path())); 42 fake_user_desktop_.path()));
36 ASSERT_TRUE(PathService::Override(base::DIR_COMMON_DESKTOP, 43 ASSERT_TRUE(PathService::Override(base::DIR_COMMON_DESKTOP,
37 fake_common_desktop_.path())); 44 fake_common_desktop_.path()));
45 ASSERT_TRUE(PathService::Override(base::DIR_USER_QUICK_LAUNCH,
46 fake_user_quick_launch_.path()));
47 ASSERT_TRUE(PathService::Override(base::DIR_DEFAULT_USER_QUICK_LAUNCH,
48 fake_default_user_quick_launch_.path()));
49 ASSERT_TRUE(PathService::Override(base::DIR_START_MENU,
50 fake_start_menu_.path()));
51 ASSERT_TRUE(PathService::Override(base::DIR_COMMON_START_MENU,
52 fake_common_start_menu_.path()));
53
54 FilePath icon_path;
55 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path);
56 test_properties_.reset(
57 new ShellUtil::ChromeShortcutProperties(ShellUtil::CURRENT_USER));
58 test_properties_->set_chrome_exe(chrome_exe_);
59 test_properties_->set_arguments(L"--test --chrome");
60 test_properties_->set_description(L"Makes polar bears dance.");
61 test_properties_->set_icon(icon_path);
62 test_properties_->set_app_id(L"Polar.Bear");
63 test_properties_->set_dual_mode(true);
38 } 64 }
39 65
66 // Validates that the shortcut at |location| matches |properties| (and
67 // implicit default properties) for |dist|.
68 // Note: This method doesn't verify the |pin_to_taskbar| property as it
69 // implies real (non-mocked) state which is flaky to test.
70 void ValidateChromeShortcut(
71 ShellUtil::ChromeShortcutLocation location,
72 BrowserDistribution* dist,
73 const ShellUtil::ChromeShortcutProperties& properties) {
74 FilePath expected_path;
75 switch (location) {
76 case ShellUtil::SHORTCUT_DESKTOP:
77 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
78 fake_user_desktop_.path() : fake_common_desktop_.path();
79 break;
80 case ShellUtil::SHORTCUT_QUICK_LAUNCH:
81 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
82 fake_user_quick_launch_.path() :
83 fake_default_user_quick_launch_.path();
84 break;
85 case ShellUtil::SHORTCUT_START_MENU:
86 expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
87 fake_start_menu_.path() : fake_common_start_menu_.path();
88 expected_path = expected_path.Append(dist_->GetAppShortCutName());
89 break;
90 default:
91 ADD_FAILURE() << "Unknown location";
92 return;
93 }
94
95 string16 shortcut_name;
96 if (properties.has_shortcut_name()) {
97 shortcut_name = properties.shortcut_name;
98 } else {
99 shortcut_name = dist_->GetAppShortCutName();
100 }
101 shortcut_name.append(installer::kLnkExt);
102 expected_path = expected_path.Append(shortcut_name);
103
104 base::win::ShortcutProperties expected_properties;
105 expected_properties.set_target(chrome_exe_);
106 expected_properties.set_working_dir(chrome_exe_.DirName());
107
108 if (properties.has_arguments())
109 expected_properties.set_arguments(properties.arguments);
110 else
111 expected_properties.set_arguments(string16());
112
113 if (properties.has_description())
114 expected_properties.set_description(properties.description);
115 else
116 expected_properties.set_description(dist->GetAppDescription());
117
118 if (properties.has_icon()) {
119 expected_properties.set_icon(properties.icon, 0);
120 } else {
121 int icon_index = dist->GetIconIndex();
122 expected_properties.set_icon(chrome_exe_, icon_index);
123 }
124
125 if (properties.has_app_id()) {
126 expected_properties.set_app_id(properties.app_id);
127 } else {
128 // Tests are always seen as user-level installs in ShellUtil.
129 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true));
130 }
131
132 if (properties.has_dual_mode())
133 expected_properties.set_dual_mode(properties.dual_mode);
134 else
135 expected_properties.set_dual_mode(false);
136
137 base::win::ValidateShortcut(expected_path, expected_properties);
138 }
139
40 BrowserDistribution* dist_; 140 BrowserDistribution* dist_;
41 141
142 // A ChromeShortcutProperties object with common properties set already.
143 scoped_ptr<ShellUtil::ChromeShortcutProperties> test_properties_;
144
42 ScopedTempDir temp_dir_; 145 ScopedTempDir temp_dir_;
43
44 ScopedTempDir fake_user_desktop_; 146 ScopedTempDir fake_user_desktop_;
45 ScopedTempDir fake_common_desktop_; 147 ScopedTempDir fake_common_desktop_;
148 ScopedTempDir fake_user_quick_launch_;
149 ScopedTempDir fake_default_user_quick_launch_;
150 ScopedTempDir fake_start_menu_;
151 ScopedTempDir fake_common_start_menu_;
152
153 FilePath chrome_exe_;
46 }; 154 };
47 155
48 // Calls base::win::ValidateShortcut for the properties passed in. 156 } // namespace
49 // TODO(gab): This is only temporary while waiting for my upcoming CL that will 157
50 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't 158 TEST_F(ShellUtilShortcutTest, GetShortcutPath) {
51 // want to adapt every test here for this half-changed state as they will change 159 FilePath path;
52 // again very soon). 160 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist_,
53 void ValidateChromeShortcut(const FilePath& exe_path, 161 ShellUtil::CURRENT_USER, &path);
54 const FilePath& shortcut_path, 162 EXPECT_EQ(fake_user_desktop_.path(), path);
55 const string16& description, 163 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist_,
56 int icon_index) { 164 ShellUtil::SYSTEM_LEVEL, &path);
57 base::win::ShortcutProperties expected_properties; 165 EXPECT_EQ(fake_common_desktop_.path(), path);
58 expected_properties.set_target(exe_path); 166 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_,
59 expected_properties.set_description(description); 167 ShellUtil::CURRENT_USER, &path);
60 expected_properties.set_icon(exe_path, icon_index); 168 EXPECT_EQ(fake_user_quick_launch_.path(), path);
61 base::win::ValidateShortcut(shortcut_path, expected_properties); 169 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_,
62 } 170 ShellUtil::SYSTEM_LEVEL, &path);
63 171 EXPECT_EQ(fake_default_user_quick_launch_.path(), path);
64 } 172 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist_,
65 173 ShellUtil::CURRENT_USER, &path);
66 // Test that we can open archives successfully. 174 EXPECT_EQ(fake_start_menu_.path().Append(dist_->GetAppShortCutName()), path);
67 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { 175 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist_,
68 // Create an executable in test path by copying ourself to it. 176 ShellUtil::SYSTEM_LEVEL, &path);
69 wchar_t exe_full_path_str[MAX_PATH]; 177 EXPECT_EQ(fake_common_start_menu_.path().Append(dist_->GetAppShortCutName()),
70 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 178 path);
71 FilePath exe_full_path(exe_full_path_str); 179 }
72 180
73 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 181 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) {
74 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 182 ShellUtil::ChromeShortcutProperties properties(ShellUtil::CURRENT_USER);
75 183 properties.set_chrome_exe(chrome_exe_);
76 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); 184 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
77 const string16 description(L"dummy description"); 185 ShellUtil::SHORTCUT_DESKTOP, dist_, properties,
78 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( 186 ShellUtil::SHORTCUT_CREATE_ALWAYS));
79 dist_, 187 ValidateChromeShortcut(ShellUtil::SHORTCUT_DESKTOP, dist_, properties);
80 exe_path.value(), 188 }
81 shortcut_path.value(), 189
82 string16(), 190 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) {
83 description, 191 test_properties_->set_shortcut_name(L"Bobo le shortcut");
84 exe_path.value(), 192 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
85 dist_->GetIconIndex(), 193 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
86 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 194 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_,
87 ValidateChromeShortcut(exe_path, shortcut_path, description, 0); 195 ShellUtil::SHORTCUT_CREATE_ALWAYS));
88 196 ValidateChromeShortcut(ShellUtil::SHORTCUT_START_MENU, dist_,
89 // Now specify an icon index in master prefs and make sure it works. 197 *test_properties_);
90 FilePath prefs_path = temp_dir_.path().AppendASCII( 198 }
91 installer::kDefaultMasterPrefs); 199
92 std::ofstream file; 200 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) {
93 file.open(prefs_path.value().c_str()); 201 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
94 ASSERT_TRUE(file.is_open()); 202 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
95 file << 203 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, *test_properties_,
96 "{" 204 ShellUtil::SHORTCUT_CREATE_ALWAYS));
97 " \"distribution\":{" 205
98 " \"chrome_shortcut_icon_index\" : 1" 206 ShellUtil::ChromeShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL);
99 " }" 207 new_properties.set_chrome_exe(chrome_exe_);
100 "}"; 208 new_properties.set_description(L"New description");
101 file.close(); 209 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
102 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); 210 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, new_properties,
103 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( 211 ShellUtil::SHORTCUT_REPLACE_EXISTING));
104 dist_, 212
105 exe_path.value(), 213 // Expect the properties set in |new_properties| to be set as above and
106 shortcut_path.value(), 214 // properties that don't have a default value to be set back to their default
107 string16(), 215 // (as validated in ValidateChromeShortcut()) or unset if they don't .
108 description, 216 ShellUtil::ChromeShortcutProperties expected_properties(new_properties);
109 exe_path.value(), 217 expected_properties.set_arguments(string16());
110 dist_->GetIconIndex(), 218 expected_properties.set_dual_mode(false);
111 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 219
112 ValidateChromeShortcut(exe_path, shortcut_path, description, 1); 220 ValidateChromeShortcut(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_,
113 221 expected_properties);
114 // Now change only description to update shortcut and make sure icon index 222 }
115 // doesn't change. 223
116 const string16 description2(L"dummy description 2"); 224 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) {
117 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, 225 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
118 exe_path.value(), 226 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, *test_properties_,
119 shortcut_path.value(), 227 ShellUtil::SHORTCUT_CREATE_ALWAYS));
120 string16(), 228
121 description2, 229 ShellUtil::ChromeShortcutProperties updated_properties(
122 exe_path.value(), 230 ShellUtil::CURRENT_USER);
123 dist_->GetIconIndex(), 231 updated_properties.set_arguments(L"--updated --arguments");
124 ShellUtil::SHORTCUT_NO_OPTIONS)); 232 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
125 ValidateChromeShortcut(exe_path, shortcut_path, description2, 1); 233 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, updated_properties,
126 } 234 ShellUtil::SHORTCUT_UPDATE_EXISTING));
127 235
128 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { 236 // Expect the properties set in |updated_properties| to be set as above and
129 // Create an executable in test path by copying ourself to it. 237 // all other properties to remain unchanged.
130 wchar_t exe_full_path_str[MAX_PATH]; 238 ShellUtil::ChromeShortcutProperties expected_properties(*test_properties_);
131 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 239 expected_properties.set_arguments(updated_properties.arguments);
132 FilePath exe_full_path(exe_full_path_str); 240
133 241 ValidateChromeShortcut(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_,
134 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 242 expected_properties);
135 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 243 }
136 244
137 const string16 description(L"dummy description"); 245 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) {
138 246 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
139 FilePath user_desktop_path; 247 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
140 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); 248 ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
141 FilePath system_desktop_path; 249 ValidateChromeShortcut(ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_);
142 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); 250 }
143 251
144 string16 shortcut_name; 252 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) {
145 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, string16(), 253 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
146 &shortcut_name)); 254
147 255 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
148 string16 default_profile_shortcut_name; 256 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
149 const string16 default_profile_user_name = L"Minsk"; 257 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
150 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, 258 ShellUtil::SHORTCUT_CREATE_ALWAYS));
151 default_profile_user_name, 259 ASSERT_TRUE(file_util::PathExists(
152 &default_profile_shortcut_name)); 260 fake_common_desktop_.path().Append(shortcut_name)));
153 261
154 string16 second_profile_shortcut_name; 262 test_properties_->level = ShellUtil::CURRENT_USER;
155 const string16 second_profile_user_name = L"Pinsk"; 263 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
156 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, 264 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
157 second_profile_user_name, 265 ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
158 &second_profile_shortcut_name)); 266 ASSERT_FALSE(file_util::PathExists(
159 267 fake_user_desktop_.path().Append(shortcut_name)));
160 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); 268 }
161 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); 269
162 FilePath default_profile_shortcut_path = user_desktop_path.Append( 270 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) {
163 default_profile_shortcut_name); 271 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
164 FilePath second_profile_shortcut_path = user_desktop_path.Append( 272
165 second_profile_shortcut_name); 273 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
166 274 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
167 // Test simple creation of a user-level shortcut. 275 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
168 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 276 ShellUtil::SHORTCUT_CREATE_ALWAYS));
169 dist_, 277 ASSERT_TRUE(file_util::PathExists(
170 exe_path.value(), 278 fake_common_desktop_.path().Append(shortcut_name)));
171 description, 279
172 string16(), 280 test_properties_->level = ShellUtil::CURRENT_USER;
173 string16(), 281 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
174 exe_path.value(), 282 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
175 dist_->GetIconIndex(), 283 ShellUtil::SHORTCUT_CREATE_ALWAYS));
176 ShellUtil::CURRENT_USER, 284 ASSERT_TRUE(file_util::PathExists(
177 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 285 fake_user_desktop_.path().Append(shortcut_name)));
178 ValidateChromeShortcut(exe_path, user_shortcut_path, description, 0); 286 }
179 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 287
180 dist_, 288 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) {
181 ShellUtil::CURRENT_USER, 289 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
182 ShellUtil::SHORTCUT_NO_OPTIONS)); 290 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
183 291 ShellUtil::SHORTCUT_CREATE_ALWAYS));
184 // Test simple creation of a system-level shortcut. 292
185 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 293 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
186 dist_, 294 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
187 exe_path.value(), 295 ASSERT_TRUE(file_util::PathExists(shortcut_path));
188 description, 296
189 string16(), 297 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut(
190 string16(), 298 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::CURRENT_USER, NULL));
191 exe_path.value(), 299 ASSERT_FALSE(file_util::PathExists(shortcut_path));
192 dist_->GetIconIndex(), 300 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
193 ShellUtil::SYSTEM_LEVEL, 301 }
194 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 302
195 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); 303 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) {
196 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 304 test_properties_->level = ShellUtil::SYSTEM_LEVEL;
197 dist_, 305 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
198 ShellUtil::SYSTEM_LEVEL, 306 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
199 ShellUtil::SHORTCUT_NO_OPTIONS)); 307 ShellUtil::SHORTCUT_CREATE_ALWAYS));
200 308
201 // Test creation of a user-level shortcut when a system-level shortcut 309 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt);
202 // is already present (should fail). 310 FilePath shortcut_path(fake_common_desktop_.path().Append(shortcut_name));
203 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 311 ASSERT_TRUE(file_util::PathExists(shortcut_path));
204 dist_, 312
205 exe_path.value(), 313 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut(
206 description, 314 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, NULL));
207 string16(), 315 ASSERT_FALSE(file_util::PathExists(shortcut_path));
208 string16(), 316 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
209 exe_path.value(), 317 }
210 dist_->GetIconIndex(), 318
211 ShellUtil::SYSTEM_LEVEL, 319 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) {
212 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 320 static const wchar_t kSpecialName[] = L"I'm special";
213 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( 321 test_properties_->set_shortcut_name(kSpecialName);
214 dist_, 322 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
215 exe_path.value(), 323 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_,
216 description, 324 ShellUtil::SHORTCUT_CREATE_ALWAYS));
217 string16(), 325
218 string16(), 326 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt));
219 exe_path.value(), 327 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name));
220 dist_->GetIconIndex(), 328 ASSERT_TRUE(file_util::PathExists(shortcut_path));
221 ShellUtil::CURRENT_USER, 329
222 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 330 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut(
223 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); 331 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::CURRENT_USER,
224 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); 332 &string16(kSpecialName)));
225 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( 333 ASSERT_FALSE(file_util::PathExists(shortcut_path));
226 dist_, 334 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName()));
227 ShellUtil::SYSTEM_LEVEL, 335 }
228 ShellUtil::SHORTCUT_NO_OPTIONS)); 336
229 337 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
230 // Test creation of a system-level shortcut when a user-level shortcut 338 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
231 // is already present (should succeed). 339 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_,
232 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 340 ShellUtil::SHORTCUT_CREATE_ALWAYS));
233 dist_, 341 test_properties_->set_shortcut_name(L"A second shortcut");
234 exe_path.value(), 342 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut(
235 description, 343 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_,
236 string16(), 344 ShellUtil::SHORTCUT_CREATE_ALWAYS));
237 string16(), 345
238 exe_path.value(), 346 FilePath shortcut_folder(
239 dist_->GetIconIndex(), 347 fake_start_menu_.path().Append(dist_->GetAppShortCutName()));
240 ShellUtil::CURRENT_USER, 348 file_util::FileEnumerator file_counter (shortcut_folder, false,
241 ShellUtil::SHORTCUT_CREATE_ALWAYS)); 349 file_util::FileEnumerator::FILES);
242 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( 350 int count = 0;
243 dist_, 351 while (!file_counter.Next().empty())
244 exe_path.value(), 352 ++count;
245 description, 353 EXPECT_EQ(2, count);
246 string16(), 354
247 string16(), 355 ASSERT_TRUE(file_util::PathExists(shortcut_folder));
248 exe_path.value(), 356 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut(
249 dist_->GetIconIndex(), 357 ShellUtil::SHORTCUT_START_MENU, dist_, ShellUtil::CURRENT_USER, NULL));
250 ShellUtil::SYSTEM_LEVEL, 358 ASSERT_FALSE(file_util::PathExists(shortcut_folder));
251 ShellUtil::SHORTCUT_CREATE_ALWAYS));
252 ValidateChromeShortcut(exe_path, user_shortcut_path, description, 0);
253 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0);
254 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
255 dist_,
256 ShellUtil::CURRENT_USER,
257 ShellUtil::SHORTCUT_NO_OPTIONS));
258 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(
259 dist_,
260 ShellUtil::SYSTEM_LEVEL,
261 ShellUtil::SHORTCUT_NO_OPTIONS));
262
263 // Test creation of two profile-specific shortcuts (these are always
264 // user-level).
265 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
266 dist_,
267 exe_path.value(),
268 description,
269 default_profile_user_name,
270 L"--profile-directory=\"Default\"",
271 exe_path.value(),
272 dist_->GetIconIndex(),
273 ShellUtil::CURRENT_USER,
274 ShellUtil::SHORTCUT_CREATE_ALWAYS));
275 ValidateChromeShortcut(exe_path, default_profile_shortcut_path, description,
276 0);
277 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(
278 dist_,
279 exe_path.value(),
280 description,
281 second_profile_user_name,
282 L"--profile-directory=\"Profile 1\"",
283 exe_path.value(),
284 dist_->GetIconIndex(),
285 ShellUtil::CURRENT_USER,
286 ShellUtil::SHORTCUT_CREATE_ALWAYS));
287 ValidateChromeShortcut(exe_path, second_profile_shortcut_path, description,
288 0);
289 std::vector<string16> profile_names;
290 profile_names.push_back(default_profile_shortcut_name);
291 profile_names.push_back(second_profile_shortcut_name);
292 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
293 profile_names));
294 } 359 }
295 360
296 TEST(ShellUtilTest, BuildAppModelIdBasic) { 361 TEST(ShellUtilTest, BuildAppModelIdBasic) {
297 std::vector<string16> components; 362 std::vector<string16> components;
298 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 363 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
299 const string16 base_app_id(dist->GetBaseAppId()); 364 const string16 base_app_id(dist->GetBaseAppId());
300 components.push_back(base_app_id); 365 components.push_back(base_app_id);
301 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); 366 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components));
302 } 367 }
303 368
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 429
365 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 430 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
366 L"MZXW6YTB", L"MZXW6YTBOI"}; 431 L"MZXW6YTB", L"MZXW6YTBOI"};
367 432
368 // Run the tests, with one more letter in the input every pass. 433 // Run the tests, with one more letter in the input every pass.
369 for (int i = 0; i < arraysize(expected); ++i) { 434 for (int i = 0; i < arraysize(expected); ++i) {
370 ASSERT_EQ(expected[i], 435 ASSERT_EQ(expected[i],
371 ShellUtil::ByteArrayToBase32(test_array, i)); 436 ShellUtil::ByteArrayToBase32(test_array, i));
372 } 437 }
373 } 438 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | chrome/installer/util/util_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698