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

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

Issue 580243003: Cleanup Fake* classes in remoting/protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sctp
Patch Set: Created 6 years, 2 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
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/socket/socket.h" 15 #include "net/socket/socket.h"
16 #include "remoting/protocol/fake_session.h" 16 #include "remoting/protocol/fake_stream_socket.h"
17 #include "remoting/protocol/message_reader.h" 17 #include "remoting/protocol/message_reader.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/webrtc/base/byteorder.h" 20 #include "third_party/webrtc/base/byteorder.h"
21 21
22 using testing::_; 22 using testing::_;
23 using testing::DoAll; 23 using testing::DoAll;
24 using testing::Mock; 24 using testing::Mock;
25 using testing::SaveArg; 25 using testing::SaveArg;
26 26
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 void InitReader() { 78 void InitReader() {
79 reader_->Init(&socket_, base::Bind( 79 reader_->Init(&socket_, base::Bind(
80 &MessageReaderTest::OnMessage, base::Unretained(this))); 80 &MessageReaderTest::OnMessage, base::Unretained(this)));
81 } 81 }
82 82
83 void AddMessage(const std::string& message) { 83 void AddMessage(const std::string& message) {
84 std::string data = std::string(4, ' ') + message; 84 std::string data = std::string(4, ' ') + message;
85 rtc::SetBE32(const_cast<char*>(data.data()), message.size()); 85 rtc::SetBE32(const_cast<char*>(data.data()), message.size());
86 86
87 socket_.AppendInputData(std::vector<char>(data.begin(), data.end())); 87 socket_.AppendInputData(data);
88 } 88 }
89 89
90 bool CompareResult(CompoundBuffer* buffer, const std::string& expected) { 90 bool CompareResult(CompoundBuffer* buffer, const std::string& expected) {
91 std::string result(buffer->total_bytes(), ' '); 91 std::string result(buffer->total_bytes(), ' ');
92 buffer->CopyTo(const_cast<char*>(result.data()), result.size()); 92 buffer->CopyTo(const_cast<char*>(result.data()), result.size());
93 return result == expected; 93 return result == expected;
94 } 94 }
95 95
96 void OnMessage(scoped_ptr<CompoundBuffer> buffer, 96 void OnMessage(scoped_ptr<CompoundBuffer> buffer,
97 const base::Closure& done_callback) { 97 const base::Closure& done_callback) {
98 messages_.push_back(buffer.release()); 98 messages_.push_back(buffer.release());
99 callback_.OnMessage(done_callback); 99 callback_.OnMessage(done_callback);
100 } 100 }
101 101
102 base::MessageLoop message_loop_; 102 base::MessageLoop message_loop_;
103 scoped_ptr<MessageReader> reader_; 103 scoped_ptr<MessageReader> reader_;
104 FakeSocket socket_; 104 FakeStreamSocket socket_;
105 MockMessageReceivedCallback callback_; 105 MockMessageReceivedCallback callback_;
106 std::vector<CompoundBuffer*> messages_; 106 std::vector<CompoundBuffer*> messages_;
107 bool in_callback_; 107 bool in_callback_;
108 }; 108 };
109 109
110 // Receive one message and process it with delay 110 // Receive one message and process it with delay
111 TEST_F(MessageReaderTest, OneMessage_Delay) { 111 TEST_F(MessageReaderTest, OneMessage_Delay) {
112 base::Closure done_task; 112 base::Closure done_task;
113 113
114 AddMessage(kTestMessage1); 114 AddMessage(kTestMessage1);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 EXPECT_CALL(callback_, OnMessage(_)) 318 EXPECT_CALL(callback_, OnMessage(_))
319 .Times(1) 319 .Times(1)
320 .WillOnce(Invoke(this, &MessageReaderTest::DeleteReader)); 320 .WillOnce(Invoke(this, &MessageReaderTest::DeleteReader));
321 321
322 InitReader(); 322 InitReader();
323 base::RunLoop().RunUntilIdle(); 323 base::RunLoop().RunUntilIdle();
324 } 324 }
325 325
326 } // namespace protocol 326 } // namespace protocol
327 } // namespace remoting 327 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/fake_stream_socket.cc ('k') | remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698