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

Side by Side Diff: remoting/host/setup/me2me_native_messaging_host_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 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/setup/me2me_native_messaging_host.h" 5 #include "remoting/host/setup/me2me_native_messaging_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/strings/stringize_macros.h" 20 #include "base/strings/stringize_macros.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "google_apis/gaia/gaia_oauth_client.h" 22 #include "google_apis/gaia/gaia_oauth_client.h"
22 #include "net/base/file_stream.h" 23 #include "net/base/file_stream.h"
23 #include "net/base/network_interfaces.h" 24 #include "net/base/network_interfaces.h"
24 #include "remoting/base/auto_thread_task_runner.h" 25 #include "remoting/base/auto_thread_task_runner.h"
25 #include "remoting/host/native_messaging/log_message_handler.h" 26 #include "remoting/host/native_messaging/log_message_handler.h"
26 #include "remoting/host/native_messaging/pipe_messaging_channel.h" 27 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
27 #include "remoting/host/pin_hash.h" 28 #include "remoting/host/pin_hash.h"
28 #include "remoting/host/setup/mock_oauth_client.h" 29 #include "remoting/host/setup/mock_oauth_client.h"
29 #include "remoting/host/setup/test_util.h" 30 #include "remoting/host/setup/test_util.h"
30 #include "remoting/protocol/pairing_registry.h" 31 #include "remoting/protocol/pairing_registry.h"
31 #include "remoting/protocol/protocol_mock_objects.h" 32 #include "remoting/protocol/protocol_mock_objects.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 using remoting::protocol::MockPairingRegistryDelegate; 35 using remoting::protocol::MockPairingRegistryDelegate;
35 using remoting::protocol::PairingRegistry; 36 using remoting::protocol::PairingRegistry;
36 using remoting::protocol::SynchronousPairingRegistry; 37 using remoting::protocol::SynchronousPairingRegistry;
37 38
38 namespace { 39 namespace {
39 40
40 void VerifyHelloResponse(scoped_ptr<base::DictionaryValue> response) { 41 void VerifyHelloResponse(std::unique_ptr<base::DictionaryValue> response) {
41 ASSERT_TRUE(response); 42 ASSERT_TRUE(response);
42 std::string value; 43 std::string value;
43 EXPECT_TRUE(response->GetString("type", &value)); 44 EXPECT_TRUE(response->GetString("type", &value));
44 EXPECT_EQ("helloResponse", value); 45 EXPECT_EQ("helloResponse", value);
45 EXPECT_TRUE(response->GetString("version", &value)); 46 EXPECT_TRUE(response->GetString("version", &value));
46 47
47 // The check below will compile but fail if VERSION isn't defined (STRINGIZE 48 // The check below will compile but fail if VERSION isn't defined (STRINGIZE
48 // silently converts undefined values). 49 // silently converts undefined values).
49 #ifndef VERSION 50 #ifndef VERSION
50 #error VERSION must be defined 51 #error VERSION must be defined
51 #endif 52 #endif
52 EXPECT_EQ(STRINGIZE(VERSION), value); 53 EXPECT_EQ(STRINGIZE(VERSION), value);
53 } 54 }
54 55
55 void VerifyGetHostNameResponse(scoped_ptr<base::DictionaryValue> response) { 56 void VerifyGetHostNameResponse(
57 std::unique_ptr<base::DictionaryValue> response) {
56 ASSERT_TRUE(response); 58 ASSERT_TRUE(response);
57 std::string value; 59 std::string value;
58 EXPECT_TRUE(response->GetString("type", &value)); 60 EXPECT_TRUE(response->GetString("type", &value));
59 EXPECT_EQ("getHostNameResponse", value); 61 EXPECT_EQ("getHostNameResponse", value);
60 EXPECT_TRUE(response->GetString("hostname", &value)); 62 EXPECT_TRUE(response->GetString("hostname", &value));
61 EXPECT_EQ(net::GetHostName(), value); 63 EXPECT_EQ(net::GetHostName(), value);
62 } 64 }
63 65
64 void VerifyGetPinHashResponse(scoped_ptr<base::DictionaryValue> response) { 66 void VerifyGetPinHashResponse(std::unique_ptr<base::DictionaryValue> response) {
65 ASSERT_TRUE(response); 67 ASSERT_TRUE(response);
66 std::string value; 68 std::string value;
67 EXPECT_TRUE(response->GetString("type", &value)); 69 EXPECT_TRUE(response->GetString("type", &value));
68 EXPECT_EQ("getPinHashResponse", value); 70 EXPECT_EQ("getPinHashResponse", value);
69 EXPECT_TRUE(response->GetString("hash", &value)); 71 EXPECT_TRUE(response->GetString("hash", &value));
70 EXPECT_EQ(remoting::MakeHostPinHash("my_host", "1234"), value); 72 EXPECT_EQ(remoting::MakeHostPinHash("my_host", "1234"), value);
71 } 73 }
72 74
73 void VerifyGenerateKeyPairResponse(scoped_ptr<base::DictionaryValue> response) { 75 void VerifyGenerateKeyPairResponse(
76 std::unique_ptr<base::DictionaryValue> response) {
74 ASSERT_TRUE(response); 77 ASSERT_TRUE(response);
75 std::string value; 78 std::string value;
76 EXPECT_TRUE(response->GetString("type", &value)); 79 EXPECT_TRUE(response->GetString("type", &value));
77 EXPECT_EQ("generateKeyPairResponse", value); 80 EXPECT_EQ("generateKeyPairResponse", value);
78 EXPECT_TRUE(response->GetString("privateKey", &value)); 81 EXPECT_TRUE(response->GetString("privateKey", &value));
79 EXPECT_TRUE(response->GetString("publicKey", &value)); 82 EXPECT_TRUE(response->GetString("publicKey", &value));
80 } 83 }
81 84
82 void VerifyGetDaemonConfigResponse(scoped_ptr<base::DictionaryValue> response) { 85 void VerifyGetDaemonConfigResponse(
86 std::unique_ptr<base::DictionaryValue> response) {
83 ASSERT_TRUE(response); 87 ASSERT_TRUE(response);
84 std::string value; 88 std::string value;
85 EXPECT_TRUE(response->GetString("type", &value)); 89 EXPECT_TRUE(response->GetString("type", &value));
86 EXPECT_EQ("getDaemonConfigResponse", value); 90 EXPECT_EQ("getDaemonConfigResponse", value);
87 const base::DictionaryValue* config = nullptr; 91 const base::DictionaryValue* config = nullptr;
88 EXPECT_TRUE(response->GetDictionary("config", &config)); 92 EXPECT_TRUE(response->GetDictionary("config", &config));
89 EXPECT_TRUE(base::DictionaryValue().Equals(config)); 93 EXPECT_TRUE(base::DictionaryValue().Equals(config));
90 } 94 }
91 95
92 void VerifyGetUsageStatsConsentResponse( 96 void VerifyGetUsageStatsConsentResponse(
93 scoped_ptr<base::DictionaryValue> response) { 97 std::unique_ptr<base::DictionaryValue> response) {
94 ASSERT_TRUE(response); 98 ASSERT_TRUE(response);
95 std::string value; 99 std::string value;
96 EXPECT_TRUE(response->GetString("type", &value)); 100 EXPECT_TRUE(response->GetString("type", &value));
97 EXPECT_EQ("getUsageStatsConsentResponse", value); 101 EXPECT_EQ("getUsageStatsConsentResponse", value);
98 bool supported, allowed, set_by_policy; 102 bool supported, allowed, set_by_policy;
99 EXPECT_TRUE(response->GetBoolean("supported", &supported)); 103 EXPECT_TRUE(response->GetBoolean("supported", &supported));
100 EXPECT_TRUE(response->GetBoolean("allowed", &allowed)); 104 EXPECT_TRUE(response->GetBoolean("allowed", &allowed));
101 EXPECT_TRUE(response->GetBoolean("setByPolicy", &set_by_policy)); 105 EXPECT_TRUE(response->GetBoolean("setByPolicy", &set_by_policy));
102 EXPECT_TRUE(supported); 106 EXPECT_TRUE(supported);
103 EXPECT_TRUE(allowed); 107 EXPECT_TRUE(allowed);
104 EXPECT_TRUE(set_by_policy); 108 EXPECT_TRUE(set_by_policy);
105 } 109 }
106 110
107 void VerifyStopDaemonResponse(scoped_ptr<base::DictionaryValue> response) { 111 void VerifyStopDaemonResponse(std::unique_ptr<base::DictionaryValue> response) {
108 ASSERT_TRUE(response); 112 ASSERT_TRUE(response);
109 std::string value; 113 std::string value;
110 EXPECT_TRUE(response->GetString("type", &value)); 114 EXPECT_TRUE(response->GetString("type", &value));
111 EXPECT_EQ("stopDaemonResponse", value); 115 EXPECT_EQ("stopDaemonResponse", value);
112 EXPECT_TRUE(response->GetString("result", &value)); 116 EXPECT_TRUE(response->GetString("result", &value));
113 EXPECT_EQ("OK", value); 117 EXPECT_EQ("OK", value);
114 } 118 }
115 119
116 void VerifyGetDaemonStateResponse(scoped_ptr<base::DictionaryValue> response) { 120 void VerifyGetDaemonStateResponse(
121 std::unique_ptr<base::DictionaryValue> response) {
117 ASSERT_TRUE(response); 122 ASSERT_TRUE(response);
118 std::string value; 123 std::string value;
119 EXPECT_TRUE(response->GetString("type", &value)); 124 EXPECT_TRUE(response->GetString("type", &value));
120 EXPECT_EQ("getDaemonStateResponse", value); 125 EXPECT_EQ("getDaemonStateResponse", value);
121 EXPECT_TRUE(response->GetString("state", &value)); 126 EXPECT_TRUE(response->GetString("state", &value));
122 EXPECT_EQ("STARTED", value); 127 EXPECT_EQ("STARTED", value);
123 } 128 }
124 129
125 void VerifyUpdateDaemonConfigResponse( 130 void VerifyUpdateDaemonConfigResponse(
126 scoped_ptr<base::DictionaryValue> response) { 131 std::unique_ptr<base::DictionaryValue> response) {
127 ASSERT_TRUE(response); 132 ASSERT_TRUE(response);
128 std::string value; 133 std::string value;
129 EXPECT_TRUE(response->GetString("type", &value)); 134 EXPECT_TRUE(response->GetString("type", &value));
130 EXPECT_EQ("updateDaemonConfigResponse", value); 135 EXPECT_EQ("updateDaemonConfigResponse", value);
131 EXPECT_TRUE(response->GetString("result", &value)); 136 EXPECT_TRUE(response->GetString("result", &value));
132 EXPECT_EQ("OK", value); 137 EXPECT_EQ("OK", value);
133 } 138 }
134 139
135 void VerifyStartDaemonResponse(scoped_ptr<base::DictionaryValue> response) { 140 void VerifyStartDaemonResponse(
141 std::unique_ptr<base::DictionaryValue> response) {
136 ASSERT_TRUE(response); 142 ASSERT_TRUE(response);
137 std::string value; 143 std::string value;
138 EXPECT_TRUE(response->GetString("type", &value)); 144 EXPECT_TRUE(response->GetString("type", &value));
139 EXPECT_EQ("startDaemonResponse", value); 145 EXPECT_EQ("startDaemonResponse", value);
140 EXPECT_TRUE(response->GetString("result", &value)); 146 EXPECT_TRUE(response->GetString("result", &value));
141 EXPECT_EQ("OK", value); 147 EXPECT_EQ("OK", value);
142 } 148 }
143 149
144 void VerifyGetCredentialsFromAuthCodeResponse( 150 void VerifyGetCredentialsFromAuthCodeResponse(
145 scoped_ptr<base::DictionaryValue> response) { 151 std::unique_ptr<base::DictionaryValue> response) {
146 ASSERT_TRUE(response); 152 ASSERT_TRUE(response);
147 std::string value; 153 std::string value;
148 EXPECT_TRUE(response->GetString("type", &value)); 154 EXPECT_TRUE(response->GetString("type", &value));
149 EXPECT_EQ("getCredentialsFromAuthCodeResponse", value); 155 EXPECT_EQ("getCredentialsFromAuthCodeResponse", value);
150 EXPECT_TRUE(response->GetString("userEmail", &value)); 156 EXPECT_TRUE(response->GetString("userEmail", &value));
151 EXPECT_EQ("fake_user_email", value); 157 EXPECT_EQ("fake_user_email", value);
152 EXPECT_TRUE(response->GetString("refreshToken", &value)); 158 EXPECT_TRUE(response->GetString("refreshToken", &value));
153 EXPECT_EQ("fake_refresh_token", value); 159 EXPECT_EQ("fake_refresh_token", value);
154 } 160 }
155 161
156 } // namespace 162 } // namespace
157 163
158 namespace remoting { 164 namespace remoting {
159 165
160 class MockDaemonControllerDelegate : public DaemonController::Delegate { 166 class MockDaemonControllerDelegate : public DaemonController::Delegate {
161 public: 167 public:
162 MockDaemonControllerDelegate(); 168 MockDaemonControllerDelegate();
163 ~MockDaemonControllerDelegate() override; 169 ~MockDaemonControllerDelegate() override;
164 170
165 // DaemonController::Delegate interface. 171 // DaemonController::Delegate interface.
166 DaemonController::State GetState() override; 172 DaemonController::State GetState() override;
167 scoped_ptr<base::DictionaryValue> GetConfig() override; 173 std::unique_ptr<base::DictionaryValue> GetConfig() override;
168 void SetConfigAndStart( 174 void SetConfigAndStart(
169 scoped_ptr<base::DictionaryValue> config, 175 std::unique_ptr<base::DictionaryValue> config,
170 bool consent, 176 bool consent,
171 const DaemonController::CompletionCallback& done) override; 177 const DaemonController::CompletionCallback& done) override;
172 void UpdateConfig(scoped_ptr<base::DictionaryValue> config, 178 void UpdateConfig(std::unique_ptr<base::DictionaryValue> config,
173 const DaemonController::CompletionCallback& done) override; 179 const DaemonController::CompletionCallback& done) override;
174 void Stop(const DaemonController::CompletionCallback& done) override; 180 void Stop(const DaemonController::CompletionCallback& done) override;
175 DaemonController::UsageStatsConsent GetUsageStatsConsent() override; 181 DaemonController::UsageStatsConsent GetUsageStatsConsent() override;
176 182
177 private: 183 private:
178 DISALLOW_COPY_AND_ASSIGN(MockDaemonControllerDelegate); 184 DISALLOW_COPY_AND_ASSIGN(MockDaemonControllerDelegate);
179 }; 185 };
180 186
181 MockDaemonControllerDelegate::MockDaemonControllerDelegate() {} 187 MockDaemonControllerDelegate::MockDaemonControllerDelegate() {}
182 188
183 MockDaemonControllerDelegate::~MockDaemonControllerDelegate() {} 189 MockDaemonControllerDelegate::~MockDaemonControllerDelegate() {}
184 190
185 DaemonController::State MockDaemonControllerDelegate::GetState() { 191 DaemonController::State MockDaemonControllerDelegate::GetState() {
186 return DaemonController::STATE_STARTED; 192 return DaemonController::STATE_STARTED;
187 } 193 }
188 194
189 scoped_ptr<base::DictionaryValue> MockDaemonControllerDelegate::GetConfig() { 195 std::unique_ptr<base::DictionaryValue>
190 return make_scoped_ptr(new base::DictionaryValue()); 196 MockDaemonControllerDelegate::GetConfig() {
197 return base::WrapUnique(new base::DictionaryValue());
191 } 198 }
192 199
193 void MockDaemonControllerDelegate::SetConfigAndStart( 200 void MockDaemonControllerDelegate::SetConfigAndStart(
194 scoped_ptr<base::DictionaryValue> config, 201 std::unique_ptr<base::DictionaryValue> config,
195 bool consent, 202 bool consent,
196 const DaemonController::CompletionCallback& done) { 203 const DaemonController::CompletionCallback& done) {
197
198 // Verify parameters passed in. 204 // Verify parameters passed in.
199 if (consent && config && config->HasKey("start")) { 205 if (consent && config && config->HasKey("start")) {
200 done.Run(DaemonController::RESULT_OK); 206 done.Run(DaemonController::RESULT_OK);
201 } else { 207 } else {
202 done.Run(DaemonController::RESULT_FAILED); 208 done.Run(DaemonController::RESULT_FAILED);
203 } 209 }
204 } 210 }
205 211
206 void MockDaemonControllerDelegate::UpdateConfig( 212 void MockDaemonControllerDelegate::UpdateConfig(
207 scoped_ptr<base::DictionaryValue> config, 213 std::unique_ptr<base::DictionaryValue> config,
208 const DaemonController::CompletionCallback& done) { 214 const DaemonController::CompletionCallback& done) {
209 if (config && config->HasKey("update")) { 215 if (config && config->HasKey("update")) {
210 done.Run(DaemonController::RESULT_OK); 216 done.Run(DaemonController::RESULT_OK);
211 } else { 217 } else {
212 done.Run(DaemonController::RESULT_FAILED); 218 done.Run(DaemonController::RESULT_FAILED);
213 } 219 }
214 } 220 }
215 221
216 void MockDaemonControllerDelegate::Stop( 222 void MockDaemonControllerDelegate::Stop(
217 const DaemonController::CompletionCallback& done) { 223 const DaemonController::CompletionCallback& done) {
(...skipping 10 matching lines...) Expand all
228 } 234 }
229 235
230 class Me2MeNativeMessagingHostTest : public testing::Test { 236 class Me2MeNativeMessagingHostTest : public testing::Test {
231 public: 237 public:
232 Me2MeNativeMessagingHostTest(); 238 Me2MeNativeMessagingHostTest();
233 ~Me2MeNativeMessagingHostTest() override; 239 ~Me2MeNativeMessagingHostTest() override;
234 240
235 void SetUp() override; 241 void SetUp() override;
236 void TearDown() override; 242 void TearDown() override;
237 243
238 scoped_ptr<base::DictionaryValue> ReadMessageFromOutputPipe(); 244 std::unique_ptr<base::DictionaryValue> ReadMessageFromOutputPipe();
239 245
240 void WriteMessageToInputPipe(const base::Value& message); 246 void WriteMessageToInputPipe(const base::Value& message);
241 247
242 // The Host process should shut down when it receives a malformed request. 248 // The Host process should shut down when it receives a malformed request.
243 // This is tested by sending a known-good request, followed by |message|, 249 // This is tested by sending a known-good request, followed by |message|,
244 // followed by the known-good request again. The response file should only 250 // followed by the known-good request again. The response file should only
245 // contain a single response from the first good request. 251 // contain a single response from the first good request.
246 void TestBadRequest(const base::Value& message); 252 void TestBadRequest(const base::Value& message);
247 253
248 protected: 254 protected:
249 // Reference to the MockDaemonControllerDelegate, which is owned by 255 // Reference to the MockDaemonControllerDelegate, which is owned by
250 // |channel_|. 256 // |channel_|.
251 MockDaemonControllerDelegate* daemon_controller_delegate_; 257 MockDaemonControllerDelegate* daemon_controller_delegate_;
252 258
253 private: 259 private:
254 void StartHost(); 260 void StartHost();
255 void StopHost(); 261 void StopHost();
256 void ExitTest(); 262 void ExitTest();
257 263
258 // Each test creates two unidirectional pipes: "input" and "output". 264 // Each test creates two unidirectional pipes: "input" and "output".
259 // Me2MeNativeMessagingHost reads from input_read_handle and writes to 265 // Me2MeNativeMessagingHost reads from input_read_handle and writes to
260 // output_write_file. The unittest supplies data to input_write_handle, and 266 // output_write_file. The unittest supplies data to input_write_handle, and
261 // verifies output from output_read_handle. 267 // verifies output from output_read_handle.
262 // 268 //
263 // unittest -> [input] -> Me2MeNativeMessagingHost -> [output] -> unittest 269 // unittest -> [input] -> Me2MeNativeMessagingHost -> [output] -> unittest
264 base::File input_write_file_; 270 base::File input_write_file_;
265 base::File output_read_file_; 271 base::File output_read_file_;
266 272
267 // Message loop of the test thread. 273 // Message loop of the test thread.
268 scoped_ptr<base::MessageLoop> test_message_loop_; 274 std::unique_ptr<base::MessageLoop> test_message_loop_;
269 scoped_ptr<base::RunLoop> test_run_loop_; 275 std::unique_ptr<base::RunLoop> test_run_loop_;
270 276
271 scoped_ptr<base::Thread> host_thread_; 277 std::unique_ptr<base::Thread> host_thread_;
272 scoped_ptr<base::RunLoop> host_run_loop_; 278 std::unique_ptr<base::RunLoop> host_run_loop_;
273 279
274 // Task runner of the host thread. 280 // Task runner of the host thread.
275 scoped_refptr<AutoThreadTaskRunner> host_task_runner_; 281 scoped_refptr<AutoThreadTaskRunner> host_task_runner_;
276 scoped_ptr<remoting::Me2MeNativeMessagingHost> host_; 282 std::unique_ptr<remoting::Me2MeNativeMessagingHost> host_;
277 283
278 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHostTest); 284 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHostTest);
279 }; 285 };
280 286
281 Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() {} 287 Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() {}
282 288
283 Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() {} 289 Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() {}
284 290
285 void Me2MeNativeMessagingHostTest::SetUp() { 291 void Me2MeNativeMessagingHostTest::SetUp() {
286 base::File input_read_file; 292 base::File input_read_file;
(...skipping 28 matching lines...) Expand all
315 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); 321 DCHECK(host_task_runner_->RunsTasksOnCurrentThread());
316 322
317 base::File input_read_file; 323 base::File input_read_file;
318 base::File output_write_file; 324 base::File output_write_file;
319 325
320 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_)); 326 ASSERT_TRUE(MakePipe(&input_read_file, &input_write_file_));
321 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file)); 327 ASSERT_TRUE(MakePipe(&output_read_file_, &output_write_file));
322 328
323 daemon_controller_delegate_ = new MockDaemonControllerDelegate(); 329 daemon_controller_delegate_ = new MockDaemonControllerDelegate();
324 scoped_refptr<DaemonController> daemon_controller( 330 scoped_refptr<DaemonController> daemon_controller(
325 new DaemonController(make_scoped_ptr(daemon_controller_delegate_))); 331 new DaemonController(base::WrapUnique(daemon_controller_delegate_)));
326 332
327 scoped_refptr<PairingRegistry> pairing_registry = 333 scoped_refptr<PairingRegistry> pairing_registry =
328 new SynchronousPairingRegistry( 334 new SynchronousPairingRegistry(
329 make_scoped_ptr(new MockPairingRegistryDelegate())); 335 base::WrapUnique(new MockPairingRegistryDelegate()));
330 336
331 scoped_ptr<extensions::NativeMessagingChannel> channel( 337 std::unique_ptr<extensions::NativeMessagingChannel> channel(
332 new PipeMessagingChannel(std::move(input_read_file), 338 new PipeMessagingChannel(std::move(input_read_file),
333 std::move(output_write_file))); 339 std::move(output_write_file)));
334 340
335 scoped_ptr<OAuthClient> oauth_client( 341 std::unique_ptr<OAuthClient> oauth_client(
336 new MockOAuthClient("fake_user_email", "fake_refresh_token")); 342 new MockOAuthClient("fake_user_email", "fake_refresh_token"));
337 343
338 host_.reset(new Me2MeNativeMessagingHost(false, 0, std::move(channel), 344 host_.reset(new Me2MeNativeMessagingHost(false, 0, std::move(channel),
339 daemon_controller, pairing_registry, 345 daemon_controller, pairing_registry,
340 std::move(oauth_client))); 346 std::move(oauth_client)));
341 host_->Start(base::Bind(&Me2MeNativeMessagingHostTest::StopHost, 347 host_->Start(base::Bind(&Me2MeNativeMessagingHostTest::StopHost,
342 base::Unretained(this))); 348 base::Unretained(this)));
343 349
344 // Notify the test that the host has finished starting up. 350 // Notify the test that the host has finished starting up.
345 test_message_loop_->task_runner()->PostTask( 351 test_message_loop_->task_runner()->PostTask(
(...skipping 26 matching lines...) Expand all
372 void Me2MeNativeMessagingHostTest::TearDown() { 378 void Me2MeNativeMessagingHostTest::TearDown() {
373 // Closing the write-end of the input will send an EOF to the native 379 // Closing the write-end of the input will send an EOF to the native
374 // messaging reader. This will trigger a host shutdown. 380 // messaging reader. This will trigger a host shutdown.
375 input_write_file_.Close(); 381 input_write_file_.Close();
376 382
377 // Start a new RunLoop and Wait until the host finishes shutting down. 383 // Start a new RunLoop and Wait until the host finishes shutting down.
378 test_run_loop_.reset(new base::RunLoop()); 384 test_run_loop_.reset(new base::RunLoop());
379 test_run_loop_->Run(); 385 test_run_loop_->Run();
380 386
381 // Verify there are no more message in the output pipe. 387 // Verify there are no more message in the output pipe.
382 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 388 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
383 EXPECT_FALSE(response); 389 EXPECT_FALSE(response);
384 390
385 // The It2MeMe2MeNativeMessagingHost dtor closes the handles that are passed 391 // The It2MeMe2MeNativeMessagingHost dtor closes the handles that are passed
386 // to it. So the only handle left to close is |output_read_file_|. 392 // to it. So the only handle left to close is |output_read_file_|.
387 output_read_file_.Close(); 393 output_read_file_.Close();
388 } 394 }
389 395
390 scoped_ptr<base::DictionaryValue> 396 std::unique_ptr<base::DictionaryValue>
391 Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() { 397 Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() {
392 while (true) { 398 while (true) {
393 uint32_t length; 399 uint32_t length;
394 int read_result = output_read_file_.ReadAtCurrentPos( 400 int read_result = output_read_file_.ReadAtCurrentPos(
395 reinterpret_cast<char*>(&length), sizeof(length)); 401 reinterpret_cast<char*>(&length), sizeof(length));
396 if (read_result != sizeof(length)) { 402 if (read_result != sizeof(length)) {
397 return nullptr; 403 return nullptr;
398 } 404 }
399 405
400 std::string message_json(length, '\0'); 406 std::string message_json(length, '\0');
401 read_result = output_read_file_.ReadAtCurrentPos( 407 read_result = output_read_file_.ReadAtCurrentPos(
402 string_as_array(&message_json), length); 408 string_as_array(&message_json), length);
403 if (read_result != static_cast<int>(length)) { 409 if (read_result != static_cast<int>(length)) {
404 return nullptr; 410 return nullptr;
405 } 411 }
406 412
407 scoped_ptr<base::Value> message = base::JSONReader::Read(message_json); 413 std::unique_ptr<base::Value> message = base::JSONReader::Read(message_json);
408 if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) { 414 if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) {
409 return nullptr; 415 return nullptr;
410 } 416 }
411 417
412 scoped_ptr<base::DictionaryValue> result = make_scoped_ptr( 418 std::unique_ptr<base::DictionaryValue> result = base::WrapUnique(
413 static_cast<base::DictionaryValue*>(message.release())); 419 static_cast<base::DictionaryValue*>(message.release()));
414 std::string type; 420 std::string type;
415 // If this is a debug message log, ignore it, otherwise return it. 421 // If this is a debug message log, ignore it, otherwise return it.
416 if (!result->GetString("type", &type) || 422 if (!result->GetString("type", &type) ||
417 type != LogMessageHandler::kDebugMessageTypeName) { 423 type != LogMessageHandler::kDebugMessageTypeName) {
418 return result; 424 return result;
419 } 425 }
420 } 426 }
421 } 427 }
422 428
(...skipping 12 matching lines...) Expand all
435 base::DictionaryValue good_message; 441 base::DictionaryValue good_message;
436 good_message.SetString("type", "hello"); 442 good_message.SetString("type", "hello");
437 443
438 // This test currently relies on synchronous processing of hello messages and 444 // This test currently relies on synchronous processing of hello messages and
439 // message parameters verification. 445 // message parameters verification.
440 WriteMessageToInputPipe(good_message); 446 WriteMessageToInputPipe(good_message);
441 WriteMessageToInputPipe(message); 447 WriteMessageToInputPipe(message);
442 WriteMessageToInputPipe(good_message); 448 WriteMessageToInputPipe(good_message);
443 449
444 // Read from output pipe, and verify responses. 450 // Read from output pipe, and verify responses.
445 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 451 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
446 VerifyHelloResponse(std::move(response)); 452 VerifyHelloResponse(std::move(response));
447 453
448 response = ReadMessageFromOutputPipe(); 454 response = ReadMessageFromOutputPipe();
449 EXPECT_FALSE(response); 455 EXPECT_FALSE(response);
450 } 456 }
451 457
452 // TODO (weitaosu): crbug.com/323306. Re-enable these tests. 458 // TODO (weitaosu): crbug.com/323306. Re-enable these tests.
453 // Test all valid request-types. 459 // Test all valid request-types.
454 TEST_F(Me2MeNativeMessagingHostTest, All) { 460 TEST_F(Me2MeNativeMessagingHostTest, All) {
455 int next_id = 0; 461 int next_id = 0;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 message.SetBoolean("consent", true); 509 message.SetBoolean("consent", true);
504 message.SetInteger("id", next_id++); 510 message.SetInteger("id", next_id++);
505 message.SetString("type", "startDaemon"); 511 message.SetString("type", "startDaemon");
506 WriteMessageToInputPipe(message); 512 WriteMessageToInputPipe(message);
507 513
508 message.SetInteger("id", next_id++); 514 message.SetInteger("id", next_id++);
509 message.SetString("type", "getCredentialsFromAuthCode"); 515 message.SetString("type", "getCredentialsFromAuthCode");
510 message.SetString("authorizationCode", "fake_auth_code"); 516 message.SetString("authorizationCode", "fake_auth_code");
511 WriteMessageToInputPipe(message); 517 WriteMessageToInputPipe(message);
512 518
513 void (*verify_routines[])(scoped_ptr<base::DictionaryValue>) = { 519 void (*verify_routines[])(std::unique_ptr<base::DictionaryValue>) = {
514 &VerifyHelloResponse, 520 &VerifyHelloResponse,
515 &VerifyGetHostNameResponse, 521 &VerifyGetHostNameResponse,
516 &VerifyGetPinHashResponse, 522 &VerifyGetPinHashResponse,
517 &VerifyGenerateKeyPairResponse, 523 &VerifyGenerateKeyPairResponse,
518 &VerifyGetDaemonConfigResponse, 524 &VerifyGetDaemonConfigResponse,
519 &VerifyGetUsageStatsConsentResponse, 525 &VerifyGetUsageStatsConsentResponse,
520 &VerifyStopDaemonResponse, 526 &VerifyStopDaemonResponse,
521 &VerifyGetDaemonStateResponse, 527 &VerifyGetDaemonStateResponse,
522 &VerifyUpdateDaemonConfigResponse, 528 &VerifyUpdateDaemonConfigResponse,
523 &VerifyStartDaemonResponse, 529 &VerifyStartDaemonResponse,
524 &VerifyGetCredentialsFromAuthCodeResponse, 530 &VerifyGetCredentialsFromAuthCodeResponse,
525 }; 531 };
526 ASSERT_EQ(arraysize(verify_routines), static_cast<size_t>(next_id)); 532 ASSERT_EQ(arraysize(verify_routines), static_cast<size_t>(next_id));
527 533
528 // Read all responses from output pipe, and verify them. 534 // Read all responses from output pipe, and verify them.
529 for (int i = 0; i < next_id; ++i) { 535 for (int i = 0; i < next_id; ++i) {
530 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 536 std::unique_ptr<base::DictionaryValue> response =
537 ReadMessageFromOutputPipe();
531 538
532 // Make sure that id is available and is in the range. 539 // Make sure that id is available and is in the range.
533 int id; 540 int id;
534 ASSERT_TRUE(response->GetInteger("id", &id)); 541 ASSERT_TRUE(response->GetInteger("id", &id));
535 ASSERT_TRUE(0 <= id && id < next_id); 542 ASSERT_TRUE(0 <= id && id < next_id);
536 543
537 // Call the verification routine corresponding to the message id. 544 // Call the verification routine corresponding to the message id.
538 ASSERT_TRUE(verify_routines[id]); 545 ASSERT_TRUE(verify_routines[id]);
539 verify_routines[id](std::move(response)); 546 verify_routines[id](std::move(response));
540 547
541 // Clear the pointer so that the routine cannot be called the second time. 548 // Clear the pointer so that the routine cannot be called the second time.
542 verify_routines[id] = nullptr; 549 verify_routines[id] = nullptr;
543 } 550 }
544 } 551 }
545 552
546 // Verify that response ID matches request ID. 553 // Verify that response ID matches request ID.
547 TEST_F(Me2MeNativeMessagingHostTest, Id) { 554 TEST_F(Me2MeNativeMessagingHostTest, Id) {
548 base::DictionaryValue message; 555 base::DictionaryValue message;
549 message.SetString("type", "hello"); 556 message.SetString("type", "hello");
550 WriteMessageToInputPipe(message); 557 WriteMessageToInputPipe(message);
551 message.SetString("id", "42"); 558 message.SetString("id", "42");
552 WriteMessageToInputPipe(message); 559 WriteMessageToInputPipe(message);
553 560
554 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 561 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
555 EXPECT_TRUE(response); 562 EXPECT_TRUE(response);
556 std::string value; 563 std::string value;
557 EXPECT_FALSE(response->GetString("id", &value)); 564 EXPECT_FALSE(response->GetString("id", &value));
558 565
559 response = ReadMessageFromOutputPipe(); 566 response = ReadMessageFromOutputPipe();
560 EXPECT_TRUE(response); 567 EXPECT_TRUE(response);
561 EXPECT_TRUE(response->GetString("id", &value)); 568 EXPECT_TRUE(response->GetString("id", &value));
562 EXPECT_EQ("42", value); 569 EXPECT_EQ("42", value);
563 } 570 }
564 571
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 630 }
624 631
625 // Verify rejection if getCredentialsFromAuthCode has no auth code. 632 // Verify rejection if getCredentialsFromAuthCode has no auth code.
626 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) { 633 TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) {
627 base::DictionaryValue message; 634 base::DictionaryValue message;
628 message.SetString("type", "getCredentialsFromAuthCode"); 635 message.SetString("type", "getCredentialsFromAuthCode");
629 TestBadRequest(message); 636 TestBadRequest(message);
630 } 637 }
631 638
632 } // namespace remoting 639 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/me2me_native_messaging_host_main.cc ('k') | remoting/host/setup/service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698