Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: remoting/protocol/connection_to_client_unittest.cc

Issue 1460593005: Make protocol::ConnectionToClient an abstract interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/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 ConnectionToClientTest : public testing::Test {
24 public:
25 ConnectionToClientTest() {
26 }
27
28 protected:
29 void SetUp() override {
30 session_ = new FakeSession();
31
32 // Allocate a ClientConnection object with the mock objects.
33 viewer_.reset(new ConnectionToClient(session_));
34 viewer_->SetEventHandler(&handler_);
35 EXPECT_CALL(handler_, OnConnectionAuthenticated(viewer_.get()))
36 .WillOnce(
37 InvokeWithoutArgs(this, &ConnectionToClientTest::ConnectStubs));
38 EXPECT_CALL(handler_, OnConnectionChannelsConnected(viewer_.get()));
39 session_->event_handler()->OnSessionStateChange(Session::CONNECTED);
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 // Owned by |viewer_|.
63 FakeSession* session_;
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest);
67 };
68
69 TEST_F(ConnectionToClientTest, SendUpdateStream) {
70 scoped_ptr<VideoPacket> packet(new VideoPacket());
71 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure());
72
73 base::RunLoop().RunUntilIdle();
74
75 // Verify that something has been written.
76 // TODO(sergeyu): Verify that the correct data has been written.
77 FakeStreamSocket* channel =
78 session_->GetTransport()->GetStreamChannelFactory()->GetFakeChannel(
79 kVideoChannelName);
80 ASSERT_TRUE(channel);
81 EXPECT_FALSE(channel->written_data().empty());
82
83 // And then close the connection to ConnectionToClient.
84 viewer_->Disconnect(protocol::OK);
85
86 base::RunLoop().RunUntilIdle();
87 }
88
89 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) {
90 scoped_ptr<VideoPacket> packet(new VideoPacket());
91 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure());
92
93 // And then close the connection to ConnectionToClient.
94 viewer_->Disconnect(protocol::OK);
95
96 // The test will crash if data writer tries to write data to the
97 // channel socket.
98 // TODO(sergeyu): Use MockSession to verify that no data is written?
99 base::RunLoop().RunUntilIdle();
100 }
101
102 TEST_F(ConnectionToClientTest, StateChange) {
103 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), OK));
104 session_->event_handler()->OnSessionStateChange(Session::CLOSED);
105 base::RunLoop().RunUntilIdle();
106
107 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get(), SESSION_REJECTED));
108 session_->set_error(SESSION_REJECTED);
109 session_->event_handler()->OnSessionStateChange(Session::FAILED);
110 base::RunLoop().RunUntilIdle();
111 }
112
113 } // namespace protocol
114 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698