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" | |
14 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/win/scoped_comptr.h" | 17 #include "base/win/scoped_comptr.h" |
17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
18 #include "chrome/installer/util/browser_distribution.h" | 19 #include "chrome/installer/util/browser_distribution.h" |
19 #include "chrome/installer/util/master_preferences.h" | 20 #include "chrome/installer/util/master_preferences.h" |
20 #include "chrome/installer/util/shell_util.h" | 21 #include "chrome/installer/util/shell_util.h" |
21 #include "chrome/installer/util/util_constants.h" | 22 #include "chrome/installer/util/util_constants.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 ((FilePath(file_path) != FilePath(long_path)) && | 82 ((FilePath(file_path) != FilePath(long_path)) && |
82 (FilePath(file_path) != FilePath(short_path))) || | 83 (FilePath(file_path) != FilePath(short_path))) || |
83 (index != icon_index)); | 84 (index != icon_index)); |
84 EXPECT_FALSE(failed); | 85 EXPECT_FALSE(failed); |
85 if (failed) | 86 if (failed) |
86 return false; | 87 return false; |
87 | 88 |
88 return true; | 89 return true; |
89 } | 90 } |
90 | 91 |
91 class ShellUtilTest : public testing::Test { | 92 class ShellUtilTestWithDirAndDist : public testing::Test { |
92 protected: | 93 protected: |
93 virtual void SetUp() { | 94 virtual void SetUp() { |
94 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 95 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
95 dist_ = BrowserDistribution::GetDistribution(); | 96 dist_ = BrowserDistribution::GetDistribution(); |
96 ASSERT_TRUE(dist_ != NULL); | 97 ASSERT_TRUE(dist_ != NULL); |
97 } | 98 } |
98 | 99 |
99 BrowserDistribution* dist_; | 100 BrowserDistribution* dist_; |
100 | 101 |
101 ScopedTempDir temp_dir_; | 102 ScopedTempDir temp_dir_; |
102 }; | 103 }; |
103 }; | 104 }; |
104 | 105 |
105 // Test that we can open archives successfully. | 106 // Test that we can open archives successfully. |
106 TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { | 107 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { |
107 // Create an executable in test path by copying ourself to it. | 108 // Create an executable in test path by copying ourself to it. |
108 wchar_t exe_full_path_str[MAX_PATH]; | 109 wchar_t exe_full_path_str[MAX_PATH]; |
109 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 110 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
110 FilePath exe_full_path(exe_full_path_str); | 111 FilePath exe_full_path(exe_full_path_str); |
111 | 112 |
112 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); | 113 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); |
113 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); | 114 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); |
114 | 115 |
115 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); | 116 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); |
116 const std::wstring description(L"dummy description"); | 117 const std::wstring description(L"dummy description"); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 L"", | 164 L"", |
164 description2, | 165 description2, |
165 exe_path.value(), | 166 exe_path.value(), |
166 dist_->GetIconIndex(), | 167 dist_->GetIconIndex(), |
167 ShellUtil::SHORTCUT_NO_OPTIONS)); | 168 ShellUtil::SHORTCUT_NO_OPTIONS)); |
168 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), | 169 EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), |
169 shortcut_path.value(), | 170 shortcut_path.value(), |
170 description2, 1)); | 171 description2, 1)); |
171 } | 172 } |
172 | 173 |
173 TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { | 174 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { |
174 // Run this test on Vista+ only if we are running elevated. | 175 // Run this test on Vista+ only if we are running elevated. |
175 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { | 176 if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { |
176 LOG(ERROR) << "Must be admin to run this test on Vista+"; | 177 LOG(ERROR) << "Must be admin to run this test on Vista+"; |
177 return; | 178 return; |
178 } | 179 } |
179 | 180 |
180 // Create an executable in test path by copying ourself to it. | 181 // Create an executable in test path by copying ourself to it. |
181 wchar_t exe_full_path_str[MAX_PATH]; | 182 wchar_t exe_full_path_str[MAX_PATH]; |
182 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); | 183 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); |
183 FilePath exe_full_path(exe_full_path_str); | 184 FilePath exe_full_path(exe_full_path_str); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 second_profile_shortcut_path.value(), | 357 second_profile_shortcut_path.value(), |
357 description, | 358 description, |
358 0)); | 359 0)); |
359 std::vector<string16> profile_names; | 360 std::vector<string16> profile_names; |
360 profile_names.push_back(default_profile_shortcut_name); | 361 profile_names.push_back(default_profile_shortcut_name); |
361 profile_names.push_back(second_profile_shortcut_name); | 362 profile_names.push_back(second_profile_shortcut_name); |
362 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 363 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
363 profile_names)); | 364 profile_names)); |
364 } | 365 } |
365 | 366 |
366 TEST_F(ShellUtilTest, BuildAppModelIdBasic) { | 367 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { |
367 std::vector<string16> components; | 368 std::vector<string16> components; |
368 const string16 base_app_id(dist_->GetBaseAppId()); | 369 const string16 base_app_id(dist_->GetBaseAppId()); |
369 components.push_back(base_app_id); | 370 components.push_back(base_app_id); |
370 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); | 371 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); |
371 } | 372 } |
372 | 373 |
373 TEST_F(ShellUtilTest, BuildAppModelIdManySmall) { | 374 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) { |
374 std::vector<string16> components; | 375 std::vector<string16> components; |
375 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); | 376 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); |
376 components.push_back(suffixed_app_id); | 377 components.push_back(suffixed_app_id); |
377 components.push_back(L"Default"); | 378 components.push_back(L"Default"); |
378 components.push_back(L"Test"); | 379 components.push_back(L"Test"); |
379 ASSERT_EQ(suffixed_app_id + L".Default.Test", | 380 ASSERT_EQ(suffixed_app_id + L".Default.Test", |
380 ShellUtil::BuildAppModelId(components)); | 381 ShellUtil::BuildAppModelId(components)); |
381 } | 382 } |
382 | 383 |
383 TEST_F(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { | 384 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) { |
384 std::vector<string16> components; | 385 std::vector<string16> components; |
385 const string16 long_appname( | 386 const string16 long_appname( |
386 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 387 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
387 L"that_goes_over_64_characters"); | 388 L"that_goes_over_64_characters"); |
388 components.push_back(long_appname); | 389 components.push_back(long_appname); |
389 components.push_back(L"Default"); | 390 components.push_back(L"Default"); |
390 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", | 391 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", |
391 ShellUtil::BuildAppModelId(components)); | 392 ShellUtil::BuildAppModelId(components)); |
392 } | 393 } |
393 | 394 |
394 TEST_F(ShellUtilTest, BuildAppModelIdLongEverything) { | 395 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) { |
395 std::vector<string16> components; | 396 std::vector<string16> components; |
396 const string16 long_appname( | 397 const string16 long_appname( |
397 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" | 398 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |
398 L"that_goes_over_64_characters"); | 399 L"that_goes_over_64_characters"); |
399 components.push_back(long_appname); | 400 components.push_back(long_appname); |
400 components.push_back( | 401 components.push_back( |
401 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); | 402 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); |
402 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); | 403 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); |
403 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); | 404 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); |
404 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", | 405 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", |
405 constructed_app_id); | 406 constructed_app_id); |
406 } | 407 } |
408 | |
409 TEST(ShellUtilTest, MD5DigestToBase32) { | |
robertshield
2012/06/22 19:20:22
Please add the test cases from http://tools.ietf.o
gab
2012/06/22 20:32:12
Done (which forced me to split the implementation
| |
410 base::MD5Digest digest = { 'f', 'o', 'o', 'b', 'a', 'f', 'o', 'o', 'b', 'a', | |
411 'f', 'o', 'o', 'b', 'a', 'f' }; | |
412 EXPECT_EQ(L"MZXW6YTBMZXW6YTBMZXW6YTBMY", | |
413 ShellUtil::MD5DigestToBase32(digest)); | |
414 } | |
OLD | NEW |