| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shellapi.h> | 6 #include <shellapi.h> |
| 7 #include <shlobj.h> | 7 #include <shlobj.h> |
| 8 | 8 |
| 9 #include <fstream> | 9 #include <fstream> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "base/string16.h" |
| 14 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.h" |
| 15 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
| 16 #include "chrome/installer/util/browser_distribution.h" | 18 #include "chrome/installer/util/browser_distribution.h" |
| 17 #include "chrome/installer/util/master_preferences.h" | 19 #include "chrome/installer/util/master_preferences.h" |
| 18 #include "chrome/installer/util/shell_util.h" | 20 #include "chrome/installer/util/shell_util.h" |
| 21 #include "chrome/installer/util/util_constants.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 bool VerifyChromeShortcut(const std::wstring& exe_path, | 25 bool VerifyChromeShortcut(const std::wstring& exe_path, |
| 23 const std::wstring& shortcut, | 26 const std::wstring& shortcut, |
| 24 const std::wstring& description, | 27 const std::wstring& description, |
| 25 int icon_index) { | 28 int icon_index) { |
| 26 base::win::ScopedComPtr<IShellLink> i_shell_link; | 29 base::win::ScopedComPtr<IShellLink> i_shell_link; |
| 27 base::win::ScopedComPtr<IPersistFile> i_persist_file; | 30 base::win::ScopedComPtr<IPersistFile> i_persist_file; |
| 28 | 31 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (failed) | 85 if (failed) |
| 83 return false; | 86 return false; |
| 84 | 87 |
| 85 return true; | 88 return true; |
| 86 } | 89 } |
| 87 | 90 |
| 88 class ShellUtilTest : public testing::Test { | 91 class ShellUtilTest : public testing::Test { |
| 89 protected: | 92 protected: |
| 90 virtual void SetUp() { | 93 virtual void SetUp() { |
| 91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 94 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 95 dist_ = BrowserDistribution::GetDistribution(); |
| 96 ASSERT_TRUE(dist_ != NULL); |
| 92 } | 97 } |
| 93 | 98 |
| 99 BrowserDistribution* dist_; |
| 100 |
| 94 ScopedTempDir temp_dir_; | 101 ScopedTempDir temp_dir_; |
| 95 }; | 102 }; |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 // Test that we can open archives successfully. | 105 // Test that we can open archives successfully. |
| 99 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { | 106 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { |
| 100 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 101 ASSERT_TRUE(dist != NULL); | |
| 102 // Create an executable in test path by copying ourself to it. | 107 // Create an executable in test path by copying ourself to it. |
| 103 wchar_t exe_full_path_str[MAX_PATH]; | 108 wchar_t exe_full_path_str[MAX_PATH]; |
| 104 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 109 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
| 105 FilePath exe_full_path(exe_full_path_str); | 110 FilePath exe_full_path(exe_full_path_str); |
| 106 | 111 |
| 107 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 112 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
| 108 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 113 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
| 109 | 114 |
| 110 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 115 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
| 111 const std::wstring description(L"dummy description"); | 116 const std::wstring description(L"dummy description"); |
| 112 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 117 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
| 113 dist, | 118 dist_, |
| 114 exe_path.value(), | 119 exe_path.value(), |
| 115 shortcut_path.value(), | 120 shortcut_path.value(), |
| 116 L"", | 121 L"", |
| 117 description, | 122 description, |
| 118 exe_path.value(), | 123 exe_path.value(), |
| 119 dist->GetIconIndex(), | 124 dist_->GetIconIndex(), |
| 120 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 125 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 121 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 126 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 122 shortcut_path.value(), | 127 shortcut_path.value(), |
| 123 description, 0)); | 128 description, 0)); |
| 124 | 129 |
| 125 // Now specify an icon index in master prefs and make sure it works. | 130 // Now specify an icon index in master prefs and make sure it works. |
| 126 FilePath prefs_path = temp_dir_.path().AppendASCII( | 131 FilePath prefs_path = temp_dir_.path().AppendASCII( |
| 127 installer::kDefaultMasterPrefs); | 132 installer::kDefaultMasterPrefs); |
| 128 std::ofstream file; | 133 std::ofstream file; |
| 129 file.open(prefs_path.value().c_str()); | 134 file.open(prefs_path.value().c_str()); |
| 130 ASSERT_TRUE(file.is_open()); | 135 ASSERT_TRUE(file.is_open()); |
| 131 file << | 136 file << |
| 132 "{" | 137 "{" |
| 133 " \"distribution\":{" | 138 " \"distribution\":{" |
| 134 " \"chrome_shortcut_icon_index\" : 1" | 139 " \"chrome_shortcut_icon_index\" : 1" |
| 135 " }" | 140 " }" |
| 136 "}"; | 141 "}"; |
| 137 file.close(); | 142 file.close(); |
| 138 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); | 143 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); |
| 139 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 144 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
| 140 dist, | 145 dist_, |
| 141 exe_path.value(), | 146 exe_path.value(), |
| 142 shortcut_path.value(), | 147 shortcut_path.value(), |
| 143 L"", | 148 L"", |
| 144 description, | 149 description, |
| 145 exe_path.value(), | 150 exe_path.value(), |
| 146 dist->GetIconIndex(), | 151 dist_->GetIconIndex(), |
| 147 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 152 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 148 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 153 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 149 shortcut_path.value(), | 154 shortcut_path.value(), |
| 150 description, 1)); | 155 description, 1)); |
| 151 | 156 |
| 152 // Now change only description to update shortcut and make sure icon index | 157 // Now change only description to update shortcut and make sure icon index |
| 153 // doesn't change. | 158 // doesn't change. |
| 154 const std::wstring description2(L"dummy description 2"); | 159 const std::wstring description2(L"dummy description 2"); |
| 155 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, | 160 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, |
| 156 exe_path.value(), | 161 exe_path.value(), |
| 157 shortcut_path.value(), | 162 shortcut_path.value(), |
| 158 L"", | 163 L"", |
| 159 description2, | 164 description2, |
| 160 exe_path.value(), | 165 exe_path.value(), |
| 161 dist->GetIconIndex(), | 166 dist_->GetIconIndex(), |
| 162 ShellUtil::SHORTCUT_NO_OPTIONS)); | 167 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 163 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 168 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 164 shortcut_path.value(), | 169 shortcut_path.value(), |
| 165 description2, 1)); | 170 description2, 1)); |
| 166 } | 171 } |
| 167 | 172 |
| 168 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { | 173 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { |
| 169 // Run this test on Vista+ only if we are running elevated. | 174 // Run this test on Vista+ only if we are running elevated. |
| 170 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | 175 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { |
| 171 LOG(ERROR) << "Must be admin to run this test on Vista+"; | 176 LOG(ERROR) << "Must be admin to run this test on Vista+"; |
| 172 return; | 177 return; |
| 173 } | 178 } |
| 174 | 179 |
| 175 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 176 ASSERT_TRUE(dist != NULL); | |
| 177 // Create an executable in test path by copying ourself to it. | 180 // Create an executable in test path by copying ourself to it. |
| 178 wchar_t exe_full_path_str[MAX_PATH]; | 181 wchar_t exe_full_path_str[MAX_PATH]; |
| 179 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 182 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
| 180 FilePath exe_full_path(exe_full_path_str); | 183 FilePath exe_full_path(exe_full_path_str); |
| 181 | 184 |
| 182 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 185 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
| 183 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 186 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
| 184 | 187 |
| 185 const std::wstring description(L"dummy description"); | 188 const std::wstring description(L"dummy description"); |
| 186 | 189 |
| 187 FilePath user_desktop_path; | 190 FilePath user_desktop_path; |
| 188 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); | 191 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); |
| 189 FilePath system_desktop_path; | 192 FilePath system_desktop_path; |
| 190 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); | 193 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); |
| 191 | 194 |
| 192 std::wstring shortcut_name; | 195 std::wstring shortcut_name; |
| 193 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, L"", | 196 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"", |
| 194 &shortcut_name)); | 197 &shortcut_name)); |
| 195 | 198 |
| 196 std::wstring default_profile_shortcut_name; | 199 std::wstring default_profile_shortcut_name; |
| 197 const std::wstring default_profile_user_name = L"Minsk"; | 200 const std::wstring default_profile_user_name = L"Minsk"; |
| 198 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, | 201 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, |
| 199 default_profile_user_name, | 202 default_profile_user_name, |
| 200 &default_profile_shortcut_name)); | 203 &default_profile_shortcut_name)); |
| 201 | 204 |
| 202 std::wstring second_profile_shortcut_name; | 205 std::wstring second_profile_shortcut_name; |
| 203 const std::wstring second_profile_user_name = L"Pinsk"; | 206 const std::wstring second_profile_user_name = L"Pinsk"; |
| 204 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, | 207 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, |
| 205 second_profile_user_name, | 208 second_profile_user_name, |
| 206 &second_profile_shortcut_name)); | 209 &second_profile_shortcut_name)); |
| 207 | 210 |
| 208 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); | 211 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); |
| 209 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); | 212 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); |
| 210 FilePath default_profile_shortcut_path = user_desktop_path.Append( | 213 FilePath default_profile_shortcut_path = user_desktop_path.Append( |
| 211 default_profile_shortcut_name); | 214 default_profile_shortcut_name); |
| 212 FilePath second_profile_shortcut_path = user_desktop_path.Append( | 215 FilePath second_profile_shortcut_path = user_desktop_path.Append( |
| 213 second_profile_shortcut_name); | 216 second_profile_shortcut_name); |
| 214 | 217 |
| 215 // Test simple creation of a user-level shortcut. | 218 // Test simple creation of a user-level shortcut. |
| 216 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 219 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 217 dist, | 220 dist_, |
| 218 exe_path.value(), | 221 exe_path.value(), |
| 219 description, | 222 description, |
| 220 L"", | 223 L"", |
| 221 L"", | 224 L"", |
| 222 exe_path.value(), | 225 exe_path.value(), |
| 223 dist->GetIconIndex(), | 226 dist_->GetIconIndex(), |
| 224 ShellUtil::CURRENT_USER, | 227 ShellUtil::CURRENT_USER, |
| 225 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 228 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 226 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 229 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 227 user_shortcut_path.value(), | 230 user_shortcut_path.value(), |
| 228 description, | 231 description, |
| 229 0)); | 232 0)); |
| 230 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 233 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 231 dist, | 234 dist_, |
| 232 ShellUtil::CURRENT_USER, | 235 ShellUtil::CURRENT_USER, |
| 233 ShellUtil::SHORTCUT_NO_OPTIONS)); | 236 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 234 | 237 |
| 235 // Test simple creation of a system-level shortcut. | 238 // Test simple creation of a system-level shortcut. |
| 236 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 239 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 237 dist, | 240 dist_, |
| 238 exe_path.value(), | 241 exe_path.value(), |
| 239 description, | 242 description, |
| 240 L"", | 243 L"", |
| 241 L"", | 244 L"", |
| 242 exe_path.value(), | 245 exe_path.value(), |
| 243 dist->GetIconIndex(), | 246 dist_->GetIconIndex(), |
| 244 ShellUtil::SYSTEM_LEVEL, | 247 ShellUtil::SYSTEM_LEVEL, |
| 245 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 248 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 246 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 249 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 247 system_shortcut_path.value(), | 250 system_shortcut_path.value(), |
| 248 description, | 251 description, |
| 249 0)); | 252 0)); |
| 250 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 253 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 251 dist, | 254 dist_, |
| 252 ShellUtil::SYSTEM_LEVEL, | 255 ShellUtil::SYSTEM_LEVEL, |
| 253 ShellUtil::SHORTCUT_NO_OPTIONS)); | 256 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 254 | 257 |
| 255 // Test creation of a user-level shortcut when a system-level shortcut | 258 // Test creation of a user-level shortcut when a system-level shortcut |
| 256 // is already present (should fail). | 259 // is already present (should fail). |
| 257 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 260 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 258 dist, | 261 dist_, |
| 259 exe_path.value(), | 262 exe_path.value(), |
| 260 description, | 263 description, |
| 261 L"", | 264 L"", |
| 262 L"", | 265 L"", |
| 263 exe_path.value(), | 266 exe_path.value(), |
| 264 dist->GetIconIndex(), | 267 dist_->GetIconIndex(), |
| 265 ShellUtil::SYSTEM_LEVEL, | 268 ShellUtil::SYSTEM_LEVEL, |
| 266 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 269 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 267 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( | 270 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( |
| 268 dist, | 271 dist_, |
| 269 exe_path.value(), | 272 exe_path.value(), |
| 270 description, | 273 description, |
| 271 L"", | 274 L"", |
| 272 L"", | 275 L"", |
| 273 exe_path.value(), | 276 exe_path.value(), |
| 274 dist->GetIconIndex(), | 277 dist_->GetIconIndex(), |
| 275 ShellUtil::CURRENT_USER, | 278 ShellUtil::CURRENT_USER, |
| 276 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 279 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 277 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 280 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 278 system_shortcut_path.value(), | 281 system_shortcut_path.value(), |
| 279 description, | 282 description, |
| 280 0)); | 283 0)); |
| 281 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); | 284 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); |
| 282 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 285 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 283 dist, | 286 dist_, |
| 284 ShellUtil::SYSTEM_LEVEL, | 287 ShellUtil::SYSTEM_LEVEL, |
| 285 ShellUtil::SHORTCUT_NO_OPTIONS)); | 288 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 286 | 289 |
| 287 // Test creation of a system-level shortcut when a user-level shortcut | 290 // Test creation of a system-level shortcut when a user-level shortcut |
| 288 // is already present (should succeed). | 291 // is already present (should succeed). |
| 289 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 292 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 290 dist, | 293 dist_, |
| 291 exe_path.value(), | 294 exe_path.value(), |
| 292 description, | 295 description, |
| 293 L"", | 296 L"", |
| 294 L"", | 297 L"", |
| 295 exe_path.value(), | 298 exe_path.value(), |
| 296 dist->GetIconIndex(), | 299 dist_->GetIconIndex(), |
| 297 ShellUtil::CURRENT_USER, | 300 ShellUtil::CURRENT_USER, |
| 298 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 301 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 299 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 302 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 300 dist, | 303 dist_, |
| 301 exe_path.value(), | 304 exe_path.value(), |
| 302 description, | 305 description, |
| 303 L"", | 306 L"", |
| 304 L"", | 307 L"", |
| 305 exe_path.value(), | 308 exe_path.value(), |
| 306 dist->GetIconIndex(), | 309 dist_->GetIconIndex(), |
| 307 ShellUtil::SYSTEM_LEVEL, | 310 ShellUtil::SYSTEM_LEVEL, |
| 308 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 311 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 309 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 312 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 310 user_shortcut_path.value(), | 313 user_shortcut_path.value(), |
| 311 description, | 314 description, |
| 312 0)); | 315 0)); |
| 313 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 316 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 314 system_shortcut_path.value(), | 317 system_shortcut_path.value(), |
| 315 description, | 318 description, |
| 316 0)); | 319 0)); |
| 317 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 320 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 318 dist, | 321 dist_, |
| 319 ShellUtil::CURRENT_USER, | 322 ShellUtil::CURRENT_USER, |
| 320 ShellUtil::SHORTCUT_NO_OPTIONS)); | 323 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 321 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 324 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 322 dist, | 325 dist_, |
| 323 ShellUtil::SYSTEM_LEVEL, | 326 ShellUtil::SYSTEM_LEVEL, |
| 324 ShellUtil::SHORTCUT_NO_OPTIONS)); | 327 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 325 | 328 |
| 326 // Test creation of two profile-specific shortcuts (these are always | 329 // Test creation of two profile-specific shortcuts (these are always |
| 327 // user-level). | 330 // user-level). |
| 328 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 331 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 329 dist, | 332 dist_, |
| 330 exe_path.value(), | 333 exe_path.value(), |
| 331 description, | 334 description, |
| 332 default_profile_user_name, | 335 default_profile_user_name, |
| 333 L"--profile-directory=\"Default\"", | 336 L"--profile-directory=\"Default\"", |
| 334 exe_path.value(), | 337 exe_path.value(), |
| 335 dist->GetIconIndex(), | 338 dist_->GetIconIndex(), |
| 336 ShellUtil::CURRENT_USER, | 339 ShellUtil::CURRENT_USER, |
| 337 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 340 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 338 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 341 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 339 default_profile_shortcut_path.value(), | 342 default_profile_shortcut_path.value(), |
| 340 description, | 343 description, |
| 341 0)); | 344 0)); |
| 342 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 345 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 343 dist, | 346 dist_, |
| 344 exe_path.value(), | 347 exe_path.value(), |
| 345 description, | 348 description, |
| 346 second_profile_user_name, | 349 second_profile_user_name, |
| 347 L"--profile-directory=\"Profile 1\"", | 350 L"--profile-directory=\"Profile 1\"", |
| 348 exe_path.value(), | 351 exe_path.value(), |
| 349 dist->GetIconIndex(), | 352 dist_->GetIconIndex(), |
| 350 ShellUtil::CURRENT_USER, | 353 ShellUtil::CURRENT_USER, |
| 351 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 354 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 352 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 355 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
| 353 second_profile_shortcut_path.value(), | 356 second_profile_shortcut_path.value(), |
| 354 description, | 357 description, |
| 355 0)); | 358 0)); |
| 356 std::vector<string16> profile_names; | 359 std::vector<string16> profile_names; |
| 357 profile_names.push_back(default_profile_shortcut_name); | 360 profile_names.push_back(default_profile_shortcut_name); |
| 358 profile_names.push_back(second_profile_shortcut_name); | 361 profile_names.push_back(second_profile_shortcut_name); |
| 359 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 362 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
| 360 profile_names)); | 363 profile_names)); |
| 361 } | 364 } |
| 365 |
| 366 TEST_F(ShellUtilTest, BuildAppModelIdBasic) { |
| 367 std::vector<string16> components; |
| 368 const string16 base_app_id(dist_->GetBaseAppId()); |
| 369 components.push_back(base_app_id); |
| 370 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
| 371 } |
| 372 |
| 373 TEST_F(ShellUtilTest, BuildAppModelIdManySmall) { |
| 374 std::vector<string16> components; |
| 375 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); |
| 376 components.push_back(suffixed_app_id); |
| 377 components.push_back(L"Default"); |
| 378 components.push_back(L"Test"); |
| 379 ASSERT_EQ(suffixed_app_id + L".Default.Test", |
| 380 ShellUtil::BuildAppModelId(components)); |
| 381 } |
| 382 |
| 383 TEST_F(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { |
| 384 std::vector<string16> components; |
| 385 const string16 long_appname( |
| 386 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
| 387 L"that_goes_over_64_characters"); |
| 388 components.push_back(long_appname); |
| 389 components.push_back(L"Default"); |
| 390 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", |
| 391 ShellUtil::BuildAppModelId(components)); |
| 392 } |
| 393 |
| 394 TEST_F(ShellUtilTest, BuildAppModelIdLongEverything) { |
| 395 std::vector<string16> components; |
| 396 const string16 long_appname( |
| 397 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
| 398 L"that_goes_over_64_characters"); |
| 399 components.push_back(long_appname); |
| 400 components.push_back( |
| 401 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); |
| 402 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); |
| 403 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); |
| 404 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", |
| 405 constructed_app_id); |
| 406 } |
| OLD | NEW |