OLD | NEW |
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/bindings/lib/remote_ptr.h" | 5 #include "mojo/public/bindings/lib/remote_ptr.h" |
6 #include "mojo/public/tests/simple_bindings_support.h" | 6 #include "mojo/public/tests/simple_bindings_support.h" |
7 #include "mojo/public/tests/test_support.h" | 7 #include "mojo/public/tests/test_support.h" |
8 #include "mojom/sample_factory.h" | 8 #include "mojom/sample_factory.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 SampleFactoryImpl : public sample::FactoryStub { | 18 class SampleFactoryImpl : public sample::Factory { |
19 public: | 19 public: |
20 explicit SampleFactoryImpl(ScopedMessagePipeHandle pipe) | 20 explicit SampleFactoryImpl(ScopedMessagePipeHandle pipe) |
21 : client_(pipe.Pass()) { | 21 : client_(pipe.Pass(), this) { |
22 client_.SetPeer(this); | |
23 } | 22 } |
24 | 23 |
25 virtual void DoStuff(const sample::Request& request, | 24 virtual void DoStuff(const sample::Request& request, |
26 ScopedMessagePipeHandle pipe) MOJO_OVERRIDE { | 25 ScopedMessagePipeHandle pipe) MOJO_OVERRIDE { |
27 std::string text1; | 26 std::string text1; |
28 if (pipe.is_valid()) | 27 if (pipe.is_valid()) |
29 EXPECT_TRUE(ReadTextMessage(pipe.get(), &text1)); | 28 EXPECT_TRUE(ReadTextMessage(pipe.get(), &text1)); |
30 | 29 |
31 std::string text2; | 30 std::string text2; |
32 if (request.pipe().is_valid()) { | 31 if (request.pipe().is_valid()) { |
(...skipping 14 matching lines...) Expand all Loading... |
47 response.set_x(2); | 46 response.set_x(2); |
48 response.set_pipe(pipe0.Pass()); | 47 response.set_pipe(pipe0.Pass()); |
49 client_->DidStuff(response.Finish(), text1); | 48 client_->DidStuff(response.Finish(), text1); |
50 } | 49 } |
51 | 50 |
52 private: | 51 private: |
53 RemotePtr<sample::FactoryClient> client_; | 52 RemotePtr<sample::FactoryClient> client_; |
54 ScopedMessagePipeHandle pipe1_; | 53 ScopedMessagePipeHandle pipe1_; |
55 }; | 54 }; |
56 | 55 |
57 class SampleFactoryClientImpl : public sample::FactoryClientStub { | 56 class SampleFactoryClientImpl : public sample::FactoryClient { |
58 public: | 57 public: |
59 explicit SampleFactoryClientImpl(ScopedMessagePipeHandle pipe) | 58 explicit SampleFactoryClientImpl(ScopedMessagePipeHandle pipe) |
60 : factory_(pipe.Pass()), | 59 : factory_(pipe.Pass(), this), |
61 got_response_(false) { | 60 got_response_(false) { |
62 factory_.SetPeer(this); | |
63 } | 61 } |
64 | 62 |
65 void Start() { | 63 void Start() { |
66 expected_text_reply_ = kText1; | 64 expected_text_reply_ = kText1; |
67 | 65 |
68 ScopedMessagePipeHandle pipe0; | 66 ScopedMessagePipeHandle pipe0; |
69 CreateMessagePipe(&pipe0, &pipe1_); | 67 CreateMessagePipe(&pipe0, &pipe1_); |
70 | 68 |
71 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), kText1)); | 69 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), kText1)); |
72 | 70 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 164 |
167 EXPECT_FALSE(factory_client.got_response()); | 165 EXPECT_FALSE(factory_client.got_response()); |
168 | 166 |
169 PumpMessages(); | 167 PumpMessages(); |
170 | 168 |
171 EXPECT_TRUE(factory_client.got_response()); | 169 EXPECT_TRUE(factory_client.got_response()); |
172 } | 170 } |
173 | 171 |
174 } // namespace test | 172 } // namespace test |
175 } // namespace mojo | 173 } // namespace mojo |
OLD | NEW |