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

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: Refactored the locking semantics. 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-excist.
jar (doing other things) 2012/09/17 17:06:08 nit: excist --> exist
pastarmovj 2012/09/18 14:27:13 Done.
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 // PathService::Override should always create the path provided if it doesn't
122 // exist.
123 EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
124 EXPECT_TRUE(file_util::PathExists(fake_cache_dir1));
125
126 FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
127 // PathService::Override should always create the path provided if it doesn't
128 // exist.
129 EXPECT_TRUE(PathService::Override(my_special_key + 1, fake_cache_dir2));
130 EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
131
132 FilePath result;
133 EXPECT_TRUE(PathService::Get(my_special_key, &result));
134 EXPECT_EQ(fake_cache_dir1, result);
135 EXPECT_TRUE(PathService::Get(my_special_key + 1, &result));
136 EXPECT_EQ(fake_cache_dir2, result);
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