mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -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. |
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 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 11 | #include <base/file_util.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 12 | #include <base/logging.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 13 | #include <base/scoped_temp_dir.h> |
| 14 | #include <base/stl_util.h> |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 15 | #include <base/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 17 | #include <gmock/gmock.h> |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 19 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 20 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 21 | #include "shill/ephemeral_profile.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 22 | #include "shill/error.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 23 | #include "shill/glib.h" |
| 24 | #include "shill/key_file_store.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 25 | #include "shill/key_value_store.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 26 | #include "shill/mock_adaptors.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 27 | #include "shill/mock_connection.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 28 | #include "shill/mock_control.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 29 | #include "shill/mock_device.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 30 | #include "shill/mock_device_info.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | #include "shill/mock_glib.h" |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 32 | #include "shill/mock_metrics.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 33 | #include "shill/mock_profile.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 34 | #include "shill/mock_service.h" |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 35 | #include "shill/mock_store.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 36 | #include "shill/mock_wifi.h" |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 37 | #include "shill/mock_wifi_service.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 38 | #include "shill/property_store_unittest.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 39 | #include "shill/service_under_test.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 40 | #include "shill/wifi_service.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 41 | |
| 42 | using std::map; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 43 | using std::set; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 44 | using std::string; |
| 45 | using std::vector; |
| 46 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 47 | namespace shill { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 48 | using ::testing::_; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 49 | using ::testing::AnyNumber; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 50 | using ::testing::ContainerEq; |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 51 | using ::testing::InSequence; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 52 | using ::testing::Ne; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 53 | using ::testing::NiceMock; |
| 54 | using ::testing::Return; |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 55 | using ::testing::ReturnRef; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 56 | using ::testing::StrEq; |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 57 | using ::testing::StrictMock; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 58 | using ::testing::Test; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 59 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 60 | class ManagerTest : public PropertyStoreTest { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 61 | public: |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 62 | ManagerTest() |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 63 | : mock_wifi_(new NiceMock<MockWiFi>(control_interface(), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 64 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 65 | metrics(), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 66 | manager(), |
| 67 | "wifi0", |
| 68 | "addr4", |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 69 | 4)), |
| 70 | device_info_(new NiceMock<MockDeviceInfo>( |
| 71 | control_interface(), |
| 72 | reinterpret_cast<EventDispatcher*>(NULL), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 73 | reinterpret_cast<Metrics*>(NULL), |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 74 | reinterpret_cast<Manager*>(NULL))), |
| 75 | manager_adaptor_(new NiceMock<ManagerMockAdaptor>()) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 76 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 77 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 78 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 79 | manager(), |
| 80 | "null0", |
| 81 | "addr0", |
| 82 | 0)); |
| 83 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 84 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 85 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 86 | manager(), |
| 87 | "null1", |
| 88 | "addr1", |
| 89 | 1)); |
| 90 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 91 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 92 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 93 | manager(), |
| 94 | "null2", |
| 95 | "addr2", |
| 96 | 2)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 97 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 98 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 99 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 100 | manager(), |
| 101 | "null3", |
| 102 | "addr3", |
| 103 | 3)); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 104 | manager()->connect_profiles_to_rpc_ = false; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 105 | |
| 106 | // Replace the manager's adaptor with a quieter one, and one |
| 107 | // we can do EXPECT*() against. Passes ownership. |
| 108 | manager()->adaptor_.reset(manager_adaptor_); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 109 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 110 | virtual ~ManagerTest() {} |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 111 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 112 | bool IsDeviceRegistered(const DeviceRefPtr &device, |
| 113 | Technology::Identifier tech) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 114 | vector<DeviceRefPtr> devices; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 115 | manager()->FilterByTechnology(tech, &devices); |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 116 | return (devices.size() == 1 && devices[0].get() == device.get()); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 117 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 118 | bool ServiceOrderIs(ServiceRefPtr svc1, ServiceRefPtr svc2); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 119 | |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 120 | void AdoptProfile(Manager *manager, ProfileRefPtr profile) { |
| 121 | manager->profiles_.push_back(profile); |
| 122 | } |
| 123 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 124 | ProfileRefPtr GetEphemeralProfile(Manager *manager) { |
| 125 | return manager->ephemeral_profile_; |
| 126 | } |
| 127 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 128 | Profile *CreateProfileForManager(Manager *manager, GLib *glib) { |
| 129 | Profile::Identifier id("rather", "irrelevant"); |
| 130 | scoped_ptr<Profile> profile(new Profile(control_interface(), |
| 131 | manager, |
| 132 | id, |
| 133 | "", |
| 134 | false)); |
| 135 | FilePath final_path(storage_path()); |
| 136 | final_path = final_path.Append("test.profile"); |
| 137 | scoped_ptr<KeyFileStore> storage(new KeyFileStore(glib)); |
| 138 | storage->set_path(final_path); |
| 139 | if (!storage->Open()) |
| 140 | return NULL; |
| 141 | profile->set_storage(storage.release()); // Passes ownership. |
| 142 | return profile.release(); |
| 143 | } |
| 144 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 145 | bool CreateBackingStoreForService(ScopedTempDir *temp_dir, |
| 146 | const string &profile_identifier, |
| 147 | const string &service_name) { |
| 148 | GLib glib; |
| 149 | KeyFileStore store(&glib); |
| 150 | store.set_path(temp_dir->path().Append(profile_identifier + ".profile")); |
| 151 | return store.Open() && |
| 152 | store.SetString(service_name, "rather", "irrelevant") && |
| 153 | store.Close(); |
| 154 | } |
| 155 | |
| 156 | Error::Type TestCreateProfile(Manager *manager, const string &name) { |
| 157 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 158 | string path; |
| 159 | manager->CreateProfile(name, &path, &error); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 160 | return error.type(); |
| 161 | } |
| 162 | |
| 163 | Error::Type TestPopAnyProfile(Manager *manager) { |
| 164 | Error error; |
| 165 | manager->PopAnyProfile(&error); |
| 166 | return error.type(); |
| 167 | } |
| 168 | |
| 169 | Error::Type TestPopProfile(Manager *manager, const string &name) { |
| 170 | Error error; |
| 171 | manager->PopProfile(name, &error); |
| 172 | return error.type(); |
| 173 | } |
| 174 | |
| 175 | Error::Type TestPushProfile(Manager *manager, const string &name) { |
| 176 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 177 | string path; |
| 178 | manager->PushProfile(name, &path, &error); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 179 | return error.type(); |
| 180 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 181 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 182 | protected: |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 183 | typedef scoped_refptr<MockService> MockServiceRefPtr; |
| 184 | |
| 185 | MockServiceRefPtr MakeAutoConnectableService() { |
| 186 | MockServiceRefPtr service = new NiceMock<MockService>(control_interface(), |
| 187 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 188 | metrics(), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 189 | manager()); |
| 190 | service->MakeFavorite(); |
| 191 | service->set_connectable(true); |
| 192 | return service; |
| 193 | } |
| 194 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 195 | scoped_refptr<MockWiFi> mock_wifi_; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 196 | vector<scoped_refptr<MockDevice> > mock_devices_; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 197 | scoped_ptr<MockDeviceInfo> device_info_; |
| 198 | |
| 199 | // This pointer is owned by the manager, and only tracked here for EXPECT*() |
| 200 | ManagerMockAdaptor *manager_adaptor_; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 203 | bool ManagerTest::ServiceOrderIs(ServiceRefPtr svc0, ServiceRefPtr svc1) { |
| 204 | return (svc0.get() == manager()->services_[0].get() && |
| 205 | svc1.get() == manager()->services_[1].get()); |
| 206 | } |
| 207 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 208 | TEST_F(ManagerTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 209 | EXPECT_TRUE(manager()->store().Contains(flimflam::kStateProperty)); |
| 210 | EXPECT_FALSE(manager()->store().Contains("")); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 213 | TEST_F(ManagerTest, DeviceRegistration) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 214 | ON_CALL(*mock_devices_[0].get(), TechnologyIs(Technology::kEthernet)) |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 215 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 216 | ON_CALL(*mock_devices_[1].get(), TechnologyIs(Technology::kWifi)) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 217 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 218 | ON_CALL(*mock_devices_[2].get(), TechnologyIs(Technology::kCellular)) |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 219 | .WillByDefault(Return(true)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 220 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 221 | manager()->RegisterDevice(mock_devices_[0]); |
| 222 | manager()->RegisterDevice(mock_devices_[1]); |
| 223 | manager()->RegisterDevice(mock_devices_[2]); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 224 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 225 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
| 226 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
| 227 | EXPECT_TRUE(IsDeviceRegistered(mock_devices_[2], Technology::kCellular)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 230 | TEST_F(ManagerTest, DeviceRegistrationAndStart) { |
| 231 | manager()->running_ = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 232 | mock_devices_[0]->enabled_persistent_ = true; |
| 233 | mock_devices_[1]->enabled_persistent_ = false; |
| 234 | EXPECT_CALL(*mock_devices_[0].get(), SetEnabled(true)) |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 235 | .Times(1); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 236 | EXPECT_CALL(*mock_devices_[1].get(), SetEnabled(_)) |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 237 | .Times(0); |
| 238 | manager()->RegisterDevice(mock_devices_[0]); |
| 239 | manager()->RegisterDevice(mock_devices_[1]); |
| 240 | } |
| 241 | |
| 242 | TEST_F(ManagerTest, DeviceRegistrationWithProfile) { |
| 243 | MockProfile *profile = new MockProfile(control_interface(), manager(), ""); |
| 244 | DeviceRefPtr device_ref(mock_devices_[0].get()); |
| 245 | AdoptProfile(manager(), profile); // Passes ownership. |
| 246 | EXPECT_CALL(*profile, ConfigureDevice(device_ref)); |
| 247 | EXPECT_CALL(*profile, Save()); |
| 248 | manager()->RegisterDevice(mock_devices_[0]); |
| 249 | } |
| 250 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 251 | TEST_F(ManagerTest, DeviceDeregistration) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 252 | ON_CALL(*mock_devices_[0].get(), TechnologyIs(Technology::kEthernet)) |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 253 | .WillByDefault(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 254 | ON_CALL(*mock_devices_[1].get(), TechnologyIs(Technology::kWifi)) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 255 | .WillByDefault(Return(true)); |
| 256 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 257 | manager()->RegisterDevice(mock_devices_[0]); |
| 258 | manager()->RegisterDevice(mock_devices_[1]); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 259 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 260 | ASSERT_TRUE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
| 261 | ASSERT_TRUE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 262 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 263 | EXPECT_CALL(*mock_devices_[0].get(), SetEnabled(false)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 264 | manager()->DeregisterDevice(mock_devices_[0]); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 265 | EXPECT_FALSE(IsDeviceRegistered(mock_devices_[0], Technology::kEthernet)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 266 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 267 | EXPECT_CALL(*mock_devices_[1].get(), SetEnabled(false)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 268 | manager()->DeregisterDevice(mock_devices_[1]); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 269 | EXPECT_FALSE(IsDeviceRegistered(mock_devices_[1], Technology::kWifi)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | TEST_F(ManagerTest, ServiceRegistration) { |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 273 | // It's much easier and safer to use a real GLib for this test. |
| 274 | GLib glib; |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 275 | Manager manager(control_interface(), |
| 276 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 277 | metrics(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 278 | &glib, |
| 279 | run_path(), |
| 280 | storage_path(), |
| 281 | string()); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 282 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 283 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 284 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 285 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 286 | scoped_refptr<MockService> mock_service( |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 287 | new NiceMock<MockService>(control_interface(), |
| 288 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 289 | metrics(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 290 | &manager)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 291 | scoped_refptr<MockService> mock_service2( |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 292 | new NiceMock<MockService>(control_interface(), |
| 293 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 294 | metrics(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 295 | &manager)); |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 296 | |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 297 | string service1_name(mock_service->UniqueName()); |
| 298 | string service2_name(mock_service2->UniqueName()); |
| 299 | |
| 300 | EXPECT_CALL(*mock_service.get(), GetRpcIdentifier()) |
| 301 | .WillRepeatedly(Return(service1_name)); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 302 | EXPECT_CALL(*mock_service2.get(), GetRpcIdentifier()) |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 303 | .WillRepeatedly(Return(service2_name)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 304 | // TODO(quiche): make this EXPECT_CALL work (crosbug.com/20154) |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 305 | // EXPECT_CALL(*dynamic_cast<ManagerMockAdaptor *>(manager.adaptor_.get()), |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 306 | // EmitRpcIdentifierArrayChanged(flimflam::kServicesProperty, _)); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 307 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 308 | manager.RegisterService(mock_service); |
| 309 | manager.RegisterService(mock_service2); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 310 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 311 | Error error; |
| 312 | vector<string> rpc_ids = manager.EnumerateAvailableServices(&error); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 313 | set<string> ids(rpc_ids.begin(), rpc_ids.end()); |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 314 | EXPECT_EQ(2, ids.size()); |
| 315 | EXPECT_TRUE(ContainsKey(ids, mock_service->GetRpcIdentifier())); |
| 316 | EXPECT_TRUE(ContainsKey(ids, mock_service2->GetRpcIdentifier())); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 317 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 318 | EXPECT_TRUE(manager.FindService(service1_name).get() != NULL); |
| 319 | EXPECT_TRUE(manager.FindService(service2_name).get() != NULL); |
| 320 | |
| 321 | manager.Stop(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 324 | TEST_F(ManagerTest, RegisterKnownService) { |
| 325 | // It's much easier and safer to use a real GLib for this test. |
| 326 | GLib glib; |
| 327 | Manager manager(control_interface(), |
| 328 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 329 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 330 | &glib, |
| 331 | run_path(), |
| 332 | storage_path(), |
| 333 | string()); |
| 334 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 335 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 336 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 337 | { |
| 338 | ServiceRefPtr service1(new ServiceUnderTest(control_interface(), |
| 339 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 340 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 341 | &manager)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 342 | ASSERT_TRUE(profile->AdoptService(service1)); |
| 343 | ASSERT_TRUE(profile->ContainsService(service1)); |
| 344 | } // Force destruction of service1. |
| 345 | |
| 346 | ServiceRefPtr service2(new ServiceUnderTest(control_interface(), |
| 347 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 348 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 349 | &manager)); |
| 350 | manager.RegisterService(service2); |
| 351 | EXPECT_EQ(service2->profile().get(), profile.get()); |
| 352 | manager.Stop(); |
| 353 | } |
| 354 | |
| 355 | TEST_F(ManagerTest, RegisterUnknownService) { |
| 356 | // It's much easier and safer to use a real GLib for this test. |
| 357 | GLib glib; |
| 358 | Manager manager(control_interface(), |
| 359 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 360 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 361 | &glib, |
| 362 | run_path(), |
| 363 | storage_path(), |
| 364 | string()); |
| 365 | ProfileRefPtr profile(CreateProfileForManager(&manager, &glib)); |
| 366 | ASSERT_TRUE(profile.get()); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 367 | AdoptProfile(&manager, profile); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 368 | { |
| 369 | ServiceRefPtr service1(new ServiceUnderTest(control_interface(), |
| 370 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 371 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 372 | &manager)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 373 | ASSERT_TRUE(profile->AdoptService(service1)); |
| 374 | ASSERT_TRUE(profile->ContainsService(service1)); |
| 375 | } // Force destruction of service1. |
| 376 | scoped_refptr<MockService> mock_service2( |
| 377 | new NiceMock<MockService>(control_interface(), |
| 378 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 379 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 380 | &manager)); |
| 381 | EXPECT_CALL(*mock_service2.get(), GetStorageIdentifier()) |
| 382 | .WillRepeatedly(Return(mock_service2->UniqueName())); |
| 383 | manager.RegisterService(mock_service2); |
| 384 | EXPECT_NE(mock_service2->profile().get(), profile.get()); |
| 385 | manager.Stop(); |
| 386 | } |
| 387 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 388 | TEST_F(ManagerTest, DeregisterUnregisteredService) { |
| 389 | // WiFi assumes that it can deregister a service that is not |
| 390 | // registered. (E.g. a hidden service can be deregistered when it |
| 391 | // loses its last endpoint, and again when WiFi is Stop()-ed.) |
| 392 | // |
| 393 | // So test that doing so doesn't cause a crash. |
| 394 | MockServiceRefPtr service = new NiceMock<MockService>(control_interface(), |
| 395 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 396 | metrics(), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 397 | manager()); |
| 398 | manager()->DeregisterService(service); |
| 399 | } |
| 400 | |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 401 | TEST_F(ManagerTest, GetProperties) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 402 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 403 | AdoptProfile(manager(), profile); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 404 | map<string, ::DBus::Variant> props; |
| 405 | Error error(Error::kInvalidProperty, ""); |
| 406 | { |
| 407 | ::DBus::Error dbus_error; |
| 408 | string expected("portal_list"); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 409 | manager()->mutable_store()->SetStringProperty( |
| 410 | flimflam::kCheckPortalListProperty, |
| 411 | expected, |
| 412 | &error); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 413 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 414 | ASSERT_FALSE(props.find(flimflam::kCheckPortalListProperty) == props.end()); |
| 415 | EXPECT_EQ(props[flimflam::kCheckPortalListProperty].reader().get_string(), |
| 416 | expected); |
| 417 | } |
| 418 | { |
| 419 | ::DBus::Error dbus_error; |
| 420 | bool expected = true; |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 421 | manager()->mutable_store()->SetBoolProperty(flimflam::kOfflineModeProperty, |
| 422 | expected, |
| 423 | &error); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 424 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 425 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 426 | EXPECT_EQ(props[flimflam::kOfflineModeProperty].reader().get_bool(), |
| 427 | expected); |
| 428 | } |
| 429 | } |
| 430 | |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 431 | TEST_F(ManagerTest, GetDevicesProperty) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 432 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 433 | AdoptProfile(manager(), profile); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 434 | manager()->RegisterDevice(mock_devices_[0]); |
| 435 | manager()->RegisterDevice(mock_devices_[1]); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 436 | { |
| 437 | map<string, ::DBus::Variant> props; |
| 438 | ::DBus::Error dbus_error; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 439 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 440 | ASSERT_FALSE(props.find(flimflam::kDevicesProperty) == props.end()); |
| 441 | Strings devices = |
| 442 | props[flimflam::kDevicesProperty].operator vector<string>(); |
| 443 | EXPECT_EQ(2, devices.size()); |
| 444 | } |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 445 | } |
| 446 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 447 | TEST_F(ManagerTest, GetServicesProperty) { |
| 448 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
| 449 | AdoptProfile(manager(), profile); |
| 450 | map<string, ::DBus::Variant> props; |
| 451 | ::DBus::Error dbus_error; |
| 452 | DBusAdaptor::GetProperties(manager()->store(), &props, &dbus_error); |
| 453 | map<string, ::DBus::Variant>::const_iterator prop = |
| 454 | props.find(flimflam::kServicesProperty); |
| 455 | ASSERT_FALSE(prop == props.end()); |
| 456 | const ::DBus::Variant &variant = prop->second; |
| 457 | ASSERT_TRUE(DBusAdaptor::IsPaths(variant.signature())); |
| 458 | } |
| 459 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 460 | TEST_F(ManagerTest, MoveService) { |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 461 | Manager manager(control_interface(), |
| 462 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 463 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 464 | glib(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 465 | run_path(), |
| 466 | storage_path(), |
| 467 | string()); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 468 | scoped_refptr<MockService> s2(new MockService(control_interface(), |
| 469 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 470 | metrics(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 471 | &manager)); |
| 472 | // Inject an actual profile, backed by a fake StoreInterface |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 473 | { |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 474 | Profile::Identifier id("irrelevant"); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 475 | ProfileRefPtr profile( |
| 476 | new Profile(control_interface(), &manager, id, "", false)); |
| 477 | MockStore *storage = new MockStore; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 478 | // Say we don't have |s2| the first time asked, then that we do. |
| 479 | EXPECT_CALL(*storage, ContainsGroup(s2->GetStorageIdentifier())) |
| 480 | .WillOnce(Return(false)) |
| 481 | .WillRepeatedly(Return(true)); |
| 482 | EXPECT_CALL(*storage, Flush()) |
| 483 | .Times(AnyNumber()) |
| 484 | .WillRepeatedly(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 485 | profile->set_storage(storage); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 486 | AdoptProfile(&manager, profile); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 487 | } |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 488 | // Create a profile that already has |s2| in it. |
| 489 | ProfileRefPtr profile(new EphemeralProfile(control_interface(), &manager)); |
| 490 | profile->AdoptService(s2); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 491 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 492 | // Now, move the Service |s2| to another profile. |
| 493 | EXPECT_CALL(*s2.get(), Save(_)).WillOnce(Return(true)); |
| 494 | ASSERT_TRUE(manager.MoveServiceToProfile(s2, manager.ActiveProfile())); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 495 | |
| 496 | // Force destruction of the original Profile, to ensure that the Service |
| 497 | // is kept alive and populated with data. |
| 498 | profile = NULL; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 499 | ASSERT_TRUE(manager.ActiveProfile()->ContainsService(s2)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 500 | manager.Stop(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 503 | TEST_F(ManagerTest, LookupProfileByRpcIdentifier) { |
| 504 | scoped_refptr<MockProfile> mock_profile( |
| 505 | new MockProfile(control_interface(), manager(), "")); |
| 506 | const string kProfileName("profile0"); |
| 507 | EXPECT_CALL(*mock_profile, GetRpcIdentifier()) |
| 508 | .WillRepeatedly(Return(kProfileName)); |
| 509 | AdoptProfile(manager(), mock_profile); |
| 510 | |
| 511 | EXPECT_FALSE(manager()->LookupProfileByRpcIdentifier("foo")); |
| 512 | ProfileRefPtr profile = manager()->LookupProfileByRpcIdentifier(kProfileName); |
| 513 | EXPECT_EQ(mock_profile.get(), profile.get()); |
| 514 | } |
| 515 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 516 | TEST_F(ManagerTest, SetProfileForService) { |
| 517 | scoped_refptr<MockProfile> profile0( |
| 518 | new MockProfile(control_interface(), manager(), "")); |
| 519 | string profile_name0("profile0"); |
| 520 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 521 | .WillRepeatedly(Return(profile_name0)); |
| 522 | AdoptProfile(manager(), profile0); |
| 523 | scoped_refptr<MockService> service(new MockService(control_interface(), |
| 524 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 525 | metrics(), |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 526 | manager())); |
| 527 | service->set_profile(profile0); |
| 528 | |
| 529 | { |
| 530 | Error error; |
| 531 | manager()->SetProfileForService(service, "foo", &error); |
| 532 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 533 | EXPECT_EQ("Unknown Profile foo requested for Service", error.message()); |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | { |
| 537 | Error error; |
| 538 | manager()->SetProfileForService(service, profile_name0, &error); |
| 539 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 540 | EXPECT_EQ("Service is already connected to this profile", error.message()); |
| 541 | } |
| 542 | |
| 543 | scoped_refptr<MockProfile> profile1( |
| 544 | new MockProfile(control_interface(), manager(), "")); |
| 545 | string profile_name1("profile1"); |
| 546 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 547 | .WillRepeatedly(Return(profile_name1)); |
| 548 | AdoptProfile(manager(), profile1); |
| 549 | |
| 550 | { |
| 551 | Error error; |
| 552 | EXPECT_CALL(*profile1, AdoptService(_)) |
| 553 | .WillOnce(Return(true)); |
| 554 | EXPECT_CALL(*profile0, AbandonService(_)) |
| 555 | .WillOnce(Return(true)); |
| 556 | manager()->SetProfileForService(service, profile_name1, &error); |
| 557 | EXPECT_TRUE(error.IsSuccess()); |
| 558 | } |
| 559 | } |
| 560 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 561 | TEST_F(ManagerTest, CreateProfile) { |
| 562 | // It's much easier to use real Glib here since we want the storage |
| 563 | // side-effects. |
| 564 | GLib glib; |
| 565 | ScopedTempDir temp_dir; |
| 566 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 567 | |
| 568 | Manager manager(control_interface(), |
| 569 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 570 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 571 | &glib, |
| 572 | run_path(), |
| 573 | storage_path(), |
| 574 | temp_dir.path().value()); |
| 575 | |
| 576 | // Invalid name should be rejected. |
| 577 | EXPECT_EQ(Error::kInvalidArguments, TestCreateProfile(&manager, "")); |
| 578 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 579 | // A profile with invalid characters in it should similarly be rejected. |
| 580 | EXPECT_EQ(Error::kInvalidArguments, |
| 581 | TestCreateProfile(&manager, "valid_profile")); |
| 582 | |
| 583 | // We should be able to create a machine profile. |
| 584 | EXPECT_EQ(Error::kSuccess, TestCreateProfile(&manager, "valid")); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 585 | |
| 586 | // We should succeed in creating a valid user profile. |
| 587 | const char kProfile[] = "~user/profile"; |
| 588 | EXPECT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile)); |
| 589 | |
| 590 | // We should fail in creating it a second time (already exists). |
| 591 | EXPECT_EQ(Error::kAlreadyExists, TestCreateProfile(&manager, kProfile)); |
| 592 | } |
| 593 | |
| 594 | TEST_F(ManagerTest, PushPopProfile) { |
| 595 | // It's much easier to use real Glib in creating a Manager for this |
| 596 | // test here since we want the storage side-effects. |
| 597 | GLib glib; |
| 598 | ScopedTempDir temp_dir; |
| 599 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 600 | Manager manager(control_interface(), |
| 601 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 602 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 603 | &glib, |
| 604 | run_path(), |
| 605 | storage_path(), |
| 606 | temp_dir.path().value()); |
| 607 | |
| 608 | // Pushing an invalid profile should fail. |
| 609 | EXPECT_EQ(Error::kInvalidArguments, TestPushProfile(&manager, "")); |
| 610 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 611 | // Pushing a default profile that does not exist should fail. |
| 612 | EXPECT_EQ(Error::kNotFound, TestPushProfile(&manager, "default")); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 613 | |
| 614 | const char kProfile0[] = "~user/profile0"; |
| 615 | const char kProfile1[] = "~user/profile1"; |
| 616 | |
| 617 | // Create a couple of profiles. |
| 618 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile0)); |
| 619 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile1)); |
| 620 | |
| 621 | // Push these profiles on the stack. |
| 622 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 623 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile1)); |
| 624 | |
| 625 | // Pushing a profile a second time should fail. |
| 626 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile0)); |
| 627 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile1)); |
| 628 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 629 | Error error; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 630 | // Active profile should be the last one we pushed. |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 631 | EXPECT_EQ(kProfile1, "~" + manager.ActiveProfile()->GetFriendlyName()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 632 | |
| 633 | // Make sure a profile name that doesn't exist fails. |
| 634 | const char kProfile2Id[] = "profile2"; |
| 635 | const string kProfile2 = base::StringPrintf("~user/%s", kProfile2Id); |
| 636 | EXPECT_EQ(Error::kNotFound, TestPushProfile(&manager, kProfile2)); |
| 637 | |
| 638 | // Create a new service, with a specific storage name. |
| 639 | scoped_refptr<MockService> service( |
| 640 | new NiceMock<MockService>(control_interface(), |
| 641 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 642 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 643 | &manager)); |
| 644 | const char kServiceName[] = "service_storage_name"; |
| 645 | EXPECT_CALL(*service.get(), GetStorageIdentifier()) |
| 646 | .WillRepeatedly(Return(kServiceName)); |
| 647 | EXPECT_CALL(*service.get(), Load(_)) |
| 648 | .WillRepeatedly(Return(true)); |
| 649 | |
| 650 | // Add this service to the manager -- it should end up in the ephemeral |
| 651 | // profile. |
| 652 | manager.RegisterService(service); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 653 | ASSERT_EQ(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 654 | |
| 655 | // Create storage for a profile that contains the service storage name. |
| 656 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile2Id, |
| 657 | kServiceName)); |
| 658 | |
| 659 | // When we push the profile, the service should move away from the |
| 660 | // ephemeral profile to this new profile since it has an entry for |
| 661 | // this service. |
| 662 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile2)); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 663 | EXPECT_NE(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 664 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 665 | |
| 666 | // Insert another profile that should supersede ownership of the service. |
| 667 | const char kProfile3Id[] = "profile3"; |
| 668 | const string kProfile3 = base::StringPrintf("~user/%s", kProfile3Id); |
| 669 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile3Id, |
| 670 | kServiceName)); |
| 671 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile3)); |
| 672 | EXPECT_EQ(kProfile3, "~" + service->profile()->GetFriendlyName()); |
| 673 | |
| 674 | // Popping an invalid profile name should fail. |
| 675 | EXPECT_EQ(Error::kInvalidArguments, TestPopProfile(&manager, "~")); |
| 676 | |
| 677 | // Popping an profile that is not at the top of the stack should fail. |
| 678 | EXPECT_EQ(Error::kNotSupported, TestPopProfile(&manager, kProfile0)); |
| 679 | |
| 680 | // Popping the top profile should succeed. |
| 681 | EXPECT_EQ(Error::kSuccess, TestPopProfile(&manager, kProfile3)); |
| 682 | |
| 683 | // Moreover the service should have switched profiles to profile 2. |
| 684 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 685 | |
| 686 | // Popping the top profile should succeed. |
| 687 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 688 | |
| 689 | // The service should now revert to the ephemeral profile. |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 690 | EXPECT_EQ(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 691 | |
| 692 | // Pop the remaining two services off the stack. |
| 693 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 694 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 695 | |
| 696 | // Next pop should fail with "stack is empty". |
| 697 | EXPECT_EQ(Error::kNotFound, TestPopAnyProfile(&manager)); |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 698 | |
| 699 | const char kMachineProfile0[] = "machineprofile0"; |
| 700 | const char kMachineProfile1[] = "machineprofile1"; |
| 701 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kMachineProfile0)); |
| 702 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kMachineProfile1)); |
| 703 | |
| 704 | // Should be able to push a machine profile. |
| 705 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kMachineProfile0)); |
| 706 | |
| 707 | // Should be able to push a user profile atop a machine profile. |
| 708 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 709 | |
| 710 | // Pushing a system-wide profile on top of a user profile should fail. |
| 711 | EXPECT_EQ(Error::kInvalidArguments, |
| 712 | TestPushProfile(&manager, kMachineProfile1)); |
| 713 | |
| 714 | // However if we pop the user profile, we should be able stack another |
| 715 | // machine profile on. |
| 716 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 717 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kMachineProfile1)); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 720 | TEST_F(ManagerTest, RemoveProfile) { |
| 721 | // It's much easier to use real Glib in creating a Manager for this |
| 722 | // test here since we want the storage side-effects. |
| 723 | GLib glib; |
| 724 | ScopedTempDir temp_dir; |
| 725 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 726 | Manager manager(control_interface(), |
| 727 | dispatcher(), |
| 728 | metrics(), |
| 729 | &glib, |
| 730 | run_path(), |
| 731 | storage_path(), |
| 732 | temp_dir.path().value()); |
| 733 | |
| 734 | const char kProfile0[] = "profile0"; |
| 735 | FilePath profile_path( |
| 736 | FilePath(storage_path()).Append(string(kProfile0) + ".profile")); |
| 737 | |
| 738 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile0)); |
| 739 | ASSERT_TRUE(file_util::PathExists(profile_path)); |
| 740 | |
| 741 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 742 | |
| 743 | // Remove should fail since the profile is still on the stack. |
| 744 | { |
| 745 | Error error; |
| 746 | manager.RemoveProfile(kProfile0, &error); |
| 747 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 748 | } |
| 749 | |
| 750 | // Profile path should still exist. |
| 751 | EXPECT_TRUE(file_util::PathExists(profile_path)); |
| 752 | |
| 753 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 754 | |
| 755 | // This should succeed now that the profile is off the stack. |
| 756 | { |
| 757 | Error error; |
| 758 | manager.RemoveProfile(kProfile0, &error); |
| 759 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 760 | } |
| 761 | |
| 762 | // Profile path should no longer exist. |
| 763 | EXPECT_FALSE(file_util::PathExists(profile_path)); |
| 764 | |
| 765 | // Another remove succeeds, due to a foible in file_util::Delete -- |
| 766 | // it is not an error to delete a file that does not exist. |
| 767 | { |
| 768 | Error error; |
| 769 | manager.RemoveProfile(kProfile0, &error); |
| 770 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 771 | } |
| 772 | |
| 773 | // Let's create an error case that will "work". Create a non-empty |
| 774 | // directory in the place of the profile pathname. |
| 775 | ASSERT_TRUE(file_util::CreateDirectory(profile_path.Append("foo"))); |
| 776 | { |
| 777 | Error error; |
| 778 | manager.RemoveProfile(kProfile0, &error); |
| 779 | EXPECT_EQ(Error::kOperationFailed, error.type()); |
| 780 | } |
| 781 | } |
| 782 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 783 | // Use this matcher instead of passing RefPtrs directly into the arguments |
| 784 | // of EXPECT_CALL() because otherwise we may create un-cleaned-up references at |
| 785 | // system teardown. |
| 786 | MATCHER_P(IsRefPtrTo, ref_address, "") { |
| 787 | return arg.get() == ref_address; |
| 788 | } |
| 789 | |
| 790 | TEST_F(ManagerTest, HandleProfileEntryDeletion) { |
| 791 | MockServiceRefPtr s_not_in_profile( |
| 792 | new NiceMock<MockService>(control_interface(), |
| 793 | dispatcher(), |
| 794 | metrics(), |
| 795 | manager())); |
| 796 | MockServiceRefPtr s_not_in_group( |
| 797 | new NiceMock<MockService>(control_interface(), |
| 798 | dispatcher(), |
| 799 | metrics(), |
| 800 | manager())); |
| 801 | MockServiceRefPtr s_configure_fail( |
| 802 | new NiceMock<MockService>(control_interface(), |
| 803 | dispatcher(), |
| 804 | metrics(), |
| 805 | manager())); |
| 806 | MockServiceRefPtr s_configure_succeed( |
| 807 | new NiceMock<MockService>(control_interface(), |
| 808 | dispatcher(), |
| 809 | metrics(), |
| 810 | manager())); |
| 811 | |
| 812 | string entry_name("entry_name"); |
| 813 | EXPECT_CALL(*s_not_in_profile.get(), GetStorageIdentifier()).Times(0); |
| 814 | EXPECT_CALL(*s_not_in_group.get(), GetStorageIdentifier()) |
| 815 | .WillRepeatedly(Return("not_entry_name")); |
| 816 | EXPECT_CALL(*s_configure_fail.get(), GetStorageIdentifier()) |
| 817 | .WillRepeatedly(Return(entry_name)); |
| 818 | EXPECT_CALL(*s_configure_succeed.get(), GetStorageIdentifier()) |
| 819 | .WillRepeatedly(Return(entry_name)); |
| 820 | |
| 821 | manager()->RegisterService(s_not_in_profile); |
| 822 | manager()->RegisterService(s_not_in_group); |
| 823 | manager()->RegisterService(s_configure_fail); |
| 824 | manager()->RegisterService(s_configure_succeed); |
| 825 | |
| 826 | scoped_refptr<MockProfile> profile0( |
| 827 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 828 | scoped_refptr<MockProfile> profile1( |
| 829 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 830 | |
| 831 | s_not_in_group->set_profile(profile1); |
| 832 | s_configure_fail->set_profile(profile1); |
| 833 | s_configure_succeed->set_profile(profile1); |
| 834 | |
| 835 | AdoptProfile(manager(), profile0); |
| 836 | AdoptProfile(manager(), profile1); |
| 837 | |
| 838 | // No services are a member of this profile. |
| 839 | EXPECT_FALSE(manager()->HandleProfileEntryDeletion(profile0, entry_name)); |
| 840 | |
| 841 | // No services that are members of this profile have this entry name. |
| 842 | EXPECT_FALSE(manager()->HandleProfileEntryDeletion(profile1, "")); |
| 843 | |
| 844 | // Only services that are members of the profile and group will be abandoned. |
| 845 | EXPECT_CALL(*profile1.get(), |
| 846 | AbandonService(IsRefPtrTo(s_not_in_profile.get()))).Times(0); |
| 847 | EXPECT_CALL(*profile1.get(), |
| 848 | AbandonService(IsRefPtrTo(s_not_in_group.get()))).Times(0); |
| 849 | EXPECT_CALL(*profile1.get(), |
| 850 | AbandonService(IsRefPtrTo(s_configure_fail.get()))) |
| 851 | .WillOnce(Return(true)); |
| 852 | EXPECT_CALL(*profile1.get(), |
| 853 | AbandonService(IsRefPtrTo(s_configure_succeed.get()))) |
| 854 | .WillOnce(Return(true)); |
| 855 | |
| 856 | // Never allow services to re-join profile1. |
| 857 | EXPECT_CALL(*profile1.get(), ConfigureService(_)) |
| 858 | .WillRepeatedly(Return(false)); |
| 859 | |
| 860 | // Only allow one of the members of the profile and group to successfully |
| 861 | // join profile0. |
| 862 | EXPECT_CALL(*profile0.get(), |
| 863 | ConfigureService(IsRefPtrTo(s_not_in_profile.get()))).Times(0); |
| 864 | EXPECT_CALL(*profile0.get(), |
| 865 | ConfigureService(IsRefPtrTo(s_not_in_group.get()))).Times(0); |
| 866 | EXPECT_CALL(*profile0.get(), |
| 867 | ConfigureService(IsRefPtrTo(s_configure_fail.get()))) |
| 868 | .WillOnce(Return(false)); |
| 869 | EXPECT_CALL(*profile0.get(), |
| 870 | ConfigureService(IsRefPtrTo(s_configure_succeed.get()))) |
| 871 | .WillOnce(Return(true)); |
| 872 | |
| 873 | // Expect the failed-to-configure service to have Unload() called on it. |
| 874 | EXPECT_CALL(*s_not_in_profile.get(), Unload()).Times(0); |
| 875 | EXPECT_CALL(*s_not_in_group.get(), Unload()).Times(0); |
| 876 | EXPECT_CALL(*s_configure_fail.get(), Unload()).Times(1); |
| 877 | EXPECT_CALL(*s_configure_succeed.get(), Unload()).Times(0); |
| 878 | |
| 879 | EXPECT_TRUE(manager()->HandleProfileEntryDeletion(profile1, entry_name)); |
| 880 | |
| 881 | EXPECT_EQ(GetEphemeralProfile(manager()), s_not_in_profile->profile().get()); |
| 882 | EXPECT_EQ(profile1, s_not_in_group->profile()); |
| 883 | EXPECT_EQ(GetEphemeralProfile(manager()), s_configure_fail->profile()); |
| 884 | |
| 885 | // Since we are using a MockProfile, the profile does not actually change, |
| 886 | // since ConfigureService was not actually called on the service. |
| 887 | EXPECT_EQ(profile1, s_configure_succeed->profile()); |
| 888 | } |
| 889 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 890 | TEST_F(ManagerTest, HandleProfileEntryDeletionWithUnload) { |
| 891 | MockServiceRefPtr s_will_remove0( |
| 892 | new NiceMock<MockService>(control_interface(), |
| 893 | dispatcher(), |
| 894 | metrics(), |
| 895 | manager())); |
| 896 | MockServiceRefPtr s_will_remove1( |
| 897 | new NiceMock<MockService>(control_interface(), |
| 898 | dispatcher(), |
| 899 | metrics(), |
| 900 | manager())); |
| 901 | MockServiceRefPtr s_will_not_remove0( |
| 902 | new NiceMock<MockService>(control_interface(), |
| 903 | dispatcher(), |
| 904 | metrics(), |
| 905 | manager())); |
| 906 | MockServiceRefPtr s_will_not_remove1( |
| 907 | new NiceMock<MockService>(control_interface(), |
| 908 | dispatcher(), |
| 909 | metrics(), |
| 910 | manager())); |
| 911 | |
| 912 | EXPECT_CALL(*metrics(), NotifyDefaultServiceChanged(NULL)) |
| 913 | .Times(4); // Once for each registration. |
| 914 | |
| 915 | string entry_name("entry_name"); |
| 916 | EXPECT_CALL(*s_will_remove0.get(), GetStorageIdentifier()) |
| 917 | .WillRepeatedly(Return(entry_name)); |
| 918 | EXPECT_CALL(*s_will_remove1.get(), GetStorageIdentifier()) |
| 919 | .WillRepeatedly(Return(entry_name)); |
| 920 | EXPECT_CALL(*s_will_not_remove0.get(), GetStorageIdentifier()) |
| 921 | .WillRepeatedly(Return(entry_name)); |
| 922 | EXPECT_CALL(*s_will_not_remove1.get(), GetStorageIdentifier()) |
| 923 | .WillRepeatedly(Return(entry_name)); |
| 924 | |
| 925 | manager()->RegisterService(s_will_remove0); |
| 926 | manager()->RegisterService(s_will_not_remove0); |
| 927 | manager()->RegisterService(s_will_remove1); |
| 928 | manager()->RegisterService(s_will_not_remove1); |
| 929 | |
| 930 | // One for each service added above. |
| 931 | ASSERT_EQ(4, manager()->services_.size()); |
| 932 | |
| 933 | scoped_refptr<MockProfile> profile( |
| 934 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 935 | |
| 936 | s_will_remove0->set_profile(profile); |
| 937 | s_will_remove1->set_profile(profile); |
| 938 | s_will_not_remove0->set_profile(profile); |
| 939 | s_will_not_remove1->set_profile(profile); |
| 940 | |
| 941 | AdoptProfile(manager(), profile); |
| 942 | |
| 943 | // Deny any of the services re-entry to the profile. |
| 944 | EXPECT_CALL(*profile, ConfigureService(_)) |
| 945 | .WillRepeatedly(Return(false)); |
| 946 | |
| 947 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_remove0))) |
| 948 | .WillOnce(Return(true)); |
| 949 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_remove1))) |
| 950 | .WillOnce(Return(true)); |
| 951 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_not_remove0))) |
| 952 | .WillOnce(Return(true)); |
| 953 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_not_remove1))) |
| 954 | .WillOnce(Return(true)); |
| 955 | |
| 956 | EXPECT_CALL(*s_will_remove0, Unload()) |
| 957 | .WillOnce(Return(true)); |
| 958 | EXPECT_CALL(*s_will_remove1, Unload()) |
| 959 | .WillOnce(Return(true)); |
| 960 | EXPECT_CALL(*s_will_not_remove0, Unload()) |
| 961 | .WillOnce(Return(false)); |
| 962 | EXPECT_CALL(*s_will_not_remove1, Unload()) |
| 963 | .WillOnce(Return(false)); |
| 964 | |
| 965 | |
| 966 | // This will cause all the profiles to be unloaded. |
| 967 | EXPECT_TRUE(manager()->HandleProfileEntryDeletion(profile, entry_name)); |
| 968 | |
| 969 | // 2 of the 4 services added above should have been unregistered and |
| 970 | // removed, leaving 2. |
| 971 | EXPECT_EQ(2, manager()->services_.size()); |
| 972 | EXPECT_EQ(s_will_not_remove0.get(), manager()->services_[0].get()); |
| 973 | EXPECT_EQ(s_will_not_remove1.get(), manager()->services_[1].get()); |
| 974 | } |
| 975 | |
| 976 | TEST_F(ManagerTest, PopProfileWithUnload) { |
| 977 | MockServiceRefPtr s_will_remove0( |
| 978 | new NiceMock<MockService>(control_interface(), |
| 979 | dispatcher(), |
| 980 | metrics(), |
| 981 | manager())); |
| 982 | MockServiceRefPtr s_will_remove1( |
| 983 | new NiceMock<MockService>(control_interface(), |
| 984 | dispatcher(), |
| 985 | metrics(), |
| 986 | manager())); |
| 987 | MockServiceRefPtr s_will_not_remove0( |
| 988 | new NiceMock<MockService>(control_interface(), |
| 989 | dispatcher(), |
| 990 | metrics(), |
| 991 | manager())); |
| 992 | MockServiceRefPtr s_will_not_remove1( |
| 993 | new NiceMock<MockService>(control_interface(), |
| 994 | dispatcher(), |
| 995 | metrics(), |
| 996 | manager())); |
| 997 | |
| 998 | EXPECT_CALL(*metrics(), NotifyDefaultServiceChanged(NULL)) |
| 999 | .Times(5); // Once for each registration, and one after profile pop. |
| 1000 | |
| 1001 | manager()->RegisterService(s_will_remove0); |
| 1002 | manager()->RegisterService(s_will_not_remove0); |
| 1003 | manager()->RegisterService(s_will_remove1); |
| 1004 | manager()->RegisterService(s_will_not_remove1); |
| 1005 | |
| 1006 | // One for each service added above. |
| 1007 | ASSERT_EQ(4, manager()->services_.size()); |
| 1008 | |
| 1009 | scoped_refptr<MockProfile> profile0( |
| 1010 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1011 | scoped_refptr<MockProfile> profile1( |
| 1012 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1013 | |
| 1014 | s_will_remove0->set_profile(profile1); |
| 1015 | s_will_remove1->set_profile(profile1); |
| 1016 | s_will_not_remove0->set_profile(profile1); |
| 1017 | s_will_not_remove1->set_profile(profile1); |
| 1018 | |
| 1019 | AdoptProfile(manager(), profile0); |
| 1020 | AdoptProfile(manager(), profile1); |
| 1021 | |
| 1022 | // Deny any of the services entry to profile0, so they will all be unloaded. |
| 1023 | EXPECT_CALL(*profile0, ConfigureService(_)) |
| 1024 | .WillRepeatedly(Return(false)); |
| 1025 | |
| 1026 | EXPECT_CALL(*s_will_remove0, Unload()) |
| 1027 | .WillOnce(Return(true)); |
| 1028 | EXPECT_CALL(*s_will_remove1, Unload()) |
| 1029 | .WillOnce(Return(true)); |
| 1030 | EXPECT_CALL(*s_will_not_remove0, Unload()) |
| 1031 | .WillOnce(Return(false)); |
| 1032 | EXPECT_CALL(*s_will_not_remove1, Unload()) |
| 1033 | .WillOnce(Return(false)); |
| 1034 | |
| 1035 | // This will pop profile1, which should cause all our profiles to unload. |
| 1036 | manager()->PopProfileInternal(); |
| 1037 | |
| 1038 | // 2 of the 4 services added above should have been unregistered and |
| 1039 | // removed, leaving 2. |
| 1040 | EXPECT_EQ(2, manager()->services_.size()); |
| 1041 | EXPECT_EQ(s_will_not_remove0.get(), manager()->services_[0].get()); |
| 1042 | EXPECT_EQ(s_will_not_remove1.get(), manager()->services_[1].get()); |
| 1043 | } |
| 1044 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1045 | TEST_F(ManagerTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1046 | { |
| 1047 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1048 | EXPECT_TRUE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1049 | flimflam::kOfflineModeProperty, |
| 1050 | PropertyStoreTest::kBoolV, |
| 1051 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1052 | } |
| 1053 | { |
| 1054 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1055 | EXPECT_TRUE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1056 | flimflam::kCountryProperty, |
| 1057 | PropertyStoreTest::kStringV, |
| 1058 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1059 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1060 | // Attempt to write with value of wrong type should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1061 | { |
| 1062 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1063 | EXPECT_FALSE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1064 | flimflam::kCountryProperty, |
| 1065 | PropertyStoreTest::kBoolV, |
| 1066 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1067 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1068 | } |
| 1069 | { |
| 1070 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1071 | EXPECT_FALSE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1072 | flimflam::kOfflineModeProperty, |
| 1073 | PropertyStoreTest::kStringV, |
| 1074 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1075 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1076 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1077 | // Attempt to write R/O property should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1078 | { |
| 1079 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1080 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 1081 | manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1082 | flimflam::kEnabledTechnologiesProperty, |
| 1083 | PropertyStoreTest::kStringsV, |
| 1084 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1085 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1086 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1089 | TEST_F(ManagerTest, RequestScan) { |
| 1090 | { |
| 1091 | Error error; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1092 | manager()->RegisterDevice(mock_devices_[0].get()); |
| 1093 | manager()->RegisterDevice(mock_devices_[1].get()); |
| 1094 | EXPECT_CALL(*mock_devices_[0], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1095 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1096 | EXPECT_CALL(*mock_devices_[0], Scan(_)); |
| 1097 | EXPECT_CALL(*mock_devices_[1], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1098 | .WillRepeatedly(Return(false)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1099 | EXPECT_CALL(*mock_devices_[1], Scan(_)).Times(0); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1100 | manager()->RequestScan(flimflam::kTypeWifi, &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | { |
| 1104 | Error error; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1105 | manager()->RequestScan("bogus_device_type", &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1106 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1107 | } |
| 1108 | } |
| 1109 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1110 | TEST_F(ManagerTest, GetServiceNoType) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1111 | KeyValueStore args; |
| 1112 | Error e; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1113 | manager()->GetService(args, &e); |
| 1114 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1115 | EXPECT_EQ("must specify service type", e.message()); |
| 1116 | } |
| 1117 | |
| 1118 | TEST_F(ManagerTest, GetServiceUnknownType) { |
| 1119 | KeyValueStore args; |
| 1120 | Error e; |
| 1121 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeEthernet); |
| 1122 | manager()->GetService(args, &e); |
| 1123 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1124 | EXPECT_EQ("service type is unsupported", e.message()); |
| 1125 | } |
| 1126 | |
| 1127 | TEST_F(ManagerTest, GetServiceNoWifiDevice) { |
| 1128 | KeyValueStore args; |
| 1129 | Error e; |
| 1130 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1131 | manager()->GetService(args, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1132 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1133 | EXPECT_EQ("no wifi devices available", e.message()); |
| 1134 | } |
| 1135 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1136 | TEST_F(ManagerTest, GetServiceWifi) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1137 | KeyValueStore args; |
| 1138 | Error e; |
| 1139 | WiFiServiceRefPtr wifi_service; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1140 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1141 | manager()->RegisterDevice(mock_wifi_); |
| 1142 | EXPECT_CALL(*mock_wifi_, GetService(_, _)) |
| 1143 | .WillRepeatedly(Return(wifi_service)); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1144 | manager()->GetService(args, &e); |
| 1145 | EXPECT_TRUE(e.IsSuccess()); |
| 1146 | } |
| 1147 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1148 | TEST_F(ManagerTest, GetServiceVPNUnknownType) { |
| 1149 | KeyValueStore args; |
| 1150 | Error e; |
| 1151 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeVPN); |
| 1152 | ServiceRefPtr service = manager()->GetService(args, &e); |
| 1153 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1154 | EXPECT_FALSE(service); |
| 1155 | } |
| 1156 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1157 | TEST_F(ManagerTest, GetServiceVPN) { |
| 1158 | KeyValueStore args; |
| 1159 | Error e; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1160 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeVPN); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1161 | args.SetString(flimflam::kProviderTypeProperty, flimflam::kProviderOpenVpn); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 1162 | args.SetString(flimflam::kProviderHostProperty, "10.8.0.1"); |
| 1163 | args.SetString(flimflam::kProviderNameProperty, "vpn-name"); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1164 | ServiceRefPtr service = manager()->GetService(args, &e); |
| 1165 | EXPECT_TRUE(e.IsSuccess()); |
| 1166 | EXPECT_TRUE(service); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1169 | TEST_F(ManagerTest, ConfigureServiceWithInvalidProfile) { |
| 1170 | // Manager calls ActiveProfile() so we need at least one profile installed. |
| 1171 | scoped_refptr<MockProfile> profile( |
| 1172 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1173 | AdoptProfile(manager(), profile); |
| 1174 | |
| 1175 | KeyValueStore args; |
| 1176 | args.SetString(flimflam::kProfileProperty, "xxx"); |
| 1177 | Error error; |
| 1178 | manager()->ConfigureService(args, &error); |
| 1179 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1180 | EXPECT_EQ("Invalid profile name xxx", error.message()); |
| 1181 | } |
| 1182 | |
| 1183 | TEST_F(ManagerTest, ConfigureServiceWithGetServiceFailure) { |
| 1184 | // Manager calls ActiveProfile() so we need at least one profile installed. |
| 1185 | scoped_refptr<MockProfile> profile( |
| 1186 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1187 | AdoptProfile(manager(), profile); |
| 1188 | |
| 1189 | KeyValueStore args; |
| 1190 | Error error; |
| 1191 | manager()->ConfigureService(args, &error); |
| 1192 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1193 | EXPECT_EQ("must specify service type", error.message()); |
| 1194 | } |
| 1195 | |
| 1196 | // A registered service in the ephemeral profile should be moved to the |
| 1197 | // active profile as a part of configuration if no profile was explicitly |
| 1198 | // specified. |
| 1199 | TEST_F(ManagerTest, ConfigureRegisteredServiceWithoutProfile) { |
| 1200 | scoped_refptr<MockProfile> profile( |
| 1201 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1202 | |
| 1203 | AdoptProfile(manager(), profile); // This is now the active profile. |
| 1204 | |
| 1205 | const std::vector<uint8_t> ssid; |
| 1206 | scoped_refptr<MockWiFiService> service( |
| 1207 | new NiceMock<MockWiFiService>(control_interface(), |
| 1208 | dispatcher(), |
| 1209 | metrics(), |
| 1210 | manager(), |
| 1211 | mock_wifi_, |
| 1212 | ssid, |
| 1213 | "", |
| 1214 | "", |
| 1215 | false)); |
| 1216 | |
| 1217 | manager()->RegisterService(service); |
| 1218 | service->set_profile(GetEphemeralProfile(manager())); |
| 1219 | |
| 1220 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1221 | // the same device as that used above causes a refcounting loop. |
| 1222 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1223 | dispatcher(), |
| 1224 | metrics(), |
| 1225 | manager(), |
| 1226 | "wifi1", |
| 1227 | "addr5", |
| 1228 | 5)); |
| 1229 | manager()->RegisterDevice(wifi); |
| 1230 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1231 | .WillOnce(Return(service)); |
| 1232 | EXPECT_CALL(*profile, UpdateService(ServiceRefPtr(service.get()))) |
| 1233 | .WillOnce(Return(true)); |
| 1234 | EXPECT_CALL(*profile, AdoptService(ServiceRefPtr(service.get()))) |
| 1235 | .WillOnce(Return(true)); |
| 1236 | |
| 1237 | KeyValueStore args; |
| 1238 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1239 | Error error; |
| 1240 | manager()->ConfigureService(args, &error); |
| 1241 | EXPECT_TRUE(error.IsSuccess()); |
| 1242 | } |
| 1243 | |
| 1244 | // If were configure a service that was already registered and explicitly |
| 1245 | // specify a profile, it should be moved from the profile it was previously |
| 1246 | // in to the specified profile if one was requested. |
| 1247 | TEST_F(ManagerTest, ConfigureRegisteredServiceWithProfile) { |
| 1248 | scoped_refptr<MockProfile> profile0( |
| 1249 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1250 | scoped_refptr<MockProfile> profile1( |
| 1251 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1252 | |
| 1253 | const string kProfileName0 = "profile0"; |
| 1254 | const string kProfileName1 = "profile1"; |
| 1255 | |
| 1256 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 1257 | .WillRepeatedly(Return(kProfileName0)); |
| 1258 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 1259 | .WillRepeatedly(Return(kProfileName1)); |
| 1260 | |
| 1261 | AdoptProfile(manager(), profile0); |
| 1262 | AdoptProfile(manager(), profile1); // profile1 is now the ActiveProfile. |
| 1263 | |
| 1264 | const std::vector<uint8_t> ssid; |
| 1265 | scoped_refptr<MockWiFiService> service( |
| 1266 | new NiceMock<MockWiFiService>(control_interface(), |
| 1267 | dispatcher(), |
| 1268 | metrics(), |
| 1269 | manager(), |
| 1270 | mock_wifi_, |
| 1271 | ssid, |
| 1272 | "", |
| 1273 | "", |
| 1274 | false)); |
| 1275 | |
| 1276 | manager()->RegisterService(service); |
| 1277 | service->set_profile(profile1); |
| 1278 | |
| 1279 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1280 | // the same device as that used above causes a refcounting loop. |
| 1281 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1282 | dispatcher(), |
| 1283 | metrics(), |
| 1284 | manager(), |
| 1285 | "wifi1", |
| 1286 | "addr5", |
| 1287 | 5)); |
| 1288 | manager()->RegisterDevice(wifi); |
| 1289 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1290 | .WillOnce(Return(service)); |
| 1291 | EXPECT_CALL(*profile0, UpdateService(ServiceRefPtr(service.get()))) |
| 1292 | .WillOnce(Return(true)); |
| 1293 | EXPECT_CALL(*profile0, AdoptService(ServiceRefPtr(service.get()))) |
| 1294 | .WillOnce(Return(true)); |
| 1295 | EXPECT_CALL(*profile1, AbandonService(ServiceRefPtr(service.get()))) |
| 1296 | .WillOnce(Return(true)); |
| 1297 | |
| 1298 | KeyValueStore args; |
| 1299 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1300 | args.SetString(flimflam::kProfileProperty, kProfileName0); |
| 1301 | Error error; |
| 1302 | manager()->ConfigureService(args, &error); |
| 1303 | EXPECT_TRUE(error.IsSuccess()); |
| 1304 | service->set_profile(NULL); // Breaks refcounting loop. |
| 1305 | } |
| 1306 | |
| 1307 | // An unregistered service should remain unregistered, but its contents should |
| 1308 | // be saved to the specified profile nonetheless. |
| 1309 | TEST_F(ManagerTest, ConfigureUnregisteredServiceWithProfile) { |
| 1310 | scoped_refptr<MockProfile> profile0( |
| 1311 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1312 | scoped_refptr<MockProfile> profile1( |
| 1313 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1314 | |
| 1315 | const string kProfileName0 = "profile0"; |
| 1316 | const string kProfileName1 = "profile1"; |
| 1317 | |
| 1318 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 1319 | .WillRepeatedly(Return(kProfileName0)); |
| 1320 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 1321 | .WillRepeatedly(Return(kProfileName1)); |
| 1322 | |
| 1323 | AdoptProfile(manager(), profile0); |
| 1324 | AdoptProfile(manager(), profile1); // profile1 is now the ActiveProfile. |
| 1325 | |
| 1326 | const std::vector<uint8_t> ssid; |
| 1327 | scoped_refptr<MockWiFiService> service( |
| 1328 | new NiceMock<MockWiFiService>(control_interface(), |
| 1329 | dispatcher(), |
| 1330 | metrics(), |
| 1331 | manager(), |
| 1332 | mock_wifi_, |
| 1333 | ssid, |
| 1334 | "", |
| 1335 | "", |
| 1336 | false)); |
| 1337 | |
| 1338 | service->set_profile(profile1); |
| 1339 | |
| 1340 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1341 | // the same device as that used above causes a refcounting loop. |
| 1342 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1343 | dispatcher(), |
| 1344 | metrics(), |
| 1345 | manager(), |
| 1346 | "wifi1", |
| 1347 | "addr5", |
| 1348 | 5)); |
| 1349 | manager()->RegisterDevice(wifi); |
| 1350 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1351 | .WillOnce(Return(service)); |
| 1352 | EXPECT_CALL(*profile0, UpdateService(ServiceRefPtr(service.get()))) |
| 1353 | .WillOnce(Return(true)); |
| 1354 | EXPECT_CALL(*profile0, AdoptService(_)) |
| 1355 | .Times(0); |
| 1356 | EXPECT_CALL(*profile1, AdoptService(_)) |
| 1357 | .Times(0); |
| 1358 | |
| 1359 | KeyValueStore args; |
| 1360 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1361 | args.SetString(flimflam::kProfileProperty, kProfileName0); |
| 1362 | Error error; |
| 1363 | manager()->ConfigureService(args, &error); |
| 1364 | EXPECT_TRUE(error.IsSuccess()); |
| 1365 | } |
| 1366 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1367 | TEST_F(ManagerTest, TechnologyOrder) { |
| 1368 | Error error; |
| 1369 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "," + |
| 1370 | string(flimflam::kTypeWifi), &error); |
| 1371 | ASSERT_TRUE(error.IsSuccess()); |
| 1372 | EXPECT_EQ(manager()->GetTechnologyOrder(), |
| 1373 | string(flimflam::kTypeEthernet) + "," + |
| 1374 | string(flimflam::kTypeWifi)); |
| 1375 | |
| 1376 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "x," + |
| 1377 | string(flimflam::kTypeWifi), &error); |
| 1378 | ASSERT_FALSE(error.IsSuccess()); |
| 1379 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1380 | EXPECT_EQ(string(flimflam::kTypeEthernet) + "," + |
| 1381 | string(flimflam::kTypeWifi), |
| 1382 | manager()->GetTechnologyOrder()); |
| 1383 | } |
| 1384 | |
| 1385 | TEST_F(ManagerTest, SortServices) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1386 | // TODO(quiche): Some of these tests would probably fit better in |
| 1387 | // service_unittest, since the actual comparison of Services is |
| 1388 | // implemented in Service. (crosbug.com/23370) |
| 1389 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1390 | scoped_refptr<MockService> mock_service0( |
| 1391 | new NiceMock<MockService>(control_interface(), |
| 1392 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1393 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1394 | manager())); |
| 1395 | scoped_refptr<MockService> mock_service1( |
| 1396 | new NiceMock<MockService>(control_interface(), |
| 1397 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1398 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1399 | manager())); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1400 | |
| 1401 | manager()->RegisterService(mock_service0); |
| 1402 | manager()->RegisterService(mock_service1); |
| 1403 | |
| 1404 | // Services should already be sorted by UniqueName |
| 1405 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1406 | |
| 1407 | // Asking explictly to sort services should not change anything |
| 1408 | manager()->SortServices(); |
| 1409 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1410 | |
| 1411 | // Two otherwise equal services should be reordered by strength |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 1412 | mock_service1->SetStrength(1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1413 | manager()->UpdateService(mock_service1); |
| 1414 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1415 | |
| 1416 | // Security |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 1417 | mock_service0->set_security_level(1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1418 | manager()->UpdateService(mock_service0); |
| 1419 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1420 | |
| 1421 | // Technology |
| 1422 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Technology::kWifi)) |
| 1423 | .WillRepeatedly(Return(true)); |
| 1424 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Technology::kEthernet)) |
| 1425 | .WillRepeatedly(Return(true)); |
| 1426 | // NB: Redefine default (false) return values so we don't use the default rule |
| 1427 | // which makes the logs noisier |
| 1428 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Ne(Technology::kWifi))) |
| 1429 | .WillRepeatedly(Return(false)); |
| 1430 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Ne(Technology::kEthernet))) |
| 1431 | .WillRepeatedly(Return(false)); |
| 1432 | |
| 1433 | Error error; |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 1434 | // Default technology ordering should favor Ethernet over WiFi. |
| 1435 | manager()->SortServices(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1436 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1437 | |
| 1438 | manager()->SetTechnologyOrder(string(flimflam::kTypeWifi) + "," + |
| 1439 | string(flimflam::kTypeEthernet), &error); |
| 1440 | EXPECT_TRUE(error.IsSuccess()); |
| 1441 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1442 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1443 | // Priority. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1444 | mock_service0->set_priority(1); |
| 1445 | manager()->UpdateService(mock_service0); |
| 1446 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1447 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1448 | // Favorite. |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1449 | mock_service1->MakeFavorite(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1450 | manager()->UpdateService(mock_service1); |
| 1451 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1452 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1453 | // Auto-connect. |
| 1454 | mock_service0->set_auto_connect(true); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1455 | manager()->UpdateService(mock_service0); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1456 | mock_service1->set_auto_connect(false); |
| 1457 | manager()->UpdateService(mock_service1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1458 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1459 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1460 | // Connectable. |
| 1461 | mock_service1->set_connectable(true); |
| 1462 | manager()->UpdateService(mock_service1); |
| 1463 | mock_service0->set_connectable(false); |
| 1464 | manager()->UpdateService(mock_service0); |
| 1465 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1466 | |
| 1467 | // IsFailed. |
| 1468 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1469 | .WillRepeatedly(Return(Service::kStateIdle)); |
| 1470 | EXPECT_CALL(*mock_service0.get(), IsFailed()) |
| 1471 | .WillRepeatedly(Return(false)); |
| 1472 | manager()->UpdateService(mock_service0); |
| 1473 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1474 | .WillRepeatedly(Return(Service::kStateFailure)); |
| 1475 | EXPECT_CALL(*mock_service1.get(), IsFailed()) |
| 1476 | .WillRepeatedly(Return(true)); |
| 1477 | manager()->UpdateService(mock_service1); |
| 1478 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1479 | |
| 1480 | // Connecting. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1481 | EXPECT_CALL(*mock_service1.get(), state()) |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1482 | .WillRepeatedly(Return(Service::kStateAssociating)); |
| 1483 | EXPECT_CALL(*mock_service1.get(), IsConnecting()) |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1484 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1485 | manager()->UpdateService(mock_service1); |
| 1486 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1487 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1488 | // Connected. |
| 1489 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1490 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 1491 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1492 | .WillRepeatedly(Return(true)); |
| 1493 | manager()->UpdateService(mock_service0); |
| 1494 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1495 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1496 | manager()->DeregisterService(mock_service0); |
| 1497 | manager()->DeregisterService(mock_service1); |
| 1498 | } |
| 1499 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1500 | TEST_F(ManagerTest, SortServicesWithConnection) { |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1501 | MockMetrics mock_metrics; |
| 1502 | manager()->set_metrics(&mock_metrics); |
| 1503 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1504 | scoped_refptr<MockService> mock_service0( |
| 1505 | new NiceMock<MockService>(control_interface(), |
| 1506 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1507 | metrics(), |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1508 | manager())); |
| 1509 | scoped_refptr<MockService> mock_service1( |
| 1510 | new NiceMock<MockService>(control_interface(), |
| 1511 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1512 | metrics(), |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1513 | manager())); |
| 1514 | |
| 1515 | scoped_refptr<MockConnection> mock_connection0( |
| 1516 | new NiceMock<MockConnection>(device_info_.get())); |
| 1517 | scoped_refptr<MockConnection> mock_connection1( |
| 1518 | new NiceMock<MockConnection>(device_info_.get())); |
| 1519 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1520 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1521 | manager()->RegisterService(mock_service0); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1522 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1523 | manager()->RegisterService(mock_service1); |
| 1524 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1525 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1526 | manager()->SortServices(); |
| 1527 | |
| 1528 | mock_service1->set_priority(1); |
| 1529 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1530 | manager()->SortServices(); |
| 1531 | |
| 1532 | mock_service1->set_priority(0); |
| 1533 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1534 | manager()->SortServices(); |
| 1535 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1536 | mock_service0->set_mock_connection(mock_connection0); |
| 1537 | mock_service1->set_mock_connection(mock_connection1); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1538 | |
| 1539 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1540 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service0.get())); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1541 | manager()->SortServices(); |
| 1542 | |
| 1543 | mock_service1->set_priority(1); |
| 1544 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(false)); |
| 1545 | EXPECT_CALL(*mock_connection1.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1546 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service1.get())); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1547 | manager()->SortServices(); |
| 1548 | |
| 1549 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1550 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service0.get())); |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1551 | mock_service1->set_mock_connection(NULL); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1552 | manager()->DeregisterService(mock_service1); |
| 1553 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1554 | mock_service0->set_mock_connection(NULL); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1555 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1556 | manager()->DeregisterService(mock_service0); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1557 | |
| 1558 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1559 | manager()->SortServices(); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1562 | TEST_F(ManagerTest, AvailableTechnologies) { |
| 1563 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 1564 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1565 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1566 | manager(), |
| 1567 | "null4", |
| 1568 | "addr4", |
| 1569 | 0)); |
| 1570 | manager()->RegisterDevice(mock_devices_[0]); |
| 1571 | manager()->RegisterDevice(mock_devices_[1]); |
| 1572 | manager()->RegisterDevice(mock_devices_[2]); |
| 1573 | manager()->RegisterDevice(mock_devices_[3]); |
| 1574 | |
| 1575 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 1576 | .WillByDefault(Return(Technology::kEthernet)); |
| 1577 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 1578 | .WillByDefault(Return(Technology::kWifi)); |
| 1579 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 1580 | .WillByDefault(Return(Technology::kCellular)); |
| 1581 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 1582 | .WillByDefault(Return(Technology::kWifi)); |
| 1583 | |
| 1584 | set<string> expected_technologies; |
| 1585 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1586 | Technology::kEthernet)); |
| 1587 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1588 | Technology::kWifi)); |
| 1589 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1590 | Technology::kCellular)); |
| 1591 | Error error; |
| 1592 | vector<string> technologies = manager()->AvailableTechnologies(&error); |
| 1593 | |
| 1594 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 1595 | ContainerEq(expected_technologies)); |
| 1596 | } |
| 1597 | |
| 1598 | TEST_F(ManagerTest, ConnectedTechnologies) { |
| 1599 | scoped_refptr<MockService> connected_service1( |
| 1600 | new NiceMock<MockService>(control_interface(), |
| 1601 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1602 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1603 | manager())); |
| 1604 | scoped_refptr<MockService> connected_service2( |
| 1605 | new NiceMock<MockService>(control_interface(), |
| 1606 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1607 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1608 | manager())); |
| 1609 | scoped_refptr<MockService> disconnected_service1( |
| 1610 | new NiceMock<MockService>(control_interface(), |
| 1611 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1612 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1613 | manager())); |
| 1614 | scoped_refptr<MockService> disconnected_service2( |
| 1615 | new NiceMock<MockService>(control_interface(), |
| 1616 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1617 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1618 | manager())); |
| 1619 | |
| 1620 | ON_CALL(*connected_service1.get(), IsConnected()) |
| 1621 | .WillByDefault(Return(true)); |
| 1622 | ON_CALL(*connected_service2.get(), IsConnected()) |
| 1623 | .WillByDefault(Return(true)); |
| 1624 | |
| 1625 | manager()->RegisterService(connected_service1); |
| 1626 | manager()->RegisterService(connected_service2); |
| 1627 | manager()->RegisterService(disconnected_service1); |
| 1628 | manager()->RegisterService(disconnected_service2); |
| 1629 | |
| 1630 | manager()->RegisterDevice(mock_devices_[0]); |
| 1631 | manager()->RegisterDevice(mock_devices_[1]); |
| 1632 | manager()->RegisterDevice(mock_devices_[2]); |
| 1633 | manager()->RegisterDevice(mock_devices_[3]); |
| 1634 | |
| 1635 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 1636 | .WillByDefault(Return(Technology::kEthernet)); |
| 1637 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 1638 | .WillByDefault(Return(Technology::kWifi)); |
| 1639 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 1640 | .WillByDefault(Return(Technology::kCellular)); |
| 1641 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 1642 | .WillByDefault(Return(Technology::kWifi)); |
| 1643 | |
| 1644 | mock_devices_[0]->SelectService(connected_service1); |
| 1645 | mock_devices_[1]->SelectService(disconnected_service1); |
| 1646 | mock_devices_[2]->SelectService(disconnected_service2); |
| 1647 | mock_devices_[3]->SelectService(connected_service2); |
| 1648 | |
| 1649 | set<string> expected_technologies; |
| 1650 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1651 | Technology::kEthernet)); |
| 1652 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1653 | Technology::kWifi)); |
| 1654 | Error error; |
| 1655 | |
| 1656 | vector<string> technologies = manager()->ConnectedTechnologies(&error); |
| 1657 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 1658 | ContainerEq(expected_technologies)); |
| 1659 | } |
| 1660 | |
| 1661 | TEST_F(ManagerTest, DefaultTechnology) { |
| 1662 | scoped_refptr<MockService> connected_service( |
| 1663 | new NiceMock<MockService>(control_interface(), |
| 1664 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1665 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1666 | manager())); |
| 1667 | scoped_refptr<MockService> disconnected_service( |
| 1668 | new NiceMock<MockService>(control_interface(), |
| 1669 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1670 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1671 | manager())); |
| 1672 | |
| 1673 | // Connected. WiFi. |
| 1674 | ON_CALL(*connected_service.get(), IsConnected()) |
| 1675 | .WillByDefault(Return(true)); |
| 1676 | ON_CALL(*connected_service.get(), state()) |
| 1677 | .WillByDefault(Return(Service::kStateConnected)); |
| 1678 | ON_CALL(*connected_service.get(), technology()) |
| 1679 | .WillByDefault(Return(Technology::kWifi)); |
| 1680 | |
| 1681 | // Disconnected. Ethernet. |
| 1682 | ON_CALL(*disconnected_service.get(), technology()) |
| 1683 | .WillByDefault(Return(Technology::kEthernet)); |
| 1684 | |
| 1685 | manager()->RegisterService(disconnected_service); |
| 1686 | Error error; |
| 1687 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq("")); |
| 1688 | |
| 1689 | |
| 1690 | manager()->RegisterService(connected_service); |
| 1691 | // Connected service should be brought to the front now. |
| 1692 | string expected_technology = |
| 1693 | Technology::NameFromIdentifier(Technology::kWifi); |
| 1694 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq(expected_technology)); |
| 1695 | } |
| 1696 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1697 | TEST_F(ManagerTest, DisconnectServicesOnStop) { |
| 1698 | scoped_refptr<MockService> mock_service( |
| 1699 | new NiceMock<MockService>(control_interface(), |
| 1700 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1701 | metrics(), |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1702 | manager())); |
| 1703 | manager()->RegisterService(mock_service); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1704 | EXPECT_CALL(*mock_service.get(), Disconnect(_)).Times(1); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1705 | manager()->Stop(); |
| 1706 | } |
| 1707 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1708 | TEST_F(ManagerTest, UpdateServiceConnected) { |
| 1709 | scoped_refptr<MockService> mock_service( |
| 1710 | new NiceMock<MockService>(control_interface(), |
| 1711 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1712 | metrics(), |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1713 | manager())); |
| 1714 | manager()->RegisterService(mock_service); |
| 1715 | EXPECT_FALSE(mock_service->favorite()); |
| 1716 | EXPECT_FALSE(mock_service->auto_connect()); |
| 1717 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1718 | EXPECT_CALL(*mock_service.get(), IsConnected()) |
| 1719 | .WillRepeatedly(Return(true)); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1720 | manager()->UpdateService(mock_service); |
| 1721 | // We can't EXPECT_CALL(..., MakeFavorite), because that requires us |
| 1722 | // to mock out MakeFavorite. And mocking that out would break the |
| 1723 | // SortServices test. (crosbug.com/23370) |
| 1724 | EXPECT_TRUE(mock_service->favorite()); |
| 1725 | EXPECT_TRUE(mock_service->auto_connect()); |
| 1726 | } |
| 1727 | |
Thieu Le | d4e9e55 | 2012-02-16 16:26:07 -0800 | [diff] [blame] | 1728 | TEST_F(ManagerTest, UpdateServiceConnectedPersistFavorite) { |
| 1729 | // This tests the case where the user connects to a service that is |
| 1730 | // currently associated with a profile. We want to make sure that the |
| 1731 | // favorite flag is set and that the flag is saved to the current |
| 1732 | // profile. |
| 1733 | scoped_refptr<MockService> mock_service( |
| 1734 | new NiceMock<MockService>(control_interface(), |
| 1735 | dispatcher(), |
| 1736 | metrics(), |
| 1737 | manager())); |
| 1738 | manager()->RegisterService(mock_service); |
| 1739 | EXPECT_FALSE(mock_service->favorite()); |
| 1740 | EXPECT_FALSE(mock_service->auto_connect()); |
| 1741 | |
| 1742 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
| 1743 | mock_service->set_profile(profile); |
| 1744 | |
| 1745 | EXPECT_CALL(*mock_service.get(), IsConnected()) |
| 1746 | .WillRepeatedly(Return(true)); |
| 1747 | EXPECT_CALL(*mock_service.get(), SaveToCurrentProfile()); |
| 1748 | manager()->UpdateService(mock_service); |
| 1749 | // We can't EXPECT_CALL(..., MakeFavorite), because that requires us |
| 1750 | // to mock out MakeFavorite. And mocking that out would break the |
| 1751 | // SortServices test. (crosbug.com/23370) |
| 1752 | EXPECT_TRUE(mock_service->favorite()); |
| 1753 | EXPECT_TRUE(mock_service->auto_connect()); |
| 1754 | } |
| 1755 | |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1756 | TEST_F(ManagerTest, SaveSuccessfulService) { |
| 1757 | scoped_refptr<MockProfile> profile( |
| 1758 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1759 | AdoptProfile(manager(), profile); |
| 1760 | scoped_refptr<MockService> service( |
| 1761 | new NiceMock<MockService>(control_interface(), |
| 1762 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1763 | metrics(), |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1764 | manager())); |
| 1765 | |
| 1766 | // Re-cast this back to a ServiceRefPtr, so EXPECT arguments work correctly. |
| 1767 | ServiceRefPtr expect_service(service.get()); |
| 1768 | |
| 1769 | EXPECT_CALL(*profile.get(), ConfigureService(expect_service)) |
| 1770 | .WillOnce(Return(false)); |
| 1771 | manager()->RegisterService(service); |
| 1772 | |
| 1773 | EXPECT_CALL(*service.get(), state()) |
| 1774 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 1775 | EXPECT_CALL(*service.get(), IsConnected()) |
| 1776 | .WillRepeatedly(Return(true)); |
| 1777 | EXPECT_CALL(*profile.get(), AdoptService(expect_service)) |
| 1778 | .WillOnce(Return(true)); |
| 1779 | manager()->UpdateService(service); |
| 1780 | } |
| 1781 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1782 | TEST_F(ManagerTest, EnumerateProfiles) { |
| 1783 | vector<string> profile_paths; |
| 1784 | for (size_t i = 0; i < 10; i++) { |
| 1785 | scoped_refptr<MockProfile> profile( |
| 1786 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
Jason Glasgow | 5d8197b | 2012-01-27 08:37:32 -0500 | [diff] [blame] | 1787 | profile_paths.push_back(base::StringPrintf("/profile/%zd", i)); |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1788 | EXPECT_CALL(*profile.get(), GetRpcIdentifier()) |
| 1789 | .WillOnce(Return(profile_paths.back())); |
| 1790 | AdoptProfile(manager(), profile); |
| 1791 | } |
| 1792 | |
| 1793 | Error error; |
| 1794 | vector<string> returned_paths = manager()->EnumerateProfiles(&error); |
| 1795 | EXPECT_TRUE(error.IsSuccess()); |
| 1796 | EXPECT_EQ(profile_paths.size(), returned_paths.size()); |
| 1797 | for (size_t i = 0; i < profile_paths.size(); i++) { |
| 1798 | EXPECT_EQ(profile_paths[i], returned_paths[i]); |
| 1799 | } |
| 1800 | } |
| 1801 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1802 | TEST_F(ManagerTest, AutoConnectOnRegister) { |
| 1803 | MockServiceRefPtr service = MakeAutoConnectableService(); |
| 1804 | EXPECT_CALL(*service.get(), AutoConnect()); |
| 1805 | manager()->RegisterService(service); |
| 1806 | dispatcher()->DispatchPendingEvents(); |
| 1807 | } |
| 1808 | |
| 1809 | TEST_F(ManagerTest, AutoConnectOnUpdate) { |
| 1810 | MockServiceRefPtr service1 = MakeAutoConnectableService(); |
| 1811 | service1->set_priority(1); |
| 1812 | MockServiceRefPtr service2 = MakeAutoConnectableService(); |
| 1813 | service2->set_priority(2); |
| 1814 | manager()->RegisterService(service1); |
| 1815 | manager()->RegisterService(service2); |
| 1816 | dispatcher()->DispatchPendingEvents(); |
| 1817 | |
| 1818 | EXPECT_CALL(*service1.get(), AutoConnect()); |
| 1819 | EXPECT_CALL(*service2.get(), state()) |
| 1820 | .WillRepeatedly(Return(Service::kStateFailure)); |
| 1821 | EXPECT_CALL(*service2.get(), IsFailed()) |
| 1822 | .WillRepeatedly(Return(true)); |
| 1823 | EXPECT_CALL(*service2.get(), IsConnected()) |
| 1824 | .WillRepeatedly(Return(false)); |
| 1825 | manager()->UpdateService(service2); |
| 1826 | dispatcher()->DispatchPendingEvents(); |
| 1827 | } |
| 1828 | |
| 1829 | TEST_F(ManagerTest, AutoConnectOnDeregister) { |
| 1830 | MockServiceRefPtr service1 = MakeAutoConnectableService(); |
| 1831 | service1->set_priority(1); |
| 1832 | MockServiceRefPtr service2 = MakeAutoConnectableService(); |
| 1833 | service2->set_priority(2); |
| 1834 | manager()->RegisterService(service1); |
| 1835 | manager()->RegisterService(service2); |
| 1836 | dispatcher()->DispatchPendingEvents(); |
| 1837 | |
| 1838 | EXPECT_CALL(*service1.get(), AutoConnect()); |
| 1839 | manager()->DeregisterService(service2); |
| 1840 | dispatcher()->DispatchPendingEvents(); |
| 1841 | } |
| 1842 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 1843 | TEST_F(ManagerTest, RecheckPortal) { |
| 1844 | EXPECT_CALL(*mock_devices_[0].get(), RequestPortalDetection()) |
| 1845 | .WillOnce(Return(false)); |
| 1846 | EXPECT_CALL(*mock_devices_[1].get(), RequestPortalDetection()) |
| 1847 | .WillOnce(Return(true)); |
| 1848 | EXPECT_CALL(*mock_devices_[2].get(), RequestPortalDetection()) |
| 1849 | .Times(0); |
| 1850 | |
| 1851 | manager()->RegisterDevice(mock_devices_[0]); |
| 1852 | manager()->RegisterDevice(mock_devices_[1]); |
| 1853 | manager()->RegisterDevice(mock_devices_[2]); |
| 1854 | |
| 1855 | manager()->RecheckPortal(NULL); |
| 1856 | } |
| 1857 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1858 | TEST_F(ManagerTest, GetDefaultService) { |
| 1859 | EXPECT_FALSE(manager()->GetDefaultService().get()); |
| 1860 | |
| 1861 | scoped_refptr<MockService> mock_service( |
| 1862 | new NiceMock<MockService>(control_interface(), |
| 1863 | dispatcher(), |
| 1864 | metrics(), |
| 1865 | manager())); |
| 1866 | |
| 1867 | manager()->RegisterService(mock_service); |
| 1868 | EXPECT_FALSE(manager()->GetDefaultService().get()); |
| 1869 | |
| 1870 | scoped_refptr<MockConnection> mock_connection( |
| 1871 | new NiceMock<MockConnection>(device_info_.get())); |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1872 | mock_service->set_mock_connection(mock_connection); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1873 | EXPECT_EQ(mock_service.get(), manager()->GetDefaultService().get()); |
| 1874 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1875 | mock_service->set_mock_connection(NULL); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1876 | manager()->DeregisterService(mock_service); |
| 1877 | } |
| 1878 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1879 | TEST_F(ManagerTest, GetServiceWithGUID) { |
| 1880 | scoped_refptr<MockService> mock_service0( |
| 1881 | new NiceMock<MockService>(control_interface(), |
| 1882 | dispatcher(), |
| 1883 | metrics(), |
| 1884 | manager())); |
| 1885 | |
| 1886 | scoped_refptr<MockService> mock_service1( |
| 1887 | new NiceMock<MockService>(control_interface(), |
| 1888 | dispatcher(), |
| 1889 | metrics(), |
| 1890 | manager())); |
| 1891 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1892 | EXPECT_CALL(*mock_service0.get(), Configure(_, _)) |
| 1893 | .Times(0); |
| 1894 | EXPECT_CALL(*mock_service1.get(), Configure(_, _)) |
| 1895 | .Times(0); |
| 1896 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1897 | manager()->RegisterService(mock_service0); |
| 1898 | manager()->RegisterService(mock_service1); |
| 1899 | |
| 1900 | const string kGUID0 = "GUID0"; |
| 1901 | const string kGUID1 = "GUID1"; |
| 1902 | |
| 1903 | { |
| 1904 | Error error; |
| 1905 | ServiceRefPtr service = manager()->GetServiceWithGUID(kGUID0, &error); |
| 1906 | EXPECT_FALSE(error.IsSuccess()); |
| 1907 | EXPECT_FALSE(service); |
| 1908 | } |
| 1909 | |
| 1910 | KeyValueStore args; |
| 1911 | args.SetString(flimflam::kGuidProperty, kGUID1); |
| 1912 | |
| 1913 | { |
| 1914 | Error error; |
| 1915 | ServiceRefPtr service = manager()->GetService(args, &error); |
| 1916 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1917 | EXPECT_FALSE(service); |
| 1918 | } |
| 1919 | |
| 1920 | mock_service0->set_guid(kGUID0); |
| 1921 | mock_service1->set_guid(kGUID1); |
| 1922 | |
| 1923 | { |
| 1924 | Error error; |
| 1925 | ServiceRefPtr service = manager()->GetServiceWithGUID(kGUID0, &error); |
| 1926 | EXPECT_TRUE(error.IsSuccess()); |
| 1927 | EXPECT_EQ(mock_service0.get(), service.get()); |
| 1928 | } |
| 1929 | |
| 1930 | { |
| 1931 | Error error; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1932 | EXPECT_CALL(*mock_service1.get(), Configure(_, &error)) |
| 1933 | .Times(1); |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1934 | ServiceRefPtr service = manager()->GetService(args, &error); |
| 1935 | EXPECT_TRUE(error.IsSuccess()); |
| 1936 | EXPECT_EQ(mock_service1.get(), service.get()); |
| 1937 | } |
| 1938 | |
| 1939 | manager()->DeregisterService(mock_service0); |
| 1940 | manager()->DeregisterService(mock_service1); |
| 1941 | } |
| 1942 | |
Gary Morain | 028545d | 2012-04-07 14:55:52 -0700 | [diff] [blame] | 1943 | |
| 1944 | TEST_F(ManagerTest, CalculateStateOffline) { |
| 1945 | MockMetrics mock_metrics; |
| 1946 | manager()->set_metrics(&mock_metrics); |
| 1947 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(_)) |
| 1948 | .Times(AnyNumber()); |
| 1949 | scoped_refptr<MockService> mock_service0( |
| 1950 | new NiceMock<MockService>(control_interface(), |
| 1951 | dispatcher(), |
| 1952 | metrics(), |
| 1953 | manager())); |
| 1954 | |
| 1955 | scoped_refptr<MockService> mock_service1( |
| 1956 | new NiceMock<MockService>(control_interface(), |
| 1957 | dispatcher(), |
| 1958 | metrics(), |
| 1959 | manager())); |
| 1960 | |
| 1961 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1962 | .WillRepeatedly(Return(false)); |
| 1963 | EXPECT_CALL(*mock_service1.get(), IsConnected()) |
| 1964 | .WillRepeatedly(Return(false)); |
| 1965 | |
| 1966 | manager()->RegisterService(mock_service0); |
| 1967 | manager()->RegisterService(mock_service1); |
| 1968 | |
| 1969 | EXPECT_EQ("offline", manager()->CalculateState(NULL)); |
| 1970 | |
| 1971 | manager()->DeregisterService(mock_service0); |
| 1972 | manager()->DeregisterService(mock_service1); |
| 1973 | } |
| 1974 | |
| 1975 | TEST_F(ManagerTest, CalculateStateOnline) { |
| 1976 | MockMetrics mock_metrics; |
| 1977 | manager()->set_metrics(&mock_metrics); |
| 1978 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(_)) |
| 1979 | .Times(AnyNumber()); |
| 1980 | scoped_refptr<MockService> mock_service0( |
| 1981 | new NiceMock<MockService>(control_interface(), |
| 1982 | dispatcher(), |
| 1983 | metrics(), |
| 1984 | manager())); |
| 1985 | |
| 1986 | scoped_refptr<MockService> mock_service1( |
| 1987 | new NiceMock<MockService>(control_interface(), |
| 1988 | dispatcher(), |
| 1989 | metrics(), |
| 1990 | manager())); |
| 1991 | |
| 1992 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1993 | .WillRepeatedly(Return(false)); |
| 1994 | EXPECT_CALL(*mock_service1.get(), IsConnected()) |
| 1995 | .WillRepeatedly(Return(true)); |
| 1996 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1997 | .WillRepeatedly(Return(Service::kStateIdle)); |
| 1998 | EXPECT_CALL(*mock_service1.get(), state()) |
| 1999 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 2000 | |
| 2001 | manager()->RegisterService(mock_service0); |
| 2002 | manager()->RegisterService(mock_service1); |
| 2003 | |
| 2004 | EXPECT_EQ("online", manager()->CalculateState(NULL)); |
| 2005 | |
| 2006 | manager()->DeregisterService(mock_service0); |
| 2007 | manager()->DeregisterService(mock_service1); |
| 2008 | } |
| 2009 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 2010 | } // namespace shill |