Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 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/service.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include <gtest/gtest.h> |
| 14 | #include <gmock/gmock.h> |
| 15 | |
| 16 | #include "shill/dbus_adaptor.h" |
| 17 | #include "shill/ethernet_service.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 18 | #include "shill/event_dispatcher.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 19 | #include "shill/manager.h" |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 20 | #include "shill/mock_adaptors.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 21 | #include "shill/mock_control.h" |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 22 | #include "shill/mock_manager.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 23 | #include "shill/mock_store.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 24 | #include "shill/property_store_unittest.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 25 | #include "shill/service_under_test.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | |
| 27 | using std::map; |
| 28 | using std::string; |
| 29 | using std::vector; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 30 | using testing::_; |
| 31 | using testing::AtLeast; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 32 | using testing::DoAll; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 33 | using testing::NiceMock; |
| 34 | using testing::Return; |
| 35 | using testing::StrictMock; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 36 | using testing::SetArgumentPointee; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 37 | using testing::Test; |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 38 | using testing::Values; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 39 | |
| 40 | namespace shill { |
| 41 | |
| 42 | class ServiceTest : public PropertyStoreTest { |
| 43 | public: |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 44 | ServiceTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 45 | : mock_manager_(control_interface(), dispatcher(), metrics(), glib()), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 46 | service_(new ServiceUnderTest(control_interface(), |
| 47 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 48 | metrics(), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 49 | &mock_manager_)), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 50 | storage_id_(ServiceUnderTest::kStorageId) { |
| 51 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 52 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 53 | virtual ~ServiceTest() {} |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 54 | |
| 55 | protected: |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 56 | MockManager mock_manager_; |
| 57 | scoped_refptr<ServiceUnderTest> service_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 58 | string storage_id_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 61 | TEST_F(ServiceTest, Constructor) { |
| 62 | EXPECT_TRUE(service_->save_credentials_); |
| 63 | EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_); |
| 64 | } |
| 65 | |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 66 | TEST_F(ServiceTest, GetProperties) { |
| 67 | map<string, ::DBus::Variant> props; |
| 68 | Error error(Error::kInvalidProperty, ""); |
| 69 | { |
| 70 | ::DBus::Error dbus_error; |
| 71 | string expected("portal_list"); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 72 | service_->mutable_store()->SetStringProperty(flimflam::kCheckPortalProperty, |
| 73 | expected, |
| 74 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 75 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 76 | ASSERT_FALSE(props.find(flimflam::kCheckPortalProperty) == props.end()); |
| 77 | EXPECT_EQ(props[flimflam::kCheckPortalProperty].reader().get_string(), |
| 78 | expected); |
| 79 | } |
| 80 | { |
| 81 | ::DBus::Error dbus_error; |
| 82 | bool expected = true; |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 83 | service_->set_favorite(true); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 84 | service_->mutable_store()->SetBoolProperty(flimflam::kAutoConnectProperty, |
| 85 | expected, |
| 86 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 87 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 88 | ASSERT_FALSE(props.find(flimflam::kAutoConnectProperty) == props.end()); |
| 89 | EXPECT_EQ(props[flimflam::kAutoConnectProperty].reader().get_bool(), |
| 90 | expected); |
| 91 | } |
| 92 | { |
| 93 | ::DBus::Error dbus_error; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 94 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 95 | ASSERT_FALSE(props.find(flimflam::kConnectableProperty) == props.end()); |
| 96 | EXPECT_EQ(props[flimflam::kConnectableProperty].reader().get_bool(), false); |
| 97 | } |
| 98 | { |
| 99 | ::DBus::Error dbus_error; |
| 100 | int32 expected = 127; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 101 | service_->mutable_store()->SetInt32Property(flimflam::kPriorityProperty, |
| 102 | expected, |
| 103 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 104 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 105 | ASSERT_FALSE(props.find(flimflam::kPriorityProperty) == props.end()); |
| 106 | EXPECT_EQ(props[flimflam::kPriorityProperty].reader().get_int32(), |
| 107 | expected); |
| 108 | } |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 109 | { |
| 110 | ::DBus::Error dbus_error; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 111 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 112 | ASSERT_FALSE(props.find(flimflam::kDeviceProperty) == props.end()); |
| 113 | EXPECT_EQ(props[flimflam::kDeviceProperty].reader().get_string(), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 114 | string(ServiceUnderTest::kRpcId)); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 115 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 116 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 117 | |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 118 | TEST_F(ServiceTest, Dispatch) { |
| 119 | { |
| 120 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 121 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 122 | flimflam::kSaveCredentialsProperty, |
| 123 | PropertyStoreTest::kBoolV, |
| 124 | &error)); |
| 125 | } |
| 126 | { |
| 127 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 128 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 129 | flimflam::kPriorityProperty, |
| 130 | PropertyStoreTest::kInt32V, |
| 131 | &error)); |
| 132 | } |
| 133 | { |
| 134 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 135 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 136 | flimflam::kEAPEAPProperty, |
| 137 | PropertyStoreTest::kStringV, |
| 138 | &error)); |
| 139 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 140 | // Ensure that an attempt to write a R/O property returns InvalidArgs error. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 141 | { |
| 142 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 143 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 144 | flimflam::kFavoriteProperty, |
| 145 | PropertyStoreTest::kBoolV, |
| 146 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 147 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 148 | } |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 149 | { |
| 150 | ::DBus::Error error; |
| 151 | service_->set_favorite(true); |
| 152 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
| 153 | flimflam::kAutoConnectProperty, |
| 154 | PropertyStoreTest::kBoolV, |
| 155 | &error)); |
| 156 | } |
| 157 | { |
| 158 | ::DBus::Error error; |
| 159 | service_->set_favorite(false); |
| 160 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_->mutable_store(), |
| 161 | flimflam::kAutoConnectProperty, |
| 162 | PropertyStoreTest::kBoolV, |
| 163 | &error)); |
| 164 | EXPECT_EQ(invalid_args(), error.name()); |
| 165 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 168 | TEST_F(ServiceTest, Load) { |
| 169 | NiceMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 170 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
| 171 | EXPECT_CALL(storage, GetString(storage_id_, _, _)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 172 | .Times(AtLeast(1)) |
| 173 | .WillRepeatedly(Return(true)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 174 | EXPECT_TRUE(service_->Load(&storage)); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | TEST_F(ServiceTest, LoadFail) { |
| 178 | StrictMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 179 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(false)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 180 | EXPECT_FALSE(service_->Load(&storage)); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | TEST_F(ServiceTest, SaveString) { |
| 184 | MockStore storage; |
| 185 | static const char kKey[] = "test-key"; |
| 186 | static const char kData[] = "test-data"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 187 | EXPECT_CALL(storage, SetString(storage_id_, kKey, kData)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 188 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 189 | service_->SaveString(&storage, storage_id_, kKey, kData, false, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TEST_F(ServiceTest, SaveStringCrypted) { |
| 193 | MockStore storage; |
| 194 | static const char kKey[] = "test-key"; |
| 195 | static const char kData[] = "test-data"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 196 | EXPECT_CALL(storage, SetCryptedString(storage_id_, kKey, kData)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 197 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 198 | service_->SaveString(&storage, storage_id_, kKey, kData, true, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | TEST_F(ServiceTest, SaveStringDontSave) { |
| 202 | MockStore storage; |
| 203 | static const char kKey[] = "test-key"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 204 | EXPECT_CALL(storage, DeleteKey(storage_id_, kKey)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 205 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 206 | service_->SaveString(&storage, storage_id_, kKey, "data", false, false); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(ServiceTest, SaveStringEmpty) { |
| 210 | MockStore storage; |
| 211 | static const char kKey[] = "test-key"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 212 | EXPECT_CALL(storage, DeleteKey(storage_id_, kKey)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 213 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 214 | service_->SaveString(&storage, storage_id_, kKey, "", true, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | TEST_F(ServiceTest, Save) { |
| 218 | NiceMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 219 | EXPECT_CALL(storage, SetString(storage_id_, _, _)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 220 | .Times(AtLeast(1)) |
| 221 | .WillRepeatedly(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 222 | EXPECT_CALL(storage, DeleteKey(storage_id_, _)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 223 | .Times(AtLeast(1)) |
| 224 | .WillRepeatedly(Return(true)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 225 | EXPECT_TRUE(service_->Save(&storage)); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 228 | TEST_F(ServiceTest, Unload) { |
| 229 | NiceMock<MockStore> storage; |
| 230 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
| 231 | static const string string_value("value"); |
| 232 | EXPECT_CALL(storage, GetString(storage_id_, _, _)) |
| 233 | .Times(AtLeast(1)) |
| 234 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(string_value), Return(true))); |
| 235 | ASSERT_TRUE(service_->Load(&storage)); |
| 236 | // TODO(pstew): A single string property in the service is tested as |
| 237 | // a sentinel that properties are being set and reset at the rit times. |
| 238 | // However, since property load/store is essentially a manual process, |
| 239 | // it is error prone and should either be exhaustively unit-tested or |
| 240 | // a generic framework for registering loaded/stored properties should |
| 241 | // be created. crosbug.com/24859 |
| 242 | EXPECT_EQ(string_value, service_->ui_data_); |
| 243 | service_->Unload(); |
| 244 | EXPECT_EQ(string(""), service_->ui_data_); |
| 245 | } |
| 246 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 247 | TEST_F(ServiceTest, State) { |
| 248 | EXPECT_EQ(Service::kStateUnknown, service_->state()); |
| 249 | EXPECT_EQ(Service::kFailureUnknown, service_->failure()); |
| 250 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 251 | ServiceRefPtr service_ref(service_); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 252 | |
| 253 | // TODO(quiche): make this EXPECT_CALL work (crosbug.com/20154) |
| 254 | // EXPECT_CALL(*dynamic_cast<ServiceMockAdaptor *>(service_->adaptor_.get()), |
| 255 | // EmitStringChanged(flimflam::kStateProperty, _)); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 256 | EXPECT_CALL(mock_manager_, UpdateService(service_ref)); |
| 257 | service_->SetState(Service::kStateConnected); |
| 258 | // A second state change shouldn't cause another update |
| 259 | service_->SetState(Service::kStateConnected); |
| 260 | |
| 261 | EXPECT_EQ(Service::kStateConnected, service_->state()); |
| 262 | EXPECT_EQ(Service::kFailureUnknown, service_->failure()); |
| 263 | EXPECT_CALL(mock_manager_, UpdateService(service_ref)); |
| 264 | service_->SetState(Service::kStateDisconnected); |
| 265 | |
| 266 | EXPECT_CALL(mock_manager_, UpdateService(service_ref)); |
| 267 | service_->SetFailure(Service::kFailureOutOfRange); |
| 268 | |
| 269 | EXPECT_EQ(Service::kStateFailure, service_->state()); |
| 270 | EXPECT_EQ(Service::kFailureOutOfRange, service_->failure()); |
| 271 | } |
| 272 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 273 | TEST_F(ServiceTest, ActivateCellularModem) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 274 | MockReturner returner; |
| 275 | EXPECT_CALL(returner, Return()).Times(0); |
| 276 | EXPECT_CALL(returner, ReturnError(_)); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 277 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 278 | service_->ActivateCellularModem("Carrier", &returner); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 279 | } |
| 280 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 281 | TEST_F(ServiceTest, MakeFavorite) { |
| 282 | EXPECT_FALSE(service_->favorite()); |
| 283 | EXPECT_FALSE(service_->auto_connect()); |
| 284 | |
| 285 | service_->MakeFavorite(); |
| 286 | EXPECT_TRUE(service_->favorite()); |
| 287 | EXPECT_TRUE(service_->auto_connect()); |
| 288 | } |
| 289 | |
| 290 | TEST_F(ServiceTest, ReMakeFavorite) { |
| 291 | service_->MakeFavorite(); |
| 292 | EXPECT_TRUE(service_->favorite()); |
| 293 | EXPECT_TRUE(service_->auto_connect()); |
| 294 | |
| 295 | service_->set_auto_connect(false); |
| 296 | service_->MakeFavorite(); |
| 297 | EXPECT_TRUE(service_->favorite()); |
| 298 | EXPECT_FALSE(service_->auto_connect()); |
| 299 | } |
| 300 | |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 301 | TEST_F(ServiceTest, IsAutoConnectable) { |
| 302 | service_->set_connectable(true); |
| 303 | EXPECT_TRUE(service_->IsAutoConnectable()); |
| 304 | |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 305 | // We should not auto-connect to a Service that a user has |
| 306 | // deliberately disconnected. |
| 307 | Error error; |
| 308 | service_->Disconnect(&error); |
| 309 | EXPECT_FALSE(service_->IsAutoConnectable()); |
| 310 | |
| 311 | // But if the Service is reloaded, it is eligible for auto-connect |
| 312 | // again. |
| 313 | NiceMock<MockStore> storage; |
| 314 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
| 315 | EXPECT_TRUE(service_->Load(&storage)); |
| 316 | EXPECT_TRUE(service_->IsAutoConnectable()); |
| 317 | |
| 318 | // A deliberate Connect should also re-enable auto-connect. |
| 319 | service_->Disconnect(&error); |
| 320 | EXPECT_FALSE(service_->IsAutoConnectable()); |
| 321 | service_->Connect(&error); |
| 322 | EXPECT_TRUE(service_->IsAutoConnectable()); |
| 323 | |
| 324 | // TODO(quiche): After we have resume handling in place, test that |
| 325 | // we re-enable auto-connect on resume. crosbug.com/25213 |
| 326 | |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 327 | service_->SetState(Service::kStateConnected); |
| 328 | EXPECT_FALSE(service_->IsAutoConnectable()); |
| 329 | |
| 330 | service_->SetState(Service::kStateAssociating); |
| 331 | EXPECT_FALSE(service_->IsAutoConnectable()); |
| 332 | } |
| 333 | |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 334 | // Make sure a property is registered as a write only property |
| 335 | // by reading and comparing all string properties returned on the store. |
| 336 | // Subtle: We need to convert the test argument back and forth between |
| 337 | // string and ::DBus::Variant because this is the parameter type that |
| 338 | // our supeclass (PropertyStoreTest) is declared with. |
| 339 | class ReadOnlyServicePropertyTest : public ServiceTest {}; |
| 340 | TEST_P(ReadOnlyServicePropertyTest, PropertyWriteOnly) { |
| 341 | ReadablePropertyConstIterator<string> it = |
| 342 | (service_->store()).GetStringPropertiesIter(); |
| 343 | string property(GetParam().reader().get_string()); |
| 344 | for( ; !it.AtEnd(); it.Advance()) |
| 345 | EXPECT_NE(it.Key(), property); |
| 346 | } |
| 347 | |
| 348 | INSTANTIATE_TEST_CASE_P( |
| 349 | ReadOnlyServicePropertyTestInstance, |
| 350 | ReadOnlyServicePropertyTest, |
| 351 | Values( |
| 352 | DBusAdaptor::StringToVariant(flimflam::kEapPrivateKeyPasswordProperty), |
| 353 | DBusAdaptor::StringToVariant(flimflam::kEapPasswordProperty))); |
| 354 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 355 | } // namespace shill |