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

Unified Diff: components/filesystem/directory_impl_unittest.cc

Issue 1646673002: mojo filesystem: Simplify full file reading/writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Take 2 at trying to fix compile. The release version is complaining about duplicate -1s and this is… Created 4 years, 11 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 | « components/filesystem/directory_impl.cc ('k') | components/filesystem/file_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/filesystem/directory_impl_unittest.cc
diff --git a/components/filesystem/directory_impl_unittest.cc b/components/filesystem/directory_impl_unittest.cc
index 41deec95ec68e580204e6f9e1313c6b6eb0dc785..daac202426c0bf3d6d083ff6740ca5222e4ca006 100644
--- a/components/filesystem/directory_impl_unittest.cc
+++ b/components/filesystem/directory_impl_unittest.cc
@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "components/filesystem/files_test_base.h"
+#include "mojo/common/common_type_converters.h"
#include "mojo/util/capture_util.h"
using mojo::Capture;
@@ -153,6 +154,93 @@ TEST_F(DirectoryImplTest, CantOpenDirectoriesAsFiles) {
}
}
+TEST_F(DirectoryImplTest, WriteFileReadFile) {
+ DirectoryPtr directory;
+ GetTemporaryRoot(&directory);
+ FileError error;
+
+ std::string data("one two three");
+ {
+ directory->WriteFile("data", mojo::Array<uint8_t>::From(data),
+ Capture(&error));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::OK, error);
+ }
+
+ {
+ mojo::Array<uint8_t> file_contents;
+ directory->ReadEntireFile("data", Capture(&error, &file_contents));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::OK, error);
+
+ EXPECT_EQ(data, file_contents.To<std::string>());
+ }
+}
+
+TEST_F(DirectoryImplTest, ReadEmptyFileIsNotFoundError) {
+ DirectoryPtr directory;
+ GetTemporaryRoot(&directory);
+ FileError error;
+
+ {
+ mojo::Array<uint8_t> file_contents;
+ directory->ReadEntireFile("doesnt_exist", Capture(&error, &file_contents));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::NOT_FOUND, error);
+ }
+}
+
+TEST_F(DirectoryImplTest, CantReadEntireFileOnADirectory) {
+ DirectoryPtr directory;
+ GetTemporaryRoot(&directory);
+ FileError error;
+
+ // Create a directory
+ {
+ DirectoryPtr my_file_directory;
+ error = FileError::FAILED;
+ directory->OpenDirectory(
+ "my_dir", GetProxy(&my_file_directory),
+ kFlagRead | kFlagWrite | kFlagCreate,
+ Capture(&error));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::OK, error);
+ }
+
+ // Try to read it as a file
+ {
+ mojo::Array<uint8_t> file_contents;
+ directory->ReadEntireFile("my_dir", Capture(&error, &file_contents));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::NOT_A_FILE, error);
+ }
+}
+
+TEST_F(DirectoryImplTest, CantWriteFileOnADirectory) {
+ DirectoryPtr directory;
+ GetTemporaryRoot(&directory);
+ FileError error;
+
+ // Create a directory
+ {
+ DirectoryPtr my_file_directory;
+ error = FileError::FAILED;
+ directory->OpenDirectory(
+ "my_dir", GetProxy(&my_file_directory),
+ kFlagRead | kFlagWrite | kFlagCreate,
+ Capture(&error));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::OK, error);
+ }
+
+ {
+ std::string data("one two three");
+ directory->WriteFile("my_dir", mojo::Array<uint8_t>::From(data),
+ Capture(&error));
+ ASSERT_TRUE(directory.WaitForIncomingResponse());
+ EXPECT_EQ(FileError::NOT_A_FILE, error);
+ }
+}
// TODO(vtl): Test delete flags.
« no previous file with comments | « components/filesystem/directory_impl.cc ('k') | components/filesystem/file_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698