OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/util/shell_util.h" | 5 #include "chrome/installer/util/shell_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/base_paths_win.h" | 10 #include "base/base_paths_win.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/md5.h" | 13 #include "base/md5.h" |
13 #include "base/scoped_temp_dir.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/string16.h" | 15 #include "base/string16.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/test/scoped_path_override.h" | 17 #include "base/test/scoped_path_override.h" |
18 #include "base/test/test_shortcut_win.h" | 18 #include "base/test/test_shortcut_win.h" |
19 #include "base/win/shortcut.h" | 19 #include "base/win/shortcut.h" |
20 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
21 #include "chrome/installer/util/browser_distribution.h" | 21 #include "chrome/installer/util/browser_distribution.h" |
22 #include "chrome/installer/util/product.h" | 22 #include "chrome/installer/util/product.h" |
23 #include "chrome/installer/util/util_constants.h" | 23 #include "chrome/installer/util/util_constants.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 namespace { | 26 namespace { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 base::win::ValidateShortcut(expected_path, expected_properties); | 150 base::win::ValidateShortcut(expected_path, expected_properties); |
151 } | 151 } |
152 | 152 |
153 BrowserDistribution* dist_; | 153 BrowserDistribution* dist_; |
154 scoped_ptr<installer::Product> product_; | 154 scoped_ptr<installer::Product> product_; |
155 | 155 |
156 // A ShellUtil::ShortcutProperties object with common properties set already. | 156 // A ShellUtil::ShortcutProperties object with common properties set already. |
157 scoped_ptr<ShellUtil::ShortcutProperties> test_properties_; | 157 scoped_ptr<ShellUtil::ShortcutProperties> test_properties_; |
158 | 158 |
159 ScopedTempDir temp_dir_; | 159 base::ScopedTempDir temp_dir_; |
160 ScopedTempDir fake_user_desktop_; | 160 base::ScopedTempDir fake_user_desktop_; |
161 ScopedTempDir fake_common_desktop_; | 161 base::ScopedTempDir fake_common_desktop_; |
162 ScopedTempDir fake_user_quick_launch_; | 162 base::ScopedTempDir fake_user_quick_launch_; |
163 ScopedTempDir fake_default_user_quick_launch_; | 163 base::ScopedTempDir fake_default_user_quick_launch_; |
164 ScopedTempDir fake_start_menu_; | 164 base::ScopedTempDir fake_start_menu_; |
165 ScopedTempDir fake_common_start_menu_; | 165 base::ScopedTempDir fake_common_start_menu_; |
166 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 166 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
167 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 167 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
168 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 168 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
169 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; | 169 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; |
170 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 170 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
171 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 171 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
172 | 172 |
173 FilePath chrome_exe_; | 173 FilePath chrome_exe_; |
174 }; | 174 }; |
175 | 175 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 EXPECT_EQ(2, count); | 421 EXPECT_EQ(2, count); |
422 | 422 |
423 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); | 423 ASSERT_TRUE(file_util::PathExists(shortcut_folder)); |
424 ASSERT_TRUE(ShellUtil::RemoveShortcut( | 424 ASSERT_TRUE(ShellUtil::RemoveShortcut( |
425 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_.value(), | 425 ShellUtil::SHORTCUT_LOCATION_START_MENU, dist_, chrome_exe_.value(), |
426 ShellUtil::CURRENT_USER, NULL)); | 426 ShellUtil::CURRENT_USER, NULL)); |
427 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); | 427 ASSERT_FALSE(file_util::PathExists(shortcut_folder)); |
428 } | 428 } |
429 | 429 |
430 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { | 430 TEST_F(ShellUtilShortcutTest, DontRemoveChromeShortcutIfPointsToAnotherChrome) { |
431 ScopedTempDir other_exe_dir; | 431 base::ScopedTempDir other_exe_dir; |
432 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); | 432 ASSERT_TRUE(other_exe_dir.CreateUniqueTempDir()); |
433 FilePath other_chrome_exe = | 433 FilePath other_chrome_exe = |
434 other_exe_dir.path().Append(installer::kChromeExe); | 434 other_exe_dir.path().Append(installer::kChromeExe); |
435 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); | 435 EXPECT_EQ(0, file_util::WriteFile(other_chrome_exe, "", 0)); |
436 | 436 |
437 test_properties_->set_target(other_chrome_exe); | 437 test_properties_->set_target(other_chrome_exe); |
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
440 *test_properties_, | 440 *test_properties_, |
441 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 441 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 525 |
526 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 526 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
527 L"MZXW6YTB", L"MZXW6YTBOI"}; | 527 L"MZXW6YTB", L"MZXW6YTBOI"}; |
528 | 528 |
529 // Run the tests, with one more letter in the input every pass. | 529 // Run the tests, with one more letter in the input every pass. |
530 for (int i = 0; i < arraysize(expected); ++i) { | 530 for (int i = 0; i < arraysize(expected); ++i) { |
531 ASSERT_EQ(expected[i], | 531 ASSERT_EQ(expected[i], |
532 ShellUtil::ByteArrayToBase32(test_array, i)); | 532 ShellUtil::ByteArrayToBase32(test_array, i)); |
533 } | 533 } |
534 } | 534 } |
OLD | NEW |