Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/installer/util/shell_util_unittest.cc

Issue 10958009: Revert 157667 - Add new PathService paths for Windows' All Users Desktop and Quick Launch folders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
5 #include <fstream> 7 #include <fstream>
6 #include <vector> 8 #include <vector>
7 9
8 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/path_service.h"
9 #include "base/md5.h" 12 #include "base/md5.h"
10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
12 #include "base/string16.h" 14 #include "base/string16.h"
13 #include "base/string_util.h" 15 #include "base/string_util.h"
14 #include "base/test/test_shortcut_win.h" 16 #include "base/test/test_shortcut_win.h"
15 #include "base/win/shortcut.h" 17 #include "base/win/shortcut.h"
16 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
17 #include "chrome/installer/util/browser_distribution.h" 19 #include "chrome/installer/util/browser_distribution.h"
18 #include "chrome/installer/util/master_preferences.h" 20 #include "chrome/installer/util/master_preferences.h"
19 #include "chrome/installer/util/shell_util.h" 21 #include "chrome/installer/util/shell_util.h"
20 #include "chrome/installer/util/util_constants.h" 22 #include "chrome/installer/util/util_constants.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace { 25 namespace {
24 26
25 class ShellUtilShortcutTest : public testing::Test { 27 class ShellUtilTestWithDirAndDist : public testing::Test {
26 protected: 28 protected:
27 virtual void SetUp() OVERRIDE { 29 virtual void SetUp() {
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
28 dist_ = BrowserDistribution::GetDistribution(); 31 dist_ = BrowserDistribution::GetDistribution();
29 ASSERT_TRUE(dist_ != NULL); 32 ASSERT_TRUE(dist_ != NULL);
30
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir());
33 ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir());
34 ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP,
35 fake_user_desktop_.path()));
36 ASSERT_TRUE(PathService::Override(base::DIR_COMMON_DESKTOP,
37 fake_common_desktop_.path()));
38 } 33 }
39 34
40 BrowserDistribution* dist_; 35 BrowserDistribution* dist_;
41 36
42 ScopedTempDir temp_dir_; 37 ScopedTempDir temp_dir_;
43
44 ScopedTempDir fake_user_desktop_;
45 ScopedTempDir fake_common_desktop_;
46 }; 38 };
47 39
48 // Returns the status of a call to base::win::VerifyShorcut for the properties 40 // Returns the status of a call to base::win::VerifyShorcut for the properties
49 // passed in. 41 // passed in.
50 // TODO(gab): This is only temporary while waiting for my upcoming CL that will 42 // TODO(gab): This is only temporary while waiting for my upcoming CL that will
51 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't 43 // massively refactor the shell_util shortcut methods' interface (i.e. I didn't
52 // want to adapt every test here for this half-changed state as they will change 44 // want to adapt every test here for this half-changed state as they will change
53 // again very soon). 45 // again very soon).
54 base::win::VerifyShortcutStatus VerifyChromeShortcut( 46 base::win::VerifyShortcutStatus VerifyChromeShortcut(
55 const FilePath& exe_path, 47 const FilePath& exe_path,
56 const FilePath& shortcut_path, 48 const FilePath& shortcut_path,
57 const string16& description, 49 const string16& description,
58 int icon_index) { 50 int icon_index) {
59 base::win::ShortcutProperties expected_properties; 51 base::win::ShortcutProperties expected_properties;
60 expected_properties.set_target(exe_path); 52 expected_properties.set_target(exe_path);
61 expected_properties.set_description(description); 53 expected_properties.set_description(description);
62 expected_properties.set_icon(exe_path, icon_index); 54 expected_properties.set_icon(exe_path, icon_index);
63 return base::win::VerifyShortcut(shortcut_path, expected_properties); 55 return base::win::VerifyShortcut(shortcut_path, expected_properties);
64 } 56 }
65 57
66 } 58 }
67 59
68 // Test that we can open archives successfully. 60 // Test that we can open archives successfully.
69 TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { 61 TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) {
70 // Create an executable in test path by copying ourself to it. 62 // Create an executable in test path by copying ourself to it.
71 wchar_t exe_full_path_str[MAX_PATH]; 63 wchar_t exe_full_path_str[MAX_PATH];
72 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 64 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
73 FilePath exe_full_path(exe_full_path_str); 65 FilePath exe_full_path(exe_full_path_str);
74 66
75 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 67 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
76 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 68 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
77 69
78 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); 70 FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk");
79 const string16 description(L"dummy description"); 71 const string16 description(L"dummy description");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 shortcut_path.value(), 115 shortcut_path.value(),
124 string16(), 116 string16(),
125 description2, 117 description2,
126 exe_path.value(), 118 exe_path.value(),
127 dist_->GetIconIndex(), 119 dist_->GetIconIndex(),
128 ShellUtil::SHORTCUT_NO_OPTIONS)); 120 ShellUtil::SHORTCUT_NO_OPTIONS));
129 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, 121 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS,
130 VerifyChromeShortcut(exe_path, shortcut_path, description2, 1)); 122 VerifyChromeShortcut(exe_path, shortcut_path, description2, 1));
131 } 123 }
132 124
133 TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { 125 TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) {
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
134 // Create an executable in test path by copying ourself to it. 132 // Create an executable in test path by copying ourself to it.
135 wchar_t exe_full_path_str[MAX_PATH]; 133 wchar_t exe_full_path_str[MAX_PATH];
136 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); 134 EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0);
137 FilePath exe_full_path(exe_full_path_str); 135 FilePath exe_full_path(exe_full_path_str);
138 136
139 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe"); 137 FilePath exe_path = temp_dir_.path().AppendASCII("setup.exe");
140 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path)); 138 EXPECT_TRUE(file_util::CopyFile(exe_full_path, exe_path));
141 139
142 const string16 description(L"dummy description"); 140 const string16 description(L"dummy description");
143 141
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS, 299 EXPECT_EQ(base::win::VERIFY_SHORTCUT_SUCCESS,
302 VerifyChromeShortcut( 300 VerifyChromeShortcut(
303 exe_path, second_profile_shortcut_path, description, 0)); 301 exe_path, second_profile_shortcut_path, description, 0));
304 std::vector<string16> profile_names; 302 std::vector<string16> profile_names;
305 profile_names.push_back(default_profile_shortcut_name); 303 profile_names.push_back(default_profile_shortcut_name);
306 profile_names.push_back(second_profile_shortcut_name); 304 profile_names.push_back(second_profile_shortcut_name);
307 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( 305 EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
308 profile_names)); 306 profile_names));
309 } 307 }
310 308
311 TEST(ShellUtilTest, BuildAppModelIdBasic) { 309 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) {
312 std::vector<string16> components; 310 std::vector<string16> components;
313 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 311 const string16 base_app_id(dist_->GetBaseAppId());
314 const string16 base_app_id(dist->GetBaseAppId());
315 components.push_back(base_app_id); 312 components.push_back(base_app_id);
316 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); 313 ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components));
317 } 314 }
318 315
319 TEST(ShellUtilTest, BuildAppModelIdManySmall) { 316 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) {
320 std::vector<string16> components; 317 std::vector<string16> components;
321 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 318 const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab"));
322 const string16 suffixed_app_id(dist->GetBaseAppId().append(L".gab"));
323 components.push_back(suffixed_app_id); 319 components.push_back(suffixed_app_id);
324 components.push_back(L"Default"); 320 components.push_back(L"Default");
325 components.push_back(L"Test"); 321 components.push_back(L"Test");
326 ASSERT_EQ(suffixed_app_id + L".Default.Test", 322 ASSERT_EQ(suffixed_app_id + L".Default.Test",
327 ShellUtil::BuildAppModelId(components)); 323 ShellUtil::BuildAppModelId(components));
328 } 324 }
329 325
330 TEST(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { 326 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) {
331 std::vector<string16> components; 327 std::vector<string16> components;
332 const string16 long_appname( 328 const string16 long_appname(
333 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" 329 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_"
334 L"that_goes_over_64_characters"); 330 L"that_goes_over_64_characters");
335 components.push_back(long_appname); 331 components.push_back(long_appname);
336 components.push_back(L"Default"); 332 components.push_back(L"Default");
337 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default", 333 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.Default",
338 ShellUtil::BuildAppModelId(components)); 334 ShellUtil::BuildAppModelId(components));
339 } 335 }
340 336
341 TEST(ShellUtilTest, BuildAppModelIdLongEverything) { 337 TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) {
342 std::vector<string16> components; 338 std::vector<string16> components;
343 const string16 long_appname( 339 const string16 long_appname(
344 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" 340 L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_"
345 L"that_goes_over_64_characters"); 341 L"that_goes_over_64_characters");
346 components.push_back(long_appname); 342 components.push_back(long_appname);
347 components.push_back( 343 components.push_back(
348 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible"); 344 L"A_crazy_profile_name_not_even_sure_whether_that_is_possible");
349 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components)); 345 const string16 constructed_app_id(ShellUtil::BuildAppModelId(components));
350 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength); 346 ASSERT_LE(constructed_app_id.length(), installer::kMaxAppModelIdLength);
351 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible", 347 ASSERT_EQ(L"Chrome.a_user_wer_64_characters.A_crazy_profilethat_is_possible",
(...skipping 27 matching lines...) Expand all
379 375
380 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ", 376 const string16 expected[] = { L"", L"MY", L"MZXQ", L"MZXW6", L"MZXW6YQ",
381 L"MZXW6YTB", L"MZXW6YTBOI"}; 377 L"MZXW6YTB", L"MZXW6YTBOI"};
382 378
383 // Run the tests, with one more letter in the input every pass. 379 // Run the tests, with one more letter in the input every pass.
384 for (int i = 0; i < arraysize(expected); ++i) { 380 for (int i = 0; i < arraysize(expected); ++i) {
385 ASSERT_EQ(expected[i], 381 ASSERT_EQ(expected[i],
386 ShellUtil::ByteArrayToBase32(test_array, i)); 382 ShellUtil::ByteArrayToBase32(test_array, i));
387 } 383 }
388 } 384 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698