OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/system/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | |
14 #include "base/files/file_util.h" | |
15 #include "base/files/scoped_temp_dir.h" | |
16 #include "base/location.h" | 13 #include "base/location.h" |
17 #include "base/logging.h" | 14 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
20 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
21 #include "base/threading/simple_thread.h" | 18 #include "base/threading/simple_thread.h" |
22 #include "build/build_config.h" // TODO(vtl): Remove this. | 19 #include "build/build_config.h" // TODO(vtl): Remove this. |
23 #include "mojo/edk/embedder/platform_channel_pair.h" | 20 #include "mojo/edk/embedder/platform_channel_pair.h" |
24 #include "mojo/edk/embedder/platform_handle.h" | 21 #include "mojo/edk/embedder/platform_handle.h" |
25 #include "mojo/edk/embedder/scoped_platform_handle.h" | 22 #include "mojo/edk/embedder/scoped_platform_handle.h" |
26 #include "mojo/edk/system/message_in_transit.h" | 23 #include "mojo/edk/system/message_in_transit.h" |
27 #include "mojo/edk/system/mutex.h" | 24 #include "mojo/edk/system/mutex.h" |
28 #include "mojo/edk/system/test_utils.h" | 25 #include "mojo/edk/system/test_utils.h" |
29 #include "mojo/edk/system/transport_data.h" | 26 #include "mojo/edk/system/transport_data.h" |
| 27 #include "mojo/edk/test/scoped_test_dir.h" |
30 #include "mojo/edk/test/test_io_thread.h" | 28 #include "mojo/edk/test/test_io_thread.h" |
31 #include "mojo/edk/test/test_utils.h" | 29 #include "mojo/edk/test/test_utils.h" |
32 #include "mojo/edk/util/scoped_file.h" | 30 #include "mojo/edk/util/scoped_file.h" |
33 #include "mojo/public/cpp/system/macros.h" | 31 #include "mojo/public/cpp/system/macros.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
35 | 33 |
36 namespace mojo { | 34 namespace mojo { |
37 namespace system { | 35 namespace system { |
38 namespace { | 36 namespace { |
39 | 37 |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); | 792 MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); |
795 }; | 793 }; |
796 | 794 |
797 #if defined(OS_POSIX) | 795 #if defined(OS_POSIX) |
798 #define MAYBE_ReadWritePlatformHandles ReadWritePlatformHandles | 796 #define MAYBE_ReadWritePlatformHandles ReadWritePlatformHandles |
799 #else | 797 #else |
800 // Not yet implemented (on Windows). | 798 // Not yet implemented (on Windows). |
801 #define MAYBE_ReadWritePlatformHandles DISABLED_ReadWritePlatformHandles | 799 #define MAYBE_ReadWritePlatformHandles DISABLED_ReadWritePlatformHandles |
802 #endif | 800 #endif |
803 TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { | 801 TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { |
804 base::ScopedTempDir temp_dir; | 802 mojo::test::ScopedTestDir test_dir; |
805 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
806 | 803 |
807 WriteOnlyRawChannelDelegate write_delegate; | 804 WriteOnlyRawChannelDelegate write_delegate; |
808 scoped_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass())); | 805 scoped_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass())); |
809 io_thread()->PostTaskAndWait(FROM_HERE, | 806 io_thread()->PostTaskAndWait(FROM_HERE, |
810 base::Bind(&InitOnIOThread, rc_write.get(), | 807 base::Bind(&InitOnIOThread, rc_write.get(), |
811 base::Unretained(&write_delegate))); | 808 base::Unretained(&write_delegate))); |
812 | 809 |
813 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; | 810 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; |
814 scoped_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); | 811 scoped_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); |
815 io_thread()->PostTaskAndWait(FROM_HERE, | 812 io_thread()->PostTaskAndWait(FROM_HERE, |
816 base::Bind(&InitOnIOThread, rc_read.get(), | 813 base::Bind(&InitOnIOThread, rc_read.get(), |
817 base::Unretained(&read_delegate))); | 814 base::Unretained(&read_delegate))); |
818 | 815 |
819 base::FilePath unused; | 816 util::ScopedFILE fp1(test_dir.CreateFile()); |
820 util::ScopedFILE fp1( | |
821 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | |
822 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get())); | 817 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get())); |
823 util::ScopedFILE fp2( | 818 util::ScopedFILE fp2(test_dir.CreateFile()); |
824 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | |
825 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get())); | 819 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get())); |
826 | 820 |
827 { | 821 { |
828 const char kHello[] = "hello"; | 822 const char kHello[] = "hello"; |
829 embedder::ScopedPlatformHandleVectorPtr platform_handles( | 823 embedder::ScopedPlatformHandleVectorPtr platform_handles( |
830 new embedder::PlatformHandleVector()); | 824 new embedder::PlatformHandleVector()); |
831 platform_handles->push_back( | 825 platform_handles->push_back( |
832 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); | 826 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); |
833 platform_handles->push_back( | 827 platform_handles->push_back( |
834 mojo::test::PlatformHandleFromFILE(fp2.Pass()).release()); | 828 mojo::test::PlatformHandleFromFILE(fp2.Pass()).release()); |
(...skipping 13 matching lines...) Expand all Loading... |
848 FROM_HERE, | 842 FROM_HERE, |
849 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); | 843 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); |
850 io_thread()->PostTaskAndWait( | 844 io_thread()->PostTaskAndWait( |
851 FROM_HERE, | 845 FROM_HERE, |
852 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); | 846 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); |
853 } | 847 } |
854 | 848 |
855 } // namespace | 849 } // namespace |
856 } // namespace system | 850 } // namespace system |
857 } // namespace mojo | 851 } // namespace mojo |
OLD | NEW |