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

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: Cleaned up a typo in unit tests file. 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 // 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 // Direct comparison of FilePath object fails.
135 EXPECT_EQ(fake_cache_dir1.value(), result.value());
136 EXPECT_TRUE(PathService::Get(my_special_key + 1, &result));
137 EXPECT_EQ(fake_cache_dir2.value(), result.value());
138 }
139
140 TEST_F(PathServiceTest, RemoveOverride) {
141 // Before we start the test we have to call RemoveOverride at least once to
142 // clear any overrides that might have been left from other tests.
143 PathService::RemoveOverride(base::DIR_TEMP);
144
145 FilePath original_user_data_dir;
146 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &original_user_data_dir));
147 EXPECT_FALSE(PathService::RemoveOverride(base::DIR_TEMP));
148
149 ScopedTempDir temp_dir;
150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
151 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
152 FilePath new_user_data_dir;
153 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
154 EXPECT_NE(original_user_data_dir, new_user_data_dir);
155
156 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP));
157 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
158 EXPECT_EQ(original_user_data_dir, new_user_data_dir);
159 }
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