Remove --enable-hidpi-pdf-plugin flags, enable by default
[chromium-blink-merge.git] / base / path_service_unittest.cc
blob294f8d8b0f085dcc4ef8a2e0253d0ce2f2d9e743
1 // Copyright (c) 2012 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 "base/path_service.h"
7 #include "base/basictypes.h"
8 #include "base/file_util.h"
9 #include "base/file_path.h"
10 #include "base/scoped_temp_dir.h"
11 #if defined(OS_WIN)
12 #include "base/win/windows_version.h"
13 #endif
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/gtest/include/gtest/gtest-spi.h"
16 #include "testing/platform_test.h"
18 namespace {
20 // Returns true if PathService::Get returns true and sets the path parameter
21 // to non-empty for the given PathService::DirType enumeration value.
22 bool ReturnsValidPath(int dir_type) {
23 FilePath path;
24 bool result = PathService::Get(dir_type, &path);
25 #if defined(OS_POSIX)
26 // If chromium has never been started on this account, the cache path may not
27 // exist.
28 if (dir_type == base::DIR_CACHE)
29 return result && !path.value().empty();
30 #endif
31 return result && !path.value().empty() && file_util::PathExists(path);
34 #if defined(OS_WIN)
35 // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
36 bool ReturnsInvalidPath(int dir_type) {
37 FilePath path;
38 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
39 return !result && path.empty();
41 #endif
43 } // namespace
45 // On the Mac this winds up using some autoreleased objects, so we need to
46 // be a PlatformTest.
47 typedef PlatformTest PathServiceTest;
49 // Test that all PathService::Get calls return a value and a true result
50 // in the development environment. (This test was created because a few
51 // later changes to Get broke the semantics of the function and yielded the
52 // correct value while returning false.)
53 TEST_F(PathServiceTest, Get) {
54 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
55 #if defined(OS_ANDROID)
56 if (key == base::FILE_MODULE)
57 continue; // Android doesn't implement FILE_MODULE;
58 #endif
59 EXPECT_PRED1(ReturnsValidPath, key);
61 #if defined(OS_WIN)
62 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
63 if (key == base::DIR_LOCAL_APP_DATA_LOW &&
64 base::win::GetVersion() < base::win::VERSION_VISTA) {
65 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to
66 // fail.
67 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
68 } else {
69 EXPECT_TRUE(ReturnsValidPath(key)) << key;
72 #elif defined(OS_MACOSX)
73 for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) {
74 EXPECT_PRED1(ReturnsValidPath, key);
76 #endif
79 // test that all versions of the Override function of PathService do what they
80 // are supposed to do.
81 TEST_F(PathServiceTest, Override) {
82 int my_special_key = 666;
83 ScopedTempDir temp_dir;
84 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
85 FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
86 // PathService::Override should always create the path provided if it doesn't
87 // exist.
88 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir));
89 EXPECT_TRUE(file_util::PathExists(fake_cache_dir));
91 FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
92 // PathService::OverrideAndCreateIfNeeded should obey the |create| parameter.
93 PathService::OverrideAndCreateIfNeeded(my_special_key,
94 fake_cache_dir2,
95 false);
96 EXPECT_FALSE(file_util::PathExists(fake_cache_dir2));
97 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
98 fake_cache_dir2,
99 true));
100 EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));