| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 11 #include "base/win_util.h" | 11 #include "base/win_util.h" |
| 12 #endif | 12 #endif |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/gtest/include/gtest/gtest-spi.h" | 14 #include "testing/gtest/include/gtest/gtest-spi.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Returns true if PathService::Get returns true and sets the path parameter | 19 // Returns true if PathService::Get returns true and sets the path parameter |
| 20 // to non-empty for the given PathService::DirType enumeration value. | 20 // to non-empty for the given PathService::DirType enumeration value. |
| 21 bool ReturnsValidPath(int dir_type) { | 21 bool ReturnsValidPath(int dir_type) { |
| 22 FilePath path; | 22 FilePath path; |
| 23 bool result = PathService::Get(dir_type, &path); | 23 bool result = PathService::Get(dir_type, &path); |
| 24 return result && !path.value().empty() && file_util::PathExists(path); | 24 return result && !path.value().empty() && file_util::PathExists(path); |
| 25 } | 25 } |
| 26 | 26 |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. | 28 // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. |
| 29 bool ReturnsInvalidPath(int dir_type) { | 29 bool ReturnsInvalidPath(int dir_type) { |
| 30 std::wstring path; | 30 FilePath path; |
| 31 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); | 31 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); |
| 32 return !result && path.empty(); | 32 return !result && path.empty(); |
| 33 } | 33 } |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 // On the Mac this winds up using some autoreleased objects, so we need to | 38 // On the Mac this winds up using some autoreleased objects, so we need to |
| 39 // be a PlatformTest. | 39 // be a PlatformTest. |
| 40 typedef PlatformTest PathServiceTest; | 40 typedef PlatformTest PathServiceTest; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { | 53 win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { |
| 54 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to | 54 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to |
| 55 // fail. | 55 // fail. |
| 56 EXPECT_TRUE(ReturnsInvalidPath(key)) << key; | 56 EXPECT_TRUE(ReturnsInvalidPath(key)) << key; |
| 57 } else { | 57 } else { |
| 58 EXPECT_TRUE(ReturnsValidPath(key)) << key; | 58 EXPECT_TRUE(ReturnsValidPath(key)) << key; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 #endif | 61 #endif |
| 62 } | 62 } |
| OLD | NEW |