Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2408)

Unified Diff: chrome/common/chrome_paths_unittest.cc

Issue 5123004: chrome_paths: refactor and sanitize cache directory handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/chrome_paths_unittest.cc
diff --git a/chrome/common/chrome_paths_unittest.cc b/chrome/common/chrome_paths_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a7cb242947c29521aa439df0337bd4b4f12b8382
--- /dev/null
+++ b/chrome/common/chrome_paths_unittest.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2010 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/file_path.h"
+#include "base/file_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Test the behavior of chrome::GetUserCacheDirectory.
+// See that function's comments for discussion of the subtleties.
+TEST(ChromePaths, UserCacheDir) {
+#if defined(OS_MACOSX)
+ // Verify that ~/Library/Application Support/foobar maps to .cache/foobar.
+ FilePath homedir = FilePath(getenv("HOME"));
Mark Mentovai 2010/11/18 16:54:54 Why not file_util::GetHomeDir() as in non-Mac POSI
Evan Martin 2010/11/18 18:13:07 We only have a Linux impl. (If $HOME is unset you
Mark Mentovai 2010/11/18 19:11:48 Evan Martin wrote:
+ FilePath user_data_dir = homedir.Append("Library/Application Support/foobar");
+ FilePath cache_dir;
+ ASSERT_TRUE(chrome::GetUserCacheDirectory(user_data_dir, &cache_dir));
+ EXPECT_EQ(homedir.Append("Library/Caches/foobar").value(), cache_dir.value());
+
+ // Verify that a custom user data dir doesn't get a custom cache dir.
Mark Mentovai 2010/11/18 16:54:54 This block is the same for Mac and non-Mac POSIX,
+ user_data_dir = homedir.Append("some_other_dir");
+ ASSERT_TRUE(chrome::GetUserCacheDirectory(user_data_dir, &cache_dir));
+ EXPECT_EQ(user_data_dir.value(), cache_dir.value());
+
+#elif(OS_POSIX)
+ // We assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their default settings.
+ FilePath homedir = file_util::GetHomeDir();
+
+ // Verify that .config/foobar maps to .cache/foobar.
+ FilePath user_data_dir = homedir.Append(".config/foobar");
+ FilePath cache_dir;
+ ASSERT_TRUE(chrome::GetUserCacheDirectory(user_data_dir, &cache_dir));
Mark Mentovai 2010/11/18 16:54:54 For that matter, maybe you can put this line outsi
Evan Martin 2010/11/18 18:13:07 Great idea, I've now rewritten the test to be much
+ EXPECT_EQ(homedir.Append(".cache/foobar").value(), cache_dir.value());
+
+ // Verify that a custom user data dir doesn't get a custom cache dir.
+ user_data_dir = homedir.Append("some_other_dir");
+ ASSERT_TRUE(chrome::GetUserCacheDirectory(user_data_dir, &cache_dir));
+ EXPECT_EQ(user_data_dir.value(), cache_dir.value());
+#endif
+}

Powered by Google App Engine
This is Rietveld 408576698