1 // Copyright (c) 2010 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.
5 #include "chrome/common/chrome_paths_internal.h"
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/path_service.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 // Test the behavior of chrome::GetUserCacheDirectory.
15 // See that function's comments for discussion of the subtleties.
16 TEST(ChromePaths
, UserCacheDir
) {
17 FilePath test_profile_dir
, cache_dir
;
18 #if defined(OS_MACOSX)
19 ASSERT_TRUE(PathService::Get(base::DIR_APP_DATA
, &test_profile_dir
));
20 test_profile_dir
= test_profile_dir
.Append("foobar");
21 FilePath expected_cache_dir
;
22 ASSERT_TRUE(PathService::Get(base::DIR_CACHE
, &expected_cache_dir
));
23 expected_cache_dir
= expected_cache_dir
.Append("foobar");
25 FilePath homedir
= file_util::GetHomeDir();
26 // Note: we assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their
28 test_profile_dir
= homedir
.Append(".config/foobar");
29 FilePath expected_cache_dir
= homedir
.Append(".cache/foobar");
32 // Verify that a profile in the special platform-specific source
33 // location ends up in the special target location.
34 #if !defined(OS_WIN) // No special behavior on Windows.
35 chrome::GetUserCacheDirectory(test_profile_dir
, &cache_dir
);
36 EXPECT_EQ(expected_cache_dir
.value(), cache_dir
.value());
39 // Verify that a profile in some other random directory doesn't use
40 // the special cache dir.
41 test_profile_dir
= FilePath(FILE_PATH_LITERAL("/some/other/path"));
42 chrome::GetUserCacheDirectory(test_profile_dir
, &cache_dir
);
43 EXPECT_EQ(test_profile_dir
.value(), cache_dir
.value());