diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 09:16:43 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 09:16:43 +0000 |
commit | 5bcc8054cad35c87a449e9eb9c9401155dcbde00 (patch) | |
tree | 0629755e36bd0b1893a19c7a3a7931bd4cf1a0e4 /mojo/public | |
parent | 35075b1c5639ee7b9566a09416a1e0b0e6dc3ecc (diff) | |
download | chromium_src-5bcc8054cad35c87a449e9eb9c9401155dcbde00.zip chromium_src-5bcc8054cad35c87a449e9eb9c9401155dcbde00.tar.gz chromium_src-5bcc8054cad35c87a449e9eb9c9401155dcbde00.tar.bz2 |
Adds support for DataPipe to .mojom
Definitions were missing in PackedField. Also adds a test for
coverage.
BUG=none
TEST=none
R=davemoore@chromium.org
Review URL: https://codereview.chromium.org/155753004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public')
-rw-r--r-- | mojo/public/bindings/pylib/generate/mojom_pack.py | 2 | ||||
-rw-r--r-- | mojo/public/bindings/tests/handle_passing_unittest.cc | 65 | ||||
-rw-r--r-- | mojo/public/bindings/tests/sample_factory.mojom | 2 |
3 files changed, 69 insertions, 0 deletions
diff --git a/mojo/public/bindings/pylib/generate/mojom_pack.py b/mojo/public/bindings/pylib/generate/mojom_pack.py index 3007372..51e4279 100644 --- a/mojo/public/bindings/pylib/generate/mojom_pack.py +++ b/mojo/public/bindings/pylib/generate/mojom_pack.py @@ -23,6 +23,8 @@ class PackedField(object): mojom.FLOAT: 4, mojom.HANDLE: 4, mojom.MSGPIPE: 4, + mojom.DCPIPE: 4, + mojom.DPPIPE: 4, mojom.INT64: 8, mojom.UINT64: 8, mojom.DOUBLE: 8, diff --git a/mojo/public/bindings/tests/handle_passing_unittest.cc b/mojo/public/bindings/tests/handle_passing_unittest.cc index f2fdbb24..5d977ba 100644 --- a/mojo/public/bindings/tests/handle_passing_unittest.cc +++ b/mojo/public/bindings/tests/handle_passing_unittest.cc @@ -50,6 +50,25 @@ class SampleFactoryImpl : public sample::Factory { client_->DidStuff(response.Finish(), text1); } + virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE { + // Read the data from the pipe, writing the response (as a string) to + // DidStuff2(). + ASSERT_TRUE(pipe.is_valid()); + uint32_t data_size = 0; + ASSERT_EQ(MOJO_RESULT_OK, + ReadDataRaw(pipe.get(), NULL, &data_size, + MOJO_READ_DATA_FLAG_QUERY)); + ASSERT_NE(0, static_cast<int>(data_size)); + char data[64]; + ASSERT_LT(static_cast<int>(data_size), 64); + ASSERT_EQ(MOJO_RESULT_OK, + ReadDataRaw(pipe.get(), data, &data_size, + MOJO_READ_DATA_FLAG_ALL_OR_NONE)); + + AllocationScope scope; + client_->DidStuff2(String(std::string(data))); + } + private: RemotePtr<sample::FactoryClient> client_; ScopedMessagePipeHandle pipe1_; @@ -91,6 +110,31 @@ class SampleFactoryClientImpl : public sample::FactoryClient { factory_->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass()); } + // Writes a string to a data pipe and passes the data pipe (consumer) to the + // factory. + void StartDataPipe() { + expected_text_reply_.clear(); + + ScopedDataPipeProducerHandle producer_handle; + ScopedDataPipeConsumerHandle consumer_handle; + MojoCreateDataPipeOptions options = { + sizeof(MojoCreateDataPipeOptions), + MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, + 1, + 1024}; + ASSERT_EQ(MOJO_RESULT_OK, + CreateDataPipe(&options, &producer_handle, &consumer_handle)); + expected_text_reply_ = "got it"; + // +1 for \0. + uint32_t data_size = static_cast<uint32_t>(expected_text_reply_.size() + 1); + ASSERT_EQ(MOJO_RESULT_OK, + WriteDataRaw(producer_handle.get(), expected_text_reply_.c_str(), + &data_size, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); + + AllocationScope scope; + factory_->DoStuff2(consumer_handle.Pass()); + } + bool got_response() const { return got_response_; } @@ -117,6 +161,11 @@ class SampleFactoryClientImpl : public sample::FactoryClient { got_response_ = true; } + virtual void DidStuff2(const String& text_reply) MOJO_OVERRIDE { + got_response_ = true; + EXPECT_EQ(expected_text_reply_, text_reply.To<std::string>()); + } + private: RemotePtr<sample::Factory> factory_; ScopedMessagePipeHandle pipe1_; @@ -168,5 +217,21 @@ TEST_F(HandlePassingTest, PassInvalid) { EXPECT_TRUE(factory_client.got_response()); } +// Verifies DataPipeConsumer can be passed and read from. +TEST_F(HandlePassingTest, DataPipe) { + InterfacePipe<sample::Factory> pipe; + + SampleFactoryImpl factory(pipe.handle_to_peer.Pass()); + SampleFactoryClientImpl factory_client(pipe.handle_to_self.Pass()); + + ASSERT_NO_FATAL_FAILURE(factory_client.StartDataPipe()); + + EXPECT_FALSE(factory_client.got_response()); + + PumpMessages(); + + EXPECT_TRUE(factory_client.got_response()); +} + } // namespace test } // namespace mojo diff --git a/mojo/public/bindings/tests/sample_factory.mojom b/mojo/public/bindings/tests/sample_factory.mojom index 7ae6b34..5f076df 100644 --- a/mojo/public/bindings/tests/sample_factory.mojom +++ b/mojo/public/bindings/tests/sample_factory.mojom @@ -20,11 +20,13 @@ struct Response { [Peer=FactoryClient] interface Factory { void DoStuff(Request request, handle<message_pipe> pipe); + void DoStuff2(handle<data_pipe_consumer> pipe); }; [Peer=Factory] interface FactoryClient { void DidStuff(Response response, string text); + void DidStuff2(string text); }; } // module sample |