| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file contains tests that are shared between different implementations of | 5 // This file contains tests that are shared between different implementations of |
| 6 // |DataPipeImpl|. | 6 // |DataPipeImpl|. |
| 7 | 7 |
| 8 #include "mojo/edk/system/data_pipe_impl.h" | 8 #include "mojo/edk/system/data_pipe_impl.h" |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/bind.h" | |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 18 #include "mojo/edk/embedder/simple_platform_support.h" | 17 #include "mojo/edk/embedder/simple_platform_support.h" |
| 19 #include "mojo/edk/system/channel.h" | 18 #include "mojo/edk/system/channel.h" |
| 20 #include "mojo/edk/system/channel_endpoint.h" | 19 #include "mojo/edk/system/channel_endpoint.h" |
| 21 #include "mojo/edk/system/data_pipe.h" | 20 #include "mojo/edk/system/data_pipe.h" |
| 22 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 21 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
| 23 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 22 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| 24 #include "mojo/edk/system/memory.h" | 23 #include "mojo/edk/system/memory.h" |
| 25 #include "mojo/edk/system/message_pipe.h" | 24 #include "mojo/edk/system/message_pipe.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 public: | 226 public: |
| 228 RemoteDataPipeImplTestHelper() | 227 RemoteDataPipeImplTestHelper() |
| 229 : io_thread_(test::TestIOThread::StartMode::AUTO) {} | 228 : io_thread_(test::TestIOThread::StartMode::AUTO) {} |
| 230 ~RemoteDataPipeImplTestHelper() override {} | 229 ~RemoteDataPipeImplTestHelper() override {} |
| 231 | 230 |
| 232 void SetUp() override { | 231 void SetUp() override { |
| 233 RefPtr<ChannelEndpoint> ep[2]; | 232 RefPtr<ChannelEndpoint> ep[2]; |
| 234 message_pipes_[0] = MessagePipe::CreateLocalProxy(&ep[0]); | 233 message_pipes_[0] = MessagePipe::CreateLocalProxy(&ep[0]); |
| 235 message_pipes_[1] = MessagePipe::CreateLocalProxy(&ep[1]); | 234 message_pipes_[1] = MessagePipe::CreateLocalProxy(&ep[1]); |
| 236 | 235 |
| 237 io_thread_.PostTaskAndWait(base::Bind( | 236 io_thread_.PostTaskAndWait([this, &ep]() mutable { |
| 238 &RemoteDataPipeImplTestHelper::SetUpOnIOThread, base::Unretained(this), | 237 SetUpOnIOThread(std::move(ep[0]), std::move(ep[1])); |
| 239 base::Passed(&ep[0]), base::Passed(&ep[1]))); | 238 }); |
| 240 } | 239 } |
| 241 | 240 |
| 242 void TearDown() override { | 241 void TearDown() override { |
| 243 EnsureMessagePipeClosed(0); | 242 EnsureMessagePipeClosed(0); |
| 244 EnsureMessagePipeClosed(1); | 243 EnsureMessagePipeClosed(1); |
| 245 io_thread_.PostTaskAndWait( | 244 io_thread_.PostTaskAndWait([this]() { TearDownOnIOThread(); }); |
| 246 base::Bind(&RemoteDataPipeImplTestHelper::TearDownOnIOThread, | |
| 247 base::Unretained(this))); | |
| 248 } | 245 } |
| 249 | 246 |
| 250 void Create(const MojoCreateDataPipeOptions& validated_options) override { | 247 void Create(const MojoCreateDataPipeOptions& validated_options) override { |
| 251 CHECK(!dp_); | 248 CHECK(!dp_); |
| 252 dp_ = DataPipe::CreateLocal(validated_options); | 249 dp_ = DataPipe::CreateLocal(validated_options); |
| 253 } | 250 } |
| 254 | 251 |
| 255 bool IsStrictCircularBuffer() const override { return false; } | 252 bool IsStrictCircularBuffer() const override { return false; } |
| 256 | 253 |
| 257 protected: | 254 protected: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 RefPtr<DataPipe> dp() { return dp_; } | 308 RefPtr<DataPipe> dp() { return dp_; } |
| 312 | 309 |
| 313 private: | 310 private: |
| 314 void EnsureMessagePipeClosed(size_t i) { | 311 void EnsureMessagePipeClosed(size_t i) { |
| 315 if (!message_pipes_[i]) | 312 if (!message_pipes_[i]) |
| 316 return; | 313 return; |
| 317 message_pipes_[i]->Close(0); | 314 message_pipes_[i]->Close(0); |
| 318 message_pipes_[i] = nullptr; | 315 message_pipes_[i] = nullptr; |
| 319 } | 316 } |
| 320 | 317 |
| 321 // TODO(vtl): The arguments should be rvalue references, but that doesn't | 318 void SetUpOnIOThread(RefPtr<ChannelEndpoint>&& ep0, |
| 322 // currently work correctly with base::Bind. | 319 RefPtr<ChannelEndpoint>&& ep1) { |
| 323 void SetUpOnIOThread(RefPtr<ChannelEndpoint> ep0, | |
| 324 RefPtr<ChannelEndpoint> ep1) { | |
| 325 CHECK(io_thread_.IsCurrentAndRunning()); | 320 CHECK(io_thread_.IsCurrentAndRunning()); |
| 326 | 321 |
| 327 embedder::PlatformChannelPair channel_pair; | 322 embedder::PlatformChannelPair channel_pair; |
| 328 channels_[0] = MakeRefCounted<Channel>(&platform_support_); | 323 channels_[0] = MakeRefCounted<Channel>(&platform_support_); |
| 329 channels_[0]->Init(RawChannel::Create(channel_pair.PassServerHandle())); | 324 channels_[0]->Init(RawChannel::Create(channel_pair.PassServerHandle())); |
| 330 channels_[0]->SetBootstrapEndpoint(std::move(ep0)); | 325 channels_[0]->SetBootstrapEndpoint(std::move(ep0)); |
| 331 channels_[1] = MakeRefCounted<Channel>(&platform_support_); | 326 channels_[1] = MakeRefCounted<Channel>(&platform_support_); |
| 332 channels_[1]->Init(RawChannel::Create(channel_pair.PassClientHandle())); | 327 channels_[1]->Init(RawChannel::Create(channel_pair.PassClientHandle())); |
| 333 channels_[1]->SetBootstrapEndpoint(std::move(ep1)); | 328 channels_[1]->SetBootstrapEndpoint(std::move(ep1)); |
| 334 } | 329 } |
| (...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 test::Sleep(10u); | 2489 test::Sleep(10u); |
| 2495 | 2490 |
| 2496 EXPECT_EQ(MOJO_RESULT_OK, this->ConsumerEndReadData(num_bytes)); | 2491 EXPECT_EQ(MOJO_RESULT_OK, this->ConsumerEndReadData(num_bytes)); |
| 2497 | 2492 |
| 2498 this->ConsumerClose(); | 2493 this->ConsumerClose(); |
| 2499 } | 2494 } |
| 2500 | 2495 |
| 2501 } // namespace | 2496 } // namespace |
| 2502 } // namespace system | 2497 } // namespace system |
| 2503 } // namespace mojo | 2498 } // namespace mojo |
| OLD | NEW |