Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc

Issue 272323003: Mojo: Implement support for |Foo&| mojom syntax (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/public/cpp/environment/environment.h" 5 #include "mojo/public/cpp/environment/environment.h"
6 #include "mojo/public/cpp/test_support/test_utils.h" 6 #include "mojo/public/cpp/test_support/test_utils.h"
7 #include "mojo/public/cpp/utility/run_loop.h" 7 #include "mojo/public/cpp/utility/run_loop.h"
8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" 8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace test { 12 namespace test {
13 namespace { 13 namespace {
14 14
15 const char kText1[] = "hello"; 15 const char kText1[] = "hello";
16 const char kText2[] = "world"; 16 const char kText2[] = "world";
17 17
18 class StringRecorder {
19 public:
20 explicit StringRecorder(std::string* buf) : buf_(buf) {
21 }
22 void Run(const String& a) const {
23 *buf_ = a.To<std::string>();
24 }
25 private:
26 std::string* buf_;
27 };
28
29 class SampleObjectImpl : public InterfaceImpl<sample::Object> {
30 public:
31 virtual void OnConnectionError() MOJO_OVERRIDE {
32 delete this;
33 }
34
35 virtual void SetName(const mojo::String& name) MOJO_OVERRIDE {
36 name_ = name;
37 }
38
39 virtual void GetName(const mojo::Callback<void(mojo::String)>& callback)
40 MOJO_OVERRIDE {
41 callback.Run(name_);
42 }
43
44 private:
45 std::string name_;
46 };
47
18 class SampleFactoryImpl : public InterfaceImpl<sample::Factory> { 48 class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
19 public: 49 public:
20 virtual void OnConnectionError() MOJO_OVERRIDE { 50 virtual void OnConnectionError() MOJO_OVERRIDE {
21 delete this; 51 delete this;
22 } 52 }
23 53
24 virtual void DoStuff(sample::RequestPtr request, 54 virtual void DoStuff(sample::RequestPtr request,
25 ScopedMessagePipeHandle pipe) MOJO_OVERRIDE { 55 ScopedMessagePipeHandle pipe) MOJO_OVERRIDE {
26 std::string text1; 56 std::string text1;
27 if (pipe.is_valid()) 57 if (pipe.is_valid())
(...skipping 30 matching lines...) Expand all
58 ASSERT_NE(0, static_cast<int>(data_size)); 88 ASSERT_NE(0, static_cast<int>(data_size));
59 char data[64]; 89 char data[64];
60 ASSERT_LT(static_cast<int>(data_size), 64); 90 ASSERT_LT(static_cast<int>(data_size), 64);
61 ASSERT_EQ(MOJO_RESULT_OK, 91 ASSERT_EQ(MOJO_RESULT_OK,
62 ReadDataRaw(pipe.get(), data, &data_size, 92 ReadDataRaw(pipe.get(), data, &data_size,
63 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 93 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
64 94
65 client()->DidStuff2(data); 95 client()->DidStuff2(data);
66 } 96 }
67 97
98 virtual void CreateObject(InterfaceRequest<sample::Object> object_request)
99 MOJO_OVERRIDE {
100 EXPECT_TRUE(object_request.is_pending());
101 BindToRequest(new SampleObjectImpl(), &object_request);
102 }
103
68 private: 104 private:
69 ScopedMessagePipeHandle pipe1_; 105 ScopedMessagePipeHandle pipe1_;
70 }; 106 };
71 107
72 class SampleFactoryClientImpl : public sample::FactoryClient { 108 class SampleFactoryClientImpl : public sample::FactoryClient {
73 public: 109 public:
74 SampleFactoryClientImpl() : got_response_(false) { 110 SampleFactoryClientImpl() : got_response_(false) {
75 } 111 }
76 112
77 void set_expected_text_reply(const std::string& expected_text_reply) { 113 void set_expected_text_reply(const std::string& expected_text_reply) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 EXPECT_TRUE(internal::IsHandle<DataPipeConsumerHandle>::value); 288 EXPECT_TRUE(internal::IsHandle<DataPipeConsumerHandle>::value);
253 EXPECT_TRUE(internal::IsHandle<DataPipeProducerHandle>::value); 289 EXPECT_TRUE(internal::IsHandle<DataPipeProducerHandle>::value);
254 EXPECT_TRUE(internal::IsHandle<SharedBufferHandle>::value); 290 EXPECT_TRUE(internal::IsHandle<SharedBufferHandle>::value);
255 291
256 // Basic sanity checks... 292 // Basic sanity checks...
257 EXPECT_FALSE(internal::IsHandle<int>::value); 293 EXPECT_FALSE(internal::IsHandle<int>::value);
258 EXPECT_FALSE(internal::IsHandle<sample::FactoryPtr>::value); 294 EXPECT_FALSE(internal::IsHandle<sample::FactoryPtr>::value);
259 EXPECT_FALSE(internal::IsHandle<String>::value); 295 EXPECT_FALSE(internal::IsHandle<String>::value);
260 } 296 }
261 297
298 TEST_F(HandlePassingTest, CreateObject) {
299 sample::FactoryPtr factory;
300 BindToProxy(new SampleFactoryImpl(), &factory);
301
302 sample::ObjectPtr object1;
303 EXPECT_FALSE(object1.get());
304
305 InterfaceRequest<sample::Object> object1_request = Get(&object1);
306 EXPECT_TRUE(object1_request.is_pending());
307 factory->CreateObject(object1_request.Pass());
308 EXPECT_FALSE(object1_request.is_pending()); // We've passed the request.
309
310 ASSERT_TRUE(object1.get());
311 object1->SetName("object1");
312
313 sample::ObjectPtr object2;
314 factory->CreateObject(Get(&object2));
315 object2->SetName("object2");
316
317 std::string name1;
318 object1->GetName(StringRecorder(&name1));
319
320 std::string name2;
321 object2->GetName(StringRecorder(&name2));
322
323 PumpMessages(); // Yield for results.
324
325 EXPECT_EQ(std::string("object1"), name1);
326 EXPECT_EQ(std::string("object2"), name2);
327 }
328
262 } // namespace 329 } // namespace
263 } // namespace test 330 } // namespace test
264 } // namespace mojo 331 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/no_interface.h ('k') | mojo/public/cpp/bindings/tests/request_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698