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 "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.options & |
| 97 ShellUtil::ChromeShortcutProperties::PROPERTIES_SHORTCUT_NAME) { |
| 98 shortcut_name = properties.shortcut_name; |
| 99 } else { |
| 100 shortcut_name = dist_->GetAppShortCutName(); |
| 101 } |
| 102 shortcut_name.append(installer::kLnkExt); |
| 103 expected_path = expected_path.Append(shortcut_name); |
| 104 |
| 105 base::win::ShortcutProperties expected_properties; |
| 106 expected_properties.set_target(chrome_exe_); |
| 107 expected_properties.set_working_dir(chrome_exe_.DirName()); |
| 108 |
| 109 if (properties.options & |
| 110 ShellUtil::ChromeShortcutProperties::PROPERTIES_ARGUMENTS) { |
| 111 expected_properties.set_arguments(properties.arguments); |
| 112 } else { |
| 113 expected_properties.set_arguments(string16()); |
| 114 } |
| 115 |
| 116 if (properties.options & |
| 117 ShellUtil::ChromeShortcutProperties::PROPERTIES_DESCRIPTION) { |
| 118 expected_properties.set_description(properties.description); |
| 119 } else { |
| 120 expected_properties.set_description(dist->GetAppDescription()); |
| 121 } |
| 122 |
| 123 if (properties.options & |
| 124 ShellUtil::ChromeShortcutProperties::PROPERTIES_ICON) { |
| 125 expected_properties.set_icon(properties.icon, 0); |
| 126 } else { |
| 127 int icon_index = dist->GetIconIndex(); |
| 128 expected_properties.set_icon(chrome_exe_, icon_index); |
| 129 } |
| 130 |
| 131 if (properties.options & |
| 132 ShellUtil::ChromeShortcutProperties::PROPERTIES_APP_ID) { |
| 133 expected_properties.set_app_id(properties.app_id); |
| 134 } else { |
| 135 // Tests are always seen as user-level installs in ShellUtil. |
| 136 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
| 137 } |
| 138 |
| 139 if (properties.options & |
| 140 ShellUtil::ChromeShortcutProperties::PROPERTIES_DUAL_MODE) { |
| 141 expected_properties.set_dual_mode(properties.dual_mode); |
| 142 } else { |
| 143 expected_properties.set_dual_mode(false); |
| 144 } |
| 145 |
| 146 base::win::ValidateShortcut(expected_path, expected_properties); |
| 147 } |
| 148 |
40 BrowserDistribution* dist_; | 149 BrowserDistribution* dist_; |
41 | 150 |
| 151 // A ChromeShortcutProperties object with common properties set already. |
| 152 scoped_ptr<ShellUtil::ChromeShortcutProperties> test_properties_; |
| 153 |
42 ScopedTempDir temp_dir_; | 154 ScopedTempDir temp_dir_; |
43 | |
44 ScopedTempDir fake_user_desktop_; | 155 ScopedTempDir fake_user_desktop_; |
45 ScopedTempDir fake_common_desktop_; | 156 ScopedTempDir fake_common_desktop_; |
| 157 ScopedTempDir fake_user_quick_launch_; |
| 158 ScopedTempDir fake_default_user_quick_launch_; |
| 159 ScopedTempDir fake_start_menu_; |
| 160 ScopedTempDir fake_common_start_menu_; |
| 161 |
| 162 FilePath chrome_exe_; |
46 }; | 163 }; |
47 | 164 |
48 // Calls base::win::ValidateShortcut for the properties passed in. | 165 } // namespace |
49 // TODO(gab): This is only temporary while waiting for my upcoming CL that will | 166 |
50 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't | 167 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { |
51 // want to adapt every test here for this half-changed state as they will change | 168 FilePath path; |
52 // again very soon). | 169 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist_, |
53 void ValidateChromeShortcut(const FilePath& exe_path, | 170 ShellUtil::CURRENT_USER, &path); |
54 const FilePath& shortcut_path, | 171 EXPECT_EQ(fake_user_desktop_.path(), path); |
55 const string16& description, | 172 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist_, |
56 int icon_index) { | 173 ShellUtil::SYSTEM_LEVEL, &path); |
57 base::win::ShortcutProperties expected_properties; | 174 EXPECT_EQ(fake_common_desktop_.path(), path); |
58 expected_properties.set_target(exe_path); | 175 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, |
59 expected_properties.set_description(description); | 176 ShellUtil::CURRENT_USER, &path); |
60 expected_properties.set_icon(exe_path, icon_index); | 177 EXPECT_EQ(fake_user_quick_launch_.path(), path); |
61 base::win::ValidateShortcut(shortcut_path, expected_properties); | 178 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, |
62 } | 179 ShellUtil::SYSTEM_LEVEL, &path); |
63 | 180 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); |
64 } | 181 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist_, |
65 | 182 ShellUtil::CURRENT_USER, &path); |
66 // Test that we can open archives successfully. | 183 EXPECT_EQ(fake_start_menu_.path().Append(dist_->GetAppShortCutName()), path); |
67 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { | 184 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist_, |
68 // Create an executable in test path by copying ourself to it. | 185 ShellUtil::SYSTEM_LEVEL, &path); |
69 wchar_t exe_full_path_str[MAX_PATH]; | 186 EXPECT_EQ(fake_common_start_menu_.path().Append(dist_->GetAppShortCutName()), |
70 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 187 path); |
71 FilePath exe_full_path(exe_full_path_str); | 188 } |
72 | 189 |
73 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 190 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { |
74 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 191 ShellUtil::ChromeShortcutProperties properties(ShellUtil::CURRENT_USER); |
75 | 192 properties.set_chrome_exe(chrome_exe_); |
76 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 193 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
77 const string16 description(L"dummy description"); | 194 ShellUtil::SHORTCUT_DESKTOP, dist_, properties, |
78 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 195 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
79 dist_, | 196 ValidateChromeShortcut(ShellUtil::SHORTCUT_DESKTOP, dist_, properties); |
80 exe_path.value(), | 197 } |
81 shortcut_path.value(), | 198 |
82 string16(), | 199 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { |
83 description, | 200 test_properties_->set_shortcut_name(L"Bobo le shortcut"); |
84 exe_path.value(), | 201 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
85 dist_->GetIconIndex(), | 202 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
86 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 203 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_, |
87 ValidateChromeShortcut(exe_path, shortcut_path, description, 0); | 204 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
88 | 205 ValidateChromeShortcut(ShellUtil::SHORTCUT_START_MENU, dist_, |
89 // Now specify an icon index in master prefs and make sure it works. | 206 *test_properties_); |
90 FilePath prefs_path = temp_dir_.path().AppendASCII( | 207 } |
91 installer::kDefaultMasterPrefs); | 208 |
92 std::ofstream file; | 209 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) { |
93 file.open(prefs_path.value().c_str()); | 210 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
94 ASSERT_TRUE(file.is_open()); | 211 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
95 file << | 212 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, *test_properties_, |
96 "{" | 213 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
97 " \"distribution\":{" | 214 |
98 " \"chrome_shortcut_icon_index\" : 1" | 215 ShellUtil::ChromeShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); |
99 " }" | 216 new_properties.set_chrome_exe(chrome_exe_); |
100 "}"; | 217 new_properties.set_description(L"New description"); |
101 file.close(); | 218 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
102 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); | 219 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, new_properties, |
103 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 220 ShellUtil::SHORTCUT_REPLACE_EXISTING)); |
104 dist_, | 221 |
105 exe_path.value(), | 222 // Expect the properties set in |new_properties| to be set as above and |
106 shortcut_path.value(), | 223 // properties that don't have a default value to be set back to their default |
107 string16(), | 224 // (as validated in ValidateChromeShortcut()) or unset if they don't . |
108 description, | 225 ShellUtil::ChromeShortcutProperties expected_properties(new_properties); |
109 exe_path.value(), | 226 expected_properties.set_arguments(string16()); |
110 dist_->GetIconIndex(), | 227 expected_properties.set_dual_mode(false); |
111 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 228 |
112 ValidateChromeShortcut(exe_path, shortcut_path, description, 1); | 229 ValidateChromeShortcut(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, |
113 | 230 expected_properties); |
114 // Now change only description to update shortcut and make sure icon index | 231 } |
115 // doesn't change. | 232 |
116 const string16 description2(L"dummy description 2"); | 233 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) { |
117 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, | 234 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
118 exe_path.value(), | 235 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, *test_properties_, |
119 shortcut_path.value(), | 236 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
120 string16(), | 237 |
121 description2, | 238 ShellUtil::ChromeShortcutProperties updated_properties( |
122 exe_path.value(), | 239 ShellUtil::CURRENT_USER); |
123 dist_->GetIconIndex(), | 240 updated_properties.set_arguments(L"--updated --arguments"); |
124 ShellUtil::SHORTCUT_NO_OPTIONS)); | 241 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
125 ValidateChromeShortcut(exe_path, shortcut_path, description2, 1); | 242 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, updated_properties, |
126 } | 243 ShellUtil::SHORTCUT_UPDATE_EXISTING)); |
127 | 244 |
128 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { | 245 // 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. | 246 // all other properties to remain unchanged. |
130 wchar_t exe_full_path_str[MAX_PATH]; | 247 ShellUtil::ChromeShortcutProperties expected_properties(*test_properties_); |
131 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 248 expected_properties.set_arguments(updated_properties.arguments); |
132 FilePath exe_full_path(exe_full_path_str); | 249 |
133 | 250 ValidateChromeShortcut(ShellUtil::SHORTCUT_QUICK_LAUNCH, dist_, |
134 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 251 expected_properties); |
135 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 252 } |
136 | 253 |
137 const string16 description(L"dummy description"); | 254 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { |
138 | 255 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
139 FilePath user_desktop_path; | 256 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
140 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); | 257 ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
141 FilePath system_desktop_path; | 258 ValidateChromeShortcut(ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_); |
142 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); | 259 } |
143 | 260 |
144 string16 shortcut_name; | 261 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { |
145 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, string16(), | 262 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
146 &shortcut_name)); | 263 |
147 | 264 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
148 string16 default_profile_shortcut_name; | 265 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
149 const string16 default_profile_user_name = L"Minsk"; | 266 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
150 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, | 267 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
151 default_profile_user_name, | 268 ASSERT_TRUE(file_util::PathExists( |
152 &default_profile_shortcut_name)); | 269 fake_common_desktop_.path().Append(shortcut_name))); |
153 | 270 |
154 string16 second_profile_shortcut_name; | 271 test_properties_->level = ShellUtil::CURRENT_USER; |
155 const string16 second_profile_user_name = L"Pinsk"; | 272 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
156 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, | 273 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
157 second_profile_user_name, | 274 ShellUtil::SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
158 &second_profile_shortcut_name)); | 275 ASSERT_FALSE(file_util::PathExists( |
159 | 276 fake_user_desktop_.path().Append(shortcut_name))); |
160 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); | 277 } |
161 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); | 278 |
162 FilePath default_profile_shortcut_path = user_desktop_path.Append( | 279 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { |
163 default_profile_shortcut_name); | 280 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
164 FilePath second_profile_shortcut_path = user_desktop_path.Append( | 281 |
165 second_profile_shortcut_name); | 282 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
166 | 283 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
167 // Test simple creation of a user-level shortcut. | 284 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
168 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 285 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
169 dist_, | 286 ASSERT_TRUE(file_util::PathExists( |
170 exe_path.value(), | 287 fake_common_desktop_.path().Append(shortcut_name))); |
171 description, | 288 |
172 string16(), | 289 test_properties_->level = ShellUtil::CURRENT_USER; |
173 string16(), | 290 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
174 exe_path.value(), | 291 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
175 dist_->GetIconIndex(), | 292 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
176 ShellUtil::CURRENT_USER, | 293 ASSERT_TRUE(file_util::PathExists( |
177 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 294 fake_user_desktop_.path().Append(shortcut_name))); |
178 ValidateChromeShortcut(exe_path, user_shortcut_path, description, 0); | 295 } |
179 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 296 |
180 dist_, | 297 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { |
181 ShellUtil::CURRENT_USER, | 298 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
182 ShellUtil::SHORTCUT_NO_OPTIONS)); | 299 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
183 | 300 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
184 // Test simple creation of a system-level shortcut. | 301 |
185 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 302 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
186 dist_, | 303 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
187 exe_path.value(), | 304 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
188 description, | 305 |
189 string16(), | 306 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut( |
190 string16(), | 307 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::CURRENT_USER, NULL)); |
191 exe_path.value(), | 308 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
192 dist_->GetIconIndex(), | 309 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
193 ShellUtil::SYSTEM_LEVEL, | 310 } |
194 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 311 |
195 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); | 312 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { |
196 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 313 test_properties_->level = ShellUtil::SYSTEM_LEVEL; |
197 dist_, | 314 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
198 ShellUtil::SYSTEM_LEVEL, | 315 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
199 ShellUtil::SHORTCUT_NO_OPTIONS)); | 316 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
200 | 317 |
201 // Test creation of a user-level shortcut when a system-level shortcut | 318 string16 shortcut_name(dist_->GetAppShortCutName() + installer::kLnkExt); |
202 // is already present (should fail). | 319 FilePath shortcut_path(fake_common_desktop_.path().Append(shortcut_name)); |
203 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 320 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
204 dist_, | 321 |
205 exe_path.value(), | 322 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut( |
206 description, | 323 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, NULL)); |
207 string16(), | 324 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
208 string16(), | 325 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
209 exe_path.value(), | 326 } |
210 dist_->GetIconIndex(), | 327 |
211 ShellUtil::SYSTEM_LEVEL, | 328 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcutWithSpecialName) { |
212 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 329 static const wchar_t kSpecialName[] = L"I'm special"; |
213 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( | 330 test_properties_->set_shortcut_name(kSpecialName); |
214 dist_, | 331 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
215 exe_path.value(), | 332 ShellUtil::SHORTCUT_DESKTOP, dist_, *test_properties_, |
216 description, | 333 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
217 string16(), | 334 |
218 string16(), | 335 string16 shortcut_name(string16(kSpecialName).append(installer::kLnkExt)); |
219 exe_path.value(), | 336 FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
220 dist_->GetIconIndex(), | 337 ASSERT_TRUE(file_util::PathExists(shortcut_path)); |
221 ShellUtil::CURRENT_USER, | 338 |
222 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 339 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut( |
223 ValidateChromeShortcut(exe_path, system_shortcut_path, description, 0); | 340 ShellUtil::SHORTCUT_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
224 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); | 341 &string16(kSpecialName))); |
225 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 342 ASSERT_FALSE(file_util::PathExists(shortcut_path)); |
226 dist_, | 343 ASSERT_TRUE(file_util::PathExists(shortcut_path.DirName())); |
227 ShellUtil::SYSTEM_LEVEL, | 344 } |
228 ShellUtil::SHORTCUT_NO_OPTIONS)); | 345 |
229 | 346 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
230 // Test creation of a system-level shortcut when a user-level shortcut | 347 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
231 // is already present (should succeed). | 348 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_, |
232 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 349 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
233 dist_, | 350 test_properties_->set_shortcut_name(L"A second shortcut"); |
234 exe_path.value(), | 351 ASSERT_TRUE(ShellUtil::CreateOrUpdateChromeShortcut( |
235 description, | 352 ShellUtil::SHORTCUT_START_MENU, dist_, *test_properties_, |
236 string16(), | 353 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
237 string16(), | 354 |
238 exe_path.value(), | 355 FilePath shortcut_folder( |
239 dist_->GetIconIndex(), | 356 fake_start_menu_.path().Append(dist_->GetAppShortCutName())); |
240 ShellUtil::CURRENT_USER, | 357 file_util::FileEnumerator file_counter (shortcut_folder, false, |
241 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 358 file_util::FileEnumerator::FILES); |
242 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 359 int count = 0; |
243 dist_, | 360 while (!file_counter.Next().empty()) |
244 exe_path.value(), | 361 ++count; |
245 description, | 362 EXPECT_EQ(2, count); |
246 string16(), | 363 |
247 string16(), | 364 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); |
248 exe_path.value(), | 365 ASSERT_TRUE(ShellUtil::RemoveChromeShortcut( |
249 dist_->GetIconIndex(), | 366 ShellUtil::SHORTCUT_START_MENU, dist_, ShellUtil::CURRENT_USER, NULL)); |
250 ShellUtil::SYSTEM_LEVEL, | 367 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 } | 368 } |
295 | 369 |
296 TEST(ShellUtilTest, BuildAppModelIdBasic) { | 370 TEST(ShellUtilTest, BuildAppModelIdBasic) { |
297 std::vector<string16> components; | 371 std::vector<string16> components; |
298 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 372 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
299 const string16 base_app_id(dist->GetBaseAppId()); | 373 const string16 base_app_id(dist->GetBaseAppId()); |
300 components.push_back(base_app_id); | 374 components.push_back(base_app_id); |
301 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 375 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
302 } | 376 } |
303 | 377 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 438 |
365 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 439 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
366 L"MZXW6YTB", L"MZXW6YTBOI"}; | 440 L"MZXW6YTB", L"MZXW6YTBOI"}; |
367 | 441 |
368 // Run the tests, with one more letter in the input every pass. | 442 // Run the tests, with one more letter in the input every pass. |
369 for (int i = 0; i < arraysize(expected); ++i) { | 443 for (int i = 0; i < arraysize(expected); ++i) { |
370 ASSERT_EQ(expected[i], | 444 ASSERT_EQ(expected[i], |
371 ShellUtil::ByteArrayToBase32(test_array, i)); | 445 ShellUtil::ByteArrayToBase32(test_array, i)); |
372 } | 446 } |
373 } | 447 } |
OLD | NEW |