| 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> | |
| 6 #include <shellapi.h> | |
| 7 #include <shlobj.h> | 5 #include <shlobj.h> |
| 8 | 6 |
| 9 #include <fstream> | 7 #include <fstream> |
| 10 #include <vector> | 8 #include <vector> |
| 11 | 9 |
| 12 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 14 #include "base/md5.h" | 12 #include "base/md5.h" |
| 15 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 16 #include "base/string16.h" | 14 #include "base/string16.h" |
| 17 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 18 #include "base/win/scoped_comptr.h" | |
| 19 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 20 #include "chrome/installer/util/browser_distribution.h" | 17 #include "chrome/installer/util/browser_distribution.h" |
| 21 #include "chrome/installer/util/master_preferences.h" | 18 #include "chrome/installer/util/master_preferences.h" |
| 22 #include "chrome/installer/util/shell_util.h" | 19 #include "chrome/installer/util/shell_util.h" |
| 23 #include "chrome/installer/util/util_constants.h" | 20 #include "chrome/installer/util/util_constants.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 22 |
| 26 namespace { | 23 namespace { |
| 27 bool VerifyChromeShortcut(const std::wstring& exe_path, | |
| 28 const std::wstring& shortcut, | |
| 29 const std::wstring& description, | |
| 30 int icon_index) { | |
| 31 base::win::ScopedComPtr<IShellLink> i_shell_link; | |
| 32 base::win::ScopedComPtr<IPersistFile> i_persist_file; | |
| 33 | |
| 34 // Get pointer to the IShellLink interface | |
| 35 bool failed = FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, | |
| 36 CLSCTX_INPROC_SERVER)); | |
| 37 EXPECT_FALSE(failed) << "Failed to get IShellLink"; | |
| 38 if (failed) | |
| 39 return false; | |
| 40 | |
| 41 // Query IShellLink for the IPersistFile interface | |
| 42 failed = FAILED(i_persist_file.QueryFrom(i_shell_link)); | |
| 43 EXPECT_FALSE(failed) << "Failed to get IPersistFile"; | |
| 44 if (failed) | |
| 45 return false; | |
| 46 | |
| 47 failed = FAILED(i_persist_file->Load(shortcut.c_str(), 0)); | |
| 48 EXPECT_FALSE(failed) << "Failed to load shortcut " << shortcut.c_str(); | |
| 49 if (failed) | |
| 50 return false; | |
| 51 | |
| 52 wchar_t long_path[MAX_PATH] = {0}; | |
| 53 wchar_t short_path[MAX_PATH] = {0}; | |
| 54 failed = ((::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0) || | |
| 55 (::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0)); | |
| 56 EXPECT_FALSE(failed) << "Failed to get long and short path names for " | |
| 57 << exe_path; | |
| 58 if (failed) | |
| 59 return false; | |
| 60 | |
| 61 wchar_t file_path[MAX_PATH] = {0}; | |
| 62 failed = ((FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL, | |
| 63 SLGP_UNCPRIORITY))) || | |
| 64 ((FilePath(file_path) != FilePath(long_path)) && | |
| 65 (FilePath(file_path) != FilePath(short_path)))); | |
| 66 EXPECT_FALSE(failed) << "File path " << file_path << " did not match with " | |
| 67 << exe_path; | |
| 68 if (failed) | |
| 69 return false; | |
| 70 | |
| 71 wchar_t desc[MAX_PATH] = {0}; | |
| 72 failed = ((FAILED(i_shell_link->GetDescription(desc, MAX_PATH))) || | |
| 73 (std::wstring(desc) != std::wstring(description))); | |
| 74 EXPECT_FALSE(failed) << "Description " << desc << " did not match with " | |
| 75 << description; | |
| 76 if (failed) | |
| 77 return false; | |
| 78 | |
| 79 wchar_t icon_path[MAX_PATH] = {0}; | |
| 80 int index = 0; | |
| 81 failed = ((FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH, | |
| 82 &index))) || | |
| 83 ((FilePath(file_path) != FilePath(long_path)) && | |
| 84 (FilePath(file_path) != FilePath(short_path))) || | |
| 85 (index != icon_index)); | |
| 86 EXPECT_FALSE(failed); | |
| 87 if (failed) | |
| 88 return false; | |
| 89 | |
| 90 return true; | |
| 91 } | |
| 92 | 24 |
| 93 class ShellUtilTestWithDirAndDist : public testing::Test { | 25 class ShellUtilTestWithDirAndDist : public testing::Test { |
| 94 protected: | 26 protected: |
| 95 virtual void SetUp() { | 27 virtual void SetUp() { |
| 96 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 97 dist_ = BrowserDistribution::GetDistribution(); | 29 dist_ = BrowserDistribution::GetDistribution(); |
| 98 ASSERT_TRUE(dist_ != NULL); | 30 ASSERT_TRUE(dist_ != NULL); |
| 99 } | 31 } |
| 100 | 32 |
| 101 BrowserDistribution* dist_; | 33 BrowserDistribution* dist_; |
| 102 | 34 |
| 103 ScopedTempDir temp_dir_; | 35 ScopedTempDir temp_dir_; |
| 104 }; | 36 }; |
| 105 }; | 37 |
| 38 } |
| 106 | 39 |
| 107 // Test that we can open archives successfully. | 40 // Test that we can open archives successfully. |
| 108 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { | 41 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { |
| 109 // Create an executable in test path by copying ourself to it. | 42 // Create an executable in test path by copying ourself to it. |
| 110 wchar_t exe_full_path_str[MAX_PATH]; | 43 wchar_t exe_full_path_str[MAX_PATH]; |
| 111 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 44 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
| 112 FilePath exe_full_path(exe_full_path_str); | 45 FilePath exe_full_path(exe_full_path_str); |
| 113 | 46 |
| 114 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 47 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
| 115 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 48 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
| 116 | 49 |
| 117 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 50 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
| 118 const std::wstring description(L"dummy description"); | 51 const string16 description(L"dummy description"); |
| 119 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 52 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
| 120 dist_, | 53 dist_, |
| 121 exe_path.value(), | 54 exe_path.value(), |
| 122 shortcut_path.value(), | 55 shortcut_path.value(), |
| 123 L"", | 56 L"", |
| 124 description, | 57 description, |
| 125 exe_path.value(), | 58 exe_path.value(), |
| 126 dist_->GetIconIndex(), | 59 dist_->GetIconIndex(), |
| 127 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 60 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 128 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 61 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 129 shortcut_path.value(), | 62 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 130 description, 0)); | 63 shortcut_path.value(), description, 0)); |
| 131 | 64 |
| 132 // Now specify an icon index in master prefs and make sure it works. | 65 // Now specify an icon index in master prefs and make sure it works. |
| 133 FilePath prefs_path = temp_dir_.path().AppendASCII( | 66 FilePath prefs_path = temp_dir_.path().AppendASCII( |
| 134 installer::kDefaultMasterPrefs); | 67 installer::kDefaultMasterPrefs); |
| 135 std::ofstream file; | 68 std::ofstream file; |
| 136 file.open(prefs_path.value().c_str()); | 69 file.open(prefs_path.value().c_str()); |
| 137 ASSERT_TRUE(file.is_open()); | 70 ASSERT_TRUE(file.is_open()); |
| 138 file << | 71 file << |
| 139 "{" | 72 "{" |
| 140 " \"distribution\":{" | 73 " \"distribution\":{" |
| 141 " \"chrome_shortcut_icon_index\" : 1" | 74 " \"chrome_shortcut_icon_index\" : 1" |
| 142 " }" | 75 " }" |
| 143 "}"; | 76 "}"; |
| 144 file.close(); | 77 file.close(); |
| 145 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); | 78 ASSERT_TRUE(file_util::Delete(shortcut_path, false)); |
| 146 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( | 79 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut( |
| 147 dist_, | 80 dist_, |
| 148 exe_path.value(), | 81 exe_path.value(), |
| 149 shortcut_path.value(), | 82 shortcut_path.value(), |
| 150 L"", | 83 L"", |
| 151 description, | 84 description, |
| 152 exe_path.value(), | 85 exe_path.value(), |
| 153 dist_->GetIconIndex(), | 86 dist_->GetIconIndex(), |
| 154 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 87 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 155 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 88 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 156 shortcut_path.value(), | 89 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 157 description, 1)); | 90 shortcut_path.value(), description, 1)); |
| 158 | 91 |
| 159 // Now change only description to update shortcut and make sure icon index | 92 // Now change only description to update shortcut and make sure icon index |
| 160 // doesn't change. | 93 // doesn't change. |
| 161 const std::wstring description2(L"dummy description 2"); | 94 const string16 description2(L"dummy description 2"); |
| 162 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, | 95 EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist_, |
| 163 exe_path.value(), | 96 exe_path.value(), |
| 164 shortcut_path.value(), | 97 shortcut_path.value(), |
| 165 L"", | 98 L"", |
| 166 description2, | 99 description2, |
| 167 exe_path.value(), | 100 exe_path.value(), |
| 168 dist_->GetIconIndex(), | 101 dist_->GetIconIndex(), |
| 169 ShellUtil::SHORTCUT_NO_OPTIONS)); | 102 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 170 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 103 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 171 shortcut_path.value(), | 104 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 172 description2, 1)); | 105 shortcut_path.value(), description2, 1)); |
| 173 } | 106 } |
| 174 | 107 |
| 175 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { | 108 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { |
| 176 // Run this test on Vista+ only if we are running elevated. | 109 // Run this test on Vista+ only if we are running elevated. |
| 177 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | 110 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { |
| 178 LOG(ERROR) << "Must be admin to run this test on Vista+"; | 111 LOG(ERROR) << "Must be admin to run this test on Vista+"; |
| 179 return; | 112 return; |
| 180 } | 113 } |
| 181 | 114 |
| 182 // Create an executable in test path by copying ourself to it. | 115 // Create an executable in test path by copying ourself to it. |
| 183 wchar_t exe_full_path_str[MAX_PATH]; | 116 wchar_t exe_full_path_str[MAX_PATH]; |
| 184 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 117 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
| 185 FilePath exe_full_path(exe_full_path_str); | 118 FilePath exe_full_path(exe_full_path_str); |
| 186 | 119 |
| 187 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 120 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
| 188 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 121 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
| 189 | 122 |
| 190 const std::wstring description(L"dummy description"); | 123 const string16 description(L"dummy description"); |
| 191 | 124 |
| 192 FilePath user_desktop_path; | 125 FilePath user_desktop_path; |
| 193 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); | 126 EXPECT_TRUE(ShellUtil::GetDesktopPath(false, &user_desktop_path)); |
| 194 FilePath system_desktop_path; | 127 FilePath system_desktop_path; |
| 195 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); | 128 EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); |
| 196 | 129 |
| 197 std::wstring shortcut_name; | 130 string16 shortcut_name; |
| 198 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"", | 131 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, L"", |
| 199 &shortcut_name)); | 132 &shortcut_name)); |
| 200 | 133 |
| 201 std::wstring default_profile_shortcut_name; | 134 string16 default_profile_shortcut_name; |
| 202 const std::wstring default_profile_user_name = L"Minsk"; | 135 const string16 default_profile_user_name = L"Minsk"; |
| 203 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, | 136 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, |
| 204 default_profile_user_name, | 137 default_profile_user_name, |
| 205 &default_profile_shortcut_name)); | 138 &default_profile_shortcut_name)); |
| 206 | 139 |
| 207 std::wstring second_profile_shortcut_name; | 140 string16 second_profile_shortcut_name; |
| 208 const std::wstring second_profile_user_name = L"Pinsk"; | 141 const string16 second_profile_user_name = L"Pinsk"; |
| 209 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, | 142 EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist_, false, |
| 210 second_profile_user_name, | 143 second_profile_user_name, |
| 211 &second_profile_shortcut_name)); | 144 &second_profile_shortcut_name)); |
| 212 | 145 |
| 213 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); | 146 FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); |
| 214 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); | 147 FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); |
| 215 FilePath default_profile_shortcut_path = user_desktop_path.Append( | 148 FilePath default_profile_shortcut_path = user_desktop_path.Append( |
| 216 default_profile_shortcut_name); | 149 default_profile_shortcut_name); |
| 217 FilePath second_profile_shortcut_path = user_desktop_path.Append( | 150 FilePath second_profile_shortcut_path = user_desktop_path.Append( |
| 218 second_profile_shortcut_name); | 151 second_profile_shortcut_name); |
| 219 | 152 |
| 220 // Test simple creation of a user-level shortcut. | 153 // Test simple creation of a user-level shortcut. |
| 221 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 154 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 222 dist_, | 155 dist_, |
| 223 exe_path.value(), | 156 exe_path.value(), |
| 224 description, | 157 description, |
| 225 L"", | 158 L"", |
| 226 L"", | 159 L"", |
| 227 exe_path.value(), | 160 exe_path.value(), |
| 228 dist_->GetIconIndex(), | 161 dist_->GetIconIndex(), |
| 229 ShellUtil::CURRENT_USER, | 162 ShellUtil::CURRENT_USER, |
| 230 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 163 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 231 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 164 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 232 user_shortcut_path.value(), | 165 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 233 description, | 166 user_shortcut_path.value(), description, 0)); |
| 234 0)); | |
| 235 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 167 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 236 dist_, | 168 dist_, |
| 237 ShellUtil::CURRENT_USER, | 169 ShellUtil::CURRENT_USER, |
| 238 ShellUtil::SHORTCUT_NO_OPTIONS)); | 170 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 239 | 171 |
| 240 // Test simple creation of a system-level shortcut. | 172 // Test simple creation of a system-level shortcut. |
| 241 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 173 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 242 dist_, | 174 dist_, |
| 243 exe_path.value(), | 175 exe_path.value(), |
| 244 description, | 176 description, |
| 245 L"", | 177 L"", |
| 246 L"", | 178 L"", |
| 247 exe_path.value(), | 179 exe_path.value(), |
| 248 dist_->GetIconIndex(), | 180 dist_->GetIconIndex(), |
| 249 ShellUtil::SYSTEM_LEVEL, | 181 ShellUtil::SYSTEM_LEVEL, |
| 250 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 182 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 251 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 183 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 252 system_shortcut_path.value(), | 184 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 253 description, | 185 system_shortcut_path.value(), description, 0)); |
| 254 0)); | |
| 255 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 186 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 256 dist_, | 187 dist_, |
| 257 ShellUtil::SYSTEM_LEVEL, | 188 ShellUtil::SYSTEM_LEVEL, |
| 258 ShellUtil::SHORTCUT_NO_OPTIONS)); | 189 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 259 | 190 |
| 260 // Test creation of a user-level shortcut when a system-level shortcut | 191 // Test creation of a user-level shortcut when a system-level shortcut |
| 261 // is already present (should fail). | 192 // is already present (should fail). |
| 262 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 193 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 263 dist_, | 194 dist_, |
| 264 exe_path.value(), | 195 exe_path.value(), |
| 265 description, | 196 description, |
| 266 L"", | 197 L"", |
| 267 L"", | 198 L"", |
| 268 exe_path.value(), | 199 exe_path.value(), |
| 269 dist_->GetIconIndex(), | 200 dist_->GetIconIndex(), |
| 270 ShellUtil::SYSTEM_LEVEL, | 201 ShellUtil::SYSTEM_LEVEL, |
| 271 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 202 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 272 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( | 203 EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut( |
| 273 dist_, | 204 dist_, |
| 274 exe_path.value(), | 205 exe_path.value(), |
| 275 description, | 206 description, |
| 276 L"", | 207 L"", |
| 277 L"", | 208 L"", |
| 278 exe_path.value(), | 209 exe_path.value(), |
| 279 dist_->GetIconIndex(), | 210 dist_->GetIconIndex(), |
| 280 ShellUtil::CURRENT_USER, | 211 ShellUtil::CURRENT_USER, |
| 281 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 212 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 282 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 213 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 283 system_shortcut_path.value(), | 214 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 284 description, | 215 system_shortcut_path.value(), description, 0)); |
| 285 0)); | |
| 286 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); | 216 EXPECT_FALSE(file_util::PathExists(user_shortcut_path)); |
| 287 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 217 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 288 dist_, | 218 dist_, |
| 289 ShellUtil::SYSTEM_LEVEL, | 219 ShellUtil::SYSTEM_LEVEL, |
| 290 ShellUtil::SHORTCUT_NO_OPTIONS)); | 220 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 291 | 221 |
| 292 // Test creation of a system-level shortcut when a user-level shortcut | 222 // Test creation of a system-level shortcut when a user-level shortcut |
| 293 // is already present (should succeed). | 223 // is already present (should succeed). |
| 294 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 224 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 295 dist_, | 225 dist_, |
| 296 exe_path.value(), | 226 exe_path.value(), |
| 297 description, | 227 description, |
| 298 L"", | 228 L"", |
| 299 L"", | 229 L"", |
| 300 exe_path.value(), | 230 exe_path.value(), |
| 301 dist_->GetIconIndex(), | 231 dist_->GetIconIndex(), |
| 302 ShellUtil::CURRENT_USER, | 232 ShellUtil::CURRENT_USER, |
| 303 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 233 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 304 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 234 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 305 dist_, | 235 dist_, |
| 306 exe_path.value(), | 236 exe_path.value(), |
| 307 description, | 237 description, |
| 308 L"", | 238 L"", |
| 309 L"", | 239 L"", |
| 310 exe_path.value(), | 240 exe_path.value(), |
| 311 dist_->GetIconIndex(), | 241 dist_->GetIconIndex(), |
| 312 ShellUtil::SYSTEM_LEVEL, | 242 ShellUtil::SYSTEM_LEVEL, |
| 313 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 243 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 314 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 244 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 315 user_shortcut_path.value(), | 245 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 316 description, | 246 user_shortcut_path.value(), description, 0)); |
| 317 0)); | 247 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 318 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 248 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 319 system_shortcut_path.value(), | 249 system_shortcut_path.value(), description, 0)); |
| 320 description, | |
| 321 0)); | |
| 322 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 250 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 323 dist_, | 251 dist_, |
| 324 ShellUtil::CURRENT_USER, | 252 ShellUtil::CURRENT_USER, |
| 325 ShellUtil::SHORTCUT_NO_OPTIONS)); | 253 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 326 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( | 254 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut( |
| 327 dist_, | 255 dist_, |
| 328 ShellUtil::SYSTEM_LEVEL, | 256 ShellUtil::SYSTEM_LEVEL, |
| 329 ShellUtil::SHORTCUT_NO_OPTIONS)); | 257 ShellUtil::SHORTCUT_NO_OPTIONS)); |
| 330 | 258 |
| 331 // Test creation of two profile-specific shortcuts (these are always | 259 // Test creation of two profile-specific shortcuts (these are always |
| 332 // user-level). | 260 // user-level). |
| 333 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 261 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 334 dist_, | 262 dist_, |
| 335 exe_path.value(), | 263 exe_path.value(), |
| 336 description, | 264 description, |
| 337 default_profile_user_name, | 265 default_profile_user_name, |
| 338 L"--profile-directory=\"Default\"", | 266 L"--profile-directory=\"Default\"", |
| 339 exe_path.value(), | 267 exe_path.value(), |
| 340 dist_->GetIconIndex(), | 268 dist_->GetIconIndex(), |
| 341 ShellUtil::CURRENT_USER, | 269 ShellUtil::CURRENT_USER, |
| 342 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 270 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 343 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 271 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 344 default_profile_shortcut_path.value(), | 272 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 345 description, | 273 default_profile_shortcut_path.value(), description, 0)); |
| 346 0)); | |
| 347 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( | 274 EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( |
| 348 dist_, | 275 dist_, |
| 349 exe_path.value(), | 276 exe_path.value(), |
| 350 description, | 277 description, |
| 351 second_profile_user_name, | 278 second_profile_user_name, |
| 352 L"--profile-directory=\"Profile 1\"", | 279 L"--profile-directory=\"Profile 1\"", |
| 353 exe_path.value(), | 280 exe_path.value(), |
| 354 dist_->GetIconIndex(), | 281 dist_->GetIconIndex(), |
| 355 ShellUtil::CURRENT_USER, | 282 ShellUtil::CURRENT_USER, |
| 356 ShellUtil::SHORTCUT_CREATE_ALWAYS)); | 283 ShellUtil::SHORTCUT_CREATE_ALWAYS)); |
| 357 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 284 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| 358 second_profile_shortcut_path.value(), | 285 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| 359 description, | 286 second_profile_shortcut_path.value(), description, 0)); |
| 360 0)); | |
| 361 std::vector<string16> profile_names; | 287 std::vector<string16> profile_names; |
| 362 profile_names.push_back(default_profile_shortcut_name); | 288 profile_names.push_back(default_profile_shortcut_name); |
| 363 profile_names.push_back(second_profile_shortcut_name); | 289 profile_names.push_back(second_profile_shortcut_name); |
| 364 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 290 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
| 365 profile_names)); | 291 profile_names)); |
| 366 } | 292 } |
| 367 | 293 |
| 368 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { | 294 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { |
| 369 std::vector<string16> components; | 295 std::vector<string16> components; |
| 370 const string16 base_app_id(dist_->GetBaseAppId()); | 296 const string16 base_app_id(dist_->GetBaseAppId()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 360 |
| 435 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 361 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
| 436 L"MZXW6YTB", L"MZXW6YTBOI"}; | 362 L"MZXW6YTB", L"MZXW6YTBOI"}; |
| 437 | 363 |
| 438 // Run the tests, with one more letter in the input every pass. | 364 // Run the tests, with one more letter in the input every pass. |
| 439 for (int i = 0; i < arraysize(expected); ++i) { | 365 for (int i = 0; i < arraysize(expected); ++i) { |
| 440 ASSERT_EQ(expected[i], | 366 ASSERT_EQ(expected[i], |
| 441 ShellUtil::ByteArrayToBase32(test_array, i)); | 367 ShellUtil::ByteArrayToBase32(test_array, i)); |
| 442 } | 368 } |
| 443 } | 369 } |
| OLD | NEW |