summaryrefslogtreecommitdiffstats
path: root/base/path_service_unittest.cc
diff options
context:
space:
mode:
authorpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-26 19:05:12 +0000
committerpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-26 19:05:12 +0000
commitd6b3af951d48d31f6c3ae66c17ec69d33e88e1aa (patch)
tree621c08eed5eccb1ccbab1def72c1a7f3ab071f85 /base/path_service_unittest.cc
parent013d96a1617eb4df9959904ee2dd1924491f9b28 (diff)
downloadchromium_src-d6b3af951d48d31f6c3ae66c17ec69d33e88e1aa.zip
chromium_src-d6b3af951d48d31f6c3ae66c17ec69d33e88e1aa.tar.gz
chromium_src-d6b3af951d48d31f6c3ae66c17ec69d33e88e1aa.tar.bz2
Add PathService::RemoveOverride to clear path overrides.
This is especially useful for unit tests because they live in the same process and share all the singletons including PathService. One can of course override the overrides but it is much cleaner and sometimes the only good solution to return to the original PathProvider instead. BUG=149161 TEST=base_unittests:PathServiceTest.* Review URL: https://chromiumcodereview.appspot.com/10909228 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158842 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/path_service_unittest.cc')
-rw-r--r--base/path_service_unittest.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc
index e4bda0c..d3110f9 100644
--- a/base/path_service_unittest.cc
+++ b/base/path_service_unittest.cc
@@ -149,3 +149,48 @@ TEST_F(PathServiceTest, Override) {
true));
EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
}
+
+// Check if multiple overrides can co-exist.
+TEST_F(PathServiceTest, OverrideMultiple) {
+ int my_special_key = 666;
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
+ EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
+ EXPECT_TRUE(file_util::PathExists(fake_cache_dir1));
+ ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
+
+ FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
+ EXPECT_TRUE(PathService::Override(my_special_key + 1, fake_cache_dir2));
+ EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
+ ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
+
+ FilePath result;
+ EXPECT_TRUE(PathService::Get(my_special_key, &result));
+ // Override might have changed the path representation but our test file
+ // should be still there.
+ EXPECT_TRUE(file_util::PathExists(result.AppendASCII("t1")));
+ EXPECT_TRUE(PathService::Get(my_special_key + 1, &result));
+ EXPECT_TRUE(file_util::PathExists(result.AppendASCII("t2")));
+}
+
+TEST_F(PathServiceTest, RemoveOverride) {
+ // Before we start the test we have to call RemoveOverride at least once to
+ // clear any overrides that might have been left from other tests.
+ PathService::RemoveOverride(base::DIR_TEMP);
+
+ FilePath original_user_data_dir;
+ EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &original_user_data_dir));
+ EXPECT_FALSE(PathService::RemoveOverride(base::DIR_TEMP));
+
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
+ FilePath new_user_data_dir;
+ EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
+ EXPECT_NE(original_user_data_dir, new_user_data_dir);
+
+ EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
+ EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
+ EXPECT_EQ(original_user_data_dir, new_user_data_dir);
+}