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/it2me/it2me_native_messaging_host.h" | 5 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 RunSetState(kRequestedAccessCode); | 162 RunSetState(kRequestedAccessCode); |
163 | 163 |
164 std::string access_code(kTestAccessCode); | 164 std::string access_code(kTestAccessCode); |
165 base::TimeDelta lifetime = | 165 base::TimeDelta lifetime = |
166 base::TimeDelta::FromSeconds(kTestAccessCodeLifetimeInSeconds); | 166 base::TimeDelta::FromSeconds(kTestAccessCodeLifetimeInSeconds); |
167 host_context()->ui_task_runner()->PostTask( | 167 host_context()->ui_task_runner()->PostTask( |
168 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, observer(), | 168 FROM_HERE, base::Bind(&It2MeHost::Observer::OnStoreAccessCode, observer(), |
169 access_code, lifetime)); | 169 access_code, lifetime)); |
170 | 170 |
171 RunSetState(kReceivedAccessCode); | 171 RunSetState(kReceivedAccessCode); |
| 172 RunSetState(kConnecting); |
172 | 173 |
173 std::string client_username(kTestClientUsername); | 174 std::string client_username(kTestClientUsername); |
174 host_context()->ui_task_runner()->PostTask( | 175 host_context()->ui_task_runner()->PostTask( |
175 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated, | 176 FROM_HERE, base::Bind(&It2MeHost::Observer::OnClientAuthenticated, |
176 observer(), client_username)); | 177 observer(), client_username)); |
177 | 178 |
178 RunSetState(kConnected); | 179 RunSetState(kConnected); |
179 } | 180 } |
180 | 181 |
181 void MockIt2MeHost::Disconnect() { | 182 void MockIt2MeHost::Disconnect() { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 void It2MeNativeMessagingHostTest::VerifyErrorResponse() { | 395 void It2MeNativeMessagingHostTest::VerifyErrorResponse() { |
395 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); | 396 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); |
396 VerifyStringProperty(std::move(response), "type", "error"); | 397 VerifyStringProperty(std::move(response), "type", "error"); |
397 } | 398 } |
398 | 399 |
399 void It2MeNativeMessagingHostTest::VerifyConnectResponses(int request_id) { | 400 void It2MeNativeMessagingHostTest::VerifyConnectResponses(int request_id) { |
400 bool connect_response_received = false; | 401 bool connect_response_received = false; |
401 bool starting_received = false; | 402 bool starting_received = false; |
402 bool requestedAccessCode_received = false; | 403 bool requestedAccessCode_received = false; |
403 bool receivedAccessCode_received = false; | 404 bool receivedAccessCode_received = false; |
| 405 bool connecting_received = false; |
404 bool connected_received = false; | 406 bool connected_received = false; |
405 | 407 |
406 // We expect a total of 5 messages: 1 connectResponse and 4 hostStateChanged. | 408 // We expect a total of 6 messages: 1 connectResponse and 5 hostStateChanged. |
407 for (int i = 0; i < 5; ++i) { | 409 for (int i = 0; i < 6; ++i) { |
408 std::unique_ptr<base::DictionaryValue> response = | 410 std::unique_ptr<base::DictionaryValue> response = |
409 ReadMessageFromOutputPipe(); | 411 ReadMessageFromOutputPipe(); |
410 ASSERT_TRUE(response); | 412 ASSERT_TRUE(response); |
411 | 413 |
412 std::string type; | 414 std::string type; |
413 ASSERT_TRUE(response->GetString("type", &type)); | 415 ASSERT_TRUE(response->GetString("type", &type)); |
414 | 416 |
415 if (type == "connectResponse") { | 417 if (type == "connectResponse") { |
416 EXPECT_FALSE(connect_response_received); | 418 EXPECT_FALSE(connect_response_received); |
417 connect_response_received = true; | 419 connect_response_received = true; |
(...skipping 16 matching lines...) Expand all Loading... |
434 receivedAccessCode_received = true; | 436 receivedAccessCode_received = true; |
435 | 437 |
436 EXPECT_TRUE(response->GetString("accessCode", &value)); | 438 EXPECT_TRUE(response->GetString("accessCode", &value)); |
437 EXPECT_EQ(kTestAccessCode, value); | 439 EXPECT_EQ(kTestAccessCode, value); |
438 | 440 |
439 int accessCodeLifetime; | 441 int accessCodeLifetime; |
440 EXPECT_TRUE( | 442 EXPECT_TRUE( |
441 response->GetInteger("accessCodeLifetime", &accessCodeLifetime)); | 443 response->GetInteger("accessCodeLifetime", &accessCodeLifetime)); |
442 EXPECT_EQ(kTestAccessCodeLifetimeInSeconds, accessCodeLifetime); | 444 EXPECT_EQ(kTestAccessCodeLifetimeInSeconds, accessCodeLifetime); |
443 } else if (state == | 445 } else if (state == |
| 446 It2MeNativeMessagingHost::HostStateToString(kConnecting)) { |
| 447 EXPECT_FALSE(connecting_received); |
| 448 connecting_received = true; |
| 449 } else if (state == |
444 It2MeNativeMessagingHost::HostStateToString(kConnected)) { | 450 It2MeNativeMessagingHost::HostStateToString(kConnected)) { |
445 EXPECT_FALSE(connected_received); | 451 EXPECT_FALSE(connected_received); |
446 connected_received = true; | 452 connected_received = true; |
447 | 453 |
448 EXPECT_TRUE(response->GetString("client", &value)); | 454 EXPECT_TRUE(response->GetString("client", &value)); |
449 EXPECT_EQ(kTestClientUsername, value); | 455 EXPECT_EQ(kTestClientUsername, value); |
450 } else { | 456 } else { |
451 ADD_FAILURE() << "Unexpected host state: " << state; | 457 ADD_FAILURE() << "Unexpected host state: " << state; |
452 } | 458 } |
453 } else { | 459 } else { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 base::DictionaryValue good_message; | 499 base::DictionaryValue good_message; |
494 good_message.SetString("type", "hello"); | 500 good_message.SetString("type", "hello"); |
495 good_message.SetInteger("id", 1); | 501 good_message.SetInteger("id", 1); |
496 | 502 |
497 WriteMessageToInputPipe(good_message); | 503 WriteMessageToInputPipe(good_message); |
498 WriteMessageToInputPipe(message); | 504 WriteMessageToInputPipe(message); |
499 WriteMessageToInputPipe(good_message); | 505 WriteMessageToInputPipe(good_message); |
500 | 506 |
501 VerifyHelloResponse(1); | 507 VerifyHelloResponse(1); |
502 | 508 |
503 if (expect_error_response) | 509 if (expect_error_response) { |
504 VerifyErrorResponse(); | 510 VerifyErrorResponse(); |
| 511 } |
505 | 512 |
506 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); | 513 std::unique_ptr<base::DictionaryValue> response = ReadMessageFromOutputPipe(); |
507 EXPECT_FALSE(response); | 514 EXPECT_FALSE(response); |
508 } | 515 } |
509 | 516 |
510 void It2MeNativeMessagingHostTest::StartHost() { | 517 void It2MeNativeMessagingHostTest::StartHost() { |
511 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); | 518 DCHECK(host_task_runner_->RunsTasksOnCurrentThread()); |
512 | 519 |
513 base::File input_read_file; | 520 base::File input_read_file; |
514 base::File output_write_file; | 521 base::File output_write_file; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 response = ReadMessageFromOutputPipe(); | 606 response = ReadMessageFromOutputPipe(); |
600 EXPECT_TRUE(response); | 607 EXPECT_TRUE(response); |
601 EXPECT_TRUE(response->GetString("id", &value)); | 608 EXPECT_TRUE(response->GetString("id", &value)); |
602 EXPECT_EQ("42", value); | 609 EXPECT_EQ("42", value); |
603 } | 610 } |
604 | 611 |
605 TEST_F(It2MeNativeMessagingHostTest, Connect) { | 612 TEST_F(It2MeNativeMessagingHostTest, Connect) { |
606 // A new It2MeHost instance is created for every it2me session. The native | 613 // A new It2MeHost instance is created for every it2me session. The native |
607 // messaging host, on the other hand, is long lived. This test verifies | 614 // messaging host, on the other hand, is long lived. This test verifies |
608 // multiple It2Me host startup and shutdowns. | 615 // multiple It2Me host startup and shutdowns. |
609 for (int i = 0; i < 3; ++i) | 616 for (int i = 0; i < 3; ++i) { |
610 TestConnect(); | 617 TestConnect(); |
| 618 } |
611 } | 619 } |
612 | 620 |
613 // Verify non-Dictionary requests are rejected. | 621 // Verify non-Dictionary requests are rejected. |
614 TEST_F(It2MeNativeMessagingHostTest, WrongFormat) { | 622 TEST_F(It2MeNativeMessagingHostTest, WrongFormat) { |
615 base::ListValue message; | 623 base::ListValue message; |
616 // No "error" response will be sent for non-Dictionary messages. | 624 // No "error" response will be sent for non-Dictionary messages. |
617 TestBadRequest(message, false); | 625 TestBadRequest(message, false); |
618 } | 626 } |
619 | 627 |
620 // Verify requests with no type are rejected. | 628 // Verify requests with no type are rejected. |
621 TEST_F(It2MeNativeMessagingHostTest, MissingType) { | 629 TEST_F(It2MeNativeMessagingHostTest, MissingType) { |
622 base::DictionaryValue message; | 630 base::DictionaryValue message; |
623 TestBadRequest(message, true); | 631 TestBadRequest(message, true); |
624 } | 632 } |
625 | 633 |
626 // Verify rejection if type is unrecognized. | 634 // Verify rejection if type is unrecognized. |
627 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { | 635 TEST_F(It2MeNativeMessagingHostTest, InvalidType) { |
628 base::DictionaryValue message; | 636 base::DictionaryValue message; |
629 message.SetString("type", "xxx"); | 637 message.SetString("type", "xxx"); |
630 TestBadRequest(message, true); | 638 TestBadRequest(message, true); |
631 } | 639 } |
632 | 640 |
633 } // namespace remoting | 641 } // namespace remoting |
OLD | NEW |