| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" |
| 8 #include "chromeos/dbus/shill_client_unittest_base.h" | 9 #include "chromeos/dbus/shill_client_unittest_base.h" |
| 9 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 10 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| 10 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 11 #include "chromeos/dbus/shill_third_party_vpn_observer.h" |
| 11 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 12 | 13 |
| 13 using testing::_; | 14 using testing::_; |
| 14 | 15 |
| 15 namespace chromeos { | 16 namespace chromeos { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kExampleIPConfigPath[] = "/foo/bar"; | 20 const char kExampleIPConfigPath[] = "/foo/bar"; |
| 20 | 21 |
| 21 class MockShillThirdPartyVpnObserver : public ShillThirdPartyVpnObserver { | 22 class MockShillThirdPartyVpnObserver : public ShillThirdPartyVpnObserver { |
| 22 public: | 23 public: |
| 23 MockShillThirdPartyVpnObserver() {} | 24 MockShillThirdPartyVpnObserver() {} |
| 24 ~MockShillThirdPartyVpnObserver() override {} | 25 ~MockShillThirdPartyVpnObserver() override {} |
| 25 MOCK_METHOD1(OnPacketReceived, void(const std::string& data)); | 26 MOCK_METHOD1(OnPacketReceived, void(const std::vector<char>& data)); |
| 26 MOCK_METHOD1(OnPlatformMessage, void(uint32_t message)); | 27 MOCK_METHOD1(OnPlatformMessage, void(uint32_t message)); |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 class ShillThirdPartyVpnDriverClientTest : public ShillClientUnittestBase { | 32 class ShillThirdPartyVpnDriverClientTest : public ShillClientUnittestBase { |
| 32 public: | 33 public: |
| 33 ShillThirdPartyVpnDriverClientTest() | 34 ShillThirdPartyVpnDriverClientTest() |
| 34 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, | 35 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, |
| 35 dbus::ObjectPath(kExampleIPConfigPath)) {} | 36 dbus::ObjectPath(kExampleIPConfigPath)) {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 const std::string& error_message) { | 52 const std::string& error_message) { |
| 52 ADD_FAILURE() << error_name << ": " << error_message; | 53 ADD_FAILURE() << error_name << ": " << error_message; |
| 53 } | 54 } |
| 54 | 55 |
| 55 protected: | 56 protected: |
| 56 scoped_ptr<ShillThirdPartyVpnDriverClient> client_; | 57 scoped_ptr<ShillThirdPartyVpnDriverClient> client_; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { | 60 TEST_F(ShillThirdPartyVpnDriverClientTest, PlatformSignal) { |
| 60 uint32_t connected_state = 123456; | 61 uint32_t connected_state = 123456; |
| 61 const int kPacketSize = 5; | 62 const size_t kPacketSize = 5; |
| 62 std::string data_packet(1, kPacketSize); | 63 std::vector<char> data_packet(kPacketSize, 1); |
| 63 dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, | 64 dbus::Signal pmessage_signal(shill::kFlimflamThirdPartyVpnInterface, |
| 64 shill::kOnPlatformMessageFunction); | 65 shill::kOnPlatformMessageFunction); |
| 65 { | 66 { |
| 66 dbus::MessageWriter writer(&pmessage_signal); | 67 dbus::MessageWriter writer(&pmessage_signal); |
| 67 writer.AppendUint32(connected_state); | 68 writer.AppendUint32(connected_state); |
| 68 } | 69 } |
| 69 | 70 |
| 70 dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, | 71 dbus::Signal preceived_signal(shill::kFlimflamThirdPartyVpnInterface, |
| 71 shill::kOnPacketReceivedFunction); | 72 shill::kOnPacketReceivedFunction); |
| 72 { | 73 { |
| 73 dbus::MessageWriter writer(&preceived_signal); | 74 dbus::MessageWriter writer(&preceived_signal); |
| 74 writer.AppendArrayOfBytes( | 75 writer.AppendArrayOfBytes( |
| 75 reinterpret_cast<const unsigned char*>(data_packet.data()), | 76 reinterpret_cast<const uint8_t*>(vector_as_array(&data_packet)), |
| 76 data_packet.size()); | 77 data_packet.size()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 // Expect each signal to be triggered once. | 80 // Expect each signal to be triggered once. |
| 80 MockShillThirdPartyVpnObserver observer; | 81 MockShillThirdPartyVpnObserver observer; |
| 81 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); | 82 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(1); |
| 82 EXPECT_CALL(observer, OnPacketReceived(data_packet)).Times(1); | 83 EXPECT_CALL(observer, OnPacketReceived(data_packet)).Times(1); |
| 83 | 84 |
| 84 client_->AddShillThirdPartyVpnObserver(kExampleIPConfigPath, &observer); | 85 client_->AddShillThirdPartyVpnObserver(kExampleIPConfigPath, &observer); |
| 85 | 86 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, | 161 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, |
| 161 base::Unretained(this)), | 162 base::Unretained(this)), |
| 162 base::Bind(&Failure)); | 163 base::Bind(&Failure)); |
| 163 | 164 |
| 164 message_loop_.RunUntilIdle(); | 165 message_loop_.RunUntilIdle(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { | 168 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { |
| 168 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 169 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 169 | 170 |
| 170 const std::string data(5, 0); | 171 const size_t kPacketSize = 5; |
| 172 const std::vector<char> data(kPacketSize, 0); |
| 171 | 173 |
| 172 EXPECT_CALL(*this, MockSuccess()).Times(1); | 174 EXPECT_CALL(*this, MockSuccess()).Times(1); |
| 173 | 175 |
| 174 PrepareForMethodCall(shill::kSendPacketFunction, | 176 PrepareForMethodCall(shill::kSendPacketFunction, |
| 175 base::Bind(&ExpectArrayOfBytesArgument, data), | 177 base::Bind(&ExpectArrayOfBytesArgument, |
| 178 std::string(data.begin(), data.end())), |
| 176 response.get()); | 179 response.get()); |
| 177 | 180 |
| 178 client_->SendPacket( | 181 client_->SendPacket( |
| 179 kExampleIPConfigPath, data, | 182 kExampleIPConfigPath, data, |
| 180 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, | 183 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, |
| 181 base::Unretained(this)), | 184 base::Unretained(this)), |
| 182 base::Bind(&Failure)); | 185 base::Bind(&Failure)); |
| 183 | 186 |
| 184 message_loop_.RunUntilIdle(); | 187 message_loop_.RunUntilIdle(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 } // namespace chromeos | 190 } // namespace chromeos |
| OLD | NEW |