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

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

Issue 9827006: Refactor VideoStub interface to accept ownership of video packets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 scoped_ptr<ConnectionToClient> viewer_; 56 scoped_ptr<ConnectionToClient> viewer_;
57 57
58 // Owned by |viewer_|. 58 // Owned by |viewer_|.
59 protocol::FakeSession* session_; 59 protocol::FakeSession* session_;
60 60
61 private: 61 private:
62 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); 62 DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest);
63 }; 63 };
64 64
65 TEST_F(ConnectionToClientTest, SendUpdateStream) { 65 TEST_F(ConnectionToClientTest, SendUpdateStream) {
66 // Then send the actual data. 66 scoped_ptr<VideoPacket> packet(new VideoPacket());
67 VideoPacket* packet = new VideoPacket(); 67 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure());
68 viewer_->video_stub()->ProcessVideoPacket(
69 packet, base::Bind(&base::DeletePointer<VideoPacket>, packet));
70 68
71 message_loop_.RunAllPending(); 69 message_loop_.RunAllPending();
72 70
73 // Verify that something has been written. 71 // Verify that something has been written.
74 // TODO(sergeyu): Verify that the correct data has been written. 72 // TODO(sergeyu): Verify that the correct data has been written.
75 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName)); 73 ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName));
76 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)-> 74 EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)->
77 written_data().size(), 0u); 75 written_data().size(), 0u);
78 76
79 // And then close the connection to ConnectionToClient. 77 // And then close the connection to ConnectionToClient.
80 viewer_->Disconnect(); 78 viewer_->Disconnect();
81 79
82 message_loop_.RunAllPending(); 80 message_loop_.RunAllPending();
83 } 81 }
84 82
85 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) { 83 TEST_F(ConnectionToClientTest, NoWriteAfterDisconnect) {
86 // Then send the actual data. 84 scoped_ptr<VideoPacket> packet(new VideoPacket());
87 VideoPacket* packet = new VideoPacket(); 85 viewer_->video_stub()->ProcessVideoPacket(packet.Pass(), base::Closure());
88 viewer_->video_stub()->ProcessVideoPacket(
89 packet, base::Bind(&base::DeletePointer<VideoPacket>, packet));
90 86
91 // And then close the connection to ConnectionToClient. 87 // And then close the connection to ConnectionToClient.
92 viewer_->Disconnect(); 88 viewer_->Disconnect();
93 89
94 // The test will crash if data writer tries to write data to the 90 // The test will crash if data writer tries to write data to the
95 // channel socket. 91 // channel socket.
96 // TODO(sergeyu): Use MockSession to verify that no data is written? 92 // TODO(sergeyu): Use MockSession to verify that no data is written?
97 message_loop_.RunAllPending(); 93 message_loop_.RunAllPending();
98 } 94 }
99 95
100 TEST_F(ConnectionToClientTest, StateChange) { 96 TEST_F(ConnectionToClientTest, StateChange) {
101 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); 97 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get()));
102 session_->state_change_callback().Run(protocol::Session::CLOSED); 98 session_->state_change_callback().Run(protocol::Session::CLOSED);
103 message_loop_.RunAllPending(); 99 message_loop_.RunAllPending();
104 100
105 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get(), SESSION_REJECTED)); 101 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get(), SESSION_REJECTED));
106 session_->set_error(SESSION_REJECTED); 102 session_->set_error(SESSION_REJECTED);
107 session_->state_change_callback().Run(protocol::Session::FAILED); 103 session_->state_change_callback().Run(protocol::Session::FAILED);
108 message_loop_.RunAllPending(); 104 message_loop_.RunAllPending();
109 } 105 }
110 106
111 } // namespace protocol 107 } // namespace protocol
112 } // namespace remoting 108 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698