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 93% |
copy from third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc |
copy to mojo/edk/system/raw_channel_unittest.cc |
index a9017915ac74b1499e5271a84b7f0ce3b98a1247..1a75c7dc9e5ce68bab69be984c98e33e977f6d31 100644 |
--- a/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc |
+++ b/mojo/edk/system/raw_channel_unittest.cc |
@@ -19,6 +19,7 @@ |
#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" |
@@ -27,7 +28,6 @@ |
#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/mutex.h" |
#include "mojo/edk/system/test_utils.h" |
#include "mojo/edk/system/transport_data.h" |
#include "mojo/edk/test/test_utils.h" |
@@ -35,7 +35,7 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
namespace mojo { |
-namespace system { |
+namespace edk { |
namespace { |
scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { |
@@ -61,13 +61,13 @@ 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(); |
} |
@@ -79,7 +79,7 @@ class RawChannelTest : public testing::Test { |
~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(); |
@@ -94,7 +94,7 @@ class RawChannelTest : public testing::Test { |
protected: |
base::TestIOThread* io_thread() { return &io_thread_; } |
- embedder::ScopedPlatformHandle handles[2]; |
+ ScopedPlatformHandle handles[2]; |
private: |
base::TestIOThread io_thread_; |
@@ -112,7 +112,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 +129,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 +138,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 +182,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_; |
@@ -226,14 +225,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 +260,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 +269,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); |
}; |
@@ -344,7 +343,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_); |
@@ -568,7 +567,7 @@ class ShutdownOnReadMessageRawChannelDelegate : 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_FALSE(did_shutdown_); |
EXPECT_TRUE( |
@@ -644,7 +643,7 @@ class ShutdownOnErrorRawChannelDelegate : 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 { |
CHECK(false); // Should not get called. |
} |
void OnError(Error error) override { |
@@ -747,7 +746,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 +754,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 +772,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())); |
@@ -827,12 +826,11 @@ 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, |
@@ -854,5 +852,5 @@ TEST_F(RawChannelTest, MAYBE_ReadWritePlatformHandles) { |
} |
} // namespace |
-} // namespace system |
+} // namespace edk |
} // namespace mojo |