Index: mojo/edk/system/raw_channel_unittest.cc |
diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc b/mojo/edk/system/raw_channel_unittest.cc |
similarity index 60% |
copy from third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc |
copy to mojo/edk/system/raw_channel_unittest.cc |
index 831d3848d919039099f05bb5b5732d83fafdb5ad..af75543bb2f6f1ce5d9c5f741068ae51ad4f7b52 100644 |
--- a/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc |
+++ b/mojo/edk/system/raw_channel_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "third_party/mojo/src/mojo/edk/system/raw_channel.h" |
+#include "mojo/edk/system/raw_channel.h" |
#include <stdint.h> |
#include <stdio.h> |
@@ -19,23 +19,23 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/scoped_vector.h" |
#include "base/rand_util.h" |
+#include "base/synchronization/lock.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/test/test_io_thread.h" |
#include "base/threading/simple_thread.h" |
#include "build/build_config.h" // TODO(vtl): Remove this. |
+#include "mojo/edk/embedder/platform_channel_pair.h" |
+#include "mojo/edk/embedder/platform_handle.h" |
+#include "mojo/edk/embedder/scoped_platform_handle.h" |
+#include "mojo/edk/system/message_in_transit.h" |
+#include "mojo/edk/system/test_utils.h" |
+#include "mojo/edk/system/transport_data.h" |
+#include "mojo/edk/test/test_utils.h" |
#include "mojo/public/cpp/system/macros.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/platform_handle.h" |
-#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" |
-#include "third_party/mojo/src/mojo/edk/system/message_in_transit.h" |
-#include "third_party/mojo/src/mojo/edk/system/mutex.h" |
-#include "third_party/mojo/src/mojo/edk/system/test_utils.h" |
-#include "third_party/mojo/src/mojo/edk/system/transport_data.h" |
-#include "third_party/mojo/src/mojo/edk/test/test_utils.h" |
namespace mojo { |
-namespace system { |
+namespace edk { |
namespace { |
scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { |
@@ -43,8 +43,7 @@ scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { |
for (size_t i = 0; i < num_bytes; i++) |
bytes[i] = static_cast<unsigned char>(i + num_bytes); |
return make_scoped_ptr( |
- new MessageInTransit(MessageInTransit::Type::ENDPOINT_CLIENT, |
- MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, |
+ new MessageInTransit(MessageInTransit::Type::MESSAGE, |
num_bytes, bytes.empty() ? nullptr : &bytes[0])); |
} |
@@ -61,44 +60,38 @@ void InitOnIOThread(RawChannel* raw_channel, RawChannel::Delegate* delegate) { |
raw_channel->Init(delegate); |
} |
-bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, |
+bool WriteTestMessageToHandle(const PlatformHandle& handle, |
uint32_t num_bytes) { |
scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes)); |
size_t write_size = 0; |
- mojo::test::BlockingWrite(handle, message->main_buffer(), |
- message->main_buffer_size(), &write_size); |
+ test::BlockingWrite(handle, message->main_buffer(), |
+ message->main_buffer_size(), &write_size); |
return write_size == message->main_buffer_size(); |
} |
// ----------------------------------------------------------------------------- |
-class RawChannelTest : public testing::Test { |
+class RawChannelTest : public test::MojoSystemTest { |
public: |
- RawChannelTest() : io_thread_(base::TestIOThread::kManualStart) {} |
+ RawChannelTest() {} |
~RawChannelTest() override {} |
void SetUp() override { |
- embedder::PlatformChannelPair channel_pair; |
+ PlatformChannelPair channel_pair; |
handles[0] = channel_pair.PassServerHandle(); |
- handles[1] = channel_pair.PassClientHandle(); |
- io_thread_.Start(); |
+ handles[1] = channel_pair.PassClientHandle();\ |
} |
void TearDown() override { |
- io_thread_.Stop(); |
handles[0].reset(); |
handles[1].reset(); |
} |
protected: |
- base::TestIOThread* io_thread() { return &io_thread_; } |
- |
- embedder::ScopedPlatformHandle handles[2]; |
+ ScopedPlatformHandle handles[2]; |
private: |
- base::TestIOThread io_thread_; |
- |
MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelTest); |
}; |
@@ -112,7 +105,7 @@ class WriteOnlyRawChannelDelegate : public RawChannel::Delegate { |
// |RawChannel::Delegate| implementation: |
void OnReadMessage( |
const MessageInTransit::View& /*message_view*/, |
- embedder::ScopedPlatformHandleVectorPtr /*platform_handles*/) override { |
+ ScopedPlatformHandleVectorPtr /*platform_handles*/) override { |
CHECK(false); // Should not get called. |
} |
void OnError(Error error) override { |
@@ -129,7 +122,7 @@ static const size_t kMessageReaderMaxPollIterations = 3000; |
class TestMessageReaderAndChecker { |
public: |
- explicit TestMessageReaderAndChecker(embedder::PlatformHandle handle) |
+ explicit TestMessageReaderAndChecker(PlatformHandle handle) |
: handle_(handle) {} |
~TestMessageReaderAndChecker() { CHECK(bytes_.empty()); } |
@@ -138,8 +131,7 @@ class TestMessageReaderAndChecker { |
for (size_t i = 0; i < kMessageReaderMaxPollIterations;) { |
size_t read_size = 0; |
- CHECK(mojo::test::NonBlockingRead(handle_, buffer, sizeof(buffer), |
- &read_size)); |
+ CHECK(test::NonBlockingRead(handle_, buffer, sizeof(buffer), &read_size)); |
// Append newly-read data to |bytes_|. |
bytes_.insert(bytes_.end(), buffer, buffer + read_size); |
@@ -183,7 +175,7 @@ class TestMessageReaderAndChecker { |
} |
private: |
- const embedder::PlatformHandle handle_; |
+ const PlatformHandle handle_; |
// The start of the received data should always be on a message boundary. |
std::vector<unsigned char> bytes_; |
@@ -194,11 +186,11 @@ class TestMessageReaderAndChecker { |
// Tests writing (and verifies reading using our own custom reader). |
TEST_F(RawChannelTest, WriteMessage) { |
WriteOnlyRawChannelDelegate delegate; |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
+ RawChannel* rc = RawChannel::Create(handles[0].Pass()); |
TestMessageReaderAndChecker checker(handles[1].get()); |
- io_thread()->PostTaskAndWait( |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
+ base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
// Write and read, for a variety of sizes. |
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { |
@@ -212,8 +204,8 @@ TEST_F(RawChannelTest, WriteMessage) { |
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) |
EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size; |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc))); |
} |
// RawChannelTest.OnReadMessage ------------------------------------------------ |
@@ -226,14 +218,14 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { |
// |RawChannel::Delegate| implementation (called on the I/O thread): |
void OnReadMessage( |
const MessageInTransit::View& message_view, |
- embedder::ScopedPlatformHandleVectorPtr platform_handles) override { |
+ ScopedPlatformHandleVectorPtr platform_handles) override { |
EXPECT_FALSE(platform_handles); |
size_t position; |
size_t expected_size; |
bool should_signal = false; |
{ |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
CHECK_LT(position_, expected_sizes_.size()); |
position = position_; |
expected_size = expected_sizes_[position]; |
@@ -261,7 +253,7 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { |
void Wait() { done_event_.Wait(); } |
void SetExpectedSizes(const std::vector<uint32_t>& expected_sizes) { |
- MutexLocker locker(&mutex_); |
+ base::AutoLock locker(lock_); |
CHECK_EQ(position_, expected_sizes_.size()); |
expected_sizes_ = expected_sizes; |
position_ = 0; |
@@ -270,9 +262,9 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { |
private: |
base::WaitableEvent done_event_; |
- Mutex mutex_; |
- std::vector<uint32_t> expected_sizes_ MOJO_GUARDED_BY(mutex_); |
- size_t position_ MOJO_GUARDED_BY(mutex_); |
+ base::Lock lock_; // Protects the following members. |
+ std::vector<uint32_t> expected_sizes_; |
+ size_t position_; |
MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate); |
}; |
@@ -280,10 +272,10 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { |
// Tests reading (writing using our own custom writer). |
TEST_F(RawChannelTest, OnReadMessage) { |
ReadCheckerRawChannelDelegate delegate; |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait( |
+ RawChannel* rc = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
+ base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
// Write and read, for a variety of sizes. |
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) { |
@@ -304,8 +296,8 @@ TEST_F(RawChannelTest, OnReadMessage) { |
EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); |
delegate.Wait(); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc))); |
} |
// RawChannelTest.WriteMessageAndOnReadMessage --------------------------------- |
@@ -344,7 +336,7 @@ class ReadCountdownRawChannelDelegate : public RawChannel::Delegate { |
// |RawChannel::Delegate| implementation (called on the I/O thread): |
void OnReadMessage( |
const MessageInTransit::View& message_view, |
- embedder::ScopedPlatformHandleVectorPtr platform_handles) override { |
+ ScopedPlatformHandleVectorPtr platform_handles) override { |
EXPECT_FALSE(platform_handles); |
EXPECT_LT(count_, expected_count_); |
@@ -377,23 +369,25 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { |
static const size_t kNumWriteMessagesPerThread = 4000; |
WriteOnlyRawChannelDelegate writer_delegate; |
- scoped_ptr<RawChannel> writer_rc(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait(FROM_HERE, |
- base::Bind(&InitOnIOThread, writer_rc.get(), |
- base::Unretained(&writer_delegate))); |
+ RawChannel* writer_rc = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, |
+ base::Bind(&InitOnIOThread, writer_rc, |
+ base::Unretained(&writer_delegate))); |
ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads * |
kNumWriteMessagesPerThread); |
- scoped_ptr<RawChannel> reader_rc(RawChannel::Create(handles[1].Pass())); |
- io_thread()->PostTaskAndWait(FROM_HERE, |
- base::Bind(&InitOnIOThread, reader_rc.get(), |
- base::Unretained(&reader_delegate))); |
+ RawChannel* reader_rc = RawChannel::Create(handles[1].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, |
+ base::Bind(&InitOnIOThread, reader_rc, |
+ base::Unretained(&reader_delegate))); |
{ |
ScopedVector<RawChannelWriterThread> writer_threads; |
for (size_t i = 0; i < kNumWriterThreads; i++) { |
writer_threads.push_back(new RawChannelWriterThread( |
- writer_rc.get(), kNumWriteMessagesPerThread)); |
+ writer_rc, kNumWriteMessagesPerThread)); |
} |
for (size_t i = 0; i < writer_threads.size(); i++) |
writer_threads[i]->Start(); |
@@ -406,13 +400,13 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { |
// Wait for reading to finish. |
reader_delegate.Wait(); |
- io_thread()->PostTaskAndWait( |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&RawChannel::Shutdown, base::Unretained(reader_rc.get()))); |
+ base::Bind(&RawChannel::Shutdown, base::Unretained(reader_rc))); |
- io_thread()->PostTaskAndWait( |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&RawChannel::Shutdown, base::Unretained(writer_rc.get()))); |
+ base::Bind(&RawChannel::Shutdown, base::Unretained(writer_rc))); |
} |
// RawChannelTest.OnError ------------------------------------------------------ |
@@ -474,10 +468,10 @@ class ErrorRecordingRawChannelDelegate |
// Tests (fatal) errors. |
TEST_F(RawChannelTest, OnError) { |
ErrorRecordingRawChannelDelegate delegate(0, true, true); |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait( |
+ RawChannel* rc = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
+ base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
// Close the handle of the other end, which should make writing fail. |
handles[1].reset(); |
@@ -496,8 +490,8 @@ TEST_F(RawChannelTest, OnError) { |
// notification. (If we actually get another one, |OnError()| crashes.) |
test::Sleep(test::DeadlineFromMilliseconds(20)); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc))); |
} |
// RawChannelTest.ReadUnaffectedByWriteError ----------------------------------- |
@@ -517,10 +511,10 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) { |
// Only start up reading here. The system buffer should still contain the |
// messages that were written. |
ErrorRecordingRawChannelDelegate delegate(kMessageCount, true, true); |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait( |
+ RawChannel* rc = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
+ base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
@@ -533,8 +527,8 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) { |
// And then we should get a read error. |
delegate.WaitForReadError(); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc))); |
} |
// RawChannelTest.WriteMessageAfterShutdown ------------------------------------ |
@@ -543,197 +537,14 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) { |
// correctly. |
TEST_F(RawChannelTest, WriteMessageAfterShutdown) { |
WriteOnlyRawChannelDelegate delegate; |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
- |
- EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
-} |
- |
-// RawChannelTest.{Shutdown, ShutdownAndDestroy}OnReadMessage ------------------ |
- |
-class ShutdownOnReadMessageRawChannelDelegate : public RawChannel::Delegate { |
- public: |
- explicit ShutdownOnReadMessageRawChannelDelegate(RawChannel* raw_channel, |
- bool should_destroy) |
- : raw_channel_(raw_channel), |
- should_destroy_(should_destroy), |
- done_event_(false, false), |
- did_shutdown_(false) {} |
- ~ShutdownOnReadMessageRawChannelDelegate() override {} |
- |
- // |RawChannel::Delegate| implementation (called on the I/O thread): |
- void OnReadMessage( |
- const MessageInTransit::View& message_view, |
- embedder::ScopedPlatformHandleVectorPtr platform_handles) override { |
- EXPECT_FALSE(platform_handles); |
- EXPECT_FALSE(did_shutdown_); |
- EXPECT_TRUE( |
- CheckMessageData(message_view.bytes(), message_view.num_bytes())); |
- raw_channel_->Shutdown(); |
- if (should_destroy_) |
- delete raw_channel_; |
- did_shutdown_ = true; |
- done_event_.Signal(); |
- } |
- void OnError(Error /*error*/) override { |
- CHECK(false); // Should not get called. |
- } |
- |
- // Waits for shutdown. |
- void Wait() { |
- done_event_.Wait(); |
- EXPECT_TRUE(did_shutdown_); |
- } |
- |
- private: |
- RawChannel* const raw_channel_; |
- const bool should_destroy_; |
- base::WaitableEvent done_event_; |
- bool did_shutdown_; |
- |
- MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); |
-}; |
- |
-TEST_F(RawChannelTest, ShutdownOnReadMessage) { |
- // Write a few messages into the other end. |
- for (size_t count = 0; count < 5; count++) |
- EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); |
- |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- ShutdownOnReadMessageRawChannelDelegate delegate(rc.get(), false); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
-} |
- |
-TEST_F(RawChannelTest, ShutdownAndDestroyOnReadMessage) { |
- // Write a message into the other end. |
- EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), 10)); |
- |
- // The delegate will destroy |rc|. |
- RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); |
- ShutdownOnReadMessageRawChannelDelegate delegate(rc, true); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
-} |
- |
-// RawChannelTest.{Shutdown, ShutdownAndDestroy}OnError{Read, Write} ----------- |
- |
-class ShutdownOnErrorRawChannelDelegate : public RawChannel::Delegate { |
- public: |
- ShutdownOnErrorRawChannelDelegate(RawChannel* raw_channel, |
- bool should_destroy, |
- Error shutdown_on_error_type) |
- : raw_channel_(raw_channel), |
- should_destroy_(should_destroy), |
- shutdown_on_error_type_(shutdown_on_error_type), |
- done_event_(false, false), |
- did_shutdown_(false) {} |
- ~ShutdownOnErrorRawChannelDelegate() override {} |
- |
- // |RawChannel::Delegate| implementation (called on the I/O thread): |
- void OnReadMessage( |
- const MessageInTransit::View& /*message_view*/, |
- embedder::ScopedPlatformHandleVectorPtr /*platform_handles*/) override { |
- CHECK(false); // Should not get called. |
- } |
- void OnError(Error error) override { |
- EXPECT_FALSE(did_shutdown_); |
- if (error != shutdown_on_error_type_) |
- return; |
- raw_channel_->Shutdown(); |
- if (should_destroy_) |
- delete raw_channel_; |
- did_shutdown_ = true; |
- done_event_.Signal(); |
- } |
- |
- // Waits for shutdown. |
- void Wait() { |
- done_event_.Wait(); |
- EXPECT_TRUE(did_shutdown_); |
- } |
- |
- private: |
- RawChannel* const raw_channel_; |
- const bool should_destroy_; |
- const Error shutdown_on_error_type_; |
- base::WaitableEvent done_event_; |
- bool did_shutdown_; |
- |
- MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnErrorRawChannelDelegate); |
-}; |
- |
-TEST_F(RawChannelTest, ShutdownOnErrorRead) { |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- ShutdownOnErrorRawChannelDelegate delegate( |
- rc.get(), false, RawChannel::Delegate::ERROR_READ_SHUTDOWN); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
- |
- // Close the handle of the other end, which should stuff fail. |
- handles[1].reset(); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
-} |
- |
-TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorRead) { |
- RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); |
- ShutdownOnErrorRawChannelDelegate delegate( |
- rc, true, RawChannel::Delegate::ERROR_READ_SHUTDOWN); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
- |
- // Close the handle of the other end, which should stuff fail. |
- handles[1].reset(); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
-} |
- |
-TEST_F(RawChannelTest, ShutdownOnErrorWrite) { |
- scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass())); |
- ShutdownOnErrorRawChannelDelegate delegate(rc.get(), false, |
- RawChannel::Delegate::ERROR_WRITE); |
- io_thread()->PostTaskAndWait( |
+ RawChannel* rc = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate))); |
- |
- // Close the handle of the other end, which should stuff fail. |
- handles[1].reset(); |
- |
- EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
-} |
- |
-TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorWrite) { |
- RawChannel* rc = RawChannel::Create(handles[0].Pass()).release(); |
- ShutdownOnErrorRawChannelDelegate delegate(rc, true, |
- RawChannel::Delegate::ERROR_WRITE); |
- io_thread()->PostTaskAndWait( |
- FROM_HERE, base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
- |
- // Close the handle of the other end, which should stuff fail. |
- handles[1].reset(); |
+ base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate))); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc))); |
EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
- |
- // Wait for the delegate, which will shut the |RawChannel| down. |
- delegate.Wait(); |
} |
// RawChannelTest.ReadWritePlatformHandles ------------------------------------- |
@@ -747,7 +558,7 @@ class ReadPlatformHandlesCheckerRawChannelDelegate |
// |RawChannel::Delegate| implementation (called on the I/O thread): |
void OnReadMessage( |
const MessageInTransit::View& message_view, |
- embedder::ScopedPlatformHandleVectorPtr platform_handles) override { |
+ ScopedPlatformHandleVectorPtr platform_handles) override { |
const char kHello[] = "hello"; |
EXPECT_EQ(sizeof(kHello), message_view.num_bytes()); |
@@ -755,16 +566,16 @@ class ReadPlatformHandlesCheckerRawChannelDelegate |
ASSERT_TRUE(platform_handles); |
ASSERT_EQ(2u, platform_handles->size()); |
- embedder::ScopedPlatformHandle h1(platform_handles->at(0)); |
+ ScopedPlatformHandle h1(platform_handles->at(0)); |
EXPECT_TRUE(h1.is_valid()); |
- embedder::ScopedPlatformHandle h2(platform_handles->at(1)); |
+ ScopedPlatformHandle h2(platform_handles->at(1)); |
EXPECT_TRUE(h2.is_valid()); |
platform_handles->clear(); |
{ |
char buffer[100] = {}; |
- base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h1.Pass(), "rb")); |
+ base::ScopedFILE fp(test::FILEFromPlatformHandle(h1.Pass(), "rb")); |
EXPECT_TRUE(fp); |
rewind(fp.get()); |
EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); |
@@ -773,7 +584,7 @@ class ReadPlatformHandlesCheckerRawChannelDelegate |
{ |
char buffer[100] = {}; |
- base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h2.Pass(), "rb")); |
+ base::ScopedFILE fp(test::FILEFromPlatformHandle(h2.Pass(), "rb")); |
EXPECT_TRUE(fp); |
rewind(fp.get()); |
EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); |
@@ -795,27 +606,21 @@ class ReadPlatformHandlesCheckerRawChannelDelegate |
MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); |
}; |
-#if defined(OS_POSIX) |
-#define MAYBE_ReadWritePlatformHandles ReadWritePlatformHandles |
-#else |
-// Not yet implemented (on Windows). |
-#define MAYBE_ReadWritePlatformHandles DISABLED_ReadWritePlatformHandles |
-#endif |
-TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { |
+TEST_F(RawChannelTest, ReadWritePlatformHandles) { |
base::ScopedTempDir temp_dir; |
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
WriteOnlyRawChannelDelegate write_delegate; |
- scoped_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass())); |
- io_thread()->PostTaskAndWait(FROM_HERE, |
- base::Bind(&InitOnIOThread, rc_write.get(), |
- base::Unretained(&write_delegate))); |
+ RawChannel* rc_write = RawChannel::Create(handles[0].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, |
+ base::Bind(&InitOnIOThread, rc_write, base::Unretained(&write_delegate))); |
ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; |
- scoped_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); |
- io_thread()->PostTaskAndWait(FROM_HERE, |
- base::Bind(&InitOnIOThread, rc_read.get(), |
- base::Unretained(&read_delegate))); |
+ RawChannel* rc_read = RawChannel::Create(handles[1].Pass()); |
+ test_io_thread()->PostTaskAndWait( |
+ FROM_HERE, |
+ base::Bind(&InitOnIOThread, rc_read, base::Unretained(&read_delegate))); |
base::FilePath unused; |
base::ScopedFILE fp1( |
@@ -827,16 +632,14 @@ TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { |
{ |
const char kHello[] = "hello"; |
- embedder::ScopedPlatformHandleVectorPtr platform_handles( |
- new embedder::PlatformHandleVector()); |
+ ScopedPlatformHandleVectorPtr platform_handles(new PlatformHandleVector()); |
platform_handles->push_back( |
- mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); |
+ test::PlatformHandleFromFILE(fp1.Pass()).release()); |
platform_handles->push_back( |
- mojo::test::PlatformHandleFromFILE(fp2.Pass()).release()); |
+ test::PlatformHandleFromFILE(fp2.Pass()).release()); |
scoped_ptr<MessageInTransit> message( |
- new MessageInTransit(MessageInTransit::Type::ENDPOINT_CLIENT, |
- MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, |
+ new MessageInTransit(MessageInTransit::Type::MESSAGE, |
sizeof(kHello), kHello)); |
message->SetTransportData(make_scoped_ptr(new TransportData( |
platform_handles.Pass(), rc_write->GetSerializedPlatformHandleSize()))); |
@@ -845,14 +648,14 @@ TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { |
read_delegate.Wait(); |
- io_thread()->PostTaskAndWait( |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); |
- io_thread()->PostTaskAndWait( |
+ base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read))); |
+ test_io_thread()->PostTaskAndWait( |
FROM_HERE, |
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); |
+ base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write))); |
} |
} // namespace |
-} // namespace system |
+} // namespace edk |
} // namespace mojo |