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

Side by Side Diff: webkit/fileapi/obfuscated_file_util_unittest.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | « webkit/fileapi/obfuscated_file_util.cc ('k') | webkit/fileapi/remote_file_system_proxy.h » ('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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 15 matching lines...) Expand all
26 #include "webkit/fileapi/obfuscated_file_util.h" 26 #include "webkit/fileapi/obfuscated_file_util.h"
27 #include "webkit/fileapi/test_file_set.h" 27 #include "webkit/fileapi/test_file_set.h"
28 #include "webkit/quota/mock_special_storage_policy.h" 28 #include "webkit/quota/mock_special_storage_policy.h"
29 #include "webkit/quota/quota_manager.h" 29 #include "webkit/quota/quota_manager.h"
30 #include "webkit/quota/quota_types.h" 30 #include "webkit/quota/quota_types.h"
31 31
32 namespace fileapi { 32 namespace fileapi {
33 33
34 namespace { 34 namespace {
35 35
36 bool FileExists(const FilePath& path) { 36 bool FileExists(const base::FilePath& path) {
37 return file_util::PathExists(path) && !file_util::DirectoryExists(path); 37 return file_util::PathExists(path) && !file_util::DirectoryExists(path);
38 } 38 }
39 39
40 int64 GetSize(const FilePath& path) { 40 int64 GetSize(const base::FilePath& path) {
41 int64 size; 41 int64 size;
42 EXPECT_TRUE(file_util::GetFileSize(path, &size)); 42 EXPECT_TRUE(file_util::GetFileSize(path, &size));
43 return size; 43 return size;
44 } 44 }
45 45
46 // After a move, the dest exists and the source doesn't. 46 // After a move, the dest exists and the source doesn't.
47 // After a copy, both source and dest exist. 47 // After a copy, both source and dest exist.
48 struct CopyMoveTestCaseRecord { 48 struct CopyMoveTestCaseRecord {
49 bool is_copy_not_move; 49 bool is_copy_not_move;
50 const char source_path[64]; 50 const char source_path[64];
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 new LocalFileSystemTestOriginHelper(origin, type); 184 new LocalFileSystemTestOriginHelper(origin, type);
185 185
186 helper->SetUp(file_system_context_.get()); 186 helper->SetUp(file_system_context_.get());
187 return helper; 187 return helper;
188 } 188 }
189 189
190 ObfuscatedFileUtil* ofu() { 190 ObfuscatedFileUtil* ofu() {
191 return static_cast<ObfuscatedFileUtil*>(test_helper_.file_util()); 191 return static_cast<ObfuscatedFileUtil*>(test_helper_.file_util());
192 } 192 }
193 193
194 const FilePath& test_directory() const { 194 const base::FilePath& test_directory() const {
195 return data_dir_.path(); 195 return data_dir_.path();
196 } 196 }
197 197
198 const GURL& origin() const { 198 const GURL& origin() const {
199 return origin_; 199 return origin_;
200 } 200 }
201 201
202 fileapi::FileSystemType type() const { 202 fileapi::FileSystemType type() const {
203 return type_; 203 return type_;
204 } 204 }
(...skipping 22 matching lines...) Expand all
227 } 227 }
228 228
229 int64 SizeInUsageFile() { 229 int64 SizeInUsageFile() {
230 MessageLoop::current()->RunUntilIdle(); 230 MessageLoop::current()->RunUntilIdle();
231 return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); 231 return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath());
232 } 232 }
233 233
234 bool PathExists(const FileSystemURL& url) { 234 bool PathExists(const FileSystemURL& url) {
235 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 235 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
236 base::PlatformFileInfo file_info; 236 base::PlatformFileInfo file_info;
237 FilePath platform_path; 237 base::FilePath platform_path;
238 base::PlatformFileError error = ofu()->GetFileInfo( 238 base::PlatformFileError error = ofu()->GetFileInfo(
239 context.get(), url, &file_info, &platform_path); 239 context.get(), url, &file_info, &platform_path);
240 return error == base::PLATFORM_FILE_OK; 240 return error == base::PLATFORM_FILE_OK;
241 } 241 }
242 242
243 bool DirectoryExists(const FileSystemURL& url) { 243 bool DirectoryExists(const FileSystemURL& url) {
244 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 244 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
245 return FileUtilHelper::DirectoryExists(context.get(), ofu(), url); 245 return FileUtilHelper::DirectoryExists(context.get(), ofu(), url);
246 } 246 }
247 247
248 int64 usage() const { return usage_; } 248 int64 usage() const { return usage_; }
249 249
250 FileSystemURL CreateURLFromUTF8(const std::string& path) { 250 FileSystemURL CreateURLFromUTF8(const std::string& path) {
251 return test_helper_.CreateURLFromUTF8(path); 251 return test_helper_.CreateURLFromUTF8(path);
252 } 252 }
253 253
254 int64 PathCost(const FileSystemURL& url) { 254 int64 PathCost(const FileSystemURL& url) {
255 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 255 return ObfuscatedFileUtil::ComputeFilePathCost(url.path());
256 } 256 }
257 257
258 FileSystemURL CreateURL(const FilePath& path) { 258 FileSystemURL CreateURL(const base::FilePath& path) {
259 return test_helper_.CreateURL(path); 259 return test_helper_.CreateURL(path);
260 } 260 }
261 261
262 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) { 262 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) {
263 EXPECT_EQ(quota::kQuotaStatusOk, status); 263 EXPECT_EQ(quota::kQuotaStatusOk, status);
264 quota_status_ = status; 264 quota_status_ = status;
265 usage_ = usage; 265 usage_ = usage;
266 } 266 }
267 267
268 void CheckFileAndCloseHandle( 268 void CheckFileAndCloseHandle(
269 const FileSystemURL& url, base::PlatformFile file_handle) { 269 const FileSystemURL& url, base::PlatformFile file_handle) {
270 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 270 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
271 FilePath local_path; 271 base::FilePath local_path;
272 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 272 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
273 context.get(), url, &local_path)); 273 context.get(), url, &local_path));
274 274
275 base::PlatformFileInfo file_info0; 275 base::PlatformFileInfo file_info0;
276 FilePath data_path; 276 base::FilePath data_path;
277 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 277 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
278 context.get(), url, &file_info0, &data_path)); 278 context.get(), url, &file_info0, &data_path));
279 EXPECT_EQ(data_path, local_path); 279 EXPECT_EQ(data_path, local_path);
280 EXPECT_TRUE(FileExists(data_path)); 280 EXPECT_TRUE(FileExists(data_path));
281 EXPECT_EQ(0, GetSize(data_path)); 281 EXPECT_EQ(0, GetSize(data_path));
282 282
283 const char data[] = "test data"; 283 const char data[] = "test data";
284 const int length = arraysize(data) - 1; 284 const int length = arraysize(data) - 1;
285 285
286 if (base::kInvalidPlatformFileValue == file_handle) { 286 if (base::kInvalidPlatformFileValue == file_handle) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_EQ(length * 2, GetSize(data_path)); 319 EXPECT_EQ(length * 2, GetSize(data_path));
320 320
321 context.reset(NewContext(NULL)); 321 context.reset(NewContext(NULL));
322 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 322 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
323 context.get(), url, 0)); 323 context.get(), url, 0));
324 EXPECT_EQ(0, GetSize(data_path)); 324 EXPECT_EQ(0, GetSize(data_path));
325 } 325 }
326 326
327 void ValidateTestDirectory( 327 void ValidateTestDirectory(
328 const FileSystemURL& root_url, 328 const FileSystemURL& root_url,
329 const std::set<FilePath::StringType>& files, 329 const std::set<base::FilePath::StringType>& files,
330 const std::set<FilePath::StringType>& directories) { 330 const std::set<base::FilePath::StringType>& directories) {
331 scoped_ptr<FileSystemOperationContext> context; 331 scoped_ptr<FileSystemOperationContext> context;
332 std::set<FilePath::StringType>::const_iterator iter; 332 std::set<base::FilePath::StringType>::const_iterator iter;
333 for (iter = files.begin(); iter != files.end(); ++iter) { 333 for (iter = files.begin(); iter != files.end(); ++iter) {
334 bool created = true; 334 bool created = true;
335 context.reset(NewContext(NULL)); 335 context.reset(NewContext(NULL));
336 ASSERT_EQ(base::PLATFORM_FILE_OK, 336 ASSERT_EQ(base::PLATFORM_FILE_OK,
337 ofu()->EnsureFileExists( 337 ofu()->EnsureFileExists(
338 context.get(), root_url.WithPath(root_url.path().Append(*iter)), 338 context.get(), root_url.WithPath(root_url.path().Append(*iter)),
339 &created)); 339 &created));
340 ASSERT_FALSE(created); 340 ASSERT_FALSE(created);
341 } 341 }
342 for (iter = directories.begin(); iter != directories.end(); ++iter) { 342 for (iter = directories.begin(); iter != directories.end(); ++iter) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 383 }
384 384
385 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) { 385 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) {
386 int64 usage = test_helper_.GetCachedOriginUsage(); 386 int64 usage = test_helper_.GetCachedOriginUsage();
387 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 387 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
388 LimitedContext(requested_growth - 1), &test_helper_, usage)); 388 LimitedContext(requested_growth - 1), &test_helper_, usage));
389 } 389 }
390 390
391 void FillTestDirectory( 391 void FillTestDirectory(
392 const FileSystemURL& root_url, 392 const FileSystemURL& root_url,
393 std::set<FilePath::StringType>* files, 393 std::set<base::FilePath::StringType>* files,
394 std::set<FilePath::StringType>* directories) { 394 std::set<base::FilePath::StringType>* directories) {
395 scoped_ptr<FileSystemOperationContext> context; 395 scoped_ptr<FileSystemOperationContext> context;
396 context.reset(NewContext(NULL)); 396 context.reset(NewContext(NULL));
397 std::vector<base::FileUtilProxy::Entry> entries; 397 std::vector<base::FileUtilProxy::Entry> entries;
398 EXPECT_EQ(base::PLATFORM_FILE_OK, 398 EXPECT_EQ(base::PLATFORM_FILE_OK,
399 FileUtilHelper::ReadDirectory( 399 FileUtilHelper::ReadDirectory(
400 context.get(), ofu(), root_url, &entries)); 400 context.get(), ofu(), root_url, &entries));
401 EXPECT_EQ(0UL, entries.size()); 401 EXPECT_EQ(0UL, entries.size());
402 402
403 files->clear(); 403 files->clear();
404 files->insert(FILE_PATH_LITERAL("first")); 404 files->insert(FILE_PATH_LITERAL("first"));
405 files->insert(FILE_PATH_LITERAL("second")); 405 files->insert(FILE_PATH_LITERAL("second"));
406 files->insert(FILE_PATH_LITERAL("third")); 406 files->insert(FILE_PATH_LITERAL("third"));
407 directories->clear(); 407 directories->clear();
408 directories->insert(FILE_PATH_LITERAL("fourth")); 408 directories->insert(FILE_PATH_LITERAL("fourth"));
409 directories->insert(FILE_PATH_LITERAL("fifth")); 409 directories->insert(FILE_PATH_LITERAL("fifth"));
410 directories->insert(FILE_PATH_LITERAL("sixth")); 410 directories->insert(FILE_PATH_LITERAL("sixth"));
411 std::set<FilePath::StringType>::iterator iter; 411 std::set<base::FilePath::StringType>::iterator iter;
412 for (iter = files->begin(); iter != files->end(); ++iter) { 412 for (iter = files->begin(); iter != files->end(); ++iter) {
413 bool created = false; 413 bool created = false;
414 context.reset(NewContext(NULL)); 414 context.reset(NewContext(NULL));
415 ASSERT_EQ(base::PLATFORM_FILE_OK, 415 ASSERT_EQ(base::PLATFORM_FILE_OK,
416 ofu()->EnsureFileExists( 416 ofu()->EnsureFileExists(
417 context.get(), 417 context.get(),
418 root_url.WithPath(root_url.path().Append(*iter)), 418 root_url.WithPath(root_url.path().Append(*iter)),
419 &created)); 419 &created));
420 ASSERT_TRUE(created); 420 ASSERT_TRUE(created);
421 } 421 }
422 for (iter = directories->begin(); iter != directories->end(); ++iter) { 422 for (iter = directories->begin(); iter != directories->end(); ++iter) {
423 bool exclusive = true; 423 bool exclusive = true;
424 bool recursive = false; 424 bool recursive = false;
425 context.reset(NewContext(NULL)); 425 context.reset(NewContext(NULL));
426 EXPECT_EQ(base::PLATFORM_FILE_OK, 426 EXPECT_EQ(base::PLATFORM_FILE_OK,
427 ofu()->CreateDirectory( 427 ofu()->CreateDirectory(
428 context.get(), root_url.WithPath(root_url.path().Append(*iter)), 428 context.get(), root_url.WithPath(root_url.path().Append(*iter)),
429 exclusive, recursive)); 429 exclusive, recursive));
430 } 430 }
431 ValidateTestDirectory(root_url, *files, *directories); 431 ValidateTestDirectory(root_url, *files, *directories);
432 } 432 }
433 433
434 void TestReadDirectoryHelper(const FileSystemURL& root_url) { 434 void TestReadDirectoryHelper(const FileSystemURL& root_url) {
435 std::set<FilePath::StringType> files; 435 std::set<base::FilePath::StringType> files;
436 std::set<FilePath::StringType> directories; 436 std::set<base::FilePath::StringType> directories;
437 FillTestDirectory(root_url, &files, &directories); 437 FillTestDirectory(root_url, &files, &directories);
438 438
439 scoped_ptr<FileSystemOperationContext> context; 439 scoped_ptr<FileSystemOperationContext> context;
440 std::vector<base::FileUtilProxy::Entry> entries; 440 std::vector<base::FileUtilProxy::Entry> entries;
441 context.reset(NewContext(NULL)); 441 context.reset(NewContext(NULL));
442 EXPECT_EQ(base::PLATFORM_FILE_OK, 442 EXPECT_EQ(base::PLATFORM_FILE_OK,
443 FileUtilHelper::ReadDirectory( 443 FileUtilHelper::ReadDirectory(
444 context.get(), ofu(), root_url, &entries)); 444 context.get(), ofu(), root_url, &entries));
445 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; 445 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter;
446 EXPECT_EQ(files.size() + directories.size(), entries.size()); 446 EXPECT_EQ(files.size() + directories.size(), entries.size());
447 EXPECT_TRUE(change_observer()->HasNoChange()); 447 EXPECT_TRUE(change_observer()->HasNoChange());
448 for (entry_iter = entries.begin(); entry_iter != entries.end(); 448 for (entry_iter = entries.begin(); entry_iter != entries.end();
449 ++entry_iter) { 449 ++entry_iter) {
450 const base::FileUtilProxy::Entry& entry = *entry_iter; 450 const base::FileUtilProxy::Entry& entry = *entry_iter;
451 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); 451 std::set<base::FilePath::StringType>::iterator iter = files.find(entry.nam e);
452 if (iter != files.end()) { 452 if (iter != files.end()) {
453 EXPECT_FALSE(entry.is_directory); 453 EXPECT_FALSE(entry.is_directory);
454 files.erase(iter); 454 files.erase(iter);
455 continue; 455 continue;
456 } 456 }
457 iter = directories.find(entry.name); 457 iter = directories.find(entry.name);
458 EXPECT_FALSE(directories.end() == iter); 458 EXPECT_FALSE(directories.end() == iter);
459 EXPECT_TRUE(entry.is_directory); 459 EXPECT_TRUE(entry.is_directory);
460 directories.erase(iter); 460 directories.erase(iter);
461 } 461 }
462 } 462 }
463 463
464 void TestTouchHelper(const FileSystemURL& url, bool is_file) { 464 void TestTouchHelper(const FileSystemURL& url, bool is_file) {
465 base::Time last_access_time = base::Time::Now(); 465 base::Time last_access_time = base::Time::Now();
466 base::Time last_modified_time = base::Time::Now(); 466 base::Time last_modified_time = base::Time::Now();
467 467
468 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 468 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
469 EXPECT_EQ(base::PLATFORM_FILE_OK, 469 EXPECT_EQ(base::PLATFORM_FILE_OK,
470 ofu()->Touch( 470 ofu()->Touch(
471 context.get(), url, last_access_time, last_modified_time)); 471 context.get(), url, last_access_time, last_modified_time));
472 // Currently we fire no change notifications for Touch. 472 // Currently we fire no change notifications for Touch.
473 EXPECT_TRUE(change_observer()->HasNoChange()); 473 EXPECT_TRUE(change_observer()->HasNoChange());
474 FilePath local_path; 474 base::FilePath local_path;
475 base::PlatformFileInfo file_info; 475 base::PlatformFileInfo file_info;
476 context.reset(NewContext(NULL)); 476 context.reset(NewContext(NULL));
477 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 477 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
478 context.get(), url, &file_info, &local_path)); 478 context.get(), url, &file_info, &local_path));
479 // We compare as time_t here to lower our resolution, to avoid false 479 // We compare as time_t here to lower our resolution, to avoid false
480 // negatives caused by conversion to the local filesystem's native 480 // negatives caused by conversion to the local filesystem's native
481 // representation and back. 481 // representation and back.
482 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 482 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
483 483
484 context.reset(NewContext(NULL)); 484 context.reset(NewContext(NULL));
485 last_modified_time += base::TimeDelta::FromHours(1); 485 last_modified_time += base::TimeDelta::FromHours(1);
486 last_access_time += base::TimeDelta::FromHours(14); 486 last_access_time += base::TimeDelta::FromHours(14);
487 EXPECT_EQ(base::PLATFORM_FILE_OK, 487 EXPECT_EQ(base::PLATFORM_FILE_OK,
488 ofu()->Touch( 488 ofu()->Touch(
489 context.get(), url, last_access_time, last_modified_time)); 489 context.get(), url, last_access_time, last_modified_time));
490 EXPECT_TRUE(change_observer()->HasNoChange()); 490 EXPECT_TRUE(change_observer()->HasNoChange());
491 context.reset(NewContext(NULL)); 491 context.reset(NewContext(NULL));
492 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 492 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
493 context.get(), url, &file_info, &local_path)); 493 context.get(), url, &file_info, &local_path));
494 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 494 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
495 if (is_file) // Directories in OFU don't support atime. 495 if (is_file) // Directories in OFU don't support atime.
496 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); 496 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT());
497 } 497 }
498 498
499 void TestCopyInForeignFileHelper(bool overwrite) { 499 void TestCopyInForeignFileHelper(bool overwrite) {
500 base::ScopedTempDir source_dir; 500 base::ScopedTempDir source_dir;
501 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); 501 ASSERT_TRUE(source_dir.CreateUniqueTempDir());
502 FilePath root_file_path = source_dir.path(); 502 base::FilePath root_file_path = source_dir.path();
503 FilePath src_file_path = root_file_path.AppendASCII("file_name"); 503 base::FilePath src_file_path = root_file_path.AppendASCII("file_name");
504 FileSystemURL dest_url = CreateURLFromUTF8("new file"); 504 FileSystemURL dest_url = CreateURLFromUTF8("new file");
505 int64 src_file_length = 87; 505 int64 src_file_length = 87;
506 506
507 base::PlatformFileError error_code; 507 base::PlatformFileError error_code;
508 bool created = false; 508 bool created = false;
509 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 509 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
510 base::PlatformFile file_handle = 510 base::PlatformFile file_handle =
511 base::CreatePlatformFile( 511 base::CreatePlatformFile(
512 src_file_path, file_flags, &created, &error_code); 512 src_file_path, file_flags, &created, &error_code);
513 EXPECT_TRUE(created); 513 EXPECT_TRUE(created);
(...skipping 30 matching lines...) Expand all
544 context->set_allowed_bytes_growth(path_cost + src_file_length); 544 context->set_allowed_bytes_growth(path_cost + src_file_length);
545 EXPECT_EQ(base::PLATFORM_FILE_OK, 545 EXPECT_EQ(base::PLATFORM_FILE_OK,
546 ofu()->CopyInForeignFile(context.get(), 546 ofu()->CopyInForeignFile(context.get(),
547 src_file_path, dest_url)); 547 src_file_path, dest_url));
548 548
549 EXPECT_TRUE(PathExists(dest_url)); 549 EXPECT_TRUE(PathExists(dest_url));
550 EXPECT_FALSE(DirectoryExists(dest_url)); 550 EXPECT_FALSE(DirectoryExists(dest_url));
551 551
552 context.reset(NewContext(NULL)); 552 context.reset(NewContext(NULL));
553 base::PlatformFileInfo file_info; 553 base::PlatformFileInfo file_info;
554 FilePath data_path; 554 base::FilePath data_path;
555 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 555 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
556 context.get(), dest_url, &file_info, &data_path)); 556 context.get(), dest_url, &file_info, &data_path));
557 EXPECT_NE(data_path, src_file_path); 557 EXPECT_NE(data_path, src_file_path);
558 EXPECT_TRUE(FileExists(data_path)); 558 EXPECT_TRUE(FileExists(data_path));
559 EXPECT_EQ(src_file_length, GetSize(data_path)); 559 EXPECT_EQ(src_file_length, GetSize(data_path));
560 560
561 EXPECT_EQ(base::PLATFORM_FILE_OK, 561 EXPECT_EQ(base::PLATFORM_FILE_OK,
562 ofu()->DeleteFile(context.get(), dest_url)); 562 ofu()->DeleteFile(context.get(), dest_url));
563 } 563 }
564 564
565 void ClearTimestamp(const FileSystemURL& url) { 565 void ClearTimestamp(const FileSystemURL& url) {
566 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 566 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
567 EXPECT_EQ(base::PLATFORM_FILE_OK, 567 EXPECT_EQ(base::PLATFORM_FILE_OK,
568 ofu()->Touch(context.get(), url, base::Time(), base::Time())); 568 ofu()->Touch(context.get(), url, base::Time(), base::Time()));
569 EXPECT_EQ(base::Time(), GetModifiedTime(url)); 569 EXPECT_EQ(base::Time(), GetModifiedTime(url));
570 } 570 }
571 571
572 base::Time GetModifiedTime(const FileSystemURL& url) { 572 base::Time GetModifiedTime(const FileSystemURL& url) {
573 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 573 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
574 FilePath data_path; 574 base::FilePath data_path;
575 base::PlatformFileInfo file_info; 575 base::PlatformFileInfo file_info;
576 context.reset(NewContext(NULL)); 576 context.reset(NewContext(NULL));
577 EXPECT_EQ(base::PLATFORM_FILE_OK, 577 EXPECT_EQ(base::PLATFORM_FILE_OK,
578 ofu()->GetFileInfo(context.get(), url, &file_info, &data_path)); 578 ofu()->GetFileInfo(context.get(), url, &file_info, &data_path));
579 EXPECT_TRUE(change_observer()->HasNoChange()); 579 EXPECT_TRUE(change_observer()->HasNoChange());
580 return file_info.last_modified; 580 return file_info.last_modified;
581 } 581 }
582 582
583 void TestDirectoryTimestampHelper(const FileSystemURL& base_dir, 583 void TestDirectoryTimestampHelper(const FileSystemURL& base_dir,
584 bool copy, 584 bool copy,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 ASSERT_EQ(base::PLATFORM_FILE_OK, 686 ASSERT_EQ(base::PLATFORM_FILE_OK,
687 ofu()->CreateOrOpen( 687 ofu()->CreateOrOpen(
688 context.get(), url, file_flags, &file_handle, &created)); 688 context.get(), url, file_flags, &file_handle, &created));
689 ASSERT_TRUE(created); 689 ASSERT_TRUE(created);
690 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 690 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
691 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 691 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
692 692
693 CheckFileAndCloseHandle(url, file_handle); 693 CheckFileAndCloseHandle(url, file_handle);
694 694
695 context.reset(NewContext(NULL)); 695 context.reset(NewContext(NULL));
696 FilePath local_path; 696 base::FilePath local_path;
697 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 697 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
698 context.get(), url, &local_path)); 698 context.get(), url, &local_path));
699 EXPECT_TRUE(file_util::PathExists(local_path)); 699 EXPECT_TRUE(file_util::PathExists(local_path));
700 700
701 // Verify that deleting a file isn't stopped by zero quota, and that it frees 701 // Verify that deleting a file isn't stopped by zero quota, and that it frees
702 // up quote from its path. 702 // up quote from its path.
703 context.reset(NewContext(NULL)); 703 context.reset(NewContext(NULL));
704 context->set_allowed_bytes_growth(0); 704 context->set_allowed_bytes_growth(0);
705 EXPECT_EQ(base::PLATFORM_FILE_OK, 705 EXPECT_EQ(base::PLATFORM_FILE_OK,
706 ofu()->DeleteFile(context.get(), url)); 706 ofu()->DeleteFile(context.get(), url));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 754 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
755 ofu()->Truncate(context.get(), url, 4)); 755 ofu()->Truncate(context.get(), url, 4));
756 756
757 context.reset(NewContext(NULL)); 757 context.reset(NewContext(NULL));
758 ASSERT_EQ(base::PLATFORM_FILE_OK, 758 ASSERT_EQ(base::PLATFORM_FILE_OK,
759 ofu()->EnsureFileExists(context.get(), url, &created)); 759 ofu()->EnsureFileExists(context.get(), url, &created));
760 ASSERT_TRUE(created); 760 ASSERT_TRUE(created);
761 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 761 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
762 762
763 context.reset(NewContext(NULL)); 763 context.reset(NewContext(NULL));
764 FilePath local_path; 764 base::FilePath local_path;
765 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 765 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
766 context.get(), url, &local_path)); 766 context.get(), url, &local_path));
767 EXPECT_EQ(0, GetSize(local_path)); 767 EXPECT_EQ(0, GetSize(local_path));
768 768
769 context.reset(NewContext(NULL)); 769 context.reset(NewContext(NULL));
770 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( 770 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
771 context.get(), url, 10)); 771 context.get(), url, 10));
772 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 772 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
773 EXPECT_EQ(10, GetSize(local_path)); 773 EXPECT_EQ(10, GetSize(local_path));
774 774
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 { 830 {
831 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(-1); 831 scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(-1);
832 helper->context()->set_allowed_bytes_growth( 832 helper->context()->set_allowed_bytes_growth(
833 helper->context()->allowed_bytes_growth() - 1); 833 helper->context()->allowed_bytes_growth() - 1);
834 EXPECT_EQ(base::PLATFORM_FILE_OK, 834 EXPECT_EQ(base::PLATFORM_FILE_OK,
835 ofu()->Truncate(helper->context(), url, 1019)); 835 ofu()->Truncate(helper->context(), url, 1019));
836 ASSERT_EQ(1019, ComputeTotalFileSize()); 836 ASSERT_EQ(1019, ComputeTotalFileSize());
837 } 837 }
838 838
839 // Delete backing file to make following truncation fail. 839 // Delete backing file to make following truncation fail.
840 FilePath local_path; 840 base::FilePath local_path;
841 ASSERT_EQ(base::PLATFORM_FILE_OK, 841 ASSERT_EQ(base::PLATFORM_FILE_OK,
842 ofu()->GetLocalFilePath( 842 ofu()->GetLocalFilePath(
843 UnlimitedContext().get(), 843 UnlimitedContext().get(),
844 url, &local_path)); 844 url, &local_path));
845 ASSERT_FALSE(local_path.empty()); 845 ASSERT_FALSE(local_path.empty());
846 ASSERT_TRUE(file_util::Delete(local_path, false)); 846 ASSERT_TRUE(file_util::Delete(local_path, false));
847 847
848 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 848 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
849 ofu()->Truncate( 849 ofu()->Truncate(
850 LimitedContext(1234).get(), 850 LimitedContext(1234).get(),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 url.WithPath(url.path().DirName()))); 947 url.WithPath(url.path().DirName())));
948 948
949 // Can't remove a non-empty directory. 949 // Can't remove a non-empty directory.
950 context.reset(NewContext(NULL)); 950 context.reset(NewContext(NULL));
951 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 951 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
952 ofu()->DeleteDirectory(context.get(), 952 ofu()->DeleteDirectory(context.get(),
953 url.WithPath(url.path().DirName()))); 953 url.WithPath(url.path().DirName())));
954 EXPECT_TRUE(change_observer()->HasNoChange()); 954 EXPECT_TRUE(change_observer()->HasNoChange());
955 955
956 base::PlatformFileInfo file_info; 956 base::PlatformFileInfo file_info;
957 FilePath local_path; 957 base::FilePath local_path;
958 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 958 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
959 context.get(), url, &file_info, &local_path)); 959 context.get(), url, &file_info, &local_path));
960 EXPECT_TRUE(local_path.empty()); 960 EXPECT_TRUE(local_path.empty());
961 EXPECT_TRUE(file_info.is_directory); 961 EXPECT_TRUE(file_info.is_directory);
962 EXPECT_FALSE(file_info.is_symbolic_link); 962 EXPECT_FALSE(file_info.is_symbolic_link);
963 963
964 // Same create again should succeed, since exclusive is false. 964 // Same create again should succeed, since exclusive is false.
965 context.reset(NewContext(NULL)); 965 context.reset(NewContext(NULL));
966 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 966 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
967 context.get(), url, exclusive, recursive)); 967 context.get(), url, exclusive, recursive));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 EXPECT_EQ(base::PLATFORM_FILE_OK, 1131 EXPECT_EQ(base::PLATFORM_FILE_OK,
1132 ofu()->EnsureFileExists(context.get(), url, &created)); 1132 ofu()->EnsureFileExists(context.get(), url, &created));
1133 EXPECT_TRUE(created); 1133 EXPECT_TRUE(created);
1134 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 1134 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(url.path());
1135 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); 1135 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
1136 1136
1137 context->set_allowed_bytes_growth(1024); 1137 context->set_allowed_bytes_growth(1024);
1138 bool exclusive = true; 1138 bool exclusive = true;
1139 bool recursive = true; 1139 bool recursive = true;
1140 url = CreateURLFromUTF8("directory/to/use"); 1140 url = CreateURLFromUTF8("directory/to/use");
1141 std::vector<FilePath::StringType> components; 1141 std::vector<base::FilePath::StringType> components;
1142 url.path().GetComponents(&components); 1142 url.path().GetComponents(&components);
1143 path_cost = 0; 1143 path_cost = 0;
1144 for (std::vector<FilePath::StringType>::iterator iter = components.begin(); 1144 for (std::vector<base::FilePath::StringType>::iterator iter = components.begin ();
1145 iter != components.end(); ++iter) { 1145 iter != components.end(); ++iter) {
1146 path_cost += ObfuscatedFileUtil::ComputeFilePathCost( 1146 path_cost += ObfuscatedFileUtil::ComputeFilePathCost(
1147 FilePath(*iter)); 1147 base::FilePath(*iter));
1148 } 1148 }
1149 context.reset(NewContext(NULL)); 1149 context.reset(NewContext(NULL));
1150 context->set_allowed_bytes_growth(1024); 1150 context->set_allowed_bytes_growth(1024);
1151 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1151 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
1152 context.get(), url, exclusive, recursive)); 1152 context.get(), url, exclusive, recursive));
1153 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); 1153 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
1154 } 1154 }
1155 1155
1156 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { 1156 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) {
1157 FileSystemURL source_url = CreateURLFromUTF8("path0.txt"); 1157 FileSystemURL source_url = CreateURLFromUTF8("path0.txt");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 ASSERT_EQ(base::PLATFORM_FILE_OK, 1243 ASSERT_EQ(base::PLATFORM_FILE_OK,
1244 ofu()->Truncate(context.get(), dest_url, kDestLength)); 1244 ofu()->Truncate(context.get(), dest_url, kDestLength));
1245 } 1245 }
1246 1246
1247 context.reset(NewContext(NULL)); 1247 context.reset(NewContext(NULL));
1248 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile(context.get(), 1248 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile(context.get(),
1249 source_url, dest_url, test_case.is_copy_not_move)); 1249 source_url, dest_url, test_case.is_copy_not_move));
1250 1250
1251 if (test_case.is_copy_not_move) { 1251 if (test_case.is_copy_not_move) {
1252 base::PlatformFileInfo file_info; 1252 base::PlatformFileInfo file_info;
1253 FilePath local_path; 1253 base::FilePath local_path;
1254 context.reset(NewContext(NULL)); 1254 context.reset(NewContext(NULL));
1255 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 1255 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
1256 context.get(), source_url, &file_info, &local_path)); 1256 context.get(), source_url, &file_info, &local_path));
1257 EXPECT_EQ(kSourceLength, file_info.size); 1257 EXPECT_EQ(kSourceLength, file_info.size);
1258 EXPECT_EQ(base::PLATFORM_FILE_OK, 1258 EXPECT_EQ(base::PLATFORM_FILE_OK,
1259 ofu()->DeleteFile(context.get(), source_url)); 1259 ofu()->DeleteFile(context.get(), source_url));
1260 } else { 1260 } else {
1261 base::PlatformFileInfo file_info; 1261 base::PlatformFileInfo file_info;
1262 FilePath local_path; 1262 base::FilePath local_path;
1263 context.reset(NewContext(NULL)); 1263 context.reset(NewContext(NULL));
1264 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo( 1264 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo(
1265 context.get(), source_url, &file_info, &local_path)); 1265 context.get(), source_url, &file_info, &local_path));
1266 } 1266 }
1267 base::PlatformFileInfo file_info; 1267 base::PlatformFileInfo file_info;
1268 FilePath local_path; 1268 base::FilePath local_path;
1269 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 1269 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
1270 context.get(), dest_url, &file_info, &local_path)); 1270 context.get(), dest_url, &file_info, &local_path));
1271 EXPECT_EQ(kSourceLength, file_info.size); 1271 EXPECT_EQ(kSourceLength, file_info.size);
1272 1272
1273 EXPECT_EQ(base::PLATFORM_FILE_OK, 1273 EXPECT_EQ(base::PLATFORM_FILE_OK,
1274 ofu()->DeleteFile(context.get(), dest_url)); 1274 ofu()->DeleteFile(context.get(), dest_url));
1275 } 1275 }
1276 } 1276 }
1277 1277
1278 TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) { 1278 TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 } 1382 }
1383 1383
1384 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) { 1384 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) {
1385 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1385 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1386 FileSystemURL src_url = CreateURLFromUTF8("source dir"); 1386 FileSystemURL src_url = CreateURLFromUTF8("source dir");
1387 bool exclusive = true; 1387 bool exclusive = true;
1388 bool recursive = false; 1388 bool recursive = false;
1389 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( 1389 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
1390 context.get(), src_url, exclusive, recursive)); 1390 context.get(), src_url, exclusive, recursive));
1391 1391
1392 std::set<FilePath::StringType> files; 1392 std::set<base::FilePath::StringType> files;
1393 std::set<FilePath::StringType> directories; 1393 std::set<base::FilePath::StringType> directories;
1394 FillTestDirectory(src_url, &files, &directories); 1394 FillTestDirectory(src_url, &files, &directories);
1395 1395
1396 FileSystemURL dest_url = CreateURLFromUTF8("destination dir"); 1396 FileSystemURL dest_url = CreateURLFromUTF8("destination dir");
1397 1397
1398 EXPECT_FALSE(DirectoryExists(dest_url)); 1398 EXPECT_FALSE(DirectoryExists(dest_url));
1399 context.reset(NewContext(NULL)); 1399 context.reset(NewContext(NULL));
1400 ASSERT_EQ(base::PLATFORM_FILE_OK, 1400 ASSERT_EQ(base::PLATFORM_FILE_OK,
1401 test_helper().SameFileUtilCopy(context.get(), src_url, dest_url)); 1401 test_helper().SameFileUtilCopy(context.get(), src_url, dest_url));
1402 1402
1403 ValidateTestDirectory(dest_url, files, directories); 1403 ValidateTestDirectory(dest_url, files, directories);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 } 1498 }
1499 1499
1500 TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) { 1500 TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) {
1501 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 1501 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1502 1502
1503 int64 expected_quota = 0; 1503 int64 expected_quota = 0;
1504 1504
1505 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 1505 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
1506 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i); 1506 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCase " << i);
1507 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 1507 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
1508 FilePath file_path(test_case.path); 1508 base::FilePath file_path(test_case.path);
1509 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path); 1509 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path);
1510 if (test_case.is_directory) { 1510 if (test_case.is_directory) {
1511 bool exclusive = true; 1511 bool exclusive = true;
1512 bool recursive = false; 1512 bool recursive = false;
1513 ASSERT_EQ(base::PLATFORM_FILE_OK, 1513 ASSERT_EQ(base::PLATFORM_FILE_OK,
1514 ofu()->CreateDirectory(context.get(), CreateURL(file_path), 1514 ofu()->CreateDirectory(context.get(), CreateURL(file_path),
1515 exclusive, recursive)); 1515 exclusive, recursive));
1516 } else { 1516 } else {
1517 bool created = false; 1517 bool created = false;
1518 ASSERT_EQ(base::PLATFORM_FILE_OK, 1518 ASSERT_EQ(base::PLATFORM_FILE_OK,
(...skipping 24 matching lines...) Expand all
1543 EXPECT_EQ(expected_quota, usage()); 1543 EXPECT_EQ(expected_quota, usage());
1544 } 1544 }
1545 1545
1546 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) { 1546 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) {
1547 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge"); 1547 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge");
1548 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga"); 1548 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga");
1549 1549
1550 scoped_ptr<FileSystemOperationContext> context; 1550 scoped_ptr<FileSystemOperationContext> context;
1551 base::PlatformFile file; 1551 base::PlatformFile file;
1552 base::PlatformFileInfo file_info; 1552 base::PlatformFileInfo file_info;
1553 FilePath data_path; 1553 base::FilePath data_path;
1554 bool created = false; 1554 bool created = false;
1555 1555
1556 // Create a non-empty file. 1556 // Create a non-empty file.
1557 context.reset(NewContext(NULL)); 1557 context.reset(NewContext(NULL));
1558 EXPECT_EQ(base::PLATFORM_FILE_OK, 1558 EXPECT_EQ(base::PLATFORM_FILE_OK,
1559 ofu()->EnsureFileExists(context.get(), kPath1, &created)); 1559 ofu()->EnsureFileExists(context.get(), kPath1, &created));
1560 EXPECT_TRUE(created); 1560 EXPECT_TRUE(created);
1561 context.reset(NewContext(NULL)); 1561 context.reset(NewContext(NULL));
1562 EXPECT_EQ(base::PLATFORM_FILE_OK, 1562 EXPECT_EQ(base::PLATFORM_FILE_OK,
1563 ofu()->Truncate(context.get(), kPath1, 10)); 1563 ofu()->Truncate(context.get(), kPath1, 10));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 EXPECT_EQ(0, file_info.size); 1618 EXPECT_EQ(0, file_info.size);
1619 EXPECT_TRUE(base::ClosePlatformFile(file)); 1619 EXPECT_TRUE(base::ClosePlatformFile(file));
1620 } 1620 }
1621 1621
1622 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) { 1622 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
1623 const FileSystemURL kPath[] = { 1623 const FileSystemURL kPath[] = {
1624 CreateURLFromUTF8("foo"), 1624 CreateURLFromUTF8("foo"),
1625 CreateURLFromUTF8("bar"), 1625 CreateURLFromUTF8("bar"),
1626 CreateURLFromUTF8("baz") 1626 CreateURLFromUTF8("baz")
1627 }; 1627 };
1628 const FileSystemURL empty_path = CreateURL(FilePath()); 1628 const FileSystemURL empty_path = CreateURL(base::FilePath());
1629 scoped_ptr<FileSystemOperationContext> context; 1629 scoped_ptr<FileSystemOperationContext> context;
1630 1630
1631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { 1631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) {
1632 bool created = false; 1632 bool created = false;
1633 context.reset(NewContext(NULL)); 1633 context.reset(NewContext(NULL));
1634 EXPECT_EQ(base::PLATFORM_FILE_OK, 1634 EXPECT_EQ(base::PLATFORM_FILE_OK,
1635 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); 1635 ofu()->EnsureFileExists(context.get(), kPath[i], &created));
1636 EXPECT_TRUE(created); 1636 EXPECT_TRUE(created);
1637 } 1637 }
1638 1638
1639 context.reset(NewContext(NULL)); 1639 context.reset(NewContext(NULL));
1640 std::vector<base::FileUtilProxy::Entry> entries; 1640 std::vector<base::FileUtilProxy::Entry> entries;
1641 EXPECT_EQ(base::PLATFORM_FILE_OK, 1641 EXPECT_EQ(base::PLATFORM_FILE_OK,
1642 FileUtilHelper::ReadDirectory( 1642 FileUtilHelper::ReadDirectory(
1643 context.get(), ofu(), empty_path, &entries)); 1643 context.get(), ofu(), empty_path, &entries));
1644 EXPECT_EQ(3u, entries.size()); 1644 EXPECT_EQ(3u, entries.size());
1645 1645
1646 context.reset(NewContext(NULL)); 1646 context.reset(NewContext(NULL));
1647 FilePath local_path; 1647 base::FilePath local_path;
1648 EXPECT_EQ(base::PLATFORM_FILE_OK, 1648 EXPECT_EQ(base::PLATFORM_FILE_OK,
1649 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); 1649 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path));
1650 EXPECT_TRUE(file_util::Delete(local_path, false)); 1650 EXPECT_TRUE(file_util::Delete(local_path, false));
1651 1651
1652 context.reset(NewContext(NULL)); 1652 context.reset(NewContext(NULL));
1653 entries.clear(); 1653 entries.clear();
1654 EXPECT_EQ(base::PLATFORM_FILE_OK, 1654 EXPECT_EQ(base::PLATFORM_FILE_OK,
1655 FileUtilHelper::ReadDirectory( 1655 FileUtilHelper::ReadDirectory(
1656 context.get(), ofu(), empty_path, &entries)); 1656 context.get(), ofu(), empty_path, &entries));
1657 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size()); 1657 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); 1773 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
1774 1774
1775 // CopyInForeignFile, create case. 1775 // CopyInForeignFile, create case.
1776 url = dir_url.WithPath(dir_url.path().AppendASCII("CopyInForeignFile_file")); 1776 url = dir_url.WithPath(dir_url.path().AppendASCII("CopyInForeignFile_file"));
1777 FileSystemURL src_path = dir_url.WithPath( 1777 FileSystemURL src_path = dir_url.WithPath(
1778 dir_url.path().AppendASCII("CopyInForeignFile_src_file")); 1778 dir_url.path().AppendASCII("CopyInForeignFile_src_file"));
1779 context.reset(NewContext(NULL)); 1779 context.reset(NewContext(NULL));
1780 EXPECT_EQ(base::PLATFORM_FILE_OK, 1780 EXPECT_EQ(base::PLATFORM_FILE_OK,
1781 ofu()->EnsureFileExists(context.get(), src_path, &created)); 1781 ofu()->EnsureFileExists(context.get(), src_path, &created));
1782 EXPECT_TRUE(created); 1782 EXPECT_TRUE(created);
1783 FilePath src_local_path; 1783 base::FilePath src_local_path;
1784 context.reset(NewContext(NULL)); 1784 context.reset(NewContext(NULL));
1785 EXPECT_EQ(base::PLATFORM_FILE_OK, 1785 EXPECT_EQ(base::PLATFORM_FILE_OK,
1786 ofu()->GetLocalFilePath(context.get(), src_path, &src_local_path)); 1786 ofu()->GetLocalFilePath(context.get(), src_path, &src_local_path));
1787 1787
1788 ClearTimestamp(dir_url); 1788 ClearTimestamp(dir_url);
1789 context.reset(NewContext(NULL)); 1789 context.reset(NewContext(NULL));
1790 EXPECT_EQ(base::PLATFORM_FILE_OK, 1790 EXPECT_EQ(base::PLATFORM_FILE_OK,
1791 ofu()->CopyInForeignFile(context.get(), 1791 ofu()->CopyInForeignFile(context.get(),
1792 src_local_path, 1792 src_local_path,
1793 url)); 1793 url));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 bool created = false; 1876 bool created = false;
1877 context.reset(NewContext(NULL)); 1877 context.reset(NewContext(NULL));
1878 EXPECT_EQ(base::PLATFORM_FILE_OK, 1878 EXPECT_EQ(base::PLATFORM_FILE_OK,
1879 ofu()->EnsureFileExists(context.get(), url1, &created)); 1879 ofu()->EnsureFileExists(context.get(), url1, &created));
1880 EXPECT_TRUE(created); 1880 EXPECT_TRUE(created);
1881 1881
1882 context.reset(NewContext(NULL)); 1882 context.reset(NewContext(NULL));
1883 EXPECT_EQ(base::PLATFORM_FILE_OK, 1883 EXPECT_EQ(base::PLATFORM_FILE_OK,
1884 ofu()->CreateDirectory(context.get(), url2, false, false)); 1884 ofu()->CreateDirectory(context.get(), url2, false, false));
1885 1885
1886 FilePath file_path; 1886 base::FilePath file_path;
1887 context.reset(NewContext(NULL)); 1887 context.reset(NewContext(NULL));
1888 EXPECT_EQ(base::PLATFORM_FILE_OK, 1888 EXPECT_EQ(base::PLATFORM_FILE_OK,
1889 ofu()->GetLocalFilePath(context.get(), url1, &file_path)); 1889 ofu()->GetLocalFilePath(context.get(), url1, &file_path));
1890 EXPECT_FALSE(file_path.empty()); 1890 EXPECT_FALSE(file_path.empty());
1891 1891
1892 context.reset(NewContext(NULL)); 1892 context.reset(NewContext(NULL));
1893 EXPECT_EQ(base::PLATFORM_FILE_OK, 1893 EXPECT_EQ(base::PLATFORM_FILE_OK,
1894 ofu()->Touch(context.get(), url1, 1894 ofu()->Touch(context.get(), url1,
1895 base::Time::Now() + base::TimeDelta::FromHours(1), 1895 base::Time::Now() + base::TimeDelta::FromHours(1),
1896 base::Time())); 1896 base::Time()));
1897 1897
1898 context.reset(NewContext(NULL)); 1898 context.reset(NewContext(NULL));
1899 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 1899 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
1900 ofu()->CreateFileEnumerator(context.get(), dir, false)); 1900 ofu()->CreateFileEnumerator(context.get(), dir, false));
1901 1901
1902 int count = 0; 1902 int count = 0;
1903 FilePath file_path_each; 1903 base::FilePath file_path_each;
1904 while (!(file_path_each = file_enum->Next()).empty()) { 1904 while (!(file_path_each = file_enum->Next()).empty()) {
1905 context.reset(NewContext(NULL)); 1905 context.reset(NewContext(NULL));
1906 base::PlatformFileInfo file_info; 1906 base::PlatformFileInfo file_info;
1907 FilePath file_path; 1907 base::FilePath file_path;
1908 EXPECT_EQ(base::PLATFORM_FILE_OK, 1908 EXPECT_EQ(base::PLATFORM_FILE_OK,
1909 ofu()->GetFileInfo(context.get(), 1909 ofu()->GetFileInfo(context.get(),
1910 dir.WithPath(file_path_each), 1910 dir.WithPath(file_path_each),
1911 &file_info, &file_path)); 1911 &file_info, &file_path));
1912 EXPECT_EQ(file_info.is_directory, file_enum->IsDirectory()); 1912 EXPECT_EQ(file_info.is_directory, file_enum->IsDirectory());
1913 EXPECT_EQ(file_info.last_modified, file_enum->LastModifiedTime()); 1913 EXPECT_EQ(file_info.last_modified, file_enum->LastModifiedTime());
1914 EXPECT_EQ(file_info.size, file_enum->Size()); 1914 EXPECT_EQ(file_info.size, file_enum->Size());
1915 ++count; 1915 ++count;
1916 } 1916 }
1917 EXPECT_EQ(2, count); 1917 EXPECT_EQ(2, count);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 ASSERT_EQ(base::PLATFORM_FILE_OK, 2225 ASSERT_EQ(base::PLATFORM_FILE_OK,
2226 ofu()->CreateOrOpen( 2226 ofu()->CreateOrOpen(
2227 AllowUsageIncrease(-length)->context(), file, 2227 AllowUsageIncrease(-length)->context(), file,
2228 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, 2228 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE,
2229 &file_handle, &created)); 2229 &file_handle, &created));
2230 ASSERT_EQ(0, ComputeTotalFileSize()); 2230 ASSERT_EQ(0, ComputeTotalFileSize());
2231 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 2231 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
2232 } 2232 }
2233 2233
2234 } // namespace fileapi 2234 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/obfuscated_file_util.cc ('k') | webkit/fileapi/remote_file_system_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698