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 "chrome/installer/util/shell_util.h" | 5 #include "chrome/installer/util/shell_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/base_paths_win.h" | 10 #include "base/base_paths_win.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); | 64 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); |
65 user_desktop_override_.reset( | 65 user_desktop_override_.reset( |
66 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, | 66 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, |
67 fake_user_desktop_.path())); | 67 fake_user_desktop_.path())); |
68 common_desktop_override_.reset( | 68 common_desktop_override_.reset( |
69 new base::ScopedPathOverride(base::DIR_COMMON_DESKTOP, | 69 new base::ScopedPathOverride(base::DIR_COMMON_DESKTOP, |
70 fake_common_desktop_.path())); | 70 fake_common_desktop_.path())); |
71 user_quick_launch_override_.reset( | 71 user_quick_launch_override_.reset( |
72 new base::ScopedPathOverride(base::DIR_USER_QUICK_LAUNCH, | 72 new base::ScopedPathOverride(base::DIR_USER_QUICK_LAUNCH, |
73 fake_user_quick_launch_.path())); | 73 fake_user_quick_launch_.path())); |
74 default_user_quick_launch_override_.reset( | |
75 new base::ScopedPathOverride(base::DIR_DEFAULT_USER_QUICK_LAUNCH, | |
76 fake_default_user_quick_launch_.path())); | |
77 start_menu_override_.reset( | 74 start_menu_override_.reset( |
78 new base::ScopedPathOverride(base::DIR_START_MENU, | 75 new base::ScopedPathOverride(base::DIR_START_MENU, |
79 fake_start_menu_.path())); | 76 fake_start_menu_.path())); |
80 common_start_menu_override_.reset( | 77 common_start_menu_override_.reset( |
81 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, | 78 new base::ScopedPathOverride(base::DIR_COMMON_START_MENU, |
82 fake_common_start_menu_.path())); | 79 fake_common_start_menu_.path())); |
83 | 80 |
84 base::FilePath icon_path; | 81 base::FilePath icon_path; |
85 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); | 82 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); |
86 test_properties_.set_target(chrome_exe_); | 83 test_properties_.set_target(chrome_exe_); |
(...skipping 10 matching lines...) Expand all Loading... |
97 ShellUtil::ShortcutLocation location, | 94 ShellUtil::ShortcutLocation location, |
98 BrowserDistribution* dist, | 95 BrowserDistribution* dist, |
99 const ShellUtil::ShortcutProperties& properties) { | 96 const ShellUtil::ShortcutProperties& properties) { |
100 base::FilePath expected_path; | 97 base::FilePath expected_path; |
101 switch (location) { | 98 switch (location) { |
102 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: | 99 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: |
103 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 100 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? |
104 fake_user_desktop_.path() : fake_common_desktop_.path(); | 101 fake_user_desktop_.path() : fake_common_desktop_.path(); |
105 break; | 102 break; |
106 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: | 103 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: |
107 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 104 expected_path = fake_user_quick_launch_.path(); |
108 fake_user_quick_launch_.path() : | |
109 fake_default_user_quick_launch_.path(); | |
110 break; | 105 break; |
111 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | 106 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: |
112 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? | 107 expected_path = (properties.level == ShellUtil::CURRENT_USER) ? |
113 fake_start_menu_.path() : fake_common_start_menu_.path(); | 108 fake_start_menu_.path() : fake_common_start_menu_.path(); |
114 expected_path = expected_path.Append( | 109 expected_path = expected_path.Append( |
115 dist_->GetStartMenuShortcutSubfolder( | 110 dist_->GetStartMenuShortcutSubfolder( |
116 BrowserDistribution::SUBFOLDER_CHROME)); | 111 BrowserDistribution::SUBFOLDER_CHROME)); |
117 break; | 112 break; |
118 default: | 113 default: |
119 ADD_FAILURE() << "Unknown location"; | 114 ADD_FAILURE() << "Unknown location"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 base::ScopedTempDir temp_dir_; | 183 base::ScopedTempDir temp_dir_; |
189 base::ScopedTempDir fake_user_desktop_; | 184 base::ScopedTempDir fake_user_desktop_; |
190 base::ScopedTempDir fake_common_desktop_; | 185 base::ScopedTempDir fake_common_desktop_; |
191 base::ScopedTempDir fake_user_quick_launch_; | 186 base::ScopedTempDir fake_user_quick_launch_; |
192 base::ScopedTempDir fake_default_user_quick_launch_; | 187 base::ScopedTempDir fake_default_user_quick_launch_; |
193 base::ScopedTempDir fake_start_menu_; | 188 base::ScopedTempDir fake_start_menu_; |
194 base::ScopedTempDir fake_common_start_menu_; | 189 base::ScopedTempDir fake_common_start_menu_; |
195 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 190 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
196 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 191 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
197 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 192 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
198 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; | |
199 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 193 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
200 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 194 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
201 | 195 |
202 base::FilePath chrome_exe_; | 196 base::FilePath chrome_exe_; |
203 base::FilePath manganese_exe_; | 197 base::FilePath manganese_exe_; |
204 base::FilePath iron_exe_; | 198 base::FilePath iron_exe_; |
205 base::FilePath other_ico_; | 199 base::FilePath other_ico_; |
206 }; | 200 }; |
207 | 201 |
208 } // namespace | 202 } // namespace |
209 | 203 |
210 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { | 204 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { |
211 base::FilePath path; | 205 base::FilePath path; |
| 206 |
212 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 207 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
213 ShellUtil::CURRENT_USER, &path); | 208 ShellUtil::CURRENT_USER, &path); |
214 EXPECT_EQ(fake_user_desktop_.path(), path); | 209 EXPECT_EQ(fake_user_desktop_.path(), path); |
| 210 |
215 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 211 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
216 ShellUtil::SYSTEM_LEVEL, &path); | 212 ShellUtil::SYSTEM_LEVEL, &path); |
217 EXPECT_EQ(fake_common_desktop_.path(), path); | 213 EXPECT_EQ(fake_common_desktop_.path(), path); |
| 214 |
218 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 215 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, |
219 ShellUtil::CURRENT_USER, &path); | 216 ShellUtil::CURRENT_USER, &path); |
220 EXPECT_EQ(fake_user_quick_launch_.path(), path); | 217 EXPECT_EQ(fake_user_quick_launch_.path(), path); |
221 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 218 |
222 ShellUtil::SYSTEM_LEVEL, &path); | |
223 EXPECT_EQ(fake_default_user_quick_launch_.path(), path); | |
224 base::string16 start_menu_subfolder = | 219 base::string16 start_menu_subfolder = |
225 dist_->GetStartMenuShortcutSubfolder( | 220 dist_->GetStartMenuShortcutSubfolder( |
226 BrowserDistribution::SUBFOLDER_CHROME); | 221 BrowserDistribution::SUBFOLDER_CHROME); |
227 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 222 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
228 dist_, ShellUtil::CURRENT_USER, &path); | 223 dist_, ShellUtil::CURRENT_USER, &path); |
229 EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder), | 224 EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder), |
230 path); | 225 path); |
| 226 |
231 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 227 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
232 dist_, ShellUtil::SYSTEM_LEVEL, &path); | 228 dist_, ShellUtil::SYSTEM_LEVEL, &path); |
233 EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder), | 229 EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder), |
234 path); | 230 path); |
235 } | 231 } |
236 | 232 |
237 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { | 233 TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) { |
238 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); | 234 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER); |
239 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); | 235 product_->AddDefaultShortcutProperties(chrome_exe_, &properties); |
240 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 236 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
241 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, | 237 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, properties, |
242 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 238 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
243 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 239 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
244 properties); | 240 properties); |
245 } | 241 } |
246 | 242 |
247 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { | 243 TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) { |
248 test_properties_.set_shortcut_name(L"Bobo le shortcut"); | 244 test_properties_.set_shortcut_name(L"Bobo le shortcut"); |
249 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 245 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
250 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 246 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
251 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 247 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
252 dist_, test_properties_, | 248 dist_, test_properties_, |
253 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 249 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
254 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 250 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
255 dist_, test_properties_); | 251 dist_, test_properties_); |
256 } | 252 } |
257 | 253 |
258 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelQuickLaunchShortcut) { | 254 TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelDesktopShortcut) { |
259 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 255 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
260 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 256 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
261 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 257 ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
262 dist_, test_properties_, | 258 dist_, test_properties_, |
263 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 259 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
264 | 260 |
265 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); | 261 ShellUtil::ShortcutProperties new_properties(ShellUtil::SYSTEM_LEVEL); |
266 product_->AddDefaultShortcutProperties(chrome_exe_, &new_properties); | 262 product_->AddDefaultShortcutProperties(chrome_exe_, &new_properties); |
267 new_properties.set_description(L"New description"); | 263 new_properties.set_description(L"New description"); |
268 new_properties.set_arguments(L"--new-arguments"); | 264 new_properties.set_arguments(L"--new-arguments"); |
269 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 265 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
270 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 266 ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
271 dist_, new_properties, | 267 dist_, new_properties, |
272 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING)); | 268 ShellUtil::SHELL_SHORTCUT_REPLACE_EXISTING)); |
273 | 269 |
274 // Expect the properties set in |new_properties| to be set as above and | 270 // Expect the properties set in |new_properties| to be set as above and |
275 // properties that don't have a default value to be set back to their default | 271 // properties that don't have a default value to be set back to their default |
276 // (as validated in ValidateChromeShortcut()) or unset if they don't . | 272 // (as validated in ValidateChromeShortcut()) or unset if they don't . |
277 ShellUtil::ShortcutProperties expected_properties(new_properties); | 273 ShellUtil::ShortcutProperties expected_properties(new_properties); |
278 expected_properties.set_dual_mode(false); | 274 expected_properties.set_dual_mode(false); |
279 | 275 |
280 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist_, | 276 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
281 expected_properties); | 277 expected_properties); |
282 } | 278 } |
283 | 279 |
284 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) { | 280 TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) { |
285 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 281 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
286 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, | 282 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
287 dist_, test_properties_, | 283 dist_, test_properties_, |
288 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 284 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
289 | 285 |
290 // Only changing one property, don't need all the defaults. | 286 // Only changing one property, don't need all the defaults. |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 864 |
869 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 865 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
870 L"MZXW6YTB", L"MZXW6YTBOI"}; | 866 L"MZXW6YTB", L"MZXW6YTBOI"}; |
871 | 867 |
872 // Run the tests, with one more letter in the input every pass. | 868 // Run the tests, with one more letter in the input every pass. |
873 for (int i = 0; i < arraysize(expected); ++i) { | 869 for (int i = 0; i < arraysize(expected); ++i) { |
874 ASSERT_EQ(expected[i], | 870 ASSERT_EQ(expected[i], |
875 ShellUtil::ByteArrayToBase32(test_array, i)); | 871 ShellUtil::ByteArrayToBase32(test_array, i)); |
876 } | 872 } |
877 } | 873 } |
OLD | NEW |