license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 5 | #include "base/path_service.h" |
| 6 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 7 | #include "base/basictypes.h" |
| 8 | #include "base/file_util.h" |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 9 | #include "base/file_path.h" |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 10 | #if defined(OS_WIN) |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 11 | #include "base/win_util.h" |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 12 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest-spi.h" |
jeremy@chromium.org | 0d8eba7 | 2008-12-03 04:20:15 +0900 | [diff] [blame] | 15 | #include "testing/platform_test.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 16 | |
| 17 | namespace { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 18 | |
| 19 | // Returns true if PathService::Get returns true and sets the path parameter |
| 20 | // to non-empty for the given PathService::DirType enumeration value. |
| 21 | bool ReturnsValidPath(int dir_type) { |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 22 | FilePath path; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 23 | bool result = PathService::Get(dir_type, &path); |
evanm@google.com | 874d167 | 2008-10-31 08:54:04 +0900 | [diff] [blame] | 24 | return result && !path.value().empty() && file_util::PathExists(path); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 25 | } |
| 26 | |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 27 | #if defined(OS_WIN) |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 28 | // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 29 | bool ReturnsInvalidPath(int dir_type) { |
phajdan.jr@chromium.org | c800858 | 2009-09-15 04:36:31 +0900 | [diff] [blame^] | 30 | FilePath path; |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 31 | bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 32 | return !result && path.empty(); |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 33 | } |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 34 | #endif |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 35 | |
| 36 | } // namespace |
| 37 | |
erikkay@google.com | f240684 | 2008-08-21 00:59:49 +0900 | [diff] [blame] | 38 | // On the Mac this winds up using some autoreleased objects, so we need to |
| 39 | // be a PlatformTest. |
| 40 | typedef PlatformTest PathServiceTest; |
| 41 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 42 | // Test that all PathService::Get calls return a value and a true result |
| 43 | // in the development environment. (This test was created because a few |
| 44 | // later changes to Get broke the semantics of the function and yielded the |
| 45 | // correct value while returning false.) |
erikkay@google.com | f240684 | 2008-08-21 00:59:49 +0900 | [diff] [blame] | 46 | TEST_F(PathServiceTest, Get) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 47 | for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) { |
| 48 | EXPECT_PRED1(ReturnsValidPath, key); |
| 49 | } |
erikkay@google.com | 1d4507f | 2008-08-07 01:29:44 +0900 | [diff] [blame] | 50 | #ifdef OS_WIN |
| 51 | for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) { |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 52 | if (key == base::DIR_LOCAL_APP_DATA_LOW && |
| 53 | win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { |
| 54 | // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to |
| 55 | // fail. |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 56 | EXPECT_TRUE(ReturnsInvalidPath(key)) << key; |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 57 | } else { |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 58 | EXPECT_TRUE(ReturnsValidPath(key)) << key; |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 59 | } |
erikkay@google.com | 1d4507f | 2008-08-07 01:29:44 +0900 | [diff] [blame] | 60 | } |
| 61 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 62 | } |