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

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host_unittest.cc

Issue 1458323002: Simplify It2Me host shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_main.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/it2me/it2me_native_messaging_host.h" 5 #include "remoting/host/it2me/it2me_native_messaging_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 void MockIt2MeHost::Disconnect() { 129 void MockIt2MeHost::Disconnect() {
130 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { 130 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) {
131 DCHECK(task_runner()->BelongsToCurrentThread()); 131 DCHECK(task_runner()->BelongsToCurrentThread());
132 host_context()->network_task_runner()->PostTask( 132 host_context()->network_task_runner()->PostTask(
133 FROM_HERE, base::Bind(&MockIt2MeHost::Disconnect, this)); 133 FROM_HERE, base::Bind(&MockIt2MeHost::Disconnect, this));
134 return; 134 return;
135 } 135 }
136 136
137 RunSetState(kDisconnecting);
138 RunSetState(kDisconnected); 137 RunSetState(kDisconnected);
139 } 138 }
140 139
141 void MockIt2MeHost::RequestNatPolicy() {} 140 void MockIt2MeHost::RequestNatPolicy() {}
142 141
143 void MockIt2MeHost::RunSetState(It2MeHostState state) { 142 void MockIt2MeHost::RunSetState(It2MeHostState state) {
144 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) { 143 if (!host_context()->network_task_runner()->BelongsToCurrentThread()) {
145 host_context()->network_task_runner()->PostTask( 144 host_context()->network_task_runner()->PostTask(
146 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state, "")); 145 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, this, state, ""));
147 } else { 146 } else {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 ADD_FAILURE() << "Unexpected host state: " << state; 371 ADD_FAILURE() << "Unexpected host state: " << state;
373 } 372 }
374 } else { 373 } else {
375 ADD_FAILURE() << "Unexpected message type: " << type; 374 ADD_FAILURE() << "Unexpected message type: " << type;
376 } 375 }
377 } 376 }
378 } 377 }
379 378
380 void It2MeNativeMessagingHostTest::VerifyDisconnectResponses(int request_id) { 379 void It2MeNativeMessagingHostTest::VerifyDisconnectResponses(int request_id) {
381 bool disconnect_response_received = false; 380 bool disconnect_response_received = false;
382 bool disconnecting_received = false;
383 bool disconnected_received = false; 381 bool disconnected_received = false;
384 382
385 // We expect a total of 3 messages: 1 connectResponse and 2 hostStateChanged. 383 // We expect a total of 3 messages: 1 connectResponse and 1 hostStateChanged.
386 for (int i = 0; i < 3; ++i) { 384 for (int i = 0; i < 2; ++i) {
387 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); 385 scoped_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe();
388 ASSERT_TRUE(response); 386 ASSERT_TRUE(response);
389 387
390 std::string type; 388 std::string type;
391 ASSERT_TRUE(response->GetString("type", &type)); 389 ASSERT_TRUE(response->GetString("type", &type));
392 390
393 if (type == "disconnectResponse") { 391 if (type == "disconnectResponse") {
394 EXPECT_FALSE(disconnect_response_received); 392 EXPECT_FALSE(disconnect_response_received);
395 disconnect_response_received = true; 393 disconnect_response_received = true;
396 VerifyId(response.Pass(), request_id); 394 VerifyId(response.Pass(), request_id);
397 } else if (type == "hostStateChanged") { 395 } else if (type == "hostStateChanged") {
398 std::string state; 396 std::string state;
399 ASSERT_TRUE(response->GetString("state", &state)); 397 ASSERT_TRUE(response->GetString("state", &state));
400 if (state == 398 if (state == It2MeNativeMessagingHost::HostStateToString(kDisconnected)) {
401 It2MeNativeMessagingHost::HostStateToString(kDisconnecting)) {
402 EXPECT_FALSE(disconnecting_received);
403 disconnecting_received = true;
404 } else if (state ==
405 It2MeNativeMessagingHost::HostStateToString(kDisconnected)) {
406 EXPECT_FALSE(disconnected_received); 399 EXPECT_FALSE(disconnected_received);
407 disconnected_received = true; 400 disconnected_received = true;
408 } else { 401 } else {
409 ADD_FAILURE() << "Unexpected host state: " << state; 402 ADD_FAILURE() << "Unexpected host state: " << state;
410 } 403 }
411 } else { 404 } else {
412 ADD_FAILURE() << "Unexpected message type: " << type; 405 ADD_FAILURE() << "Unexpected message type: " << type;
413 } 406 }
414 } 407 }
415 } 408 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 542 }
550 543
551 // Verify rejection if type is unrecognized. 544 // Verify rejection if type is unrecognized.
552 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { 545 TEST_F(It2MeNativeMessagingHostTest, InvalidType) {
553 base::DictionaryValue message; 546 base::DictionaryValue message;
554 message.SetString("type", "xxx"); 547 message.SetString("type", "xxx");
555 TestBadRequest(message, true); 548 TestBadRequest(message, true);
556 } 549 }
557 550
558 } // namespace remoting 551 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698