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

Side by Side Diff: base/path_service_unittest.cc

Issue 265013002: Revert of Enable Enterprise enrollment on desktop builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/path_service.cc ('k') | chrome/app/chrome_main_delegate.cc » ('j') | 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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 EXPECT_PRED1(ReturnsValidPath, key); 140 EXPECT_PRED1(ReturnsValidPath, key);
141 } 141 }
142 #elif defined(OS_POSIX) 142 #elif defined(OS_POSIX)
143 for (int key = base::PATH_POSIX_START + 1; key < base::PATH_POSIX_END; 143 for (int key = base::PATH_POSIX_START + 1; key < base::PATH_POSIX_END;
144 ++key) { 144 ++key) {
145 EXPECT_PRED1(ReturnsValidPath, key); 145 EXPECT_PRED1(ReturnsValidPath, key);
146 } 146 }
147 #endif 147 #endif
148 } 148 }
149 149
150 // Test that all versions of the Override function of PathService do what they 150 // test that all versions of the Override function of PathService do what they
151 // are supposed to do. 151 // are supposed to do.
152 TEST_F(PathServiceTest, Override) { 152 TEST_F(PathServiceTest, Override) {
153 int my_special_key = 666; 153 int my_special_key = 666;
154 base::ScopedTempDir temp_dir; 154 base::ScopedTempDir temp_dir;
155 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 155 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
156 base::FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache")); 156 base::FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
157 // PathService::Override should always create the path provided if it doesn't 157 // PathService::Override should always create the path provided if it doesn't
158 // exist. 158 // exist.
159 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir)); 159 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir));
160 EXPECT_TRUE(base::PathExists(fake_cache_dir)); 160 EXPECT_TRUE(base::PathExists(fake_cache_dir));
161 161
162 base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2")); 162 base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
163 // PathService::OverrideAndCreateIfNeeded should obey the |create| parameter. 163 // PathService::OverrideAndCreateIfNeeded should obey the |create| parameter.
164 PathService::OverrideAndCreateIfNeeded(my_special_key, 164 PathService::OverrideAndCreateIfNeeded(my_special_key,
165 fake_cache_dir2, 165 fake_cache_dir2,
166 false,
167 false); 166 false);
168 EXPECT_FALSE(base::PathExists(fake_cache_dir2)); 167 EXPECT_FALSE(base::PathExists(fake_cache_dir2));
169 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key, 168 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
170 fake_cache_dir2, 169 fake_cache_dir2,
171 false,
172 true)); 170 true));
173 EXPECT_TRUE(base::PathExists(fake_cache_dir2)); 171 EXPECT_TRUE(base::PathExists(fake_cache_dir2));
174
175 #if defined(OS_POSIX)
176 base::FilePath non_existent(
177 base::MakeAbsoluteFilePath(temp_dir.path()).AppendASCII("non_existent"));
178 EXPECT_TRUE(non_existent.IsAbsolute());
179 EXPECT_FALSE(base::PathExists(non_existent));
180 // This fails because MakeAbsoluteFilePath fails for non-existent files.
181 EXPECT_FALSE(PathService::OverrideAndCreateIfNeeded(my_special_key,
182 non_existent,
183 false,
184 false));
185 // This works because indicating that |non_existent| is absolute skips the
186 // internal MakeAbsoluteFilePath call.
187 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(my_special_key,
188 non_existent,
189 true,
190 false));
191 // Check that the path has been overridden and no directory was created.
192 EXPECT_FALSE(base::PathExists(non_existent));
193 base::FilePath path;
194 EXPECT_TRUE(PathService::Get(my_special_key, &path));
195 EXPECT_EQ(non_existent, path);
196 #endif
197 } 172 }
198 173
199 // Check if multiple overrides can co-exist. 174 // Check if multiple overrides can co-exist.
200 TEST_F(PathServiceTest, OverrideMultiple) { 175 TEST_F(PathServiceTest, OverrideMultiple) {
201 int my_special_key = 666; 176 int my_special_key = 666;
202 base::ScopedTempDir temp_dir; 177 base::ScopedTempDir temp_dir;
203 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 178 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
204 base::FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1")); 179 base::FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
205 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1)); 180 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
206 EXPECT_TRUE(base::PathExists(fake_cache_dir1)); 181 EXPECT_TRUE(base::PathExists(fake_cache_dir1));
(...skipping 26 matching lines...) Expand all
233 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 208 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
234 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); 209 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
235 base::FilePath new_user_data_dir; 210 base::FilePath new_user_data_dir;
236 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); 211 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
237 EXPECT_NE(original_user_data_dir, new_user_data_dir); 212 EXPECT_NE(original_user_data_dir, new_user_data_dir);
238 213
239 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); 214 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
240 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); 215 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
241 EXPECT_EQ(original_user_data_dir, new_user_data_dir); 216 EXPECT_EQ(original_user_data_dir, new_user_data_dir);
242 } 217 }
OLDNEW
« no previous file with comments | « base/path_service.cc ('k') | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698