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

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

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually add braces Created 6 years, 10 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
(Empty)
1 // Copyright 2014 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 "base/test/test_simple_task_runner.h"
6 #include "net/base/net_errors.h"
7 #include "net/socket/socket_test_util.h"
8 #include "remoting/host/gnubby_connection.h"
9 #include "remoting/host/host_mock_objects.h"
10 #include "remoting/protocol/protocol_mock_objects.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace remoting {
14
15 using protocol::MockClientStub;
16
17 using testing::_;
18
19 class GnubbyConnectionTest : public testing::Test {
20 public:
21 GnubbyConnectionTest() {}
22
23 virtual void SetUp() OVERRIDE;
24
25 protected:
26 // Create a mock connected socket.
27 net::MockTCPClientSocket* GetConnectedSocket(
28 net::StaticSocketDataProvider* socket_data);
29
30 // Object under test.
31 scoped_ptr<GnubbyConnection> connection_;
32
33 // Mock gnubby auth handler that receives connection callbacks.
34 scoped_ptr<MockGnubbyAuthHandler> gnubby_auth_handler_;
35
36 // Mock gnubby connection factory for mock gnubby auth handler.
37 scoped_ptr<MockGnubbyConnectionFactory> gnubby_connection_factory_;
38
39 // Mock client stub.
40 MockClientStub client_stub_;
41
42 private:
43 void OnConnect(int result);
44 };
45
46 void GnubbyConnectionTest::SetUp() {
47 gnubby_connection_factory_.reset(new MockGnubbyConnectionFactory());
48 gnubby_auth_handler_.reset(new MockGnubbyAuthHandler(
49 gnubby_connection_factory_.get(), &client_stub_));
50 }
51
52 net::MockTCPClientSocket* GnubbyConnectionTest::GetConnectedSocket(
53 net::StaticSocketDataProvider* socket_data) {
54
55 net::AddressList addresses;
56 socket_data->set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK));
57 net::MockTCPClientSocket* socket =
58 new net::MockTCPClientSocket(addresses, NULL, socket_data);
59
60 int result = socket->Connect(
61 base::Bind(&GnubbyConnectionTest::OnConnect, base::Unretained(this)));
62 EXPECT_EQ(net::OK, result);
63 return socket;
64 }
65
66 void GnubbyConnectionTest::OnConnect(int result) {}
67
68 TEST_F(GnubbyConnectionTest, Read) {
69 EXPECT_CALL(*gnubby_auth_handler_, DeliverHostDataMessage(42, "test_msg"));
70 EXPECT_CALL(*gnubby_auth_handler_, ConnectionClosed(42));
71
72 net::MockRead read(net::SYNCHRONOUS, "test_msg");
73 net::MockRead close(net::SYNCHRONOUS, net::OK, "");
74 net::MockRead* read_and_close[] = {&read, &close};
75
76 net::StaticSocketDataProvider socket_data(
77 read_and_close[0], sizeof(read_and_close), NULL, 0);
78
79 connection_.reset(new GnubbyConnection(gnubby_auth_handler_.get(),
80 42,
81 GetConnectedSocket(&socket_data)));
82 connection_->Read();
83 }
84
85 TEST_F(GnubbyConnectionTest, ReadFailed) {
86 EXPECT_CALL(*gnubby_auth_handler_, ConnectionError(42, net::ERR_FAILED));
87
88 net::MockRead read_fail(net::SYNCHRONOUS, net::ERR_FAILED);
89 net::StaticSocketDataProvider socket_data(&read_fail, 1, NULL, 0);
90
91 connection_.reset(new GnubbyConnection(gnubby_auth_handler_.get(),
92 42,
93 GetConnectedSocket(&socket_data)));
94 connection_->Read();
95 }
96
97 TEST_F(GnubbyConnectionTest, WriteFailed) {
98 EXPECT_CALL(*gnubby_auth_handler_, ConnectionError(42, net::ERR_FAILED));
99
100 net::MockWrite write_fail(net::SYNCHRONOUS, net::ERR_FAILED);
101 net::StaticSocketDataProvider socket_data(NULL, 0, &write_fail, 1);
102
103 connection_.reset(new GnubbyConnection(gnubby_auth_handler_.get(),
104 42,
105 GetConnectedSocket(&socket_data)));
106 connection_->Write("test_msg");
107 }
108
109 TEST_F(GnubbyConnectionTest, Write) {
110 net::MockWrite write(net::SYNCHRONOUS, "test_msg");
111 net::StaticSocketDataProvider socket_data(NULL, 0, &write, 1);
112
113 connection_.reset(new GnubbyConnection(gnubby_auth_handler_.get(),
114 42,
115 GetConnectedSocket(&socket_data)));
116 connection_->Write("test_msg");
117 }
118
119 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698