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

Side by Side Diff: remoting/host/client_connection_unittest.cc

Issue 2829018: Fix thread usage in chromoting host (Closed)
Patch Set: removed useless test Created 10 years, 5 months 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
« no previous file with comments | « remoting/host/client_connection.cc ('k') | remoting/host/encoder_verbatim.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "media/base/data_buffer.h" 6 #include "media/base/data_buffer.h"
7 #include "remoting/base/mock_objects.h" 7 #include "remoting/base/mock_objects.h"
8 #include "remoting/host/client_connection.h" 8 #include "remoting/host/client_connection.h"
9 #include "remoting/host/mock_objects.h" 9 #include "remoting/host/mock_objects.h"
10 #include "remoting/jingle_glue/mock_objects.h" 10 #include "remoting/jingle_glue/mock_objects.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 12
13 using ::testing::_; 13 using ::testing::_;
14 using ::testing::NotNull; 14 using ::testing::NotNull;
15 using ::testing::StrictMock;
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 class ClientConnectionTest : public testing::Test { 19 class ClientConnectionTest : public testing::Test {
19 public: 20 public:
20 ClientConnectionTest() { 21 ClientConnectionTest() {
21 } 22 }
22 23
23 protected: 24 protected:
24 virtual void SetUp() { 25 virtual void SetUp() {
25 decoder_ = new MockProtocolDecoder(); 26 decoder_ = new MockProtocolDecoder();
26 channel_ = new MockJingleChannel(); 27 channel_ = new StrictMock<MockJingleChannel>();
27 28
28 // Allocate a ClientConnection object with the mock objects. we give the 29 // Allocate a ClientConnection object with the mock objects. we give the
29 // ownership of decoder to the viewer. 30 // ownership of decoder to the viewer.
30 viewer_ = new ClientConnection(&message_loop_, 31 viewer_ = new ClientConnection(&message_loop_,
31 decoder_, 32 decoder_,
32 &handler_); 33 &handler_);
33 34
34 viewer_->set_jingle_channel(channel_.get()); 35 viewer_->set_jingle_channel(channel_.get());
35 } 36 }
36 37
37 MessageLoop message_loop_; 38 MessageLoop message_loop_;
38 MockProtocolDecoder* decoder_; 39 MockProtocolDecoder* decoder_;
39 MockClientConnectionEventHandler handler_; 40 MockClientConnectionEventHandler handler_;
40 scoped_refptr<MockJingleChannel> channel_;
41 scoped_refptr<ClientConnection> viewer_; 41 scoped_refptr<ClientConnection> viewer_;
42 42
43 // |channel_| is wrapped with StrictMock because we limit strictly the calls
44 // to it.
45 scoped_refptr<StrictMock<MockJingleChannel> > channel_;
46
43 private: 47 private:
44 DISALLOW_COPY_AND_ASSIGN(ClientConnectionTest); 48 DISALLOW_COPY_AND_ASSIGN(ClientConnectionTest);
45 }; 49 };
46 50
47 TEST_F(ClientConnectionTest, SendUpdateStream) { 51 TEST_F(ClientConnectionTest, SendUpdateStream) {
48 // Tell the viewer we are starting an update stream. 52 // Tell the viewer we are starting an update stream.
49 EXPECT_CALL(*channel_, Write(_)); 53 EXPECT_CALL(*channel_, Write(_));
50 viewer_->SendBeginUpdateStreamMessage(); 54 viewer_->SendBeginUpdateStreamMessage();
51 55
52 // Then send the actual data. 56 // Then send the actual data.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 92
89 // Give the data to the ClientConnection, it will use ProtocolDecoder to 93 // Give the data to the ClientConnection, it will use ProtocolDecoder to
90 // decode the messages. 94 // decode the messages.
91 EXPECT_CALL(*decoder_, ParseClientMessages(data, NotNull())); 95 EXPECT_CALL(*decoder_, ParseClientMessages(data, NotNull()));
92 EXPECT_CALL(handler_, HandleMessages(viewer_.get(), NotNull())); 96 EXPECT_CALL(handler_, HandleMessages(viewer_.get(), NotNull()));
93 97
94 viewer_->OnPacketReceived(channel_.get(), data); 98 viewer_->OnPacketReceived(channel_.get(), data);
95 message_loop_.RunAllPending(); 99 message_loop_.RunAllPending();
96 } 100 }
97 101
102 // Test that we can close client connection more than once and operations
103 // after the connection is closed has no effect.
104 TEST_F(ClientConnectionTest, Close) {
105 EXPECT_CALL(*channel_, Close());
106 viewer_->Disconnect();
107
108 viewer_->SendBeginUpdateStreamMessage();
109 scoped_ptr<UpdateStreamPacketHeader> header(new UpdateStreamPacketHeader);
110 header->set_x(0);
111 header->set_y(0);
112 header->set_width(640);
113 header->set_height(480);
114
115 scoped_refptr<media::DataBuffer> data = new media::DataBuffer(10);
116 viewer_->SendUpdateStreamPacketMessage(header.get(), data);
117 viewer_->SendEndUpdateStreamMessage();
118 viewer_->Disconnect();
119 }
120
98 } // namespace remoting 121 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_connection.cc ('k') | remoting/host/encoder_verbatim.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698