blob: 32f49b21498d5030ada37b22b179a3473d3ecf78 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004
evanm@google.com874d1672008-10-31 08:54:04 +09005#include "base/path_service.h"
6
initial.commit3f4a7322008-07-27 06:49:38 +09007#include "base/basictypes.h"
8#include "base/file_util.h"
evanm@google.com874d1672008-10-31 08:54:04 +09009#include "base/file_path.h"
erikkay@google.com3620e4c2008-08-12 00:38:27 +090010#if defined(OS_WIN)
maruel@google.com15cfc7f2008-08-08 05:23:09 +090011#include "base/win_util.h"
erikkay@google.com3620e4c2008-08-12 00:38:27 +090012#endif
initial.commit3f4a7322008-07-27 06:49:38 +090013#include "testing/gtest/include/gtest/gtest.h"
maruel@google.com15cfc7f2008-08-08 05:23:09 +090014#include "testing/gtest/include/gtest/gtest-spi.h"
jeremy@chromium.org0d8eba72008-12-03 04:20:15 +090015#include "testing/platform_test.h"
initial.commit3f4a7322008-07-27 06:49:38 +090016
17namespace {
initial.commit3f4a7322008-07-27 06:49:38 +090018
19// Returns true if PathService::Get returns true and sets the path parameter
20// to non-empty for the given PathService::DirType enumeration value.
21bool ReturnsValidPath(int dir_type) {
evanm@google.com874d1672008-10-31 08:54:04 +090022 FilePath path;
initial.commit3f4a7322008-07-27 06:49:38 +090023 bool result = PathService::Get(dir_type, &path);
evanm@google.com874d1672008-10-31 08:54:04 +090024 return result && !path.value().empty() && file_util::PathExists(path);
initial.commit3f4a7322008-07-27 06:49:38 +090025}
26
erikkay@google.com3620e4c2008-08-12 00:38:27 +090027#if defined(OS_WIN)
maruel@google.com15cfc7f2008-08-08 05:23:09 +090028// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
maruel@google.com31177672008-08-08 08:59:04 +090029bool ReturnsInvalidPath(int dir_type) {
phajdan.jr@chromium.orgc8008582009-09-15 04:36:31 +090030 FilePath path;
maruel@google.com15cfc7f2008-08-08 05:23:09 +090031 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
maruel@google.com31177672008-08-08 08:59:04 +090032 return !result && path.empty();
maruel@google.com15cfc7f2008-08-08 05:23:09 +090033}
erikkay@google.com3620e4c2008-08-12 00:38:27 +090034#endif
maruel@google.com15cfc7f2008-08-08 05:23:09 +090035
36} // namespace
37
erikkay@google.comf2406842008-08-21 00:59:49 +090038// On the Mac this winds up using some autoreleased objects, so we need to
39// be a PlatformTest.
40typedef PlatformTest PathServiceTest;
41
initial.commit3f4a7322008-07-27 06:49:38 +090042// 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.comf2406842008-08-21 00:59:49 +090046TEST_F(PathServiceTest, Get) {
initial.commit3f4a7322008-07-27 06:49:38 +090047 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
48 EXPECT_PRED1(ReturnsValidPath, key);
49 }
erikkay@google.com1d4507f2008-08-07 01:29:44 +090050#ifdef OS_WIN
51 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
maruel@google.com15cfc7f2008-08-08 05:23:09 +090052 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.com31177672008-08-08 08:59:04 +090056 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
maruel@google.com15cfc7f2008-08-08 05:23:09 +090057 } else {
maruel@google.com31177672008-08-08 08:59:04 +090058 EXPECT_TRUE(ReturnsValidPath(key)) << key;
maruel@google.com15cfc7f2008-08-08 05:23:09 +090059 }
erikkay@google.com1d4507f2008-08-07 01:29:44 +090060 }
61#endif
initial.commit3f4a7322008-07-27 06:49:38 +090062}