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

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

Issue 8728029: Update mtime of directory when containee changed. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: '' Created 9 years 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
OLDNEW
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/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( 469 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
470 context.get(), dest_path, &file_info, &data_path)); 470 context.get(), dest_path, &file_info, &data_path));
471 EXPECT_NE(data_path, src_path); 471 EXPECT_NE(data_path, src_path);
472 EXPECT_TRUE(FileExists(data_path)); 472 EXPECT_TRUE(FileExists(data_path));
473 EXPECT_EQ(src_file_length, GetSize(data_path)); 473 EXPECT_EQ(src_file_length, GetSize(data_path));
474 474
475 EXPECT_EQ(base::PLATFORM_FILE_OK, 475 EXPECT_EQ(base::PLATFORM_FILE_OK,
476 ofu()->DeleteFile(context.get(), dest_path)); 476 ofu()->DeleteFile(context.get(), dest_path));
477 } 477 }
478 478
479 void ClearTimestamp(const FilePath& path) {
480 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
481 EXPECT_EQ(base::PLATFORM_FILE_OK,
482 ofu()->Touch(context.get(), path, base::Time(), base::Time()));
483 base::PlatformFileInfo file_info;
484 FilePath data_path;
ericu 2011/12/05 21:43:50 This could use GetModifiedTime here.
tzik 2011/12/06 05:13:50 Done.
485 context.reset(NewContext(NULL));
486 EXPECT_EQ(base::PLATFORM_FILE_OK,
487 ofu()->GetFileInfo(context.get(), path, &file_info, &data_path));
488 EXPECT_EQ(base::Time(), file_info.last_modified);
489 }
490
491 base::Time GetModifiedTime(const FilePath& path) {
492 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
493 FilePath data_path;
494 base::PlatformFileInfo file_info;
495 context.reset(NewContext(NULL));
496 EXPECT_EQ(base::PLATFORM_FILE_OK,
497 ofu()->GetFileInfo(context.get(), path, &file_info, &data_path));
498 return file_info.last_modified;
499 }
500
501 void TestDirectoryTimestampHelper(const FilePath& base_dir,
502 bool copy,
503 bool overwrite) {
504 scoped_ptr<FileSystemOperationContext> context;
505 const FilePath src_dir_path(base_dir.AppendASCII("foo_dir"));
506 const FilePath dest_dir_path(base_dir.AppendASCII("bar_dir"));
507
508 const FilePath src_file_path(src_dir_path.AppendASCII("hoge"));
509 const FilePath dest_file_path(dest_dir_path.AppendASCII("fuga"));
510
511 context.reset(NewContext(NULL));
512 EXPECT_EQ(base::PLATFORM_FILE_OK,
513 ofu()->CreateDirectory(context.get(), src_dir_path, true, true));
514 context.reset(NewContext(NULL));
515 EXPECT_EQ(base::PLATFORM_FILE_OK,
516 ofu()->CreateDirectory(context.get(), dest_dir_path, true, true));
517
518 bool created = false;
519 context.reset(NewContext(NULL));
520 EXPECT_EQ(base::PLATFORM_FILE_OK,
521 ofu()->EnsureFileExists(context.get(), src_file_path, &created));
522 if (overwrite) {
523 context.reset(NewContext(NULL));
524 EXPECT_EQ(base::PLATFORM_FILE_OK,
525 ofu()->EnsureFileExists(context.get(),
526 dest_file_path, &created));
527 }
528
529 ClearTimestamp(src_dir_path);
530 ClearTimestamp(dest_dir_path);
531 context.reset(NewContext(NULL));
532 EXPECT_EQ(base::PLATFORM_FILE_OK,
533 ofu()->CopyOrMoveFile(context.get(),
534 src_file_path, dest_file_path,
535 copy));
536
537 if (copy)
538 EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_path));
539 else
540 EXPECT_NE(base::Time(), GetModifiedTime(src_dir_path));
541 EXPECT_NE(base::Time(), GetModifiedTime(dest_dir_path));
542 }
543
479 private: 544 private:
480 ScopedTempDir data_dir_; 545 ScopedTempDir data_dir_;
481 scoped_refptr<ObfuscatedFileUtil> obfuscated_file_util_; 546 scoped_refptr<ObfuscatedFileUtil> obfuscated_file_util_;
482 scoped_refptr<quota::QuotaManager> quota_manager_; 547 scoped_refptr<quota::QuotaManager> quota_manager_;
483 scoped_refptr<FileSystemContext> file_system_context_; 548 scoped_refptr<FileSystemContext> file_system_context_;
484 GURL origin_; 549 GURL origin_;
485 fileapi::FileSystemType type_; 550 fileapi::FileSystemType type_;
486 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; 551 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_;
487 FileSystemTestOriginHelper test_helper_; 552 FileSystemTestOriginHelper test_helper_;
488 quota::QuotaStatusCode quota_status_; 553 quota::QuotaStatusCode quota_status_;
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 EXPECT_EQ(base::PLATFORM_FILE_OK, 1498 EXPECT_EQ(base::PLATFORM_FILE_OK,
1434 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); 1499 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path));
1435 EXPECT_TRUE(file_util::Delete(local_path, false)); 1500 EXPECT_TRUE(file_util::Delete(local_path, false));
1436 1501
1437 context.reset(NewContext(NULL)); 1502 context.reset(NewContext(NULL));
1438 entries.clear(); 1503 entries.clear();
1439 EXPECT_EQ(base::PLATFORM_FILE_OK, 1504 EXPECT_EQ(base::PLATFORM_FILE_OK,
1440 ofu()->ReadDirectory(context.get(), FilePath(), &entries)); 1505 ofu()->ReadDirectory(context.get(), FilePath(), &entries));
1441 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size()); 1506 EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size());
1442 } 1507 }
1508
1509 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
1510 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1511 const FilePath dir_path(FILE_PATH_LITERAL("foo_dir"));
1512
1513 // Create working directory.
1514 EXPECT_EQ(base::PLATFORM_FILE_OK,
1515 ofu()->CreateDirectory(context.get(), dir_path, false, false));
1516
1517 // EnsureFileExists, create case.
ericu 2011/12/05 21:43:50 Please add a fail case as well [perhaps trying to
tzik 2011/12/06 05:13:50 Done.
1518 FilePath path(dir_path.AppendASCII("EnsureFileExists_file"));
1519 bool created = false;
1520 ClearTimestamp(dir_path);
1521 context.reset(NewContext(NULL));
1522 EXPECT_EQ(base::PLATFORM_FILE_OK,
1523 ofu()->EnsureFileExists(context.get(), path, &created));
1524 EXPECT_TRUE(created);
1525 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1526
1527 // non create case.
1528 created = true;
1529 ClearTimestamp(dir_path);
1530 context.reset(NewContext(NULL));
1531 EXPECT_EQ(base::PLATFORM_FILE_OK,
1532 ofu()->EnsureFileExists(context.get(), path, &created));
1533 EXPECT_FALSE(created);
1534 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1535
1536 // CreateOrOpen, create case.
1537 path = dir_path.AppendASCII("CreateOrOpen_file");
1538 PlatformFile file_handle = base::kInvalidPlatformFileValue;
1539 created = false;
1540 ClearTimestamp(dir_path);
1541 context.reset(NewContext(NULL));
1542 EXPECT_EQ(base::PLATFORM_FILE_OK,
1543 ofu()->CreateOrOpen(
1544 context.get(), path,
1545 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
1546 &file_handle, &created));
1547 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
1548 EXPECT_TRUE(created);
1549 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
1550 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1551
1552 // open case.
1553 file_handle = base::kInvalidPlatformFileValue;
1554 created = true;
1555 ClearTimestamp(dir_path);
1556 context.reset(NewContext(NULL));
1557 EXPECT_EQ(base::PLATFORM_FILE_OK,
1558 ofu()->CreateOrOpen(
1559 context.get(), path,
1560 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
1561 &file_handle, &created));
1562 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
1563 EXPECT_FALSE(created);
1564 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
1565 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1566
1567 // fail case
1568 file_handle = base::kInvalidPlatformFileValue;
1569 ClearTimestamp(dir_path);
1570 context.reset(NewContext(NULL));
1571 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS,
1572 ofu()->CreateOrOpen(
1573 context.get(), path,
1574 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
1575 &file_handle, &created));
1576 EXPECT_EQ(base::kInvalidPlatformFileValue, file_handle);
1577 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1578
1579 // CreateDirectory, create case.
1580 path = dir_path.AppendASCII("CreateDirectory_dir/1/2/3");
1581 ClearTimestamp(dir_path);
1582 context.reset(NewContext(NULL));
1583 EXPECT_EQ(base::PLATFORM_FILE_OK,
1584 ofu()->CreateDirectory(context.get(), path,
1585 true /* exclusive */, true /* recursive */));
1586 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1587
1588 // create subdir case.
1589 path = dir_path.AppendASCII("CreateDirectory_dir/1/4/5");
1590 ClearTimestamp(dir_path);
1591 context.reset(NewContext(NULL));
1592 EXPECT_EQ(base::PLATFORM_FILE_OK,
1593 ofu()->CreateDirectory(context.get(), path,
1594 true /* exclusive */, true /* recursive */));
1595 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
ericu 2011/12/05 21:43:50 Please also check that the timestamp on CreateDire
tzik 2011/12/06 05:13:50 Done.
1596
1597 // fail case.
1598 path = dir_path.AppendASCII("CreateDirectory_dir");
1599 ClearTimestamp(dir_path);
1600 context.reset(NewContext(NULL));
1601 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS,
1602 ofu()->CreateDirectory(context.get(), path,
1603 true /* exclusive */, true /* recursive */));
1604 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1605
1606 // CopyInForeignFile, create case.
1607 path = dir_path.AppendASCII("CopyInForeignFile_file");
1608 FilePath src_path = dir_path.AppendASCII("CopyInForeignFile_src_file");
1609 context.reset(NewContext(NULL));
1610 EXPECT_EQ(base::PLATFORM_FILE_OK,
1611 ofu()->EnsureFileExists(context.get(), src_path, &created));
1612 EXPECT_TRUE(created);
1613 FilePath src_local_path;
1614 context.reset(NewContext(NULL));
1615 EXPECT_EQ(base::PLATFORM_FILE_OK,
1616 ofu()->GetLocalFilePath(context.get(), src_path, &src_local_path));
1617
1618 ClearTimestamp(dir_path);
1619 context.reset(NewContext(NULL));
1620 EXPECT_EQ(base::PLATFORM_FILE_OK,
1621 ofu()->CopyInForeignFile(context.get(), src_local_path, path));
1622 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1623
1624 }
1625
1626 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) {
1627 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
1628 const FilePath dir_path(FILE_PATH_LITERAL("foo_dir"));
1629
1630 // Create working directory.
1631 EXPECT_EQ(base::PLATFORM_FILE_OK,
1632 ofu()->CreateDirectory(context.get(), dir_path, false, false));
1633
1634 // DeleteFile, delete case.
1635 FilePath path = dir_path.AppendASCII("DeleteFile_file");
1636 bool created = false;
1637 context.reset(NewContext(NULL));
1638 EXPECT_EQ(base::PLATFORM_FILE_OK,
1639 ofu()->EnsureFileExists(context.get(), path, &created));
1640 EXPECT_TRUE(created);
1641
1642 ClearTimestamp(dir_path);
1643 context.reset(NewContext(NULL));
1644 EXPECT_EQ(base::PLATFORM_FILE_OK,
1645 ofu()->DeleteFile(context.get(), path));
1646 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1647
1648 // fail case.
1649 ClearTimestamp(dir_path);
1650 context.reset(NewContext(NULL));
1651 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
1652 ofu()->DeleteFile(context.get(), path));
1653 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1654
1655 // DeleteSingleDirectory, fail case.
1656 path = dir_path.AppendASCII("DeleteSingleDirectory_dir");
1657 FilePath file_path(path.AppendASCII("pakeratta"));
1658 context.reset(NewContext(NULL));
1659 EXPECT_EQ(base::PLATFORM_FILE_OK,
1660 ofu()->CreateDirectory(context.get(), path, true, true));
1661 created = false;
1662 context.reset(NewContext(NULL));
1663 EXPECT_EQ(base::PLATFORM_FILE_OK,
1664 ofu()->EnsureFileExists(context.get(), file_path, &created));
1665 EXPECT_TRUE(created);
1666
1667 ClearTimestamp(dir_path);
1668 context.reset(NewContext(NULL));
1669 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
1670 ofu()->DeleteSingleDirectory(context.get(), path));
1671 EXPECT_EQ(base::Time(), GetModifiedTime(dir_path));
1672
1673 // delete case.
1674 context.reset(NewContext(NULL));
1675 EXPECT_EQ(base::PLATFORM_FILE_OK,
1676 ofu()->DeleteFile(context.get(), file_path));
1677
1678 ClearTimestamp(dir_path);
1679 context.reset(NewContext(NULL));
1680 EXPECT_EQ(base::PLATFORM_FILE_OK,
1681 ofu()->DeleteSingleDirectory(context.get(), path));
1682 EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
1683 }
1684
1685 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCopyAndMove) {
1686 TestDirectoryTimestampHelper(
1687 FilePath(FILE_PATH_LITERAL("copy overwrite")), true, true);
1688 TestDirectoryTimestampHelper(
1689 FilePath(FILE_PATH_LITERAL("copy non-overwrite")), true, false);
1690 TestDirectoryTimestampHelper(
1691 FilePath(FILE_PATH_LITERAL("move overwrite")), false, true);
1692 TestDirectoryTimestampHelper(
1693 FilePath(FILE_PATH_LITERAL("move non-overwrite")),false, false);
1694 }
OLDNEW
« webkit/fileapi/obfuscated_file_util.cc ('K') | « webkit/fileapi/obfuscated_file_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698