Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/vpn_service.h" |
| 6 | |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 7 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 8 | #include <gtest/gtest.h> |
| 9 | |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 10 | #include "shill/dbus_adaptor.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 11 | #include "shill/error.h" |
| 12 | #include "shill/nice_mock_control.h" |
| 13 | #include "shill/mock_adaptors.h" |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 14 | #include "shill/mock_connection.h" |
| 15 | #include "shill/mock_device_info.h" |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 16 | #include "shill/mock_manager.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 17 | #include "shill/mock_metrics.h" |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 18 | #include "shill/mock_profile.h" |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 19 | #include "shill/mock_sockets.h" |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 20 | #include "shill/mock_store.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 21 | #include "shill/mock_vpn_driver.h" |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 22 | #include "shill/mock_vpn_provider.h" |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 23 | #include "shill/service_property_change_test.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 24 | |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 25 | using std::string; |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 26 | using testing::_; |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 27 | using testing::NiceMock; |
| 28 | using testing::Return; |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 29 | using testing::ReturnRef; |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 30 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 31 | namespace shill { |
| 32 | |
| 33 | class VPNServiceTest : public testing::Test { |
| 34 | public: |
| 35 | VPNServiceTest() |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 36 | : interface_name_("test-interface"), |
| 37 | driver_(new MockVPNDriver()), |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 38 | manager_(&control_, NULL, NULL, NULL), |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 39 | metrics_(NULL), |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 40 | device_info_(&control_, NULL, NULL, NULL), |
| 41 | connection_(new NiceMock<MockConnection>(&device_info_)), |
| 42 | sockets_(new MockSockets()), |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 43 | service_(new VPNService(&control_, NULL, &metrics_, &manager_, |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 44 | driver_)) { |
| 45 | service_->sockets_.reset(sockets_); // Passes ownership. |
| 46 | } |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 47 | |
| 48 | virtual ~VPNServiceTest() {} |
| 49 | |
| 50 | protected: |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 51 | virtual void SetUp() { |
| 52 | ON_CALL(*connection_, interface_name()) |
| 53 | .WillByDefault(ReturnRef(interface_name_)); |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 54 | ON_CALL(*connection_, ipconfig_rpc_identifier()) |
| 55 | .WillByDefault(ReturnRef(ipconfig_rpc_identifier_)); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | virtual void TearDown() { |
| 59 | EXPECT_CALL(device_info_, FlushAddresses(0)); |
| 60 | } |
| 61 | |
| 62 | void SetServiceState(Service::ConnectState state) { |
| 63 | service_->state_ = state; |
| 64 | } |
| 65 | |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 66 | void SetHasEverConnected(bool connected) { |
| 67 | service_->has_ever_connected_ = connected; |
| 68 | } |
| 69 | |
| 70 | void SetConnectable(bool connectable) { |
| 71 | service_->connectable_ = connectable; |
| 72 | } |
| 73 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 74 | const char *GetAutoConnOffline() { |
| 75 | return Service::kAutoConnOffline; |
| 76 | } |
| 77 | |
| 78 | const char *GetAutoConnNeverConnected() { |
| 79 | return VPNService::kAutoConnNeverConnected; |
| 80 | } |
| 81 | |
| 82 | const char *GetAutoConnVPNAlreadyActive() { |
| 83 | return VPNService::kAutoConnVPNAlreadyActive; |
| 84 | } |
| 85 | |
| 86 | bool IsAutoConnectable(const char **reason) const { |
| 87 | return service_->IsAutoConnectable(reason); |
| 88 | } |
| 89 | |
Darin Petkov | c3505a5 | 2013-03-18 15:13:29 +0100 | [diff] [blame] | 90 | // Takes ownership of |provider|. |
| 91 | void SetVPNProvider(VPNProvider *provider) { |
| 92 | manager_.vpn_provider_.reset(provider); |
| 93 | } |
| 94 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 95 | ServiceMockAdaptor *GetAdaptor() { |
| 96 | return dynamic_cast<ServiceMockAdaptor *>(service_->adaptor()); |
| 97 | } |
| 98 | |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 99 | std::string interface_name_; |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 100 | std::string ipconfig_rpc_identifier_; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 101 | MockVPNDriver *driver_; // Owned by |service_|. |
| 102 | NiceMockControl control_; |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 103 | MockManager manager_; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 104 | MockMetrics metrics_; |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 105 | MockDeviceInfo device_info_; |
| 106 | scoped_refptr<NiceMock<MockConnection> > connection_; |
| 107 | MockSockets *sockets_; // Owned by |service_|. |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 108 | VPNServiceRefPtr service_; |
| 109 | }; |
| 110 | |
| 111 | TEST_F(VPNServiceTest, Connect) { |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 112 | EXPECT_TRUE(service_->connectable()); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 113 | Error error; |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 114 | EXPECT_CALL(*driver_, Connect(_, &error)); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 115 | service_->Connect(&error, "in test"); |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 116 | EXPECT_TRUE(error.IsSuccess()); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 119 | TEST_F(VPNServiceTest, ConnectAlreadyConnected) { |
| 120 | Error error; |
| 121 | EXPECT_CALL(*driver_, Connect(_, _)).Times(0); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 122 | SetServiceState(Service::kStateOnline); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 123 | service_->Connect(&error, "in test"); |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 124 | EXPECT_EQ(Error::kAlreadyConnected, error.type()); |
| 125 | error.Reset(); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 126 | SetServiceState(Service::kStateConfiguring); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 127 | service_->Connect(&error, "in test"); |
mukesh agrawal | dba1046 | 2013-06-04 11:36:21 -0700 | [diff] [blame] | 128 | EXPECT_EQ(Error::kInProgress, error.type()); |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Darin Petkov | 6aa2187 | 2012-03-09 16:10:19 +0100 | [diff] [blame] | 131 | TEST_F(VPNServiceTest, Disconnect) { |
| 132 | Error error; |
| 133 | EXPECT_CALL(*driver_, Disconnect()); |
| 134 | service_->Disconnect(&error); |
| 135 | EXPECT_TRUE(error.IsSuccess()); |
| 136 | } |
| 137 | |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 138 | TEST_F(VPNServiceTest, CreateStorageIdentifierNoHost) { |
| 139 | KeyValueStore args; |
| 140 | Error error; |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 141 | args.SetString(flimflam::kNameProperty, "vpn-name"); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 142 | EXPECT_EQ("", VPNService::CreateStorageIdentifier(args, &error)); |
| 143 | EXPECT_EQ(Error::kInvalidProperty, error.type()); |
| 144 | } |
| 145 | |
| 146 | TEST_F(VPNServiceTest, CreateStorageIdentifierNoName) { |
| 147 | KeyValueStore args; |
| 148 | Error error; |
| 149 | args.SetString(flimflam::kProviderHostProperty, "10.8.0.1"); |
| 150 | EXPECT_EQ("", VPNService::CreateStorageIdentifier(args, &error)); |
| 151 | EXPECT_EQ(Error::kNotSupported, error.type()); |
| 152 | } |
| 153 | |
| 154 | TEST_F(VPNServiceTest, CreateStorageIdentifier) { |
| 155 | KeyValueStore args; |
| 156 | Error error; |
Darin Petkov | 4e02ba2 | 2013-04-02 13:44:08 +0200 | [diff] [blame] | 157 | args.SetString(flimflam::kNameProperty, "vpn-name"); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 158 | args.SetString(flimflam::kProviderHostProperty, "10.8.0.1"); |
| 159 | EXPECT_EQ("vpn_10_8_0_1_vpn_name", |
| 160 | VPNService::CreateStorageIdentifier(args, &error)); |
| 161 | EXPECT_TRUE(error.IsSuccess()); |
| 162 | } |
| 163 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 164 | TEST_F(VPNServiceTest, GetStorageIdentifier) { |
| 165 | EXPECT_EQ("", service_->GetStorageIdentifier()); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 166 | service_->set_storage_id("foo"); |
| 167 | EXPECT_EQ("foo", service_->GetStorageIdentifier()); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TEST_F(VPNServiceTest, GetDeviceRpcId) { |
| 171 | Error error; |
| 172 | EXPECT_EQ("/", service_->GetDeviceRpcId(&error)); |
| 173 | EXPECT_EQ(Error::kNotSupported, error.type()); |
| 174 | } |
| 175 | |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 176 | TEST_F(VPNServiceTest, Load) { |
| 177 | NiceMock<MockStore> storage; |
| 178 | static const char kStorageID[] = "storage-id"; |
| 179 | service_->set_storage_id(kStorageID); |
| 180 | EXPECT_CALL(storage, ContainsGroup(kStorageID)).WillOnce(Return(true)); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 181 | EXPECT_CALL(*driver_, Load(&storage, kStorageID)) |
| 182 | .WillOnce(Return(true)); |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 183 | EXPECT_TRUE(service_->Load(&storage)); |
| 184 | } |
| 185 | |
| 186 | TEST_F(VPNServiceTest, Save) { |
| 187 | NiceMock<MockStore> storage; |
| 188 | static const char kStorageID[] = "storage-id"; |
| 189 | service_->set_storage_id(kStorageID); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 190 | EXPECT_CALL(*driver_, Save(&storage, kStorageID, false)) |
| 191 | .WillOnce(Return(true)); |
Darin Petkov | f3c71d7 | 2012-03-21 12:32:15 +0100 | [diff] [blame] | 192 | EXPECT_TRUE(service_->Save(&storage)); |
| 193 | } |
| 194 | |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 195 | TEST_F(VPNServiceTest, SaveCredentials) { |
| 196 | NiceMock<MockStore> storage; |
| 197 | static const char kStorageID[] = "storage-id"; |
| 198 | service_->set_storage_id(kStorageID); |
| 199 | service_->set_save_credentials(true); |
| 200 | EXPECT_CALL(*driver_, Save(&storage, kStorageID, true)) |
| 201 | .WillOnce(Return(true)); |
| 202 | EXPECT_TRUE(service_->Save(&storage)); |
| 203 | } |
| 204 | |
| 205 | TEST_F(VPNServiceTest, Unload) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 206 | service_->SetAutoConnect(true); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 207 | service_->set_save_credentials(true); |
| 208 | EXPECT_CALL(*driver_, Disconnect()); |
| 209 | EXPECT_CALL(*driver_, UnloadCredentials()); |
Darin Petkov | c3505a5 | 2013-03-18 15:13:29 +0100 | [diff] [blame] | 210 | MockVPNProvider *provider = new MockVPNProvider; |
| 211 | SetVPNProvider(provider); |
| 212 | provider->services_.push_back(service_); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 213 | service_->Unload(); |
| 214 | EXPECT_FALSE(service_->auto_connect()); |
| 215 | EXPECT_FALSE(service_->save_credentials()); |
Darin Petkov | c3505a5 | 2013-03-18 15:13:29 +0100 | [diff] [blame] | 216 | EXPECT_TRUE(provider->services_.empty()); |
Darin Petkov | cb71529 | 2012-04-25 13:04:37 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Paul Stewart | ebd3856 | 2012-03-23 13:06:40 -0700 | [diff] [blame] | 219 | TEST_F(VPNServiceTest, InitPropertyStore) { |
| 220 | EXPECT_CALL(*driver_, InitPropertyStore(service_->mutable_store())); |
| 221 | service_->InitDriverPropertyStore(); |
| 222 | } |
| 223 | |
Darin Petkov | 1d0080a | 2012-04-30 17:10:36 +0200 | [diff] [blame] | 224 | TEST_F(VPNServiceTest, MakeFavorite) { |
| 225 | EXPECT_FALSE(service_->favorite()); |
| 226 | EXPECT_FALSE(service_->auto_connect()); |
| 227 | service_->MakeFavorite(); |
| 228 | EXPECT_TRUE(service_->favorite()); |
| 229 | EXPECT_FALSE(service_->auto_connect()); |
| 230 | } |
| 231 | |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 232 | TEST_F(VPNServiceTest, SetConnection) { |
| 233 | EXPECT_FALSE(service_->connection_binder_.get()); |
| 234 | EXPECT_FALSE(service_->connection()); |
| 235 | EXPECT_CALL(*sockets_, Socket(_, _, _)).WillOnce(Return(-1)); |
| 236 | service_->SetConnection(connection_); |
| 237 | ASSERT_TRUE(service_->connection_binder_.get()); |
| 238 | EXPECT_EQ(connection_.get(), |
| 239 | service_->connection_binder_->connection().get()); |
| 240 | EXPECT_EQ(connection_.get(), service_->connection().get()); |
| 241 | EXPECT_CALL(*driver_, OnConnectionDisconnected()).Times(0); |
| 242 | } |
| 243 | |
| 244 | TEST_F(VPNServiceTest, OnConnectionDisconnected) { |
| 245 | EXPECT_CALL(*sockets_, Socket(_, _, _)).WillOnce(Return(-1)); |
| 246 | service_->SetConnection(connection_); |
| 247 | EXPECT_CALL(*driver_, OnConnectionDisconnected()).Times(1); |
| 248 | connection_->OnLowerDisconnect(); |
| 249 | } |
| 250 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 251 | TEST_F(VPNServiceTest, IsAutoConnectableOffline) { |
| 252 | EXPECT_TRUE(service_->connectable()); |
| 253 | const char *reason = NULL; |
| 254 | EXPECT_CALL(manager_, IsOnline()).WillOnce(Return(false)); |
| 255 | EXPECT_FALSE(IsAutoConnectable(&reason)); |
| 256 | EXPECT_STREQ(GetAutoConnOffline(), reason); |
| 257 | } |
| 258 | |
| 259 | TEST_F(VPNServiceTest, IsAutoConnectableNeverConnected) { |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 260 | EXPECT_TRUE(service_->connectable()); |
| 261 | EXPECT_FALSE(service_->has_ever_connected()); |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 262 | const char *reason = NULL; |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 263 | EXPECT_CALL(manager_, IsOnline()).WillOnce(Return(true)); |
| 264 | EXPECT_FALSE(IsAutoConnectable(&reason)); |
| 265 | EXPECT_STREQ(GetAutoConnNeverConnected(), reason); |
| 266 | } |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 267 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 268 | TEST_F(VPNServiceTest, IsAutoConnectableVPNAlreadyActive) { |
| 269 | EXPECT_TRUE(service_->connectable()); |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 270 | SetHasEverConnected(true); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 271 | EXPECT_CALL(manager_, IsOnline()).WillOnce(Return(true)); |
Darin Petkov | c3505a5 | 2013-03-18 15:13:29 +0100 | [diff] [blame] | 272 | MockVPNProvider *provider = new MockVPNProvider; |
| 273 | SetVPNProvider(provider); |
| 274 | EXPECT_CALL(*provider, HasActiveService()).WillOnce(Return(true)); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 275 | const char *reason = NULL; |
| 276 | EXPECT_FALSE(IsAutoConnectable(&reason)); |
| 277 | EXPECT_STREQ(GetAutoConnVPNAlreadyActive(), reason); |
| 278 | } |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 279 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 280 | TEST_F(VPNServiceTest, IsAutoConnectableNotConnectable) { |
| 281 | const char *reason = NULL; |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 282 | SetConnectable(false); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 283 | EXPECT_FALSE(IsAutoConnectable(&reason)); |
| 284 | } |
| 285 | |
| 286 | TEST_F(VPNServiceTest, IsAutoConnectable) { |
| 287 | EXPECT_TRUE(service_->connectable()); |
| 288 | SetHasEverConnected(true); |
| 289 | EXPECT_CALL(manager_, IsOnline()).WillOnce(Return(true)); |
Darin Petkov | c3505a5 | 2013-03-18 15:13:29 +0100 | [diff] [blame] | 290 | MockVPNProvider *provider = new MockVPNProvider; |
| 291 | SetVPNProvider(provider); |
| 292 | EXPECT_CALL(*provider, HasActiveService()).WillOnce(Return(false)); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 293 | const char *reason = NULL; |
| 294 | EXPECT_TRUE(IsAutoConnectable(&reason)); |
| 295 | EXPECT_FALSE(reason); |
Darin Petkov | 79349f0 | 2013-01-24 16:18:26 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 298 | TEST_F(VPNServiceTest, SetNamePropertyTrivial) { |
| 299 | DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 300 | // A null change returns false, but with error set to success. |
| 301 | EXPECT_FALSE(DBusAdaptor::SetProperty(service_->mutable_store(), |
| 302 | flimflam::kNameProperty, |
| 303 | DBusAdaptor::StringToVariant( |
| 304 | service_->friendly_name()), |
| 305 | &error)); |
| 306 | EXPECT_FALSE(error.is_set()); |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | TEST_F(VPNServiceTest, SetNameProperty) { |
| 310 | const string kHost = "1.2.3.4"; |
| 311 | driver_->args()->SetString(flimflam::kProviderHostProperty, kHost); |
| 312 | string kOldId = service_->GetStorageIdentifier(); |
| 313 | DBus::Error error; |
| 314 | const string kName = "New Name"; |
| 315 | scoped_refptr<MockProfile> profile( |
| 316 | new MockProfile(&control_, &metrics_, &manager_)); |
| 317 | EXPECT_CALL(*profile, DeleteEntry(kOldId, _)); |
| 318 | EXPECT_CALL(*profile, UpdateService(_)); |
| 319 | service_->set_profile(profile); |
| 320 | EXPECT_TRUE(DBusAdaptor::SetProperty(service_->mutable_store(), |
| 321 | flimflam::kNameProperty, |
| 322 | DBusAdaptor::StringToVariant(kName), |
| 323 | &error)); |
| 324 | EXPECT_NE(service_->GetStorageIdentifier(), kOldId); |
| 325 | EXPECT_EQ(kName, service_->friendly_name()); |
| 326 | } |
| 327 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 328 | TEST_F(VPNServiceTest, PropertyChanges) { |
| 329 | TestCommonPropertyChanges(service_, GetAdaptor()); |
| 330 | TestAutoConnectPropertyChange(service_, GetAdaptor()); |
| 331 | |
| 332 | const string kHost = "1.2.3.4"; |
| 333 | scoped_refptr<MockProfile> profile( |
| 334 | new NiceMock<MockProfile>(&control_, &metrics_, &manager_)); |
| 335 | service_->set_profile(profile); |
| 336 | driver_->args()->SetString(flimflam::kProviderHostProperty, kHost); |
| 337 | TestNamePropertyChange(service_, GetAdaptor()); |
| 338 | } |
| 339 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 340 | // Custom property setters should return false, and make no changes, if |
| 341 | // the new value is the same as the old value. |
| 342 | TEST_F(VPNServiceTest, CustomSetterNoopChange) { |
| 343 | TestCustomSetterNoopChange(service_, &manager_); |
| 344 | } |
| 345 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 346 | } // namespace shill |