blob: c65f7a56ba2cee4e306f01b0a8481f21d3993b3f [file] [log] [blame]
[email protected]935aa542010-10-15 01:59:151// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]640517f2008-10-30 23:54:045#include "base/path_service.h"
6
initial.commitd7cae122008-07-26 21:49:387#include "base/basictypes.h"
8#include "base/file_util.h"
[email protected]640517f2008-10-30 23:54:049#include "base/file_path.h"
[email protected]6723f832008-08-11 15:38:2710#if defined(OS_WIN)
[email protected]935aa542010-10-15 01:59:1511#include "base/win/windows_version.h"
[email protected]6723f832008-08-11 15:38:2712#endif
initial.commitd7cae122008-07-26 21:49:3813#include "testing/gtest/include/gtest/gtest.h"
[email protected]09ad1e622008-08-07 20:23:0914#include "testing/gtest/include/gtest/gtest-spi.h"
[email protected]23887f04f2008-12-02 19:20:1515#include "testing/platform_test.h"
initial.commitd7cae122008-07-26 21:49:3816
17namespace {
initial.commitd7cae122008-07-26 21:49:3818
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) {
[email protected]640517f2008-10-30 23:54:0422 FilePath path;
initial.commitd7cae122008-07-26 21:49:3823 bool result = PathService::Get(dir_type, &path);
[email protected]d8a80d62010-11-23 22:39:3024#if defined(OS_POSIX)
25 // If chromium has never been started on this account, the cache path will not
26 // exist.
27 if (dir_type == base::DIR_USER_CACHE)
28 return result && !path.value().empty();
29#endif
[email protected]640517f2008-10-30 23:54:0430 return result && !path.value().empty() && file_util::PathExists(path);
initial.commitd7cae122008-07-26 21:49:3831}
32
[email protected]6723f832008-08-11 15:38:2733#if defined(OS_WIN)
[email protected]09ad1e622008-08-07 20:23:0934// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
[email protected]0cfda1e2008-08-07 23:59:0435bool ReturnsInvalidPath(int dir_type) {
[email protected]b65de8b92009-09-14 19:36:3136 FilePath path;
[email protected]09ad1e622008-08-07 20:23:0937 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
[email protected]0cfda1e2008-08-07 23:59:0438 return !result && path.empty();
[email protected]09ad1e622008-08-07 20:23:0939}
[email protected]6723f832008-08-11 15:38:2740#endif
[email protected]09ad1e622008-08-07 20:23:0941
42} // namespace
43
[email protected]ed2f2332008-08-20 15:59:4944// On the Mac this winds up using some autoreleased objects, so we need to
45// be a PlatformTest.
46typedef PlatformTest PathServiceTest;
47
initial.commitd7cae122008-07-26 21:49:3848// Test that all PathService::Get calls return a value and a true result
49// in the development environment. (This test was created because a few
50// later changes to Get broke the semantics of the function and yielded the
51// correct value while returning false.)
[email protected]ed2f2332008-08-20 15:59:4952TEST_F(PathServiceTest, Get) {
initial.commitd7cae122008-07-26 21:49:3853 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
54 EXPECT_PRED1(ReturnsValidPath, key);
55 }
[email protected]405a64b2009-09-16 21:03:4456#if defined(OS_WIN)
[email protected]1010f7d2008-08-06 16:29:4457 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
[email protected]09ad1e622008-08-07 20:23:0958 if (key == base::DIR_LOCAL_APP_DATA_LOW &&
[email protected]935aa542010-10-15 01:59:1559 base::win::GetVersion() < base::win::VERSION_VISTA) {
[email protected]09ad1e622008-08-07 20:23:0960 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to
61 // fail.
[email protected]0cfda1e2008-08-07 23:59:0462 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0963 } else {
[email protected]0cfda1e2008-08-07 23:59:0464 EXPECT_TRUE(ReturnsValidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0965 }
[email protected]1010f7d2008-08-06 16:29:4466 }
[email protected]405a64b2009-09-16 21:03:4467#elif defined(OS_MACOSX)
68 for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) {
69 EXPECT_PRED1(ReturnsValidPath, key);
70 }
[email protected]1010f7d2008-08-06 16:29:4471#endif
initial.commitd7cae122008-07-26 21:49:3872}