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_reader.h" | 5 #include "remoting/host/native_messaging/native_messaging_reader.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 void SetUp() override; | 23 void SetUp() override; |
24 | 24 |
25 // Starts the reader and runs the MessageLoop to completion. | 25 // Starts the reader and runs the MessageLoop to completion. |
26 void Run(); | 26 void Run(); |
27 | 27 |
28 // MessageCallback passed to the Reader. Stores |message| so it can be | 28 // MessageCallback passed to the Reader. Stores |message| so it can be |
29 // verified by tests. | 29 // verified by tests. |
30 void OnMessage(scoped_ptr<base::Value> message); | 30 void OnMessage(scoped_ptr<base::Value> message); |
31 | 31 |
32 // Writes a message (header+body) to the write-end of the pipe. | 32 // Writes a message (header+body) to the write-end of the pipe. |
33 void WriteMessage(std::string message); | 33 void WriteMessage(const std::string& message); |
34 | 34 |
35 // Writes some data to the write-end of the pipe. | 35 // Writes some data to the write-end of the pipe. |
36 void WriteData(const char* data, int length); | 36 void WriteData(const char* data, int length); |
37 | 37 |
38 protected: | 38 protected: |
39 scoped_ptr<NativeMessagingReader> reader_; | 39 scoped_ptr<NativeMessagingReader> reader_; |
40 base::File read_file_; | 40 base::File read_file_; |
41 base::File write_file_; | 41 base::File write_file_; |
42 scoped_ptr<base::Value> message_; | 42 scoped_ptr<base::Value> message_; |
43 | 43 |
(...skipping 23 matching lines...) Expand all Loading... |
67 reader_->Start( | 67 reader_->Start( |
68 base::Bind(&NativeMessagingReaderTest::OnMessage, base::Unretained(this)), | 68 base::Bind(&NativeMessagingReaderTest::OnMessage, base::Unretained(this)), |
69 run_loop_.QuitClosure()); | 69 run_loop_.QuitClosure()); |
70 run_loop_.Run(); | 70 run_loop_.Run(); |
71 } | 71 } |
72 | 72 |
73 void NativeMessagingReaderTest::OnMessage(scoped_ptr<base::Value> message) { | 73 void NativeMessagingReaderTest::OnMessage(scoped_ptr<base::Value> message) { |
74 message_ = message.Pass(); | 74 message_ = message.Pass(); |
75 } | 75 } |
76 | 76 |
77 void NativeMessagingReaderTest::WriteMessage(std::string message) { | 77 void NativeMessagingReaderTest::WriteMessage(const std::string& message) { |
78 uint32 length = message.length(); | 78 uint32 length = message.length(); |
79 WriteData(reinterpret_cast<char*>(&length), 4); | 79 WriteData(reinterpret_cast<char*>(&length), 4); |
80 WriteData(message.data(), length); | 80 WriteData(message.data(), length); |
81 } | 81 } |
82 | 82 |
83 void NativeMessagingReaderTest::WriteData(const char* data, int length) { | 83 void NativeMessagingReaderTest::WriteData(const char* data, int length) { |
84 int written = write_file_.WriteAtCurrentPos(data, length); | 84 int written = write_file_.WriteAtCurrentPos(data, length); |
85 ASSERT_EQ(length, written); | 85 ASSERT_EQ(length, written); |
86 } | 86 } |
87 | 87 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 Run(); | 145 Run(); |
146 EXPECT_TRUE(message_); | 146 EXPECT_TRUE(message_); |
147 base::DictionaryValue* message_dict; | 147 base::DictionaryValue* message_dict; |
148 EXPECT_TRUE(message_->GetAsDictionary(&message_dict)); | 148 EXPECT_TRUE(message_->GetAsDictionary(&message_dict)); |
149 int result; | 149 int result; |
150 EXPECT_TRUE(message_dict->GetInteger("foo", &result)); | 150 EXPECT_TRUE(message_dict->GetInteger("foo", &result)); |
151 EXPECT_EQ(42, result); | 151 EXPECT_EQ(42, result); |
152 } | 152 } |
153 | 153 |
154 } // namespace remoting | 154 } // namespace remoting |
OLD | NEW |