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, |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame^] | 129 | DefaultProfile::kStorageIgnoredDNSSearchPaths, |
| 130 | "")) |
| 131 | .WillOnce(Return(true)); |
| 132 | EXPECT_CALL(*storage.get(), |
| 133 | SetString(DefaultProfile::kStorageId, |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 134 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 135 | "")) |
| 136 | .WillOnce(Return(true)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 137 | EXPECT_CALL(*storage.get(), SetString(DefaultProfile::kStorageId, |
| 138 | DefaultProfile::kStoragePortalURL, |
| 139 | "")) |
| 140 | .WillOnce(Return(true)); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 141 | EXPECT_CALL(*storage.get(), |
| 142 | SetString(DefaultProfile::kStorageId, |
| 143 | DefaultProfile::kStoragePortalCheckInterval, |
| 144 | "0")) |
| 145 | .WillOnce(Return(true)); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 146 | EXPECT_CALL(*storage.get(), |
| 147 | SetString(DefaultProfile::kStorageId, |
| 148 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 149 | "")) |
| 150 | .WillOnce(Return(true)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 151 | EXPECT_CALL(*storage.get(), Flush()).WillOnce(Return(true)); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 152 | |
Paul Stewart | 212d60f | 2012-07-12 10:59:13 -0700 | [diff] [blame] | 153 | EXPECT_CALL(*device_.get(), Save(storage.get())).Times(0); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 154 | profile_->set_storage(storage.release()); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 155 | |
| 156 | manager()->RegisterDevice(device_); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 157 | ASSERT_TRUE(profile_->Save()); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 158 | manager()->DeregisterDevice(device_); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 161 | TEST_F(DefaultProfileTest, LoadManagerDefaultProperties) { |
| 162 | scoped_ptr<MockStore> storage(new MockStore); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 163 | Manager::Properties manager_props; |
| 164 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 165 | DefaultProfile::kStorageArpGateway, |
| 166 | &manager_props.arp_gateway)) |
| 167 | .WillOnce(Return(false)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 168 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 169 | DefaultProfile::kStorageHostName, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 170 | &manager_props.host_name)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 171 | .WillOnce(Return(false)); |
| 172 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 173 | DefaultProfile::kStorageOfflineMode, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 174 | &manager_props.offline_mode)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 175 | .WillOnce(Return(false)); |
| 176 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 177 | DefaultProfile::kStorageCheckPortalList, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 178 | &manager_props.check_portal_list)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 179 | .WillOnce(Return(false)); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 180 | EXPECT_CALL(*storage.get(), |
| 181 | GetString(DefaultProfile::kStorageId, |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame^] | 182 | DefaultProfile::kStorageIgnoredDNSSearchPaths, |
| 183 | &manager_props.ignored_dns_search_paths)) |
| 184 | .WillOnce(Return(false)); |
| 185 | EXPECT_CALL(*storage.get(), |
| 186 | GetString(DefaultProfile::kStorageId, |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 187 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 188 | _)) |
| 189 | .WillOnce(Return(false)); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 190 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 191 | DefaultProfile::kStoragePortalURL, |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 192 | &manager_props.portal_url)) |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 193 | .WillOnce(Return(false)); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 194 | EXPECT_CALL(*storage.get(), |
| 195 | GetString(DefaultProfile::kStorageId, |
| 196 | DefaultProfile::kStoragePortalCheckInterval, |
| 197 | _)) |
| 198 | .WillOnce(Return(false)); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 199 | EXPECT_CALL(*storage.get(), |
| 200 | GetString(DefaultProfile::kStorageId, |
| 201 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 202 | _)) |
| 203 | .WillOnce(Return(false)); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 204 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 205 | profile_->set_storage(storage.release()); |
| 206 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 207 | ASSERT_TRUE(profile_->LoadManagerProperties(&manager_props)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 208 | EXPECT_TRUE(manager_props.arp_gateway); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 209 | EXPECT_EQ("", manager_props.host_name); |
| 210 | EXPECT_FALSE(manager_props.offline_mode); |
Paul Stewart | f555cf8 | 2012-03-15 14:42:43 -0700 | [diff] [blame] | 211 | EXPECT_EQ(PortalDetector::kDefaultCheckPortalList, |
| 212 | manager_props.check_portal_list); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame^] | 213 | EXPECT_EQ(Resolver::kDefaultIgnoredSearchList, |
| 214 | manager_props.ignored_dns_search_paths); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 215 | EXPECT_EQ(LinkMonitor::kDefaultLinkMonitorTechnologies, |
| 216 | manager_props.link_monitor_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 217 | EXPECT_EQ(PortalDetector::kDefaultURL, manager_props.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 218 | EXPECT_EQ(PortalDetector::kDefaultCheckIntervalSeconds, |
| 219 | manager_props.portal_check_interval_seconds); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 220 | EXPECT_EQ(Resolver::kDefaultShortTimeoutTechnologies, |
| 221 | manager_props.short_dns_timeout_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 224 | TEST_F(DefaultProfileTest, LoadManagerProperties) { |
| 225 | scoped_ptr<MockStore> storage(new MockStore); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 226 | const string host_name("hostname"); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 227 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 228 | DefaultProfile::kStorageArpGateway, |
| 229 | _)) |
| 230 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 231 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 232 | DefaultProfile::kStorageHostName, |
| 233 | _)) |
| 234 | .WillOnce(DoAll(SetArgumentPointee<2>(host_name), Return(true))); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 235 | EXPECT_CALL(*storage.get(), GetBool(DefaultProfile::kStorageId, |
| 236 | DefaultProfile::kStorageOfflineMode, |
| 237 | _)) |
| 238 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 239 | const string portal_list("technology1,technology2"); |
| 240 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 241 | DefaultProfile::kStorageCheckPortalList, |
| 242 | _)) |
| 243 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_list), Return(true))); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame^] | 244 | const string ignored_paths("chromium.org,google.com"); |
| 245 | EXPECT_CALL(*storage.get(), |
| 246 | GetString(DefaultProfile::kStorageId, |
| 247 | DefaultProfile::kStorageIgnoredDNSSearchPaths, |
| 248 | _)) |
| 249 | .WillOnce(DoAll(SetArgumentPointee<2>(ignored_paths), Return(true))); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 250 | const string link_monitor_technologies("ethernet,wimax"); |
| 251 | EXPECT_CALL(*storage.get(), |
| 252 | GetString(DefaultProfile::kStorageId, |
| 253 | DefaultProfile::kStorageLinkMonitorTechnologies, |
| 254 | _)) |
| 255 | .WillOnce(DoAll(SetArgumentPointee<2>(link_monitor_technologies), |
| 256 | Return(true))); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 257 | const string portal_url("http://www.chromium.org"); |
| 258 | EXPECT_CALL(*storage.get(), GetString(DefaultProfile::kStorageId, |
| 259 | DefaultProfile::kStoragePortalURL, |
| 260 | _)) |
| 261 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_url), Return(true))); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 262 | const string portal_check_interval_string("10"); |
| 263 | const int portal_check_interval_int = 10; |
| 264 | EXPECT_CALL(*storage.get(), |
| 265 | GetString(DefaultProfile::kStorageId, |
| 266 | DefaultProfile::kStoragePortalCheckInterval, |
| 267 | _)) |
| 268 | .WillOnce(DoAll(SetArgumentPointee<2>(portal_check_interval_string), |
| 269 | Return(true))); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 270 | const string short_dns_timeout_technologies("wimax,cellular"); |
| 271 | EXPECT_CALL(*storage.get(), |
| 272 | GetString(DefaultProfile::kStorageId, |
| 273 | DefaultProfile::kStorageShortDNSTimeoutTechnologies, |
| 274 | _)) |
| 275 | .WillOnce(DoAll(SetArgumentPointee<2>(short_dns_timeout_technologies), |
| 276 | Return(true))); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 277 | profile_->set_storage(storage.release()); |
| 278 | |
| 279 | Manager::Properties manager_props; |
| 280 | ASSERT_TRUE(profile_->LoadManagerProperties(&manager_props)); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 281 | EXPECT_FALSE(manager_props.arp_gateway); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 282 | EXPECT_EQ(host_name, manager_props.host_name); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 283 | EXPECT_TRUE(manager_props.offline_mode); |
| 284 | EXPECT_EQ(portal_list, manager_props.check_portal_list); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame^] | 285 | EXPECT_EQ(ignored_paths, manager_props.ignored_dns_search_paths); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 286 | EXPECT_EQ(link_monitor_technologies, |
| 287 | manager_props.link_monitor_technologies); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 288 | EXPECT_EQ(portal_url, manager_props.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 289 | EXPECT_EQ(portal_check_interval_int, |
| 290 | manager_props.portal_check_interval_seconds); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 291 | EXPECT_EQ(short_dns_timeout_technologies, |
| 292 | manager_props.short_dns_timeout_technologies); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 295 | TEST_F(DefaultProfileTest, GetStoragePath) { |
| 296 | FilePath path; |
| 297 | EXPECT_TRUE(profile_->GetStoragePath(&path)); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 298 | EXPECT_EQ(storage_path() + "/default.profile", path.value()); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Paul Stewart | f284a23 | 2012-05-01 10:24:37 -0700 | [diff] [blame] | 301 | TEST_F(DefaultProfileTest, ConfigureService) { |
| 302 | scoped_ptr<MockStore> storage(new MockStore); |
| 303 | EXPECT_CALL(*storage, ContainsGroup(_)) |
| 304 | .WillRepeatedly(Return(false)); |
| 305 | EXPECT_CALL(*storage, Flush()) |
| 306 | .WillOnce(Return(true)); |
| 307 | |
| 308 | scoped_refptr<MockService> unknown_service(new MockService( |
| 309 | control_interface(), |
| 310 | dispatcher(), |
| 311 | metrics(), |
| 312 | manager())); |
| 313 | EXPECT_CALL(*unknown_service, technology()) |
| 314 | .WillOnce(Return(Technology::kUnknown)); |
| 315 | EXPECT_CALL(*unknown_service, Save(_)) .Times(0); |
| 316 | |
| 317 | scoped_refptr<MockService> ethernet_service(new MockService( |
| 318 | control_interface(), |
| 319 | dispatcher(), |
| 320 | metrics(), |
| 321 | manager())); |
| 322 | EXPECT_CALL(*ethernet_service, technology()) |
| 323 | .WillOnce(Return(Technology::kEthernet)); |
| 324 | EXPECT_CALL(*ethernet_service, Save(storage.get())) |
| 325 | .WillOnce(Return(true)); |
| 326 | |
| 327 | profile_->set_storage(storage.release()); |
| 328 | EXPECT_FALSE(profile_->ConfigureService(unknown_service)); |
| 329 | EXPECT_TRUE(profile_->ConfigureService(ethernet_service)); |
| 330 | } |
| 331 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 332 | TEST_F(DefaultProfileTest, UpdateDevice) { |
| 333 | scoped_ptr<MockStore> storage(new MockStore()); |
| 334 | EXPECT_CALL(*storage, Flush()).WillOnce(Return(true)); |
| 335 | EXPECT_CALL(*device_, Save(storage.get())) |
| 336 | .WillOnce(Return(true)) |
| 337 | .WillOnce(Return(false)); |
| 338 | profile_->set_storage(storage.release()); |
| 339 | EXPECT_TRUE(profile_->UpdateDevice(device_)); |
| 340 | EXPECT_FALSE(profile_->UpdateDevice(device_)); |
| 341 | } |
| 342 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 343 | } // namespace shill |