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