| Index: remoting/host/security_key/security_key_message_reader_impl_unittest.cc
|
| diff --git a/remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc b/remoting/host/security_key/security_key_message_reader_impl_unittest.cc
|
| similarity index 75%
|
| rename from remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc
|
| rename to remoting/host/security_key/security_key_message_reader_impl_unittest.cc
|
| index c9c2d92ef3f5a9135b9b383f5dfd1a413695b26e..96010844f3719bf6af345d0e346dcbb523c0374b 100644
|
| --- a/remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc
|
| +++ b/remoting/host/security_key/security_key_message_reader_impl_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_reader_impl.h"
|
| +#include "remoting/host/security_key/security_key_message_reader_impl.h"
|
|
|
| #include <cstdint>
|
| #include <memory>
|
| @@ -17,17 +17,17 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
| -const remoting::RemoteSecurityKeyMessageType kTestMessageType =
|
| - remoting::RemoteSecurityKeyMessageType::CONNECT;
|
| +const remoting::SecurityKeyMessageType kTestMessageType =
|
| + remoting::SecurityKeyMessageType::CONNECT;
|
| const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024;
|
| } // namespace
|
|
|
| namespace remoting {
|
|
|
| -class RemoteSecurityKeyMessageReaderImplTest : public testing::Test {
|
| +class SecurityKeyMessageReaderImplTest : public testing::Test {
|
| public:
|
| - RemoteSecurityKeyMessageReaderImplTest();
|
| - ~RemoteSecurityKeyMessageReaderImplTest() override;
|
| + SecurityKeyMessageReaderImplTest();
|
| + ~SecurityKeyMessageReaderImplTest() override;
|
|
|
| // SecurityKeyMessageCallback passed to the Reader. Stores |message| so it can
|
| // be verified by tests.
|
| @@ -48,13 +48,13 @@ class RemoteSecurityKeyMessageReaderImplTest : public testing::Test {
|
| void CloseWriteFileAndRunLoop();
|
|
|
| // Writes a message (header+code+body) to the write-end of the pipe.
|
| - void WriteMessage(RemoteSecurityKeyMessageType message_type,
|
| + void WriteMessage(SecurityKeyMessageType message_type,
|
| const std::string& message_payload);
|
|
|
| // Writes some data to the write-end of the pipe.
|
| void WriteData(const char* data, int length);
|
|
|
| - std::unique_ptr<RemoteSecurityKeyMessageReader> reader_;
|
| + std::unique_ptr<SecurityKeyMessageReader> reader_;
|
| base::File read_file_;
|
| base::File write_file_;
|
|
|
| @@ -64,51 +64,50 @@ class RemoteSecurityKeyMessageReaderImplTest : public testing::Test {
|
| base::MessageLoopForIO message_loop_;
|
| std::unique_ptr<base::RunLoop> run_loop_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageReaderImplTest);
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessageReaderImplTest);
|
| };
|
|
|
| -RemoteSecurityKeyMessageReaderImplTest::RemoteSecurityKeyMessageReaderImplTest()
|
| +SecurityKeyMessageReaderImplTest::SecurityKeyMessageReaderImplTest()
|
| : run_loop_(new base::RunLoop()) {}
|
|
|
| -RemoteSecurityKeyMessageReaderImplTest::
|
| - ~RemoteSecurityKeyMessageReaderImplTest() {}
|
| +SecurityKeyMessageReaderImplTest::~SecurityKeyMessageReaderImplTest() {}
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::SetUp() {
|
| +void SecurityKeyMessageReaderImplTest::SetUp() {
|
| ASSERT_TRUE(MakePipe(&read_file_, &write_file_));
|
| - reader_.reset(new RemoteSecurityKeyMessageReaderImpl(std::move(read_file_)));
|
| + reader_.reset(new SecurityKeyMessageReaderImpl(std::move(read_file_)));
|
|
|
| // base::Unretained is safe since no further tasks can run after
|
| // RunLoop::Run() returns.
|
| reader_->Start(
|
| - base::Bind(&RemoteSecurityKeyMessageReaderImplTest::OnMessage,
|
| + base::Bind(&SecurityKeyMessageReaderImplTest::OnMessage,
|
| base::Unretained(this)),
|
| - base::Bind(&RemoteSecurityKeyMessageReaderImplTest::OperationComplete,
|
| + base::Bind(&SecurityKeyMessageReaderImplTest::OperationComplete,
|
| base::Unretained(this)));
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::RunLoop() {
|
| +void SecurityKeyMessageReaderImplTest::RunLoop() {
|
| run_loop_->Run();
|
| run_loop_.reset(new base::RunLoop());
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::CloseWriteFileAndRunLoop() {
|
| +void SecurityKeyMessageReaderImplTest::CloseWriteFileAndRunLoop() {
|
| write_file_.Close();
|
| run_loop_->Run();
|
| run_loop_.reset(new base::RunLoop());
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::OnMessage(
|
| +void SecurityKeyMessageReaderImplTest::OnMessage(
|
| std::unique_ptr<SecurityKeyMessage> message) {
|
| messages_received_.push_back(std::move(message));
|
| OperationComplete();
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::OperationComplete() {
|
| +void SecurityKeyMessageReaderImplTest::OperationComplete() {
|
| run_loop_->Quit();
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::WriteMessage(
|
| - RemoteSecurityKeyMessageType message_type,
|
| +void SecurityKeyMessageReaderImplTest::WriteMessage(
|
| + SecurityKeyMessageType message_type,
|
| const std::string& message_payload) {
|
| uint32_t length =
|
| SecurityKeyMessage::kMessageTypeSizeBytes + message_payload.size();
|
| @@ -121,13 +120,12 @@ void RemoteSecurityKeyMessageReaderImplTest::WriteMessage(
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageReaderImplTest::WriteData(const char* data,
|
| - int length) {
|
| +void SecurityKeyMessageReaderImplTest::WriteData(const char* data, int length) {
|
| int written = write_file_.WriteAtCurrentPos(data, length);
|
| ASSERT_EQ(length, written);
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithNoPayload) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, SingleMessageWithNoPayload) {
|
| WriteMessage(kTestMessageType, std::string());
|
| RunLoop();
|
| ASSERT_EQ(1u, messages_received_.size());
|
| @@ -137,7 +135,7 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithNoPayload) {
|
| CloseWriteFileAndRunLoop();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithPayload) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, SingleMessageWithPayload) {
|
| std::string payload("I AM A VALID MESSAGE PAYLOAD!!!!!!!!!!!!!!!!!!!!!!");
|
| WriteMessage(kTestMessageType, payload);
|
| RunLoop();
|
| @@ -148,7 +146,7 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithPayload) {
|
| CloseWriteFileAndRunLoop();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaSingleWrite) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, SingleMessageViaSingleWrite) {
|
| // All other tests write in 2-3 chunks, this writes the message in one shot.
|
| std::string payload("LLLLTI am the best payload in the history of testing.");
|
| // Overwite the 'L' values with the actual length.
|
| @@ -168,7 +166,7 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaSingleWrite) {
|
| CloseWriteFileAndRunLoop();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaMultipleWrites) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, SingleMessageViaMultipleWrites) {
|
| // All other tests write in 2-3 chunks, this writes the message byte by byte.
|
| std::string payload("LLLLTI am the worst payload in the history of testing.");
|
| // Overwite the 'L' values with the actual length.
|
| @@ -191,7 +189,7 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageViaMultipleWrites) {
|
| CloseWriteFileAndRunLoop();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) {
|
| std::string payload(kMaxSecurityKeyMessageByteCount -
|
| SecurityKeyMessage::kMessageTypeSizeBytes,
|
| 'Y');
|
| @@ -204,12 +202,12 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, SingleMessageWithLargePayload) {
|
| CloseWriteFileAndRunLoop();
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, EmptyFile) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, EmptyFile) {
|
| CloseWriteFileAndRunLoop();
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, InvalidMessageLength) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, InvalidMessageLength) {
|
| uint32_t length = kMaxSecurityKeyMessageByteCount + 1;
|
| ASSERT_FALSE(SecurityKeyMessage::IsValidMessageSize(length));
|
| WriteData(reinterpret_cast<char*>(&length), sizeof(length));
|
| @@ -217,28 +215,28 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, InvalidMessageLength) {
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, ShortHeader) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, ShortHeader) {
|
| // Write only 3 bytes - the message length header is supposed to be 4 bytes.
|
| WriteData("xxx", SecurityKeyMessage::kHeaderSizeBytes - 1);
|
| CloseWriteFileAndRunLoop();
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, ZeroLengthMessage) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, ZeroLengthMessage) {
|
| uint32_t length = 0;
|
| WriteData(reinterpret_cast<char*>(&length), sizeof(length));
|
| CloseWriteFileAndRunLoop();
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, MissingControlCode) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, MissingControlCode) {
|
| uint32_t length = 1;
|
| WriteData(reinterpret_cast<char*>(&length), sizeof(length));
|
| CloseWriteFileAndRunLoop();
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, MissingPayload) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, MissingPayload) {
|
| uint32_t length = 2;
|
| WriteData(reinterpret_cast<char*>(&length), sizeof(length));
|
|
|
| @@ -248,7 +246,7 @@ TEST_F(RemoteSecurityKeyMessageReaderImplTest, MissingPayload) {
|
| ASSERT_EQ(0u, messages_received_.size());
|
| }
|
|
|
| -TEST_F(RemoteSecurityKeyMessageReaderImplTest, MultipleMessages) {
|
| +TEST_F(SecurityKeyMessageReaderImplTest, MultipleMessages) {
|
| std::vector<std::string> payloads({"", "S", // Really short
|
| "", "Short", "", "Medium Length", "",
|
| "Longer than medium, but not super long",
|
|
|