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> | 5 #include <windows.h> |
6 #include <shellapi.h> | 6 #include <shellapi.h> |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include <fstream> | 9 #include <fstream> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/md5.h" | |
15 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
16 #include "base/string16.h" | 15 #include "base/string16.h" |
17 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ((FilePath(file_path) != FilePath(long_path)) && | 81 ((FilePath(file_path) != FilePath(long_path)) && |
83 (FilePath(file_path) != FilePath(short_path))) || | 82 (FilePath(file_path) != FilePath(short_path))) || |
84 (index != icon_index)); | 83 (index != icon_index)); |
85 EXPECT_FALSE(failed); | 84 EXPECT_FALSE(failed); |
86 if (failed) | 85 if (failed) |
87 return false; | 86 return false; |
88 | 87 |
89 return true; | 88 return true; |
90 } | 89 } |
91 | 90 |
92 class ShellUtilTestWithDirAndDist : public testing::Test { | 91 class ShellUtilTest : public testing::Test { |
93 protected: | 92 protected: |
94 virtual void SetUp() { | 93 virtual void SetUp() { |
95 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 94 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
96 dist_ = BrowserDistribution::GetDistribution(); | 95 dist_ = BrowserDistribution::GetDistribution(); |
97 ASSERT_TRUE(dist_ != NULL); | 96 ASSERT_TRUE(dist_ != NULL); |
98 } | 97 } |
99 | 98 |
100 BrowserDistribution* dist_; | 99 BrowserDistribution* dist_; |
101 | 100 |
102 ScopedTempDir temp_dir_; | 101 ScopedTempDir temp_dir_; |
103 }; | 102 }; |
104 }; | 103 }; |
105 | 104 |
106 // Test that we can open archives successfully. | 105 // Test that we can open archives successfully. |
107 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { | 106 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { |
108 // Create an executable in test path by copying ourself to it. | 107 // Create an executable in test path by copying ourself to it. |
109 wchar_t exe_full_path_str[MAX_PATH]; | 108 wchar_t exe_full_path_str[MAX_PATH]; |
110 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 109 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
111 FilePath exe_full_path(exe_full_path_str); | 110 FilePath exe_full_path(exe_full_path_str); |
112 | 111 |
113 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 112 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
114 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 113 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
115 | 114 |
116 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 115 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
117 const std::wstring description(L"dummy description"); | 116 const std::wstring description(L"dummy description"); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 L"", | 163 L"", |
165 description2, | 164 description2, |
166 exe_path.value(), | 165 exe_path.value(), |
167 dist_->GetIconIndex(), | 166 dist_->GetIconIndex(), |
168 ShellUtil::SHORTCUT_NO_OPTIONS)); | 167 ShellUtil::SHORTCUT_NO_OPTIONS)); |
169 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 168 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
170 shortcut_path.value(), | 169 shortcut_path.value(), |
171 description2, 1)); | 170 description2, 1)); |
172 } | 171 } |
173 | 172 |
174 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { | 173 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { |
175 // Run this test on Vista+ only if we are running elevated. | 174 // Run this test on Vista+ only if we are running elevated. |
176 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | 175 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { |
177 LOG(ERROR) << "Must be admin to run this test on Vista+"; | 176 LOG(ERROR) << "Must be admin to run this test on Vista+"; |
178 return; | 177 return; |
179 } | 178 } |
180 | 179 |
181 // Create an executable in test path by copying ourself to it. | 180 // Create an executable in test path by copying ourself to it. |
182 wchar_t exe_full_path_str[MAX_PATH]; | 181 wchar_t exe_full_path_str[MAX_PATH]; |
183 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 182 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
184 FilePath exe_full_path(exe_full_path_str); | 183 FilePath exe_full_path(exe_full_path_str); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 second_profile_shortcut_path.value(), | 356 second_profile_shortcut_path.value(), |
358 description, | 357 description, |
359 0)); | 358 0)); |
360 std::vector<string16> profile_names; | 359 std::vector<string16> profile_names; |
361 profile_names.push_back(default_profile_shortcut_name); | 360 profile_names.push_back(default_profile_shortcut_name); |
362 profile_names.push_back(second_profile_shortcut_name); | 361 profile_names.push_back(second_profile_shortcut_name); |
363 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 362 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
364 profile_names)); | 363 profile_names)); |
365 } | 364 } |
366 | 365 |
367 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { | 366 TEST_F(ShellUtilTest, BuildAppModelIdBasic) { |
368 std::vector<string16> components; | 367 std::vector<string16> components; |
369 const string16 base_app_id(dist_->GetBaseAppId()); | 368 const string16 base_app_id(dist_->GetBaseAppId()); |
370 components.push_back(base_app_id); | 369 components.push_back(base_app_id); |
371 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 370 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
372 } | 371 } |
373 | 372 |
374 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) { | 373 TEST_F(ShellUtilTest, BuildAppModelIdManySmall) { |
375 std::vector<string16> components; | 374 std::vector<string16> components; |
376 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); | 375 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); |
377 components.push_back(suffixed_app_id); | 376 components.push_back(suffixed_app_id); |
378 components.push_back(L"Default"); | 377 components.push_back(L"Default"); |
379 components.push_back(L"Test"); | 378 components.push_back(L"Test"); |
380 ASSERT_EQ(suffixed_app_id + L".Default.Test", | 379 ASSERT_EQ(suffixed_app_id + L".Default.Test", |
381 ShellUtil::BuildAppModelId(components)); | 380 ShellUtil::BuildAppModelId(components)); |
382 } | 381 } |
383 | 382 |
384 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) { | 383 TEST_F(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { |
385 std::vector<string16> components; | 384 std::vector<string16> components; |
386 const string16 long_appname( | 385 const string16 long_appname( |
387 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 386 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
388 L"that_goes_over_64_characters"); | 387 L"that_goes_over_64_characters"); |
389 components.push_back(long_appname); | 388 components.push_back(long_appname); |
390 components.push_back(L"Default"); | 389 components.push_back(L"Default"); |
391 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", | 390 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", |
392 ShellUtil::BuildAppModelId(components)); | 391 ShellUtil::BuildAppModelId(components)); |
393 } | 392 } |
394 | 393 |
395 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) { | 394 TEST_F(ShellUtilTest, BuildAppModelIdLongEverything) { |
396 std::vector<string16> components; | 395 std::vector<string16> components; |
397 const string16 long_appname( | 396 const string16 long_appname( |
398 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 397 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
399 L"that_goes_over_64_characters"); | 398 L"that_goes_over_64_characters"); |
400 components.push_back(long_appname); | 399 components.push_back(long_appname); |
401 components.push_back( | 400 components.push_back( |
402 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); | 401 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); |
403 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); | 402 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); |
404 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); | 403 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); |
405 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", | 404 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", |
406 constructed_app_id); | 405 constructed_app_id); |
407 } | 406 } |
408 | |
409 TEST(ShellUtilTest, MD5DigestToBase32) { | |
410 const base::MD5Digest digest = { 'f', 'o', 'o', 'b', 'a', 'f', 'o', 'o', 'b', | |
411 'a', 'f', 'o', 'o', 'b', 'a', 'f' }; | |
412 EXPECT_EQ(L"MZXW6YTBMZXW6YTBMZXW6YTBMY", | |
413 ShellUtil::MD5DigestToBase32(digest)); | |
414 } | |
415 | |
416 TEST(ShellUtilTest, ByteArrayToBase32) { | |
417 // Tests from http://tools.ietf.org/html/rfc4648#section-10. | |
418 const unsigned char test_array[] = { 'f', 'o', 'o', 'b', 'a', 'r' }; | |
419 | |
420 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", | |
421 L"MZXW6YTB", L"MZXW6YTBOI"}; | |
422 | |
423 // Run the tests, with one more letter in the input every pass. | |
424 for (int i = 0; i < arraysize(expected); ++i) { | |
425 EXPECT_EQ(expected[i], | |
426 ShellUtil::ByteArrayToBase32(test_array, i)); | |
427 } | |
428 | |
429 } | |
OLD | NEW |