OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "remoting/base/base_mock_objects.h" | 8 #include "remoting/base/base_mock_objects.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/protocol/fake_session.h" | 10 #include "remoting/protocol/fake_session.h" |
11 #include "remoting/protocol/connection_to_client.h" | 11 #include "remoting/protocol/connection_to_client.h" |
12 #include "remoting/protocol/protocol_mock_objects.h" | 12 #include "remoting/protocol/protocol_mock_objects.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 using ::testing::NotNull; | 16 using ::testing::NotNull; |
17 using ::testing::StrictMock; | 17 using ::testing::StrictMock; |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 namespace protocol { | 20 namespace protocol { |
21 | 21 |
22 class ConnectionToClientTest : public testing::Test { | 22 class ConnectionToClientTest : public testing::Test { |
23 public: | 23 public: |
24 ConnectionToClientTest() { | 24 ConnectionToClientTest() { |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 virtual void SetUp() { | 28 virtual void SetUp() OVERRIDE { |
29 session_ = new protocol::FakeSession(); | 29 session_ = new protocol::FakeSession(); |
30 session_->set_message_loop(&message_loop_); | 30 session_->set_message_loop(&message_loop_); |
31 | 31 |
32 // Allocate a ClientConnection object with the mock objects. | 32 // Allocate a ClientConnection object with the mock objects. |
33 viewer_ = new ConnectionToClient( | 33 viewer_.reset(new ConnectionToClient(session_)); |
34 base::MessageLoopProxy::current(), session_); | |
35 viewer_->set_host_stub(&host_stub_); | 34 viewer_->set_host_stub(&host_stub_); |
36 viewer_->set_input_stub(&input_stub_); | 35 viewer_->set_input_stub(&input_stub_); |
37 viewer_->SetEventHandler(&handler_); | 36 viewer_->SetEventHandler(&handler_); |
38 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); | 37 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); |
39 session_->state_change_callback().Run( | 38 session_->state_change_callback().Run( |
40 protocol::Session::CONNECTED); | 39 protocol::Session::CONNECTED); |
41 session_->state_change_callback().Run( | 40 session_->state_change_callback().Run( |
42 protocol::Session::CONNECTED_CHANNELS); | 41 protocol::Session::CONNECTED_CHANNELS); |
43 message_loop_.RunAllPending(); | 42 message_loop_.RunAllPending(); |
44 } | 43 } |
45 | 44 |
46 virtual void TearDown() OVERRIDE { | 45 virtual void TearDown() OVERRIDE { |
47 viewer_ = NULL; | 46 viewer_.reset(); |
48 message_loop_.RunAllPending(); | 47 message_loop_.RunAllPending(); |
49 } | 48 } |
50 | 49 |
51 MessageLoop message_loop_; | 50 MessageLoop message_loop_; |
52 MockConnectionToClientEventHandler handler_; | 51 MockConnectionToClientEventHandler handler_; |
53 MockHostStub host_stub_; | 52 MockHostStub host_stub_; |
54 MockInputStub input_stub_; | 53 MockInputStub input_stub_; |
55 scoped_refptr<ConnectionToClient> viewer_; | 54 scoped_ptr<ConnectionToClient> viewer_; |
56 | 55 |
57 // Owned by |viewer_|. | 56 // Owned by |viewer_|. |
58 protocol::FakeSession* session_; | 57 protocol::FakeSession* session_; |
59 | 58 |
60 private: | 59 private: |
61 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); | 60 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); |
62 }; | 61 }; |
63 | 62 |
64 TEST_F(ConnectionToClientTest, SendUpdateStream) { | 63 TEST_F(ConnectionToClientTest, SendUpdateStream) { |
65 // Then send the actual data. | 64 // Then send the actual data. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 session_->state_change_callback().Run(protocol::Session::CLOSED); | 100 session_->state_change_callback().Run(protocol::Session::CLOSED); |
102 message_loop_.RunAllPending(); | 101 message_loop_.RunAllPending(); |
103 | 102 |
104 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); | 103 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); |
105 session_->state_change_callback().Run(protocol::Session::FAILED); | 104 session_->state_change_callback().Run(protocol::Session::FAILED); |
106 message_loop_.RunAllPending(); | 105 message_loop_.RunAllPending(); |
107 } | 106 } |
108 | 107 |
109 } // namespace protocol | 108 } // namespace protocol |
110 } // namespace remoting | 109 } // namespace remoting |
OLD | NEW |