OLD | NEW |
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_writer.h" | 5 #include "remoting/host/native_messaging/native_messaging_writer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
| 9 #include <utility> |
| 10 |
9 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
12 #include "base/values.h" | 14 #include "base/values.h" |
13 #include "remoting/host/setup/test_util.h" | 15 #include "remoting/host/setup/test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace remoting { | 18 namespace remoting { |
17 | 19 |
18 class NativeMessagingWriterTest : public testing::Test { | 20 class NativeMessagingWriterTest : public testing::Test { |
19 public: | 21 public: |
20 NativeMessagingWriterTest(); | 22 NativeMessagingWriterTest(); |
21 ~NativeMessagingWriterTest() override; | 23 ~NativeMessagingWriterTest() override; |
22 | 24 |
23 void SetUp() override; | 25 void SetUp() override; |
24 | 26 |
25 protected: | 27 protected: |
26 scoped_ptr<NativeMessagingWriter> writer_; | 28 scoped_ptr<NativeMessagingWriter> writer_; |
27 base::File read_file_; | 29 base::File read_file_; |
28 base::File write_file_; | 30 base::File write_file_; |
29 }; | 31 }; |
30 | 32 |
31 NativeMessagingWriterTest::NativeMessagingWriterTest() {} | 33 NativeMessagingWriterTest::NativeMessagingWriterTest() {} |
32 | |
33 NativeMessagingWriterTest::~NativeMessagingWriterTest() {} | 34 NativeMessagingWriterTest::~NativeMessagingWriterTest() {} |
34 | 35 |
35 void NativeMessagingWriterTest::SetUp() { | 36 void NativeMessagingWriterTest::SetUp() { |
36 ASSERT_TRUE(MakePipe(&read_file_, &write_file_)); | 37 ASSERT_TRUE(MakePipe(&read_file_, &write_file_)); |
37 writer_.reset(new NativeMessagingWriter(write_file_.Pass())); | 38 writer_.reset(new NativeMessagingWriter(std::move(write_file_))); |
38 } | 39 } |
39 | 40 |
40 TEST_F(NativeMessagingWriterTest, GoodMessage) { | 41 TEST_F(NativeMessagingWriterTest, GoodMessage) { |
41 base::DictionaryValue message; | 42 base::DictionaryValue message; |
42 message.SetInteger("foo", 42); | 43 message.SetInteger("foo", 42); |
43 EXPECT_TRUE(writer_->WriteMessage(message)); | 44 EXPECT_TRUE(writer_->WriteMessage(message)); |
44 | 45 |
45 // Read from the pipe and verify the content. | 46 // Read from the pipe and verify the content. |
46 uint32_t length; | 47 uint32_t length; |
47 int read = read_file_.ReadAtCurrentPos(reinterpret_cast<char*>(&length), 4); | 48 int read = read_file_.ReadAtCurrentPos(reinterpret_cast<char*>(&length), 4); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 90 |
90 TEST_F(NativeMessagingWriterTest, FailedWrite) { | 91 TEST_F(NativeMessagingWriterTest, FailedWrite) { |
91 // Close the read end so that writing fails immediately. | 92 // Close the read end so that writing fails immediately. |
92 read_file_.Close(); | 93 read_file_.Close(); |
93 | 94 |
94 base::DictionaryValue message; | 95 base::DictionaryValue message; |
95 EXPECT_FALSE(writer_->WriteMessage(message)); | 96 EXPECT_FALSE(writer_->WriteMessage(message)); |
96 } | 97 } |
97 | 98 |
98 } // namespace remoting | 99 } // namespace remoting |
OLD | NEW |