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

Side by Side Diff: remoting/host/native_messaging/native_messaging_reader_unittest.cc

Issue 1549493004: Use std::move() instead of .Pass() in remoting/host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass
Patch Set: include <utility> Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/native_messaging/native_messaging_reader.h" 5 #include "remoting/host/native_messaging/native_messaging_reader.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility>
10
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 14 #include "base/run_loop.h"
13 #include "base/values.h" 15 #include "base/values.h"
14 #include "remoting/host/setup/test_util.h" 16 #include "remoting/host/setup/test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace remoting { 19 namespace remoting {
18 20
(...skipping 23 matching lines...) Expand all
42 base::File write_file_; 44 base::File write_file_;
43 scoped_ptr<base::Value> message_; 45 scoped_ptr<base::Value> message_;
44 46
45 private: 47 private:
46 // MessageLoop declared here, since the NativeMessageReader ctor requires a 48 // MessageLoop declared here, since the NativeMessageReader ctor requires a
47 // MessageLoop to have been created. 49 // MessageLoop to have been created.
48 base::MessageLoopForIO message_loop_; 50 base::MessageLoopForIO message_loop_;
49 base::RunLoop run_loop_; 51 base::RunLoop run_loop_;
50 }; 52 };
51 53
52 NativeMessagingReaderTest::NativeMessagingReaderTest() { 54 NativeMessagingReaderTest::NativeMessagingReaderTest() {}
53 }
54
55 NativeMessagingReaderTest::~NativeMessagingReaderTest() {} 55 NativeMessagingReaderTest::~NativeMessagingReaderTest() {}
56 56
57 void NativeMessagingReaderTest::SetUp() { 57 void NativeMessagingReaderTest::SetUp() {
58 ASSERT_TRUE(MakePipe(&read_file_, &write_file_)); 58 ASSERT_TRUE(MakePipe(&read_file_, &write_file_));
59 reader_.reset(new NativeMessagingReader(read_file_.Pass())); 59 reader_.reset(new NativeMessagingReader(std::move(read_file_)));
60 } 60 }
61 61
62 void NativeMessagingReaderTest::Run() { 62 void NativeMessagingReaderTest::Run() {
63 // Close the write-end, so the reader doesn't block waiting for more data. 63 // Close the write-end, so the reader doesn't block waiting for more data.
64 write_file_.Close(); 64 write_file_.Close();
65 65
66 // base::Unretained is safe since no further tasks can run after 66 // base::Unretained is safe since no further tasks can run after
67 // RunLoop::Run() returns. 67 // RunLoop::Run() returns.
68 reader_->Start( 68 reader_->Start(
69 base::Bind(&NativeMessagingReaderTest::OnMessage, base::Unretained(this)), 69 base::Bind(&NativeMessagingReaderTest::OnMessage, base::Unretained(this)),
70 run_loop_.QuitClosure()); 70 run_loop_.QuitClosure());
71 run_loop_.Run(); 71 run_loop_.Run();
72 } 72 }
73 73
74 void NativeMessagingReaderTest::OnMessage(scoped_ptr<base::Value> message) { 74 void NativeMessagingReaderTest::OnMessage(scoped_ptr<base::Value> message) {
75 message_ = message.Pass(); 75 message_ = std::move(message);
76 } 76 }
77 77
78 void NativeMessagingReaderTest::WriteMessage(const std::string& message) { 78 void NativeMessagingReaderTest::WriteMessage(const std::string& message) {
79 uint32_t length = message.length(); 79 uint32_t length = message.length();
80 WriteData(reinterpret_cast<char*>(&length), 4); 80 WriteData(reinterpret_cast<char*>(&length), 4);
81 WriteData(message.data(), length); 81 WriteData(message.data(), length);
82 } 82 }
83 83
84 void NativeMessagingReaderTest::WriteData(const char* data, int length) { 84 void NativeMessagingReaderTest::WriteData(const char* data, int length) {
85 int written = write_file_.WriteAtCurrentPos(data, length); 85 int written = write_file_.WriteAtCurrentPos(data, length);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 Run(); 146 Run();
147 EXPECT_TRUE(message_); 147 EXPECT_TRUE(message_);
148 base::DictionaryValue* message_dict; 148 base::DictionaryValue* message_dict;
149 EXPECT_TRUE(message_->GetAsDictionary(&message_dict)); 149 EXPECT_TRUE(message_->GetAsDictionary(&message_dict));
150 int result; 150 int result;
151 EXPECT_TRUE(message_dict->GetInteger("foo", &result)); 151 EXPECT_TRUE(message_dict->GetInteger("foo", &result));
152 EXPECT_EQ(42, result); 152 EXPECT_EQ(42, result);
153 } 153 }
154 154
155 } // namespace remoting 155 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/native_messaging/native_messaging_reader.cc ('k') | remoting/host/native_messaging/native_messaging_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698