OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_callback_factory.h" |
| 13 #include "base/message_loop.h" |
12 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
13 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
14 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_operation_context.h" | 19 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_path_manager.h" |
18 #include "webkit/fileapi/file_system_test_helper.h" | 21 #include "webkit/fileapi/file_system_test_helper.h" |
| 22 #include "webkit/fileapi/file_system_usage_cache.h" |
19 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 23 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
| 24 #include "webkit/quota/mock_special_storage_policy.h" |
| 25 #include "webkit/quota/quota_manager.h" |
| 26 #include "webkit/quota/quota_types.h" |
20 | 27 |
21 using namespace fileapi; | 28 using namespace fileapi; |
22 | 29 |
23 namespace { | 30 namespace { |
24 | 31 |
25 FilePath UTF8ToFilePath(const std::string& str) { | 32 FilePath UTF8ToFilePath(const std::string& str) { |
26 FilePath::StringType result; | 33 FilePath::StringType result; |
27 #if defined(OS_POSIX) | 34 #if defined(OS_POSIX) |
28 result = str; | 35 result = str; |
29 #elif defined(OS_WIN) | 36 #elif defined(OS_WIN) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 126 |
120 // TODO(ericu): The vast majority of this and the other FSFU subclass tests | 127 // TODO(ericu): The vast majority of this and the other FSFU subclass tests |
121 // could theoretically be shared. It would basically be a FSFU interface | 128 // could theoretically be shared. It would basically be a FSFU interface |
122 // compliance test, and only the subclass-specific bits that look into the | 129 // compliance test, and only the subclass-specific bits that look into the |
123 // implementation would need to be written per-subclass. | 130 // implementation would need to be written per-subclass. |
124 class ObfuscatedFileSystemFileUtilTest : public testing::Test { | 131 class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
125 public: | 132 public: |
126 ObfuscatedFileSystemFileUtilTest() | 133 ObfuscatedFileSystemFileUtilTest() |
127 : origin_(GURL("http://www.example.com")), | 134 : origin_(GURL("http://www.example.com")), |
128 type_(kFileSystemTypeTemporary), | 135 type_(kFileSystemTypeTemporary), |
129 test_helper_(origin_, type_) { | 136 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 137 test_helper_(origin_, type_), |
| 138 quota_status_(quota::kQuotaStatusUnknown), |
| 139 usage_(-1) { |
130 } | 140 } |
131 | 141 |
132 void SetUp() { | 142 void SetUp() { |
133 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 143 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
134 | 144 |
| 145 quota_manager_ = new quota::QuotaManager( |
| 146 false /* is_incognito */, |
| 147 data_dir_.path(), |
| 148 base::MessageLoopProxy::CreateForCurrentThread(), |
| 149 base::MessageLoopProxy::CreateForCurrentThread(), |
| 150 NULL /* special storage policy */); |
| 151 |
| 152 file_system_context_ = new FileSystemContext( |
| 153 base::MessageLoopProxy::CreateForCurrentThread(), |
| 154 base::MessageLoopProxy::CreateForCurrentThread(), |
| 155 new quota::MockSpecialStoragePolicy(), |
| 156 quota_manager_->proxy(), |
| 157 data_dir_.path(), |
| 158 false /* incognito */, |
| 159 true /* allow_file_access_from_files */, |
| 160 false /* unlimited_quota */, |
| 161 NULL /* path_manager */); |
| 162 |
135 obfuscated_file_system_file_util_ = | 163 obfuscated_file_system_file_util_ = |
136 new ObfuscatedFileSystemFileUtil(data_dir_.path(), | 164 static_cast<ObfuscatedFileSystemFileUtil*>( |
137 new FileSystemFileUtil()); | 165 file_system_context_->path_manager()->GetFileSystemFileUtil(type_)); |
| 166 |
138 test_helper_.SetUp(data_dir_.path(), | 167 test_helper_.SetUp(data_dir_.path(), |
139 false, // incognito | 168 false, // incognito |
140 false, // unlimited quota | 169 false, // unlimited quota |
141 NULL, // quota::QuotaManagerProxy | 170 quota_manager_->proxy(), |
142 obfuscated_file_system_file_util_.get()); | 171 obfuscated_file_system_file_util_.get()); |
143 } | 172 } |
144 | 173 |
145 FileSystemOperationContext* NewContext() { | 174 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { |
146 FileSystemOperationContext* context = test_helper_.NewOperationContext(); | 175 FileSystemOperationContext* context; |
| 176 if (helper) |
| 177 context = helper->NewOperationContext(); |
| 178 else |
| 179 context = test_helper_.NewOperationContext(); |
| 180 context->set_allowed_bytes_growth(1024 * 1024); // Big enough for all tests. |
147 return context; | 181 return context; |
148 } | 182 } |
149 | 183 |
| 184 // This can only be used after SetUp has run and created data_dir_ and |
| 185 // obfuscated_file_system_file_util_. |
| 186 // Use this for tests which need to run in multiple origins; we need a test |
| 187 // helper per origin. |
| 188 FileSystemTestOriginHelper* NewHelper( |
| 189 const GURL& origin, fileapi::FileSystemType type) { |
| 190 FileSystemTestOriginHelper* helper = |
| 191 new FileSystemTestOriginHelper(origin, type); |
| 192 helper->SetUp(data_dir_.path(), |
| 193 false, // incognito |
| 194 false, // unlimited quota |
| 195 NULL, // quota::QuotaManagerProxy |
| 196 obfuscated_file_system_file_util_.get()); |
| 197 return helper; |
| 198 } |
| 199 |
150 ObfuscatedFileSystemFileUtil* ofsfu() { | 200 ObfuscatedFileSystemFileUtil* ofsfu() { |
151 return obfuscated_file_system_file_util_.get(); | 201 return obfuscated_file_system_file_util_.get(); |
152 } | 202 } |
153 | 203 |
154 const FilePath& test_directory() const { | 204 const FilePath& test_directory() const { |
155 return data_dir_.path(); | 205 return data_dir_.path(); |
156 } | 206 } |
157 | 207 |
158 const GURL& origin_url() const { | 208 const GURL& origin() const { |
159 return origin_; | 209 return origin_; |
160 } | 210 } |
161 | 211 |
162 fileapi::FileSystemType type() const { | 212 fileapi::FileSystemType type() const { |
163 return type_; | 213 return type_; |
164 } | 214 } |
165 | 215 |
| 216 void GetUsageFromQuotaManager() { |
| 217 quota_manager_->GetUsageAndQuota( |
| 218 origin(), test_helper_.storage_type(), |
| 219 callback_factory_.NewCallback( |
| 220 &ObfuscatedFileSystemFileUtilTest::OnGetUsage)); |
| 221 MessageLoop::current()->RunAllPending(); |
| 222 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); |
| 223 } |
| 224 |
| 225 void RevokeUsageCache() { |
| 226 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); |
| 227 ASSERT_TRUE(test_helper_.RevokeUsageCache()); |
| 228 } |
| 229 |
| 230 int64 SizeInUsageFile() { |
| 231 return test_helper_.GetCachedOriginUsage(); |
| 232 } |
| 233 |
| 234 int64 usage() const { return usage_; } |
| 235 |
| 236 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) { |
| 237 EXPECT_EQ(quota::kQuotaStatusOk, status); |
| 238 quota_status_ = status; |
| 239 usage_ = usage; |
| 240 } |
| 241 |
166 void CheckFileAndCloseHandle( | 242 void CheckFileAndCloseHandle( |
167 const FilePath& virtual_path, PlatformFile file_handle) { | 243 const FilePath& virtual_path, PlatformFile file_handle) { |
168 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 244 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
169 FilePath local_path; | 245 FilePath local_path; |
170 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 246 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
171 context.get(), virtual_path, &local_path)); | 247 context.get(), virtual_path, &local_path)); |
172 | 248 |
173 base::PlatformFileInfo file_info0; | 249 base::PlatformFileInfo file_info0; |
174 FilePath data_path; | 250 FilePath data_path; |
175 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 251 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
176 context.get(), virtual_path, &file_info0, &data_path)); | 252 context.get(), virtual_path, &file_info0, &data_path)); |
177 EXPECT_EQ(data_path, local_path); | 253 EXPECT_EQ(data_path, local_path); |
178 EXPECT_TRUE(FileExists(data_path)); | 254 EXPECT_TRUE(FileExists(data_path)); |
(...skipping 12 matching lines...) Expand all Loading... |
191 &error); | 267 &error); |
192 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 268 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
193 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 269 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
194 EXPECT_FALSE(created); | 270 EXPECT_FALSE(created); |
195 } | 271 } |
196 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); | 272 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); |
197 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 273 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
198 | 274 |
199 base::PlatformFileInfo file_info1; | 275 base::PlatformFileInfo file_info1; |
200 EXPECT_EQ(length, GetSize(data_path)); | 276 EXPECT_EQ(length, GetSize(data_path)); |
201 context.reset(NewContext()); | 277 context.reset(NewContext(NULL)); |
202 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 278 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
203 context.get(), virtual_path, &file_info1, &data_path)); | 279 context.get(), virtual_path, &file_info1, &data_path)); |
204 EXPECT_EQ(data_path, local_path); | 280 EXPECT_EQ(data_path, local_path); |
205 | 281 |
206 EXPECT_FALSE(file_info0.is_directory); | 282 EXPECT_FALSE(file_info0.is_directory); |
207 EXPECT_FALSE(file_info1.is_directory); | 283 EXPECT_FALSE(file_info1.is_directory); |
208 EXPECT_FALSE(file_info0.is_symbolic_link); | 284 EXPECT_FALSE(file_info0.is_symbolic_link); |
209 EXPECT_FALSE(file_info1.is_symbolic_link); | 285 EXPECT_FALSE(file_info1.is_symbolic_link); |
210 EXPECT_EQ(0, file_info0.size); | 286 EXPECT_EQ(0, file_info0.size); |
211 EXPECT_EQ(length, file_info1.size); | 287 EXPECT_EQ(length, file_info1.size); |
212 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); | 288 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); |
213 | 289 |
214 context.reset(NewContext()); | 290 context.reset(NewContext(NULL)); |
215 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 291 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
216 context.get(), virtual_path, length * 2)); | 292 context.get(), virtual_path, length * 2)); |
217 EXPECT_EQ(length * 2, GetSize(data_path)); | 293 EXPECT_EQ(length * 2, GetSize(data_path)); |
218 | 294 |
219 context.reset(NewContext()); | 295 context.reset(NewContext(NULL)); |
220 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 296 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
221 context.get(), virtual_path, 1)); | 297 context.get(), virtual_path, 1)); |
222 EXPECT_EQ(1, GetSize(data_path)); | 298 EXPECT_EQ(1, GetSize(data_path)); |
223 } | 299 } |
224 | 300 |
225 void ValidateTestDirectory( | 301 void ValidateTestDirectory( |
226 const FilePath& root_path, | 302 const FilePath& root_path, |
227 const std::set<FilePath::StringType>& files, | 303 const std::set<FilePath::StringType>& files, |
228 const std::set<FilePath::StringType>& directories) { | 304 const std::set<FilePath::StringType>& directories) { |
229 scoped_ptr<FileSystemOperationContext> context; | 305 scoped_ptr<FileSystemOperationContext> context; |
230 std::set<FilePath::StringType>::const_iterator iter; | 306 std::set<FilePath::StringType>::const_iterator iter; |
231 for (iter = files.begin(); iter != files.end(); ++iter) { | 307 for (iter = files.begin(); iter != files.end(); ++iter) { |
232 bool created = true; | 308 bool created = true; |
233 context.reset(NewContext()); | 309 context.reset(NewContext(NULL)); |
234 ASSERT_EQ(base::PLATFORM_FILE_OK, | 310 ASSERT_EQ(base::PLATFORM_FILE_OK, |
235 ofsfu()->EnsureFileExists( | 311 ofsfu()->EnsureFileExists( |
236 context.get(), root_path.Append(*iter), | 312 context.get(), root_path.Append(*iter), |
237 &created)); | 313 &created)); |
238 ASSERT_FALSE(created); | 314 ASSERT_FALSE(created); |
239 } | 315 } |
240 for (iter = directories.begin(); iter != directories.end(); ++iter) { | 316 for (iter = directories.begin(); iter != directories.end(); ++iter) { |
241 context.reset(NewContext()); | 317 context.reset(NewContext(NULL)); |
242 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), | 318 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), |
243 root_path.Append(*iter))); | 319 root_path.Append(*iter))); |
244 } | 320 } |
245 } | 321 } |
246 | 322 |
247 void FillTestDirectory( | 323 void FillTestDirectory( |
248 const FilePath& root_path, | 324 const FilePath& root_path, |
249 std::set<FilePath::StringType>* files, | 325 std::set<FilePath::StringType>* files, |
250 std::set<FilePath::StringType>* directories) { | 326 std::set<FilePath::StringType>* directories) { |
251 scoped_ptr<FileSystemOperationContext> context; | 327 scoped_ptr<FileSystemOperationContext> context; |
252 context.reset(NewContext()); | 328 context.reset(NewContext(NULL)); |
253 std::vector<base::FileUtilProxy::Entry> entries; | 329 std::vector<base::FileUtilProxy::Entry> entries; |
254 EXPECT_EQ(base::PLATFORM_FILE_OK, | 330 EXPECT_EQ(base::PLATFORM_FILE_OK, |
255 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 331 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
256 EXPECT_EQ(0UL, entries.size()); | 332 EXPECT_EQ(0UL, entries.size()); |
257 | 333 |
258 files->clear(); | 334 files->clear(); |
259 files->insert(FILE_PATH_LITERAL("first")); | 335 files->insert(FILE_PATH_LITERAL("first")); |
260 files->insert(FILE_PATH_LITERAL("second")); | 336 files->insert(FILE_PATH_LITERAL("second")); |
261 files->insert(FILE_PATH_LITERAL("third")); | 337 files->insert(FILE_PATH_LITERAL("third")); |
262 directories->clear(); | 338 directories->clear(); |
263 directories->insert(FILE_PATH_LITERAL("fourth")); | 339 directories->insert(FILE_PATH_LITERAL("fourth")); |
264 directories->insert(FILE_PATH_LITERAL("fifth")); | 340 directories->insert(FILE_PATH_LITERAL("fifth")); |
265 directories->insert(FILE_PATH_LITERAL("sixth")); | 341 directories->insert(FILE_PATH_LITERAL("sixth")); |
266 std::set<FilePath::StringType>::iterator iter; | 342 std::set<FilePath::StringType>::iterator iter; |
267 for (iter = files->begin(); iter != files->end(); ++iter) { | 343 for (iter = files->begin(); iter != files->end(); ++iter) { |
268 bool created = false; | 344 bool created = false; |
269 context.reset(NewContext()); | 345 context.reset(NewContext(NULL)); |
270 ASSERT_EQ(base::PLATFORM_FILE_OK, | 346 ASSERT_EQ(base::PLATFORM_FILE_OK, |
271 ofsfu()->EnsureFileExists( | 347 ofsfu()->EnsureFileExists( |
272 context.get(), root_path.Append(*iter), &created)); | 348 context.get(), root_path.Append(*iter), &created)); |
273 ASSERT_TRUE(created); | 349 ASSERT_TRUE(created); |
274 } | 350 } |
275 for (iter = directories->begin(); iter != directories->end(); ++iter) { | 351 for (iter = directories->begin(); iter != directories->end(); ++iter) { |
276 bool exclusive = true; | 352 bool exclusive = true; |
277 bool recursive = false; | 353 bool recursive = false; |
278 context.reset(NewContext()); | 354 context.reset(NewContext(NULL)); |
279 EXPECT_EQ(base::PLATFORM_FILE_OK, | 355 EXPECT_EQ(base::PLATFORM_FILE_OK, |
280 ofsfu()->CreateDirectory( | 356 ofsfu()->CreateDirectory( |
281 context.get(), root_path.Append(*iter), exclusive, recursive)); | 357 context.get(), root_path.Append(*iter), exclusive, recursive)); |
282 } | 358 } |
283 ValidateTestDirectory(root_path, *files, *directories); | 359 ValidateTestDirectory(root_path, *files, *directories); |
284 } | 360 } |
285 | 361 |
286 void TestReadDirectoryHelper(const FilePath& root_path) { | 362 void TestReadDirectoryHelper(const FilePath& root_path) { |
287 std::set<FilePath::StringType> files; | 363 std::set<FilePath::StringType> files; |
288 std::set<FilePath::StringType> directories; | 364 std::set<FilePath::StringType> directories; |
289 FillTestDirectory(root_path, &files, &directories); | 365 FillTestDirectory(root_path, &files, &directories); |
290 | 366 |
291 scoped_ptr<FileSystemOperationContext> context; | 367 scoped_ptr<FileSystemOperationContext> context; |
292 std::vector<base::FileUtilProxy::Entry> entries; | 368 std::vector<base::FileUtilProxy::Entry> entries; |
293 context.reset(NewContext()); | 369 context.reset(NewContext(NULL)); |
294 EXPECT_EQ(base::PLATFORM_FILE_OK, | 370 EXPECT_EQ(base::PLATFORM_FILE_OK, |
295 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 371 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
296 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; | 372 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; |
297 EXPECT_EQ(files.size() + directories.size(), entries.size()); | 373 EXPECT_EQ(files.size() + directories.size(), entries.size()); |
298 for (entry_iter = entries.begin(); entry_iter != entries.end(); | 374 for (entry_iter = entries.begin(); entry_iter != entries.end(); |
299 ++entry_iter) { | 375 ++entry_iter) { |
300 const base::FileUtilProxy::Entry& entry = *entry_iter; | 376 const base::FileUtilProxy::Entry& entry = *entry_iter; |
301 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); | 377 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); |
302 if (iter != files.end()) { | 378 if (iter != files.end()) { |
303 EXPECT_FALSE(entry.is_directory); | 379 EXPECT_FALSE(entry.is_directory); |
304 files.erase(iter); | 380 files.erase(iter); |
305 continue; | 381 continue; |
306 } | 382 } |
307 iter = directories.find(entry.name); | 383 iter = directories.find(entry.name); |
308 EXPECT_FALSE(directories.end() == iter); | 384 EXPECT_FALSE(directories.end() == iter); |
309 EXPECT_TRUE(entry.is_directory); | 385 EXPECT_TRUE(entry.is_directory); |
310 directories.erase(iter); | 386 directories.erase(iter); |
311 } | 387 } |
312 } | 388 } |
313 | 389 |
314 void TestTouchHelper(const FilePath& path) { | 390 void TestTouchHelper(const FilePath& path) { |
315 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 391 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
316 base::Time last_modified_time = base::Time::Now(); | 392 base::Time last_modified_time = base::Time::Now(); |
317 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 393 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
318 EXPECT_EQ(base::PLATFORM_FILE_OK, | 394 EXPECT_EQ(base::PLATFORM_FILE_OK, |
319 ofsfu()->Touch( | 395 ofsfu()->Touch( |
320 context.get(), path, last_access_time, last_modified_time)); | 396 context.get(), path, last_access_time, last_modified_time)); |
321 FilePath local_path; | 397 FilePath local_path; |
322 base::PlatformFileInfo file_info; | 398 base::PlatformFileInfo file_info; |
323 context.reset(NewContext()); | 399 context.reset(NewContext(NULL)); |
324 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 400 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
325 context.get(), path, &file_info, &local_path)); | 401 context.get(), path, &file_info, &local_path)); |
326 // We compare as time_t here to lower our resolution, to avoid false | 402 // We compare as time_t here to lower our resolution, to avoid false |
327 // negatives caused by conversion to the local filesystem's native | 403 // negatives caused by conversion to the local filesystem's native |
328 // representation and back. | 404 // representation and back. |
329 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 405 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
330 | 406 |
331 context.reset(NewContext()); | 407 context.reset(NewContext(NULL)); |
332 last_modified_time += base::TimeDelta::FromHours(1); | 408 last_modified_time += base::TimeDelta::FromHours(1); |
333 EXPECT_EQ(base::PLATFORM_FILE_OK, | 409 EXPECT_EQ(base::PLATFORM_FILE_OK, |
334 ofsfu()->Touch( | 410 ofsfu()->Touch( |
335 context.get(), path, last_access_time, last_modified_time)); | 411 context.get(), path, last_access_time, last_modified_time)); |
336 context.reset(NewContext()); | 412 context.reset(NewContext(NULL)); |
337 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 413 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
338 context.get(), path, &file_info, &local_path)); | 414 context.get(), path, &file_info, &local_path)); |
339 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 415 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
340 } | 416 } |
341 | 417 |
342 void TestCopyInForeignFileHelper(bool overwrite) { | 418 void TestCopyInForeignFileHelper(bool overwrite) { |
343 ScopedTempDir source_dir; | 419 ScopedTempDir source_dir; |
344 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 420 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
345 FilePath root_path = source_dir.path(); | 421 FilePath root_path = source_dir.path(); |
346 FilePath src_path = root_path.AppendASCII("file_name"); | 422 FilePath src_path = root_path.AppendASCII("file_name"); |
347 FilePath dest_path(FILE_PATH_LITERAL("new file")); | 423 FilePath dest_path(FILE_PATH_LITERAL("new file")); |
348 int64 src_file_length = 87; | 424 int64 src_file_length = 87; |
349 | 425 |
350 base::PlatformFileError error_code; | 426 base::PlatformFileError error_code; |
351 bool created = false; | 427 bool created = false; |
352 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 428 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
353 base::PlatformFile file_handle = | 429 base::PlatformFile file_handle = |
354 base::CreatePlatformFile( | 430 base::CreatePlatformFile( |
355 src_path, file_flags, &created, &error_code); | 431 src_path, file_flags, &created, &error_code); |
356 EXPECT_TRUE(created); | 432 EXPECT_TRUE(created); |
357 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | 433 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
358 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 434 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
359 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); | 435 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); |
360 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 436 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
361 | 437 |
362 scoped_ptr<FileSystemOperationContext> context; | 438 scoped_ptr<FileSystemOperationContext> context; |
363 | 439 |
364 if (overwrite) { | 440 if (overwrite) { |
365 context.reset(NewContext()); | 441 context.reset(NewContext(NULL)); |
366 EXPECT_EQ(base::PLATFORM_FILE_OK, | 442 EXPECT_EQ(base::PLATFORM_FILE_OK, |
367 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 443 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
368 EXPECT_TRUE(created); | 444 EXPECT_TRUE(created); |
369 } | 445 } |
370 | 446 |
371 context.reset(NewContext()); | 447 context.reset(NewContext(NULL)); |
372 EXPECT_EQ(base::PLATFORM_FILE_OK, | 448 EXPECT_EQ(base::PLATFORM_FILE_OK, |
373 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); | 449 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); |
374 context.reset(NewContext()); | 450 context.reset(NewContext(NULL)); |
375 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); | 451 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); |
376 context.reset(NewContext()); | 452 context.reset(NewContext(NULL)); |
377 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 453 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
378 context.reset(NewContext()); | 454 context.reset(NewContext(NULL)); |
379 base::PlatformFileInfo file_info; | 455 base::PlatformFileInfo file_info; |
380 FilePath data_path; | 456 FilePath data_path; |
381 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 457 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
382 context.get(), dest_path, &file_info, &data_path)); | 458 context.get(), dest_path, &file_info, &data_path)); |
383 EXPECT_NE(data_path, src_path); | 459 EXPECT_NE(data_path, src_path); |
384 EXPECT_TRUE(FileExists(data_path)); | 460 EXPECT_TRUE(FileExists(data_path)); |
385 EXPECT_EQ(src_file_length, GetSize(data_path)); | 461 EXPECT_EQ(src_file_length, GetSize(data_path)); |
386 | 462 |
387 EXPECT_EQ(base::PLATFORM_FILE_OK, | 463 EXPECT_EQ(base::PLATFORM_FILE_OK, |
388 ofsfu()->DeleteFile(context.get(), dest_path)); | 464 ofsfu()->DeleteFile(context.get(), dest_path)); |
389 } | 465 } |
390 | 466 |
391 private: | 467 private: |
392 ScopedTempDir data_dir_; | 468 ScopedTempDir data_dir_; |
393 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; | 469 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; |
| 470 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 471 scoped_refptr<FileSystemContext> file_system_context_; |
394 GURL origin_; | 472 GURL origin_; |
395 fileapi::FileSystemType type_; | 473 fileapi::FileSystemType type_; |
| 474 base::ScopedCallbackFactory<ObfuscatedFileSystemFileUtilTest> |
| 475 callback_factory_; |
396 FileSystemTestOriginHelper test_helper_; | 476 FileSystemTestOriginHelper test_helper_; |
| 477 quota::QuotaStatusCode quota_status_; |
| 478 int64 usage_; |
397 | 479 |
398 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); | 480 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); |
399 }; | 481 }; |
400 | 482 |
401 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { | 483 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
402 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 484 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
403 bool created; | 485 bool created; |
404 FilePath path = UTF8ToFilePath("fake/file"); | 486 FilePath path = UTF8ToFilePath("fake/file"); |
405 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 487 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
406 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 488 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
407 | 489 |
408 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 490 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
409 ofsfu()->CreateOrOpen( | 491 ofsfu()->CreateOrOpen( |
410 context.get(), path, file_flags, &file_handle, | 492 context.get(), path, file_flags, &file_handle, |
411 &created)); | 493 &created)); |
412 | 494 |
413 context.reset(NewContext()); | 495 context.reset(NewContext(NULL)); |
414 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 496 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
415 ofsfu()->DeleteFile(context.get(), path)); | 497 ofsfu()->DeleteFile(context.get(), path)); |
416 | 498 |
417 path = UTF8ToFilePath("test file"); | 499 path = UTF8ToFilePath("test file"); |
418 | 500 |
419 context.reset(NewContext()); | 501 context.reset(NewContext(NULL)); |
420 ASSERT_EQ(base::PLATFORM_FILE_OK, | 502 ASSERT_EQ(base::PLATFORM_FILE_OK, |
421 ofsfu()->CreateOrOpen( | 503 ofsfu()->CreateOrOpen( |
422 context.get(), path, file_flags, &file_handle, &created)); | 504 context.get(), path, file_flags, &file_handle, &created)); |
423 ASSERT_TRUE(created); | 505 ASSERT_TRUE(created); |
424 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 506 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
425 | 507 |
426 CheckFileAndCloseHandle(path, file_handle); | 508 CheckFileAndCloseHandle(path, file_handle); |
427 | 509 |
428 context.reset(NewContext()); | 510 context.reset(NewContext(NULL)); |
429 FilePath local_path; | 511 FilePath local_path; |
430 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 512 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
431 context.get(), path, &local_path)); | 513 context.get(), path, &local_path)); |
432 EXPECT_TRUE(file_util::PathExists(local_path)); | 514 EXPECT_TRUE(file_util::PathExists(local_path)); |
433 | 515 |
434 context.reset(NewContext()); | 516 context.reset(NewContext(NULL)); |
435 EXPECT_EQ(base::PLATFORM_FILE_OK, | 517 EXPECT_EQ(base::PLATFORM_FILE_OK, |
436 ofsfu()->DeleteFile(context.get(), path)); | 518 ofsfu()->DeleteFile(context.get(), path)); |
437 EXPECT_FALSE(file_util::PathExists(local_path)); | 519 EXPECT_FALSE(file_util::PathExists(local_path)); |
438 | 520 |
439 context.reset(NewContext()); | 521 context.reset(NewContext(NULL)); |
440 bool exclusive = true; | 522 bool exclusive = true; |
441 bool recursive = true; | 523 bool recursive = true; |
442 FilePath directory_path = UTF8ToFilePath("series/of/directories"); | 524 FilePath directory_path = UTF8ToFilePath("series/of/directories"); |
443 path = directory_path.AppendASCII("file name"); | 525 path = directory_path.AppendASCII("file name"); |
444 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 526 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
445 context.get(), directory_path, exclusive, recursive)); | 527 context.get(), directory_path, exclusive, recursive)); |
446 | 528 |
447 context.reset(NewContext()); | 529 context.reset(NewContext(NULL)); |
448 file_handle = base::kInvalidPlatformFileValue; | 530 file_handle = base::kInvalidPlatformFileValue; |
449 ASSERT_EQ(base::PLATFORM_FILE_OK, | 531 ASSERT_EQ(base::PLATFORM_FILE_OK, |
450 ofsfu()->CreateOrOpen( | 532 ofsfu()->CreateOrOpen( |
451 context.get(), path, file_flags, &file_handle, &created)); | 533 context.get(), path, file_flags, &file_handle, &created)); |
452 ASSERT_TRUE(created); | 534 ASSERT_TRUE(created); |
453 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 535 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
454 | 536 |
455 CheckFileAndCloseHandle(path, file_handle); | 537 CheckFileAndCloseHandle(path, file_handle); |
456 | 538 |
457 context.reset(NewContext()); | 539 context.reset(NewContext(NULL)); |
458 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 540 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
459 context.get(), path, &local_path)); | 541 context.get(), path, &local_path)); |
460 EXPECT_TRUE(file_util::PathExists(local_path)); | 542 EXPECT_TRUE(file_util::PathExists(local_path)); |
461 | 543 |
462 context.reset(NewContext()); | 544 context.reset(NewContext(NULL)); |
463 EXPECT_EQ(base::PLATFORM_FILE_OK, | 545 EXPECT_EQ(base::PLATFORM_FILE_OK, |
464 ofsfu()->DeleteFile(context.get(), path)); | 546 ofsfu()->DeleteFile(context.get(), path)); |
465 EXPECT_FALSE(file_util::PathExists(local_path)); | 547 EXPECT_FALSE(file_util::PathExists(local_path)); |
466 } | 548 } |
467 | 549 |
468 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { | 550 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { |
469 bool created = false; | 551 bool created = false; |
470 FilePath path = UTF8ToFilePath("file"); | 552 FilePath path = UTF8ToFilePath("file"); |
471 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 553 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
472 | 554 |
473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 555 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
474 ofsfu()->Truncate(context.get(), path, 4)); | 556 ofsfu()->Truncate(context.get(), path, 4)); |
475 | 557 |
476 context.reset(NewContext()); | 558 context.reset(NewContext(NULL)); |
477 ASSERT_EQ(base::PLATFORM_FILE_OK, | 559 ASSERT_EQ(base::PLATFORM_FILE_OK, |
478 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 560 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
479 ASSERT_TRUE(created); | 561 ASSERT_TRUE(created); |
480 | 562 |
481 context.reset(NewContext()); | 563 context.reset(NewContext(NULL)); |
482 FilePath local_path; | 564 FilePath local_path; |
483 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 565 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
484 context.get(), path, &local_path)); | 566 context.get(), path, &local_path)); |
485 EXPECT_EQ(0, GetSize(local_path)); | 567 EXPECT_EQ(0, GetSize(local_path)); |
486 | 568 |
487 context.reset(NewContext()); | 569 context.reset(NewContext(NULL)); |
488 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 570 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
489 context.get(), path, 10)); | 571 context.get(), path, 10)); |
490 EXPECT_EQ(10, GetSize(local_path)); | 572 EXPECT_EQ(10, GetSize(local_path)); |
491 | 573 |
492 context.reset(NewContext()); | 574 context.reset(NewContext(NULL)); |
493 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 575 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
494 context.get(), path, 1)); | 576 context.get(), path, 1)); |
495 EXPECT_EQ(1, GetSize(local_path)); | 577 EXPECT_EQ(1, GetSize(local_path)); |
496 | 578 |
497 context.reset(NewContext()); | 579 context.reset(NewContext(NULL)); |
498 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 580 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
499 context.reset(NewContext()); | 581 context.reset(NewContext(NULL)); |
500 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 582 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
501 } | 583 } |
502 | 584 |
503 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { | 585 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { |
504 FilePath path = UTF8ToFilePath("fake/file"); | 586 FilePath path = UTF8ToFilePath("fake/file"); |
505 bool created = false; | 587 bool created = false; |
506 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 588 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
507 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 589 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
508 ofsfu()->EnsureFileExists( | 590 ofsfu()->EnsureFileExists( |
509 context.get(), path, &created)); | 591 context.get(), path, &created)); |
510 | 592 |
511 context.reset(NewContext()); | 593 context.reset(NewContext(NULL)); |
512 path = UTF8ToFilePath("test file"); | 594 path = UTF8ToFilePath("test file"); |
513 created = false; | 595 created = false; |
514 ASSERT_EQ(base::PLATFORM_FILE_OK, | 596 ASSERT_EQ(base::PLATFORM_FILE_OK, |
515 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 597 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
516 ASSERT_TRUE(created); | 598 ASSERT_TRUE(created); |
517 | 599 |
518 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); | 600 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); |
519 | 601 |
520 context.reset(NewContext()); | 602 context.reset(NewContext(NULL)); |
521 ASSERT_EQ(base::PLATFORM_FILE_OK, | 603 ASSERT_EQ(base::PLATFORM_FILE_OK, |
522 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 604 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
523 ASSERT_FALSE(created); | 605 ASSERT_FALSE(created); |
524 | 606 |
525 // Also test in a subdirectory. | 607 // Also test in a subdirectory. |
526 path = UTF8ToFilePath("path/to/file.txt"); | 608 path = UTF8ToFilePath("path/to/file.txt"); |
527 context.reset(NewContext()); | 609 context.reset(NewContext(NULL)); |
528 bool exclusive = true; | 610 bool exclusive = true; |
529 bool recursive = true; | 611 bool recursive = true; |
530 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 612 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
531 context.get(), path.DirName(), exclusive, recursive)); | 613 context.get(), path.DirName(), exclusive, recursive)); |
532 | 614 |
533 context.reset(NewContext()); | 615 context.reset(NewContext(NULL)); |
534 ASSERT_EQ(base::PLATFORM_FILE_OK, | 616 ASSERT_EQ(base::PLATFORM_FILE_OK, |
535 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 617 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
536 ASSERT_TRUE(created); | 618 ASSERT_TRUE(created); |
537 context.reset(NewContext()); | 619 context.reset(NewContext(NULL)); |
538 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 620 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
539 context.reset(NewContext()); | 621 context.reset(NewContext(NULL)); |
540 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 622 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
541 } | 623 } |
542 | 624 |
543 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { | 625 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
544 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 626 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
545 | 627 |
546 bool exclusive = false; | 628 bool exclusive = false; |
547 bool recursive = false; | 629 bool recursive = false; |
548 FilePath path = UTF8ToFilePath("foo/bar"); | 630 FilePath path = UTF8ToFilePath("foo/bar"); |
549 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( | 631 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( |
550 context.get(), path, exclusive, recursive)); | 632 context.get(), path, exclusive, recursive)); |
551 | 633 |
552 context.reset(NewContext()); | 634 context.reset(NewContext(NULL)); |
553 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 635 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
554 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 636 ofsfu()->DeleteSingleDirectory(context.get(), path)); |
555 | 637 |
556 FilePath root = UTF8ToFilePath(""); | 638 FilePath root = UTF8ToFilePath(""); |
557 context.reset(NewContext()); | 639 context.reset(NewContext(NULL)); |
558 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 640 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
559 context.reset(NewContext()); | 641 context.reset(NewContext(NULL)); |
560 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 642 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
561 context.reset(NewContext()); | 643 context.reset(NewContext(NULL)); |
562 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 644 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
563 | 645 |
564 context.reset(NewContext()); | 646 context.reset(NewContext(NULL)); |
565 exclusive = false; | 647 exclusive = false; |
566 recursive = true; | 648 recursive = true; |
567 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 649 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
568 context.get(), path, exclusive, recursive)); | 650 context.get(), path, exclusive, recursive)); |
569 | 651 |
570 context.reset(NewContext()); | 652 context.reset(NewContext(NULL)); |
571 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 653 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
572 context.reset(NewContext()); | 654 context.reset(NewContext(NULL)); |
573 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 655 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
574 context.reset(NewContext()); | 656 context.reset(NewContext(NULL)); |
575 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 657 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
576 context.reset(NewContext()); | 658 context.reset(NewContext(NULL)); |
577 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); | 659 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); |
578 context.reset(NewContext()); | 660 context.reset(NewContext(NULL)); |
579 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); | 661 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); |
580 | 662 |
581 // Can't remove a non-empty directory. | 663 // Can't remove a non-empty directory. |
582 context.reset(NewContext()); | 664 context.reset(NewContext(NULL)); |
583 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 665 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
584 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); | 666 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); |
585 | 667 |
586 base::PlatformFileInfo file_info; | 668 base::PlatformFileInfo file_info; |
587 FilePath local_path; | 669 FilePath local_path; |
588 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 670 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
589 context.get(), path, &file_info, &local_path)); | 671 context.get(), path, &file_info, &local_path)); |
590 EXPECT_TRUE(local_path.empty()); | 672 EXPECT_TRUE(local_path.empty()); |
591 EXPECT_TRUE(file_info.is_directory); | 673 EXPECT_TRUE(file_info.is_directory); |
592 EXPECT_FALSE(file_info.is_symbolic_link); | 674 EXPECT_FALSE(file_info.is_symbolic_link); |
593 | 675 |
594 // Same create again should succeed, since exclusive is false. | 676 // Same create again should succeed, since exclusive is false. |
595 context.reset(NewContext()); | 677 context.reset(NewContext(NULL)); |
596 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 678 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
597 context.get(), path, exclusive, recursive)); | 679 context.get(), path, exclusive, recursive)); |
598 | 680 |
599 exclusive = true; | 681 exclusive = true; |
600 recursive = true; | 682 recursive = true; |
601 context.reset(NewContext()); | 683 context.reset(NewContext(NULL)); |
602 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 684 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
603 context.get(), path, exclusive, recursive)); | 685 context.get(), path, exclusive, recursive)); |
604 | 686 |
605 context.reset(NewContext()); | 687 context.reset(NewContext(NULL)); |
606 EXPECT_EQ(base::PLATFORM_FILE_OK, | 688 EXPECT_EQ(base::PLATFORM_FILE_OK, |
607 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 689 ofsfu()->DeleteSingleDirectory(context.get(), path)); |
608 | 690 |
609 path = UTF8ToFilePath("foo/bop"); | 691 path = UTF8ToFilePath("foo/bop"); |
610 | 692 |
611 context.reset(NewContext()); | 693 context.reset(NewContext(NULL)); |
612 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 694 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
613 context.reset(NewContext()); | 695 context.reset(NewContext(NULL)); |
614 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 696 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
615 context.reset(NewContext()); | 697 context.reset(NewContext(NULL)); |
616 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 698 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); |
617 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 699 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
618 context.get(), path, &file_info, &local_path)); | 700 context.get(), path, &file_info, &local_path)); |
619 | 701 |
620 exclusive = true; | 702 exclusive = true; |
621 recursive = false; | 703 recursive = false; |
622 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 704 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
623 context.get(), path, exclusive, recursive)); | 705 context.get(), path, exclusive, recursive)); |
624 | 706 |
625 context.reset(NewContext()); | 707 context.reset(NewContext(NULL)); |
626 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 708 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
627 context.reset(NewContext()); | 709 context.reset(NewContext(NULL)); |
628 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 710 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
629 | 711 |
630 exclusive = true; | 712 exclusive = true; |
631 recursive = false; | 713 recursive = false; |
632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 714 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
633 context.get(), path, exclusive, recursive)); | 715 context.get(), path, exclusive, recursive)); |
634 | 716 |
635 exclusive = true; | 717 exclusive = true; |
636 recursive = false; | 718 recursive = false; |
637 path = UTF8ToFilePath("foo"); | 719 path = UTF8ToFilePath("foo"); |
638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 720 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
639 context.get(), path, exclusive, recursive)); | 721 context.get(), path, exclusive, recursive)); |
640 | 722 |
641 path = UTF8ToFilePath("blah"); | 723 path = UTF8ToFilePath("blah"); |
642 | 724 |
643 context.reset(NewContext()); | 725 context.reset(NewContext(NULL)); |
644 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 726 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
645 context.reset(NewContext()); | 727 context.reset(NewContext(NULL)); |
646 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 728 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
647 | 729 |
648 exclusive = true; | 730 exclusive = true; |
649 recursive = false; | 731 recursive = false; |
650 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 732 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
651 context.get(), path, exclusive, recursive)); | 733 context.get(), path, exclusive, recursive)); |
652 | 734 |
653 context.reset(NewContext()); | 735 context.reset(NewContext(NULL)); |
654 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 736 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
655 context.reset(NewContext()); | 737 context.reset(NewContext(NULL)); |
656 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 738 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
657 | 739 |
658 exclusive = true; | 740 exclusive = true; |
659 recursive = false; | 741 recursive = false; |
660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 742 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
661 context.get(), path, exclusive, recursive)); | 743 context.get(), path, exclusive, recursive)); |
662 } | 744 } |
663 | 745 |
664 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { | 746 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { |
665 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 747 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
666 bool exclusive = true; | 748 bool exclusive = true; |
667 bool recursive = true; | 749 bool recursive = true; |
668 FilePath path = UTF8ToFilePath("directory/to/use"); | 750 FilePath path = UTF8ToFilePath("directory/to/use"); |
669 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 751 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
670 context.get(), path, exclusive, recursive)); | 752 context.get(), path, exclusive, recursive)); |
671 TestReadDirectoryHelper(path); | 753 TestReadDirectoryHelper(path); |
672 } | 754 } |
673 | 755 |
674 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { | 756 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { |
675 TestReadDirectoryHelper(UTF8ToFilePath("")); | 757 TestReadDirectoryHelper(UTF8ToFilePath("")); |
676 } | 758 } |
677 | 759 |
678 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { | 760 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { |
679 TestReadDirectoryHelper(UTF8ToFilePath("/")); | 761 TestReadDirectoryHelper(UTF8ToFilePath("/")); |
680 } | 762 } |
681 | 763 |
682 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { | 764 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { |
683 FilePath path = UTF8ToFilePath("file"); | 765 FilePath path = UTF8ToFilePath("file"); |
684 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 766 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
685 | 767 |
686 bool created = false; | 768 bool created = false; |
687 ASSERT_EQ(base::PLATFORM_FILE_OK, | 769 ASSERT_EQ(base::PLATFORM_FILE_OK, |
688 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 770 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
689 ASSERT_TRUE(created); | 771 ASSERT_TRUE(created); |
690 | 772 |
691 context.reset(NewContext()); | 773 context.reset(NewContext(NULL)); |
692 std::vector<base::FileUtilProxy::Entry> entries; | 774 std::vector<base::FileUtilProxy::Entry> entries; |
693 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 775 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
694 ofsfu()->ReadDirectory(context.get(), path, &entries)); | 776 ofsfu()->ReadDirectory(context.get(), path, &entries)); |
695 | 777 |
696 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 778 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); |
697 } | 779 } |
698 | 780 |
699 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { | 781 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { |
700 FilePath path = UTF8ToFilePath("fake/file"); | 782 FilePath path = UTF8ToFilePath("fake/file"); |
701 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 783 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
702 base::Time last_modified_time = base::Time::Now(); | 784 base::Time last_modified_time = base::Time::Now(); |
703 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 785 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 786 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
705 ofsfu()->Touch( | 787 ofsfu()->Touch( |
706 context.get(), path, last_access_time, last_modified_time)); | 788 context.get(), path, last_access_time, last_modified_time)); |
707 | 789 |
708 // Touch will create a file if it's not there but its parent is. | 790 // Touch will create a file if it's not there but its parent is. |
709 path = UTF8ToFilePath("file name"); | 791 path = UTF8ToFilePath("file name"); |
710 TestTouchHelper(path); | 792 TestTouchHelper(path); |
711 | 793 |
712 bool exclusive = true; | 794 bool exclusive = true; |
713 bool recursive = true; | 795 bool recursive = true; |
714 path = UTF8ToFilePath("directory/to/use"); | 796 path = UTF8ToFilePath("directory/to/use"); |
715 context.reset(NewContext()); | 797 context.reset(NewContext(NULL)); |
716 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 798 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
717 context.get(), path, exclusive, recursive)); | 799 context.get(), path, exclusive, recursive)); |
718 TestTouchHelper(path); | 800 TestTouchHelper(path); |
719 } | 801 } |
720 | 802 |
| 803 TEST_F(ObfuscatedFileSystemFileUtilTest, TestPathQuotas) { |
| 804 FilePath path = UTF8ToFilePath("fake/file"); |
| 805 base::Time last_access_time = base::Time::Now(); |
| 806 base::Time last_modified_time = base::Time::Now(); |
| 807 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 808 |
| 809 // Touch will create a file if it's not there but its parent is. |
| 810 path = UTF8ToFilePath("file name"); |
| 811 context->set_allowed_bytes_growth(5); |
| 812 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 813 ofsfu()->Touch( |
| 814 context.get(), path, last_access_time, last_modified_time)); |
| 815 context->set_allowed_bytes_growth(1024); |
| 816 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 817 ofsfu()->Touch( |
| 818 context.get(), path, last_access_time, last_modified_time)); |
| 819 int64 path_cost = ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); |
| 820 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| 821 |
| 822 context->set_allowed_bytes_growth(1024); |
| 823 bool exclusive = true; |
| 824 bool recursive = true; |
| 825 path = UTF8ToFilePath("directory/to/use"); |
| 826 std::vector<FilePath::StringType> components; |
| 827 path.GetComponents(&components); |
| 828 path_cost = 0; |
| 829 for (std::vector<FilePath::StringType>::iterator iter = components.begin(); |
| 830 iter != components.end(); ++iter) { |
| 831 path_cost += ObfuscatedFileSystemFileUtil::ComputeFilePathCost( |
| 832 FilePath(*iter)); |
| 833 } |
| 834 context.reset(NewContext(NULL)); |
| 835 context->set_allowed_bytes_growth(1024); |
| 836 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| 837 context.get(), path, exclusive, recursive)); |
| 838 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| 839 } |
| 840 |
721 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { | 841 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { |
722 FilePath source_path = UTF8ToFilePath("path0.txt"); | 842 FilePath source_path = UTF8ToFilePath("path0.txt"); |
723 FilePath dest_path = UTF8ToFilePath("path1.txt"); | 843 FilePath dest_path = UTF8ToFilePath("path1.txt"); |
724 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 844 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
725 | 845 |
726 bool is_copy_not_move = false; | 846 bool is_copy_not_move = false; |
727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 847 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
728 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 848 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
729 is_copy_not_move)); | 849 is_copy_not_move)); |
730 context.reset(NewContext()); | 850 context.reset(NewContext(NULL)); |
731 is_copy_not_move = true; | 851 is_copy_not_move = true; |
732 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 852 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
733 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 853 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
734 is_copy_not_move)); | 854 is_copy_not_move)); |
735 source_path = UTF8ToFilePath("dir/dir/file"); | 855 source_path = UTF8ToFilePath("dir/dir/file"); |
736 bool exclusive = true; | 856 bool exclusive = true; |
737 bool recursive = true; | 857 bool recursive = true; |
738 context.reset(NewContext()); | 858 context.reset(NewContext(NULL)); |
739 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 859 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
740 context.get(), source_path.DirName(), exclusive, recursive)); | 860 context.get(), source_path.DirName(), exclusive, recursive)); |
741 is_copy_not_move = false; | 861 is_copy_not_move = false; |
742 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 862 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
743 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 863 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
744 is_copy_not_move)); | 864 is_copy_not_move)); |
745 context.reset(NewContext()); | 865 context.reset(NewContext(NULL)); |
746 is_copy_not_move = true; | 866 is_copy_not_move = true; |
747 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 867 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
748 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 868 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
749 is_copy_not_move)); | 869 is_copy_not_move)); |
750 } | 870 } |
751 | 871 |
752 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { | 872 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { |
753 const int64 kSourceLength = 5; | 873 const int64 kSourceLength = 5; |
754 const int64 kDestLength = 50; | 874 const int64 kDestLength = 50; |
755 | 875 |
756 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { | 876 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { |
757 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); | 877 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); |
758 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; | 878 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; |
759 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << | 879 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << |
760 test_case.is_copy_not_move); | 880 test_case.is_copy_not_move); |
761 SCOPED_TRACE(testing::Message() << "\t source_path " << | 881 SCOPED_TRACE(testing::Message() << "\t source_path " << |
762 test_case.source_path); | 882 test_case.source_path); |
763 SCOPED_TRACE(testing::Message() << "\t dest_path " << | 883 SCOPED_TRACE(testing::Message() << "\t dest_path " << |
764 test_case.dest_path); | 884 test_case.dest_path); |
765 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << | 885 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << |
766 test_case.cause_overwrite); | 886 test_case.cause_overwrite); |
767 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 887 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
768 | 888 |
769 bool exclusive = false; | 889 bool exclusive = false; |
770 bool recursive = true; | 890 bool recursive = true; |
771 FilePath source_path = UTF8ToFilePath(test_case.source_path); | 891 FilePath source_path = UTF8ToFilePath(test_case.source_path); |
772 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); | 892 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); |
773 | 893 |
774 context.reset(NewContext()); | 894 context.reset(NewContext(NULL)); |
775 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 895 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
776 context.get(), source_path.DirName(), exclusive, recursive)); | 896 context.get(), source_path.DirName(), exclusive, recursive)); |
777 context.reset(NewContext()); | 897 context.reset(NewContext(NULL)); |
778 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 898 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
779 context.get(), dest_path.DirName(), exclusive, recursive)); | 899 context.get(), dest_path.DirName(), exclusive, recursive)); |
780 | 900 |
781 bool created = false; | 901 bool created = false; |
782 context.reset(NewContext()); | 902 context.reset(NewContext(NULL)); |
783 ASSERT_EQ(base::PLATFORM_FILE_OK, | 903 ASSERT_EQ(base::PLATFORM_FILE_OK, |
784 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); | 904 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); |
785 ASSERT_TRUE(created); | 905 ASSERT_TRUE(created); |
786 context.reset(NewContext()); | 906 context.reset(NewContext(NULL)); |
787 ASSERT_EQ(base::PLATFORM_FILE_OK, | 907 ASSERT_EQ(base::PLATFORM_FILE_OK, |
788 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); | 908 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); |
789 | 909 |
790 if (test_case.cause_overwrite) { | 910 if (test_case.cause_overwrite) { |
791 context.reset(NewContext()); | 911 context.reset(NewContext(NULL)); |
792 created = false; | 912 created = false; |
793 ASSERT_EQ(base::PLATFORM_FILE_OK, | 913 ASSERT_EQ(base::PLATFORM_FILE_OK, |
794 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 914 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
795 ASSERT_TRUE(created); | 915 ASSERT_TRUE(created); |
796 context.reset(NewContext()); | 916 context.reset(NewContext(NULL)); |
797 ASSERT_EQ(base::PLATFORM_FILE_OK, | 917 ASSERT_EQ(base::PLATFORM_FILE_OK, |
798 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); | 918 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); |
799 } | 919 } |
800 | 920 |
801 context.reset(NewContext()); | 921 context.reset(NewContext(NULL)); |
802 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), | 922 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), |
803 source_path, dest_path, test_case.is_copy_not_move)); | 923 source_path, dest_path, test_case.is_copy_not_move)); |
804 if (test_case.is_copy_not_move) { | 924 if (test_case.is_copy_not_move) { |
805 base::PlatformFileInfo file_info; | 925 base::PlatformFileInfo file_info; |
806 FilePath local_path; | 926 FilePath local_path; |
807 context.reset(NewContext()); | 927 context.reset(NewContext(NULL)); |
808 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 928 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
809 context.get(), source_path, &file_info, &local_path)); | 929 context.get(), source_path, &file_info, &local_path)); |
810 EXPECT_EQ(kSourceLength, file_info.size); | 930 EXPECT_EQ(kSourceLength, file_info.size); |
811 EXPECT_EQ(base::PLATFORM_FILE_OK, | 931 EXPECT_EQ(base::PLATFORM_FILE_OK, |
812 ofsfu()->DeleteFile(context.get(), source_path)); | 932 ofsfu()->DeleteFile(context.get(), source_path)); |
813 } else { | 933 } else { |
814 base::PlatformFileInfo file_info; | 934 base::PlatformFileInfo file_info; |
815 FilePath local_path; | 935 FilePath local_path; |
816 context.reset(NewContext()); | 936 context.reset(NewContext(NULL)); |
817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 937 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
818 context.get(), source_path, &file_info, &local_path)); | 938 context.get(), source_path, &file_info, &local_path)); |
819 } | 939 } |
820 base::PlatformFileInfo file_info; | 940 base::PlatformFileInfo file_info; |
821 FilePath local_path; | 941 FilePath local_path; |
822 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 942 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
823 context.get(), dest_path, &file_info, &local_path)); | 943 context.get(), dest_path, &file_info, &local_path)); |
824 EXPECT_EQ(kSourceLength, file_info.size); | 944 EXPECT_EQ(kSourceLength, file_info.size); |
825 | 945 |
826 EXPECT_EQ(base::PLATFORM_FILE_OK, | 946 EXPECT_EQ(base::PLATFORM_FILE_OK, |
827 ofsfu()->DeleteFile(context.get(), dest_path)); | 947 ofsfu()->DeleteFile(context.get(), dest_path)); |
828 } | 948 } |
829 } | 949 } |
830 | 950 |
831 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { | 951 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { |
832 TestCopyInForeignFileHelper(false /* overwrite */); | 952 TestCopyInForeignFileHelper(false /* overwrite */); |
833 TestCopyInForeignFileHelper(true /* overwrite */); | 953 TestCopyInForeignFileHelper(true /* overwrite */); |
834 } | 954 } |
835 | 955 |
836 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { | 956 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { |
837 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 957 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
838 FilePath src_path = UTF8ToFilePath("source dir"); | 958 FilePath src_path = UTF8ToFilePath("source dir"); |
839 bool exclusive = true; | 959 bool exclusive = true; |
840 bool recursive = false; | 960 bool recursive = false; |
841 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 961 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
842 context.get(), src_path, exclusive, recursive)); | 962 context.get(), src_path, exclusive, recursive)); |
843 | 963 |
844 std::set<FilePath::StringType> files; | 964 std::set<FilePath::StringType> files; |
845 std::set<FilePath::StringType> directories; | 965 std::set<FilePath::StringType> directories; |
846 FillTestDirectory(src_path, &files, &directories); | 966 FillTestDirectory(src_path, &files, &directories); |
847 | 967 |
848 FilePath dest_path = UTF8ToFilePath("destination dir"); | 968 FilePath dest_path = UTF8ToFilePath("destination dir"); |
849 | 969 |
850 context.reset(NewContext()); | 970 context.reset(NewContext(NULL)); |
851 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 971 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
852 context.reset(NewContext()); | 972 context.reset(NewContext(NULL)); |
853 ASSERT_EQ(base::PLATFORM_FILE_OK, | 973 ASSERT_EQ(base::PLATFORM_FILE_OK, |
854 ofsfu()->Copy(context.get(), src_path, dest_path)); | 974 ofsfu()->Copy(context.get(), src_path, dest_path)); |
855 | 975 |
856 ValidateTestDirectory(dest_path, files, directories); | 976 ValidateTestDirectory(dest_path, files, directories); |
857 context.reset(NewContext()); | 977 context.reset(NewContext(NULL)); |
858 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); | 978 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); |
859 context.reset(NewContext()); | 979 context.reset(NewContext(NULL)); |
860 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 980 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
861 context.reset(NewContext()); | 981 context.reset(NewContext(NULL)); |
862 recursive = true; | 982 recursive = true; |
863 ASSERT_EQ(base::PLATFORM_FILE_OK, | 983 ASSERT_EQ(base::PLATFORM_FILE_OK, |
864 ofsfu()->Delete(context.get(), dest_path, recursive)); | 984 ofsfu()->Delete(context.get(), dest_path, recursive)); |
865 context.reset(NewContext()); | 985 context.reset(NewContext(NULL)); |
866 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 986 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
867 } | 987 } |
868 | 988 |
869 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { | 989 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
870 ScopedTempDir source_dir; | 990 ScopedTempDir source_dir; |
871 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 991 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
872 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); | 992 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
873 ASSERT_TRUE(file_util::CreateDirectory(root_path)); | 993 ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
874 | 994 |
875 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 995 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
(...skipping 12 matching lines...) Expand all Loading... |
888 local_src_path, file_flags, &created, &error_code); | 1008 local_src_path, file_flags, &created, &error_code); |
889 EXPECT_TRUE(created); | 1009 EXPECT_TRUE(created); |
890 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 1010 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
891 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | 1011 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
892 ASSERT_TRUE( | 1012 ASSERT_TRUE( |
893 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); | 1013 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); |
894 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 1014 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
895 } | 1015 } |
896 } | 1016 } |
897 | 1017 |
898 EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin_url(), type(), root_path)); | 1018 EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin(), type(), root_path)); |
899 | 1019 |
900 FilePath new_root = | 1020 FilePath new_root = |
901 test_directory().AppendASCII("000").Append( | 1021 test_directory().AppendASCII("File System").AppendASCII("000").Append( |
902 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); | 1022 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); |
903 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 1023 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
904 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); | 1024 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); |
905 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; | 1025 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
906 FilePath local_data_path = new_root.Append(test_case.path); | 1026 FilePath local_data_path = new_root.Append(test_case.path); |
907 #if defined(OS_WIN) | 1027 #if defined(OS_WIN) |
908 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); | 1028 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); |
909 #endif | 1029 #endif |
910 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1030 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
911 base::PlatformFileInfo ofsfu_file_info; | 1031 base::PlatformFileInfo ofsfu_file_info; |
912 FilePath data_path; | 1032 FilePath data_path; |
913 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); | 1033 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
914 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1034 EXPECT_EQ(base::PLATFORM_FILE_OK, |
915 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), | 1035 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), |
916 &ofsfu_file_info, &data_path)); | 1036 &ofsfu_file_info, &data_path)); |
917 if (test_case.is_directory) { | 1037 if (test_case.is_directory) { |
918 EXPECT_TRUE(ofsfu_file_info.is_directory); | 1038 EXPECT_TRUE(ofsfu_file_info.is_directory); |
919 } else { | 1039 } else { |
920 base::PlatformFileInfo platform_file_info; | 1040 base::PlatformFileInfo platform_file_info; |
921 SCOPED_TRACE(testing::Message() << "local_data_path is " << | 1041 SCOPED_TRACE(testing::Message() << "local_data_path is " << |
922 local_data_path.value()); | 1042 local_data_path.value()); |
923 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); | 1043 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); |
924 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); | 1044 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
925 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); | 1045 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
926 EXPECT_FALSE(platform_file_info.is_directory); | 1046 EXPECT_FALSE(platform_file_info.is_directory); |
927 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1047 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
928 EXPECT_EQ(local_data_path, data_path); | 1048 EXPECT_EQ(local_data_path, data_path); |
929 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); | 1049 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); |
930 EXPECT_FALSE(ofsfu_file_info.is_directory); | 1050 EXPECT_FALSE(ofsfu_file_info.is_directory); |
931 } | 1051 } |
932 } | 1052 } |
933 } | 1053 } |
934 | 1054 |
935 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { | 1055 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { |
| 1056 scoped_refptr<ObfuscatedFileSystemFileUtil> file_util = |
| 1057 new ObfuscatedFileSystemFileUtil(test_directory(), |
| 1058 new FileSystemFileUtil()); |
936 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> | 1059 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> |
937 enumerator(ofsfu()->CreateOriginEnumerator()); | 1060 enumerator(file_util->CreateOriginEnumerator()); |
938 EXPECT_TRUE(enumerator.get()); | 1061 EXPECT_TRUE(enumerator.get()); |
939 EXPECT_EQ(GURL(), enumerator->Next()); | 1062 EXPECT_EQ(GURL(), enumerator->Next()); |
940 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); | 1063 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); |
941 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); | 1064 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); |
942 | 1065 |
943 std::set<GURL> origins_expected; | 1066 std::set<GURL> origins_expected; |
944 | 1067 |
945 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { | 1068 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { |
946 SCOPED_TRACE(testing::Message() << | 1069 SCOPED_TRACE(testing::Message() << |
947 "Validating kOriginEnumerationTestRecords " << i); | 1070 "Validating kOriginEnumerationTestRecords " << i); |
948 const OriginEnumerationTestRecord& record = | 1071 const OriginEnumerationTestRecord& record = |
949 kOriginEnumerationTestRecords[i]; | 1072 kOriginEnumerationTestRecords[i]; |
950 GURL origin_url(record.origin_url); | 1073 GURL origin_url(record.origin_url); |
951 origins_expected.insert(origin_url); | 1074 origins_expected.insert(origin_url); |
952 if (record.has_temporary) { | 1075 if (record.has_temporary) { |
953 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1076 scoped_ptr<FileSystemTestOriginHelper> helper( |
| 1077 NewHelper(origin_url, kFileSystemTypeTemporary)); |
| 1078 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
954 context->set_src_origin_url(origin_url); | 1079 context->set_src_origin_url(origin_url); |
955 context->set_src_type(kFileSystemTypeTemporary); | 1080 context->set_src_type(kFileSystemTypeTemporary); |
956 bool created = false; | 1081 bool created = false; |
957 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1082 ASSERT_EQ(base::PLATFORM_FILE_OK, |
958 ofsfu()->EnsureFileExists(context.get(), | 1083 file_util->EnsureFileExists(context.get(), |
959 FilePath().AppendASCII("file"), &created)); | 1084 FilePath().AppendASCII("file"), &created)); |
960 EXPECT_TRUE(created); | 1085 EXPECT_TRUE(created); |
961 } | 1086 } |
962 if (record.has_persistent) { | 1087 if (record.has_persistent) { |
963 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 1088 scoped_ptr<FileSystemTestOriginHelper> helper( |
| 1089 NewHelper(origin_url, kFileSystemTypePersistent)); |
| 1090 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
964 context->set_src_origin_url(origin_url); | 1091 context->set_src_origin_url(origin_url); |
965 context->set_src_type(kFileSystemTypePersistent); | 1092 context->set_src_type(kFileSystemTypePersistent); |
966 bool created = false; | 1093 bool created = false; |
967 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1094 ASSERT_EQ(base::PLATFORM_FILE_OK, |
968 ofsfu()->EnsureFileExists(context.get(), | 1095 file_util->EnsureFileExists(context.get(), |
969 FilePath().AppendASCII("file"), &created)); | 1096 FilePath().AppendASCII("file"), &created)); |
970 EXPECT_TRUE(created); | 1097 EXPECT_TRUE(created); |
971 } | 1098 } |
972 } | 1099 } |
973 enumerator.reset(ofsfu()->CreateOriginEnumerator()); | 1100 enumerator.reset(file_util->CreateOriginEnumerator()); |
974 EXPECT_TRUE(enumerator.get()); | 1101 EXPECT_TRUE(enumerator.get()); |
975 std::set<GURL> origins_found; | 1102 std::set<GURL> origins_found; |
976 GURL origin; | 1103 GURL origin; |
977 while (!(origin = enumerator->Next()).is_empty()) { | 1104 while (!(origin = enumerator->Next()).is_empty()) { |
978 origins_found.insert(origin); | 1105 origins_found.insert(origin); |
979 SCOPED_TRACE(testing::Message() << "Handling " << origin.spec()); | 1106 SCOPED_TRACE(testing::Message() << "Handling " << origin.spec()); |
980 bool found = false; | 1107 bool found = false; |
981 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords); | 1108 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords); |
982 ++i) { | 1109 ++i) { |
983 const OriginEnumerationTestRecord& record = | 1110 const OriginEnumerationTestRecord& record = |
984 kOriginEnumerationTestRecords[i]; | 1111 kOriginEnumerationTestRecords[i]; |
985 if (GURL(record.origin_url) != origin) | 1112 if (GURL(record.origin_url) != origin) |
986 continue; | 1113 continue; |
987 found = true; | 1114 found = true; |
988 EXPECT_EQ(record.has_temporary, | 1115 EXPECT_EQ(record.has_temporary, |
989 enumerator->HasFileSystemType(kFileSystemTypeTemporary)); | 1116 enumerator->HasFileSystemType(kFileSystemTypeTemporary)); |
990 EXPECT_EQ(record.has_persistent, | 1117 EXPECT_EQ(record.has_persistent, |
991 enumerator->HasFileSystemType(kFileSystemTypePersistent)); | 1118 enumerator->HasFileSystemType(kFileSystemTypePersistent)); |
992 } | 1119 } |
993 EXPECT_TRUE(found); | 1120 EXPECT_TRUE(found); |
994 } | 1121 } |
995 | 1122 |
996 std::set<GURL> diff; | 1123 std::set<GURL> diff; |
997 std::set_symmetric_difference(origins_expected.begin(), | 1124 std::set_symmetric_difference(origins_expected.begin(), |
998 origins_expected.end(), origins_found.begin(), origins_found.end(), | 1125 origins_expected.end(), origins_found.begin(), origins_found.end(), |
999 inserter(diff, diff.begin())); | 1126 inserter(diff, diff.begin())); |
1000 EXPECT_TRUE(diff.empty()); | 1127 EXPECT_TRUE(diff.empty()); |
1001 } | 1128 } |
| 1129 |
| 1130 TEST_F(ObfuscatedFileSystemFileUtilTest, TestRevokeUsageCache) { |
| 1131 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1132 |
| 1133 int64 expected_quota = FileSystemUsageCache::kUsageFileSize; |
| 1134 |
| 1135 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 1136 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); |
| 1137 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 1138 FilePath path(test_case.path); |
| 1139 expected_quota += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); |
| 1140 if (test_case.is_directory) { |
| 1141 bool exclusive = true; |
| 1142 bool recursive = false; |
| 1143 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1144 ofsfu()->CreateDirectory(context.get(), path, exclusive, recursive)); |
| 1145 } else { |
| 1146 bool created = false; |
| 1147 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1148 ofsfu()->EnsureFileExists(context.get(), path, &created)); |
| 1149 ASSERT_TRUE(created); |
| 1150 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1151 ofsfu()->Truncate(context.get(), path, |
| 1152 test_case.data_file_size)); |
| 1153 expected_quota += test_case.data_file_size; |
| 1154 } |
| 1155 } |
| 1156 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
| 1157 RevokeUsageCache(); |
| 1158 EXPECT_EQ(-1, SizeInUsageFile()); |
| 1159 GetUsageFromQuotaManager(); |
| 1160 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
| 1161 EXPECT_EQ(expected_quota, usage()); |
| 1162 } |
OLD | NEW |