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

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

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

Powered by Google App Engine
This is Rietveld 408576698