diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-09 17:42:10 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-09 17:42:10 +0000 |
commit | c4e6f9ca783c3959ae4730376723a6f0064ce783 (patch) | |
tree | a23d35c4131d5785fea0627285ce35066005cc2c /webkit/fileapi/obfuscated_file_util_unittest.cc | |
parent | 36e2f42527f6b556045f44a0782dea1a04465763 (diff) | |
download | chromium_src-c4e6f9ca783c3959ae4730376723a6f0064ce783.zip chromium_src-c4e6f9ca783c3959ae4730376723a6f0064ce783.tar.gz chromium_src-c4e6f9ca783c3959ae4730376723a6f0064ce783.tar.bz2 |
Add FileChangeObserver to track changes in local file system
BUG=146290,146317
TEST=LocalFileSystemOperationTest.*, ObfuscatedFileUtilTest.*
Review URL: https://chromiumcodereview.appspot.com/10909060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/obfuscated_file_util_unittest.cc')
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index 76c28ba..a7f9c4b 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -21,6 +21,7 @@ #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/file_util_helper.h" #include "webkit/fileapi/local_file_system_test_helper.h" +#include "webkit/fileapi/mock_file_change_observer.h" #include "webkit/fileapi/mock_file_system_options.h" #include "webkit/fileapi/obfuscated_file_util.h" #include "webkit/fileapi/test_file_set.h" @@ -28,7 +29,7 @@ #include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_types.h" -using namespace fileapi; +namespace fileapi { namespace { @@ -133,6 +134,8 @@ class ObfuscatedFileUtilTest : public testing::Test { test_helper_.SetUp(file_system_context_.get(), obfuscated_file_util_); + + change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); } void TearDown() { @@ -154,15 +157,25 @@ class ObfuscatedFileUtilTest : public testing::Test { FileSystemOperationContext* NewContext( LocalFileSystemTestOriginHelper* helper) { + change_observer()->ResetCount(); FileSystemOperationContext* context; if (helper) context = helper->NewOperationContext(); else context = test_helper_.NewOperationContext(); context->set_allowed_bytes_growth(1024 * 1024); // Big enough for all tests. + context->set_change_observers(change_observers()); return context; } + const ChangeObserverList& change_observers() const { + return change_observers_; + } + + MockFileChangeObserver* change_observer() { + return &change_observer_; + } + // This can only be used after SetUp has run and created file_system_context_ // and obfuscated_file_util_. // Use this for tests which need to run in multiple origins; we need a test @@ -428,6 +441,7 @@ class ObfuscatedFileUtilTest : public testing::Test { context.get(), ofu(), root_url, &entries)); std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; EXPECT_EQ(files.size() + directories.size(), entries.size()); + EXPECT_TRUE(change_observer()->HasNoChange()); for (entry_iter = entries.begin(); entry_iter != entries.end(); ++entry_iter) { const base::FileUtilProxy::Entry& entry = *entry_iter; @@ -452,6 +466,8 @@ class ObfuscatedFileUtilTest : public testing::Test { EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Touch( context.get(), url, last_access_time, last_modified_time)); + // Currently we fire no change notifications for Touch. + EXPECT_TRUE(change_observer()->HasNoChange()); FilePath local_path; base::PlatformFileInfo file_info; context.reset(NewContext(NULL)); @@ -468,6 +484,7 @@ class ObfuscatedFileUtilTest : public testing::Test { EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Touch( context.get(), url, last_access_time, last_modified_time)); + EXPECT_TRUE(change_observer()->HasNoChange()); context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( context.get(), url, &file_info, &local_path)); @@ -503,6 +520,10 @@ class ObfuscatedFileUtilTest : public testing::Test { EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(context.get(), dest_url, &created)); EXPECT_TRUE(created); + + // We must have observed one (and only one) create_file_count. + EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); + EXPECT_TRUE(change_observer()->HasNoChange()); } const int64 path_cost = @@ -552,6 +573,7 @@ class ObfuscatedFileUtilTest : public testing::Test { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(context.get(), url, &file_info, &data_path)); + EXPECT_TRUE(change_observer()->HasNoChange()); return file_info.last_modified; } @@ -594,7 +616,6 @@ class ObfuscatedFileUtilTest : public testing::Test { ofu()->CopyOrMoveFile(context.get(), src_file_url, dest_file_url, copy)); - if (copy) EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url)); else @@ -623,6 +644,8 @@ class ObfuscatedFileUtilTest : public testing::Test { LocalFileSystemTestOriginHelper test_helper_; quota::QuotaStatusCode quota_status_; int64 usage_; + MockFileChangeObserver change_observer_; + ChangeObserverList change_observers_; DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); }; @@ -645,6 +668,8 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { url = CreateURLFromUTF8("test file"); + EXPECT_TRUE(change_observer()->HasNoChange()); + // Verify that file creation requires sufficient quota for the path. context.reset(NewContext(NULL)); context->set_allowed_bytes_growth( @@ -660,6 +685,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { ofu()->CreateOrOpen( context.get(), url, file_flags, &file_handle, &created)); ASSERT_TRUE(created); + EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); CheckFileAndCloseHandle(url, file_handle); @@ -676,6 +702,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { context->set_allowed_bytes_growth(0); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->DeleteFile(context.get(), url)); + EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); EXPECT_FALSE(file_util::PathExists(local_path)); EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()), context->allowed_bytes_growth()); @@ -688,6 +715,8 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { url = directory_url.WithPath(directory_url.path().AppendASCII("file name")); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( context.get(), directory_url, exclusive, recursive)); + // The oepration created 3 directories recursively. + EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); context.reset(NewContext(NULL)); file_handle = base::kInvalidPlatformFileValue; @@ -695,6 +724,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { ofu()->CreateOrOpen( context.get(), url, file_flags, &file_handle, &created)); ASSERT_TRUE(created); + EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); CheckFileAndCloseHandle(url, file_handle); @@ -707,7 +737,11 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->DeleteFile(context.get(), url)); + EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); EXPECT_FALSE(file_util::PathExists(local_path)); + + // Make sure we have no unexpected changes. + EXPECT_TRUE(change_observer()->HasNoChange()); } TEST_F(ObfuscatedFileUtilTest, TestTruncate) { @@ -722,6 +756,7 @@ TEST_F(ObfuscatedFileUtilTest, TestTruncate) { ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(context.get(), url, &created)); ASSERT_TRUE(created); + EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); context.reset(NewContext(NULL)); FilePath local_path; @@ -732,15 +767,20 @@ TEST_F(ObfuscatedFileUtilTest, TestTruncate) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( context.get(), url, 10)); + EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); EXPECT_EQ(10, GetSize(local_path)); context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( context.get(), url, 1)); EXPECT_EQ(1, GetSize(local_path)); + EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); EXPECT_FALSE(DirectoryExists(url)); EXPECT_TRUE(PathExists(url)); + + // Make sure we have no unexpected changes. + EXPECT_TRUE(change_observer()->HasNoChange()); } TEST_F(ObfuscatedFileUtilTest, TestQuotaOnTruncation) { @@ -817,6 +857,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->EnsureFileExists( context.get(), url, &created)); + EXPECT_TRUE(change_observer()->HasNoChange()); // Verify that file creation requires sufficient quota for the path. context.reset(NewContext(NULL)); @@ -827,6 +868,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofu()->EnsureFileExists(context.get(), url, &created)); ASSERT_FALSE(created); + EXPECT_TRUE(change_observer()->HasNoChange()); context.reset(NewContext(NULL)); context->set_allowed_bytes_growth( @@ -834,6 +876,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(context.get(), url, &created)); ASSERT_TRUE(created); + EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); CheckFileAndCloseHandle(url, base::kInvalidPlatformFileValue); @@ -841,6 +884,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(context.get(), url, &created)); ASSERT_FALSE(created); + EXPECT_TRUE(change_observer()->HasNoChange()); // Also test in a subdirectory. url = CreateURLFromUTF8("path/to/file.txt"); @@ -851,6 +895,8 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { context.get(), url.WithPath(url.path().DirName()), exclusive, recursive)); + // 2 directories: path/ and path/to. + EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); context.reset(NewContext(NULL)); ASSERT_EQ(base::PLATFORM_FILE_OK, @@ -858,6 +904,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { ASSERT_TRUE(created); EXPECT_FALSE(DirectoryExists(url)); EXPECT_TRUE(PathExists(url)); + EXPECT_TRUE(change_observer()->HasNoChange()); } TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { @@ -884,6 +931,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { recursive = true; EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); EXPECT_TRUE(DirectoryExists(url)); EXPECT_TRUE(PathExists(url)); @@ -901,6 +949,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, ofu()->DeleteSingleDirectory(context.get(), url.WithPath(url.path().DirName()))); + EXPECT_TRUE(change_observer()->HasNoChange()); base::PlatformFileInfo file_info; FilePath local_path; @@ -914,12 +963,14 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); exclusive = true; recursive = true; context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); // Verify that deleting a directory isn't stopped by zero quota, and that it // frees up quota from its path. @@ -927,6 +978,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context->set_allowed_bytes_growth(0); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->DeleteSingleDirectory(context.get(), url)); + EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(url.path()), context->allowed_bytes_growth()); @@ -948,12 +1000,14 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); context.reset(NewContext(NULL)); context->set_allowed_bytes_growth( ObfuscatedFileUtil::ComputeFilePathCost(url.path())); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); EXPECT_TRUE(DirectoryExists(url)); EXPECT_TRUE(PathExists(url)); @@ -963,6 +1017,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); exclusive = true; recursive = false; @@ -970,6 +1025,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); url = CreateURLFromUTF8("blah"); @@ -981,6 +1037,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); EXPECT_TRUE(DirectoryExists(url)); EXPECT_TRUE(PathExists(url)); @@ -990,6 +1047,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( context.get(), url, exclusive, recursive)); + EXPECT_TRUE(change_observer()->HasNoChange()); } TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) { @@ -1103,11 +1161,13 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, is_copy_not_move)); + EXPECT_TRUE(change_observer()->HasNoChange()); context.reset(NewContext(NULL)); is_copy_not_move = true; EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, is_copy_not_move)); + EXPECT_TRUE(change_observer()->HasNoChange()); source_url = CreateURLFromUTF8("dir/dir/file"); bool exclusive = true; bool recursive = true; @@ -1116,15 +1176,18 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { context.get(), source_url.WithPath(source_url.path().DirName()), exclusive, recursive)); + EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); is_copy_not_move = false; EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, is_copy_not_move)); + EXPECT_TRUE(change_observer()->HasNoChange()); context.reset(NewContext(NULL)); is_copy_not_move = true; EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, is_copy_not_move)); + EXPECT_TRUE(change_observer()->HasNoChange()); } TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { @@ -1183,6 +1246,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { context.reset(NewContext(NULL)); EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, test_case.is_copy_not_move)); + if (test_case.is_copy_not_move) { base::PlatformFileInfo file_info; FilePath local_path; @@ -2210,3 +2274,5 @@ TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { ASSERT_EQ(0, ComputeTotalFileSize()); EXPECT_TRUE(base::ClosePlatformFile(file_handle)); } + +} // namespace fileapi |