OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/channel.h" | 5 #include "mojo/system/channel.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/test/test_io_thread.h" |
10 #include "mojo/embedder/platform_channel_pair.h" | 11 #include "mojo/embedder/platform_channel_pair.h" |
11 #include "mojo/embedder/simple_platform_support.h" | 12 #include "mojo/embedder/simple_platform_support.h" |
12 #include "mojo/system/message_in_transit.h" | 13 #include "mojo/system/message_in_transit.h" |
13 #include "mojo/system/message_pipe.h" | 14 #include "mojo/system/message_pipe.h" |
14 #include "mojo/system/raw_channel.h" | 15 #include "mojo/system/raw_channel.h" |
15 #include "mojo/system/test_utils.h" | 16 #include "mojo/system/test_utils.h" |
16 #include "mojo/system/waiter.h" | 17 #include "mojo/system/waiter.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace mojo { | 20 namespace mojo { |
20 namespace system { | 21 namespace system { |
21 namespace { | 22 namespace { |
22 | 23 |
23 enum Tristate { TRISTATE_UNKNOWN = -1, TRISTATE_FALSE = 0, TRISTATE_TRUE = 1 }; | 24 enum Tristate { TRISTATE_UNKNOWN = -1, TRISTATE_FALSE = 0, TRISTATE_TRUE = 1 }; |
24 | 25 |
25 Tristate BoolToTristate(bool b) { | 26 Tristate BoolToTristate(bool b) { |
26 return b ? TRISTATE_TRUE : TRISTATE_FALSE; | 27 return b ? TRISTATE_TRUE : TRISTATE_FALSE; |
27 } | 28 } |
28 | 29 |
29 class ChannelTest : public testing::Test { | 30 class ChannelTest : public testing::Test { |
30 public: | 31 public: |
31 ChannelTest() | 32 ChannelTest() |
32 : io_thread_(test::TestIOThread::kAutoStart), | 33 : io_thread_(base::TestIOThread::kAutoStart), |
33 init_result_(TRISTATE_UNKNOWN) {} | 34 init_result_(TRISTATE_UNKNOWN) {} |
34 virtual ~ChannelTest() {} | 35 virtual ~ChannelTest() {} |
35 | 36 |
36 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
37 io_thread_.PostTaskAndWait( | 38 io_thread_.PostTaskAndWait( |
38 FROM_HERE, | 39 FROM_HERE, |
39 base::Bind(&ChannelTest::SetUpOnIOThread, base::Unretained(this))); | 40 base::Bind(&ChannelTest::SetUpOnIOThread, base::Unretained(this))); |
40 } | 41 } |
41 | 42 |
42 void CreateChannelOnIOThread() { | 43 void CreateChannelOnIOThread() { |
(...skipping 11 matching lines...) Expand all Loading... |
54 init_result_ = BoolToTristate(channel_->Init(raw_channel_.Pass())); | 55 init_result_ = BoolToTristate(channel_->Init(raw_channel_.Pass())); |
55 } | 56 } |
56 | 57 |
57 void ShutdownChannelOnIOThread() { | 58 void ShutdownChannelOnIOThread() { |
58 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 59 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
59 | 60 |
60 CHECK(channel_.get()); | 61 CHECK(channel_.get()); |
61 channel_->Shutdown(); | 62 channel_->Shutdown(); |
62 } | 63 } |
63 | 64 |
64 test::TestIOThread* io_thread() { return &io_thread_; } | 65 base::TestIOThread* io_thread() { return &io_thread_; } |
65 RawChannel* raw_channel() { return raw_channel_.get(); } | 66 RawChannel* raw_channel() { return raw_channel_.get(); } |
66 scoped_ptr<RawChannel>* mutable_raw_channel() { return &raw_channel_; } | 67 scoped_ptr<RawChannel>* mutable_raw_channel() { return &raw_channel_; } |
67 Channel* channel() { return channel_.get(); } | 68 Channel* channel() { return channel_.get(); } |
68 scoped_refptr<Channel>* mutable_channel() { return &channel_; } | 69 scoped_refptr<Channel>* mutable_channel() { return &channel_; } |
69 Tristate init_result() const { return init_result_; } | 70 Tristate init_result() const { return init_result_; } |
70 | 71 |
71 private: | 72 private: |
72 void SetUpOnIOThread() { | 73 void SetUpOnIOThread() { |
73 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 74 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
74 | 75 |
75 embedder::PlatformChannelPair channel_pair; | 76 embedder::PlatformChannelPair channel_pair; |
76 raw_channel_ = RawChannel::Create(channel_pair.PassServerHandle()).Pass(); | 77 raw_channel_ = RawChannel::Create(channel_pair.PassServerHandle()).Pass(); |
77 other_platform_handle_ = channel_pair.PassClientHandle(); | 78 other_platform_handle_ = channel_pair.PassClientHandle(); |
78 } | 79 } |
79 | 80 |
80 embedder::SimplePlatformSupport platform_support_; | 81 embedder::SimplePlatformSupport platform_support_; |
81 test::TestIOThread io_thread_; | 82 base::TestIOThread io_thread_; |
82 scoped_ptr<RawChannel> raw_channel_; | 83 scoped_ptr<RawChannel> raw_channel_; |
83 embedder::ScopedPlatformHandle other_platform_handle_; | 84 embedder::ScopedPlatformHandle other_platform_handle_; |
84 scoped_refptr<Channel> channel_; | 85 scoped_refptr<Channel> channel_; |
85 | 86 |
86 Tristate init_result_; | 87 Tristate init_result_; |
87 | 88 |
88 DISALLOW_COPY_AND_ASSIGN(ChannelTest); | 89 DISALLOW_COPY_AND_ASSIGN(ChannelTest); |
89 }; | 90 }; |
90 | 91 |
91 // ChannelTest.InitShutdown ---------------------------------------------------- | 92 // ChannelTest.InitShutdown ---------------------------------------------------- |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 mp->Close(0); | 306 mp->Close(0); |
306 | 307 |
307 EXPECT_TRUE(channel()->HasOneRef()); | 308 EXPECT_TRUE(channel()->HasOneRef()); |
308 } | 309 } |
309 | 310 |
310 // TODO(vtl): More. ------------------------------------------------------------ | 311 // TODO(vtl): More. ------------------------------------------------------------ |
311 | 312 |
312 } // namespace | 313 } // namespace |
313 } // namespace system | 314 } // namespace system |
314 } // namespace mojo | 315 } // namespace mojo |
OLD | NEW |