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 #include "mojo/edk/system/endpoint_relayer.h" | 5 #include "mojo/edk/system/endpoint_relayer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "mojo/edk/system/channel_endpoint_id.h" | 10 #include "mojo/edk/system/channel_endpoint_id.h" |
11 #include "mojo/edk/system/channel_test_base.h" | 11 #include "mojo/edk/system/channel_test_base.h" |
12 #include "mojo/edk/system/message_in_transit_queue.h" | 12 #include "mojo/edk/system/message_in_transit_queue.h" |
13 #include "mojo/edk/system/message_in_transit_test_utils.h" | 13 #include "mojo/edk/system/message_in_transit_test_utils.h" |
| 14 #include "mojo/edk/system/ref_ptr.h" |
14 #include "mojo/edk/system/test_channel_endpoint_client.h" | 15 #include "mojo/edk/system/test_channel_endpoint_client.h" |
15 #include "mojo/edk/util/make_unique.h" | 16 #include "mojo/edk/util/make_unique.h" |
16 #include "mojo/public/cpp/system/macros.h" | 17 #include "mojo/public/cpp/system/macros.h" |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 namespace system { | 20 namespace system { |
20 namespace { | 21 namespace { |
21 | 22 |
22 class EndpointRelayerTest : public test::ChannelTestBase { | 23 class EndpointRelayerTest : public test::ChannelTestBase { |
23 public: | 24 public: |
(...skipping 12 matching lines...) Expand all Loading... |
36 // * Across the pair of channels, we'll have a pair of connections (call | 37 // * Across the pair of channels, we'll have a pair of connections (call |
37 // them "a" and "b"). | 38 // them "a" and "b"). |
38 // * On channel 0, we'll have a pair of endpoints ("0a" and "0b") hooked up | 39 // * On channel 0, we'll have a pair of endpoints ("0a" and "0b") hooked up |
39 // to an |EndpointRelayer|. | 40 // to an |EndpointRelayer|. |
40 // * On channel 1, we'll have a pair of endpoints hooked up to test endpoint | 41 // * On channel 1, we'll have a pair of endpoints hooked up to test endpoint |
41 // clients ("1a" and "1b"). | 42 // clients ("1a" and "1b"). |
42 LocalChannelEndpointIdGenerator id_generator; | 43 LocalChannelEndpointIdGenerator id_generator; |
43 ChannelEndpointId ida = id_generator.GetNext(); | 44 ChannelEndpointId ida = id_generator.GetNext(); |
44 ChannelEndpointId idb = id_generator.GetNext(); | 45 ChannelEndpointId idb = id_generator.GetNext(); |
45 | 46 |
46 relayer_ = new EndpointRelayer(); | 47 relayer_ = MakeRefCounted<EndpointRelayer>(); |
47 endpoint0a_ = MakeRefCounted<ChannelEndpoint>(relayer_.get(), 0); | 48 endpoint0a_ = MakeRefCounted<ChannelEndpoint>(relayer_.Clone(), 0); |
48 endpoint0b_ = MakeRefCounted<ChannelEndpoint>(relayer_.get(), 1); | 49 endpoint0b_ = MakeRefCounted<ChannelEndpoint>(relayer_.Clone(), 1); |
49 relayer_->Init(endpoint0a_.Clone(), endpoint0b_.Clone()); | 50 relayer_->Init(endpoint0a_.Clone(), endpoint0b_.Clone()); |
50 channel(0)->SetBootstrapEndpointWithIds(endpoint0a_.Clone(), ida, ida); | 51 channel(0)->SetBootstrapEndpointWithIds(endpoint0a_.Clone(), ida, ida); |
51 channel(0)->SetBootstrapEndpointWithIds(endpoint0b_.Clone(), idb, idb); | 52 channel(0)->SetBootstrapEndpointWithIds(endpoint0b_.Clone(), idb, idb); |
52 | 53 |
53 client1a_ = new test::TestChannelEndpointClient(); | 54 client1a_ = MakeRefCounted<test::TestChannelEndpointClient>(); |
54 client1b_ = new test::TestChannelEndpointClient(); | 55 client1b_ = MakeRefCounted<test::TestChannelEndpointClient>(); |
55 endpoint1a_ = MakeRefCounted<ChannelEndpoint>(client1a_.get(), 0); | 56 endpoint1a_ = MakeRefCounted<ChannelEndpoint>(client1a_.Clone(), 0); |
56 endpoint1b_ = MakeRefCounted<ChannelEndpoint>(client1b_.get(), 0); | 57 endpoint1b_ = MakeRefCounted<ChannelEndpoint>(client1b_.Clone(), 0); |
57 client1a_->Init(0, endpoint1a_.Clone()); | 58 client1a_->Init(0, endpoint1a_.Clone()); |
58 client1b_->Init(0, endpoint1b_.Clone()); | 59 client1b_->Init(0, endpoint1b_.Clone()); |
59 channel(1)->SetBootstrapEndpointWithIds(endpoint1a_.Clone(), ida, ida); | 60 channel(1)->SetBootstrapEndpointWithIds(endpoint1a_.Clone(), ida, ida); |
60 channel(1)->SetBootstrapEndpointWithIds(endpoint1b_.Clone(), idb, idb); | 61 channel(1)->SetBootstrapEndpointWithIds(endpoint1b_.Clone(), idb, idb); |
61 } | 62 } |
62 | 63 |
63 void TearDown() override { | 64 void TearDown() override { |
64 PostMethodToIOThreadAndWait( | 65 PostMethodToIOThreadAndWait( |
65 FROM_HERE, &EndpointRelayerTest::ShutdownChannelOnIOThread, 0); | 66 FROM_HERE, &EndpointRelayerTest::ShutdownChannelOnIOThread, 0); |
66 PostMethodToIOThreadAndWait( | 67 PostMethodToIOThreadAndWait( |
67 FROM_HERE, &EndpointRelayerTest::ShutdownChannelOnIOThread, 1); | 68 FROM_HERE, &EndpointRelayerTest::ShutdownChannelOnIOThread, 1); |
68 | 69 |
69 test::ChannelTestBase::TearDown(); | 70 test::ChannelTestBase::TearDown(); |
70 } | 71 } |
71 | 72 |
72 protected: | 73 protected: |
73 EndpointRelayer* relayer() { return relayer_.get(); } | 74 EndpointRelayer* relayer() { return relayer_.get(); } |
74 test::TestChannelEndpointClient* client1a() { return client1a_.get(); } | 75 test::TestChannelEndpointClient* client1a() { return client1a_.get(); } |
75 test::TestChannelEndpointClient* client1b() { return client1b_.get(); } | 76 test::TestChannelEndpointClient* client1b() { return client1b_.get(); } |
76 ChannelEndpoint* endpoint1a() { return endpoint1a_.get(); } | 77 ChannelEndpoint* endpoint1a() { return endpoint1a_.get(); } |
77 ChannelEndpoint* endpoint1b() { return endpoint1b_.get(); } | 78 ChannelEndpoint* endpoint1b() { return endpoint1b_.get(); } |
78 | 79 |
79 private: | 80 private: |
80 scoped_refptr<EndpointRelayer> relayer_; | 81 RefPtr<EndpointRelayer> relayer_; |
81 RefPtr<ChannelEndpoint> endpoint0a_; | 82 RefPtr<ChannelEndpoint> endpoint0a_; |
82 RefPtr<ChannelEndpoint> endpoint0b_; | 83 RefPtr<ChannelEndpoint> endpoint0b_; |
83 scoped_refptr<test::TestChannelEndpointClient> client1a_; | 84 RefPtr<test::TestChannelEndpointClient> client1a_; |
84 scoped_refptr<test::TestChannelEndpointClient> client1b_; | 85 RefPtr<test::TestChannelEndpointClient> client1b_; |
85 RefPtr<ChannelEndpoint> endpoint1a_; | 86 RefPtr<ChannelEndpoint> endpoint1a_; |
86 RefPtr<ChannelEndpoint> endpoint1b_; | 87 RefPtr<ChannelEndpoint> endpoint1b_; |
87 | 88 |
88 MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayerTest); | 89 MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayerTest); |
89 }; | 90 }; |
90 | 91 |
91 TEST_F(EndpointRelayerTest, Basic) { | 92 TEST_F(EndpointRelayerTest, Basic) { |
92 base::WaitableEvent read_event(true, false); | 93 base::WaitableEvent read_event(true, false); |
93 client1b()->SetReadEvent(&read_event); | 94 client1b()->SetReadEvent(&read_event); |
94 EXPECT_EQ(0u, client1b()->NumMessages()); | 95 EXPECT_EQ(0u, client1b()->NumMessages()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ASSERT_TRUE(message); | 225 ASSERT_TRUE(message); |
225 test::VerifyTestMessage(message.get(), message_id); | 226 test::VerifyTestMessage(message.get(), message_id); |
226 } | 227 } |
227 } | 228 } |
228 | 229 |
229 // TODO(vtl): Add some "shutdown" tests. | 230 // TODO(vtl): Add some "shutdown" tests. |
230 | 231 |
231 } // namespace | 232 } // namespace |
232 } // namespace system | 233 } // namespace system |
233 } // namespace mojo | 234 } // namespace mojo |
OLD | NEW |