OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/protocol/ice_connection_to_client.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | |
10 #include "remoting/base/constants.h" | |
11 #include "remoting/protocol/fake_session.h" | |
12 #include "remoting/protocol/protocol_mock_objects.h" | |
13 #include "testing/gmock/include/gmock/gmock.h" | |
14 | |
15 using ::testing::_; | |
16 using ::testing::InvokeWithoutArgs; | |
17 using ::testing::NotNull; | |
18 using ::testing::StrictMock; | |
19 | |
20 namespace remoting { | |
21 namespace protocol { | |
22 | |
23 class IpcConnectionToClientTest : public testing::Test { | |
24 public: | |
25 IpcConnectionToClientTest() {} | |
26 | |
27 protected: | |
28 void SetUp() override { | |
29 session_ = new FakeSession(); | |
30 | |
31 // Allocate a ClientConnection object with the mock objects. | |
32 viewer_.reset(new IceConnectionToClient(make_scoped_ptr(session_), | |
33 message_loop_.task_runner())); | |
34 viewer_->SetEventHandler(&handler_); | |
35 EXPECT_CALL(handler_, OnConnectionAuthenticated(viewer_.get())) | |
36 .WillOnce( | |
37 InvokeWithoutArgs(this, &IpcConnectionToClientTest::ConnectStubs)); | |
38 EXPECT_CALL(handler_, OnConnectionChannelsConnected(viewer_.get())); | |
39 session_->event_handler()->OnSessionStateChange(Session::ACCEPTED); | |
40 session_->event_handler()->OnSessionStateChange(Session::AUTHENTICATED); | |
41 base::RunLoop().RunUntilIdle(); | |
42 } | |
43 | |
44 void TearDown() override { | |
45 viewer_.reset(); | |
46 base::RunLoop().RunUntilIdle(); | |
47 } | |
48 | |
49 void ConnectStubs() { | |
50 viewer_->set_clipboard_stub(&clipboard_stub_); | |
51 viewer_->set_host_stub(&host_stub_); | |
52 viewer_->set_input_stub(&input_stub_); | |
53 } | |
54 | |
55 base::MessageLoop message_loop_; | |
56 MockConnectionToClientEventHandler handler_; | |
57 MockClipboardStub clipboard_stub_; | |
58 MockHostStub host_stub_; | |
59 MockInputStub input_stub_; | |
60 scoped_ptr<ConnectionToClient> viewer_; | |
61 | |
62 FakeSession* session_; | |
63 | |
64 private: | |
65 DISALLOW_COPY_AND_ASSIGN(IpcConnectionToClientTest); | |
66 }; | |
67 | |
68 TEST_F(IpcConnectionToClientTest, SendUpdateStream) { | |
69 Capabilities capabilities; | |
70 viewer_->client_stub()->SetCapabilities(capabilities); | |
71 | |
72 base::RunLoop().RunUntilIdle(); | |
73 | |
74 // Verify that something has been written. | |
75 // TODO(sergeyu): Verify that the correct data has been written. | |
76 FakeStreamSocket* channel = | |
77 session_->GetTransport()->GetStreamChannelFactory()->GetFakeChannel( | |
78 kControlChannelName); | |
79 ASSERT_TRUE(channel); | |
80 EXPECT_FALSE(channel->written_data().empty()); | |
81 | |
82 // And then close the connection to ConnectionToClient. | |
83 viewer_->Disconnect(protocol::OK); | |
84 | |
85 base::RunLoop().RunUntilIdle(); | |
86 } | |
87 | |
88 TEST_F(IpcConnectionToClientTest, NoWriteAfterDisconnect) { | |
89 Capabilities capabilities; | |
90 viewer_->client_stub()->SetCapabilities(capabilities); | |
91 | |
92 // And then close the connection to ConnectionToClient. | |
93 viewer_->Disconnect(protocol::OK); | |
94 | |
95 // The test will crash if data writer tries to write data to the | |
96 // channel socket. | |
97 // TODO(sergeyu): Use MockSession to verify that no data is written? | |
98 base::RunLoop().RunUntilIdle(); | |
99 } | |
100 | |
101 TEST_F(IpcConnectionToClientTest, StateChange) { | |
102 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK)); | |
103 session_->event_handler()->OnSessionStateChange(Session::CLOSED); | |
104 base::RunLoop().RunUntilIdle(); | |
105 | |
106 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED)); | |
107 session_->set_error(SESSION_REJECTED); | |
108 session_->event_handler()->OnSessionStateChange(Session::FAILED); | |
109 base::RunLoop().RunUntilIdle(); | |
110 } | |
111 | |
112 } // namespace protocol | |
113 } // namespace remoting | |
OLD | NEW |