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 | EXPECT_CALL(*storage, ContainsGroup(s2->GetStorageIdentifier())) |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 479 | .WillRepeatedly(Return(true)); |
| 480 | EXPECT_CALL(*storage, Flush()) |
| 481 | .Times(AnyNumber()) |
| 482 | .WillRepeatedly(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 483 | profile->set_storage(storage); |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 484 | AdoptProfile(&manager, profile); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 485 | } |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 486 | // Create a profile that already has |s2| in it. |
| 487 | ProfileRefPtr profile(new EphemeralProfile(control_interface(), &manager)); |
Paul Stewart | 451aa7f | 2012-04-11 19:07:58 -0700 | [diff] [blame] | 488 | EXPECT_TRUE(profile->AdoptService(s2)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 489 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 490 | // Now, move the Service |s2| to another profile. |
| 491 | EXPECT_CALL(*s2.get(), Save(_)).WillOnce(Return(true)); |
| 492 | ASSERT_TRUE(manager.MoveServiceToProfile(s2, manager.ActiveProfile())); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 493 | |
| 494 | // Force destruction of the original Profile, to ensure that the Service |
| 495 | // is kept alive and populated with data. |
| 496 | profile = NULL; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 497 | ASSERT_TRUE(manager.ActiveProfile()->ContainsService(s2)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 498 | manager.Stop(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 501 | TEST_F(ManagerTest, LookupProfileByRpcIdentifier) { |
| 502 | scoped_refptr<MockProfile> mock_profile( |
| 503 | new MockProfile(control_interface(), manager(), "")); |
| 504 | const string kProfileName("profile0"); |
| 505 | EXPECT_CALL(*mock_profile, GetRpcIdentifier()) |
| 506 | .WillRepeatedly(Return(kProfileName)); |
| 507 | AdoptProfile(manager(), mock_profile); |
| 508 | |
| 509 | EXPECT_FALSE(manager()->LookupProfileByRpcIdentifier("foo")); |
| 510 | ProfileRefPtr profile = manager()->LookupProfileByRpcIdentifier(kProfileName); |
| 511 | EXPECT_EQ(mock_profile.get(), profile.get()); |
| 512 | } |
| 513 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 514 | TEST_F(ManagerTest, SetProfileForService) { |
| 515 | scoped_refptr<MockProfile> profile0( |
| 516 | new MockProfile(control_interface(), manager(), "")); |
| 517 | string profile_name0("profile0"); |
| 518 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 519 | .WillRepeatedly(Return(profile_name0)); |
| 520 | AdoptProfile(manager(), profile0); |
| 521 | scoped_refptr<MockService> service(new MockService(control_interface(), |
| 522 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 523 | metrics(), |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 524 | manager())); |
| 525 | service->set_profile(profile0); |
| 526 | |
| 527 | { |
| 528 | Error error; |
| 529 | manager()->SetProfileForService(service, "foo", &error); |
| 530 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 531 | EXPECT_EQ("Unknown Profile foo requested for Service", error.message()); |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | { |
| 535 | Error error; |
| 536 | manager()->SetProfileForService(service, profile_name0, &error); |
| 537 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 538 | EXPECT_EQ("Service is already connected to this profile", error.message()); |
| 539 | } |
| 540 | |
| 541 | scoped_refptr<MockProfile> profile1( |
| 542 | new MockProfile(control_interface(), manager(), "")); |
| 543 | string profile_name1("profile1"); |
| 544 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 545 | .WillRepeatedly(Return(profile_name1)); |
| 546 | AdoptProfile(manager(), profile1); |
| 547 | |
| 548 | { |
| 549 | Error error; |
| 550 | EXPECT_CALL(*profile1, AdoptService(_)) |
| 551 | .WillOnce(Return(true)); |
| 552 | EXPECT_CALL(*profile0, AbandonService(_)) |
| 553 | .WillOnce(Return(true)); |
| 554 | manager()->SetProfileForService(service, profile_name1, &error); |
| 555 | EXPECT_TRUE(error.IsSuccess()); |
| 556 | } |
| 557 | } |
| 558 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 559 | TEST_F(ManagerTest, CreateProfile) { |
| 560 | // It's much easier to use real Glib here since we want the storage |
| 561 | // side-effects. |
| 562 | GLib glib; |
| 563 | ScopedTempDir temp_dir; |
| 564 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 565 | |
| 566 | Manager manager(control_interface(), |
| 567 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 568 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 569 | &glib, |
| 570 | run_path(), |
| 571 | storage_path(), |
| 572 | temp_dir.path().value()); |
| 573 | |
| 574 | // Invalid name should be rejected. |
| 575 | EXPECT_EQ(Error::kInvalidArguments, TestCreateProfile(&manager, "")); |
| 576 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 577 | // A profile with invalid characters in it should similarly be rejected. |
| 578 | EXPECT_EQ(Error::kInvalidArguments, |
| 579 | TestCreateProfile(&manager, "valid_profile")); |
| 580 | |
| 581 | // We should be able to create a machine profile. |
| 582 | EXPECT_EQ(Error::kSuccess, TestCreateProfile(&manager, "valid")); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 583 | |
Gary Morain | b672d35 | 2012-04-25 09:19:06 -0700 | [diff] [blame^] | 584 | // We should succeed in creating a valid user profile. Verify the returned |
| 585 | // path. |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 586 | const char kProfile[] = "~user/profile"; |
Gary Morain | b672d35 | 2012-04-25 09:19:06 -0700 | [diff] [blame^] | 587 | { |
| 588 | Error error; |
| 589 | string path; |
| 590 | manager.CreateProfile(kProfile, &path, &error); |
| 591 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 592 | EXPECT_EQ("/profile_rpc", path); |
| 593 | } |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 594 | |
| 595 | // We should fail in creating it a second time (already exists). |
| 596 | EXPECT_EQ(Error::kAlreadyExists, TestCreateProfile(&manager, kProfile)); |
| 597 | } |
| 598 | |
| 599 | TEST_F(ManagerTest, PushPopProfile) { |
| 600 | // It's much easier to use real Glib in creating a Manager for this |
| 601 | // test here since we want the storage side-effects. |
| 602 | GLib glib; |
| 603 | ScopedTempDir temp_dir; |
| 604 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 605 | Manager manager(control_interface(), |
| 606 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 607 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 608 | &glib, |
| 609 | run_path(), |
| 610 | storage_path(), |
| 611 | temp_dir.path().value()); |
| 612 | |
| 613 | // Pushing an invalid profile should fail. |
| 614 | EXPECT_EQ(Error::kInvalidArguments, TestPushProfile(&manager, "")); |
| 615 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 616 | // Pushing a default profile that does not exist should fail. |
| 617 | EXPECT_EQ(Error::kNotFound, TestPushProfile(&manager, "default")); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 618 | |
| 619 | const char kProfile0[] = "~user/profile0"; |
| 620 | const char kProfile1[] = "~user/profile1"; |
| 621 | |
| 622 | // Create a couple of profiles. |
| 623 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile0)); |
| 624 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile1)); |
| 625 | |
| 626 | // Push these profiles on the stack. |
| 627 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 628 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile1)); |
| 629 | |
| 630 | // Pushing a profile a second time should fail. |
| 631 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile0)); |
| 632 | EXPECT_EQ(Error::kAlreadyExists, TestPushProfile(&manager, kProfile1)); |
| 633 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 634 | Error error; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 635 | // Active profile should be the last one we pushed. |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 636 | EXPECT_EQ(kProfile1, "~" + manager.ActiveProfile()->GetFriendlyName()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 637 | |
| 638 | // Make sure a profile name that doesn't exist fails. |
| 639 | const char kProfile2Id[] = "profile2"; |
| 640 | const string kProfile2 = base::StringPrintf("~user/%s", kProfile2Id); |
| 641 | EXPECT_EQ(Error::kNotFound, TestPushProfile(&manager, kProfile2)); |
| 642 | |
| 643 | // Create a new service, with a specific storage name. |
| 644 | scoped_refptr<MockService> service( |
| 645 | new NiceMock<MockService>(control_interface(), |
| 646 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 647 | metrics(), |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 648 | &manager)); |
| 649 | const char kServiceName[] = "service_storage_name"; |
| 650 | EXPECT_CALL(*service.get(), GetStorageIdentifier()) |
| 651 | .WillRepeatedly(Return(kServiceName)); |
| 652 | EXPECT_CALL(*service.get(), Load(_)) |
| 653 | .WillRepeatedly(Return(true)); |
| 654 | |
| 655 | // Add this service to the manager -- it should end up in the ephemeral |
| 656 | // profile. |
| 657 | manager.RegisterService(service); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 658 | ASSERT_EQ(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 659 | |
| 660 | // Create storage for a profile that contains the service storage name. |
| 661 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile2Id, |
| 662 | kServiceName)); |
| 663 | |
| 664 | // When we push the profile, the service should move away from the |
| 665 | // ephemeral profile to this new profile since it has an entry for |
| 666 | // this service. |
| 667 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile2)); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 668 | EXPECT_NE(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 669 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 670 | |
| 671 | // Insert another profile that should supersede ownership of the service. |
| 672 | const char kProfile3Id[] = "profile3"; |
| 673 | const string kProfile3 = base::StringPrintf("~user/%s", kProfile3Id); |
| 674 | ASSERT_TRUE(CreateBackingStoreForService(&temp_dir, kProfile3Id, |
| 675 | kServiceName)); |
| 676 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile3)); |
| 677 | EXPECT_EQ(kProfile3, "~" + service->profile()->GetFriendlyName()); |
| 678 | |
| 679 | // Popping an invalid profile name should fail. |
| 680 | EXPECT_EQ(Error::kInvalidArguments, TestPopProfile(&manager, "~")); |
| 681 | |
| 682 | // Popping an profile that is not at the top of the stack should fail. |
| 683 | EXPECT_EQ(Error::kNotSupported, TestPopProfile(&manager, kProfile0)); |
| 684 | |
| 685 | // Popping the top profile should succeed. |
| 686 | EXPECT_EQ(Error::kSuccess, TestPopProfile(&manager, kProfile3)); |
| 687 | |
| 688 | // Moreover the service should have switched profiles to profile 2. |
| 689 | EXPECT_EQ(kProfile2, "~" + service->profile()->GetFriendlyName()); |
| 690 | |
| 691 | // Popping the top profile should succeed. |
| 692 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 693 | |
| 694 | // The service should now revert to the ephemeral profile. |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 695 | EXPECT_EQ(GetEphemeralProfile(&manager), service->profile()); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 696 | |
| 697 | // Pop the remaining two services off the stack. |
| 698 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 699 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 700 | |
| 701 | // Next pop should fail with "stack is empty". |
| 702 | EXPECT_EQ(Error::kNotFound, TestPopAnyProfile(&manager)); |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 703 | |
| 704 | const char kMachineProfile0[] = "machineprofile0"; |
| 705 | const char kMachineProfile1[] = "machineprofile1"; |
| 706 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kMachineProfile0)); |
| 707 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kMachineProfile1)); |
| 708 | |
| 709 | // Should be able to push a machine profile. |
| 710 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kMachineProfile0)); |
| 711 | |
| 712 | // Should be able to push a user profile atop a machine profile. |
| 713 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 714 | |
| 715 | // Pushing a system-wide profile on top of a user profile should fail. |
| 716 | EXPECT_EQ(Error::kInvalidArguments, |
| 717 | TestPushProfile(&manager, kMachineProfile1)); |
| 718 | |
| 719 | // However if we pop the user profile, we should be able stack another |
| 720 | // machine profile on. |
| 721 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 722 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kMachineProfile1)); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 725 | TEST_F(ManagerTest, RemoveProfile) { |
| 726 | // It's much easier to use real Glib in creating a Manager for this |
| 727 | // test here since we want the storage side-effects. |
| 728 | GLib glib; |
| 729 | ScopedTempDir temp_dir; |
| 730 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 731 | Manager manager(control_interface(), |
| 732 | dispatcher(), |
| 733 | metrics(), |
| 734 | &glib, |
| 735 | run_path(), |
| 736 | storage_path(), |
| 737 | temp_dir.path().value()); |
| 738 | |
| 739 | const char kProfile0[] = "profile0"; |
| 740 | FilePath profile_path( |
| 741 | FilePath(storage_path()).Append(string(kProfile0) + ".profile")); |
| 742 | |
| 743 | ASSERT_EQ(Error::kSuccess, TestCreateProfile(&manager, kProfile0)); |
| 744 | ASSERT_TRUE(file_util::PathExists(profile_path)); |
| 745 | |
| 746 | EXPECT_EQ(Error::kSuccess, TestPushProfile(&manager, kProfile0)); |
| 747 | |
| 748 | // Remove should fail since the profile is still on the stack. |
| 749 | { |
| 750 | Error error; |
| 751 | manager.RemoveProfile(kProfile0, &error); |
| 752 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 753 | } |
| 754 | |
| 755 | // Profile path should still exist. |
| 756 | EXPECT_TRUE(file_util::PathExists(profile_path)); |
| 757 | |
| 758 | EXPECT_EQ(Error::kSuccess, TestPopAnyProfile(&manager)); |
| 759 | |
| 760 | // This should succeed now that the profile is off the stack. |
| 761 | { |
| 762 | Error error; |
| 763 | manager.RemoveProfile(kProfile0, &error); |
| 764 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 765 | } |
| 766 | |
| 767 | // Profile path should no longer exist. |
| 768 | EXPECT_FALSE(file_util::PathExists(profile_path)); |
| 769 | |
| 770 | // Another remove succeeds, due to a foible in file_util::Delete -- |
| 771 | // it is not an error to delete a file that does not exist. |
| 772 | { |
| 773 | Error error; |
| 774 | manager.RemoveProfile(kProfile0, &error); |
| 775 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 776 | } |
| 777 | |
| 778 | // Let's create an error case that will "work". Create a non-empty |
| 779 | // directory in the place of the profile pathname. |
| 780 | ASSERT_TRUE(file_util::CreateDirectory(profile_path.Append("foo"))); |
| 781 | { |
| 782 | Error error; |
| 783 | manager.RemoveProfile(kProfile0, &error); |
| 784 | EXPECT_EQ(Error::kOperationFailed, error.type()); |
| 785 | } |
| 786 | } |
| 787 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 788 | // Use this matcher instead of passing RefPtrs directly into the arguments |
| 789 | // of EXPECT_CALL() because otherwise we may create un-cleaned-up references at |
| 790 | // system teardown. |
| 791 | MATCHER_P(IsRefPtrTo, ref_address, "") { |
| 792 | return arg.get() == ref_address; |
| 793 | } |
| 794 | |
| 795 | TEST_F(ManagerTest, HandleProfileEntryDeletion) { |
| 796 | MockServiceRefPtr s_not_in_profile( |
| 797 | new NiceMock<MockService>(control_interface(), |
| 798 | dispatcher(), |
| 799 | metrics(), |
| 800 | manager())); |
| 801 | MockServiceRefPtr s_not_in_group( |
| 802 | new NiceMock<MockService>(control_interface(), |
| 803 | dispatcher(), |
| 804 | metrics(), |
| 805 | manager())); |
| 806 | MockServiceRefPtr s_configure_fail( |
| 807 | new NiceMock<MockService>(control_interface(), |
| 808 | dispatcher(), |
| 809 | metrics(), |
| 810 | manager())); |
| 811 | MockServiceRefPtr s_configure_succeed( |
| 812 | new NiceMock<MockService>(control_interface(), |
| 813 | dispatcher(), |
| 814 | metrics(), |
| 815 | manager())); |
| 816 | |
| 817 | string entry_name("entry_name"); |
| 818 | EXPECT_CALL(*s_not_in_profile.get(), GetStorageIdentifier()).Times(0); |
| 819 | EXPECT_CALL(*s_not_in_group.get(), GetStorageIdentifier()) |
| 820 | .WillRepeatedly(Return("not_entry_name")); |
| 821 | EXPECT_CALL(*s_configure_fail.get(), GetStorageIdentifier()) |
| 822 | .WillRepeatedly(Return(entry_name)); |
| 823 | EXPECT_CALL(*s_configure_succeed.get(), GetStorageIdentifier()) |
| 824 | .WillRepeatedly(Return(entry_name)); |
| 825 | |
| 826 | manager()->RegisterService(s_not_in_profile); |
| 827 | manager()->RegisterService(s_not_in_group); |
| 828 | manager()->RegisterService(s_configure_fail); |
| 829 | manager()->RegisterService(s_configure_succeed); |
| 830 | |
| 831 | scoped_refptr<MockProfile> profile0( |
| 832 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 833 | scoped_refptr<MockProfile> profile1( |
| 834 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 835 | |
| 836 | s_not_in_group->set_profile(profile1); |
| 837 | s_configure_fail->set_profile(profile1); |
| 838 | s_configure_succeed->set_profile(profile1); |
| 839 | |
| 840 | AdoptProfile(manager(), profile0); |
| 841 | AdoptProfile(manager(), profile1); |
| 842 | |
| 843 | // No services are a member of this profile. |
| 844 | EXPECT_FALSE(manager()->HandleProfileEntryDeletion(profile0, entry_name)); |
| 845 | |
| 846 | // No services that are members of this profile have this entry name. |
| 847 | EXPECT_FALSE(manager()->HandleProfileEntryDeletion(profile1, "")); |
| 848 | |
| 849 | // Only services that are members of the profile and group will be abandoned. |
| 850 | EXPECT_CALL(*profile1.get(), |
| 851 | AbandonService(IsRefPtrTo(s_not_in_profile.get()))).Times(0); |
| 852 | EXPECT_CALL(*profile1.get(), |
| 853 | AbandonService(IsRefPtrTo(s_not_in_group.get()))).Times(0); |
| 854 | EXPECT_CALL(*profile1.get(), |
| 855 | AbandonService(IsRefPtrTo(s_configure_fail.get()))) |
| 856 | .WillOnce(Return(true)); |
| 857 | EXPECT_CALL(*profile1.get(), |
| 858 | AbandonService(IsRefPtrTo(s_configure_succeed.get()))) |
| 859 | .WillOnce(Return(true)); |
| 860 | |
| 861 | // Never allow services to re-join profile1. |
| 862 | EXPECT_CALL(*profile1.get(), ConfigureService(_)) |
| 863 | .WillRepeatedly(Return(false)); |
| 864 | |
| 865 | // Only allow one of the members of the profile and group to successfully |
| 866 | // join profile0. |
| 867 | EXPECT_CALL(*profile0.get(), |
| 868 | ConfigureService(IsRefPtrTo(s_not_in_profile.get()))).Times(0); |
| 869 | EXPECT_CALL(*profile0.get(), |
| 870 | ConfigureService(IsRefPtrTo(s_not_in_group.get()))).Times(0); |
| 871 | EXPECT_CALL(*profile0.get(), |
| 872 | ConfigureService(IsRefPtrTo(s_configure_fail.get()))) |
| 873 | .WillOnce(Return(false)); |
| 874 | EXPECT_CALL(*profile0.get(), |
| 875 | ConfigureService(IsRefPtrTo(s_configure_succeed.get()))) |
| 876 | .WillOnce(Return(true)); |
| 877 | |
| 878 | // Expect the failed-to-configure service to have Unload() called on it. |
| 879 | EXPECT_CALL(*s_not_in_profile.get(), Unload()).Times(0); |
| 880 | EXPECT_CALL(*s_not_in_group.get(), Unload()).Times(0); |
| 881 | EXPECT_CALL(*s_configure_fail.get(), Unload()).Times(1); |
| 882 | EXPECT_CALL(*s_configure_succeed.get(), Unload()).Times(0); |
| 883 | |
| 884 | EXPECT_TRUE(manager()->HandleProfileEntryDeletion(profile1, entry_name)); |
| 885 | |
| 886 | EXPECT_EQ(GetEphemeralProfile(manager()), s_not_in_profile->profile().get()); |
| 887 | EXPECT_EQ(profile1, s_not_in_group->profile()); |
| 888 | EXPECT_EQ(GetEphemeralProfile(manager()), s_configure_fail->profile()); |
| 889 | |
| 890 | // Since we are using a MockProfile, the profile does not actually change, |
| 891 | // since ConfigureService was not actually called on the service. |
| 892 | EXPECT_EQ(profile1, s_configure_succeed->profile()); |
| 893 | } |
| 894 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 895 | TEST_F(ManagerTest, HandleProfileEntryDeletionWithUnload) { |
| 896 | MockServiceRefPtr s_will_remove0( |
| 897 | new NiceMock<MockService>(control_interface(), |
| 898 | dispatcher(), |
| 899 | metrics(), |
| 900 | manager())); |
| 901 | MockServiceRefPtr s_will_remove1( |
| 902 | new NiceMock<MockService>(control_interface(), |
| 903 | dispatcher(), |
| 904 | metrics(), |
| 905 | manager())); |
| 906 | MockServiceRefPtr s_will_not_remove0( |
| 907 | new NiceMock<MockService>(control_interface(), |
| 908 | dispatcher(), |
| 909 | metrics(), |
| 910 | manager())); |
| 911 | MockServiceRefPtr s_will_not_remove1( |
| 912 | new NiceMock<MockService>(control_interface(), |
| 913 | dispatcher(), |
| 914 | metrics(), |
| 915 | manager())); |
| 916 | |
| 917 | EXPECT_CALL(*metrics(), NotifyDefaultServiceChanged(NULL)) |
| 918 | .Times(4); // Once for each registration. |
| 919 | |
| 920 | string entry_name("entry_name"); |
| 921 | EXPECT_CALL(*s_will_remove0.get(), GetStorageIdentifier()) |
| 922 | .WillRepeatedly(Return(entry_name)); |
| 923 | EXPECT_CALL(*s_will_remove1.get(), GetStorageIdentifier()) |
| 924 | .WillRepeatedly(Return(entry_name)); |
| 925 | EXPECT_CALL(*s_will_not_remove0.get(), GetStorageIdentifier()) |
| 926 | .WillRepeatedly(Return(entry_name)); |
| 927 | EXPECT_CALL(*s_will_not_remove1.get(), GetStorageIdentifier()) |
| 928 | .WillRepeatedly(Return(entry_name)); |
| 929 | |
| 930 | manager()->RegisterService(s_will_remove0); |
| 931 | manager()->RegisterService(s_will_not_remove0); |
| 932 | manager()->RegisterService(s_will_remove1); |
| 933 | manager()->RegisterService(s_will_not_remove1); |
| 934 | |
| 935 | // One for each service added above. |
| 936 | ASSERT_EQ(4, manager()->services_.size()); |
| 937 | |
| 938 | scoped_refptr<MockProfile> profile( |
| 939 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 940 | |
| 941 | s_will_remove0->set_profile(profile); |
| 942 | s_will_remove1->set_profile(profile); |
| 943 | s_will_not_remove0->set_profile(profile); |
| 944 | s_will_not_remove1->set_profile(profile); |
| 945 | |
| 946 | AdoptProfile(manager(), profile); |
| 947 | |
| 948 | // Deny any of the services re-entry to the profile. |
| 949 | EXPECT_CALL(*profile, ConfigureService(_)) |
| 950 | .WillRepeatedly(Return(false)); |
| 951 | |
| 952 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_remove0))) |
| 953 | .WillOnce(Return(true)); |
| 954 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_remove1))) |
| 955 | .WillOnce(Return(true)); |
| 956 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_not_remove0))) |
| 957 | .WillOnce(Return(true)); |
| 958 | EXPECT_CALL(*profile, AbandonService(ServiceRefPtr(s_will_not_remove1))) |
| 959 | .WillOnce(Return(true)); |
| 960 | |
| 961 | EXPECT_CALL(*s_will_remove0, Unload()) |
| 962 | .WillOnce(Return(true)); |
| 963 | EXPECT_CALL(*s_will_remove1, Unload()) |
| 964 | .WillOnce(Return(true)); |
| 965 | EXPECT_CALL(*s_will_not_remove0, Unload()) |
| 966 | .WillOnce(Return(false)); |
| 967 | EXPECT_CALL(*s_will_not_remove1, Unload()) |
| 968 | .WillOnce(Return(false)); |
| 969 | |
| 970 | |
| 971 | // This will cause all the profiles to be unloaded. |
| 972 | EXPECT_TRUE(manager()->HandleProfileEntryDeletion(profile, entry_name)); |
| 973 | |
| 974 | // 2 of the 4 services added above should have been unregistered and |
| 975 | // removed, leaving 2. |
| 976 | EXPECT_EQ(2, manager()->services_.size()); |
| 977 | EXPECT_EQ(s_will_not_remove0.get(), manager()->services_[0].get()); |
| 978 | EXPECT_EQ(s_will_not_remove1.get(), manager()->services_[1].get()); |
| 979 | } |
| 980 | |
| 981 | TEST_F(ManagerTest, PopProfileWithUnload) { |
| 982 | MockServiceRefPtr s_will_remove0( |
| 983 | new NiceMock<MockService>(control_interface(), |
| 984 | dispatcher(), |
| 985 | metrics(), |
| 986 | manager())); |
| 987 | MockServiceRefPtr s_will_remove1( |
| 988 | new NiceMock<MockService>(control_interface(), |
| 989 | dispatcher(), |
| 990 | metrics(), |
| 991 | manager())); |
| 992 | MockServiceRefPtr s_will_not_remove0( |
| 993 | new NiceMock<MockService>(control_interface(), |
| 994 | dispatcher(), |
| 995 | metrics(), |
| 996 | manager())); |
| 997 | MockServiceRefPtr s_will_not_remove1( |
| 998 | new NiceMock<MockService>(control_interface(), |
| 999 | dispatcher(), |
| 1000 | metrics(), |
| 1001 | manager())); |
| 1002 | |
| 1003 | EXPECT_CALL(*metrics(), NotifyDefaultServiceChanged(NULL)) |
| 1004 | .Times(5); // Once for each registration, and one after profile pop. |
| 1005 | |
| 1006 | manager()->RegisterService(s_will_remove0); |
| 1007 | manager()->RegisterService(s_will_not_remove0); |
| 1008 | manager()->RegisterService(s_will_remove1); |
| 1009 | manager()->RegisterService(s_will_not_remove1); |
| 1010 | |
| 1011 | // One for each service added above. |
| 1012 | ASSERT_EQ(4, manager()->services_.size()); |
| 1013 | |
| 1014 | scoped_refptr<MockProfile> profile0( |
| 1015 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1016 | scoped_refptr<MockProfile> profile1( |
| 1017 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1018 | |
| 1019 | s_will_remove0->set_profile(profile1); |
| 1020 | s_will_remove1->set_profile(profile1); |
| 1021 | s_will_not_remove0->set_profile(profile1); |
| 1022 | s_will_not_remove1->set_profile(profile1); |
| 1023 | |
| 1024 | AdoptProfile(manager(), profile0); |
| 1025 | AdoptProfile(manager(), profile1); |
| 1026 | |
| 1027 | // Deny any of the services entry to profile0, so they will all be unloaded. |
| 1028 | EXPECT_CALL(*profile0, ConfigureService(_)) |
| 1029 | .WillRepeatedly(Return(false)); |
| 1030 | |
| 1031 | EXPECT_CALL(*s_will_remove0, Unload()) |
| 1032 | .WillOnce(Return(true)); |
| 1033 | EXPECT_CALL(*s_will_remove1, Unload()) |
| 1034 | .WillOnce(Return(true)); |
| 1035 | EXPECT_CALL(*s_will_not_remove0, Unload()) |
| 1036 | .WillOnce(Return(false)); |
| 1037 | EXPECT_CALL(*s_will_not_remove1, Unload()) |
| 1038 | .WillOnce(Return(false)); |
| 1039 | |
| 1040 | // This will pop profile1, which should cause all our profiles to unload. |
| 1041 | manager()->PopProfileInternal(); |
| 1042 | |
| 1043 | // 2 of the 4 services added above should have been unregistered and |
| 1044 | // removed, leaving 2. |
| 1045 | EXPECT_EQ(2, manager()->services_.size()); |
| 1046 | EXPECT_EQ(s_will_not_remove0.get(), manager()->services_[0].get()); |
| 1047 | EXPECT_EQ(s_will_not_remove1.get(), manager()->services_[1].get()); |
| 1048 | } |
| 1049 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1050 | TEST_F(ManagerTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1051 | { |
| 1052 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1053 | EXPECT_TRUE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1054 | flimflam::kOfflineModeProperty, |
| 1055 | PropertyStoreTest::kBoolV, |
| 1056 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1057 | } |
| 1058 | { |
| 1059 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1060 | EXPECT_TRUE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1061 | flimflam::kCountryProperty, |
| 1062 | PropertyStoreTest::kStringV, |
| 1063 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1064 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1065 | // Attempt to write with value of wrong type should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1066 | { |
| 1067 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1068 | EXPECT_FALSE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1069 | flimflam::kCountryProperty, |
| 1070 | PropertyStoreTest::kBoolV, |
| 1071 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1072 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1073 | } |
| 1074 | { |
| 1075 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1076 | EXPECT_FALSE(DBusAdaptor::SetProperty(manager()->mutable_store(), |
| 1077 | flimflam::kOfflineModeProperty, |
| 1078 | PropertyStoreTest::kStringV, |
| 1079 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1080 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1081 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1082 | // Attempt to write R/O property should return InvalidArgs. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1083 | { |
| 1084 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 1085 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 1086 | manager()->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1087 | flimflam::kEnabledTechnologiesProperty, |
| 1088 | PropertyStoreTest::kStringsV, |
| 1089 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1090 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1091 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1094 | TEST_F(ManagerTest, RequestScan) { |
| 1095 | { |
| 1096 | Error error; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1097 | manager()->RegisterDevice(mock_devices_[0].get()); |
| 1098 | manager()->RegisterDevice(mock_devices_[1].get()); |
| 1099 | EXPECT_CALL(*mock_devices_[0], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1100 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1101 | EXPECT_CALL(*mock_devices_[0], Scan(_)); |
| 1102 | EXPECT_CALL(*mock_devices_[1], TechnologyIs(Technology::kWifi)) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1103 | .WillRepeatedly(Return(false)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1104 | EXPECT_CALL(*mock_devices_[1], Scan(_)).Times(0); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1105 | manager()->RequestScan(flimflam::kTypeWifi, &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | { |
| 1109 | Error error; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 1110 | manager()->RequestScan("bogus_device_type", &error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1111 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1112 | } |
| 1113 | } |
| 1114 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1115 | TEST_F(ManagerTest, GetServiceNoType) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1116 | KeyValueStore args; |
| 1117 | Error e; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1118 | manager()->GetService(args, &e); |
| 1119 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1120 | EXPECT_EQ("must specify service type", e.message()); |
| 1121 | } |
| 1122 | |
| 1123 | TEST_F(ManagerTest, GetServiceUnknownType) { |
| 1124 | KeyValueStore args; |
| 1125 | Error e; |
| 1126 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeEthernet); |
| 1127 | manager()->GetService(args, &e); |
| 1128 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1129 | EXPECT_EQ("service type is unsupported", e.message()); |
| 1130 | } |
| 1131 | |
| 1132 | TEST_F(ManagerTest, GetServiceNoWifiDevice) { |
| 1133 | KeyValueStore args; |
| 1134 | Error e; |
| 1135 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1136 | manager()->GetService(args, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1137 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1138 | EXPECT_EQ("no wifi devices available", e.message()); |
| 1139 | } |
| 1140 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1141 | TEST_F(ManagerTest, GetServiceWifi) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1142 | KeyValueStore args; |
| 1143 | Error e; |
| 1144 | WiFiServiceRefPtr wifi_service; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1145 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1146 | manager()->RegisterDevice(mock_wifi_); |
| 1147 | EXPECT_CALL(*mock_wifi_, GetService(_, _)) |
| 1148 | .WillRepeatedly(Return(wifi_service)); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1149 | manager()->GetService(args, &e); |
| 1150 | EXPECT_TRUE(e.IsSuccess()); |
| 1151 | } |
| 1152 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1153 | TEST_F(ManagerTest, GetServiceVPNUnknownType) { |
| 1154 | KeyValueStore args; |
| 1155 | Error e; |
| 1156 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeVPN); |
| 1157 | ServiceRefPtr service = manager()->GetService(args, &e); |
| 1158 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1159 | EXPECT_FALSE(service); |
| 1160 | } |
| 1161 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1162 | TEST_F(ManagerTest, GetServiceVPN) { |
| 1163 | KeyValueStore args; |
| 1164 | Error e; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1165 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeVPN); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1166 | args.SetString(flimflam::kProviderTypeProperty, flimflam::kProviderOpenVpn); |
Darin Petkov | 0286771 | 2012-03-12 14:25:05 +0100 | [diff] [blame] | 1167 | args.SetString(flimflam::kProviderHostProperty, "10.8.0.1"); |
| 1168 | args.SetString(flimflam::kProviderNameProperty, "vpn-name"); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1169 | ServiceRefPtr service = manager()->GetService(args, &e); |
| 1170 | EXPECT_TRUE(e.IsSuccess()); |
| 1171 | EXPECT_TRUE(service); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1174 | TEST_F(ManagerTest, ConfigureServiceWithInvalidProfile) { |
| 1175 | // Manager calls ActiveProfile() so we need at least one profile installed. |
| 1176 | scoped_refptr<MockProfile> profile( |
| 1177 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1178 | AdoptProfile(manager(), profile); |
| 1179 | |
| 1180 | KeyValueStore args; |
| 1181 | args.SetString(flimflam::kProfileProperty, "xxx"); |
| 1182 | Error error; |
| 1183 | manager()->ConfigureService(args, &error); |
| 1184 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1185 | EXPECT_EQ("Invalid profile name xxx", error.message()); |
| 1186 | } |
| 1187 | |
| 1188 | TEST_F(ManagerTest, ConfigureServiceWithGetServiceFailure) { |
| 1189 | // Manager calls ActiveProfile() so we need at least one profile installed. |
| 1190 | scoped_refptr<MockProfile> profile( |
| 1191 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1192 | AdoptProfile(manager(), profile); |
| 1193 | |
| 1194 | KeyValueStore args; |
| 1195 | Error error; |
| 1196 | manager()->ConfigureService(args, &error); |
| 1197 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1198 | EXPECT_EQ("must specify service type", error.message()); |
| 1199 | } |
| 1200 | |
| 1201 | // A registered service in the ephemeral profile should be moved to the |
| 1202 | // active profile as a part of configuration if no profile was explicitly |
| 1203 | // specified. |
| 1204 | TEST_F(ManagerTest, ConfigureRegisteredServiceWithoutProfile) { |
| 1205 | scoped_refptr<MockProfile> profile( |
| 1206 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1207 | |
| 1208 | AdoptProfile(manager(), profile); // This is now the active profile. |
| 1209 | |
| 1210 | const std::vector<uint8_t> ssid; |
| 1211 | scoped_refptr<MockWiFiService> service( |
| 1212 | new NiceMock<MockWiFiService>(control_interface(), |
| 1213 | dispatcher(), |
| 1214 | metrics(), |
| 1215 | manager(), |
| 1216 | mock_wifi_, |
| 1217 | ssid, |
| 1218 | "", |
| 1219 | "", |
| 1220 | false)); |
| 1221 | |
| 1222 | manager()->RegisterService(service); |
| 1223 | service->set_profile(GetEphemeralProfile(manager())); |
| 1224 | |
| 1225 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1226 | // the same device as that used above causes a refcounting loop. |
| 1227 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1228 | dispatcher(), |
| 1229 | metrics(), |
| 1230 | manager(), |
| 1231 | "wifi1", |
| 1232 | "addr5", |
| 1233 | 5)); |
| 1234 | manager()->RegisterDevice(wifi); |
| 1235 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1236 | .WillOnce(Return(service)); |
| 1237 | EXPECT_CALL(*profile, UpdateService(ServiceRefPtr(service.get()))) |
| 1238 | .WillOnce(Return(true)); |
| 1239 | EXPECT_CALL(*profile, AdoptService(ServiceRefPtr(service.get()))) |
| 1240 | .WillOnce(Return(true)); |
| 1241 | |
| 1242 | KeyValueStore args; |
| 1243 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1244 | Error error; |
| 1245 | manager()->ConfigureService(args, &error); |
| 1246 | EXPECT_TRUE(error.IsSuccess()); |
| 1247 | } |
| 1248 | |
| 1249 | // If were configure a service that was already registered and explicitly |
| 1250 | // specify a profile, it should be moved from the profile it was previously |
| 1251 | // in to the specified profile if one was requested. |
| 1252 | TEST_F(ManagerTest, ConfigureRegisteredServiceWithProfile) { |
| 1253 | scoped_refptr<MockProfile> profile0( |
| 1254 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1255 | scoped_refptr<MockProfile> profile1( |
| 1256 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1257 | |
| 1258 | const string kProfileName0 = "profile0"; |
| 1259 | const string kProfileName1 = "profile1"; |
| 1260 | |
| 1261 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 1262 | .WillRepeatedly(Return(kProfileName0)); |
| 1263 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 1264 | .WillRepeatedly(Return(kProfileName1)); |
| 1265 | |
| 1266 | AdoptProfile(manager(), profile0); |
| 1267 | AdoptProfile(manager(), profile1); // profile1 is now the ActiveProfile. |
| 1268 | |
| 1269 | const std::vector<uint8_t> ssid; |
| 1270 | scoped_refptr<MockWiFiService> service( |
| 1271 | new NiceMock<MockWiFiService>(control_interface(), |
| 1272 | dispatcher(), |
| 1273 | metrics(), |
| 1274 | manager(), |
| 1275 | mock_wifi_, |
| 1276 | ssid, |
| 1277 | "", |
| 1278 | "", |
| 1279 | false)); |
| 1280 | |
| 1281 | manager()->RegisterService(service); |
| 1282 | service->set_profile(profile1); |
| 1283 | |
| 1284 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1285 | // the same device as that used above causes a refcounting loop. |
| 1286 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1287 | dispatcher(), |
| 1288 | metrics(), |
| 1289 | manager(), |
| 1290 | "wifi1", |
| 1291 | "addr5", |
| 1292 | 5)); |
| 1293 | manager()->RegisterDevice(wifi); |
| 1294 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1295 | .WillOnce(Return(service)); |
| 1296 | EXPECT_CALL(*profile0, UpdateService(ServiceRefPtr(service.get()))) |
| 1297 | .WillOnce(Return(true)); |
| 1298 | EXPECT_CALL(*profile0, AdoptService(ServiceRefPtr(service.get()))) |
| 1299 | .WillOnce(Return(true)); |
| 1300 | EXPECT_CALL(*profile1, AbandonService(ServiceRefPtr(service.get()))) |
| 1301 | .WillOnce(Return(true)); |
| 1302 | |
| 1303 | KeyValueStore args; |
| 1304 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1305 | args.SetString(flimflam::kProfileProperty, kProfileName0); |
| 1306 | Error error; |
| 1307 | manager()->ConfigureService(args, &error); |
| 1308 | EXPECT_TRUE(error.IsSuccess()); |
| 1309 | service->set_profile(NULL); // Breaks refcounting loop. |
| 1310 | } |
| 1311 | |
| 1312 | // An unregistered service should remain unregistered, but its contents should |
| 1313 | // be saved to the specified profile nonetheless. |
| 1314 | TEST_F(ManagerTest, ConfigureUnregisteredServiceWithProfile) { |
| 1315 | scoped_refptr<MockProfile> profile0( |
| 1316 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1317 | scoped_refptr<MockProfile> profile1( |
| 1318 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
| 1319 | |
| 1320 | const string kProfileName0 = "profile0"; |
| 1321 | const string kProfileName1 = "profile1"; |
| 1322 | |
| 1323 | EXPECT_CALL(*profile0, GetRpcIdentifier()) |
| 1324 | .WillRepeatedly(Return(kProfileName0)); |
| 1325 | EXPECT_CALL(*profile1, GetRpcIdentifier()) |
| 1326 | .WillRepeatedly(Return(kProfileName1)); |
| 1327 | |
| 1328 | AdoptProfile(manager(), profile0); |
| 1329 | AdoptProfile(manager(), profile1); // profile1 is now the ActiveProfile. |
| 1330 | |
| 1331 | const std::vector<uint8_t> ssid; |
| 1332 | scoped_refptr<MockWiFiService> service( |
| 1333 | new NiceMock<MockWiFiService>(control_interface(), |
| 1334 | dispatcher(), |
| 1335 | metrics(), |
| 1336 | manager(), |
| 1337 | mock_wifi_, |
| 1338 | ssid, |
| 1339 | "", |
| 1340 | "", |
| 1341 | false)); |
| 1342 | |
| 1343 | service->set_profile(profile1); |
| 1344 | |
| 1345 | // A separate MockWiFi from mock_wifi_ is used in the Manager since using |
| 1346 | // the same device as that used above causes a refcounting loop. |
| 1347 | scoped_refptr<MockWiFi> wifi(new NiceMock<MockWiFi>(control_interface(), |
| 1348 | dispatcher(), |
| 1349 | metrics(), |
| 1350 | manager(), |
| 1351 | "wifi1", |
| 1352 | "addr5", |
| 1353 | 5)); |
| 1354 | manager()->RegisterDevice(wifi); |
| 1355 | EXPECT_CALL(*wifi, GetService(_, _)) |
| 1356 | .WillOnce(Return(service)); |
| 1357 | EXPECT_CALL(*profile0, UpdateService(ServiceRefPtr(service.get()))) |
| 1358 | .WillOnce(Return(true)); |
| 1359 | EXPECT_CALL(*profile0, AdoptService(_)) |
| 1360 | .Times(0); |
| 1361 | EXPECT_CALL(*profile1, AdoptService(_)) |
| 1362 | .Times(0); |
| 1363 | |
| 1364 | KeyValueStore args; |
| 1365 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1366 | args.SetString(flimflam::kProfileProperty, kProfileName0); |
| 1367 | Error error; |
| 1368 | manager()->ConfigureService(args, &error); |
| 1369 | EXPECT_TRUE(error.IsSuccess()); |
| 1370 | } |
| 1371 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1372 | TEST_F(ManagerTest, TechnologyOrder) { |
| 1373 | Error error; |
| 1374 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "," + |
| 1375 | string(flimflam::kTypeWifi), &error); |
| 1376 | ASSERT_TRUE(error.IsSuccess()); |
| 1377 | EXPECT_EQ(manager()->GetTechnologyOrder(), |
| 1378 | string(flimflam::kTypeEthernet) + "," + |
| 1379 | string(flimflam::kTypeWifi)); |
| 1380 | |
| 1381 | manager()->SetTechnologyOrder(string(flimflam::kTypeEthernet) + "x," + |
| 1382 | string(flimflam::kTypeWifi), &error); |
| 1383 | ASSERT_FALSE(error.IsSuccess()); |
| 1384 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1385 | EXPECT_EQ(string(flimflam::kTypeEthernet) + "," + |
| 1386 | string(flimflam::kTypeWifi), |
| 1387 | manager()->GetTechnologyOrder()); |
| 1388 | } |
| 1389 | |
| 1390 | TEST_F(ManagerTest, SortServices) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1391 | // TODO(quiche): Some of these tests would probably fit better in |
| 1392 | // service_unittest, since the actual comparison of Services is |
| 1393 | // implemented in Service. (crosbug.com/23370) |
| 1394 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1395 | scoped_refptr<MockService> mock_service0( |
| 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())); |
| 1400 | scoped_refptr<MockService> mock_service1( |
| 1401 | new NiceMock<MockService>(control_interface(), |
| 1402 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1403 | metrics(), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1404 | manager())); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1405 | |
| 1406 | manager()->RegisterService(mock_service0); |
| 1407 | manager()->RegisterService(mock_service1); |
| 1408 | |
| 1409 | // Services should already be sorted by UniqueName |
| 1410 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1411 | |
| 1412 | // Asking explictly to sort services should not change anything |
| 1413 | manager()->SortServices(); |
| 1414 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1415 | |
| 1416 | // Two otherwise equal services should be reordered by strength |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 1417 | mock_service1->SetStrength(1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1418 | manager()->UpdateService(mock_service1); |
| 1419 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1420 | |
| 1421 | // Security |
Paul Stewart | 1ca3e85 | 2011-11-04 07:50:49 -0700 | [diff] [blame] | 1422 | mock_service0->set_security_level(1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1423 | manager()->UpdateService(mock_service0); |
| 1424 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1425 | |
| 1426 | // Technology |
| 1427 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Technology::kWifi)) |
| 1428 | .WillRepeatedly(Return(true)); |
| 1429 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Technology::kEthernet)) |
| 1430 | .WillRepeatedly(Return(true)); |
| 1431 | // NB: Redefine default (false) return values so we don't use the default rule |
| 1432 | // which makes the logs noisier |
| 1433 | EXPECT_CALL(*mock_service0.get(), TechnologyIs(Ne(Technology::kWifi))) |
| 1434 | .WillRepeatedly(Return(false)); |
| 1435 | EXPECT_CALL(*mock_service1.get(), TechnologyIs(Ne(Technology::kEthernet))) |
| 1436 | .WillRepeatedly(Return(false)); |
| 1437 | |
| 1438 | Error error; |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 1439 | // Default technology ordering should favor Ethernet over WiFi. |
| 1440 | manager()->SortServices(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1441 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1442 | |
| 1443 | manager()->SetTechnologyOrder(string(flimflam::kTypeWifi) + "," + |
| 1444 | string(flimflam::kTypeEthernet), &error); |
| 1445 | EXPECT_TRUE(error.IsSuccess()); |
| 1446 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1447 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1448 | // Priority. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1449 | mock_service0->set_priority(1); |
| 1450 | manager()->UpdateService(mock_service0); |
| 1451 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1452 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1453 | // Favorite. |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1454 | mock_service1->MakeFavorite(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1455 | manager()->UpdateService(mock_service1); |
| 1456 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1457 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1458 | // Auto-connect. |
| 1459 | mock_service0->set_auto_connect(true); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1460 | manager()->UpdateService(mock_service0); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1461 | mock_service1->set_auto_connect(false); |
| 1462 | manager()->UpdateService(mock_service1); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1463 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1464 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1465 | // Connectable. |
| 1466 | mock_service1->set_connectable(true); |
| 1467 | manager()->UpdateService(mock_service1); |
| 1468 | mock_service0->set_connectable(false); |
| 1469 | manager()->UpdateService(mock_service0); |
| 1470 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1471 | |
| 1472 | // IsFailed. |
| 1473 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1474 | .WillRepeatedly(Return(Service::kStateIdle)); |
| 1475 | EXPECT_CALL(*mock_service0.get(), IsFailed()) |
| 1476 | .WillRepeatedly(Return(false)); |
| 1477 | manager()->UpdateService(mock_service0); |
| 1478 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1479 | .WillRepeatedly(Return(Service::kStateFailure)); |
| 1480 | EXPECT_CALL(*mock_service1.get(), IsFailed()) |
| 1481 | .WillRepeatedly(Return(true)); |
| 1482 | manager()->UpdateService(mock_service1); |
| 1483 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1484 | |
| 1485 | // Connecting. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1486 | EXPECT_CALL(*mock_service1.get(), state()) |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1487 | .WillRepeatedly(Return(Service::kStateAssociating)); |
| 1488 | EXPECT_CALL(*mock_service1.get(), IsConnecting()) |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1489 | .WillRepeatedly(Return(true)); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1490 | manager()->UpdateService(mock_service1); |
| 1491 | EXPECT_TRUE(ServiceOrderIs(mock_service1, mock_service0)); |
| 1492 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1493 | // Connected. |
| 1494 | EXPECT_CALL(*mock_service0.get(), state()) |
| 1495 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 1496 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1497 | .WillRepeatedly(Return(true)); |
| 1498 | manager()->UpdateService(mock_service0); |
| 1499 | EXPECT_TRUE(ServiceOrderIs(mock_service0, mock_service1)); |
| 1500 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1501 | manager()->DeregisterService(mock_service0); |
| 1502 | manager()->DeregisterService(mock_service1); |
| 1503 | } |
| 1504 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1505 | TEST_F(ManagerTest, SortServicesWithConnection) { |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1506 | MockMetrics mock_metrics; |
| 1507 | manager()->set_metrics(&mock_metrics); |
| 1508 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1509 | scoped_refptr<MockService> mock_service0( |
| 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 | scoped_refptr<MockService> mock_service1( |
| 1515 | new NiceMock<MockService>(control_interface(), |
| 1516 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1517 | metrics(), |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1518 | manager())); |
| 1519 | |
| 1520 | scoped_refptr<MockConnection> mock_connection0( |
| 1521 | new NiceMock<MockConnection>(device_info_.get())); |
| 1522 | scoped_refptr<MockConnection> mock_connection1( |
| 1523 | new NiceMock<MockConnection>(device_info_.get())); |
| 1524 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1525 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1526 | manager()->RegisterService(mock_service0); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1527 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1528 | manager()->RegisterService(mock_service1); |
| 1529 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1530 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1531 | manager()->SortServices(); |
| 1532 | |
| 1533 | mock_service1->set_priority(1); |
| 1534 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1535 | manager()->SortServices(); |
| 1536 | |
| 1537 | mock_service1->set_priority(0); |
| 1538 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1539 | manager()->SortServices(); |
| 1540 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1541 | mock_service0->set_mock_connection(mock_connection0); |
| 1542 | mock_service1->set_mock_connection(mock_connection1); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1543 | |
| 1544 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1545 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service0.get())); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1546 | manager()->SortServices(); |
| 1547 | |
| 1548 | mock_service1->set_priority(1); |
| 1549 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(false)); |
| 1550 | EXPECT_CALL(*mock_connection1.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1551 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service1.get())); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1552 | manager()->SortServices(); |
| 1553 | |
| 1554 | EXPECT_CALL(*mock_connection0.get(), SetIsDefault(true)); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1555 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(mock_service0.get())); |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1556 | mock_service1->set_mock_connection(NULL); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1557 | manager()->DeregisterService(mock_service1); |
| 1558 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1559 | mock_service0->set_mock_connection(NULL); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1560 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1561 | manager()->DeregisterService(mock_service0); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1562 | |
| 1563 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(NULL)); |
| 1564 | manager()->SortServices(); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1565 | } |
| 1566 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1567 | TEST_F(ManagerTest, AvailableTechnologies) { |
| 1568 | mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(), |
| 1569 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1570 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1571 | manager(), |
| 1572 | "null4", |
| 1573 | "addr4", |
| 1574 | 0)); |
| 1575 | manager()->RegisterDevice(mock_devices_[0]); |
| 1576 | manager()->RegisterDevice(mock_devices_[1]); |
| 1577 | manager()->RegisterDevice(mock_devices_[2]); |
| 1578 | manager()->RegisterDevice(mock_devices_[3]); |
| 1579 | |
| 1580 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 1581 | .WillByDefault(Return(Technology::kEthernet)); |
| 1582 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 1583 | .WillByDefault(Return(Technology::kWifi)); |
| 1584 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 1585 | .WillByDefault(Return(Technology::kCellular)); |
| 1586 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 1587 | .WillByDefault(Return(Technology::kWifi)); |
| 1588 | |
| 1589 | set<string> expected_technologies; |
| 1590 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1591 | Technology::kEthernet)); |
| 1592 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1593 | Technology::kWifi)); |
| 1594 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1595 | Technology::kCellular)); |
| 1596 | Error error; |
| 1597 | vector<string> technologies = manager()->AvailableTechnologies(&error); |
| 1598 | |
| 1599 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 1600 | ContainerEq(expected_technologies)); |
| 1601 | } |
| 1602 | |
| 1603 | TEST_F(ManagerTest, ConnectedTechnologies) { |
| 1604 | scoped_refptr<MockService> connected_service1( |
| 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> connected_service2( |
| 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_service1( |
| 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 | scoped_refptr<MockService> disconnected_service2( |
| 1620 | new NiceMock<MockService>(control_interface(), |
| 1621 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1622 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1623 | manager())); |
| 1624 | |
| 1625 | ON_CALL(*connected_service1.get(), IsConnected()) |
| 1626 | .WillByDefault(Return(true)); |
| 1627 | ON_CALL(*connected_service2.get(), IsConnected()) |
| 1628 | .WillByDefault(Return(true)); |
| 1629 | |
| 1630 | manager()->RegisterService(connected_service1); |
| 1631 | manager()->RegisterService(connected_service2); |
| 1632 | manager()->RegisterService(disconnected_service1); |
| 1633 | manager()->RegisterService(disconnected_service2); |
| 1634 | |
| 1635 | manager()->RegisterDevice(mock_devices_[0]); |
| 1636 | manager()->RegisterDevice(mock_devices_[1]); |
| 1637 | manager()->RegisterDevice(mock_devices_[2]); |
| 1638 | manager()->RegisterDevice(mock_devices_[3]); |
| 1639 | |
| 1640 | ON_CALL(*mock_devices_[0].get(), technology()) |
| 1641 | .WillByDefault(Return(Technology::kEthernet)); |
| 1642 | ON_CALL(*mock_devices_[1].get(), technology()) |
| 1643 | .WillByDefault(Return(Technology::kWifi)); |
| 1644 | ON_CALL(*mock_devices_[2].get(), technology()) |
| 1645 | .WillByDefault(Return(Technology::kCellular)); |
| 1646 | ON_CALL(*mock_devices_[3].get(), technology()) |
| 1647 | .WillByDefault(Return(Technology::kWifi)); |
| 1648 | |
| 1649 | mock_devices_[0]->SelectService(connected_service1); |
| 1650 | mock_devices_[1]->SelectService(disconnected_service1); |
| 1651 | mock_devices_[2]->SelectService(disconnected_service2); |
| 1652 | mock_devices_[3]->SelectService(connected_service2); |
| 1653 | |
| 1654 | set<string> expected_technologies; |
| 1655 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1656 | Technology::kEthernet)); |
| 1657 | expected_technologies.insert(Technology::NameFromIdentifier( |
| 1658 | Technology::kWifi)); |
| 1659 | Error error; |
| 1660 | |
| 1661 | vector<string> technologies = manager()->ConnectedTechnologies(&error); |
| 1662 | EXPECT_THAT(set<string>(technologies.begin(), technologies.end()), |
| 1663 | ContainerEq(expected_technologies)); |
| 1664 | } |
| 1665 | |
| 1666 | TEST_F(ManagerTest, DefaultTechnology) { |
| 1667 | scoped_refptr<MockService> connected_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 | scoped_refptr<MockService> disconnected_service( |
| 1673 | new NiceMock<MockService>(control_interface(), |
| 1674 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1675 | metrics(), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1676 | manager())); |
| 1677 | |
| 1678 | // Connected. WiFi. |
| 1679 | ON_CALL(*connected_service.get(), IsConnected()) |
| 1680 | .WillByDefault(Return(true)); |
| 1681 | ON_CALL(*connected_service.get(), state()) |
| 1682 | .WillByDefault(Return(Service::kStateConnected)); |
| 1683 | ON_CALL(*connected_service.get(), technology()) |
| 1684 | .WillByDefault(Return(Technology::kWifi)); |
| 1685 | |
| 1686 | // Disconnected. Ethernet. |
| 1687 | ON_CALL(*disconnected_service.get(), technology()) |
| 1688 | .WillByDefault(Return(Technology::kEthernet)); |
| 1689 | |
| 1690 | manager()->RegisterService(disconnected_service); |
| 1691 | Error error; |
| 1692 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq("")); |
| 1693 | |
| 1694 | |
| 1695 | manager()->RegisterService(connected_service); |
| 1696 | // Connected service should be brought to the front now. |
| 1697 | string expected_technology = |
| 1698 | Technology::NameFromIdentifier(Technology::kWifi); |
| 1699 | EXPECT_THAT(manager()->DefaultTechnology(&error), StrEq(expected_technology)); |
| 1700 | } |
| 1701 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1702 | TEST_F(ManagerTest, DisconnectServicesOnStop) { |
| 1703 | scoped_refptr<MockService> mock_service( |
| 1704 | new NiceMock<MockService>(control_interface(), |
| 1705 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1706 | metrics(), |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1707 | manager())); |
| 1708 | manager()->RegisterService(mock_service); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 1709 | EXPECT_CALL(*mock_service.get(), Disconnect(_)).Times(1); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 1710 | manager()->Stop(); |
| 1711 | } |
| 1712 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1713 | TEST_F(ManagerTest, UpdateServiceConnected) { |
| 1714 | scoped_refptr<MockService> mock_service( |
| 1715 | new NiceMock<MockService>(control_interface(), |
| 1716 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1717 | metrics(), |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1718 | manager())); |
| 1719 | manager()->RegisterService(mock_service); |
| 1720 | EXPECT_FALSE(mock_service->favorite()); |
| 1721 | EXPECT_FALSE(mock_service->auto_connect()); |
| 1722 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1723 | EXPECT_CALL(*mock_service.get(), IsConnected()) |
| 1724 | .WillRepeatedly(Return(true)); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1725 | manager()->UpdateService(mock_service); |
| 1726 | // We can't EXPECT_CALL(..., MakeFavorite), because that requires us |
| 1727 | // to mock out MakeFavorite. And mocking that out would break the |
| 1728 | // SortServices test. (crosbug.com/23370) |
| 1729 | EXPECT_TRUE(mock_service->favorite()); |
| 1730 | EXPECT_TRUE(mock_service->auto_connect()); |
| 1731 | } |
| 1732 | |
Thieu Le | d4e9e55 | 2012-02-16 16:26:07 -0800 | [diff] [blame] | 1733 | TEST_F(ManagerTest, UpdateServiceConnectedPersistFavorite) { |
| 1734 | // This tests the case where the user connects to a service that is |
| 1735 | // currently associated with a profile. We want to make sure that the |
| 1736 | // favorite flag is set and that the flag is saved to the current |
| 1737 | // profile. |
| 1738 | scoped_refptr<MockService> mock_service( |
| 1739 | new NiceMock<MockService>(control_interface(), |
| 1740 | dispatcher(), |
| 1741 | metrics(), |
| 1742 | manager())); |
| 1743 | manager()->RegisterService(mock_service); |
| 1744 | EXPECT_FALSE(mock_service->favorite()); |
| 1745 | EXPECT_FALSE(mock_service->auto_connect()); |
| 1746 | |
| 1747 | ProfileRefPtr profile(new MockProfile(control_interface(), manager(), "")); |
| 1748 | mock_service->set_profile(profile); |
| 1749 | |
| 1750 | EXPECT_CALL(*mock_service.get(), IsConnected()) |
| 1751 | .WillRepeatedly(Return(true)); |
| 1752 | EXPECT_CALL(*mock_service.get(), SaveToCurrentProfile()); |
| 1753 | manager()->UpdateService(mock_service); |
| 1754 | // We can't EXPECT_CALL(..., MakeFavorite), because that requires us |
| 1755 | // to mock out MakeFavorite. And mocking that out would break the |
| 1756 | // SortServices test. (crosbug.com/23370) |
| 1757 | EXPECT_TRUE(mock_service->favorite()); |
| 1758 | EXPECT_TRUE(mock_service->auto_connect()); |
| 1759 | } |
| 1760 | |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1761 | TEST_F(ManagerTest, SaveSuccessfulService) { |
| 1762 | scoped_refptr<MockProfile> profile( |
| 1763 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
| 1764 | AdoptProfile(manager(), profile); |
| 1765 | scoped_refptr<MockService> service( |
| 1766 | new NiceMock<MockService>(control_interface(), |
| 1767 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1768 | metrics(), |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1769 | manager())); |
| 1770 | |
| 1771 | // Re-cast this back to a ServiceRefPtr, so EXPECT arguments work correctly. |
| 1772 | ServiceRefPtr expect_service(service.get()); |
| 1773 | |
| 1774 | EXPECT_CALL(*profile.get(), ConfigureService(expect_service)) |
| 1775 | .WillOnce(Return(false)); |
| 1776 | manager()->RegisterService(service); |
| 1777 | |
| 1778 | EXPECT_CALL(*service.get(), state()) |
| 1779 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 1780 | EXPECT_CALL(*service.get(), IsConnected()) |
| 1781 | .WillRepeatedly(Return(true)); |
| 1782 | EXPECT_CALL(*profile.get(), AdoptService(expect_service)) |
| 1783 | .WillOnce(Return(true)); |
| 1784 | manager()->UpdateService(service); |
| 1785 | } |
| 1786 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1787 | TEST_F(ManagerTest, EnumerateProfiles) { |
| 1788 | vector<string> profile_paths; |
| 1789 | for (size_t i = 0; i < 10; i++) { |
| 1790 | scoped_refptr<MockProfile> profile( |
| 1791 | new StrictMock<MockProfile>(control_interface(), manager(), "")); |
Jason Glasgow | 5d8197b | 2012-01-27 08:37:32 -0500 | [diff] [blame] | 1792 | profile_paths.push_back(base::StringPrintf("/profile/%zd", i)); |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1793 | EXPECT_CALL(*profile.get(), GetRpcIdentifier()) |
| 1794 | .WillOnce(Return(profile_paths.back())); |
| 1795 | AdoptProfile(manager(), profile); |
| 1796 | } |
| 1797 | |
| 1798 | Error error; |
| 1799 | vector<string> returned_paths = manager()->EnumerateProfiles(&error); |
| 1800 | EXPECT_TRUE(error.IsSuccess()); |
| 1801 | EXPECT_EQ(profile_paths.size(), returned_paths.size()); |
| 1802 | for (size_t i = 0; i < profile_paths.size(); i++) { |
| 1803 | EXPECT_EQ(profile_paths[i], returned_paths[i]); |
| 1804 | } |
| 1805 | } |
| 1806 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1807 | TEST_F(ManagerTest, AutoConnectOnRegister) { |
| 1808 | MockServiceRefPtr service = MakeAutoConnectableService(); |
| 1809 | EXPECT_CALL(*service.get(), AutoConnect()); |
| 1810 | manager()->RegisterService(service); |
| 1811 | dispatcher()->DispatchPendingEvents(); |
| 1812 | } |
| 1813 | |
| 1814 | TEST_F(ManagerTest, AutoConnectOnUpdate) { |
| 1815 | MockServiceRefPtr service1 = MakeAutoConnectableService(); |
| 1816 | service1->set_priority(1); |
| 1817 | MockServiceRefPtr service2 = MakeAutoConnectableService(); |
| 1818 | service2->set_priority(2); |
| 1819 | manager()->RegisterService(service1); |
| 1820 | manager()->RegisterService(service2); |
| 1821 | dispatcher()->DispatchPendingEvents(); |
| 1822 | |
| 1823 | EXPECT_CALL(*service1.get(), AutoConnect()); |
| 1824 | EXPECT_CALL(*service2.get(), state()) |
| 1825 | .WillRepeatedly(Return(Service::kStateFailure)); |
| 1826 | EXPECT_CALL(*service2.get(), IsFailed()) |
| 1827 | .WillRepeatedly(Return(true)); |
| 1828 | EXPECT_CALL(*service2.get(), IsConnected()) |
| 1829 | .WillRepeatedly(Return(false)); |
| 1830 | manager()->UpdateService(service2); |
| 1831 | dispatcher()->DispatchPendingEvents(); |
| 1832 | } |
| 1833 | |
| 1834 | TEST_F(ManagerTest, AutoConnectOnDeregister) { |
| 1835 | MockServiceRefPtr service1 = MakeAutoConnectableService(); |
| 1836 | service1->set_priority(1); |
| 1837 | MockServiceRefPtr service2 = MakeAutoConnectableService(); |
| 1838 | service2->set_priority(2); |
| 1839 | manager()->RegisterService(service1); |
| 1840 | manager()->RegisterService(service2); |
| 1841 | dispatcher()->DispatchPendingEvents(); |
| 1842 | |
| 1843 | EXPECT_CALL(*service1.get(), AutoConnect()); |
| 1844 | manager()->DeregisterService(service2); |
| 1845 | dispatcher()->DispatchPendingEvents(); |
| 1846 | } |
| 1847 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 1848 | TEST_F(ManagerTest, RecheckPortal) { |
| 1849 | EXPECT_CALL(*mock_devices_[0].get(), RequestPortalDetection()) |
| 1850 | .WillOnce(Return(false)); |
| 1851 | EXPECT_CALL(*mock_devices_[1].get(), RequestPortalDetection()) |
| 1852 | .WillOnce(Return(true)); |
| 1853 | EXPECT_CALL(*mock_devices_[2].get(), RequestPortalDetection()) |
| 1854 | .Times(0); |
| 1855 | |
| 1856 | manager()->RegisterDevice(mock_devices_[0]); |
| 1857 | manager()->RegisterDevice(mock_devices_[1]); |
| 1858 | manager()->RegisterDevice(mock_devices_[2]); |
| 1859 | |
| 1860 | manager()->RecheckPortal(NULL); |
| 1861 | } |
| 1862 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1863 | TEST_F(ManagerTest, GetDefaultService) { |
| 1864 | EXPECT_FALSE(manager()->GetDefaultService().get()); |
| 1865 | |
| 1866 | scoped_refptr<MockService> mock_service( |
| 1867 | new NiceMock<MockService>(control_interface(), |
| 1868 | dispatcher(), |
| 1869 | metrics(), |
| 1870 | manager())); |
| 1871 | |
| 1872 | manager()->RegisterService(mock_service); |
| 1873 | EXPECT_FALSE(manager()->GetDefaultService().get()); |
| 1874 | |
| 1875 | scoped_refptr<MockConnection> mock_connection( |
| 1876 | new NiceMock<MockConnection>(device_info_.get())); |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1877 | mock_service->set_mock_connection(mock_connection); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1878 | EXPECT_EQ(mock_service.get(), manager()->GetDefaultService().get()); |
| 1879 | |
Paul Stewart | ce4ec19 | 2012-03-14 12:53:46 -0700 | [diff] [blame] | 1880 | mock_service->set_mock_connection(NULL); |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1881 | manager()->DeregisterService(mock_service); |
| 1882 | } |
| 1883 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1884 | TEST_F(ManagerTest, GetServiceWithGUID) { |
| 1885 | scoped_refptr<MockService> mock_service0( |
| 1886 | new NiceMock<MockService>(control_interface(), |
| 1887 | dispatcher(), |
| 1888 | metrics(), |
| 1889 | manager())); |
| 1890 | |
| 1891 | scoped_refptr<MockService> mock_service1( |
| 1892 | new NiceMock<MockService>(control_interface(), |
| 1893 | dispatcher(), |
| 1894 | metrics(), |
| 1895 | manager())); |
| 1896 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1897 | EXPECT_CALL(*mock_service0.get(), Configure(_, _)) |
| 1898 | .Times(0); |
| 1899 | EXPECT_CALL(*mock_service1.get(), Configure(_, _)) |
| 1900 | .Times(0); |
| 1901 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1902 | manager()->RegisterService(mock_service0); |
| 1903 | manager()->RegisterService(mock_service1); |
| 1904 | |
| 1905 | const string kGUID0 = "GUID0"; |
| 1906 | const string kGUID1 = "GUID1"; |
| 1907 | |
| 1908 | { |
| 1909 | Error error; |
| 1910 | ServiceRefPtr service = manager()->GetServiceWithGUID(kGUID0, &error); |
| 1911 | EXPECT_FALSE(error.IsSuccess()); |
| 1912 | EXPECT_FALSE(service); |
| 1913 | } |
| 1914 | |
| 1915 | KeyValueStore args; |
| 1916 | args.SetString(flimflam::kGuidProperty, kGUID1); |
| 1917 | |
| 1918 | { |
| 1919 | Error error; |
| 1920 | ServiceRefPtr service = manager()->GetService(args, &error); |
| 1921 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1922 | EXPECT_FALSE(service); |
| 1923 | } |
| 1924 | |
| 1925 | mock_service0->set_guid(kGUID0); |
| 1926 | mock_service1->set_guid(kGUID1); |
| 1927 | |
| 1928 | { |
| 1929 | Error error; |
| 1930 | ServiceRefPtr service = manager()->GetServiceWithGUID(kGUID0, &error); |
| 1931 | EXPECT_TRUE(error.IsSuccess()); |
| 1932 | EXPECT_EQ(mock_service0.get(), service.get()); |
| 1933 | } |
| 1934 | |
| 1935 | { |
| 1936 | Error error; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1937 | EXPECT_CALL(*mock_service1.get(), Configure(_, &error)) |
| 1938 | .Times(1); |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1939 | ServiceRefPtr service = manager()->GetService(args, &error); |
| 1940 | EXPECT_TRUE(error.IsSuccess()); |
| 1941 | EXPECT_EQ(mock_service1.get(), service.get()); |
| 1942 | } |
| 1943 | |
| 1944 | manager()->DeregisterService(mock_service0); |
| 1945 | manager()->DeregisterService(mock_service1); |
| 1946 | } |
| 1947 | |
Gary Morain | 028545d | 2012-04-07 14:55:52 -0700 | [diff] [blame] | 1948 | |
| 1949 | TEST_F(ManagerTest, CalculateStateOffline) { |
| 1950 | MockMetrics mock_metrics; |
| 1951 | manager()->set_metrics(&mock_metrics); |
| 1952 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(_)) |
| 1953 | .Times(AnyNumber()); |
| 1954 | scoped_refptr<MockService> mock_service0( |
| 1955 | new NiceMock<MockService>(control_interface(), |
| 1956 | dispatcher(), |
| 1957 | metrics(), |
| 1958 | manager())); |
| 1959 | |
| 1960 | scoped_refptr<MockService> mock_service1( |
| 1961 | new NiceMock<MockService>(control_interface(), |
| 1962 | dispatcher(), |
| 1963 | metrics(), |
| 1964 | manager())); |
| 1965 | |
| 1966 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1967 | .WillRepeatedly(Return(false)); |
| 1968 | EXPECT_CALL(*mock_service1.get(), IsConnected()) |
| 1969 | .WillRepeatedly(Return(false)); |
| 1970 | |
| 1971 | manager()->RegisterService(mock_service0); |
| 1972 | manager()->RegisterService(mock_service1); |
| 1973 | |
| 1974 | EXPECT_EQ("offline", manager()->CalculateState(NULL)); |
| 1975 | |
| 1976 | manager()->DeregisterService(mock_service0); |
| 1977 | manager()->DeregisterService(mock_service1); |
| 1978 | } |
| 1979 | |
| 1980 | TEST_F(ManagerTest, CalculateStateOnline) { |
| 1981 | MockMetrics mock_metrics; |
| 1982 | manager()->set_metrics(&mock_metrics); |
| 1983 | EXPECT_CALL(mock_metrics, NotifyDefaultServiceChanged(_)) |
| 1984 | .Times(AnyNumber()); |
| 1985 | scoped_refptr<MockService> mock_service0( |
| 1986 | new NiceMock<MockService>(control_interface(), |
| 1987 | dispatcher(), |
| 1988 | metrics(), |
| 1989 | manager())); |
| 1990 | |
| 1991 | scoped_refptr<MockService> mock_service1( |
| 1992 | new NiceMock<MockService>(control_interface(), |
| 1993 | dispatcher(), |
| 1994 | metrics(), |
| 1995 | manager())); |
| 1996 | |
| 1997 | EXPECT_CALL(*mock_service0.get(), IsConnected()) |
| 1998 | .WillRepeatedly(Return(false)); |
| 1999 | EXPECT_CALL(*mock_service1.get(), IsConnected()) |
| 2000 | .WillRepeatedly(Return(true)); |
| 2001 | EXPECT_CALL(*mock_service0.get(), state()) |
| 2002 | .WillRepeatedly(Return(Service::kStateIdle)); |
| 2003 | EXPECT_CALL(*mock_service1.get(), state()) |
| 2004 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 2005 | |
| 2006 | manager()->RegisterService(mock_service0); |
| 2007 | manager()->RegisterService(mock_service1); |
| 2008 | |
| 2009 | EXPECT_EQ("online", manager()->CalculateState(NULL)); |
| 2010 | |
| 2011 | manager()->DeregisterService(mock_service0); |
| 2012 | manager()->DeregisterService(mock_service1); |
| 2013 | } |
| 2014 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 2015 | } // namespace shill |