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

Unified Diff: webkit/fileapi/file_system_operation_unittest.cc

Issue 3599011: Add truncate and cancel for FileWriter; write and tests will come in later CL... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_system_operation.cc ('k') | webkit/glue/plugins/pepper_file_system.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_operation_unittest.cc
===================================================================
--- webkit/fileapi/file_system_operation_unittest.cc (revision 61078)
+++ webkit/fileapi/file_system_operation_unittest.cc (working copy)
@@ -52,6 +52,10 @@
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,57 @@
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";
+ EXPECT_EQ(sizeof(test_data),
+ file_util::WriteFile(file, test_data, sizeof(test_data)));
+
+ // 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(sizeof(test_data), 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 < sizeof(test_data))
+ 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]);
+}
« no previous file with comments | « webkit/fileapi/file_system_operation.cc ('k') | webkit/glue/plugins/pepper_file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698