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

Side by Side Diff: base/path_service_unittest.cc

Issue 10909228: Add PathService::RemoveOverride to clear path overrides. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Made the tests even more OS independent. Created 8 years, 3 months 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 unified diff | Download patch
« base/path_service.cc ('K') | « base/path_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/path_service.h" 5 #include "base/path_service.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // PathService::OverrideAndCreateIfNeeded should obey the |create| parameter. 104 // PathService::OverrideAndCreateIfNeeded should obey the |create| parameter.
105 PathService::OverrideAndCreateIfNeeded(my_special_key, 105 PathService::OverrideAndCreateIfNeeded(my_special_key,
106 fake_cache_dir2, 106 fake_cache_dir2,
107 false); 107 false);
108 EXPECT_FALSE(file_util::PathExists(fake_cache_dir2)); 108 EXPECT_FALSE(file_util::PathExists(fake_cache_dir2));
109 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key, 109 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
110 fake_cache_dir2, 110 fake_cache_dir2,
111 true)); 111 true));
112 EXPECT_TRUE(file_util::PathExists(fake_cache_dir2)); 112 EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
113 } 113 }
114
115 // Check if multiple overrides can co-exist.
116 TEST_F(PathServiceTest, OverrideMultiple) {
117 int my_special_key = 666;
118 ScopedTempDir temp_dir;
119 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
120 FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
121 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
122 EXPECT_TRUE(file_util::PathExists(fake_cache_dir1));
123 ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));
124
125 FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
126 EXPECT_TRUE(PathService::Override(my_special_key + 1, fake_cache_dir2));
127 EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
128 ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));
129
130 FilePath result;
131 EXPECT_TRUE(PathService::Get(my_special_key, &result));
132 // Override might have changed the path representation but our test file
133 // should be still there.
134 EXPECT_TRUE(file_util::PathExists(result.AppendASCII("t1")));
135 EXPECT_TRUE(PathService::Get(my_special_key + 1, &result));
136 EXPECT_TRUE(file_util::PathExists(result.AppendASCII("t2")));
137 }
138
139 TEST_F(PathServiceTest, RemoveOverride) {
140 // Before we start the test we have to call RemoveOverride at least once to
141 // clear any overrides that might have been left from other tests.
142 PathService::RemoveOverride(base::DIR_TEMP);
143
144 FilePath original_user_data_dir;
145 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &original_user_data_dir));
146 EXPECT_FALSE(PathService::RemoveOverride(base::DIR_TEMP));
147
148 ScopedTempDir temp_dir;
149 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
150 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
151 FilePath new_user_data_dir;
152 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
153 EXPECT_NE(original_user_data_dir, new_user_data_dir);
154
155 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
156 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
157 EXPECT_EQ(original_user_data_dir, new_user_data_dir);
158 }
OLDNEW
« base/path_service.cc ('K') | « base/path_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698