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/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/md5.h" | 14 #include "base/md5.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/test/scoped_path_override.h" | 18 #include "base/test/scoped_path_override.h" |
19 #include "base/test/test_shortcut_win.h" | 19 #include "base/test/test_shortcut_win.h" |
20 #include "base/win/shortcut.h" | 20 #include "base/win/shortcut.h" |
21 #include "base/win/windows_version.h" | 21 #include "base/win/windows_version.h" |
22 #include "chrome/installer/util/browser_distribution.h" | 22 #include "chrome/installer/util/browser_distribution.h" |
23 #include "chrome/installer/util/product.h" | 23 #include "chrome/installer/util/product.h" |
24 #include "chrome/installer/util/util_constants.h" | 24 #include "chrome/installer/util/util_constants.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const wchar_t kManganeseExe[] = L"manganese.exe"; | 29 const wchar_t kManganeseExe[] = L"manganese.exe"; |
30 const wchar_t kOtherIco[] = L"other.ico"; | |
30 | 31 |
31 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific | 32 // TODO(huangs): Separate this into generic shortcut tests and Chrome-specific |
32 // tests. Specifically, we should not overly rely on getting shortcut properties | 33 // tests. Specifically, we should not overly rely on getting shortcut properties |
33 // from product_->AddDefaultShortcutProperties(). | 34 // from product_->AddDefaultShortcutProperties(). |
34 class ShellUtilShortcutTest : public testing::Test { | 35 class ShellUtilShortcutTest : public testing::Test { |
35 protected: | 36 protected: |
36 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {} | 37 ShellUtilShortcutTest() : test_properties_(ShellUtil::CURRENT_USER) {} |
37 | 38 |
38 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
39 dist_ = BrowserDistribution::GetDistribution(); | 40 dist_ = BrowserDistribution::GetDistribution(); |
40 ASSERT_TRUE(dist_ != NULL); | 41 ASSERT_TRUE(dist_ != NULL); |
41 product_.reset(new installer::Product(dist_)); | 42 product_.reset(new installer::Product(dist_)); |
42 | 43 |
43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
44 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); | 45 chrome_exe_ = temp_dir_.path().Append(installer::kChromeExe); |
45 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0)); | 46 EXPECT_EQ(0, file_util::WriteFile(chrome_exe_, "", 0)); |
46 | 47 |
47 manganese_exe_ = temp_dir_.path().Append(kManganeseExe); | 48 manganese_exe_ = temp_dir_.path().Append(kManganeseExe); |
48 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0)); | 49 EXPECT_EQ(0, file_util::WriteFile(manganese_exe_, "", 0)); |
49 | 50 |
51 other_ico_ = temp_dir_.path().Append(kOtherIco); | |
52 EXPECT_EQ(0, file_util::WriteFile(other_ico_, "", 0)); | |
53 | |
50 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); |
51 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); | 55 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); |
52 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir()); | 56 ASSERT_TRUE(fake_user_quick_launch_.CreateUniqueTempDir()); |
53 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(fake_default_user_quick_launch_.CreateUniqueTempDir()); |
54 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir()); | 58 ASSERT_TRUE(fake_start_menu_.CreateUniqueTempDir()); |
55 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); | 59 ASSERT_TRUE(fake_common_start_menu_.CreateUniqueTempDir()); |
56 user_desktop_override_.reset( | 60 user_desktop_override_.reset( |
57 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, | 61 new base::ScopedPathOverride(base::DIR_USER_DESKTOP, |
58 fake_user_desktop_.path())); | 62 fake_user_desktop_.path())); |
59 common_desktop_override_.reset( | 63 common_desktop_override_.reset( |
(...skipping 15 matching lines...) Expand all Loading... | |
75 base::FilePath icon_path; | 79 base::FilePath icon_path; |
76 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); | 80 base::CreateTemporaryFileInDir(temp_dir_.path(), &icon_path); |
77 test_properties_.set_target(chrome_exe_); | 81 test_properties_.set_target(chrome_exe_); |
78 test_properties_.set_arguments(L"--test --chrome"); | 82 test_properties_.set_arguments(L"--test --chrome"); |
79 test_properties_.set_description(L"Makes polar bears dance."); | 83 test_properties_.set_description(L"Makes polar bears dance."); |
80 test_properties_.set_icon(icon_path, 0); | 84 test_properties_.set_icon(icon_path, 0); |
81 test_properties_.set_app_id(L"Polar.Bear"); | 85 test_properties_.set_app_id(L"Polar.Bear"); |
82 test_properties_.set_dual_mode(true); | 86 test_properties_.set_dual_mode(true); |
83 } | 87 } |
84 | 88 |
89 // Helper to create a shortcut on the desktop, using |test_properties_|. Also | |
90 // asserts that creation was successful. |shortcut_path_out| is an optional | |
91 // output parameter, for the path to the shortcut created. | |
92 void CreateTestDesktopShortcut(base::FilePath* shortcut_path_out) { | |
huangs
2013/12/30 20:19:32
Cannot simply return base::FilePath, because ASSER
gab
2014/01/02 15:51:46
Right, that's because ASSERTs force a "return;", a
huangs
2014/01/02 19:58:22
Key changes:
- Returning base::FilePath now.
- Che
| |
93 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | |
94 ShellUtil::SHORTCUT_LOCATION_DESKTOP, | |
95 dist_, | |
96 test_properties_, | |
97 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
98 // Compute |shortcut_path|, deducing specified or default values. | |
99 const base::FilePath& base_path( | |
100 (test_properties_.level == ShellUtil::CURRENT_USER) ? | |
101 fake_user_desktop_.path() : fake_common_desktop_.path()); | |
102 string16 shortcut_name = test_properties_.has_shortcut_name() ? | |
103 test_properties_.shortcut_name : | |
104 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); | |
105 base::FilePath shortcut_path( | |
106 base_path.Append(shortcut_name + installer::kLnkExt)); | |
107 ASSERT_TRUE(base::PathExists(shortcut_path)); | |
108 if (shortcut_path_out) | |
109 *shortcut_path_out = shortcut_path; | |
110 } | |
111 | |
85 // Validates that the shortcut at |location| matches |properties| (and | 112 // Validates that the shortcut at |location| matches |properties| (and |
86 // implicit default properties) for |dist|. | 113 // implicit default properties) for |dist|. |
87 // Note: This method doesn't verify the |pin_to_taskbar| property as it | 114 // Note: This method doesn't verify the |pin_to_taskbar| property as it |
88 // implies real (non-mocked) state which is flaky to test. | 115 // implies real (non-mocked) state which is flaky to test. |
89 void ValidateChromeShortcut( | 116 void ValidateChromeShortcut( |
90 ShellUtil::ShortcutLocation location, | 117 ShellUtil::ShortcutLocation location, |
91 BrowserDistribution* dist, | 118 BrowserDistribution* dist, |
92 const ShellUtil::ShortcutProperties& properties) { | 119 const ShellUtil::ShortcutProperties& properties) { |
93 base::FilePath expected_path; | 120 base::FilePath expected_path; |
94 switch (location) { | 121 switch (location) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 expected_properties.set_arguments(properties.arguments); | 163 expected_properties.set_arguments(properties.arguments); |
137 else | 164 else |
138 expected_properties.set_arguments(string16()); | 165 expected_properties.set_arguments(string16()); |
139 | 166 |
140 if (properties.has_description()) | 167 if (properties.has_description()) |
141 expected_properties.set_description(properties.description); | 168 expected_properties.set_description(properties.description); |
142 else | 169 else |
143 expected_properties.set_description(dist->GetAppDescription()); | 170 expected_properties.set_description(dist->GetAppDescription()); |
144 | 171 |
145 if (properties.has_icon()) { | 172 if (properties.has_icon()) { |
146 expected_properties.set_icon(properties.icon, 0); | 173 expected_properties.set_icon(properties.icon, properties.icon_index); |
147 } else { | 174 } else { |
148 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); | 175 int icon_index = dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME); |
149 expected_properties.set_icon(chrome_exe_, icon_index); | 176 expected_properties.set_icon(chrome_exe_, icon_index); |
150 } | 177 } |
151 | 178 |
152 if (properties.has_app_id()) { | 179 if (properties.has_app_id()) { |
153 expected_properties.set_app_id(properties.app_id); | 180 expected_properties.set_app_id(properties.app_id); |
154 } else { | 181 } else { |
155 // Tests are always seen as user-level installs in ShellUtil. | 182 // Tests are always seen as user-level installs in ShellUtil. |
156 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); | 183 expected_properties.set_app_id(ShellUtil::GetBrowserModelId(dist, true)); |
(...skipping 22 matching lines...) Expand all Loading... | |
179 base::ScopedTempDir fake_common_start_menu_; | 206 base::ScopedTempDir fake_common_start_menu_; |
180 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 207 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
181 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 208 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
182 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 209 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
183 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; | 210 scoped_ptr<base::ScopedPathOverride> default_user_quick_launch_override_; |
184 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 211 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
185 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 212 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
186 | 213 |
187 base::FilePath chrome_exe_; | 214 base::FilePath chrome_exe_; |
188 base::FilePath manganese_exe_; | 215 base::FilePath manganese_exe_; |
216 base::FilePath other_ico_; | |
189 }; | 217 }; |
190 | 218 |
191 } // namespace | 219 } // namespace |
192 | 220 |
193 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { | 221 TEST_F(ShellUtilShortcutTest, GetShortcutPath) { |
194 base::FilePath path; | 222 base::FilePath path; |
195 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 223 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
196 ShellUtil::CURRENT_USER, &path); | 224 ShellUtil::CURRENT_USER, &path); |
197 EXPECT_EQ(fake_user_desktop_.path(), path); | 225 EXPECT_EQ(fake_user_desktop_.path(), path); |
198 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 226 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 386 |
359 test_properties_.level = ShellUtil::CURRENT_USER; | 387 test_properties_.level = ShellUtil::CURRENT_USER; |
360 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 388 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
361 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 389 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, |
362 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 390 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
363 ASSERT_TRUE(base::PathExists( | 391 ASSERT_TRUE(base::PathExists( |
364 fake_user_desktop_.path().Append(shortcut_name))); | 392 fake_user_desktop_.path().Append(shortcut_name))); |
365 } | 393 } |
366 | 394 |
367 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { | 395 TEST_F(ShellUtilShortcutTest, RemoveChromeShortcut) { |
368 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 396 base::FilePath shortcut_path; |
369 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 397 CreateTestDesktopShortcut(&shortcut_path); |
370 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
371 | |
372 string16 shortcut_name( | |
373 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
374 installer::kLnkExt); | |
375 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | |
376 ASSERT_TRUE(base::PathExists(shortcut_path)); | |
377 | 398 |
378 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 399 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
379 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 400 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
380 chrome_exe_)); | 401 chrome_exe_)); |
381 ASSERT_FALSE(base::PathExists(shortcut_path)); | 402 ASSERT_FALSE(base::PathExists(shortcut_path)); |
382 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 403 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
383 } | 404 } |
384 | 405 |
385 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { | 406 TEST_F(ShellUtilShortcutTest, RemoveSystemLevelChromeShortcut) { |
386 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 407 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
387 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 408 base::FilePath shortcut_path; |
388 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 409 CreateTestDesktopShortcut(&shortcut_path); |
389 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
390 | |
391 string16 shortcut_name( | |
392 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
393 installer::kLnkExt); | |
394 base::FilePath shortcut_path( | |
395 fake_common_desktop_.path().Append(shortcut_name)); | |
396 ASSERT_TRUE(base::PathExists(shortcut_path)); | |
397 | 410 |
398 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 411 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
399 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 412 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
400 chrome_exe_)); | 413 chrome_exe_)); |
401 ASSERT_FALSE(base::PathExists(shortcut_path)); | 414 ASSERT_FALSE(base::PathExists(shortcut_path)); |
402 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); | 415 ASSERT_TRUE(base::PathExists(shortcut_path.DirName())); |
403 } | 416 } |
404 | 417 |
405 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { | 418 TEST_F(ShellUtilShortcutTest, RemoveMultipleChromeShortcuts) { |
406 const wchar_t kShortcutName1[] = L"Chrome 1"; | 419 const wchar_t kShortcutName1[] = L"Chrome 1"; |
407 const wchar_t kShortcutName2[] = L"Chrome 2"; | 420 const wchar_t kShortcutName2[] = L"Chrome 2"; |
408 | 421 |
409 test_properties_.set_shortcut_name(kShortcutName1); | 422 test_properties_.set_shortcut_name(kShortcutName1); |
410 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 423 base::FilePath shortcut1_path; |
411 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 424 CreateTestDesktopShortcut(&shortcut1_path); |
412 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
413 string16 shortcut1_name( | |
414 string16(kShortcutName1).append(installer::kLnkExt)); | |
415 base::FilePath shortcut1_path( | |
416 fake_user_desktop_.path().Append(shortcut1_name)); | |
417 ASSERT_TRUE(base::PathExists(shortcut1_path)); | |
418 | 425 |
419 test_properties_.set_shortcut_name(kShortcutName2); | 426 test_properties_.set_shortcut_name(kShortcutName2); |
420 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); | 427 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); |
421 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 428 base::FilePath shortcut2_path; |
422 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | 429 CreateTestDesktopShortcut(&shortcut2_path); |
423 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
424 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | |
425 base::FilePath shortcut2_path( | |
426 fake_user_desktop_.path().Append(shortcut2_name)); | |
427 ASSERT_TRUE(base::PathExists(shortcut2_path)); | |
428 | 430 |
429 ASSERT_TRUE(ShellUtil::RemoveShortcuts( | 431 ASSERT_TRUE(ShellUtil::RemoveShortcuts( |
430 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 432 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
431 chrome_exe_)); | 433 chrome_exe_)); |
432 ASSERT_FALSE(base::PathExists(shortcut1_path)); | 434 ASSERT_FALSE(base::PathExists(shortcut1_path)); |
433 ASSERT_FALSE(base::PathExists(shortcut2_path)); | 435 ASSERT_FALSE(base::PathExists(shortcut2_path)); |
434 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); | 436 ASSERT_TRUE(base::PathExists(shortcut1_path.DirName())); |
435 } | 437 } |
436 | 438 |
437 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcutsWithArgs) { | 439 TEST_F(ShellUtilShortcutTest, RetargetShortcutsWithArgs) { |
438 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 440 CreateTestDesktopShortcut(NULL); |
439 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
440 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
441 | |
442 string16 shortcut_name( | |
443 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
444 installer::kLnkExt); | |
445 base::FilePath shortcut_path(fake_user_desktop_.path().Append(shortcut_name)); | |
446 ASSERT_TRUE(base::PathExists(shortcut_path)); | |
447 | 441 |
448 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 442 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
449 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 443 // Relies on fact that |test_properties_| has non-empty arguments. |
450 updated_properties.set_target(new_exe); | 444 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( |
451 // |updated_properties| has arguments. | |
452 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs( | |
453 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 445 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
454 chrome_exe_, updated_properties)); | 446 chrome_exe_, new_exe)); |
455 | 447 |
456 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 448 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
457 expected_properties.set_target(new_exe); | 449 expected_properties.set_target(new_exe); |
458 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 450 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
459 expected_properties); | 451 expected_properties); |
460 } | 452 } |
461 | 453 |
462 TEST_F(ShellUtilShortcutTest, UpdateSystemLevelChromeShortcutsWithArgs) { | 454 TEST_F(ShellUtilShortcutTest, RetargetSystemLevelChromeShortcutsWithArgs) { |
463 test_properties_.level = ShellUtil::SYSTEM_LEVEL; | 455 test_properties_.level = ShellUtil::SYSTEM_LEVEL; |
464 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 456 CreateTestDesktopShortcut(NULL); |
465 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
466 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
467 | |
468 string16 shortcut_name( | |
469 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + | |
470 installer::kLnkExt); | |
471 base::FilePath shortcut_path( | |
472 fake_common_desktop_.path().Append(shortcut_name)); | |
473 ASSERT_TRUE(base::PathExists(shortcut_path)); | |
474 | 457 |
475 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 458 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
476 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 459 // Relies on fact that |test_properties_| has non-empty arguments. |
477 updated_properties.set_target(new_exe); | 460 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( |
478 // |updated_properties| has arguments. | |
479 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs( | |
480 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, | 461 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::SYSTEM_LEVEL, |
481 chrome_exe_, updated_properties)); | 462 chrome_exe_, new_exe)); |
482 | 463 |
483 ShellUtil::ShortcutProperties expected_properties(test_properties_); | 464 ShellUtil::ShortcutProperties expected_properties(test_properties_); |
484 expected_properties.set_target(new_exe); | 465 expected_properties.set_target(new_exe); |
485 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 466 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
486 expected_properties); | 467 expected_properties); |
487 } | 468 } |
488 | 469 |
489 TEST_F(ShellUtilShortcutTest, UpdateMultipleChromeShortcutsWithArgs) { | 470 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsEmpty) { |
490 const wchar_t kShortcutName1[] = L"Chrome 1"; | 471 const wchar_t kShortcutName1[] = L"Chrome 1"; |
491 const wchar_t kShortcutName2[] = L"Chrome 2"; | 472 const wchar_t kShortcutName2[] = L"Chrome 2"; |
492 | 473 |
493 // Setup shortcut 1, which has empty arguments. | 474 // Setup shortcut 1, which has empty arguments. |
494 test_properties_.set_shortcut_name(kShortcutName1); | 475 test_properties_.set_shortcut_name(kShortcutName1); |
495 test_properties_.set_arguments(L""); | 476 test_properties_.set_arguments(L""); |
496 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 477 CreateTestDesktopShortcut(NULL); |
497 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
498 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
499 string16 shortcut1_name(string16(kShortcutName1).append(installer::kLnkExt)); | |
500 base::FilePath shortcut1_path( | |
501 fake_user_desktop_.path().Append(shortcut1_name)); | |
502 ShellUtil::ShortcutProperties expected_properties1(test_properties_); | 478 ShellUtil::ShortcutProperties expected_properties1(test_properties_); |
503 | 479 |
504 // Setup shortcut 2, which has non-empty arguments. | 480 // Setup shortcut 2, which has non-empty arguments. |
505 string16 shortcut2_args = L"--profile-directory=\"Profile 2\""; | |
506 test_properties_.set_shortcut_name(kShortcutName2); | 481 test_properties_.set_shortcut_name(kShortcutName2); |
507 test_properties_.set_arguments(shortcut2_args); | 482 test_properties_.set_arguments(L"--profile-directory=\"Profile 2\""); |
508 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 483 CreateTestDesktopShortcut(NULL); |
509 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, test_properties_, | |
510 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | |
511 string16 shortcut2_name(string16(kShortcutName2).append(installer::kLnkExt)); | |
512 base::FilePath shortcut2_path( | |
513 fake_user_desktop_.path().Append(shortcut2_name)); | |
514 ASSERT_TRUE(base::PathExists(shortcut2_path)); | |
515 ShellUtil::ShortcutProperties expected_properties2(test_properties_); | 484 ShellUtil::ShortcutProperties expected_properties2(test_properties_); |
516 | 485 |
517 // Update shortcuts: target "manganese.exe" instead of "chrome.exe". | 486 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". Only |
487 // shortcuts with non-empty arguments (i.e., shortcut 2) gets updated. | |
518 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | 488 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); |
519 ShellUtil::ShortcutProperties updated_properties(ShellUtil::CURRENT_USER); | 489 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( |
520 updated_properties.set_target(new_exe); | |
521 | |
522 // Only changing shrotcuts that have non-empty arguments, i.e., shortcut 2. | |
523 ASSERT_TRUE(ShellUtil::UpdateShortcutsWithArgs( | |
524 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | 490 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, |
525 chrome_exe_, updated_properties)); | 491 chrome_exe_, new_exe)); |
526 // Verify shortcut 1. | 492 // Verify shortcut 1. |
527 // |expected_properties1| was unchanged and still targets "chrome.exe", since | 493 // |expected_properties1| is unchanged and still targets "chrome.exe", since |
528 // it has empty target, yet we passed |require_args| = true. | 494 // it has empty target, yet we passed |require_args| = true. |
529 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 495 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
530 expected_properties1); | 496 expected_properties1); |
531 // Verify shortcut 2. | 497 // Verify shortcut 2, which now targets "manganese.exe". |
532 expected_properties2.set_target(new_exe); | 498 expected_properties2.set_target(new_exe); |
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | 499 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, |
534 expected_properties2); | 500 expected_properties2); |
535 } | 501 } |
502 | |
503 TEST_F(ShellUtilShortcutTest, RetargetChromeShortcutsWithArgsIcon) { | |
504 const wchar_t kShortcutName1[] = L"Chrome 1"; | |
505 const wchar_t kShortcutName2[] = L"Chrome 2"; | |
506 | |
507 // Setup shortcut 1, which has icon set to "chrome.exe". | |
508 test_properties_.set_shortcut_name(kShortcutName1); | |
509 test_properties_.set_icon(chrome_exe_, 3); | |
510 CreateTestDesktopShortcut(NULL); | |
511 ShellUtil::ShortcutProperties expected_properties1(test_properties_); | |
512 | |
513 // Setup shortcut 2, which has icon set to "other.ico". | |
514 test_properties_.set_shortcut_name(kShortcutName2); | |
515 test_properties_.set_icon(other_ico_, 0); | |
516 CreateTestDesktopShortcut(NULL); | |
517 ShellUtil::ShortcutProperties expected_properties2(test_properties_); | |
518 | |
519 // Retarget shortcuts: replace "chrome.exe" with "manganese.exe". | |
520 // Relies on fact that |test_properties_| has non-empty arguments. | |
gab
2014/01/02 15:51:46
To strengthen my point about not needing the helpe
huangs
2014/01/02 19:58:22
Passing test_properties_ as parameter to the routi
| |
521 base::FilePath new_exe = temp_dir_.path().Append(kManganeseExe); | |
522 ASSERT_TRUE(ShellUtil::RetargetShortcutsWithArgs( | |
523 ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, ShellUtil::CURRENT_USER, | |
524 chrome_exe_, new_exe)); | |
525 // Verify shortcut 1: icon now targets "manganese.exe", with same icon index. | |
526 expected_properties1.set_target(new_exe); | |
527 expected_properties1.set_icon(new_exe, 3); | |
528 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
529 expected_properties1); | |
530 // Verify shortcut 2: icon remains unchanged. | |
531 expected_properties2.set_target(new_exe); | |
532 expected_properties2.set_icon(other_ico_, 0); | |
533 ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist_, | |
534 expected_properties2); | |
535 } | |
536 | 536 |
537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { | 537 TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) { |
538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 538 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 539 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
540 dist_, test_properties_, | 540 dist_, test_properties_, |
541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 541 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( | 542 ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut( |
543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, | 543 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
544 dist_, test_properties_, | 544 dist_, test_properties_, |
545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); | 545 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 713 |
714 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 714 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
715 L"MZXW6YTB", L"MZXW6YTBOI"}; | 715 L"MZXW6YTB", L"MZXW6YTBOI"}; |
716 | 716 |
717 // Run the tests, with one more letter in the input every pass. | 717 // Run the tests, with one more letter in the input every pass. |
718 for (int i = 0; i < arraysize(expected); ++i) { | 718 for (int i = 0; i < arraysize(expected); ++i) { |
719 ASSERT_EQ(expected[i], | 719 ASSERT_EQ(expected[i], |
720 ShellUtil::ByteArrayToBase32(test_array, i)); | 720 ShellUtil::ByteArrayToBase32(test_array, i)); |
721 } | 721 } |
722 } | 722 } |
OLD | NEW |