1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/chrome_paths_internal.h"
#include <stdlib.h>
#include "base/base_paths.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome {
// Test the behavior of chrome::GetUserCacheDirectory.
// See that function's comments for discussion of the subtleties.
TEST(ChromePaths, UserCacheDir) {
base::FilePath test_profile_dir, cache_dir;
#if defined(OS_MAC)
ASSERT_TRUE(base::PathService::Get(base::DIR_APP_DATA, &test_profile_dir));
test_profile_dir = test_profile_dir.Append("foobar");
base::FilePath expected_cache_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_CACHE, &expected_cache_dir));
expected_cache_dir = expected_cache_dir.Append("foobar");
#elif(OS_ANDROID)
// No matter what the test_profile_dir is, Android always use the
// application's cache directory since multiple profiles are not
// supported.
base::FilePath expected_cache_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_CACHE, &expected_cache_dir));
#elif(OS_POSIX)
base::FilePath homedir;
base::PathService::Get(base::DIR_HOME, &homedir);
// Note: we assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their
// default settings.
test_profile_dir = homedir.Append(".config/foobar");
base::FilePath expected_cache_dir = homedir.Append(".cache/foobar");
#endif
// Verify that a profile in the special platform-specific source
// location ends up in the special target location. Ignore this assertion on
// platforms that don't use a special cache directory.
#if !defined(OS_WIN) && !BUILDFLAG(IS_LACROS)
GetUserCacheDirectory(test_profile_dir, &cache_dir);
EXPECT_EQ(expected_cache_dir.value(), cache_dir.value());
#endif
// Verify that a profile in some other random directory doesn't use
// the special cache dir.
test_profile_dir = base::FilePath(FILE_PATH_LITERAL("/some/other/path"));
GetUserCacheDirectory(test_profile_dir, &cache_dir);
#if defined(OS_ANDROID)
EXPECT_EQ(expected_cache_dir.value(), cache_dir.value());
#else
EXPECT_EQ(test_profile_dir.value(), cache_dir.value());
#endif
}
// Chrome OS doesn't use any of the desktop linux configuration.
#if defined(OS_LINUX) && !BUILDFLAG(IS_LACROS) && !BUILDFLAG(IS_ASH)
TEST(ChromePaths, DefaultUserDataDir) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string orig_chrome_config_home;
bool chrome_config_home_was_set =
env->GetVar("CHROME_CONFIG_HOME", &orig_chrome_config_home);
if (chrome_config_home_was_set)
env->UnSetVar("CHROME_CONFIG_HOME");
base::FilePath home_dir;
base::PathService::Get(base::DIR_HOME, &home_dir);
std::string expected_branding;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// TODO(skobes): Test channel suffixes with $CHROME_VERSION_EXTRA.
expected_branding = "google-chrome";
#else
expected_branding = "chromium";
#endif
base::FilePath user_data_dir;
GetDefaultUserDataDirectory(&user_data_dir);
EXPECT_EQ(home_dir.Append(".config/" + expected_branding).value(),
user_data_dir.value());
env->SetVar("CHROME_CONFIG_HOME", "/foo/bar");
GetDefaultUserDataDirectory(&user_data_dir);
EXPECT_EQ("/foo/bar/" + expected_branding, user_data_dir.value());
// TODO(skobes): It would be nice to test $CHROME_USER_DATA_DIR here too, but
// it's handled by ChromeMainDelegate instead of GetDefaultUserDataDirectory.
if (chrome_config_home_was_set)
env->SetVar("CHROME_CONFIG_HOME", orig_chrome_config_home);
else
env->UnSetVar("CHROME_CONFIG_HOME");
}
#endif
#if BUILDFLAG(IS_LACROS) || BUILDFLAG(IS_ASH)
TEST(ChromePaths, UserMediaDirectories) {
base::FilePath path;
// Chrome OS does not support custom media directories.
EXPECT_FALSE(GetUserMusicDirectory(&path));
EXPECT_FALSE(GetUserPicturesDirectory(&path));
EXPECT_FALSE(GetUserVideosDirectory(&path));
}
#endif
} // namespace chrome
|