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 <shlobj.h> | |
6 | |
7 #include <fstream> | 5 #include <fstream> |
8 #include <vector> | 6 #include <vector> |
9 | 7 |
10 #include "base/file_util.h" | 8 #include "base/file_util.h" |
11 #include "base/path_service.h" | 9 #include "base/path_service.h" |
12 #include "base/md5.h" | 10 #include "base/md5.h" |
11 #include "base/path_service.h" | |
13 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
14 #include "base/string16.h" | 13 #include "base/string16.h" |
15 #include "base/string_util.h" | 14 #include "base/string_util.h" |
16 #include "base/test/test_shortcut_win.h" | 15 #include "base/test/test_shortcut_win.h" |
17 #include "base/win/shortcut.h" | 16 #include "base/win/shortcut.h" |
18 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
19 #include "chrome/installer/util/browser_distribution.h" | 18 #include "chrome/installer/util/browser_distribution.h" |
20 #include "chrome/installer/util/master_preferences.h" | 19 #include "chrome/installer/util/master_preferences.h" |
21 #include "chrome/installer/util/shell_util.h" | 20 #include "chrome/installer/util/shell_util.h" |
22 #include "chrome/installer/util/util_constants.h" | 21 #include "chrome/installer/util/util_constants.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 class ShellUtilTestWithDirAndDist : public testing::Test { | 26 class ShellUtilShortcutTest : public testing::Test { |
28 protected: | 27 protected: |
29 virtual void SetUp() { | 28 virtual void SetUp() { |
grt (UTC plus 2)
2012/09/19 16:44:46
OVERRIDE
gab
2012/09/19 18:22:58
Done (and also done in profile_shorcut_manager_uni
| |
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
31 dist_ = BrowserDistribution::GetDistribution(); | 29 dist_ = BrowserDistribution::GetDistribution(); |
32 ASSERT_TRUE(dist_ != NULL); | 30 ASSERT_TRUE(dist_ != NULL); |
31 | |
32 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
33 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); | |
34 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); | |
35 EXPECT_TRUE(PathService::Override(base::DIR_USER_DESKTOP, | |
grt (UTC plus 2)
2012/09/19 16:44:46
why not ASSERT_TRUE? should the test continue if
gab
2012/09/19 18:22:58
Well the test as a whole can still pass if Overrid
| |
36 fake_user_desktop_.path())); | |
37 EXPECT_TRUE(PathService::Override(base::DIR_COMMON_DESKTOP, | |
38 fake_common_desktop_.path())); | |
33 } | 39 } |
34 | 40 |
35 BrowserDistribution* dist_; | 41 BrowserDistribution* dist_; |
36 | 42 |
37 ScopedTempDir temp_dir_; | 43 ScopedTempDir temp_dir_; |
44 | |
45 ScopedTempDir fake_user_desktop_; | |
46 ScopedTempDir fake_common_desktop_; | |
38 }; | 47 }; |
39 | 48 |
40 // Returns the status of a call to base::win::VerifyShorcut for the properties | 49 // Returns the status of a call to base::win::VerifyShorcut for the properties |
41 // passed in. | 50 // passed in. |
42 // TODO(gab): This is only temporary while waiting for my upcoming CL that will | 51 // TODO(gab): This is only temporary while waiting for my upcoming CL that will |
43 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't | 52 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't |
44 // want to adapt every test here for this half-changed state as they will change | 53 // want to adapt every test here for this half-changed state as they will change |
45 // again very soon). | 54 // again very soon). |
46 base::win::VerifyShortcutStatus VerifyChromeShortcut( | 55 base::win::VerifyShortcutStatus VerifyChromeShortcut( |
47 const FilePath& exe_path, | 56 const FilePath& exe_path, |
48 const FilePath& shortcut_path, | 57 const FilePath& shortcut_path, |
49 const string16& description, | 58 const string16& description, |
50 int icon_index) { | 59 int icon_index) { |
51 base::win::ShortcutProperties expected_properties; | 60 base::win::ShortcutProperties expected_properties; |
52 expected_properties.set_target(exe_path); | 61 expected_properties.set_target(exe_path); |
53 expected_properties.set_description(description); | 62 expected_properties.set_description(description); |
54 expected_properties.set_icon(exe_path, icon_index); | 63 expected_properties.set_icon(exe_path, icon_index); |
55 return base::win::VerifyShortcut(shortcut_path, expected_properties); | 64 return base::win::VerifyShortcut(shortcut_path, expected_properties); |
56 } | 65 } |
57 | 66 |
58 } | 67 } |
59 | 68 |
60 // Test that we can open archives successfully. | 69 // Test that we can open archives successfully. |
61 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { | 70 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { |
62 // Create an executable in test path by copying ourself to it. | 71 // Create an executable in test path by copying ourself to it. |
63 wchar_t exe_full_path_str[MAX_PATH]; | 72 wchar_t exe_full_path_str[MAX_PATH]; |
64 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 73 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
65 FilePath exe_full_path(exe_full_path_str); | 74 FilePath exe_full_path(exe_full_path_str); |
66 | 75 |
67 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 76 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
68 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 77 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
69 | 78 |
70 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 79 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
71 const string16 description(L"dummy description"); | 80 const string16 description(L"dummy description"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 shortcut_path.value(), | 124 shortcut_path.value(), |
116 string16(), | 125 string16(), |
117 description2, | 126 description2, |
118 exe_path.value(), | 127 exe_path.value(), |
119 dist_->GetIconIndex(), | 128 dist_->GetIconIndex(), |
120 ShellUtil::SHORTCUT_NO_OPTIONS)); | 129 ShellUtil::SHORTCUT_NO_OPTIONS)); |
121 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 130 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
122 VerifyChromeShortcut(exe_path, shortcut_path, description2, 1)); | 131 VerifyChromeShortcut(exe_path, shortcut_path, description2, 1)); |
123 } | 132 } |
124 | 133 |
125 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { | 134 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { |
126 // Run this test on Vista+ only if we are running elevated. | |
127 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | |
128 LOG(ERROR) << "Must be admin to run this test on Vista+"; | |
129 return; | |
130 } | |
131 | |
132 // Create an executable in test path by copying ourself to it. | 135 // Create an executable in test path by copying ourself to it. |
133 wchar_t exe_full_path_str[MAX_PATH]; | 136 wchar_t exe_full_path_str[MAX_PATH]; |
134 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 137 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
135 FilePath exe_full_path(exe_full_path_str); | 138 FilePath exe_full_path(exe_full_path_str); |
136 | 139 |
137 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 140 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
138 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 141 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
139 | 142 |
140 const string16 description(L"dummy description"); | 143 const string16 description(L"dummy description"); |
141 | 144 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, | 302 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, |
300 VerifyChromeShortcut( | 303 VerifyChromeShortcut( |
301 exe_path, second_profile_shortcut_path, description, 0)); | 304 exe_path, second_profile_shortcut_path, description, 0)); |
302 std::vector<string16> profile_names; | 305 std::vector<string16> profile_names; |
303 profile_names.push_back(default_profile_shortcut_name); | 306 profile_names.push_back(default_profile_shortcut_name); |
304 profile_names.push_back(second_profile_shortcut_name); | 307 profile_names.push_back(second_profile_shortcut_name); |
305 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 308 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
306 profile_names)); | 309 profile_names)); |
307 } | 310 } |
308 | 311 |
309 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { | 312 TEST(ShellUtilTest, BuildAppModelIdBasic) { |
310 std::vector<string16> components; | 313 std::vector<string16> components; |
311 const string16 base_app_id(dist_->GetBaseAppId()); | 314 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
315 const string16 base_app_id(dist->GetBaseAppId()); | |
312 components.push_back(base_app_id); | 316 components.push_back(base_app_id); |
313 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 317 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
314 } | 318 } |
315 | 319 |
316 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) { | 320 TEST(ShellUtilTest, BuildAppModelIdManySmall) { |
317 std::vector<string16> components; | 321 std::vector<string16> components; |
318 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); | 322 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
323 const string16 suffixed_app_id(dist->GetBaseAppId().append(L".gab")); | |
319 components.push_back(suffixed_app_id); | 324 components.push_back(suffixed_app_id); |
320 components.push_back(L"Default"); | 325 components.push_back(L"Default"); |
321 components.push_back(L"Test"); | 326 components.push_back(L"Test"); |
322 ASSERT_EQ(suffixed_app_id + L".Default.Test", | 327 ASSERT_EQ(suffixed_app_id + L".Default.Test", |
323 ShellUtil::BuildAppModelId(components)); | 328 ShellUtil::BuildAppModelId(components)); |
324 } | 329 } |
325 | 330 |
326 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) { | 331 TEST(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { |
327 std::vector<string16> components; | 332 std::vector<string16> components; |
328 const string16 long_appname( | 333 const string16 long_appname( |
329 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 334 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
330 L"that_goes_over_64_characters"); | 335 L"that_goes_over_64_characters"); |
331 components.push_back(long_appname); | 336 components.push_back(long_appname); |
332 components.push_back(L"Default"); | 337 components.push_back(L"Default"); |
333 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", | 338 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", |
334 ShellUtil::BuildAppModelId(components)); | 339 ShellUtil::BuildAppModelId(components)); |
335 } | 340 } |
336 | 341 |
337 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) { | 342 TEST(ShellUtilTest, BuildAppModelIdLongEverything) { |
338 std::vector<string16> components; | 343 std::vector<string16> components; |
339 const string16 long_appname( | 344 const string16 long_appname( |
340 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 345 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
341 L"that_goes_over_64_characters"); | 346 L"that_goes_over_64_characters"); |
342 components.push_back(long_appname); | 347 components.push_back(long_appname); |
343 components.push_back( | 348 components.push_back( |
344 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); | 349 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); |
345 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); | 350 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); |
346 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); | 351 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); |
347 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", | 352 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", |
(...skipping 27 matching lines...) Expand all Loading... | |
375 | 380 |
376 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | 381 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", |
377 L"MZXW6YTB", L"MZXW6YTBOI"}; | 382 L"MZXW6YTB", L"MZXW6YTBOI"}; |
378 | 383 |
379 // Run the tests, with one more letter in the input every pass. | 384 // Run the tests, with one more letter in the input every pass. |
380 for (int i = 0; i < arraysize(expected); ++i) { | 385 for (int i = 0; i < arraysize(expected); ++i) { |
381 ASSERT_EQ(expected[i], | 386 ASSERT_EQ(expected[i], |
382 ShellUtil::ByteArrayToBase32(test_array, i)); | 387 ShellUtil::ByteArrayToBase32(test_array, i)); |
383 } | 388 } |
384 } | 389 } |
OLD | NEW |