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

Side by Side Diff: base/path_service_unittest.cc

Issue 432273005: Fix shortcut tests and remove legacy shortcut code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't check system-level Quick Launch folder on uninstall. Created 6 years, 4 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 | « base/base_paths_win.cc ('k') | chrome/installer/setup/install.cc » ('j') | 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 "base/path_service.h" 5 #include "base/path_service.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "testing/gtest/include/gtest/gtest-spi.h" 13 #include "testing/gtest/include/gtest/gtest-spi.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
16 16
17 #if defined(OS_WIN) 17 #if defined(OS_WIN)
18 #include <userenv.h>
19 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
20 // userenv.dll is required for GetDefaultUserProfileDirectory().
21 #pragma comment(lib, "userenv.lib")
22 #endif 19 #endif
23 20
24 namespace { 21 namespace {
25 22
26 // Returns true if PathService::Get returns true and sets the path parameter 23 // Returns true if PathService::Get returns true and sets the path parameter
27 // to non-empty for the given PathService::DirType enumeration value. 24 // to non-empty for the given PathService::DirType enumeration value.
28 bool ReturnsValidPath(int dir_type) { 25 bool ReturnsValidPath(int dir_type) {
29 base::FilePath path; 26 base::FilePath path;
30 bool result = PathService::Get(dir_type, &path); 27 bool result = PathService::Get(dir_type, &path);
31 28
32 // Some paths might not exist on some platforms in which case confirming 29 // Some paths might not exist on some platforms in which case confirming
33 // |result| is true and !path.empty() is the best we can do. 30 // |result| is true and !path.empty() is the best we can do.
34 bool check_path_exists = true; 31 bool check_path_exists = true;
35 #if defined(OS_POSIX) 32 #if defined(OS_POSIX)
36 // If chromium has never been started on this account, the cache path may not 33 // If chromium has never been started on this account, the cache path may not
37 // exist. 34 // exist.
38 if (dir_type == base::DIR_CACHE) 35 if (dir_type == base::DIR_CACHE)
39 check_path_exists = false; 36 check_path_exists = false;
40 #endif 37 #endif
41 #if defined(OS_LINUX) 38 #if defined(OS_LINUX)
42 // On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop), 39 // On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop),
43 // but it doesn't exist. 40 // but it doesn't exist.
44 if (dir_type == base::DIR_USER_DESKTOP) 41 if (dir_type == base::DIR_USER_DESKTOP)
45 check_path_exists = false; 42 check_path_exists = false;
46 #endif 43 #endif
47 #if defined(OS_WIN) 44 #if defined(OS_WIN)
48 if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH) { 45 if (dir_type == base::DIR_TASKBAR_PINS) {
49 // On Windows XP, the Quick Launch folder for the "Default User" doesn't
50 // exist by default. At least confirm that the path returned begins with the
51 // Default User's profile path.
52 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
53 wchar_t default_profile_path[MAX_PATH];
54 DWORD size = arraysize(default_profile_path);
55 return (result &&
56 ::GetDefaultUserProfileDirectory(default_profile_path, &size) &&
57 StartsWith(path.value(), default_profile_path, false));
58 }
59 } else if (dir_type == base::DIR_TASKBAR_PINS) {
60 // There is no pinned-to-taskbar shortcuts prior to Win7. 46 // There is no pinned-to-taskbar shortcuts prior to Win7.
61 if (base::win::GetVersion() < base::win::VERSION_WIN7) 47 if (base::win::GetVersion() < base::win::VERSION_WIN7)
62 check_path_exists = false; 48 check_path_exists = false;
63 } 49 }
64 #endif 50 #endif
65 #if defined(OS_MACOSX) 51 #if defined(OS_MACOSX)
66 if (dir_type != base::DIR_EXE && dir_type != base::DIR_MODULE && 52 if (dir_type != base::DIR_EXE && dir_type != base::DIR_MODULE &&
67 dir_type != base::FILE_EXE && dir_type != base::FILE_MODULE) { 53 dir_type != base::FILE_EXE && dir_type != base::FILE_MODULE) {
68 if (path.ReferencesParent()) 54 if (path.ReferencesParent())
69 return false; 55 return false;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
238 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); 224 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
239 base::FilePath new_user_data_dir; 225 base::FilePath new_user_data_dir;
240 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); 226 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
241 EXPECT_NE(original_user_data_dir, new_user_data_dir); 227 EXPECT_NE(original_user_data_dir, new_user_data_dir);
242 228
243 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); 229 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
244 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); 230 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
245 EXPECT_EQ(original_user_data_dir, new_user_data_dir); 231 EXPECT_EQ(original_user_data_dir, new_user_data_dir);
246 } 232 }
OLDNEW
« no previous file with comments | « base/base_paths_win.cc ('k') | chrome/installer/setup/install.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698