diff options
author | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 20:23:09 +0000 |
---|---|---|
committer | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 20:23:09 +0000 |
commit | 09ad1e629a88f99d2e93797304f4a6060915e228 (patch) | |
tree | e69ebeea9d6aa79cf134bc892e3b0573abe10c86 /base | |
parent | e82b706db2d3da13746b66fd5ab7d5dd38fab17e (diff) | |
download | chromium_src-09ad1e629a88f99d2e93797304f4a6060915e228.zip chromium_src-09ad1e629a88f99d2e93797304f4a6060915e228.tar.gz chromium_src-09ad1e629a88f99d2e93797304f4a6060915e228.tar.bz2 |
Improve PathServiceTest test by verifying that the returned path exists.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@533 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base_paths_win.cc | 6 | ||||
-rw-r--r-- | base/path_service.cc | 6 | ||||
-rw-r--r-- | base/path_service_unittest.cc | 31 |
3 files changed, 34 insertions, 9 deletions
diff --git a/base/base_paths_win.cc b/base/base_paths_win.cc index 9afd875..fe3e1df 100644 --- a/base/base_paths_win.cc +++ b/base/base_paths_win.cc @@ -32,7 +32,9 @@ #include <shlobj.h> #include "base/file_util.h" +#include "base/logging.h" #include "base/path_service.h" +#include "base/win_util.h" // This is here for the sole purpose of looking up the corresponding HMODULE. static int handle_lookup = 0; @@ -106,6 +108,10 @@ bool PathProviderWin(int key, std::wstring* result) { cur = system_buffer; break; case base::DIR_LOCAL_APP_DATA_LOW: + if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { + NOTREACHED(); + return false; + } // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, system_buffer))) diff --git a/base/path_service.cc b/base/path_service.cc index 05f3010..12073f7 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -27,7 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "build/build_config.h" +#include "base/path_service.h" #ifdef OS_WIN #include <windows.h> @@ -36,11 +36,9 @@ #endif #include "base/hash_tables.h" -#include "base/path_service.h" - +#include "base/file_util.h" #include "base/lock.h" #include "base/logging.h" -#include "base/file_util.h" #include "base/string_util.h" namespace base { diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc index a63495d..2835d37 100644 --- a/base/path_service_unittest.cc +++ b/base/path_service_unittest.cc @@ -31,21 +31,29 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/win_util.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/gtest/include/gtest/gtest-spi.h" namespace { - class PathServiceTest : public testing::Test { - }; -}; // Returns true if PathService::Get returns true and sets the path parameter // to non-empty for the given PathService::DirType enumeration value. bool ReturnsValidPath(int dir_type) { std::wstring path; bool result = PathService::Get(dir_type, &path); - return result && !path.empty(); + return result && !path.empty() && file_util::PathExists(path); } +// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. +void GetPath() { + std::wstring path; + bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); + EXPECT_FALSE(result); +} + +} // namespace + // Test that all PathService::Get calls return a value and a true result // in the development environment. (This test was created because a few // later changes to Get broke the semantics of the function and yielded the @@ -56,7 +64,20 @@ TEST(PathServiceTest, Get) { } #ifdef OS_WIN for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) { - EXPECT_PRED1(ReturnsValidPath, key); + if (key == base::DIR_LOCAL_APP_DATA_LOW && + win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { + // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to + // fail. +#ifdef _DEBUG + EXPECT_FATAL_FAILURE(GetPath(), ":FATAL:base_paths_win.cc("); +#else + // In release, the DCHECK won't be hit. Still verify that + // PathService::Get() returns false. + GetPath(); +#endif + } else { + EXPECT_PRED1(ReturnsValidPath, key); + } } #endif } |