blob: 769a85079f22b4562d1ced294eee6d5d8e893a1f [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commitd7cae122008-07-26 21:49:384
5#include "base/basictypes.h"
6#include "base/file_util.h"
7#include "base/logging.h"
8#include "base/path_service.h"
[email protected]ed2f2332008-08-20 15:59:499#include "base/platform_test.h"
[email protected]6723f832008-08-11 15:38:2710#if defined(OS_WIN)
[email protected]09ad1e622008-08-07 20:23:0911#include "base/win_util.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"
initial.commitd7cae122008-07-26 21:49:3815
16namespace {
initial.commitd7cae122008-07-26 21:49:3817
18// Returns true if PathService::Get returns true and sets the path parameter
19// to non-empty for the given PathService::DirType enumeration value.
20bool ReturnsValidPath(int dir_type) {
21 std::wstring path;
22 bool result = PathService::Get(dir_type, &path);
[email protected]09ad1e622008-08-07 20:23:0923 return result && !path.empty() && file_util::PathExists(path);
initial.commitd7cae122008-07-26 21:49:3824}
25
[email protected]6723f832008-08-11 15:38:2726#if defined(OS_WIN)
[email protected]09ad1e622008-08-07 20:23:0927// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
[email protected]0cfda1e2008-08-07 23:59:0428bool ReturnsInvalidPath(int dir_type) {
[email protected]09ad1e622008-08-07 20:23:0929 std::wstring path;
30 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
[email protected]0cfda1e2008-08-07 23:59:0431 return !result && path.empty();
[email protected]09ad1e622008-08-07 20:23:0932}
[email protected]6723f832008-08-11 15:38:2733#endif
[email protected]09ad1e622008-08-07 20:23:0934
35} // namespace
36
[email protected]ed2f2332008-08-20 15:59:4937// On the Mac this winds up using some autoreleased objects, so we need to
38// be a PlatformTest.
39typedef PlatformTest PathServiceTest;
40
initial.commitd7cae122008-07-26 21:49:3841// Test that all PathService::Get calls return a value and a true result
42// in the development environment. (This test was created because a few
43// later changes to Get broke the semantics of the function and yielded the
44// correct value while returning false.)
[email protected]ed2f2332008-08-20 15:59:4945TEST_F(PathServiceTest, Get) {
initial.commitd7cae122008-07-26 21:49:3846 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
47 EXPECT_PRED1(ReturnsValidPath, key);
48 }
[email protected]1010f7d2008-08-06 16:29:4449#ifdef OS_WIN
50 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
[email protected]09ad1e622008-08-07 20:23:0951 if (key == base::DIR_LOCAL_APP_DATA_LOW &&
52 win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
53 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to
54 // fail.
[email protected]0cfda1e2008-08-07 23:59:0455 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0956 } else {
[email protected]0cfda1e2008-08-07 23:59:0457 EXPECT_TRUE(ReturnsValidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0958 }
[email protected]1010f7d2008-08-06 16:29:4459 }
60#endif
initial.commitd7cae122008-07-26 21:49:3861}
license.botbf09a502008-08-24 00:55:5562