| Index: mojo/common/common_custom_types_unittest.cc
|
| diff --git a/mojo/common/common_custom_types_unittest.cc b/mojo/common/common_custom_types_unittest.cc
|
| index 520f82a9a005028c8b79217b80382dd28e9c4d3a..b2886775c61338fe3a017af34857460626d4d296 100644
|
| --- a/mojo/common/common_custom_types_unittest.cc
|
| +++ b/mojo/common/common_custom_types_unittest.cc
|
| @@ -3,7 +3,9 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/files/file_path.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/numerics/safe_math.h"
|
| #include "base/run_loop.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| @@ -164,6 +166,20 @@ class TestString16Impl : public TestString16 {
|
| mojo::Binding<TestString16> binding_;
|
| };
|
|
|
| +class TestFileImpl : public TestFile {
|
| + public:
|
| + explicit TestFileImpl(TestFileRequest request)
|
| + : binding_(this, std::move(request)) {}
|
| +
|
| + // TestFile implementation:
|
| + void BounceFile(base::File in, const BounceFileCallback& callback) override {
|
| + callback.Run(std::move(in));
|
| + }
|
| +
|
| + private:
|
| + mojo::Binding<TestFile> binding_;
|
| +};
|
| +
|
| class CommonCustomTypesTest : public testing::Test {
|
| protected:
|
| CommonCustomTypesTest() {}
|
| @@ -311,6 +327,49 @@ TEST_F(CommonCustomTypesTest, EmptyString16) {
|
| run_loop.Run();
|
| }
|
|
|
| +TEST_F(CommonCustomTypesTest, File) {
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| +
|
| + TestFilePtr ptr;
|
| + TestFileImpl impl(GetProxy(&ptr));
|
| +
|
| + base::File file(
|
| + temp_dir.GetPath().AppendASCII("test_file.txt"),
|
| + base::File::FLAG_CREATE | base::File::FLAG_WRITE | base::File::FLAG_READ);
|
| + const base::StringPiece test_content =
|
| + "A test string to be stored in a test file";
|
| + file.WriteAtCurrentPos(
|
| + test_content.data(),
|
| + base::CheckedNumeric<int>(test_content.size()).ValueOrDie());
|
| +
|
| + base::File file_out;
|
| + ASSERT_TRUE(ptr->BounceFile(std::move(file), &file_out));
|
| + std::vector<char> content(test_content.size());
|
| + ASSERT_TRUE(file_out.IsValid());
|
| + ASSERT_EQ(static_cast<int>(test_content.size()),
|
| + file_out.Read(
|
| + 0, content.data(),
|
| + base::CheckedNumeric<int>(test_content.size()).ValueOrDie()));
|
| + EXPECT_EQ(test_content,
|
| + base::StringPiece(content.data(), test_content.size()));
|
| +}
|
| +
|
| +TEST_F(CommonCustomTypesTest, InvalidFile) {
|
| + TestFilePtr ptr;
|
| + TestFileImpl impl(GetProxy(&ptr));
|
| +
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| + // Test that |file_out| is set to an invalid file.
|
| + base::File file_out(
|
| + temp_dir.GetPath().AppendASCII("test_file.txt"),
|
| + base::File::FLAG_CREATE | base::File::FLAG_WRITE | base::File::FLAG_READ);
|
| +
|
| + ASSERT_TRUE(ptr->BounceFile(base::File(), &file_out));
|
| + EXPECT_FALSE(file_out.IsValid());
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace common
|
| } // namespace mojo
|
|
|