summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_operation_unittest.cc
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 02:26:47 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 02:26:47 +0000
commit7eb68a27b4edcf33b6f8edeb5a133d7397409cd8 (patch)
tree938b6749fcf8a831b2cd8cd882adb00773c3b034 /webkit/fileapi/file_system_operation_unittest.cc
parentd5cdb124950adf17d37aafe3d5187f94081921cd (diff)
downloadchromium_src-7eb68a27b4edcf33b6f8edeb5a133d7397409cd8.zip
chromium_src-7eb68a27b4edcf33b6f8edeb5a133d7397409cd8.tar.gz
chromium_src-7eb68a27b4edcf33b6f8edeb5a133d7397409cd8.tar.bz2
Second try at submitting 61462.
BUG=none TEST=in file_system_operation_unittest.cc Review URL: http://codereview.chromium.org/3526018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_operation_unittest.cc')
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index 93680a0..60db566 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -52,6 +52,10 @@ class MockDispatcher : public fileapi::FileSystemCallbackDispatcher {
NOTREACHED();
}
+ virtual void DidWrite(int64 bytes, bool complete) {
+ NOTREACHED();
+ }
+
// Helpers for testing.
int status() const { return status_; }
int request_id() const { return request_id_; }
@@ -553,3 +557,60 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path()));
EXPECT_EQ(request_id_, mock_dispatcher_->request_id());
}
+
+TEST_F(FileSystemOperationTest, TestTruncate) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ FilePath file;
+ file_util::CreateTemporaryFileInDir(dir.path(), &file);
+
+ char test_data[] = "test data";
+ int data_size = static_cast<int>(sizeof(test_data));
+ EXPECT_EQ(data_size,
+ file_util::WriteFile(file, test_data, data_size));
+
+ // Check that its length is the size of the data written.
+ operation()->GetMetadata(file);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status());
+ EXPECT_FALSE(mock_dispatcher_->info().is_directory);
+ EXPECT_EQ(data_size, mock_dispatcher_->info().size);
+ EXPECT_EQ(request_id_, mock_dispatcher_->request_id());
+
+ // Extend the file by truncating it.
+ int length = 17;
+ operation()->Truncate(file, length);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status());
+ EXPECT_EQ(request_id_, mock_dispatcher_->request_id());
+
+ // Check that its length is now 17 and that it's all zeroes after the test
+ // data.
+ base::PlatformFileInfo info;
+
+ EXPECT_TRUE(file_util::GetFileInfo(file, &info));
+ EXPECT_EQ(length, info.size);
+ char data[100];
+ EXPECT_EQ(length, file_util::ReadFile(file, data, length));
+ for (int i = 0; i < length; ++i) {
+ if (i < data_size)
+ EXPECT_EQ(test_data[i], data[i]);
+ else
+ EXPECT_EQ(0, data[i]);
+ }
+
+ // Shorten the file by truncating it.
+ length = 3;
+ operation()->Truncate(file, length);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(kFileOperationSucceeded, mock_dispatcher_->status());
+ EXPECT_EQ(request_id_, mock_dispatcher_->request_id());
+
+ // Check that its length is now 3 and that it contains only bits of test data.
+ EXPECT_TRUE(file_util::GetFileInfo(file, &info));
+ EXPECT_EQ(length, info.size);
+ EXPECT_EQ(length, file_util::ReadFile(file, data, length));
+ for (int i = 0; i < length; ++i)
+ EXPECT_EQ(test_data[i], data[i]);
+}
+