| Index: remoting/host/security_key/security_key_message_handler_unittest.cc
|
| diff --git a/remoting/host/security_key/remote_security_key_message_handler_unittest.cc b/remoting/host/security_key/security_key_message_handler_unittest.cc
|
| similarity index 58%
|
| rename from remoting/host/security_key/remote_security_key_message_handler_unittest.cc
|
| rename to remoting/host/security_key/security_key_message_handler_unittest.cc
|
| index 22b1ba85cf2c3b4aea0d23b92e12cffa37777b9f..e120fb61d97ae83018f5efae1bee81a933d4ce4b 100644
|
| --- a/remoting/host/security_key/remote_security_key_message_handler_unittest.cc
|
| +++ b/remoting/host/security_key/security_key_message_handler_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "remoting/host/security_key/remote_security_key_message_handler.h"
|
| +#include "remoting/host/security_key/security_key_message_handler.h"
|
|
|
| #include <memory>
|
| #include <string>
|
| @@ -12,20 +12,20 @@
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| -#include "remoting/host/security_key/fake_remote_security_key_ipc_client.h"
|
| -#include "remoting/host/security_key/fake_remote_security_key_message_reader.h"
|
| -#include "remoting/host/security_key/fake_remote_security_key_message_writer.h"
|
| -#include "remoting/host/security_key/remote_security_key_ipc_constants.h"
|
| +#include "remoting/host/security_key/fake_security_key_ipc_client.h"
|
| +#include "remoting/host/security_key/fake_security_key_message_reader.h"
|
| +#include "remoting/host/security_key/fake_security_key_message_writer.h"
|
| +#include "remoting/host/security_key/security_key_ipc_constants.h"
|
| #include "remoting/host/security_key/security_key_message.h"
|
| #include "remoting/host/setup/test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace remoting {
|
|
|
| -class RemoteSecurityKeyMessageHandlerTest : public testing::Test {
|
| +class SecurityKeyMessageHandlerTest : public testing::Test {
|
| public:
|
| - RemoteSecurityKeyMessageHandlerTest();
|
| - ~RemoteSecurityKeyMessageHandlerTest() override;
|
| + SecurityKeyMessageHandlerTest();
|
| + ~SecurityKeyMessageHandlerTest() override;
|
|
|
| // Passed to the object used for testing to be called back to signal
|
| // completion of an action.
|
| @@ -39,74 +39,74 @@ class RemoteSecurityKeyMessageHandlerTest : public testing::Test {
|
| void WaitForOperationComplete();
|
|
|
| // Passed to |message_channel_| and called back when a message is received.
|
| - void OnSecurityKeyMessage(RemoteSecurityKeyMessageType message_type,
|
| + void OnSecurityKeyMessage(SecurityKeyMessageType message_type,
|
| const std::string& message_payload);
|
|
|
| bool last_operation_failed_ = false;
|
| - RemoteSecurityKeyMessageType last_message_type_received_ =
|
| - RemoteSecurityKeyMessageType::INVALID;
|
| + SecurityKeyMessageType last_message_type_received_ =
|
| + SecurityKeyMessageType::INVALID;
|
| std::string last_message_payload_received_;
|
|
|
| - base::WeakPtr<FakeRemoteSecurityKeyIpcClient> ipc_client_weak_ptr_;
|
| - base::WeakPtr<FakeRemoteSecurityKeyMessageReader> reader_weak_ptr_;
|
| - base::WeakPtr<FakeRemoteSecurityKeyMessageWriter> writer_weak_ptr_;
|
| - std::unique_ptr<RemoteSecurityKeyMessageHandler> message_handler_;
|
| + base::WeakPtr<FakeSecurityKeyIpcClient> ipc_client_weak_ptr_;
|
| + base::WeakPtr<FakeSecurityKeyMessageReader> reader_weak_ptr_;
|
| + base::WeakPtr<FakeSecurityKeyMessageWriter> writer_weak_ptr_;
|
| + std::unique_ptr<SecurityKeyMessageHandler> message_handler_;
|
|
|
| private:
|
| base::MessageLoopForIO message_loop_;
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageHandlerTest);
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessageHandlerTest);
|
| };
|
|
|
| -RemoteSecurityKeyMessageHandlerTest::RemoteSecurityKeyMessageHandlerTest() {}
|
| +SecurityKeyMessageHandlerTest::SecurityKeyMessageHandlerTest() {}
|
|
|
| -RemoteSecurityKeyMessageHandlerTest::~RemoteSecurityKeyMessageHandlerTest() {}
|
| +SecurityKeyMessageHandlerTest::~SecurityKeyMessageHandlerTest() {}
|
|
|
| -void RemoteSecurityKeyMessageHandlerTest::OperationComplete() {
|
| +void SecurityKeyMessageHandlerTest::OperationComplete() {
|
| run_loop_->Quit();
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandlerTest::SetUp() {
|
| +void SecurityKeyMessageHandlerTest::SetUp() {
|
| run_loop_.reset(new base::RunLoop());
|
| - message_handler_.reset(new RemoteSecurityKeyMessageHandler());
|
| + message_handler_.reset(new SecurityKeyMessageHandler());
|
|
|
| - std::unique_ptr<FakeRemoteSecurityKeyIpcClient> ipc_client(
|
| - new FakeRemoteSecurityKeyIpcClient(
|
| - base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete,
|
| + std::unique_ptr<FakeSecurityKeyIpcClient> ipc_client(
|
| + new FakeSecurityKeyIpcClient(
|
| + base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete,
|
| base::Unretained(this))));
|
| ipc_client_weak_ptr_ = ipc_client->AsWeakPtr();
|
|
|
| - std::unique_ptr<FakeRemoteSecurityKeyMessageReader> reader(
|
| - new FakeRemoteSecurityKeyMessageReader());
|
| + std::unique_ptr<FakeSecurityKeyMessageReader> reader(
|
| + new FakeSecurityKeyMessageReader());
|
| reader_weak_ptr_ = reader->AsWeakPtr();
|
|
|
| - std::unique_ptr<FakeRemoteSecurityKeyMessageWriter> writer(
|
| - new FakeRemoteSecurityKeyMessageWriter(
|
| - base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete,
|
| + std::unique_ptr<FakeSecurityKeyMessageWriter> writer(
|
| + new FakeSecurityKeyMessageWriter(
|
| + base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete,
|
| base::Unretained(this))));
|
| writer_weak_ptr_ = writer->AsWeakPtr();
|
|
|
| - message_handler_->SetRemoteSecurityKeyMessageReaderForTest(std::move(reader));
|
| + message_handler_->SetSecurityKeyMessageReaderForTest(std::move(reader));
|
|
|
| - message_handler_->SetRemoteSecurityKeyMessageWriterForTest(std::move(writer));
|
| + message_handler_->SetSecurityKeyMessageWriterForTest(std::move(writer));
|
|
|
| base::File read_file;
|
| base::File write_file;
|
| ASSERT_TRUE(MakePipe(&read_file, &write_file));
|
| message_handler_->Start(
|
| std::move(read_file), std::move(write_file), std::move(ipc_client),
|
| - base::Bind(&RemoteSecurityKeyMessageHandlerTest::OperationComplete,
|
| + base::Bind(&SecurityKeyMessageHandlerTest::OperationComplete,
|
| base::Unretained(this)));
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandlerTest::WaitForOperationComplete() {
|
| +void SecurityKeyMessageHandlerTest::WaitForOperationComplete() {
|
| run_loop_->Run();
|
| run_loop_.reset(new base::RunLoop());
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandlerTest::OnSecurityKeyMessage(
|
| - RemoteSecurityKeyMessageType message_type,
|
| +void SecurityKeyMessageHandlerTest::OnSecurityKeyMessage(
|
| + SecurityKeyMessageType message_type,
|
| const std::string& message_payload) {
|
| last_message_type_received_ = message_type;
|
| last_message_payload_received_ = message_payload;
|
| @@ -114,31 +114,31 @@ void RemoteSecurityKeyMessageHandlerTest::OnSecurityKeyMessage(
|
| OperationComplete();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessConnectMessage_SessionExists_ConnectionAttemptSuccess) {
|
| ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true);
|
| ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::CONNECT, std::string()));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT,
|
| + std::string()));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_RESPONSE,
|
| + ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_EQ(std::string(1, kConnectResponseActiveSession),
|
| writer_weak_ptr_->last_message_payload());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessConnectMessage_SessionExists_WriteFails) {
|
| ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true);
|
| ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(true);
|
| writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::CONNECT, std::string()));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT,
|
| + std::string()));
|
| WaitForOperationComplete();
|
|
|
| ASSERT_FALSE(ipc_client_weak_ptr_.get());
|
| @@ -146,53 +146,51 @@ TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| ASSERT_FALSE(writer_weak_ptr_.get());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessConnectMessage_SessionExists_ConnectionAttemptFailure) {
|
| ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true);
|
| ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::CONNECT, std::string()));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT,
|
| + std::string()));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| - ProcessConnectMessage_NoSessionExists) {
|
| +TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_NoSessionExists) {
|
| ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(false);
|
| ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::CONNECT, std::string()));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT,
|
| + std::string()));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_RESPONSE,
|
| + ASSERT_EQ(SecurityKeyMessageType::CONNECT_RESPONSE,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_EQ(std::string(1, kConnectResponseNoSession),
|
| writer_weak_ptr_->last_message_payload());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| - ProcessConnectMessage_IncorrectPayload) {
|
| +TEST_F(SecurityKeyMessageHandlerTest, ProcessConnectMessage_IncorrectPayload) {
|
| ipc_client_weak_ptr_->set_wait_for_ipc_channel_return_value(true);
|
| ipc_client_weak_ptr_->set_establish_ipc_connection_should_succeed(false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::CONNECT, "Invalid request payload"));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::CONNECT,
|
| + "Invalid request payload"));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::CONNECT_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::CONNECT_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessRequestMessage_ValidPayload_IpcSendSuccess) {
|
| std::string request_payload("I AM A VALID REQUEST PAYLOAD!");
|
| std::string response_payload("I AM A VALID RESPONSE PAYLOAD!");
|
| @@ -200,16 +198,16 @@ TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| ipc_client_weak_ptr_->set_security_key_response_payload(response_payload);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, request_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + request_payload));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_RESPONSE,
|
| + ASSERT_EQ(SecurityKeyMessageType::REQUEST_RESPONSE,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_EQ(response_payload, writer_weak_ptr_->last_message_payload());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) {
|
| +TEST_F(SecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) {
|
| std::string request_payload("I AM A VALID REQUEST PAYLOAD!");
|
| std::string response_payload("I AM A VALID RESPONSE PAYLOAD!");
|
|
|
| @@ -218,8 +216,8 @@ TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) {
|
| writer_weak_ptr_->set_write_request_succeeded(/*should_succeed=*/false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, request_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + request_payload));
|
| WaitForOperationComplete();
|
|
|
| ASSERT_FALSE(ipc_client_weak_ptr_.get());
|
| @@ -227,22 +225,22 @@ TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessRequestMessage_WriteFails) {
|
| ASSERT_FALSE(writer_weak_ptr_.get());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessRequestMessage_ValidPayload_IpcSendFailure) {
|
| std::string request_payload("I AM A VALID REQUEST PAYLOAD!");
|
| ipc_client_weak_ptr_->set_send_security_request_should_succeed(false);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, request_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + request_payload));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessRequestMessage_ValidPayload_EmptyClientResponse) {
|
| std::string request_payload("I AM A VALID REQUEST PAYLOAD!");
|
| std::string response_payload("");
|
| @@ -250,52 +248,51 @@ TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| ipc_client_weak_ptr_->set_security_key_response_payload(response_payload);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, request_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + request_payload));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| +TEST_F(SecurityKeyMessageHandlerTest,
|
| ProcessRequestMessage_ValidPayload_ClientResponseError) {
|
| std::string request_payload("I AM A VALID REQUEST PAYLOAD!");
|
| - std::string response_payload(kRemoteSecurityKeyConnectionError);
|
| + std::string response_payload(kSecurityKeyConnectionError);
|
| ipc_client_weak_ptr_->set_send_security_request_should_succeed(true);
|
| ipc_client_weak_ptr_->set_security_key_response_payload(response_payload);
|
|
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, request_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + request_payload));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest,
|
| - ProcessRequestMessage_InvalidPayload) {
|
| +TEST_F(SecurityKeyMessageHandlerTest, ProcessRequestMessage_InvalidPayload) {
|
| std::string invalid_payload("");
|
| reader_weak_ptr_->message_callback().Run(
|
| - SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::REQUEST, invalid_payload));
|
| + SecurityKeyMessage::CreateMessageForTest(SecurityKeyMessageType::REQUEST,
|
| + invalid_payload));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + ASSERT_EQ(SecurityKeyMessageType::REQUEST_ERROR,
|
| writer_weak_ptr_->last_message_type());
|
| ASSERT_FALSE(writer_weak_ptr_->last_message_payload().empty());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageHandlerTest, ProcessUnknownMessage) {
|
| +TEST_F(SecurityKeyMessageHandlerTest, ProcessUnknownMessage) {
|
| reader_weak_ptr_->message_callback().Run(
|
| SecurityKeyMessage::CreateMessageForTest(
|
| - RemoteSecurityKeyMessageType::UNKNOWN_ERROR, std::string()));
|
| + SecurityKeyMessageType::UNKNOWN_ERROR, std::string()));
|
| WaitForOperationComplete();
|
|
|
| - ASSERT_EQ(RemoteSecurityKeyMessageType::UNKNOWN_COMMAND,
|
| + ASSERT_EQ(SecurityKeyMessageType::UNKNOWN_COMMAND,
|
| writer_weak_ptr_->last_message_type());
|
| }
|
|
|
|
|