Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 4 | |
| 5 | #include "shill/manager.h" |
| 6 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 7 | #include <set> |
| 8 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 9 | #include <glib.h> |
| 10 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 12 | #include <base/memory/scoped_temp_dir.h> |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 13 | #include <base/stl_util-inl.h> |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 14 | #include <base/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 16 | #include <gmock/gmock.h> |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 17 | #include <gtest/gtest.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 18 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 19 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 20 | #include "shill/ephemeral_profile.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 21 | #include "shill/error.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 22 | #include "shill/glib.h" |
| 23 | #include "shill/key_file_store.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 24 | #include "shill/key_value_store.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 25 | #include "shill/mock_adaptors.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 26 | #include "shill/mock_connection.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 27 | #include "shill/mock_control.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 28 | #include "shill/mock_device.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 29 | #include "shill/mock_device_info.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 30 | #include "shill/mock_glib.h" |
| 31 | #include "shill/mock_profile.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 32 | #include "shill/mock_service.h" |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 33 | #include "shill/mock_store.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 34 | #include "shill/mock_wifi.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 35 | #include "shill/property_store_unittest.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 36 | #include "shill/service_under_test.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 37 | #include "shill/wifi_service.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 38 | |
| 39 | using std::map; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 40 | using std::set; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 41 | using std::string; |
| 42 | using std::vector; |
| 43 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 44 | namespace shill { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 45 | using ::testing::_; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 46 | using ::testing::AnyNumber; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 47 | using ::testing::ContainerEq; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 48 | using ::testing::Ne; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 49 | using ::testing::NiceMock; |
| 50 | using ::testing::Return; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 51 | using ::testing::StrEq; |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 52 | using ::testing::StrictMock; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 53 | using ::testing::Test; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 54 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 55 | class ManagerTest : public PropertyStoreTest { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 56 | public: |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 57 | ManagerTest() |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 58 | : mock_wifi_(new NiceMock<MockWiFi>(control_interface(), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 59 | dispatcher(), |
| 60 | manager(), |
| 61 | "wifi0", |
| 62 | "addr4", |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 63 | 4)), |
| 64 | device_info_(new NiceMock<MockDeviceInfo>( |
| 65 | control_interface(), |
| 66 | reinterpret_cast<EventDispatcher*>(NULL), |
| 67 | reinterpret_cast<Manager*>(NULL))), |
| 68 | manager_adaptor_(new NiceMock<ManagerMockAdaptor>()) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 69 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 70 | dispatcher(), |
| 71 | manager(), |
| 72 | "null0", |
| 73 | "addr0", |
| 74 | 0)); |
| 75 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 76 | dispatcher(), |
| 77 | manager(), |
| 78 | "null1", |
| 79 | "addr1", |
| 80 | 1)); |
| 81 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 82 | dispatcher(), |
| 83 | manager(), |
| 84 | "null2", |
| 85 | "addr2", |
| 86 | 2)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 87 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 88 | dispatcher(), |
| 89 | manager(), |
| 90 | "null3", |
| 91 | "addr3", |
| 92 | 3)); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 93 | manager()->connect_profiles_to_rpc_ = false; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 94 | |
| 95 | // Replace the manager's adaptor with a quieter one, and one |
| 96 | // we can do EXPECT*() against. Passes ownership. |
| 97 | manager()->adaptor_.reset(manager_adaptor_); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 98 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 99 | virtual ~ManagerTest() {} |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 100 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 101 | bool IsDeviceRegistered(const DeviceRefPtr &device, |
| 102 | Technology::Identifier tech) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 103 | vector<DeviceRefPtr> devices; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 104 | manager()->FilterByTechnology(tech, &devices); |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 105 | return (devices.size() == 1 && devices[0].get() == device.get()); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 106 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 107 | bool ServiceOrderIs(ServiceRefPtr svc1, ServiceRefPtr svc2); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 108 | |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 109 | void AdoptProfile(Manager *manager, ProfileRefPtr profile) { |
| 110 | manager->profiles_.push_back(profile); |
| 111 | } |
| 112 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 113 | Profile *CreateProfileForManager(Manager *manager, GLib *glib) { |
| 114 | Profile::Identifier id("rather", "irrelevant"); |
| 115 | scoped_ptr<Profile> profile(new Profile(control_interface(), |
| 116 | manager, |
| 117 | id, |
| 118 | "", |
| 119 | false)); |
| 120 | FilePath final_path(storage_path()); |
| 121 | final_path = final_path.Append("test.profile"); |
| 122 | scoped_ptr<KeyFileStore> storage(new KeyFileStore(glib)); |
| 123 | storage->set_path(final_path); |
| 124 | if (!storage->Open()) |
| 125 | return NULL; |
| 126 | profile->set_storage(storage.release()); // Passes ownership. |
| 127 | return profile.release(); |
| 128 | } |
| 129 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 130 | bool CreateBackingStoreForService(ScopedTempDir *temp_dir, |
| 131 | const string &profile_identifier, |
| 132 | const string &service_name) { |
| 133 | GLib glib; |
| 134 | KeyFileStore store(&glib); |
| 135 | store.set_path(temp_dir->path().Append(profile_identifier + ".profile")); |
| 136 | return store.Open() && |
| 137 | store.SetString(service_name, "rather", "irrelevant") && |
| 138 | store.Close(); |
| 139 | } |
| 140 | |
| 141 | Error::Type TestCreateProfile(Manager *manager, const string &name) { |
| 142 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame^] | 143 | string path; |
| 144 | manager->CreateProfile(name, &path, &error); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 145 | return error.type(); |
| 146 | } |
| 147 | |
| 148 | Error::Type TestPopAnyProfile(Manager *manager) { |
| 149 | Error error; |
| 150 | manager->PopAnyProfile(&error); |
| 151 | return error.type(); |
| 152 | } |
| 153 | |
| 154 | Error::Type TestPopProfile(Manager *manager, const string &name) { |
| 155 | Error error; |
| 156 | manager->PopProfile(name, &error); |
| 157 | return error.type(); |
| 158 | } |
| 159 | |
| 160 | Error::Type TestPushProfile(Manager *manager, const string &name) { |
| 161 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame^] | 162 | string path; |
| 163 | manager->PushProfile(name, &path, &error); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 164 | return error.type(); |
| 165 | } |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 166 | protected: |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 167 | scoped_refptr<MockWiFi> mock_wifi_; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 168 | vector<scoped_refptr<MockDevice> > mock_devices_; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 169 | scoped_ptr<MockDeviceInfo> device_info_; |
| 170 | |
| 171 | // This pointer is owned by the manager, and only tracked here for EXPECT*() |
| 172 | ManagerMockAdaptor *manager_adaptor_; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 175 | bool ManagerTest::ServiceOrderIs(ServiceRefPtr svc0, ServiceRefPtr svc1) { |
| 176 | return (svc0.get() == manager()->services_[0].get() && |
| 177 | svc1.get() == manager()->services_[1].get()); |
| 178 | } |
| 179 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 180 | TEST_F(ManagerTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 181 | EXPECT_TRUE(manager()->store().Contains(flimflam::kStateProperty)); |
| 182 | EXPECT_FALSE(manager()->store().Contains("")); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 185 | TEST_F(ManagerTest, DeviceRegistration) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 186 | ON_CALL(*mock_devices_[0].get(), TechnologyIs(Technology::kEthernet)) |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 187 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 188 | ON_CALL(*mock_devices_[1].get(), TechnologyIs(Technology::kWifi)) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 189 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 190 | ON_CALL(*mock_devices_[2].get(), TechnologyIs(Technology::kCellular)) |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 191 | .WillByDefault(Return(true)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 192 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 193 | manager()->RegisterDevice(mock_devices_[0]); |
| 194 | manager()->RegisterDevice(mock_devices_[1]); |
| 195 | manager()->RegisterDevice(mock_devices_[2]); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 196 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 197 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
| 198 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
| 199 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[2], Technology::kCellular)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 202 | TEST_F(ManagerTest, DeviceRegistrationAndStart) { |
| 203 | manager()->running_ = true; |
| 204 | mock_devices_[0]->powered_ = true; |
| 205 | mock_devices_[1]->powered_ = false; |
| 206 | EXPECT_CALL(*mock_devices_[0].get(), Start()) |
| 207 | .Times(1); |
| 208 | EXPECT_CALL(*mock_devices_[1].get(), Start()) |
| 209 | .Times(0); |
| 210 | manager()->RegisterDevice(mock_devices_[0]); |
| 211 | manager()->RegisterDevice(mock_devices_[1]); |
| 212 | } |
| 213 | |
| 214 | TEST_F(ManagerTest, DeviceRegistrationWithProfile) { |
| 215 | MockProfile *profile = new MockProfile(control_interface(), manager(), ""); |
| 216 | DeviceRefPtr device_ref(mock_devices_[0].get()); |
| 217 | AdoptProfile(manager(), profile); // Passes ownership. |
| 218 | EXPECT_CALL(*profile, ConfigureDevice(device_ref)); |
| 219 | EXPECT_CALL(*profile, Save()); |
| 220 | manager()->RegisterDevice(mock_devices_[0]); |
| 221 | } |
| 222 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 223 | TEST_F(ManagerTest, DeviceDeregistration) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 224 | ON_CALL(*mock_devices_[0].get(), TechnologyIs(Technology::kEthernet)) |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 225 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 226 | ON_CALL(*mock_devices_[1].get(), TechnologyIs(Technology::kWifi)) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 227 | .WillByDefault(Return(true)); |
| 228 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 229 | manager()->RegisterDevice(mock_devices_[0]); |
| 230 | manager()->RegisterDevice(mock_devices_[1]); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 231 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 232 | ASSERT_TRUE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
| 233 | ASSERT_TRUE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 234 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 235 | EXPECT_CALL(*mock_devices_[0].get(), Stop()); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 236 | manager()->DeregisterDevice(mock_devices_[0]); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 237 | EXPECT_FALSE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 238 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 239 | EXPECT_CALL(*mock_devices_[1].get(), Stop()); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 240 | manager()->DeregisterDevice(mock_devices_[1]); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 241 | EXPECT_FALSE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | TEST_F(ManagerTest, ServiceRegistration) { |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 245 | // It's much easier and safer to use a real GLib for this test. |
| 246 | GLib glib; |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 247 | Manager manager(control_interface(), |
| 248 | dispatcher(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 249 | &glib, |
| 250 | run_path(), |
| 251 | storage_path(), |
| 252 | string()); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 253 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 254 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 255 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 256 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 257 | scoped_refptr<MockService> mock_service( |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 258 | new NiceMock<MockService>(control_interface(), |
| 259 | dispatcher(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 260 | &manager)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 261 | scoped_refptr<MockService> mock_service2( |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 262 | new NiceMock<MockService>(control_interface(), |
| 263 | dispatcher(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 264 | &manager)); |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 265 | string service1_name(mock_service->UniqueName()); |
| 266 | string service2_name(mock_service2->UniqueName()); |
| 267 | |
| 268 | EXPECT_CALL(*mock_service.get(), GetRpcIdentifier()) |
| 269 | .WillRepeatedly(Return(service1_name)); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 270 | EXPECT_CALL(*mock_service2.get(), GetRpcIdentifier()) |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 271 | .WillRepeatedly(Return(service2_name)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 272 | // TODO(quiche): make this EXPECT_CALL work (crosbug.com/20154) |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 273 | // EXPECT_CALL(*dynamic_cast<ManagerMockAdaptor *>(manager.adaptor_.get()), |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 274 | // EmitRpcIdentifierArrayChanged(flimflam::kServicesProperty, _)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 275 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 276 | manager.RegisterService(mock_service); |
| 277 | manager.RegisterService(mock_service2); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 278 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 279 | Error error; |
| 280 | vector<string> rpc_ids = manager.EnumerateAvailableServices(&error); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 281 | set<string> ids(rpc_ids.begin(), rpc_ids.end()); |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 282 | EXPECT_EQ(2, ids.size()); |
| 283 | EXPECT_TRUE(ContainsKey(ids, mock_service->GetRpcIdentifier())); |
| 284 | EXPECT_TRUE(ContainsKey(ids, mock_service2->GetRpcIdentifier())); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 285 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 286 | EXPECT_TRUE(manager.FindService(service1_name).get() != NULL); |
| 287 | EXPECT_TRUE(manager.FindService(service2_name).get() != NULL); |
| 288 | |
| 289 | manager.Stop(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 292 | TEST_F(ManagerTest, RegisterKnownService) { |
| 293 | // It's much easier and safer to use a real GLib for this test. |
| 294 | GLib glib; |
| 295 | Manager manager(control_interface(), |
| 296 | dispatcher(), |
| 297 | &glib, |
| 298 | run_path(), |
| 299 | storage_path(), |
| 300 | string()); |
| 301 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 302 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 303 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 304 | { |
| 305 | ServiceRefPtr service1(new ServiceUnderTest(control_interface(), |
| 306 | dispatcher(), |
| 307 | &manager)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 308 | ASSERT_TRUE(profile->AdoptService(service1)); |
| 309 | ASSERT_TRUE(profile->ContainsService(service1)); |
| 310 | } // Force destruction of service1. |
| 311 | |
| 312 | ServiceRefPtr service2(new ServiceUnderTest(control_interface(), |
| 313 | dispatcher(), |
| 314 | &manager)); |
| 315 | manager.RegisterService(service2); |
| 316 | EXPECT_EQ(service2->profile().get(), profile.get()); |
| 317 | manager.Stop(); |
| 318 | } |
| 319 | |
| 320 | TEST_F(ManagerTest, RegisterUnknownService) { |
| 321 | // It's much easier and safer to use a real GLib for this test. |
| 322 | GLib glib; |
| 323 | Manager manager(control_interface(), |
| 324 | dispatcher(), |
| 325 | &glib, |
| 326 | run_path(), |
| 327 | storage_path(), |
| 328 | string()); |
| 329 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 330 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 331 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 332 | { |
| 333 | ServiceRefPtr service1(new ServiceUnderTest(control_interface(), |
| 334 | dispatcher(), |
| 335 | &manager)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 336 | ASSERT_TRUE(profile->AdoptService(service1)); |
| 337 | ASSERT_TRUE(profile->ContainsService(service1)); |
| 338 | } // Force destruction of service1. |
| 339 | scoped_refptr<MockService> mock_service2( |
| 340 | new NiceMock<MockService>(control_interface(), |
| 341 | dispatcher(), |
| 342 | &manager)); |
| 343 | EXPECT_CALL(*mock_service2.get(), GetStorageIdentifier()) |
| 344 | .WillRepeatedly(Return(mock_service2->UniqueName())); |
| 345 | manager.RegisterService(mock_service2); |
| 346 | EXPECT_NE(mock_service2->profile().get(), profile.get()); |
| 347 | manager.Stop(); |
| 348 | } |
| 349 | |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 350 | TEST_F(ManagerTest, GetProperties) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 351 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 352 | AdoptProfile(manager(), profile); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 353 | map<string, ::DBus::Variant> props; |
| 354 | Error error(Error::kInvalidProperty, ""); |
| 355 | { |
| 356 | ::DBus::Error dbus_error; |
| 357 | string expected("portal_list"); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 358 | manager()->mutable_store()->SetStringProperty( |
| 359 | flimflam::kCheckPortalListProperty, |
| 360 | expected, |
| 361 | &error); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 362 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 363 | ASSERT_FALSE(props.find(flimflam::kCheckPortalListProperty) == props.end()); |
| 364 | EXPECT_EQ(props[flimflam::kCheckPortalListProperty].reader().get_string(), |
| 365 | expected); |
| 366 | } |
| 367 | { |
| 368 | ::DBus::Error dbus_error; |
| 369 | bool expected = true; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 370 | manager()->mutable_store()->SetBoolProperty(flimflam::kOfflineModeProperty, |
| 371 | expected, |
| 372 | &error); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 373 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 374 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 375 | EXPECT_EQ(props[flimflam::kOfflineModeProperty].reader().get_bool(), |
| 376 | expected); |
| 377 | } |
| 378 | } |
| 379 | |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 380 | TEST_F(ManagerTest, GetDevicesProperty) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 381 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 382 | AdoptProfile(manager(), profile); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 383 | manager()->RegisterDevice(mock_devices_[0]); |
| 384 | manager()->RegisterDevice(mock_devices_[1]); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 385 | { |
| 386 | map<string, ::DBus::Variant> props; |
| 387 | ::DBus::Error dbus_error; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 388 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 389 | ASSERT_FALSE(props.find(flimflam::kDevicesProperty) == props.end()); |
| 390 | Strings devices = |
| 391 | props[flimflam::kDevicesProperty].operator vector<string>(); |
| 392 | EXPECT_EQ(2, devices.size()); |
| 393 | } |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 396 | TEST_F(ManagerTest, MoveService) { |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 397 | Manager manager(control_interface(), |
| 398 | dispatcher(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 399 | glib(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 400 | run_path(), |
| 401 | storage_path(), |
| 402 | string()); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 403 | scoped_refptr<MockService> s2(new MockService(control_interface(), |
| 404 | dispatcher(), |
| 405 | &manager)); |
| 406 | // Inject an actual profile, backed by a fake StoreInterface |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 407 | { |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 408 | Profile::Identifier id("irrelevant"); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 409 | ProfileRefPtr profile( |
| 410 | new Profile(control_interface(), &manager, id, "", false)); |
| 411 | MockStore *storage = new MockStore; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 412 | // Say we don't have |s2| the first time asked, then that we do. |
| 413 | EXPECT_CALL(*storage, ContainsGroup(s2->GetStorageIdentifier())) |
| 414 | .WillOnce(Return(false)) |
| 415 | .WillRepeatedly(Return(true)); |
| 416 | EXPECT_CALL(*storage, Flush()) |
| 417 | .Times(AnyNumber()) |
| 418 | .WillRepeatedly(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 419 | profile->set_storage(storage); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 420 | AdoptProfile(&manager, profile); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 421 | } |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 422 | // Create a profile that already has |s2| in it. |
| 423 | ProfileRefPtr profile(new EphemeralProfile(control_interface(), &manager)); |
| 424 | profile->AdoptService(s2); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 425 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 426 | // Now, move the Service |s2| to another profile. |
| 427 | EXPECT_CALL(*s2.get(), Save(_)).WillOnce(Return(true)); |
| 428 | ASSERT_TRUE(manager.MoveServiceToProfile(s2, manager.ActiveProfile())); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 429 | |
| 430 | // Force destruction of the original Profile, to ensure that the Service |
| 431 | // is kept alive and populated with data. |
| 432 | profile = NULL; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 433 | ASSERT_TRUE(manager.ActiveProfile()->ContainsService(s2)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 434 | manager.Stop(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 437 | TEST_F(ManagerTest, CreateProfile) { |
| 438 | // It's much easier to use real Glib here since we want the storage |
| 439 | // side-effects. |
| 440 | GLib glib; |
| 441 | ScopedTempDir temp_dir; |
| 442 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 443 | |
| 444 | Manager manager(control_interface(), |
| 445 | dispatcher(), |
| 446 | &glib, |
| 447 | run_path(), |
| 448 | storage_path(), |
| 449 | temp_dir.path().value()); |
| 450 | |
| 451 | // Invalid name should be rejected. |
| 452 | EXPECT_EQ(Error::kInvalidArguments, TestCreateProfile(&manager, "")); |
| 453 | |
| 454 | // Valid name is still rejected because we can't create a profile |
| 455 | // that doesn't have a user component. Such profile names are |
| 456 | // reserved for the single DefaultProfile the manager creates |
| 457 | // at startup. |
| 458 | EXPECT_EQ(Error::kInvalidArguments, TestCreateProfile(&manager, "valid")); |
| 459 | |
| 460 | // We should succeed in creating a valid user profile. |
| 461 | const char kProfile[] = "~user/profile"; |
| 462 | EXPECT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile)); |
| 463 | |
| 464 | // We should fail in creating it a second time (already exists). |
| 465 | EXPECT_EQ(Error::kAlreadyExists, TestCreateProfile(&manager, kProfile)); |
| 466 | } |
| 467 | |
| 468 | TEST_F(ManagerTest, PushPopProfile) { |
| 469 | // It's much easier to use real Glib in creating a Manager for this |
| 470 | // test here since we want the storage side-effects. |
| 471 | GLib glib; |
| 472 | ScopedTempDir temp_dir; |
| 473 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 474 | Manager manager(control_interface(), |
| 475 | dispatcher(), |
| 476 | &glib, |
| 477 | run_path(), |
| 478 | storage_path(), |
| 479 | temp_dir.path().value()); |
| 480 | |
| 481 | // Pushing an invalid profile should fail. |
| 482 | EXPECT_EQ(Error::kInvalidArguments, TestPushProfile(&manager, "")); |
| 483 | |
| 484 | // Pushing a default profile name should fail. |
| 485 | EXPECT_EQ(Error::kInvalidArguments, TestPushProfile(&manager, "default")); |
| 486 | |
| 487 | const char kProfile0[] = "~user/profile0"; |
| 488 | const char kProfile1[] = "~user/profile1"; |
| 489 | |
| 490 | // Create a couple of profiles. |
| 491 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile0)); |
| 492 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile1)); |
| 493 | |
| 494 | // Push these profiles on the stack. |
| 495 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 496 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile1)); |
| 497 | |
| 498 | // Pushing a profile a second time should fail. |
| 499 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile0)); |
| 500 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile1)); |
| 501 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 502 | Error error; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 503 | // Active profile should be the last one we pushed. |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 504 | EXPECT_EQ(kProfile1, "~" + manager.GetActiveProfileName(&error)); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 505 | |
| 506 | // Make sure a profile name that doesn't exist fails. |
| 507 | const char kProfile2Id[] = "profile2"; |
| 508 | const string kProfile2 = base::StringPrintf("~user/%s", kProfile2Id); |
| 509 | EXPECT_EQ(Error::kNotFound, TestPushProfile(&manager, kProfile2)); |
| 510 | |
| 511 | // Create a new service, with a specific storage name. |
| 512 | scoped_refptr<MockService> service( |
| 513 | new NiceMock<MockService>(control_interface(), |
| 514 | dispatcher(), |
| 515 | &manager)); |
| 516 | const char kServiceName[] = "service_storage_name"; |
| 517 | EXPECT_CALL(*service.get(), GetStorageIdentifier()) |
| 518 | .WillRepeatedly(Return(kServiceName)); |
| 519 | EXPECT_CALL(*service.get(), Load(_)) |
| 520 | .WillRepeatedly(Return(true)); |
| 521 | |
| 522 | // Add this service to the manager -- it should end up in the ephemeral |
| 523 | // profile. |
| 524 | manager.RegisterService(service); |
| 525 | ASSERT_EQ(manager.ephemeral_profile_, service->profile()); |
| 526 | |
| 527 | // Create storage for a profile that contains the service storage name. |
| 528 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile2Id, |
| 529 | kServiceName)); |
| 530 | |
| 531 | // When we push the profile, the service should move away from the |
| 532 | // ephemeral profile to this new profile since it has an entry for |
| 533 | // this service. |
| 534 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile2)); |
| 535 | EXPECT_NE(manager.ephemeral_profile_, service->profile()); |
| 536 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 537 | |
| 538 | // Insert another profile that should supersede ownership of the service. |
| 539 | const char kProfile3Id[] = "profile3"; |
| 540 | const string kProfile3 = base::StringPrintf("~user/%s", kProfile3Id); |
| 541 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile3Id, |
| 542 | kServiceName)); |
| 543 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile3)); |
| 544 | EXPECT_EQ(kProfile3, "~" + service->profile()->GetFriendlyName()); |
| 545 | |
| 546 | // Popping an invalid profile name should fail. |
| 547 | EXPECT_EQ(Error::kInvalidArguments, TestPopProfile(&manager, "~")); |
| 548 | |
| 549 | // Popping an profile that is not at the top of the stack should fail. |
| 550 | EXPECT_EQ(Error::kNotSupported, TestPopProfile(&manager, kProfile0)); |
| 551 | |
| 552 | // Popping the top profile should succeed. |
| 553 | EXPECT_EQ(Error::kSuccess, TestPopProfile(&manager, kProfile3)); |
| 554 | |
| 555 | // Moreover the service should have switched profiles to profile 2. |
| 556 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 557 | |
| 558 | // Popping the top profile should succeed. |
| 559 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 560 | |
| 561 | // The service should now revert to the ephemeral profile. |
| 562 | EXPECT_EQ(manager.ephemeral_profile_, service->profile()); |
| 563 | |
| 564 | // Pop the remaining two services off the stack. |
| 565 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 566 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 567 | |
| 568 | // Next pop should fail with "stack is empty". |
| 569 | EXPECT_EQ(Error::kNotFound, TestPopAnyProfile(&manager)); |
| 570 | } |
| 571 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 572 | TEST_F(ManagerTest, Dispatch) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 573 | { |
| 574 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 575 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 576 | flimflam::kOfflineModeProperty, |
| 577 | PropertyStoreTest::kBoolV, |
| 578 | &error)); |
| 579 | } |
| 580 | { |
| 581 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 582 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 583 | flimflam::kCountryProperty, |
| 584 | PropertyStoreTest::kStringV, |
| 585 | &error)); |
| 586 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 587 | // Attempt to write with value of wrong type should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 588 | { |
| 589 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 590 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 591 | flimflam::kCountryProperty, |
| 592 | PropertyStoreTest::kBoolV, |
| 593 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 594 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 595 | } |
| 596 | { |
| 597 | ::DBus::Error error; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 598 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 599 | flimflam::kOfflineModeProperty, |
| 600 | PropertyStoreTest::kStringV, |
| 601 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 602 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 603 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 604 | // Attempt to write R/O property should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 605 | { |
| 606 | ::DBus::Error error; |
| 607 | EXPECT_FALSE(DBusAdaptor::DispatchOnType( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 608 | manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 609 | flimflam::kEnabledTechnologiesProperty, |
| 610 | PropertyStoreTest::kStringsV, |
| 611 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 612 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 613 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 614 | } |
| 615 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 616 | TEST_F(ManagerTest, RequestScan) { |
| 617 | { |
| 618 | Error error; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 619 | manager()->RegisterDevice(mock_devices_[0].get()); |
| 620 | manager()->RegisterDevice(mock_devices_[1].get()); |
| 621 | EXPECT_CALL(*mock_devices_[0], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 622 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 623 | EXPECT_CALL(*mock_devices_[0], Scan(_)); |
| 624 | EXPECT_CALL(*mock_devices_[1], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 625 | .WillRepeatedly(Return(false)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 626 | EXPECT_CALL(*mock_devices_[1], Scan(_)).Times(0); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 627 | manager()->RequestScan(flimflam::kTypeWifi, &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | { |
| 631 | Error error; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 632 | manager()->RequestScan("bogus_device_type", &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 633 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 634 | } |
| 635 | } |
| 636 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 637 | TEST_F(ManagerTest, GetWifiServiceNoDevice) { |
| 638 | KeyValueStore args; |
| 639 | Error e; |
| 640 | manager()->GetWifiService(args, &e); |
| 641 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 642 | EXPECT_EQ("no wifi devices available", e.message()); |
| 643 | } |
| 644 | |
| 645 | TEST_F(ManagerTest, GetWifiService) { |
| 646 | KeyValueStore args; |
| 647 | Error e; |
| 648 | WiFiServiceRefPtr wifi_service; |
| 649 | |
| 650 | manager()->RegisterDevice(mock_wifi_); |
| 651 | EXPECT_CALL(*mock_wifi_, GetService(_, _)) |
| 652 | .WillRepeatedly(Return(wifi_service)); |
| 653 | manager()->GetWifiService(args, &e); |
| 654 | } |
| 655 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 656 | TEST_F(ManagerTest, TechnologyOrder) { |
| 657 | Error error; |
| 658 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "," + |
| 659 | string(flimflam::kTypeWifi), &error); |
| 660 | ASSERT_TRUE(error.IsSuccess()); |
| 661 | EXPECT_EQ(manager()->GetTechnologyOrder(), |
| 662 | string(flimflam::kTypeEthernet) + "," + |
| 663 | string(flimflam::kTypeWifi)); |
| 664 | |
| 665 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "x," + |
| 666 | string(flimflam::kTypeWifi), &error); |
| 667 | ASSERT_FALSE(error.IsSuccess()); |
| 668 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 669 | EXPECT_EQ(string(flimflam::kTypeEthernet) + "," + |
| 670 | string(flimflam::kTypeWifi), |
| 671 | manager()->GetTechnologyOrder()); |
| 672 | } |
| 673 | |
| 674 | TEST_F(ManagerTest, SortServices) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 675 | // TODO(quiche): Some of these tests would probably fit better in |
| 676 | // service_unittest, since the actual comparison of Services is |
| 677 | // implemented in Service. (crosbug.com/23370) |
| 678 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 679 | scoped_refptr<MockService> mock_service0( |
| 680 | new NiceMock<MockService>(control_interface(), |
| 681 | dispatcher(), |
| 682 | manager())); |
| 683 | scoped_refptr<MockService> mock_service1( |
| 684 | new NiceMock<MockService>(control_interface(), |
| 685 | dispatcher(), |
| 686 | manager())); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 687 | |
| 688 | manager()->RegisterService(mock_service0); |
| 689 | manager()->RegisterService(mock_service1); |
| 690 | |
| 691 | // Services should already be sorted by UniqueName |
| 692 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 693 | |
| 694 | // Asking explictly to sort services should not change anything |
| 695 | manager()->SortServices(); |
| 696 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 697 | |
| 698 | // Two otherwise equal services should be reordered by strength |
| 699 | mock_service1->set_strength(1); |
| 700 | manager()->UpdateService(mock_service1); |
| 701 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 702 | |
| 703 | // Security |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 704 | mock_service0->set_security_level(1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 705 | manager()->UpdateService(mock_service0); |
| 706 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 707 | |
| 708 | // Technology |
| 709 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Technology::kWifi)) |
| 710 | .WillRepeatedly(Return(true)); |
| 711 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Technology::kEthernet)) |
| 712 | .WillRepeatedly(Return(true)); |
| 713 | // NB: Redefine default (false) return values so we don't use the default rule |
| 714 | // which makes the logs noisier |
| 715 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Ne(Technology::kWifi))) |
| 716 | .WillRepeatedly(Return(false)); |
| 717 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Ne(Technology::kEthernet))) |
| 718 | .WillRepeatedly(Return(false)); |
| 719 | |
| 720 | Error error; |
| 721 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "," + |
| 722 | string(flimflam::kTypeWifi), &error); |
| 723 | EXPECT_TRUE(error.IsSuccess()); |
| 724 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 725 | |
| 726 | manager()->SetTechnologyOrder(string(flimflam::kTypeWifi) + "," + |
| 727 | string(flimflam::kTypeEthernet), &error); |
| 728 | EXPECT_TRUE(error.IsSuccess()); |
| 729 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 730 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 731 | // Priority. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 732 | mock_service0->set_priority(1); |
| 733 | manager()->UpdateService(mock_service0); |
| 734 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 735 | |
| 736 | // Favorite |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 737 | mock_service1->MakeFavorite(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 738 | manager()->UpdateService(mock_service1); |
| 739 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 740 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 741 | // Connecting. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 742 | EXPECT_CALL(*mock_service0.get(), state()) |
| 743 | .WillRepeatedly(Return(Service::kStateAssociating)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 744 | EXPECT_CALL(*mock_service0.get(), IsConnecting()) |
| 745 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 746 | manager()->UpdateService(mock_service0); |
| 747 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 748 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 749 | // Connected. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 750 | EXPECT_CALL(*mock_service1.get(), state()) |
| 751 | .WillRepeatedly(Return(Service::kStateConnected)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 752 | EXPECT_CALL(*mock_service1.get(), IsConnected()) |
| 753 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 754 | manager()->UpdateService(mock_service1); |
| 755 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 756 | |
| 757 | manager()->DeregisterService(mock_service0); |
| 758 | manager()->DeregisterService(mock_service1); |
| 759 | } |
| 760 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 761 | TEST_F(ManagerTest, SortServicesWithConnection) { |
| 762 | scoped_refptr<MockService> mock_service0( |
| 763 | new NiceMock<MockService>(control_interface(), |
| 764 | dispatcher(), |
| 765 | manager())); |
| 766 | scoped_refptr<MockService> mock_service1( |
| 767 | new NiceMock<MockService>(control_interface(), |
| 768 | dispatcher(), |
| 769 | manager())); |
| 770 | |
| 771 | scoped_refptr<MockConnection> mock_connection0( |
| 772 | new NiceMock<MockConnection>(device_info_.get())); |
| 773 | scoped_refptr<MockConnection> mock_connection1( |
| 774 | new NiceMock<MockConnection>(device_info_.get())); |
| 775 | |
| 776 | manager()->RegisterService(mock_service0); |
| 777 | manager()->RegisterService(mock_service1); |
| 778 | |
| 779 | mock_service0->connection_ = mock_connection0; |
| 780 | mock_service1->connection_ = mock_connection1; |
| 781 | |
| 782 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
| 783 | manager()->SortServices(); |
| 784 | |
| 785 | mock_service1->set_priority(1); |
| 786 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(false)); |
| 787 | EXPECT_CALL(*mock_connection1.get(), SetIsDefault(true)); |
| 788 | manager()->SortServices(); |
| 789 | |
| 790 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
| 791 | mock_service1->connection_ = NULL; |
| 792 | manager()->DeregisterService(mock_service1); |
| 793 | |
| 794 | mock_service0->connection_ = NULL; |
| 795 | manager()->DeregisterService(mock_service0); |
| 796 | } |
| 797 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 798 | TEST_F(ManagerTest, AvailableTechnologies) { |
| 799 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 800 | dispatcher(), |
| 801 | manager(), |
| 802 | "null4", |
| 803 | "addr4", |
| 804 | 0)); |
| 805 | manager()->RegisterDevice(mock_devices_[0]); |
| 806 | manager()->RegisterDevice(mock_devices_[1]); |
| 807 | manager()->RegisterDevice(mock_devices_[2]); |
| 808 | manager()->RegisterDevice(mock_devices_[3]); |
| 809 | |
| 810 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 811 | .WillByDefault(Return(Technology::kEthernet)); |
| 812 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 813 | .WillByDefault(Return(Technology::kWifi)); |
| 814 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 815 | .WillByDefault(Return(Technology::kCellular)); |
| 816 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 817 | .WillByDefault(Return(Technology::kWifi)); |
| 818 | |
| 819 | set<string> expected_technologies; |
| 820 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 821 | Technology::kEthernet)); |
| 822 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 823 | Technology::kWifi)); |
| 824 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 825 | Technology::kCellular)); |
| 826 | Error error; |
| 827 | vector<string> technologies = manager()->AvailableTechnologies(&error); |
| 828 | |
| 829 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 830 | ContainerEq(expected_technologies)); |
| 831 | } |
| 832 | |
| 833 | TEST_F(ManagerTest, ConnectedTechnologies) { |
| 834 | scoped_refptr<MockService> connected_service1( |
| 835 | new NiceMock<MockService>(control_interface(), |
| 836 | dispatcher(), |
| 837 | manager())); |
| 838 | scoped_refptr<MockService> connected_service2( |
| 839 | new NiceMock<MockService>(control_interface(), |
| 840 | dispatcher(), |
| 841 | manager())); |
| 842 | scoped_refptr<MockService> disconnected_service1( |
| 843 | new NiceMock<MockService>(control_interface(), |
| 844 | dispatcher(), |
| 845 | manager())); |
| 846 | scoped_refptr<MockService> disconnected_service2( |
| 847 | new NiceMock<MockService>(control_interface(), |
| 848 | dispatcher(), |
| 849 | manager())); |
| 850 | |
| 851 | ON_CALL(*connected_service1.get(), IsConnected()) |
| 852 | .WillByDefault(Return(true)); |
| 853 | ON_CALL(*connected_service2.get(), IsConnected()) |
| 854 | .WillByDefault(Return(true)); |
| 855 | |
| 856 | manager()->RegisterService(connected_service1); |
| 857 | manager()->RegisterService(connected_service2); |
| 858 | manager()->RegisterService(disconnected_service1); |
| 859 | manager()->RegisterService(disconnected_service2); |
| 860 | |
| 861 | manager()->RegisterDevice(mock_devices_[0]); |
| 862 | manager()->RegisterDevice(mock_devices_[1]); |
| 863 | manager()->RegisterDevice(mock_devices_[2]); |
| 864 | manager()->RegisterDevice(mock_devices_[3]); |
| 865 | |
| 866 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 867 | .WillByDefault(Return(Technology::kEthernet)); |
| 868 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 869 | .WillByDefault(Return(Technology::kWifi)); |
| 870 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 871 | .WillByDefault(Return(Technology::kCellular)); |
| 872 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 873 | .WillByDefault(Return(Technology::kWifi)); |
| 874 | |
| 875 | mock_devices_[0]->SelectService(connected_service1); |
| 876 | mock_devices_[1]->SelectService(disconnected_service1); |
| 877 | mock_devices_[2]->SelectService(disconnected_service2); |
| 878 | mock_devices_[3]->SelectService(connected_service2); |
| 879 | |
| 880 | set<string> expected_technologies; |
| 881 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 882 | Technology::kEthernet)); |
| 883 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 884 | Technology::kWifi)); |
| 885 | Error error; |
| 886 | |
| 887 | vector<string> technologies = manager()->ConnectedTechnologies(&error); |
| 888 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 889 | ContainerEq(expected_technologies)); |
| 890 | } |
| 891 | |
| 892 | TEST_F(ManagerTest, DefaultTechnology) { |
| 893 | scoped_refptr<MockService> connected_service( |
| 894 | new NiceMock<MockService>(control_interface(), |
| 895 | dispatcher(), |
| 896 | manager())); |
| 897 | scoped_refptr<MockService> disconnected_service( |
| 898 | new NiceMock<MockService>(control_interface(), |
| 899 | dispatcher(), |
| 900 | manager())); |
| 901 | |
| 902 | // Connected. WiFi. |
| 903 | ON_CALL(*connected_service.get(), IsConnected()) |
| 904 | .WillByDefault(Return(true)); |
| 905 | ON_CALL(*connected_service.get(), state()) |
| 906 | .WillByDefault(Return(Service::kStateConnected)); |
| 907 | ON_CALL(*connected_service.get(), technology()) |
| 908 | .WillByDefault(Return(Technology::kWifi)); |
| 909 | |
| 910 | // Disconnected. Ethernet. |
| 911 | ON_CALL(*disconnected_service.get(), technology()) |
| 912 | .WillByDefault(Return(Technology::kEthernet)); |
| 913 | |
| 914 | manager()->RegisterService(disconnected_service); |
| 915 | Error error; |
| 916 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq("")); |
| 917 | |
| 918 | |
| 919 | manager()->RegisterService(connected_service); |
| 920 | // Connected service should be brought to the front now. |
| 921 | string expected_technology = |
| 922 | Technology::NameFromIdentifier(Technology::kWifi); |
| 923 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq(expected_technology)); |
| 924 | } |
| 925 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 926 | TEST_F(ManagerTest, DisconnectServicesOnStop) { |
| 927 | scoped_refptr<MockService> mock_service( |
| 928 | new NiceMock<MockService>(control_interface(), |
| 929 | dispatcher(), |
| 930 | manager())); |
| 931 | manager()->RegisterService(mock_service); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 932 | EXPECT_CALL(*mock_service.get(), Disconnect(_)).Times(1); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 933 | manager()->Stop(); |
| 934 | } |
| 935 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 936 | TEST_F(ManagerTest, UpdateServiceConnected) { |
| 937 | scoped_refptr<MockService> mock_service( |
| 938 | new NiceMock<MockService>(control_interface(), |
| 939 | dispatcher(), |
| 940 | manager())); |
| 941 | manager()->RegisterService(mock_service); |
| 942 | EXPECT_FALSE(mock_service->favorite()); |
| 943 | EXPECT_FALSE(mock_service->auto_connect()); |
| 944 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 945 | EXPECT_CALL(*mock_service.get(), IsConnected()) |
| 946 | .WillRepeatedly(Return(true)); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 947 | manager()->UpdateService(mock_service); |
| 948 | // We can't EXPECT_CALL(..., MakeFavorite), because that requires us |
| 949 | // to mock out MakeFavorite. And mocking that out would break the |
| 950 | // SortServices test. (crosbug.com/23370) |
| 951 | EXPECT_TRUE(mock_service->favorite()); |
| 952 | EXPECT_TRUE(mock_service->auto_connect()); |
| 953 | } |
| 954 | |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 955 | TEST_F(ManagerTest, SaveSuccessfulService) { |
| 956 | scoped_refptr<MockProfile> profile( |
| 957 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 958 | AdoptProfile(manager(), profile); |
| 959 | scoped_refptr<MockService> service( |
| 960 | new NiceMock<MockService>(control_interface(), |
| 961 | dispatcher(), |
| 962 | manager())); |
| 963 | |
| 964 | // Re-cast this back to a ServiceRefPtr, so EXPECT arguments work correctly. |
| 965 | ServiceRefPtr expect_service(service.get()); |
| 966 | |
| 967 | EXPECT_CALL(*profile.get(), ConfigureService(expect_service)) |
| 968 | .WillOnce(Return(false)); |
| 969 | manager()->RegisterService(service); |
| 970 | |
| 971 | EXPECT_CALL(*service.get(), state()) |
| 972 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 973 | EXPECT_CALL(*service.get(), IsConnected()) |
| 974 | .WillRepeatedly(Return(true)); |
| 975 | EXPECT_CALL(*profile.get(), AdoptService(expect_service)) |
| 976 | .WillOnce(Return(true)); |
| 977 | manager()->UpdateService(service); |
| 978 | } |
| 979 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 980 | } // namespace shill |