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 "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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #pragma comment(lib, "userenv.lib") | 21 #pragma comment(lib, "userenv.lib") |
22 #endif | 22 #endif |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Returns true if PathService::Get returns true and sets the path parameter | 26 // Returns true if PathService::Get returns true and sets the path parameter |
27 // to non-empty for the given PathService::DirType enumeration value. | 27 // to non-empty for the given PathService::DirType enumeration value. |
28 bool ReturnsValidPath(int dir_type) { | 28 bool ReturnsValidPath(int dir_type) { |
29 FilePath path; | 29 FilePath path; |
30 bool result = PathService::Get(dir_type, &path); | 30 bool result = PathService::Get(dir_type, &path); |
31 // Some paths might not exist on some platforms in which case confirming | |
32 // |result| is true and !path.empty() is the best we can do. | |
33 bool check_path_exists = true; | |
31 #if defined(OS_POSIX) | 34 #if defined(OS_POSIX) |
32 // If chromium has never been started on this account, the cache path may not | 35 // If chromium has never been started on this account, the cache path may not |
33 // exist. | 36 // exist. |
34 if (dir_type == base::DIR_CACHE) | 37 if (dir_type == base::DIR_CACHE) |
35 return result && !path.empty(); | 38 check_path_exists = false; |
36 #endif | 39 #endif |
37 #if defined(OS_LINUX) | 40 #if defined(OS_LINUX) |
38 // On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop), | 41 // On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop), |
39 // but it doesn't exist. | 42 // but it doesn't exist. |
40 if (dir_type == base::DIR_USER_DESKTOP) | 43 if (dir_type == base::DIR_USER_DESKTOP) |
41 return result && !path.empty(); | 44 check_path_exists = false; |
42 #endif | 45 #endif |
43 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
44 // On Windows XP, the Quick Launch folder for the "Default User" doesn't exist | 47 if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH) { |
45 // by default. At least confirm that the path returned begins with the | 48 // On Windows XP, the Quick Launch folder for the "Default User" doesn't |
46 // Default User's profile path. | 49 // exist by default. At least confirm that the path returned begins with the |
47 if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH && | 50 // Default User's profile path. |
48 base::win::GetVersion() < base::win::VERSION_VISTA) { | 51 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
49 wchar_t default_profile_path[MAX_PATH]; | 52 wchar_t default_profile_path[MAX_PATH]; |
50 DWORD size = arraysize(default_profile_path); | 53 DWORD size = arraysize(default_profile_path); |
51 return (result && | 54 return (result && |
52 ::GetDefaultUserProfileDirectory(default_profile_path, &size) && | 55 ::GetDefaultUserProfileDirectory(default_profile_path, &size) && |
53 StartsWith(path.value(), default_profile_path, false)); | 56 StartsWith(path.value(), default_profile_path, false)); |
57 } | |
58 } else if (dir_type == base::DIR_TASKBAR_PINS) { | |
59 // There is no pinned-to-taskbar shortcuts prior to Win7. | |
60 if(base::win::GetVersion() < base::win::VERSION_WIN7) | |
61 check_path_exists = false; | |
54 } | 62 } |
55 #endif | 63 #endif |
56 return result && !path.empty() && file_util::PathExists(path); | 64 return result && !path.empty() && (!check_path_exists || |
65 file_util::PathExists(path)); | |
robertshield
2012/11/06 14:31:46
nice :)
| |
57 } | 66 } |
58 | 67 |
59 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
60 // Function to test any directory keys that are not supported on some versions | 69 // Function to test any directory keys that are not supported on some versions |
61 // of Windows. Checks that the function fails and that the returned path is | 70 // of Windows. Checks that the function fails and that the returned path is |
62 // empty. | 71 // empty. |
63 bool ReturnsInvalidPath(int dir_type) { | 72 bool ReturnsInvalidPath(int dir_type) { |
64 FilePath path; | 73 FilePath path; |
65 bool result = PathService::Get(dir_type, &path); | 74 bool result = PathService::Get(dir_type, &path); |
66 return !result && path.empty(); | 75 return !result && path.empty(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 196 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
188 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); | 197 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); |
189 FilePath new_user_data_dir; | 198 FilePath new_user_data_dir; |
190 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); | 199 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); |
191 EXPECT_NE(original_user_data_dir, new_user_data_dir); | 200 EXPECT_NE(original_user_data_dir, new_user_data_dir); |
192 | 201 |
193 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); | 202 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); |
194 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); | 203 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); |
195 EXPECT_EQ(original_user_data_dir, new_user_data_dir); | 204 EXPECT_EQ(original_user_data_dir, new_user_data_dir); |
196 } | 205 } |
OLD | NEW |