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

Side by Side Diff: remoting/host/security_key/remote_security_key_message_reader_impl_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 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 "remoting/host/security_key/remote_security_key_message_reader.h" 5 #include "remoting/host/security_key/remote_security_key_message_reader_impl.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "remoting/host/security_key/remote_security_key_message_reader_impl.h"
16 #include "remoting/host/security_key/security_key_message.h" 15 #include "remoting/host/security_key/security_key_message.h"
17 #include "remoting/host/setup/test_util.h" 16 #include "remoting/host/setup/test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace { 19 namespace {
21 const remoting::RemoteSecurityKeyMessageType kTestMessageType = 20 const remoting::RemoteSecurityKeyMessageType kTestMessageType =
22 remoting::RemoteSecurityKeyMessageType::CONNECT; 21 remoting::RemoteSecurityKeyMessageType::CONNECT;
23 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; 22 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024;
24 } // namespace 23 } // namespace
25 24
26 namespace remoting { 25 namespace remoting {
27 26
28 class RemoteSecurityKeyMessageReaderImplTest : public testing::Test { 27 class RemoteSecurityKeyMessageReaderImplTest : public testing::Test {
29 public: 28 public:
30 RemoteSecurityKeyMessageReaderImplTest(); 29 RemoteSecurityKeyMessageReaderImplTest();
31 ~RemoteSecurityKeyMessageReaderImplTest() override; 30 ~RemoteSecurityKeyMessageReaderImplTest() override;
32 31
33 // SecurityKeyMessageCallback passed to the Reader. Stores |message| so it can 32 // SecurityKeyMessageCallback passed to the Reader. Stores |message| so it can
34 // be verified by tests. 33 // be verified by tests.
35 void OnMessage(scoped_ptr<SecurityKeyMessage> message); 34 void OnMessage(std::unique_ptr<SecurityKeyMessage> message);
36 35
37 // Used as a callback to signal completion. 36 // Used as a callback to signal completion.
38 void OperationComplete(); 37 void OperationComplete();
39 38
40 protected: 39 protected:
41 // testing::Test interface. 40 // testing::Test interface.
42 void SetUp() override; 41 void SetUp() override;
43 42
44 // Runs the MessageLoop until the reader has completed and called back. 43 // Runs the MessageLoop until the reader has completed and called back.
45 void RunLoop(); 44 void RunLoop();
46 45
47 // Closes |write_file_| and runs the MessageLoop until the reader has 46 // Closes |write_file_| and runs the MessageLoop until the reader has
48 // completed and called back. 47 // completed and called back.
49 void CloseWriteFileAndRunLoop(); 48 void CloseWriteFileAndRunLoop();
50 49
51 // Writes a message (header+code+body) to the write-end of the pipe. 50 // Writes a message (header+code+body) to the write-end of the pipe.
52 void WriteMessage(RemoteSecurityKeyMessageType message_type, 51 void WriteMessage(RemoteSecurityKeyMessageType message_type,
53 const std::string& message_payload); 52 const std::string& message_payload);
54 53
55 // Writes some data to the write-end of the pipe. 54 // Writes some data to the write-end of the pipe.
56 void WriteData(const char* data, int length); 55 void WriteData(const char* data, int length);
57 56
58 scoped_ptr<RemoteSecurityKeyMessageReader> reader_; 57 std::unique_ptr<RemoteSecurityKeyMessageReader> reader_;
59 base::File read_file_; 58 base::File read_file_;
60 base::File write_file_; 59 base::File write_file_;
61 60
62 std::vector<scoped_ptr<SecurityKeyMessage>> messages_received_; 61 std::vector<std::unique_ptr<SecurityKeyMessage>> messages_received_;
63 62
64 private: 63 private:
65 base::MessageLoopForIO message_loop_; 64 base::MessageLoopForIO message_loop_;
66 scoped_ptr<base::RunLoop> run_loop_; 65 std::unique_ptr<base::RunLoop> run_loop_;
67 66
68 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageReaderImplTest); 67 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageReaderImplTest);
69 }; 68 };
70 69
71 RemoteSecurityKeyMessageReaderImplTest::RemoteSecurityKeyMessageReaderImplTest() 70 RemoteSecurityKeyMessageReaderImplTest::RemoteSecurityKeyMessageReaderImplTest()
72 : run_loop_(new base::RunLoop()) {} 71 : run_loop_(new base::RunLoop()) {}
73 72
74 RemoteSecurityKeyMessageReaderImplTest:: 73 RemoteSecurityKeyMessageReaderImplTest::
75 ~RemoteSecurityKeyMessageReaderImplTest() {} 74 ~RemoteSecurityKeyMessageReaderImplTest() {}
76 75
(...skipping 15 matching lines...) Expand all
92 run_loop_.reset(new base::RunLoop()); 91 run_loop_.reset(new base::RunLoop());
93 } 92 }
94 93
95 void RemoteSecurityKeyMessageReaderImplTest::CloseWriteFileAndRunLoop() { 94 void RemoteSecurityKeyMessageReaderImplTest::CloseWriteFileAndRunLoop() {
96 write_file_.Close(); 95 write_file_.Close();
97 run_loop_->Run(); 96 run_loop_->Run();
98 run_loop_.reset(new base::RunLoop()); 97 run_loop_.reset(new base::RunLoop());
99 } 98 }
100 99
101 void RemoteSecurityKeyMessageReaderImplTest::OnMessage( 100 void RemoteSecurityKeyMessageReaderImplTest::OnMessage(
102 scoped_ptr<SecurityKeyMessage> message) { 101 std::unique_ptr<SecurityKeyMessage> message) {
103 messages_received_.push_back(std::move(message)); 102 messages_received_.push_back(std::move(message));
104 OperationComplete(); 103 OperationComplete();
105 } 104 }
106 105
107 void RemoteSecurityKeyMessageReaderImplTest::OperationComplete() { 106 void RemoteSecurityKeyMessageReaderImplTest::OperationComplete() {
108 run_loop_->Quit(); 107 run_loop_->Quit();
109 } 108 }
110 109
111 void RemoteSecurityKeyMessageReaderImplTest::WriteMessage( 110 void RemoteSecurityKeyMessageReaderImplTest::WriteMessage(
112 RemoteSecurityKeyMessageType message_type, 111 RemoteSecurityKeyMessageType message_type,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ASSERT_EQ(payloads.size(), messages_received_.size()); 219 ASSERT_EQ(payloads.size(), messages_received_.size());
221 CloseWriteFileAndRunLoop(); 220 CloseWriteFileAndRunLoop();
222 221
223 for (size_t i = 0; i < payloads.size(); i++) { 222 for (size_t i = 0; i < payloads.size(); i++) {
224 ASSERT_EQ(kTestMessageType, messages_received_[i]->type()); 223 ASSERT_EQ(kTestMessageType, messages_received_[i]->type());
225 ASSERT_EQ(payloads[i], messages_received_[i]->payload()); 224 ASSERT_EQ(payloads[i], messages_received_[i]->payload());
226 } 225 }
227 } 226 }
228 227
229 } // namespace remoting 228 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698