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