| 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/setup/native_messaging_host.h" | 5 #include "remoting/host/setup/native_messaging_host.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/stringize_macros.h" | 13 #include "base/strings/stringize_macros.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/file_stream.h" | 15 #include "net/base/file_stream.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "remoting/host/pin_hash.h" | 17 #include "remoting/host/pin_hash.h" |
| 18 #include "remoting/host/setup/daemon_controller.h" |
| 18 #include "remoting/host/setup/test_util.h" | 19 #include "remoting/host/setup/test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 void VerifyHelloResponse(const base::DictionaryValue* response) { | 24 void VerifyHelloResponse(const base::DictionaryValue* response) { |
| 24 ASSERT_TRUE(response); | 25 ASSERT_TRUE(response); |
| 25 std::string value; | 26 std::string value; |
| 26 EXPECT_TRUE(response->GetString("type", &value)); | 27 EXPECT_TRUE(response->GetString("type", &value)); |
| 27 EXPECT_EQ("helloResponse", value); | 28 EXPECT_EQ("helloResponse", value); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 EXPECT_TRUE(supported); | 79 EXPECT_TRUE(supported); |
| 79 EXPECT_TRUE(allowed); | 80 EXPECT_TRUE(allowed); |
| 80 EXPECT_TRUE(set_by_policy); | 81 EXPECT_TRUE(set_by_policy); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void VerifyStopDaemonResponse(const base::DictionaryValue* response) { | 84 void VerifyStopDaemonResponse(const base::DictionaryValue* response) { |
| 84 ASSERT_TRUE(response); | 85 ASSERT_TRUE(response); |
| 85 std::string value; | 86 std::string value; |
| 86 EXPECT_TRUE(response->GetString("type", &value)); | 87 EXPECT_TRUE(response->GetString("type", &value)); |
| 87 EXPECT_EQ("stopDaemonResponse", value); | 88 EXPECT_EQ("stopDaemonResponse", value); |
| 88 int result; | 89 EXPECT_TRUE(response->GetString("result", &value)); |
| 89 EXPECT_TRUE(response->GetInteger("result", &result)); | 90 EXPECT_EQ(remoting::DaemonController::kResultOk, value); |
| 90 EXPECT_EQ(0, result); | |
| 91 } | 91 } |
| 92 | 92 |
| 93 void VerifyGetDaemonStateResponse(const base::DictionaryValue* response) { | 93 void VerifyGetDaemonStateResponse(const base::DictionaryValue* response) { |
| 94 ASSERT_TRUE(response); | 94 ASSERT_TRUE(response); |
| 95 std::string value; | 95 std::string value; |
| 96 EXPECT_TRUE(response->GetString("type", &value)); | 96 EXPECT_TRUE(response->GetString("type", &value)); |
| 97 EXPECT_EQ("getDaemonStateResponse", value); | 97 EXPECT_EQ("getDaemonStateResponse", value); |
| 98 int result; | 98 EXPECT_TRUE(response->GetString("state", &value)); |
| 99 EXPECT_TRUE(response->GetInteger("state", &result)); | 99 EXPECT_EQ(remoting::DaemonController::kStateStarted, value); |
| 100 EXPECT_EQ(4, result); | |
| 101 } | 100 } |
| 102 | 101 |
| 103 void VerifyUpdateDaemonConfigResponse(const base::DictionaryValue* response) { | 102 void VerifyUpdateDaemonConfigResponse(const base::DictionaryValue* response) { |
| 104 ASSERT_TRUE(response); | 103 ASSERT_TRUE(response); |
| 105 std::string value; | 104 std::string value; |
| 106 EXPECT_TRUE(response->GetString("type", &value)); | 105 EXPECT_TRUE(response->GetString("type", &value)); |
| 107 EXPECT_EQ("updateDaemonConfigResponse", value); | 106 EXPECT_EQ("updateDaemonConfigResponse", value); |
| 108 int result; | 107 EXPECT_TRUE(response->GetString("result", &value)); |
| 109 EXPECT_TRUE(response->GetInteger("result", &result)); | 108 EXPECT_EQ(remoting::DaemonController::kResultOk, value); |
| 110 EXPECT_EQ(0, result); | |
| 111 } | 109 } |
| 112 | 110 |
| 113 void VerifyStartDaemonResponse(const base::DictionaryValue* response) { | 111 void VerifyStartDaemonResponse(const base::DictionaryValue* response) { |
| 114 ASSERT_TRUE(response); | 112 ASSERT_TRUE(response); |
| 115 std::string value; | 113 std::string value; |
| 116 EXPECT_TRUE(response->GetString("type", &value)); | 114 EXPECT_TRUE(response->GetString("type", &value)); |
| 117 EXPECT_EQ("startDaemonResponse", value); | 115 EXPECT_EQ("startDaemonResponse", value); |
| 118 int result; | 116 EXPECT_TRUE(response->GetString("result", &value)); |
| 119 EXPECT_TRUE(response->GetInteger("result", &result)); | 117 EXPECT_EQ(remoting::DaemonController::kResultOk, value); |
| 120 EXPECT_EQ(0, result); | |
| 121 } | 118 } |
| 122 | 119 |
| 123 } // namespace | 120 } // namespace |
| 124 | 121 |
| 125 namespace remoting { | 122 namespace remoting { |
| 126 | 123 |
| 127 class MockDaemonController : public DaemonController { | 124 class MockDaemonController : public DaemonController { |
| 128 public: | 125 public: |
| 129 MockDaemonController(); | 126 MockDaemonController(); |
| 130 virtual ~MockDaemonController(); | 127 virtual ~MockDaemonController(); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 505 |
| 509 // Verify rejection if startDaemon request has no "consent" parameter. | 506 // Verify rejection if startDaemon request has no "consent" parameter. |
| 510 TEST_F(NativeMessagingHostTest, StartDaemonNoConsent) { | 507 TEST_F(NativeMessagingHostTest, StartDaemonNoConsent) { |
| 511 base::DictionaryValue message; | 508 base::DictionaryValue message; |
| 512 message.SetString("type", "startDaemon"); | 509 message.SetString("type", "startDaemon"); |
| 513 message.Set("config", base::DictionaryValue().DeepCopy()); | 510 message.Set("config", base::DictionaryValue().DeepCopy()); |
| 514 TestBadRequest(message); | 511 TestBadRequest(message); |
| 515 } | 512 } |
| 516 | 513 |
| 517 } // namespace remoting | 514 } // namespace remoting |
| OLD | NEW |