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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 fake_start_menu_.path() : fake_common_start_menu_.path(); | 128 fake_start_menu_.path() : fake_common_start_menu_.path(); |
129 expected_path = expected_path.Append( | 129 expected_path = expected_path.Append( |
130 dist_->GetStartMenuShortcutSubfolder( | 130 dist_->GetStartMenuShortcutSubfolder( |
131 BrowserDistribution::SUBFOLDER_CHROME)); | 131 BrowserDistribution::SUBFOLDER_CHROME)); |
132 break; | 132 break; |
133 default: | 133 default: |
134 ADD_FAILURE() << "Unknown location"; | 134 ADD_FAILURE() << "Unknown location"; |
135 return base::FilePath(); | 135 return base::FilePath(); |
136 } | 136 } |
137 | 137 |
138 base::string16 shortcut_name = properties.has_shortcut_name() ? | 138 base::string16 shortcut_name = properties.has_shortcut_name() |
139 properties.shortcut_name : | 139 ? properties.shortcut_name |
140 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); | 140 : dist_->GetShortcutName(); |
141 shortcut_name.append(installer::kLnkExt); | 141 shortcut_name.append(installer::kLnkExt); |
142 return expected_path.Append(shortcut_name); | 142 return expected_path.Append(shortcut_name); |
143 } | 143 } |
144 | 144 |
145 // Validates that the shortcut at |location| matches |properties| (and | 145 // Validates that the shortcut at |location| matches |properties| (and |
146 // implicit default properties) for |dist|. | 146 // implicit default properties) for |dist|. |
147 // Note: This method doesn't verify the |pin_to_taskbar| property as it | 147 // Note: This method doesn't verify the |pin_to_taskbar| property as it |
148 // implies real (non-mocked) state which is flaky to test. | 148 // implies real (non-mocked) state which is flaky to test. |
149 void ValidateChromeShortcut( | 149 void ValidateChromeShortcut( |
150 ShellUtil::ShortcutLocation location, | 150 ShellUtil::ShortcutLocation location, |
(...skipping 17 matching lines...) Expand all Loading... |
168 expected_properties.set_arguments(base::string16()); | 168 expected_properties.set_arguments(base::string16()); |
169 | 169 |
170 if (properties.has_description()) | 170 if (properties.has_description()) |
171 expected_properties.set_description(properties.description); | 171 expected_properties.set_description(properties.description); |
172 else | 172 else |
173 expected_properties.set_description(dist->GetAppDescription()); | 173 expected_properties.set_description(dist->GetAppDescription()); |
174 | 174 |
175 if (properties.has_icon()) { | 175 if (properties.has_icon()) { |
176 expected_properties.set_icon(properties.icon, properties.icon_index); | 176 expected_properties.set_icon(properties.icon, properties.icon_index); |
177 } else { | 177 } else { |
178 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); | 178 int icon_index = dist->GetIconIndex(); |
179 expected_properties.set_icon(chrome_exe_, icon_index); | 179 expected_properties.set_icon(chrome_exe_, icon_index); |
180 } | 180 } |
181 | 181 |
182 if (properties.has_app_id()) { | 182 if (properties.has_app_id()) { |
183 expected_properties.set_app_id(properties.app_id); | 183 expected_properties.set_app_id(properties.app_id); |
184 } else { | 184 } else { |
185 // Tests are always seen as user-level installs in ShellUtil. | 185 // Tests are always seen as user-level installs in ShellUtil. |
186 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); | 186 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
187 } | 187 } |
188 | 188 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 351 |
352 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { | 352 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) { |
353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 353 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 354 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
355 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 355 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
356 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 356 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
357 test_properties_); | 357 test_properties_); |
358 } | 358 } |
359 | 359 |
360 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { | 360 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) { |
361 base::string16 shortcut_name( | 361 base::string16 shortcut_name(dist_->GetShortcutName() + installer::kLnkExt); |
362 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
363 installer::kLnkExt); | |
364 | 362 |
365 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 363 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
366 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 364 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
367 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 365 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
368 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 366 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
369 ASSERT_TRUE(base::PathExists( | 367 ASSERT_TRUE(base::PathExists( |
370 fake_common_desktop_.path().Append(shortcut_name))); | 368 fake_common_desktop_.path().Append(shortcut_name))); |
371 | 369 |
372 test_properties_.level = ShellUtil::CURRENT_USER; | 370 test_properties_.level = ShellUtil::CURRENT_USER; |
373 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 371 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
374 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 372 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
375 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 373 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
376 ASSERT_FALSE(base::PathExists( | 374 ASSERT_FALSE(base::PathExists( |
377 fake_user_desktop_.path().Append(shortcut_name))); | 375 fake_user_desktop_.path().Append(shortcut_name))); |
378 } | 376 } |
379 | 377 |
380 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { | 378 TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) { |
381 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 379 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
382 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, | 380 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, |
383 dist_, test_properties_, | 381 dist_, test_properties_, |
384 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); | 382 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)); |
385 ValidateChromeShortcut( | 383 ValidateChromeShortcut( |
386 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, | 384 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, |
387 dist_, test_properties_); | 385 dist_, test_properties_); |
388 } | 386 } |
389 | 387 |
390 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { | 388 TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) { |
391 base::string16 shortcut_name( | 389 base::string16 shortcut_name(dist_->GetShortcutName() + installer::kLnkExt); |
392 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
393 installer::kLnkExt); | |
394 | 390 |
395 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 391 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
396 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 392 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
397 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 393 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
398 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 394 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
399 ASSERT_TRUE(base::PathExists( | 395 ASSERT_TRUE(base::PathExists( |
400 fake_common_desktop_.path().Append(shortcut_name))); | 396 fake_common_desktop_.path().Append(shortcut_name))); |
401 | 397 |
402 test_properties_.level = ShellUtil::CURRENT_USER; | 398 test_properties_.level = ShellUtil::CURRENT_USER; |
403 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 399 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 ASSERT_FALSE(base::PathExists(chrome_apps_shortcut_folder)); | 766 ASSERT_FALSE(base::PathExists(chrome_apps_shortcut_folder)); |
771 } | 767 } |
772 | 768 |
773 TEST_F(ShellUtilShortcutTest, | 769 TEST_F(ShellUtilShortcutTest, |
774 DeleteStartMenuRootShortcutWithoutRemovingFolder) { | 770 DeleteStartMenuRootShortcutWithoutRemovingFolder) { |
775 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 771 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
776 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, | 772 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, |
777 dist_, test_properties_, | 773 dist_, test_properties_, |
778 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 774 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
779 | 775 |
780 base::string16 shortcut_name( | 776 base::string16 shortcut_name(dist_->GetShortcutName() + installer::kLnkExt); |
781 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
782 installer::kLnkExt); | |
783 base::FilePath shortcut_path( | 777 base::FilePath shortcut_path( |
784 fake_start_menu_.path().Append(shortcut_name)); | 778 fake_start_menu_.path().Append(shortcut_name)); |
785 | 779 |
786 ASSERT_TRUE(base::PathExists(fake_start_menu_.path())); | 780 ASSERT_TRUE(base::PathExists(fake_start_menu_.path())); |
787 ASSERT_TRUE(base::PathExists(shortcut_path)); | 781 ASSERT_TRUE(base::PathExists(shortcut_path)); |
788 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 782 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
789 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist_, | 783 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist_, |
790 ShellUtil::CURRENT_USER, chrome_exe_)); | 784 ShellUtil::CURRENT_USER, chrome_exe_)); |
791 // The shortcut should be removed but the "Start Menu" root directory should | 785 // The shortcut should be removed but the "Start Menu" root directory should |
792 // remain. | 786 // remain. |
793 ASSERT_TRUE(base::PathExists(fake_start_menu_.path())); | 787 ASSERT_TRUE(base::PathExists(fake_start_menu_.path())); |
794 ASSERT_FALSE(base::PathExists(shortcut_path)); | 788 ASSERT_FALSE(base::PathExists(shortcut_path)); |
795 } | 789 } |
796 | 790 |
797 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 791 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
798 base::ScopedTempDir other_exe_dir; | 792 base::ScopedTempDir other_exe_dir; |
799 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 793 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
800 base::FilePath other_chrome_exe = | 794 base::FilePath other_chrome_exe = |
801 other_exe_dir.path().Append(installer::kChromeExe); | 795 other_exe_dir.path().Append(installer::kChromeExe); |
802 EXPECT_EQ(0, base::WriteFile(other_chrome_exe, "", 0)); | 796 EXPECT_EQ(0, base::WriteFile(other_chrome_exe, "", 0)); |
803 | 797 |
804 test_properties_.set_target(other_chrome_exe); | 798 test_properties_.set_target(other_chrome_exe); |
805 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 799 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
806 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 800 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
807 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 801 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
808 | 802 |
809 base::string16 shortcut_name( | 803 base::string16 shortcut_name(dist_->GetShortcutName() + installer::kLnkExt); |
810 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
811 installer::kLnkExt); | |
812 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | 804 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); |
813 ASSERT_TRUE(base::PathExists(shortcut_path)); | 805 ASSERT_TRUE(base::PathExists(shortcut_path)); |
814 | 806 |
815 // The shortcut shouldn't be removed as it was installed pointing to | 807 // The shortcut shouldn't be removed as it was installed pointing to |
816 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the | 808 // |other_chrome_exe| and RemoveChromeShortcut() is being told that the |
817 // removed shortcut should point to |chrome_exe_|. | 809 // removed shortcut should point to |chrome_exe_|. |
818 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 810 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
819 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 811 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
820 chrome_exe_)); | 812 chrome_exe_)); |
821 ASSERT_TRUE(base::PathExists(shortcut_path)); | 813 ASSERT_TRUE(base::PathExists(shortcut_path)); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 | 1011 |
1020 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 1012 const base::string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
1021 L"MZXW6YTB", L"MZXW6YTBOI"}; | 1013 L"MZXW6YTB", L"MZXW6YTBOI"}; |
1022 | 1014 |
1023 // Run the tests, with one more letter in the input every pass. | 1015 // Run the tests, with one more letter in the input every pass. |
1024 for (size_t i = 0; i < arraysize(expected); ++i) { | 1016 for (size_t i = 0; i < arraysize(expected); ++i) { |
1025 ASSERT_EQ(expected[i], | 1017 ASSERT_EQ(expected[i], |
1026 ShellUtil::ByteArrayToBase32(test_array, i)); | 1018 ShellUtil::ByteArrayToBase32(test_array, i)); |
1027 } | 1019 } |
1028 } | 1020 } |
OLD | NEW |