Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/default_profile.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 9 | #include <vector> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 10 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 11 | #include <base/file_path.h> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <gmock/gmock.h> |
| 15 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 16 | #include "shill/key_file_store.h" |
| 17 | #include "shill/glib.h" |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 18 | #include "shill/link_monitor.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 19 | #include "shill/manager.h" |
| 20 | #include "shill/mock_control.h" |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 21 | #include "shill/mock_device.h" |
Paul Stewart | f284a23 | 2012-05-01 10:24:37 -0700 | [diff] [blame] | 22 | #include "shill/mock_service.h" |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 23 | #include "shill/mock_store.h" |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 24 | #include "shill/portal_detector.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 25 | #include "shill/property_store_unittest.h" |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 26 | #include "shill/resolver.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 27 | |
| 28 | using std::map; |
| 29 | using std::string; |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 30 | using std::vector; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 31 | using ::testing::_; |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 32 | using ::testing::DoAll; |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 33 | using ::testing::Return; |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 34 | using ::testing::SetArgumentPointee; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 35 | |
| 36 | namespace shill { |
| 37 | |
| 38 | class DefaultProfileTest : public PropertyStoreTest { |
| 39 | public: |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 40 | DefaultProfileTest() |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 41 | : profile_(new DefaultProfile(control_interface(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 42 | manager(), |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 43 | FilePath(storage_path()), |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 44 | DefaultProfile::kDefaultId, |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 45 | properties_)), |
| 46 | device_(new MockDevice(control_interface(), |
| 47 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 48 | metrics(), |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 49 | manager(), |
| 50 | "null0", |
| 51 | "addr0", |
| 52 | 0)) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 53 | } |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 54 | |
| 55 | virtual ~DefaultProfileTest() {} |
| 56 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 57 | virtual void SetUp() { |
| 58 | PropertyStoreTest::SetUp(); |
| 59 | FilePath final_path; |
| 60 | ASSERT_TRUE(profile_->GetStoragePath(&final_path)); |
| 61 | scoped_ptr<KeyFileStore> storage(new KeyFileStore(&real_glib_)); |
| 62 | storage->set_path(final_path); |
| 63 | ASSERT_TRUE(storage->Open()); |
| 64 | profile_->set_storage(storage.release()); // Passes ownership. |
| 65 | } |
| 66 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 67 | protected: |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 68 | static const char kTestStoragePath[]; |
| 69 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 70 | GLib real_glib_; |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 71 | scoped_refptr<DefaultProfile> profile_; |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 72 | scoped_refptr<MockDevice> device_; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 73 | Manager::Properties properties_; |
| 74 | }; |
| 75 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 76 | const char DefaultProfileTest::kTestStoragePath[] = "/no/where"; |
| 77 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 78 | TEST_F(DefaultProfileTest, GetProperties) { |
| 79 | Error error(Error::kInvalidProperty, ""); |
| 80 | { |
| 81 | map<string, ::DBus::Variant> props; |
| 82 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 83 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 84 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 85 | EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 86 | } |
| 87 | properties_.offline_mode = true; |
| 88 | { |
| 89 | map<string, ::DBus::Variant> props; |
| 90 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 91 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 92 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 93 | EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 94 | } |
| 95 | { |
| 96 | Error error(Error::kInvalidProperty, ""); |
| 97 | EXPECT_FALSE( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 98 | profile_->mutable_store()->SetBoolProperty( |
| 99 | flimflam::kOfflineModeProperty, |
| 100 | true, |
| 101 | &error)); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 105 | TEST_F(DefaultProfileTest, Save) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 106 | scoped_ptr<MockStore> storage(new MockStore); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 107 | EXPECT_CALL(*storage.get(), SetBool(DefaultProfile::kStorageId, |
| 108 | DefaultProfile::kStorageArpGateway, |
| 109 | true)) |
| 110 | .WillOnce(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 111 | EXPECT_CALL(*storage.get(), SetString(DefaultProfile::kStorageId, |
| 112 | DefaultProfile::kStorageName, |
| 113 | DefaultProfile::kDefaultId)) |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 114 | .WillOnce(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 115 | EXPECT_CALL(*storage.get(), SetString(DefaultProfile::kStorageId, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 116 | DefaultProfile::kStorageHostName, |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 117 | "")) |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 118 | .WillOnce(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 119 | EXPECT_CALL(*storage.get(), SetBool(DefaultProfile::kStorageId, |
| 120 | DefaultProfile::kStorageOfflineMode, |
| 121 | false)) |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 122 | .WillOnce(Return(true)); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 123 | EXPECT_CALL(*storage.get(), SetString(DefaultProfile::kStorageId, |
| 124 | DefaultProfile::kStorageCheckPortalList, |
| 125 | "")) |
| 126 | .WillOnce(Return(true)); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 127 | EXPECT_CALL(*storage.get(), |
| 128 | SetString(DefaultProfile::kStorageId, |
| 129 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 130 | "")) |
| 131 | .WillOnce(Return(true)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 132 | EXPECT_CALL(*storage.get(), SetString(DefaultProfile::kStorageId, |
| 133 | DefaultProfile::kStoragePortalURL, |
| 134 | "")) |
| 135 | .WillOnce(Return(true)); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 136 | EXPECT_CALL(*storage.get(), |
| 137 | SetString(DefaultProfile::kStorageId, |
| 138 | DefaultProfile::kStoragePortalCheckInterval, |
| 139 | "0")) |
| 140 | .WillOnce(Return(true)); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 141 | EXPECT_CALL(*storage.get(), |
| 142 | SetString(DefaultProfile::kStorageId, |
| 143 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 144 | "")) |
| 145 | .WillOnce(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 146 | EXPECT_CALL(*storage.get(), Flush()).WillOnce(Return(true)); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 147 | |
Paul Stewart | 212d60f | 2012-07-12 10:59:13 -0700 | [diff] [blame] | 148 | EXPECT_CALL(*device_.get(), Save(storage.get())).Times(0); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 149 | profile_->set_storage(storage.release()); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 150 | |
| 151 | manager()->RegisterDevice(device_); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 152 | ASSERT_TRUE(profile_->Save()); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 153 | manager()->DeregisterDevice(device_); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 156 | TEST_F(DefaultProfileTest, LoadManagerDefaultProperties) { |
| 157 | scoped_ptr<MockStore> storage(new MockStore); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 158 | Manager::Properties manager_props; |
| 159 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 160 | DefaultProfile::kStorageArpGateway, |
| 161 | &manager_props.arp_gateway)) |
| 162 | .WillOnce(Return(false)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 163 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 164 | DefaultProfile::kStorageHostName, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 165 | &manager_props.host_name)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 166 | .WillOnce(Return(false)); |
| 167 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 168 | DefaultProfile::kStorageOfflineMode, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 169 | &manager_props.offline_mode)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 170 | .WillOnce(Return(false)); |
| 171 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 172 | DefaultProfile::kStorageCheckPortalList, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 173 | &manager_props.check_portal_list)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 174 | .WillOnce(Return(false)); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 175 | EXPECT_CALL(*storage.get(), |
| 176 | GetString(DefaultProfile::kStorageId, |
| 177 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 178 | _)) |
| 179 | .WillOnce(Return(false)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 180 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 181 | DefaultProfile::kStoragePortalURL, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 182 | &manager_props.portal_url)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 183 | .WillOnce(Return(false)); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 184 | EXPECT_CALL(*storage.get(), |
| 185 | GetString(DefaultProfile::kStorageId, |
| 186 | DefaultProfile::kStoragePortalCheckInterval, |
| 187 | _)) |
| 188 | .WillOnce(Return(false)); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 189 | EXPECT_CALL(*storage.get(), |
| 190 | GetString(DefaultProfile::kStorageId, |
| 191 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 192 | _)) |
| 193 | .WillOnce(Return(false)); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 194 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 195 | profile_->set_storage(storage.release()); |
| 196 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 197 | ASSERT_TRUE(profile_->LoadManagerProperties(&manager_props)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 198 | EXPECT_TRUE(manager_props.arp_gateway); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 199 | EXPECT_EQ("", manager_props.host_name); |
| 200 | EXPECT_FALSE(manager_props.offline_mode); |
Paul Stewart | f555cf8 | 2012-03-15 14:42:43 -0700 | [diff] [blame] | 201 | EXPECT_EQ(PortalDetector::kDefaultCheckPortalList, |
| 202 | manager_props.check_portal_list); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 203 | EXPECT_EQ(LinkMonitor::kDefaultLinkMonitorTechnologies, |
| 204 | manager_props.link_monitor_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 205 | EXPECT_EQ(PortalDetector::kDefaultURL, manager_props.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 206 | EXPECT_EQ(PortalDetector::kDefaultCheckIntervalSeconds, |
| 207 | manager_props.portal_check_interval_seconds); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 208 | EXPECT_EQ(Resolver::kDefaultShortTimeoutTechnologies, |
| 209 | manager_props.short_dns_timeout_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 212 | TEST_F(DefaultProfileTest, LoadManagerProperties) { |
| 213 | scoped_ptr<MockStore> storage(new MockStore); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 214 | const string host_name("hostname"); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 215 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 216 | DefaultProfile::kStorageArpGateway, |
| 217 | _)) |
| 218 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 219 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 220 | DefaultProfile::kStorageHostName, |
| 221 | _)) |
| 222 | .WillOnce(DoAll(SetArgumentPointee<2>(host_name), Return(true))); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 223 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 224 | DefaultProfile::kStorageOfflineMode, |
| 225 | _)) |
| 226 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 227 | const string portal_list("technology1,technology2"); |
| 228 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 229 | DefaultProfile::kStorageCheckPortalList, |
| 230 | _)) |
| 231 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_list), Return(true))); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 232 | const string link_monitor_technologies("ethernet,wimax"); |
| 233 | EXPECT_CALL(*storage.get(), |
| 234 | GetString(DefaultProfile::kStorageId, |
| 235 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 236 | _)) |
| 237 | .WillOnce(DoAll(SetArgumentPointee<2>(link_monitor_technologies), |
| 238 | Return(true))); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 239 | const string portal_url("http://www.chromium.org"); |
| 240 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 241 | DefaultProfile::kStoragePortalURL, |
| 242 | _)) |
| 243 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_url), Return(true))); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 244 | const string portal_check_interval_string("10"); |
| 245 | const int portal_check_interval_int = 10; |
| 246 | EXPECT_CALL(*storage.get(), |
| 247 | GetString(DefaultProfile::kStorageId, |
| 248 | DefaultProfile::kStoragePortalCheckInterval, |
| 249 | _)) |
| 250 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_check_interval_string), |
| 251 | Return(true))); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 252 | const string short_dns_timeout_technologies("wimax,cellular"); |
| 253 | EXPECT_CALL(*storage.get(), |
| 254 | GetString(DefaultProfile::kStorageId, |
| 255 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 256 | _)) |
| 257 | .WillOnce(DoAll(SetArgumentPointee<2>(short_dns_timeout_technologies), |
| 258 | Return(true))); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 259 | profile_->set_storage(storage.release()); |
| 260 | |
| 261 | Manager::Properties manager_props; |
| 262 | ASSERT_TRUE(profile_->LoadManagerProperties(&manager_props)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 263 | EXPECT_FALSE(manager_props.arp_gateway); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 264 | EXPECT_EQ(host_name, manager_props.host_name); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 265 | EXPECT_TRUE(manager_props.offline_mode); |
| 266 | EXPECT_EQ(portal_list, manager_props.check_portal_list); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 267 | EXPECT_EQ(link_monitor_technologies, |
| 268 | manager_props.link_monitor_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 269 | EXPECT_EQ(portal_url, manager_props.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 270 | EXPECT_EQ(portal_check_interval_int, |
| 271 | manager_props.portal_check_interval_seconds); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 272 | EXPECT_EQ(short_dns_timeout_technologies, |
| 273 | manager_props.short_dns_timeout_technologies); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 276 | TEST_F(DefaultProfileTest, GetStoragePath) { |
| 277 | FilePath path; |
| 278 | EXPECT_TRUE(profile_->GetStoragePath(&path)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 279 | EXPECT_EQ(storage_path() + "/default.profile", path.value()); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Paul Stewart | f284a23 | 2012-05-01 10:24:37 -0700 | [diff] [blame] | 282 | TEST_F(DefaultProfileTest, ConfigureService) { |
| 283 | scoped_ptr<MockStore> storage(new MockStore); |
| 284 | EXPECT_CALL(*storage, ContainsGroup(_)) |
| 285 | .WillRepeatedly(Return(false)); |
| 286 | EXPECT_CALL(*storage, Flush()) |
| 287 | .WillOnce(Return(true)); |
| 288 | |
| 289 | scoped_refptr<MockService> unknown_service(new MockService( |
| 290 | control_interface(), |
| 291 | dispatcher(), |
| 292 | metrics(), |
| 293 | manager())); |
| 294 | EXPECT_CALL(*unknown_service, technology()) |
| 295 | .WillOnce(Return(Technology::kUnknown)); |
| 296 | EXPECT_CALL(*unknown_service, Save(_)) .Times(0); |
| 297 | |
| 298 | scoped_refptr<MockService> ethernet_service(new MockService( |
| 299 | control_interface(), |
| 300 | dispatcher(), |
| 301 | metrics(), |
| 302 | manager())); |
| 303 | EXPECT_CALL(*ethernet_service, technology()) |
| 304 | .WillOnce(Return(Technology::kEthernet)); |
| 305 | EXPECT_CALL(*ethernet_service, Save(storage.get())) |
| 306 | .WillOnce(Return(true)); |
| 307 | |
| 308 | profile_->set_storage(storage.release()); |
| 309 | EXPECT_FALSE(profile_->ConfigureService(unknown_service)); |
| 310 | EXPECT_TRUE(profile_->ConfigureService(ethernet_service)); |
| 311 | } |
| 312 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 313 | TEST_F(DefaultProfileTest, UpdateDevice) { |
| 314 | scoped_ptr<MockStore> storage(new MockStore()); |
| 315 | EXPECT_CALL(*storage, Flush()).WillOnce(Return(true)); |
| 316 | EXPECT_CALL(*device_, Save(storage.get())) |
| 317 | .WillOnce(Return(true)) |
| 318 | .WillOnce(Return(false)); |
| 319 | profile_->set_storage(storage.release()); |
| 320 | EXPECT_TRUE(profile_->UpdateDevice(device_)); |
| 321 | EXPECT_FALSE(profile_->UpdateDevice(device_)); |
| 322 | } |
| 323 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 324 | } // namespace shill |