OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 public: | 50 public: |
51 GnubbyAuthHandlerLinuxTest() | 51 GnubbyAuthHandlerLinuxTest() |
52 : run_loop_(new base::RunLoop()), last_connection_id_received_(-1) { | 52 : run_loop_(new base::RunLoop()), last_connection_id_received_(-1) { |
53 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 53 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
54 socket_path_ = temp_dir_.path().Append(kSocketFilename); | 54 socket_path_ = temp_dir_.path().Append(kSocketFilename); |
55 remoting::GnubbyAuthHandler::SetGnubbySocketName(socket_path_); | 55 remoting::GnubbyAuthHandler::SetGnubbySocketName(socket_path_); |
56 | 56 |
57 send_message_callback_ = | 57 send_message_callback_ = |
58 base::Bind(&GnubbyAuthHandlerLinuxTest::SendMessageToClient, | 58 base::Bind(&GnubbyAuthHandlerLinuxTest::SendMessageToClient, |
59 base::Unretained(this)); | 59 base::Unretained(this)); |
60 auth_handler_ = remoting::GnubbyAuthHandler::Create(send_message_callback_); | 60 session_id_callback_ = base::Bind(&GnubbyAuthHandlerLinuxTest::GetSessionId, |
61 base::Unretained(this)); | |
62 auth_handler_ = remoting::GnubbyAuthHandler::Create(send_message_callback_, | |
63 session_id_callback_); | |
61 } | 64 } |
62 | 65 |
63 void WaitForSendMessageToClient() { | 66 void WaitForSendMessageToClient() { |
64 run_loop_->Run(); | 67 run_loop_->Run(); |
65 run_loop_.reset(new base::RunLoop); | 68 run_loop_.reset(new base::RunLoop); |
66 } | 69 } |
67 | 70 |
68 void SendMessageToClient(int connection_id, const std::string& data) { | 71 void SendMessageToClient(int connection_id, const std::string& data) { |
69 last_connection_id_received_ = connection_id; | 72 last_connection_id_received_ = connection_id; |
70 last_message_received_ = data; | 73 last_message_received_ = data; |
71 run_loop_->Quit(); | 74 run_loop_->Quit(); |
72 } | 75 } |
73 | 76 |
77 uint32_t GetSessionId() const { return UINT32_MAX; } | |
Sergey Ulanov
2016/06/27 23:51:58
can be a static function.
| |
78 | |
74 void CheckHostDataMessage(int id, const std::string& expected_data) { | 79 void CheckHostDataMessage(int id, const std::string& expected_data) { |
75 ASSERT_EQ(id, last_connection_id_received_); | 80 ASSERT_EQ(id, last_connection_id_received_); |
76 ASSERT_EQ(expected_data.length(), last_message_received_.length()); | 81 ASSERT_EQ(expected_data.length(), last_message_received_.length()); |
77 ASSERT_EQ(expected_data, last_message_received_); | 82 ASSERT_EQ(expected_data, last_message_received_); |
78 } | 83 } |
79 | 84 |
80 void WriteRequestData(net::UnixDomainClientSocket* client_socket) { | 85 void WriteRequestData(net::UnixDomainClientSocket* client_socket) { |
81 int request_len = sizeof(kRequestData); | 86 int request_len = sizeof(kRequestData); |
82 scoped_refptr<net::DrainableIOBuffer> request_buffer( | 87 scoped_refptr<net::DrainableIOBuffer> request_buffer( |
83 new net::DrainableIOBuffer( | 88 new net::DrainableIOBuffer( |
(...skipping 29 matching lines...) Expand all Loading... | |
113 } | 118 } |
114 | 119 |
115 protected: | 120 protected: |
116 base::MessageLoopForIO message_loop_; | 121 base::MessageLoopForIO message_loop_; |
117 std::unique_ptr<base::RunLoop> run_loop_; | 122 std::unique_ptr<base::RunLoop> run_loop_; |
118 | 123 |
119 // Object under test. | 124 // Object under test. |
120 std::unique_ptr<GnubbyAuthHandler> auth_handler_; | 125 std::unique_ptr<GnubbyAuthHandler> auth_handler_; |
121 | 126 |
122 GnubbyAuthHandler::SendMessageCallback send_message_callback_; | 127 GnubbyAuthHandler::SendMessageCallback send_message_callback_; |
128 GnubbyAuthHandler::SessionIdCallback session_id_callback_; | |
123 | 129 |
124 int last_connection_id_received_; | 130 int last_connection_id_received_; |
125 std::string last_message_received_; | 131 std::string last_message_received_; |
126 | 132 |
127 base::ScopedTempDir temp_dir_; | 133 base::ScopedTempDir temp_dir_; |
128 base::FilePath socket_path_; | 134 base::FilePath socket_path_; |
129 base::Closure accept_callback_; | 135 base::Closure accept_callback_; |
130 | 136 |
131 private: | 137 private: |
132 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinuxTest); | 138 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinuxTest); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); | 244 net::UnixDomainClientSocket client_socket(socket_path_.value(), false); |
239 net::TestCompletionCallback connect_callback; | 245 net::TestCompletionCallback connect_callback; |
240 int rv = client_socket.Connect(connect_callback.callback()); | 246 int rv = client_socket.Connect(connect_callback.callback()); |
241 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); | 247 ASSERT_EQ(net::OK, connect_callback.GetResult(rv)); |
242 | 248 |
243 auth_handler_->SendErrorAndCloseConnection(1); | 249 auth_handler_->SendErrorAndCloseConnection(1); |
244 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); | 250 ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest()); |
245 } | 251 } |
246 | 252 |
247 } // namespace remoting | 253 } // namespace remoting |
OLD | NEW |