Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -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/service.h" |
| 6 | |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 7 | #include <algorithm> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 8 | #include <map> |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 9 | #include <memory> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 13 | #include <base/bind.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 15 | #include <dbus-c++/dbus.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include <gtest/gtest.h> |
| 17 | #include <gmock/gmock.h> |
| 18 | |
| 19 | #include "shill/dbus_adaptor.h" |
Ben Chan | 8760251 | 2014-11-07 20:50:05 -0800 | [diff] [blame] | 20 | #include "shill/ethernet/ethernet_service.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 21 | #include "shill/event_dispatcher.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 22 | #include "shill/manager.h" |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 23 | #include "shill/mock_adaptors.h" |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 24 | #include "shill/mock_connection.h" |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 25 | #include "shill/mock_control.h" |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 26 | #include "shill/mock_device_info.h" |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 27 | #include "shill/mock_diagnostics_reporter.h" |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 28 | #include "shill/mock_event_dispatcher.h" |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 29 | #include "shill/mock_log.h" |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 30 | #include "shill/mock_manager.h" |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 31 | #include "shill/mock_power_manager.h" |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 32 | #include "shill/mock_profile.h" |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 33 | #include "shill/mock_proxy_factory.h" |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 34 | #include "shill/mock_service.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 35 | #include "shill/mock_store.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 36 | #include "shill/net/mock_time.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 37 | #include "shill/property_store_unittest.h" |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 38 | #include "shill/service_property_change_test.h" |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 39 | #include "shill/service_sorter.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 40 | #include "shill/service_under_test.h" |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 41 | #include "shill/testing.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 42 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 43 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
| 44 | #include "shill/mock_eap_credentials.h" |
| 45 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
| 46 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 47 | using base::Bind; |
| 48 | using base::Unretained; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 49 | using std::deque; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 50 | using std::map; |
| 51 | using std::string; |
| 52 | using std::vector; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 53 | using testing::_; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 54 | using testing::AnyNumber; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 55 | using testing::AtLeast; |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 56 | using testing::DefaultValue; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 57 | using testing::DoAll; |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 58 | using testing::HasSubstr; |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 59 | using testing::Mock; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 60 | using testing::NiceMock; |
| 61 | using testing::Return; |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 62 | using testing::ReturnNull; |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 63 | using testing::ReturnRef; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 64 | using testing::StrictMock; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 65 | using testing::SetArgumentPointee; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 66 | using testing::Test; |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 67 | using testing::Values; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 68 | |
| 69 | namespace shill { |
| 70 | |
| 71 | class ServiceTest : public PropertyStoreTest { |
| 72 | public: |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 73 | ServiceTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 74 | : mock_manager_(control_interface(), dispatcher(), metrics(), glib()), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 75 | service_(new ServiceUnderTest(control_interface(), |
| 76 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 77 | metrics(), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 78 | &mock_manager_)), |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 79 | service2_(new ServiceUnderTest(control_interface(), |
| 80 | dispatcher(), |
| 81 | metrics(), |
| 82 | &mock_manager_)), |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 83 | storage_id_(ServiceUnderTest::kStorageId), |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 84 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
| 85 | eap_(new MockEapCredentials()), |
| 86 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
| 87 | power_manager_(new MockPowerManager(nullptr, &proxy_factory_)) { |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 88 | ON_CALL(proxy_factory_, CreatePowerManagerProxy(_)) |
| 89 | .WillByDefault(ReturnNull()); |
| 90 | |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 91 | service_->time_ = &time_; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 92 | service_->disconnects_.time_ = &time_; |
| 93 | service_->misconnects_.time_ = &time_; |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 94 | DefaultValue<Timestamp>::Set(Timestamp()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 95 | service_->diagnostics_reporter_ = &diagnostics_reporter_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 96 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 97 | service_->eap_.reset(eap_); // Passes ownership. |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 98 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 99 | mock_manager_.running_ = true; |
| 100 | mock_manager_.set_power_manager(power_manager_); // Passes ownership. |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 101 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 102 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 103 | virtual ~ServiceTest() {} |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 104 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 105 | MOCK_METHOD1(TestCallback, void(const Error& error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 106 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 107 | protected: |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 108 | typedef scoped_refptr<MockProfile> MockProfileRefPtr; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 109 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 110 | ServiceMockAdaptor* GetAdaptor() { |
| 111 | return dynamic_cast<ServiceMockAdaptor*>(service_->adaptor()); |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 114 | string GetFriendlyName() { return service_->friendly_name(); } |
| 115 | |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 116 | void SetManagerRunning(bool running) { mock_manager_.running_ = running; } |
| 117 | |
Daniel Erat | fac0953 | 2014-04-17 20:25:59 -0700 | [diff] [blame] | 118 | void SetSuspending(bool suspending) { |
| 119 | power_manager_->suspending_ = suspending; |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 122 | bool GetExplicitlyDisconnected() const { |
| 123 | return service_->explicitly_disconnected_; |
| 124 | } |
| 125 | |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 126 | void SetExplicitlyDisconnected(bool explicitly) { |
| 127 | service_->explicitly_disconnected_ = explicitly; |
| 128 | } |
| 129 | |
| 130 | void SetStateField(Service::ConnectState state) { service_->state_ = state; } |
| 131 | |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 132 | Service::ConnectState GetPreviousState() const { |
| 133 | return service_->previous_state_; |
| 134 | } |
| 135 | |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 136 | void NoteDisconnectEvent() { |
| 137 | service_->NoteDisconnectEvent(); |
| 138 | } |
| 139 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 140 | EventHistory* GetDisconnects() { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 141 | return &service_->disconnects_; |
| 142 | } |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 143 | EventHistory* GetMisconnects() { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 144 | return &service_->misconnects_; |
| 145 | } |
| 146 | |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 147 | Timestamp GetTimestamp(int monotonic_seconds, int boottime_seconds, |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 148 | const string& wall_clock) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 149 | struct timeval monotonic = { .tv_sec = monotonic_seconds, .tv_usec = 0 }; |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 150 | struct timeval boottime = { .tv_sec = boottime_seconds, .tv_usec = 0 }; |
| 151 | return Timestamp(monotonic, boottime, wall_clock); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 154 | void PushTimestamp(EventHistory* events, |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 155 | int monotonic_seconds, |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 156 | int boottime_seconds, |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 157 | const string& wall_clock) { |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 158 | events->RecordEventInternal( |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 159 | GetTimestamp(monotonic_seconds, boottime_seconds, wall_clock)); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 160 | } |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 161 | |
| 162 | int GetDisconnectsMonitorSeconds() { |
| 163 | return Service::kDisconnectsMonitorSeconds; |
| 164 | } |
| 165 | |
| 166 | int GetMisconnectsMonitorSeconds() { |
| 167 | return Service::kMisconnectsMonitorSeconds; |
| 168 | } |
| 169 | |
| 170 | int GetReportDisconnectsThreshold() { |
| 171 | return Service::kReportDisconnectsThreshold; |
| 172 | } |
| 173 | |
| 174 | int GetReportMisconnectsThreshold() { |
| 175 | return Service::kReportMisconnectsThreshold; |
| 176 | } |
| 177 | |
| 178 | int GetMaxDisconnectEventHistory() { |
| 179 | return Service::kMaxDisconnectEventHistory; |
| 180 | } |
| 181 | |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 182 | int GetMaxMisconnectEventHistory() { |
| 183 | return Service::kMaxMisconnectEventHistory; |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 186 | bool GetAutoConnect(Error* error) { |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 187 | return service_->GetAutoConnect(error); |
| 188 | } |
| 189 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 190 | void ClearAutoConnect(Error* error) { |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 191 | service_->ClearAutoConnect(error); |
| 192 | } |
| 193 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 194 | bool SetAutoConnectFull(bool connect, Error* error) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 195 | return service_->SetAutoConnectFull(connect, error); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 198 | bool SortingOrderIs(const ServiceRefPtr& service0, |
| 199 | const ServiceRefPtr& service1, |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 200 | bool should_compare_connectivity_state) { |
| 201 | vector<ServiceRefPtr> services; |
| 202 | services.push_back(service1); |
| 203 | services.push_back(service0); |
| 204 | std::sort(services.begin(), services.end(), |
| 205 | ServiceSorter(&mock_manager_, should_compare_connectivity_state, |
| 206 | technology_order_for_sorting_)); |
| 207 | return (service0.get() == services[0].get() && |
| 208 | service1.get() == services[1].get()); |
| 209 | } |
| 210 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 211 | bool DefaultSortingOrderIs(const ServiceRefPtr& service0, |
| 212 | const ServiceRefPtr& service1) { |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 213 | const bool kShouldCompareConnectivityState = true; |
| 214 | return SortingOrderIs( |
| 215 | service0, service1, kShouldCompareConnectivityState); |
| 216 | } |
| 217 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 218 | MockManager mock_manager_; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 219 | MockDiagnosticsReporter diagnostics_reporter_; |
| 220 | MockTime time_; |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 221 | scoped_refptr<ServiceUnderTest> service_; |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 222 | scoped_refptr<ServiceUnderTest> service2_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 223 | string storage_id_; |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 224 | NiceMock<MockProxyFactory> proxy_factory_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 225 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 226 | MockEapCredentials* eap_; // Owned by |service_|. |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 227 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 228 | MockPowerManager* power_manager_; // Owned by |mock_manager_|. |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 229 | vector<Technology::Identifier> technology_order_for_sorting_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 232 | class AllMockServiceTest : public testing::Test { |
| 233 | public: |
| 234 | AllMockServiceTest() |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 235 | : metrics_(&dispatcher_), |
| 236 | manager_(&control_interface_, &dispatcher_, &metrics_, &glib_), |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 237 | service_(new ServiceUnderTest(&control_interface_, |
| 238 | &dispatcher_, |
| 239 | &metrics_, |
| 240 | &manager_)) { } |
| 241 | virtual ~AllMockServiceTest() {} |
| 242 | |
| 243 | protected: |
| 244 | MockControl control_interface_; |
| 245 | StrictMock<MockEventDispatcher> dispatcher_; |
| 246 | MockGLib glib_; |
| 247 | NiceMock<MockMetrics> metrics_; |
| 248 | MockManager manager_; |
| 249 | scoped_refptr<ServiceUnderTest> service_; |
| 250 | }; |
| 251 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 252 | TEST_F(ServiceTest, Constructor) { |
| 253 | EXPECT_TRUE(service_->save_credentials_); |
| 254 | EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 255 | EXPECT_EQ(Service::kStateIdle, service_->state()); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 256 | EXPECT_FALSE(service_->has_ever_connected()); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 257 | EXPECT_EQ(0, service_->previous_error_serial_number_); |
| 258 | EXPECT_EQ("", service_->previous_error_); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 261 | TEST_F(ServiceTest, CalculateState) { |
| 262 | service_->state_ = Service::kStateConnected; |
| 263 | Error error; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 264 | EXPECT_EQ(kStateReady, service_->CalculateState(&error)); |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 265 | EXPECT_TRUE(error.IsSuccess()); |
| 266 | } |
| 267 | |
| 268 | TEST_F(ServiceTest, CalculateTechnology) { |
| 269 | service_->technology_ = Technology::kWifi; |
| 270 | Error error; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 271 | EXPECT_EQ(kTypeWifi, service_->CalculateTechnology(&error)); |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 272 | EXPECT_TRUE(error.IsSuccess()); |
| 273 | } |
| 274 | |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 275 | TEST_F(ServiceTest, GetProperties) { |
| 276 | map<string, ::DBus::Variant> props; |
| 277 | Error error(Error::kInvalidProperty, ""); |
| 278 | { |
| 279 | ::DBus::Error dbus_error; |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 280 | string expected("true"); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 281 | service_->mutable_store()->SetStringProperty(kCheckPortalProperty, |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 282 | expected, |
| 283 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 284 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 285 | ASSERT_FALSE(props.find(kCheckPortalProperty) == props.end()); |
| 286 | EXPECT_EQ(props[kCheckPortalProperty].reader().get_string(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 287 | expected); |
| 288 | } |
| 289 | { |
| 290 | ::DBus::Error dbus_error; |
| 291 | bool expected = true; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 292 | service_->mutable_store()->SetBoolProperty(kAutoConnectProperty, |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 293 | expected, |
| 294 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 295 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 296 | ASSERT_FALSE(props.find(kAutoConnectProperty) == props.end()); |
| 297 | EXPECT_EQ(props[kAutoConnectProperty].reader().get_bool(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 298 | expected); |
| 299 | } |
| 300 | { |
| 301 | ::DBus::Error dbus_error; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 302 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 303 | ASSERT_FALSE(props.find(kConnectableProperty) == props.end()); |
| 304 | EXPECT_EQ(props[kConnectableProperty].reader().get_bool(), false); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 305 | } |
| 306 | { |
| 307 | ::DBus::Error dbus_error; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 308 | int32_t expected = 127; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 309 | service_->mutable_store()->SetInt32Property(kPriorityProperty, |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 310 | expected, |
| 311 | &error); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 312 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 313 | ASSERT_FALSE(props.find(kPriorityProperty) == props.end()); |
| 314 | EXPECT_EQ(props[kPriorityProperty].reader().get_int32(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 315 | expected); |
| 316 | } |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 317 | { |
| 318 | ::DBus::Error dbus_error; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 319 | DBusAdaptor::GetProperties(service_->store(), &props, &dbus_error); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 320 | ASSERT_FALSE(props.find(kDeviceProperty) == props.end()); |
| 321 | EXPECT_EQ(props[kDeviceProperty].reader().get_path(), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 322 | string(ServiceUnderTest::kRpcId)); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 323 | } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 324 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 325 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 326 | TEST_F(ServiceTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 327 | { |
| 328 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 329 | EXPECT_TRUE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 330 | kSaveCredentialsProperty, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 331 | PropertyStoreTest::kBoolV, |
| 332 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 333 | } |
| 334 | { |
| 335 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 336 | ::DBus::Variant priority; |
| 337 | priority.writer().append_int32(1); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 338 | EXPECT_TRUE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 339 | kPriorityProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 340 | priority, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 341 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 342 | } |
| 343 | { |
| 344 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 345 | ::DBus::Variant guid; |
| 346 | guid.writer().append_string("not default"); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 347 | EXPECT_TRUE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 348 | kGuidProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 349 | guid, |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 350 | &error)); |
| 351 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 352 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 353 | // Ensure that EAP properties cannot be set on services with no EAP |
| 354 | // credentials. Use service2_ here since we're have some code in |
| 355 | // ServiceTest::SetUp() that fiddles with service_->eap_. |
| 356 | { |
| 357 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 358 | ::DBus::Variant eap; |
| 359 | eap.writer().append_string("eap eep eip!"); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 360 | EXPECT_FALSE(DBusAdaptor::SetProperty(service2_->mutable_store(), |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 361 | kEapMethodProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 362 | eap, |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 363 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 364 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 365 | EXPECT_EQ(invalid_prop(), error.name()); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 366 | // Now plumb in eap credentials, and try again. |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 367 | service2_->SetEapCredentials(new EapCredentials()); |
| 368 | EXPECT_TRUE(DBusAdaptor::SetProperty(service2_->mutable_store(), |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 369 | kEapMethodProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 370 | eap, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 371 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 372 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 373 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 374 | // Ensure that an attempt to write a R/O property returns InvalidArgs error. |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 375 | { |
| 376 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 377 | EXPECT_FALSE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 378 | kConnectableProperty, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 379 | PropertyStoreTest::kBoolV, |
| 380 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 381 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 382 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 383 | } |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 384 | { |
| 385 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 386 | ::DBus::Variant auto_connect; |
| 387 | auto_connect.writer().append_bool(true); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 388 | EXPECT_TRUE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 389 | kAutoConnectProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 390 | auto_connect, |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 391 | &error)); |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 392 | } |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 393 | // Ensure that we can perform a trivial set of the Name property (to its |
| 394 | // current value) but an attempt to set the property to a different value |
| 395 | // fails. |
| 396 | { |
| 397 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 398 | EXPECT_FALSE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 399 | kNameProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 400 | DBusAdaptor::StringToVariant( |
| 401 | GetFriendlyName()), |
| 402 | &error)); |
| 403 | EXPECT_FALSE(error.is_set()); |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 404 | } |
| 405 | { |
| 406 | ::DBus::Error error; |
| 407 | EXPECT_FALSE(DBusAdaptor::SetProperty(service_->mutable_store(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 408 | kNameProperty, |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 409 | PropertyStoreTest::kStringV, |
| 410 | &error)); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 411 | ASSERT_TRUE(error.is_set()); // name() may be invalid otherwise |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 412 | EXPECT_EQ(invalid_args(), error.name()); |
| 413 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Paul Stewart | e7de294 | 2013-04-25 17:07:31 -0700 | [diff] [blame] | 416 | TEST_F(ServiceTest, GetLoadableStorageIdentifier) { |
| 417 | NiceMock<MockStore> storage; |
| 418 | EXPECT_CALL(storage, ContainsGroup(storage_id_)) |
| 419 | .WillOnce(Return(false)) |
| 420 | .WillOnce(Return(true)); |
| 421 | EXPECT_EQ("", service_->GetLoadableStorageIdentifier(storage)); |
| 422 | EXPECT_EQ(storage_id_, service_->GetLoadableStorageIdentifier(storage)); |
| 423 | } |
| 424 | |
| 425 | TEST_F(ServiceTest, IsLoadableFrom) { |
| 426 | NiceMock<MockStore> storage; |
| 427 | EXPECT_CALL(storage, ContainsGroup(storage_id_)) |
| 428 | .WillOnce(Return(false)) |
| 429 | .WillOnce(Return(true)); |
| 430 | EXPECT_FALSE(service_->IsLoadableFrom(storage)); |
| 431 | EXPECT_TRUE(service_->IsLoadableFrom(storage)); |
| 432 | } |
| 433 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 434 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 435 | class ServiceWithOnEapCredentialsChangedOverride : public ServiceUnderTest { |
| 436 | public: |
| 437 | ServiceWithOnEapCredentialsChangedOverride( |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 438 | ControlInterface* control_interface, |
| 439 | EventDispatcher* dispatcher, |
| 440 | Metrics* metrics, |
| 441 | Manager* manager, |
| 442 | EapCredentials* eap) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 443 | : ServiceUnderTest(control_interface, dispatcher, metrics, manager) { |
| 444 | SetEapCredentials(eap); |
| 445 | } |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 446 | void OnEapCredentialsChanged(Service::UpdateCredentialsReason) override { |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 447 | SetHasEverConnected(false); |
| 448 | } |
| 449 | }; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 450 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 451 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 452 | TEST_F(ServiceTest, Load) { |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 453 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 454 | MockEapCredentials* eap = new MockEapCredentials(); // Owned by |service|. |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 455 | scoped_refptr<ServiceWithOnEapCredentialsChangedOverride> service( |
| 456 | new ServiceWithOnEapCredentialsChangedOverride(control_interface(), |
| 457 | dispatcher(), |
| 458 | metrics(), |
| 459 | &mock_manager_, |
| 460 | eap)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 461 | #else |
| 462 | scoped_refptr<ServiceUnderTest> service( |
| 463 | new ServiceUnderTest(control_interface(), |
| 464 | dispatcher(), |
| 465 | metrics(), |
| 466 | &mock_manager_)); |
| 467 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 468 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 469 | NiceMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 470 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 471 | const string kCheckPortal("check-portal"); |
| 472 | const string kGUID("guid"); |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 473 | const bool kHasEverConnected = true; |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 474 | const int kPriority = 20; |
| 475 | const string kProxyConfig("proxy-config"); |
| 476 | const string kUIData("ui-data"); |
| 477 | EXPECT_CALL(storage, GetString(storage_id_, _, _)).Times(AnyNumber()); |
| 478 | EXPECT_CALL(storage, GetInt(storage_id_, _, _)).Times(AnyNumber()); |
| 479 | EXPECT_CALL(storage, GetString(storage_id_, Service::kStorageCheckPortal, _)) |
| 480 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kCheckPortal), Return(true))); |
| 481 | EXPECT_CALL(storage, GetString(storage_id_, Service::kStorageGUID, _)) |
| 482 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kGUID), Return(true))); |
| 483 | EXPECT_CALL(storage, GetInt(storage_id_, Service::kStoragePriority, _)) |
| 484 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kPriority), Return(true))); |
| 485 | EXPECT_CALL(storage, GetString(storage_id_, Service::kStorageProxyConfig, _)) |
| 486 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kProxyConfig), Return(true))); |
| 487 | EXPECT_CALL(storage, GetString(storage_id_, Service::kStorageUIData, _)) |
| 488 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kUIData), Return(true))); |
Darin Petkov | 0debec0 | 2013-01-22 10:40:05 +0100 | [diff] [blame] | 489 | EXPECT_CALL(storage, GetBool(storage_id_, _, _)).Times(AnyNumber()); |
| 490 | EXPECT_CALL(storage, |
| 491 | GetBool(storage_id_, Service::kStorageSaveCredentials, _)); |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 492 | EXPECT_CALL(storage, |
| 493 | GetBool(storage_id_, Service::kStorageHasEverConnected, _)) |
| 494 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(kHasEverConnected), |
| 495 | Return(true))); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 496 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 497 | EXPECT_CALL(*eap, Load(&storage, storage_id_)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 498 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 499 | EXPECT_TRUE(service->Load(&storage)); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 500 | |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 501 | EXPECT_EQ(kCheckPortal, service->check_portal_); |
| 502 | EXPECT_EQ(kGUID, service->guid_); |
| 503 | EXPECT_TRUE(service->has_ever_connected_); |
| 504 | EXPECT_EQ(kProxyConfig, service->proxy_config_); |
| 505 | EXPECT_EQ(kUIData, service->ui_data_); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 506 | |
| 507 | Mock::VerifyAndClearExpectations(&storage); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 508 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 509 | Mock::VerifyAndClearExpectations(eap_); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 510 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 511 | |
| 512 | // Assure that parameters are set to default if not available in the profile. |
| 513 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
| 514 | EXPECT_CALL(storage, GetBool(storage_id_, _, _)) |
| 515 | .WillRepeatedly(Return(false)); |
| 516 | EXPECT_CALL(storage, GetString(storage_id_, _, _)) |
| 517 | .WillRepeatedly(Return(false)); |
| 518 | EXPECT_CALL(storage, GetInt(storage_id_, _, _)) |
| 519 | .WillRepeatedly(Return(false)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 520 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 521 | EXPECT_CALL(*eap, Load(&storage, storage_id_)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 522 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 523 | EXPECT_TRUE(service->Load(&storage)); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 524 | |
| 525 | EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_); |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 526 | EXPECT_EQ("", service->guid_); |
| 527 | EXPECT_EQ("", service->proxy_config_); |
| 528 | EXPECT_EQ("", service->ui_data_); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 529 | |
| 530 | // has_ever_connected_ flag will reset when EAP credential changes. |
| 531 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 532 | EXPECT_FALSE(service->has_ever_connected_); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 533 | #else |
| 534 | EXPECT_TRUE(service->has_ever_connected_); |
| 535 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | TEST_F(ServiceTest, LoadFail) { |
| 539 | StrictMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 540 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(false)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 541 | EXPECT_FALSE(service_->Load(&storage)); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 544 | TEST_F(ServiceTest, LoadAutoConnect) { |
| 545 | NiceMock<MockStore> storage; |
| 546 | EXPECT_CALL(storage, ContainsGroup(storage_id_)) |
| 547 | .WillRepeatedly(Return(true)); |
| 548 | EXPECT_CALL(storage, GetBool(storage_id_, _, _)) |
| 549 | .WillRepeatedly(Return(false)); |
| 550 | EXPECT_CALL(storage, GetString(storage_id_, _, _)) |
| 551 | .WillRepeatedly(Return(false)); |
| 552 | EXPECT_CALL(storage, GetInt(storage_id_, _, _)) |
| 553 | .WillRepeatedly(Return(false)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 554 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 555 | EXPECT_CALL(*eap_, Load(&storage, storage_id_)).Times(AnyNumber()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 556 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 557 | |
| 558 | // Three of each expectation so we can test Favorite == unset, false, true. |
| 559 | EXPECT_CALL(storage, GetBool(storage_id_, Service::kStorageAutoConnect, _)) |
| 560 | .WillOnce(Return(false)) |
| 561 | .WillOnce(Return(false)) |
| 562 | .WillOnce(Return(false)) |
| 563 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 564 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 565 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 566 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))) |
| 567 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))) |
| 568 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 569 | EXPECT_CALL(storage, GetBool(storage_id_, Service::kStorageFavorite, _)) |
| 570 | .WillOnce(Return(false)) |
| 571 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 572 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))) |
| 573 | .WillOnce(Return(false)) |
| 574 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 575 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))) |
| 576 | .WillOnce(Return(false)) |
| 577 | .WillOnce(DoAll(SetArgumentPointee<2>(false), Return(true))) |
| 578 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 579 | |
| 580 | // AutoConnect is unset, Favorite is unset. |
| 581 | EXPECT_TRUE(service_->Load(&storage)); |
| 582 | EXPECT_FALSE(service_->auto_connect()); |
| 583 | EXPECT_FALSE(service_->retain_auto_connect()); |
| 584 | |
| 585 | // AutoConnect is unset, Favorite is false. |
| 586 | EXPECT_TRUE(service_->Load(&storage)); |
| 587 | EXPECT_FALSE(service_->auto_connect()); |
| 588 | EXPECT_FALSE(service_->retain_auto_connect()); |
| 589 | |
| 590 | // AutoConnect is unset, Favorite is true. |
| 591 | EXPECT_TRUE(service_->Load(&storage)); |
| 592 | EXPECT_FALSE(service_->auto_connect()); |
| 593 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 594 | |
| 595 | // AutoConnect is false, Favorite is unset. |
| 596 | EXPECT_TRUE(service_->Load(&storage)); |
| 597 | EXPECT_FALSE(service_->auto_connect()); |
| 598 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 599 | |
| 600 | // AutoConnect is false, Favorite is false. |
| 601 | EXPECT_TRUE(service_->Load(&storage)); |
| 602 | EXPECT_FALSE(service_->auto_connect()); |
| 603 | EXPECT_FALSE(service_->retain_auto_connect()); |
| 604 | |
| 605 | // AutoConnect is false, Favorite is true. |
| 606 | EXPECT_TRUE(service_->Load(&storage)); |
| 607 | EXPECT_FALSE(service_->auto_connect()); |
| 608 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 609 | |
| 610 | // AutoConnect is true, Favorite is unset. |
| 611 | EXPECT_TRUE(service_->Load(&storage)); |
| 612 | EXPECT_TRUE(service_->auto_connect()); |
| 613 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 614 | |
| 615 | // AutoConnect is true, Favorite is false (invalid case). |
| 616 | EXPECT_TRUE(service_->Load(&storage)); |
| 617 | EXPECT_TRUE(service_->auto_connect()); |
| 618 | EXPECT_FALSE(service_->retain_auto_connect()); |
| 619 | |
| 620 | // AutoConnect is true, Favorite is true. |
| 621 | EXPECT_TRUE(service_->Load(&storage)); |
| 622 | EXPECT_TRUE(service_->auto_connect()); |
| 623 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 624 | } |
| 625 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 626 | TEST_F(ServiceTest, SaveString) { |
| 627 | MockStore storage; |
| 628 | static const char kKey[] = "test-key"; |
| 629 | static const char kData[] = "test-data"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 630 | EXPECT_CALL(storage, SetString(storage_id_, kKey, kData)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 631 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 632 | service_->SaveString(&storage, storage_id_, kKey, kData, false, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | TEST_F(ServiceTest, SaveStringCrypted) { |
| 636 | MockStore storage; |
| 637 | static const char kKey[] = "test-key"; |
| 638 | static const char kData[] = "test-data"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 639 | EXPECT_CALL(storage, SetCryptedString(storage_id_, kKey, kData)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 640 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 641 | service_->SaveString(&storage, storage_id_, kKey, kData, true, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | TEST_F(ServiceTest, SaveStringDontSave) { |
| 645 | MockStore storage; |
| 646 | static const char kKey[] = "test-key"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 647 | EXPECT_CALL(storage, DeleteKey(storage_id_, kKey)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 648 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 649 | service_->SaveString(&storage, storage_id_, kKey, "data", false, false); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | TEST_F(ServiceTest, SaveStringEmpty) { |
| 653 | MockStore storage; |
| 654 | static const char kKey[] = "test-key"; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 655 | EXPECT_CALL(storage, DeleteKey(storage_id_, kKey)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 656 | .WillOnce(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 657 | service_->SaveString(&storage, storage_id_, kKey, "", true, true); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | TEST_F(ServiceTest, Save) { |
| 661 | NiceMock<MockStore> storage; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 662 | EXPECT_CALL(storage, SetString(storage_id_, _, _)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 663 | .Times(AtLeast(1)) |
| 664 | .WillRepeatedly(Return(true)); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 665 | EXPECT_CALL(storage, DeleteKey(storage_id_, _)) |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 666 | .Times(AtLeast(1)) |
| 667 | .WillRepeatedly(Return(true)); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 668 | EXPECT_CALL(storage, DeleteKey(storage_id_, Service::kStorageFavorite)) |
| 669 | .WillOnce(Return(true)); |
| 670 | EXPECT_CALL(storage, DeleteKey(storage_id_, Service::kStorageAutoConnect)) |
| 671 | .WillOnce(Return(true)); |
Darin Petkov | 0debec0 | 2013-01-22 10:40:05 +0100 | [diff] [blame] | 672 | EXPECT_CALL(storage, SetBool(storage_id_, _, _)).Times(AnyNumber()); |
| 673 | EXPECT_CALL(storage, |
| 674 | SetBool(storage_id_, |
| 675 | Service::kStorageSaveCredentials, |
| 676 | service_->save_credentials())); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 677 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 678 | EXPECT_CALL(*eap_, Save(&storage, storage_id_, true)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 679 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 680 | EXPECT_TRUE(service_->Save(&storage)); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 683 | TEST_F(ServiceTest, RetainAutoConnect) { |
| 684 | NiceMock<MockStore> storage; |
| 685 | EXPECT_CALL(storage, SetString(storage_id_, _, _)) |
| 686 | .Times(AtLeast(1)) |
| 687 | .WillRepeatedly(Return(true)); |
| 688 | EXPECT_CALL(storage, DeleteKey(storage_id_, _)) |
| 689 | .Times(AtLeast(1)) |
| 690 | .WillRepeatedly(Return(true)); |
| 691 | EXPECT_CALL(storage, DeleteKey(storage_id_, Service::kStorageFavorite)) |
| 692 | .Times(2); |
| 693 | EXPECT_CALL(storage, DeleteKey(storage_id_, Service::kStorageAutoConnect)) |
| 694 | .Times(0); |
| 695 | EXPECT_CALL(storage, SetBool(storage_id_, _, _)).Times(AnyNumber()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 696 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 697 | EXPECT_CALL(*eap_, Save(&storage, storage_id_, true)).Times(2); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 698 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 699 | |
| 700 | // AutoConnect flag set true. |
| 701 | service_->EnableAndRetainAutoConnect(); |
| 702 | EXPECT_CALL(storage, |
| 703 | SetBool(storage_id_, Service::kStorageAutoConnect, true)); |
| 704 | EXPECT_TRUE(service_->Save(&storage)); |
| 705 | |
| 706 | // AutoConnect flag set false. |
| 707 | EXPECT_CALL(storage, |
| 708 | SetBool(storage_id_, Service::kStorageAutoConnect, false)); |
| 709 | service_->SetAutoConnect(false); |
| 710 | EXPECT_TRUE(service_->Save(&storage)); |
| 711 | } |
| 712 | |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 713 | TEST_F(ServiceTest, HasEverConnectedSavedToProfile) { |
| 714 | NiceMock<MockStore> storage; |
| 715 | EXPECT_CALL(storage, SetString(storage_id_, _, _)) |
| 716 | .Times(AtLeast(1)) |
| 717 | .WillRepeatedly(Return(true)); |
| 718 | EXPECT_CALL(storage, DeleteKey(storage_id_, _)) |
| 719 | .Times(AtLeast(1)) |
| 720 | .WillRepeatedly(Return(true)); |
| 721 | EXPECT_CALL(storage, |
| 722 | DeleteKey(storage_id_, Service::kStorageHasEverConnected)) |
| 723 | .Times(0); |
| 724 | EXPECT_CALL(storage, SetBool(storage_id_, _, _)).Times(AnyNumber()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 725 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 726 | EXPECT_CALL(*eap_, Save(&storage, storage_id_, true)).Times(2); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 727 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 728 | |
| 729 | // HasEverConnected flag set true. |
| 730 | service_->SetHasEverConnected(true); |
| 731 | EXPECT_CALL(storage, |
| 732 | SetBool(storage_id_, Service::kStorageHasEverConnected, true)); |
| 733 | EXPECT_TRUE(service_->Save(&storage)); |
| 734 | |
| 735 | // HasEverConnected flag set false. |
| 736 | EXPECT_CALL(storage, |
| 737 | SetBool(storage_id_, Service::kStorageHasEverConnected, false)); |
| 738 | service_->SetHasEverConnected(false); |
| 739 | EXPECT_TRUE(service_->Save(&storage)); |
| 740 | } |
| 741 | |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 742 | TEST_F(ServiceTest, Unload) { |
| 743 | NiceMock<MockStore> storage; |
| 744 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
| 745 | static const string string_value("value"); |
| 746 | EXPECT_CALL(storage, GetString(storage_id_, _, _)) |
| 747 | .Times(AtLeast(1)) |
| 748 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(string_value), Return(true))); |
Paul Stewart | 88769de | 2012-09-21 13:14:36 -0700 | [diff] [blame] | 749 | EXPECT_CALL(storage, GetBool(storage_id_, _, _)) |
| 750 | .Times(AtLeast(1)) |
| 751 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 752 | EXPECT_FALSE(service_->explicitly_disconnected_); |
| 753 | service_->explicitly_disconnected_ = true; |
| 754 | EXPECT_FALSE(service_->has_ever_connected_); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 755 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 756 | EXPECT_CALL(*eap_, Load(&storage, storage_id_)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 757 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 758 | ASSERT_TRUE(service_->Load(&storage)); |
Paul Stewart | e7cce8f | 2012-09-11 10:56:38 -0700 | [diff] [blame] | 759 | // TODO(pstew): Only two string properties in the service are tested as |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 760 | // a sentinel that properties are being set and reset at the right times. |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 761 | // However, since property load/store is essentially a manual process, |
| 762 | // it is error prone and should either be exhaustively unit-tested or |
| 763 | // a generic framework for registering loaded/stored properties should |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 764 | // be created. crbug.com/207798 |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 765 | EXPECT_EQ(string_value, service_->ui_data_); |
Paul Stewart | e7cce8f | 2012-09-11 10:56:38 -0700 | [diff] [blame] | 766 | EXPECT_EQ(string_value, service_->guid_); |
Paul Stewart | 88769de | 2012-09-21 13:14:36 -0700 | [diff] [blame] | 767 | EXPECT_FALSE(service_->explicitly_disconnected_); |
| 768 | EXPECT_TRUE(service_->has_ever_connected_); |
| 769 | service_->explicitly_disconnected_ = true; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 770 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 771 | EXPECT_CALL(*eap_, Reset()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 772 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 773 | service_->Unload(); |
| 774 | EXPECT_EQ(string(""), service_->ui_data_); |
Paul Stewart | e7cce8f | 2012-09-11 10:56:38 -0700 | [diff] [blame] | 775 | EXPECT_EQ(string(""), service_->guid_); |
Philipp Neubeck | f883a7b | 2012-09-14 19:52:44 +0200 | [diff] [blame] | 776 | EXPECT_FALSE(service_->explicitly_disconnected_); |
Paul Stewart | 88769de | 2012-09-21 13:14:36 -0700 | [diff] [blame] | 777 | EXPECT_FALSE(service_->has_ever_connected_); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 780 | TEST_F(ServiceTest, State) { |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 781 | EXPECT_EQ(Service::kStateIdle, service_->state()); |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 782 | EXPECT_EQ(Service::kStateIdle, GetPreviousState()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 783 | EXPECT_EQ(Service::kFailureUnknown, service_->failure()); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 784 | const string unknown_error( |
| 785 | Service::ConnectFailureToString(Service::kFailureUnknown)); |
| 786 | EXPECT_EQ(unknown_error, service_->error()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 787 | |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 788 | EXPECT_CALL(*GetAdaptor(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 789 | EmitStringChanged(kStateProperty, _)).Times(6); |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 790 | EXPECT_CALL(*GetAdaptor(), |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 791 | EmitStringChanged(kErrorProperty, _)).Times(4); |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 792 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 793 | service_->SetState(Service::kStateConnected); |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 794 | EXPECT_EQ(Service::kStateIdle, GetPreviousState()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 795 | // A second state change shouldn't cause another update |
| 796 | service_->SetState(Service::kStateConnected); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 797 | EXPECT_EQ(Service::kStateConnected, service_->state()); |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 798 | EXPECT_EQ(Service::kStateIdle, GetPreviousState()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 799 | EXPECT_EQ(Service::kFailureUnknown, service_->failure()); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 800 | EXPECT_TRUE(service_->has_ever_connected_); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 801 | |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 802 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 803 | service_->SetFailure(Service::kFailureOutOfRange); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 804 | EXPECT_TRUE(service_->IsFailed()); |
| 805 | EXPECT_GT(service_->failed_time_, 0); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 806 | EXPECT_GT(service_->previous_error_serial_number_, 0); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 807 | EXPECT_EQ(Service::kStateFailure, service_->state()); |
| 808 | EXPECT_EQ(Service::kFailureOutOfRange, service_->failure()); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 809 | const string out_of_range_error( |
| 810 | Service::ConnectFailureToString(Service::kFailureOutOfRange)); |
| 811 | EXPECT_EQ(out_of_range_error, service_->error()); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 812 | EXPECT_EQ(out_of_range_error, service_->previous_error_); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 813 | |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 814 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 815 | service_->SetState(Service::kStateConnected); |
| 816 | EXPECT_FALSE(service_->IsFailed()); |
| 817 | EXPECT_EQ(service_->failed_time_, 0); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 818 | EXPECT_EQ(unknown_error, service_->error()); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 819 | EXPECT_EQ(out_of_range_error, service_->previous_error_); |
| 820 | EXPECT_GT(service_->previous_error_serial_number_, 0); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 821 | |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 822 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 823 | service_->SetFailureSilent(Service::kFailurePinMissing); |
| 824 | EXPECT_TRUE(service_->IsFailed()); |
| 825 | EXPECT_GT(service_->failed_time_, 0); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 826 | EXPECT_GT(service_->previous_error_serial_number_, 0); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 827 | EXPECT_EQ(Service::kStateIdle, service_->state()); |
| 828 | EXPECT_EQ(Service::kFailurePinMissing, service_->failure()); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 829 | const string pin_missing_error( |
| 830 | Service::ConnectFailureToString(Service::kFailurePinMissing)); |
| 831 | EXPECT_EQ(pin_missing_error, service_->error()); |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 832 | EXPECT_EQ(pin_missing_error, service_->previous_error_); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 833 | |
| 834 | // If the Service has a Profile, the profile should be saved when |
| 835 | // the service enters kStateConnected. (The case where the service |
| 836 | // doesn't have a profile is tested above.) |
| 837 | MockProfileRefPtr mock_profile( |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 838 | new MockProfile(control_interface(), metrics(), &mock_manager_)); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 839 | NiceMock<MockStore> storage; |
| 840 | service_->set_profile(mock_profile); |
| 841 | service_->has_ever_connected_ = false; |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 842 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 843 | EXPECT_CALL(*mock_profile, GetConstStorage()) |
| 844 | .WillOnce(Return(&storage)); |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 845 | EXPECT_CALL(*mock_profile, UpdateService(IsRefPtrTo(service_))); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 846 | service_->SetState(Service::kStateConnected); |
| 847 | EXPECT_TRUE(service_->has_ever_connected_); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 848 | service_->set_profile(nullptr); // Break reference cycle. |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 849 | |
| 850 | // Similar to the above, but emulate an emphemeral profile, which |
| 851 | // has no storage. We can't update the service in the profile, but |
| 852 | // we should not crash. |
| 853 | service_->state_ = Service::kStateIdle; // Skips state change logic. |
| 854 | service_->set_profile(mock_profile); |
| 855 | service_->has_ever_connected_ = false; |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 856 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 857 | EXPECT_CALL(*mock_profile, GetConstStorage()).WillOnce(Return(nullptr)); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 858 | service_->SetState(Service::kStateConnected); |
| 859 | EXPECT_TRUE(service_->has_ever_connected_); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 860 | service_->set_profile(nullptr); // Break reference cycle. |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Peter Qiu | 9b83c89 | 2014-08-09 23:06:02 -0700 | [diff] [blame] | 863 | TEST_F(ServiceTest, PortalDetectionFailure) { |
| 864 | EXPECT_CALL(*GetAdaptor(), |
| 865 | EmitStringChanged(kPortalDetectionFailedPhaseProperty, |
| 866 | kPortalDetectionPhaseDns)).Times(1); |
| 867 | EXPECT_CALL(*GetAdaptor(), |
| 868 | EmitStringChanged(kPortalDetectionFailedStatusProperty, |
| 869 | kPortalDetectionStatusTimeout)).Times(1); |
| 870 | service_->SetPortalDetectionFailure(kPortalDetectionPhaseDns, |
| 871 | kPortalDetectionStatusTimeout); |
| 872 | EXPECT_EQ(kPortalDetectionPhaseDns, |
| 873 | service_->portal_detection_failure_phase_); |
| 874 | EXPECT_EQ(kPortalDetectionStatusTimeout, |
| 875 | service_->portal_detection_failure_status_); |
| 876 | } |
| 877 | |
Thieu Le | af47141 | 2013-06-27 14:12:37 -0700 | [diff] [blame] | 878 | TEST_F(ServiceTest, StateResetAfterFailure) { |
| 879 | service_->SetFailure(Service::kFailureOutOfRange); |
| 880 | EXPECT_EQ(Service::kStateFailure, service_->state()); |
| 881 | Error error; |
| 882 | service_->Connect(&error, "in test"); |
| 883 | EXPECT_EQ(Service::kStateIdle, service_->state()); |
| 884 | EXPECT_EQ(Service::kFailureUnknown, service_->failure()); |
| 885 | |
| 886 | service_->SetState(Service::kStateConnected); |
| 887 | service_->Connect(&error, "in test"); |
| 888 | EXPECT_EQ(Service::kStateConnected, service_->state()); |
| 889 | } |
| 890 | |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 891 | TEST_F(ServiceTest, UserInitiatedConnectionResult) { |
| 892 | service_->technology_ = Technology::kWifi; |
| 893 | Error error; |
| 894 | // User-initiated connection attempt succeed. |
| 895 | service_->SetState(Service::kStateIdle); |
| 896 | service_->UserInitiatedConnect(&error); |
| 897 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult( |
| 898 | Metrics::kMetricWifiUserInitiatedConnectionResult, |
| 899 | Metrics::kUserInitiatedConnectionResultSuccess)); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 900 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason(_, _)) |
| 901 | .Times(0); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 902 | service_->SetState(Service::kStateConnected); |
| 903 | Mock::VerifyAndClearExpectations(metrics()); |
| 904 | |
| 905 | // User-initiated connection attempt failed. |
| 906 | service_->SetState(Service::kStateIdle); |
| 907 | service_->UserInitiatedConnect(&error); |
| 908 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult( |
| 909 | Metrics::kMetricWifiUserInitiatedConnectionResult, |
| 910 | Metrics::kUserInitiatedConnectionResultFailure)); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 911 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason( |
| 912 | Metrics::kMetricWifiUserInitiatedConnectionFailureReason, |
| 913 | Service::kFailureDHCP)); |
| 914 | service_->SetFailure(Service::kFailureDHCP); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 915 | Mock::VerifyAndClearExpectations(metrics()); |
| 916 | |
| 917 | // User-initiated connection attempt aborted. |
| 918 | service_->SetState(Service::kStateIdle); |
| 919 | service_->UserInitiatedConnect(&error); |
| 920 | service_->SetState(Service::kStateAssociating); |
| 921 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult( |
| 922 | Metrics::kMetricWifiUserInitiatedConnectionResult, |
| 923 | Metrics::kUserInitiatedConnectionResultAborted)); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 924 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason(_, _)) |
| 925 | .Times(0); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 926 | service_->SetState(Service::kStateIdle); |
| 927 | Mock::VerifyAndClearExpectations(metrics()); |
| 928 | |
| 929 | // No metric reporting for other state transition. |
| 930 | service_->SetState(Service::kStateIdle); |
| 931 | service_->UserInitiatedConnect(&error); |
| 932 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult(_, _)).Times(0); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 933 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason(_, _)) |
| 934 | .Times(0); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 935 | service_->SetState(Service::kStateAssociating); |
| 936 | service_->SetState(Service::kStateConfiguring); |
| 937 | Mock::VerifyAndClearExpectations(metrics()); |
| 938 | |
| 939 | // No metric reporting for non-user-initiated connection. |
| 940 | service_->SetState(Service::kStateIdle); |
| 941 | service_->Connect(&error, "in test"); |
| 942 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult(_, _)).Times(0); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 943 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason(_, _)) |
| 944 | .Times(0); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 945 | service_->SetState(Service::kStateConnected); |
| 946 | Mock::VerifyAndClearExpectations(metrics()); |
| 947 | |
| 948 | // No metric reporting for other technology. |
| 949 | service_->technology_ = Technology::kCellular; |
| 950 | service_->SetState(Service::kStateIdle); |
| 951 | service_->UserInitiatedConnect(&error); |
| 952 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionResult(_, _)).Times(0); |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 953 | EXPECT_CALL(*metrics(), NotifyUserInitiatedConnectionFailureReason(_, _)) |
| 954 | .Times(0); |
| 955 | service_->SetFailure(Service::kFailureDHCP); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 956 | Mock::VerifyAndClearExpectations(metrics()); |
| 957 | } |
| 958 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 959 | TEST_F(ServiceTest, ActivateCellularModem) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 960 | ResultCallback callback = |
| 961 | Bind(&ServiceTest::TestCallback, Unretained(this)); |
| 962 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 963 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 964 | service_->ActivateCellularModem("Carrier", &error, callback); |
| 965 | EXPECT_TRUE(error.IsFailure()); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Ben Chan | 5d92454 | 2013-02-14 17:49:08 -0800 | [diff] [blame] | 968 | TEST_F(ServiceTest, CompleteCellularActivation) { |
| 969 | Error error; |
| 970 | service_->CompleteCellularActivation(&error); |
| 971 | EXPECT_EQ(Error::kNotSupported, error.type()); |
| 972 | } |
| 973 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 974 | TEST_F(ServiceTest, EnableAndRetainAutoConnect) { |
| 975 | EXPECT_FALSE(service_->retain_auto_connect()); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 976 | EXPECT_FALSE(service_->auto_connect()); |
| 977 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 978 | service_->EnableAndRetainAutoConnect(); |
| 979 | EXPECT_TRUE(service_->retain_auto_connect()); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 980 | EXPECT_TRUE(service_->auto_connect()); |
| 981 | } |
| 982 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 983 | TEST_F(ServiceTest, ReRetainAutoConnect) { |
| 984 | service_->EnableAndRetainAutoConnect(); |
| 985 | EXPECT_TRUE(service_->retain_auto_connect()); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 986 | EXPECT_TRUE(service_->auto_connect()); |
| 987 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 988 | service_->SetAutoConnect(false); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 989 | service_->EnableAndRetainAutoConnect(); |
| 990 | EXPECT_TRUE(service_->retain_auto_connect()); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 991 | EXPECT_FALSE(service_->auto_connect()); |
| 992 | } |
| 993 | |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 994 | TEST_F(ServiceTest, IsAutoConnectable) { |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 995 | const char* reason = nullptr; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 996 | service_->SetConnectable(true); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 997 | |
| 998 | // Services with non-primary connectivity technologies should not auto-connect |
| 999 | // when the system is offline. |
| 1000 | EXPECT_EQ(Technology::kUnknown, service_->technology()); |
Peter Qiu | 700de64 | 2014-07-14 16:31:30 -0700 | [diff] [blame] | 1001 | EXPECT_CALL(mock_manager_, IsConnected()).WillOnce(Return(false)); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 1002 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1003 | EXPECT_STREQ(Service::kAutoConnOffline, reason); |
| 1004 | |
| 1005 | service_->technology_ = Technology::kEthernet; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1006 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 1007 | |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1008 | // We should not auto-connect to a Service that a user has |
| 1009 | // deliberately disconnected. |
| 1010 | Error error; |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 1011 | service_->UserInitiatedDisconnect(&error); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1012 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1013 | EXPECT_STREQ(Service::kAutoConnExplicitDisconnect, reason); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1014 | |
| 1015 | // But if the Service is reloaded, it is eligible for auto-connect |
| 1016 | // again. |
| 1017 | NiceMock<MockStore> storage; |
| 1018 | EXPECT_CALL(storage, ContainsGroup(storage_id_)).WillOnce(Return(true)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1019 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1020 | EXPECT_CALL(*eap_, Load(&storage, storage_id_)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1021 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1022 | EXPECT_TRUE(service_->Load(&storage)); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1023 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1024 | |
| 1025 | // A deliberate Connect should also re-enable auto-connect. |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 1026 | service_->UserInitiatedDisconnect(&error); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1027 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 1028 | service_->Connect(&error, "in test"); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1029 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1030 | |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 1031 | // A non-user initiated Disconnect doesn't change anything. |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 1032 | service_->Disconnect(&error, "in test"); |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 1033 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1034 | |
Christopher Wiley | a4c61ae | 2012-10-01 11:04:30 -0700 | [diff] [blame] | 1035 | // A resume also re-enables auto-connect. |
| 1036 | service_->UserInitiatedDisconnect(&error); |
| 1037 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1038 | service_->OnAfterResume(); |
| 1039 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 1040 | |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 1041 | service_->SetState(Service::kStateConnected); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1042 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1043 | EXPECT_STREQ(Service::kAutoConnConnected, reason); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 1044 | |
| 1045 | service_->SetState(Service::kStateAssociating); |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1046 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1047 | EXPECT_STREQ(Service::kAutoConnConnecting, reason); |
Ben Chan | 8e6b8ef | 2014-07-14 21:50:18 -0700 | [diff] [blame] | 1048 | |
| 1049 | service_->SetState(Service::kStateIdle); |
| 1050 | EXPECT_CALL(mock_manager_, IsTechnologyAutoConnectDisabled( |
| 1051 | service_->technology_)).WillOnce(Return(true)); |
| 1052 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1053 | EXPECT_STREQ(Service::kAutoConnTechnologyNotConnectable, reason); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 1056 | TEST_F(ServiceTest, AutoConnectLogging) { |
| 1057 | ScopedMockLog log; |
| 1058 | EXPECT_CALL(log, Log(_, _, _)); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1059 | service_->SetConnectable(true); |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 1060 | |
| 1061 | ScopeLogger::GetInstance()->EnableScopesByName("+service"); |
| 1062 | ScopeLogger::GetInstance()->set_verbose_level(1); |
| 1063 | service_->SetState(Service::kStateConnected); |
| 1064 | EXPECT_CALL(log, Log(-1, _, HasSubstr(Service::kAutoConnConnected))); |
| 1065 | service_->AutoConnect(); |
| 1066 | |
| 1067 | ScopeLogger::GetInstance()->EnableScopesByName("-service"); |
| 1068 | ScopeLogger::GetInstance()->set_verbose_level(0); |
| 1069 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
| 1070 | HasSubstr(Service::kAutoConnNotConnectable))); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1071 | service_->SetConnectable(false); |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 1072 | service_->AutoConnect(); |
| 1073 | } |
| 1074 | |
| 1075 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1076 | TEST_F(AllMockServiceTest, AutoConnectWithFailures) { |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1077 | const char* reason; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1078 | service_->SetConnectable(true); |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 1079 | service_->technology_ = Technology::kEthernet; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1080 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1081 | |
| 1082 | // The very first AutoConnect() doesn't trigger any throttling. |
| 1083 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, _)).Times(0); |
| 1084 | service_->AutoConnect(); |
| 1085 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1086 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1087 | |
| 1088 | // The second call does trigger some throttling. |
| 1089 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, |
| 1090 | Service::kMinAutoConnectCooldownTimeMilliseconds)); |
| 1091 | service_->AutoConnect(); |
| 1092 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1093 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1094 | EXPECT_STREQ(Service::kAutoConnThrottled, reason); |
| 1095 | |
| 1096 | // Calling AutoConnect() again before the cooldown terminates does not change |
| 1097 | // the timeout. |
| 1098 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, _)).Times(0); |
| 1099 | service_->AutoConnect(); |
| 1100 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1101 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1102 | EXPECT_STREQ(Service::kAutoConnThrottled, reason); |
| 1103 | |
| 1104 | // Once the timeout expires, we can AutoConnect() again. |
| 1105 | service_->ReEnableAutoConnectTask(); |
| 1106 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1107 | |
| 1108 | // Timeouts increase exponentially. |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1109 | uint64_t next_cooldown_time = service_->auto_connect_cooldown_milliseconds_; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1110 | EXPECT_EQ(next_cooldown_time, |
| 1111 | Service::kAutoConnectCooldownBackoffFactor * |
| 1112 | Service::kMinAutoConnectCooldownTimeMilliseconds); |
| 1113 | while (next_cooldown_time <= |
| 1114 | Service::kMaxAutoConnectCooldownTimeMilliseconds) { |
| 1115 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, next_cooldown_time)); |
| 1116 | service_->AutoConnect(); |
| 1117 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1118 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1119 | EXPECT_STREQ(Service::kAutoConnThrottled, reason); |
| 1120 | service_->ReEnableAutoConnectTask(); |
| 1121 | next_cooldown_time *= Service::kAutoConnectCooldownBackoffFactor; |
| 1122 | } |
| 1123 | |
| 1124 | // Once we hit our cap, future timeouts are the same. |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1125 | for (int32_t i = 0; i < 2; i++) { |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1126 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, |
| 1127 | Service::kMaxAutoConnectCooldownTimeMilliseconds)); |
| 1128 | service_->AutoConnect(); |
| 1129 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1130 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1131 | EXPECT_STREQ(Service::kAutoConnThrottled, reason); |
| 1132 | service_->ReEnableAutoConnectTask(); |
| 1133 | } |
| 1134 | |
| 1135 | // Connecting successfully resets our cooldown. |
| 1136 | service_->SetState(Service::kStateConnected); |
| 1137 | service_->SetState(Service::kStateIdle); |
| 1138 | reason = ""; |
| 1139 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1140 | EXPECT_STREQ("", reason); |
| 1141 | EXPECT_EQ(service_->auto_connect_cooldown_milliseconds_, 0); |
| 1142 | |
| 1143 | // But future AutoConnects behave as before |
| 1144 | EXPECT_CALL(dispatcher_, PostDelayedTask(_, |
| 1145 | Service::kMinAutoConnectCooldownTimeMilliseconds)).Times(1); |
| 1146 | service_->AutoConnect(); |
| 1147 | service_->AutoConnect(); |
| 1148 | Mock::VerifyAndClearExpectations(&dispatcher_); |
| 1149 | EXPECT_FALSE(service_->IsAutoConnectable(&reason)); |
| 1150 | EXPECT_STREQ(Service::kAutoConnThrottled, reason); |
| 1151 | |
| 1152 | // Cooldowns are forgotten if we go through a suspend/resume cycle. |
| 1153 | service_->OnAfterResume(); |
| 1154 | reason = ""; |
| 1155 | EXPECT_TRUE(service_->IsAutoConnectable(&reason)); |
| 1156 | EXPECT_STREQ("", reason); |
| 1157 | } |
| 1158 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1159 | TEST_F(ServiceTest, ConfigureBadProperty) { |
| 1160 | KeyValueStore args; |
| 1161 | args.SetString("XXXInvalid", "Value"); |
| 1162 | Error error; |
| 1163 | service_->Configure(args, &error); |
| 1164 | EXPECT_FALSE(error.IsSuccess()); |
| 1165 | } |
| 1166 | |
| 1167 | TEST_F(ServiceTest, ConfigureBoolProperty) { |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1168 | service_->EnableAndRetainAutoConnect(); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1169 | service_->SetAutoConnect(false); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1170 | ASSERT_FALSE(service_->auto_connect()); |
| 1171 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1172 | args.SetBool(kAutoConnectProperty, true); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1173 | Error error; |
| 1174 | service_->Configure(args, &error); |
| 1175 | EXPECT_TRUE(error.IsSuccess()); |
| 1176 | EXPECT_TRUE(service_->auto_connect()); |
| 1177 | } |
| 1178 | |
| 1179 | TEST_F(ServiceTest, ConfigureStringProperty) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1180 | const string kGuid0 = "guid_zero"; |
| 1181 | const string kGuid1 = "guid_one"; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1182 | service_->SetGuid(kGuid0, nullptr); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1183 | ASSERT_EQ(kGuid0, service_->guid()); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1184 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1185 | args.SetString(kGuidProperty, kGuid1); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1186 | Error error; |
| 1187 | service_->Configure(args, &error); |
| 1188 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1189 | EXPECT_EQ(kGuid1, service_->guid()); |
| 1190 | } |
| 1191 | |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1192 | TEST_F(ServiceTest, ConfigureStringsProperty) { |
| 1193 | const vector<string> kStrings0{ "string0", "string1" }; |
| 1194 | const vector<string> kStrings1{ "string2", "string3" }; |
| 1195 | service_->set_strings(kStrings0); |
| 1196 | ASSERT_EQ(kStrings0, service_->strings()); |
| 1197 | KeyValueStore args; |
| 1198 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings1); |
| 1199 | Error error; |
| 1200 | service_->Configure(args, &error); |
| 1201 | EXPECT_TRUE(error.IsSuccess()); |
| 1202 | EXPECT_EQ(kStrings1, service_->strings()); |
| 1203 | } |
| 1204 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1205 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1206 | TEST_F(ServiceTest, ConfigureEapStringProperty) { |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1207 | MockEapCredentials* eap = new MockEapCredentials(); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1208 | service2_->SetEapCredentials(eap); // Passes ownership. |
| 1209 | |
| 1210 | const string kEAPManagement0 = "management_zero"; |
| 1211 | const string kEAPManagement1 = "management_one"; |
| 1212 | service2_->SetEAPKeyManagement(kEAPManagement0); |
| 1213 | |
| 1214 | EXPECT_CALL(*eap, key_management()) |
| 1215 | .WillOnce(ReturnRef(kEAPManagement0)); |
| 1216 | ASSERT_EQ(kEAPManagement0, service2_->GetEAPKeyManagement()); |
| 1217 | KeyValueStore args; |
| 1218 | EXPECT_CALL(*eap, SetKeyManagement(kEAPManagement1, _)); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1219 | args.SetString(kEapKeyMgmtProperty, kEAPManagement1); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1220 | Error error; |
| 1221 | service2_->Configure(args, &error); |
| 1222 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1223 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1224 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1225 | |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1226 | TEST_F(ServiceTest, ConfigureIntProperty) { |
| 1227 | const int kPriority0 = 100; |
| 1228 | const int kPriority1 = 200; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1229 | service_->SetPriority(kPriority0, nullptr); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1230 | ASSERT_EQ(kPriority0, service_->priority()); |
| 1231 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1232 | args.SetInt(kPriorityProperty, kPriority1); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1233 | Error error; |
| 1234 | service_->Configure(args, &error); |
| 1235 | EXPECT_TRUE(error.IsSuccess()); |
| 1236 | EXPECT_EQ(kPriority1, service_->priority()); |
| 1237 | } |
| 1238 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1239 | TEST_F(ServiceTest, ConfigureIgnoredProperty) { |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1240 | service_->EnableAndRetainAutoConnect(); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1241 | service_->SetAutoConnect(false); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1242 | ASSERT_FALSE(service_->auto_connect()); |
| 1243 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1244 | args.SetBool(kAutoConnectProperty, true); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1245 | Error error; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1246 | service_->IgnoreParameterForConfigure(kAutoConnectProperty); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1247 | service_->Configure(args, &error); |
| 1248 | EXPECT_TRUE(error.IsSuccess()); |
| 1249 | EXPECT_FALSE(service_->auto_connect()); |
| 1250 | } |
| 1251 | |
Paul Stewart | ad0e598 | 2013-07-02 08:47:47 -0700 | [diff] [blame] | 1252 | TEST_F(ServiceTest, ConfigureProfileProperty) { |
| 1253 | // Ensure that the Profile property is always ignored. |
| 1254 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1255 | args.SetString(kProfileProperty, "profile"); |
Paul Stewart | ad0e598 | 2013-07-02 08:47:47 -0700 | [diff] [blame] | 1256 | Error error; |
| 1257 | EXPECT_CALL(mock_manager_, SetProfileForService(_, _, _)).Times(0); |
| 1258 | service_->Configure(args, &error); |
| 1259 | EXPECT_TRUE(error.IsSuccess()); |
| 1260 | } |
| 1261 | |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1262 | TEST_F(ServiceTest, ConfigureKeyValueStoreProperty) { |
| 1263 | KeyValueStore key_value_store0; |
| 1264 | key_value_store0.SetBool("key0", true); |
| 1265 | KeyValueStore key_value_store1; |
| 1266 | key_value_store1.SetInt("key1", 1); |
| 1267 | service_->SetKeyValueStore(key_value_store0, NULL); |
| 1268 | ASSERT_TRUE(key_value_store0.Equals(service_->GetKeyValueStore(NULL))); |
| 1269 | KeyValueStore args; |
| 1270 | args.SetKeyValueStore( |
| 1271 | ServiceUnderTest::kKeyValueStoreProperty, key_value_store1); |
| 1272 | Error error; |
| 1273 | service_->Configure(args, &error); |
| 1274 | EXPECT_TRUE(error.IsSuccess()); |
| 1275 | EXPECT_TRUE(key_value_store1.Equals(service_->GetKeyValueStore(NULL))); |
| 1276 | } |
| 1277 | |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1278 | TEST_F(ServiceTest, DoPropertiesMatch) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1279 | service_->SetAutoConnect(false); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1280 | const string kGUID0 = "guid_zero"; |
| 1281 | const string kGUID1 = "guid_one"; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1282 | service_->SetGuid(kGUID0, nullptr); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1283 | const uint32_t kPriority0 = 100; |
| 1284 | const uint32_t kPriority1 = 200; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1285 | service_->SetPriority(kPriority0, nullptr); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1286 | const vector<string> kStrings0{ "string0", "string1" }; |
| 1287 | const vector<string> kStrings1{ "string2", "string3" }; |
| 1288 | service_->set_strings(kStrings0); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1289 | KeyValueStore key_value_store0; |
| 1290 | key_value_store0.SetBool("key0", true); |
| 1291 | KeyValueStore key_value_store1; |
| 1292 | key_value_store1.SetInt("key1", 1); |
| 1293 | service_->SetKeyValueStore(key_value_store0, NULL); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1294 | |
| 1295 | { |
| 1296 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1297 | args.SetString(kGuidProperty, kGUID0); |
| 1298 | args.SetBool(kAutoConnectProperty, false); |
| 1299 | args.SetInt(kPriorityProperty, kPriority0); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1300 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings0); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1301 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1302 | key_value_store0); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1303 | EXPECT_TRUE(service_->DoPropertiesMatch(args)); |
| 1304 | } |
| 1305 | { |
| 1306 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1307 | args.SetString(kGuidProperty, kGUID1); |
| 1308 | args.SetBool(kAutoConnectProperty, false); |
| 1309 | args.SetInt(kPriorityProperty, kPriority0); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1310 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings0); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1311 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1312 | key_value_store0); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1313 | EXPECT_FALSE(service_->DoPropertiesMatch(args)); |
| 1314 | } |
| 1315 | { |
| 1316 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1317 | args.SetString(kGuidProperty, kGUID0); |
| 1318 | args.SetBool(kAutoConnectProperty, true); |
| 1319 | args.SetInt(kPriorityProperty, kPriority0); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1320 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings0); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1321 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1322 | key_value_store0); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1323 | EXPECT_FALSE(service_->DoPropertiesMatch(args)); |
| 1324 | } |
| 1325 | { |
| 1326 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1327 | args.SetString(kGuidProperty, kGUID0); |
| 1328 | args.SetBool(kAutoConnectProperty, false); |
| 1329 | args.SetInt(kPriorityProperty, kPriority1); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1330 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings0); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1331 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1332 | key_value_store0); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1333 | EXPECT_FALSE(service_->DoPropertiesMatch(args)); |
| 1334 | } |
| 1335 | { |
| 1336 | KeyValueStore args; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1337 | args.SetString(kGuidProperty, kGUID0); |
| 1338 | args.SetBool(kAutoConnectProperty, false); |
| 1339 | args.SetInt(kPriorityProperty, kPriority0); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 1340 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings1); |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 1341 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1342 | key_value_store0); |
| 1343 | EXPECT_FALSE(service_->DoPropertiesMatch(args)); |
| 1344 | } |
| 1345 | { |
| 1346 | KeyValueStore args; |
| 1347 | args.SetString(kGuidProperty, kGUID0); |
| 1348 | args.SetBool(kAutoConnectProperty, false); |
| 1349 | args.SetInt(kPriorityProperty, kPriority0); |
| 1350 | args.SetStrings(ServiceUnderTest::kStringsProperty, kStrings0); |
| 1351 | args.SetKeyValueStore(ServiceUnderTest::kKeyValueStoreProperty, |
| 1352 | key_value_store1); |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 1353 | EXPECT_FALSE(service_->DoPropertiesMatch(args)); |
| 1354 | } |
| 1355 | } |
| 1356 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1357 | TEST_F(ServiceTest, IsRemembered) { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1358 | service_->set_profile(nullptr); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1359 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(_)).Times(0); |
| 1360 | EXPECT_FALSE(service_->IsRemembered()); |
| 1361 | |
| 1362 | scoped_refptr<MockProfile> profile( |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 1363 | new StrictMock<MockProfile>(control_interface(), metrics(), manager())); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1364 | service_->set_profile(profile); |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 1365 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(IsRefPtrTo(service_))) |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1366 | .WillOnce(Return(true)) |
| 1367 | .WillOnce(Return(false)); |
| 1368 | EXPECT_FALSE(service_->IsRemembered()); |
| 1369 | EXPECT_TRUE(service_->IsRemembered()); |
| 1370 | } |
| 1371 | |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1372 | TEST_F(ServiceTest, IsDependentOn) { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1373 | EXPECT_FALSE(service_->IsDependentOn(nullptr)); |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1374 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 1375 | std::unique_ptr<MockDeviceInfo> mock_device_info( |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1376 | new NiceMock<MockDeviceInfo>(control_interface(), dispatcher(), metrics(), |
| 1377 | &mock_manager_)); |
| 1378 | scoped_refptr<MockConnection> mock_connection0( |
| 1379 | new NiceMock<MockConnection>(mock_device_info.get())); |
| 1380 | scoped_refptr<MockConnection> mock_connection1( |
| 1381 | new NiceMock<MockConnection>(mock_device_info.get())); |
| 1382 | |
| 1383 | service_->connection_ = mock_connection0; |
Paul Stewart | cd7f585 | 2013-03-27 13:54:23 -0700 | [diff] [blame] | 1384 | EXPECT_CALL(*mock_connection0, GetLowerConnection()) |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1385 | .WillRepeatedly(Return(mock_connection1)); |
Paul Stewart | cd7f585 | 2013-03-27 13:54:23 -0700 | [diff] [blame] | 1386 | EXPECT_CALL(*mock_connection1, GetLowerConnection()) |
| 1387 | .WillRepeatedly(Return(ConnectionRefPtr())); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1388 | EXPECT_FALSE(service_->IsDependentOn(nullptr)); |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1389 | |
| 1390 | scoped_refptr<ServiceUnderTest> service1 = |
| 1391 | new ServiceUnderTest(control_interface(), |
| 1392 | dispatcher(), |
| 1393 | metrics(), |
| 1394 | &mock_manager_); |
| 1395 | EXPECT_FALSE(service_->IsDependentOn(service1)); |
| 1396 | |
| 1397 | service1->connection_ = mock_connection0; |
| 1398 | EXPECT_FALSE(service_->IsDependentOn(service1)); |
| 1399 | |
| 1400 | service1->connection_ = mock_connection1; |
| 1401 | EXPECT_TRUE(service_->IsDependentOn(service1)); |
| 1402 | |
Paul Stewart | cd7f585 | 2013-03-27 13:54:23 -0700 | [diff] [blame] | 1403 | service_->connection_ = mock_connection1; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1404 | service1->connection_ = nullptr; |
Paul Stewart | cd7f585 | 2013-03-27 13:54:23 -0700 | [diff] [blame] | 1405 | EXPECT_FALSE(service_->IsDependentOn(service1)); |
| 1406 | |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1407 | service_->connection_ = nullptr; |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1408 | } |
| 1409 | |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 1410 | TEST_F(ServiceTest, OnPropertyChanged) { |
| 1411 | scoped_refptr<MockProfile> profile( |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 1412 | new StrictMock<MockProfile>(control_interface(), metrics(), manager())); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1413 | service_->set_profile(nullptr); |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 1414 | // Expect no crash. |
| 1415 | service_->OnPropertyChanged(""); |
| 1416 | |
| 1417 | // Expect no call to Update if the profile has no storage. |
| 1418 | service_->set_profile(profile); |
| 1419 | EXPECT_CALL(*profile, UpdateService(_)).Times(0); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1420 | EXPECT_CALL(*profile, GetConstStorage()).WillOnce(Return(nullptr)); |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 1421 | service_->OnPropertyChanged(""); |
| 1422 | |
| 1423 | // Expect call to Update if the profile has storage. |
| 1424 | EXPECT_CALL(*profile, UpdateService(_)).Times(1); |
| 1425 | NiceMock<MockStore> storage; |
| 1426 | EXPECT_CALL(*profile, GetConstStorage()).WillOnce(Return(&storage)); |
| 1427 | service_->OnPropertyChanged(""); |
| 1428 | } |
| 1429 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1430 | |
| 1431 | TEST_F(ServiceTest, RecheckPortal) { |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1432 | service_->state_ = Service::kStateIdle; |
| 1433 | EXPECT_CALL(mock_manager_, RecheckPortalOnService(_)).Times(0); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1434 | service_->OnPropertyChanged(kCheckPortalProperty); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1435 | |
| 1436 | service_->state_ = Service::kStatePortal; |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 1437 | EXPECT_CALL(mock_manager_, RecheckPortalOnService(IsRefPtrTo(service_))) |
| 1438 | .Times(1); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1439 | service_->OnPropertyChanged(kCheckPortalProperty); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1440 | |
| 1441 | service_->state_ = Service::kStateConnected; |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 1442 | EXPECT_CALL(mock_manager_, RecheckPortalOnService(IsRefPtrTo(service_))) |
| 1443 | .Times(1); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1444 | service_->OnPropertyChanged(kProxyConfigProperty); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1445 | |
| 1446 | service_->state_ = Service::kStateOnline; |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 1447 | EXPECT_CALL(mock_manager_, RecheckPortalOnService(IsRefPtrTo(service_))) |
| 1448 | .Times(1); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1449 | service_->OnPropertyChanged(kCheckPortalProperty); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1450 | |
| 1451 | service_->state_ = Service::kStatePortal; |
| 1452 | EXPECT_CALL(mock_manager_, RecheckPortalOnService(_)).Times(0); |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1453 | service_->OnPropertyChanged(kEapKeyIdProperty); |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | TEST_F(ServiceTest, SetCheckPortal) { |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1457 | { |
| 1458 | Error error; |
| 1459 | service_->SetCheckPortal("false", &error); |
| 1460 | EXPECT_TRUE(error.IsSuccess()); |
| 1461 | EXPECT_EQ(Service::kCheckPortalFalse, service_->check_portal_); |
| 1462 | } |
| 1463 | { |
| 1464 | Error error; |
| 1465 | service_->SetCheckPortal("true", &error); |
| 1466 | EXPECT_TRUE(error.IsSuccess()); |
| 1467 | EXPECT_EQ(Service::kCheckPortalTrue, service_->check_portal_); |
| 1468 | } |
| 1469 | { |
| 1470 | Error error; |
| 1471 | service_->SetCheckPortal("auto", &error); |
| 1472 | EXPECT_TRUE(error.IsSuccess()); |
| 1473 | EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_); |
| 1474 | } |
| 1475 | { |
| 1476 | Error error; |
| 1477 | service_->SetCheckPortal("xxx", &error); |
| 1478 | EXPECT_FALSE(error.IsSuccess()); |
| 1479 | EXPECT_EQ(Error::kInvalidArguments, error.type()); |
| 1480 | EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_); |
| 1481 | } |
| 1482 | } |
| 1483 | |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1484 | TEST_F(ServiceTest, SetFriendlyName) { |
| 1485 | EXPECT_EQ(service_->unique_name_, service_->friendly_name_); |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1486 | ServiceMockAdaptor* adaptor = GetAdaptor(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1487 | |
| 1488 | EXPECT_CALL(*adaptor, EmitStringChanged(_, _)).Times(0); |
| 1489 | service_->SetFriendlyName(service_->unique_name_); |
| 1490 | EXPECT_EQ(service_->unique_name_, service_->friendly_name_); |
| 1491 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1492 | EXPECT_CALL(*adaptor, EmitStringChanged(kNameProperty, |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1493 | "Test Name 1")); |
| 1494 | service_->SetFriendlyName("Test Name 1"); |
| 1495 | EXPECT_EQ("Test Name 1", service_->friendly_name_); |
| 1496 | |
| 1497 | EXPECT_CALL(*adaptor, EmitStringChanged(_, _)).Times(0); |
| 1498 | service_->SetFriendlyName("Test Name 1"); |
| 1499 | EXPECT_EQ("Test Name 1", service_->friendly_name_); |
| 1500 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1501 | EXPECT_CALL(*adaptor, EmitStringChanged(kNameProperty, |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1502 | "Test Name 2")); |
| 1503 | service_->SetFriendlyName("Test Name 2"); |
| 1504 | EXPECT_EQ("Test Name 2", service_->friendly_name_); |
| 1505 | } |
| 1506 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1507 | TEST_F(ServiceTest, SetConnectableFull) { |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1508 | EXPECT_FALSE(service_->connectable()); |
| 1509 | |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1510 | ServiceMockAdaptor* adaptor = GetAdaptor(); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1511 | |
| 1512 | EXPECT_CALL(*adaptor, EmitBoolChanged(_, _)).Times(0); |
| 1513 | EXPECT_CALL(mock_manager_, HasService(_)).Times(0); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1514 | service_->SetConnectableFull(false); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1515 | EXPECT_FALSE(service_->connectable()); |
| 1516 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1517 | EXPECT_CALL(*adaptor, EmitBoolChanged(kConnectableProperty, true)); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1518 | EXPECT_CALL(mock_manager_, HasService(_)).WillOnce(Return(false)); |
| 1519 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1520 | service_->SetConnectableFull(true); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1521 | EXPECT_TRUE(service_->connectable()); |
| 1522 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1523 | EXPECT_CALL(*adaptor, EmitBoolChanged(kConnectableProperty, false)); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1524 | EXPECT_CALL(mock_manager_, HasService(_)).WillOnce(Return(true)); |
| 1525 | EXPECT_CALL(mock_manager_, UpdateService(_)); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1526 | service_->SetConnectableFull(false); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1527 | EXPECT_FALSE(service_->connectable()); |
| 1528 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1529 | EXPECT_CALL(*adaptor, EmitBoolChanged(kConnectableProperty, true)); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1530 | EXPECT_CALL(mock_manager_, HasService(_)).WillOnce(Return(true)); |
| 1531 | EXPECT_CALL(mock_manager_, UpdateService(_)); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1532 | service_->SetConnectableFull(true); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1533 | EXPECT_TRUE(service_->connectable()); |
| 1534 | } |
| 1535 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1536 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1537 | class WriteOnlyServicePropertyTest : public ServiceTest {}; |
| 1538 | TEST_P(WriteOnlyServicePropertyTest, PropertyWriteOnly) { |
| 1539 | // Use a real EapCredentials instance since the base Service class |
| 1540 | // contains no write-only properties. |
| 1541 | EapCredentials eap; |
| 1542 | eap.InitPropertyStore(service_->mutable_store()); |
| 1543 | |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 1544 | string property(GetParam().reader().get_string()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 1545 | Error error; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1546 | EXPECT_FALSE(service_->store().GetStringProperty(property, nullptr, &error)); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 1547 | EXPECT_EQ(Error::kPermissionDenied, error.type()); |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | INSTANTIATE_TEST_CASE_P( |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1551 | WriteOnlyServicePropertyTestInstance, |
| 1552 | WriteOnlyServicePropertyTest, |
Paul Stewart | 9f32d19 | 2012-01-30 20:37:50 -0800 | [diff] [blame] | 1553 | Values( |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1554 | DBusAdaptor::StringToVariant(kEapPrivateKeyPasswordProperty), |
| 1555 | DBusAdaptor::StringToVariant(kEapPasswordProperty))); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1556 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1557 | |
| 1558 | TEST_F(ServiceTest, GetIPConfigRpcIdentifier) { |
| 1559 | { |
| 1560 | Error error; |
| 1561 | EXPECT_EQ("/", service_->GetIPConfigRpcIdentifier(&error)); |
| 1562 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 1563 | } |
| 1564 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 1565 | std::unique_ptr<MockDeviceInfo> mock_device_info( |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1566 | new NiceMock<MockDeviceInfo>(control_interface(), dispatcher(), metrics(), |
| 1567 | &mock_manager_)); |
| 1568 | scoped_refptr<MockConnection> mock_connection( |
| 1569 | new NiceMock<MockConnection>(mock_device_info.get())); |
| 1570 | |
| 1571 | service_->connection_ = mock_connection; |
| 1572 | |
| 1573 | { |
| 1574 | Error error; |
| 1575 | const string empty_string; |
| 1576 | EXPECT_CALL(*mock_connection, ipconfig_rpc_identifier()) |
| 1577 | .WillOnce(ReturnRef(empty_string)); |
| 1578 | EXPECT_EQ("/", service_->GetIPConfigRpcIdentifier(&error)); |
| 1579 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 1580 | } |
| 1581 | |
| 1582 | { |
| 1583 | Error error; |
| 1584 | const string nonempty_string("/ipconfig/path"); |
| 1585 | EXPECT_CALL(*mock_connection, ipconfig_rpc_identifier()) |
| 1586 | .WillOnce(ReturnRef(nonempty_string)); |
| 1587 | EXPECT_EQ(nonempty_string, service_->GetIPConfigRpcIdentifier(&error)); |
| 1588 | EXPECT_EQ(Error::kSuccess, error.type()); |
| 1589 | } |
| 1590 | |
| 1591 | // Assure orderly destruction of the Connection before DeviceInfo. |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1592 | service_->connection_ = nullptr; |
| 1593 | mock_connection = nullptr; |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1594 | mock_device_info.reset(); |
| 1595 | } |
| 1596 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1597 | #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1598 | class ServiceWithMockOnEapCredentialsChanged : public ServiceUnderTest { |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1599 | public: |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1600 | ServiceWithMockOnEapCredentialsChanged(ControlInterface* control_interface, |
| 1601 | EventDispatcher* dispatcher, |
| 1602 | Metrics* metrics, |
| 1603 | Manager* manager) |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1604 | : ServiceUnderTest(control_interface, dispatcher, metrics, manager), |
| 1605 | is_8021x_(false) {} |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1606 | MOCK_METHOD1(OnEapCredentialsChanged, void(Service::UpdateCredentialsReason)); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1607 | virtual bool Is8021x() const { return is_8021x_; } |
| 1608 | void set_is_8021x(bool is_8021x) { is_8021x_ = is_8021x; } |
| 1609 | |
| 1610 | private: |
| 1611 | bool is_8021x_; |
| 1612 | }; |
| 1613 | |
| 1614 | TEST_F(ServiceTest, SetEAPCredentialsOverRPC) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1615 | scoped_refptr<ServiceWithMockOnEapCredentialsChanged> service( |
| 1616 | new ServiceWithMockOnEapCredentialsChanged(control_interface(), |
| 1617 | dispatcher(), |
| 1618 | metrics(), |
| 1619 | &mock_manager_)); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1620 | string eap_credential_properties[] = { |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1621 | kEapAnonymousIdentityProperty, |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1622 | kEapCertIdProperty, |
| 1623 | kEapClientCertProperty, |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1624 | kEapIdentityProperty, |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1625 | kEapKeyIdProperty, |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1626 | kEapPasswordProperty, |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1627 | kEapPinProperty, |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1628 | kEapPrivateKeyProperty, |
| 1629 | kEapPrivateKeyPasswordProperty |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1630 | }; |
| 1631 | string eap_non_credential_properties[] = { |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1632 | kEapCaCertIdProperty, |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1633 | kEapCaCertNssProperty, |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1634 | kEapMethodProperty, |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1635 | kEapPhase2AuthProperty, |
Ben Chan | 011e666 | 2014-05-07 11:03:25 -0700 | [diff] [blame] | 1636 | kEapUseSystemCasProperty |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1637 | }; |
| 1638 | // While this is not an 802.1x-based service, none of these property |
| 1639 | // changes should cause a call to set_eap(). |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1640 | EXPECT_CALL(*service, OnEapCredentialsChanged(_)).Times(0); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1641 | for (size_t i = 0; i < arraysize(eap_credential_properties); ++i) |
| 1642 | service->OnPropertyChanged(eap_credential_properties[i]); |
| 1643 | for (size_t i = 0; i < arraysize(eap_non_credential_properties); ++i) |
| 1644 | service->OnPropertyChanged(eap_non_credential_properties[i]); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1645 | service->OnPropertyChanged(kEapKeyMgmtProperty); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1646 | |
| 1647 | service->set_is_8021x(true); |
| 1648 | |
| 1649 | // When this is an 802.1x-based service, set_eap should be called for |
| 1650 | // all credential-carrying properties. |
| 1651 | for (size_t i = 0; i < arraysize(eap_credential_properties); ++i) { |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1652 | EXPECT_CALL(*service, |
| 1653 | OnEapCredentialsChanged( |
| 1654 | Service::kReasonPropertyUpdate)).Times(1); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1655 | service->OnPropertyChanged(eap_credential_properties[i]); |
| 1656 | Mock::VerifyAndClearExpectations(service.get()); |
| 1657 | } |
Paul Stewart | adf79d8 | 2012-07-18 16:09:56 -0700 | [diff] [blame] | 1658 | |
| 1659 | // The key management property is a special case. While not strictly |
| 1660 | // a credential, it can change which credentials are used. Therefore it |
| 1661 | // should also trigger a call to set_eap(); |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1662 | EXPECT_CALL(*service, |
| 1663 | OnEapCredentialsChanged(Service::kReasonPropertyUpdate)).Times(1); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1664 | service->OnPropertyChanged(kEapKeyMgmtProperty); |
Paul Stewart | adf79d8 | 2012-07-18 16:09:56 -0700 | [diff] [blame] | 1665 | Mock::VerifyAndClearExpectations(service.get()); |
| 1666 | |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1667 | EXPECT_CALL(*service, OnEapCredentialsChanged(_)).Times(0); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1668 | for (size_t i = 0; i < arraysize(eap_non_credential_properties); ++i) |
| 1669 | service->OnPropertyChanged(eap_non_credential_properties[i]); |
| 1670 | } |
| 1671 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1672 | TEST_F(ServiceTest, Certification) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1673 | EXPECT_FALSE(service_->remote_certification_.size()); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1674 | |
| 1675 | ScopedMockLog log; |
| 1676 | EXPECT_CALL(log, Log(logging::LOG_WARNING, _, |
| 1677 | HasSubstr("exceeds our maximum"))).Times(2); |
| 1678 | string kSubject("foo"); |
| 1679 | EXPECT_FALSE(service_->AddEAPCertification( |
| 1680 | kSubject, Service::kEAPMaxCertificationElements)); |
| 1681 | EXPECT_FALSE(service_->AddEAPCertification( |
| 1682 | kSubject, Service::kEAPMaxCertificationElements + 1)); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1683 | EXPECT_FALSE(service_->remote_certification_.size()); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1684 | Mock::VerifyAndClearExpectations(&log); |
| 1685 | |
| 1686 | EXPECT_CALL(log, |
| 1687 | Log(logging::LOG_INFO, _, HasSubstr("Received certification"))) |
| 1688 | .Times(1); |
| 1689 | EXPECT_TRUE(service_->AddEAPCertification( |
| 1690 | kSubject, Service::kEAPMaxCertificationElements - 1)); |
| 1691 | Mock::VerifyAndClearExpectations(&log); |
| 1692 | EXPECT_EQ(Service::kEAPMaxCertificationElements, |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1693 | service_->remote_certification_.size()); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1694 | for (size_t i = 0; i < Service::kEAPMaxCertificationElements - 1; ++i) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1695 | EXPECT_TRUE(service_->remote_certification_[i].empty()); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1696 | } |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1697 | EXPECT_EQ(kSubject, service_->remote_certification_[ |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1698 | Service::kEAPMaxCertificationElements - 1]); |
| 1699 | |
| 1700 | // Re-adding the same name in the same position should not generate a log. |
| 1701 | EXPECT_CALL(log, Log(_, _, _)).Times(0); |
| 1702 | EXPECT_TRUE(service_->AddEAPCertification( |
| 1703 | kSubject, Service::kEAPMaxCertificationElements - 1)); |
| 1704 | |
| 1705 | // Replacing the item should generate a log message. |
| 1706 | EXPECT_CALL(log, |
| 1707 | Log(logging::LOG_INFO, _, HasSubstr("Received certification"))) |
| 1708 | .Times(1); |
| 1709 | EXPECT_TRUE(service_->AddEAPCertification( |
| 1710 | kSubject + "x", Service::kEAPMaxCertificationElements - 1)); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1711 | |
| 1712 | service_->ClearEAPCertification(); |
| 1713 | EXPECT_TRUE(service_->remote_certification_.empty()); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1714 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 1715 | #endif // DISABLE_WIFI || DISABLE_WIRED_8021X |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 1716 | |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 1717 | TEST_F(ServiceTest, NoteDisconnectEventIdle) { |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1718 | Timestamp timestamp; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1719 | EXPECT_CALL(time_, GetNow()).Times(7).WillRepeatedly((Return(timestamp))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1720 | SetStateField(Service::kStateOnline); |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1721 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1722 | service_->SetState(Service::kStateIdle); |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 1723 | // The transition Online->Idle is not an event. |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1724 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 1725 | service_->SetState(Service::kStateFailure); |
| 1726 | // The transition Online->Idle->Failure is a connection drop. |
| 1727 | EXPECT_TRUE(service_->HasRecentConnectionIssues()); |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | TEST_F(ServiceTest, NoteDisconnectEventOnSetStateFailure) { |
| 1731 | Timestamp timestamp; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1732 | EXPECT_CALL(time_, GetNow()).Times(5).WillRepeatedly((Return(timestamp))); |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1733 | SetStateField(Service::kStateOnline); |
| 1734 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
| 1735 | service_->SetState(Service::kStateFailure); |
| 1736 | EXPECT_TRUE(service_->HasRecentConnectionIssues()); |
| 1737 | } |
| 1738 | |
| 1739 | TEST_F(ServiceTest, NoteDisconnectEventOnSetFailureSilent) { |
| 1740 | Timestamp timestamp; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1741 | EXPECT_CALL(time_, GetNow()).Times(5).WillRepeatedly((Return(timestamp))); |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1742 | SetStateField(Service::kStateConfiguring); |
| 1743 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
| 1744 | service_->SetFailureSilent(Service::kFailureEAPAuthentication); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1745 | EXPECT_TRUE(service_->HasRecentConnectionIssues()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | TEST_F(ServiceTest, NoteDisconnectEventNonEvent) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1749 | EXPECT_CALL(time_, GetNow()).Times(0); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1750 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(0); |
| 1751 | |
| 1752 | // Explicit disconnect is a non-event. |
| 1753 | SetStateField(Service::kStateOnline); |
| 1754 | SetExplicitlyDisconnected(true); |
| 1755 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1756 | EXPECT_TRUE(GetDisconnects()->Empty()); |
| 1757 | EXPECT_TRUE(GetMisconnects()->Empty()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1758 | |
| 1759 | // Failure to idle transition is a non-event. |
| 1760 | SetStateField(Service::kStateFailure); |
| 1761 | SetExplicitlyDisconnected(false); |
| 1762 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1763 | EXPECT_TRUE(GetDisconnects()->Empty()); |
| 1764 | EXPECT_TRUE(GetMisconnects()->Empty()); |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 1765 | |
| 1766 | // Disconnect while manager is stopped is a non-event. |
| 1767 | SetStateField(Service::kStateOnline); |
| 1768 | SetManagerRunning(false); |
| 1769 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1770 | EXPECT_TRUE(GetDisconnects()->Empty()); |
| 1771 | EXPECT_TRUE(GetMisconnects()->Empty()); |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 1772 | |
| 1773 | // Disconnect while suspending is a non-event. |
| 1774 | SetManagerRunning(true); |
Daniel Erat | fac0953 | 2014-04-17 20:25:59 -0700 | [diff] [blame] | 1775 | SetSuspending(true); |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 1776 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1777 | EXPECT_TRUE(GetDisconnects()->Empty()); |
| 1778 | EXPECT_TRUE(GetMisconnects()->Empty()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | TEST_F(ServiceTest, NoteDisconnectEventDisconnectOnce) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1782 | const int kNow = 5; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1783 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1784 | SetStateField(Service::kStateOnline); |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1785 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(GetTimestamp(kNow, kNow, ""))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1786 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(0); |
| 1787 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1788 | ASSERT_EQ(1, GetDisconnects()->Size()); |
| 1789 | EXPECT_EQ(kNow, GetDisconnects()->Front().monotonic.tv_sec); |
| 1790 | EXPECT_TRUE(GetMisconnects()->Empty()); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1791 | |
| 1792 | Mock::VerifyAndClearExpectations(&time_); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1793 | EXPECT_CALL(time_, GetNow()).Times(2).WillRepeatedly(Return(GetTimestamp( |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1794 | kNow + GetDisconnectsMonitorSeconds() - 1, |
| 1795 | kNow + GetDisconnectsMonitorSeconds() - 1, |
| 1796 | ""))); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1797 | EXPECT_TRUE(service_->HasRecentConnectionIssues()); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1798 | ASSERT_EQ(1, GetDisconnects()->Size()); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1799 | |
| 1800 | Mock::VerifyAndClearExpectations(&time_); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1801 | EXPECT_CALL(time_, GetNow()).Times(2).WillRepeatedly(Return(GetTimestamp( |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1802 | kNow + GetDisconnectsMonitorSeconds(), |
| 1803 | kNow + GetDisconnectsMonitorSeconds(), |
| 1804 | ""))); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1805 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1806 | ASSERT_TRUE(GetDisconnects()->Empty()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | TEST_F(ServiceTest, NoteDisconnectEventDisconnectThreshold) { |
| 1810 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1811 | SetStateField(Service::kStateOnline); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1812 | const int kNow = 6; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1813 | for (int i = 0; i < GetReportDisconnectsThreshold() - 1; i++) { |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1814 | PushTimestamp(GetDisconnects(), kNow, kNow, ""); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1815 | } |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1816 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(GetTimestamp(kNow, kNow, ""))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1817 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(1); |
| 1818 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1819 | EXPECT_EQ(GetReportDisconnectsThreshold(), GetDisconnects()->Size()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | TEST_F(ServiceTest, NoteDisconnectEventMisconnectOnce) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1823 | const int kNow = 7; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1824 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1825 | SetStateField(Service::kStateConfiguring); |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1826 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(GetTimestamp(kNow, kNow, ""))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1827 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(0); |
| 1828 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1829 | EXPECT_TRUE(GetDisconnects()->Empty()); |
| 1830 | ASSERT_EQ(1, GetMisconnects()->Size()); |
| 1831 | EXPECT_EQ(kNow, GetMisconnects()->Front().monotonic.tv_sec); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1832 | |
| 1833 | Mock::VerifyAndClearExpectations(&time_); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1834 | EXPECT_CALL(time_, GetNow()).Times(2).WillRepeatedly(Return(GetTimestamp( |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1835 | kNow + GetMisconnectsMonitorSeconds() - 1, |
| 1836 | kNow + GetMisconnectsMonitorSeconds() - 1, |
| 1837 | ""))); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1838 | EXPECT_TRUE(service_->HasRecentConnectionIssues()); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1839 | ASSERT_EQ(1, GetMisconnects()->Size()); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1840 | |
| 1841 | Mock::VerifyAndClearExpectations(&time_); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1842 | EXPECT_CALL(time_, GetNow()).Times(2).WillRepeatedly(Return(GetTimestamp( |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1843 | kNow + GetMisconnectsMonitorSeconds(), |
| 1844 | kNow + GetMisconnectsMonitorSeconds(), |
| 1845 | ""))); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1846 | EXPECT_FALSE(service_->HasRecentConnectionIssues()); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1847 | ASSERT_TRUE(GetMisconnects()->Empty()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | TEST_F(ServiceTest, NoteDisconnectEventMisconnectThreshold) { |
| 1851 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1852 | SetStateField(Service::kStateConfiguring); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1853 | const int kNow = 8; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1854 | for (int i = 0; i < GetReportMisconnectsThreshold() - 1; i++) { |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1855 | PushTimestamp(GetMisconnects(), kNow, kNow, ""); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1856 | } |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1857 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(GetTimestamp(kNow, kNow, ""))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1858 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(1); |
| 1859 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1860 | EXPECT_EQ(GetReportMisconnectsThreshold(), GetMisconnects()->Size()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | TEST_F(ServiceTest, NoteDisconnectEventDiscardOld) { |
| 1864 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1865 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(0); |
| 1866 | for (int i = 0; i < 2; i++) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1867 | int now = 0; |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1868 | EventHistory* events = nullptr; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1869 | if (i == 0) { |
| 1870 | SetStateField(Service::kStateConnected); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1871 | now = GetDisconnectsMonitorSeconds() + 1; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1872 | events = GetDisconnects(); |
| 1873 | } else { |
| 1874 | SetStateField(Service::kStateAssociating); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1875 | now = GetMisconnectsMonitorSeconds() + 1; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1876 | events = GetMisconnects(); |
| 1877 | } |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1878 | PushTimestamp(events, 0, 0, ""); |
| 1879 | PushTimestamp(events, 0, 0, ""); |
| 1880 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(GetTimestamp(now, now, ""))); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1881 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1882 | ASSERT_EQ(1, events->Size()); |
| 1883 | EXPECT_EQ(now, events->Front().monotonic.tv_sec); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | TEST_F(ServiceTest, NoteDisconnectEventDiscardExcessive) { |
| 1888 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1889 | SetStateField(Service::kStateOnline); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1890 | for (int i = 0; i < 2 * GetMaxDisconnectEventHistory(); i++) { |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1891 | PushTimestamp(GetDisconnects(), 0, 0, ""); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1892 | } |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1893 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(Timestamp())); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1894 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(1); |
| 1895 | NoteDisconnectEvent(); |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1896 | EXPECT_EQ(GetMaxDisconnectEventHistory(), GetDisconnects()->Size()); |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1899 | TEST_F(ServiceTest, NoteMisconnectEventDiscardExcessive) { |
| 1900 | EXPECT_FALSE(service_->explicitly_disconnected()); |
| 1901 | SetStateField(Service::kStateAssociating); |
| 1902 | for (int i = 0; i < 2 * GetMaxMisconnectEventHistory(); i++) { |
| 1903 | PushTimestamp(GetMisconnects(), 0, 0, ""); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1904 | } |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1905 | EXPECT_CALL(time_, GetNow()).WillOnce(Return(Timestamp())); |
| 1906 | EXPECT_CALL(diagnostics_reporter_, OnConnectivityEvent()).Times(1); |
| 1907 | NoteDisconnectEvent(); |
| 1908 | EXPECT_EQ(GetMaxMisconnectEventHistory(), GetMisconnects()->Size()); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | TEST_F(ServiceTest, DiagnosticsProperties) { |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 1912 | const string kWallClock0 = "2012-12-09T12:41:22.234567-0800"; |
| 1913 | const string kWallClock1 = "2012-12-31T23:59:59.345678-0800"; |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1914 | Strings values; |
| 1915 | |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1916 | PushTimestamp(GetDisconnects(), 0, 0, kWallClock0); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 1917 | Error unused_error; |
| 1918 | ASSERT_TRUE(service_->store().GetStringsProperty( |
| 1919 | kDiagnosticsDisconnectsProperty, &values, &unused_error)); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1920 | ASSERT_EQ(1, values.size()); |
| 1921 | EXPECT_EQ(kWallClock0, values[0]); |
| 1922 | |
Peter Qiu | 3b4ebd5 | 2014-07-29 11:16:55 -0700 | [diff] [blame] | 1923 | PushTimestamp(GetMisconnects(), 0, 0, kWallClock1); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 1924 | ASSERT_TRUE(service_->store().GetStringsProperty( |
| 1925 | kDiagnosticsMisconnectsProperty, &values, &unused_error)); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1926 | ASSERT_EQ(1, values.size()); |
| 1927 | EXPECT_EQ(kWallClock1, values[0]); |
| 1928 | } |
| 1929 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1930 | TEST_F(ServiceTest, SecurityLevel) { |
| 1931 | // Encrypted is better than not. |
| 1932 | service_->SetSecurity(Service::kCryptoNone, false, false); |
| 1933 | service2_->SetSecurity(Service::kCryptoRc4, false, false); |
| 1934 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1935 | |
| 1936 | // AES encryption is better than RC4 encryption. |
| 1937 | service_->SetSecurity(Service::kCryptoRc4, false, false); |
| 1938 | service2_->SetSecurity(Service::kCryptoAes, false, false); |
| 1939 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1940 | |
| 1941 | // Crypto algorithm is more important than key rotation. |
| 1942 | service_->SetSecurity(Service::kCryptoNone, true, false); |
| 1943 | service2_->SetSecurity(Service::kCryptoAes, false, false); |
| 1944 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1945 | |
| 1946 | // Encrypted-but-unauthenticated is better than clear-but-authenticated. |
| 1947 | service_->SetSecurity(Service::kCryptoNone, false, true); |
| 1948 | service2_->SetSecurity(Service::kCryptoAes, false, false); |
| 1949 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1950 | |
| 1951 | // For same encryption, prefer key rotation. |
| 1952 | service_->SetSecurity(Service::kCryptoRc4, false, false); |
| 1953 | service2_->SetSecurity(Service::kCryptoRc4, true, false); |
| 1954 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1955 | |
| 1956 | // For same encryption, prefer authenticated AP. |
| 1957 | service_->SetSecurity(Service::kCryptoRc4, false, false); |
| 1958 | service2_->SetSecurity(Service::kCryptoRc4, false, true); |
| 1959 | EXPECT_GT(service2_->SecurityLevel(), service_->SecurityLevel()); |
| 1960 | } |
| 1961 | |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 1962 | TEST_F(ServiceTest, SetErrorDetails) { |
| 1963 | EXPECT_EQ(Service::kErrorDetailsNone, service_->error_details()); |
| 1964 | static const char kDetails[] = "Certificate revoked."; |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 1965 | ServiceMockAdaptor* adaptor = GetAdaptor(); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 1966 | EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, kDetails)); |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 1967 | service_->SetErrorDetails(Service::kErrorDetailsNone); |
| 1968 | EXPECT_EQ(Service::kErrorDetailsNone, service_->error_details()); |
| 1969 | service_->SetErrorDetails(kDetails); |
| 1970 | EXPECT_EQ(kDetails, service_->error_details()); |
| 1971 | service_->SetErrorDetails(kDetails); |
| 1972 | } |
| 1973 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1974 | TEST_F(ServiceTest, SetAutoConnectFull) { |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1975 | EXPECT_FALSE(service_->auto_connect()); |
| 1976 | Error error; |
| 1977 | EXPECT_FALSE(GetAutoConnect(&error)); |
| 1978 | EXPECT_TRUE(error.IsSuccess()); |
| 1979 | |
| 1980 | // false -> false |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1981 | EXPECT_FALSE(service_->retain_auto_connect()); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1982 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1983 | SetAutoConnectFull(false, &error); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1984 | EXPECT_TRUE(error.IsSuccess()); |
| 1985 | EXPECT_FALSE(service_->auto_connect()); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1986 | EXPECT_TRUE(service_->retain_auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1987 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1988 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 1989 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1990 | // Clear the |retain_auto_connect_| flag for the next test. |
Paul Stewart | 96a6d09 | 2013-08-26 09:32:49 -0700 | [diff] [blame] | 1991 | service_->Unload(); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1992 | ASSERT_FALSE(service_->retain_auto_connect()); |
Paul Stewart | 96a6d09 | 2013-08-26 09:32:49 -0700 | [diff] [blame] | 1993 | |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1994 | // false -> true |
| 1995 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(1); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1996 | SetAutoConnectFull(true, &error); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1997 | EXPECT_TRUE(error.IsSuccess()); |
| 1998 | EXPECT_TRUE(service_->auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1999 | EXPECT_TRUE(GetAutoConnect(nullptr)); |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2000 | EXPECT_TRUE(service_->retain_auto_connect()); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2001 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2002 | |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2003 | // Clear the |retain_auto_connect_| flag for the next test. |
| 2004 | service_->Unload(); |
| 2005 | ASSERT_FALSE(service_->retain_auto_connect()); |
| 2006 | |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2007 | // true -> true |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2008 | service_->SetAutoConnect(true); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2009 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 2010 | SetAutoConnectFull(true, &error); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2011 | EXPECT_TRUE(error.IsSuccess()); |
| 2012 | EXPECT_TRUE(service_->auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2013 | EXPECT_TRUE(GetAutoConnect(nullptr)); |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2014 | EXPECT_TRUE(service_->retain_auto_connect()); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2015 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2016 | |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2017 | // Clear the |retain_auto_connect_| flag for the next test. |
| 2018 | service_->Unload(); |
| 2019 | ASSERT_FALSE(service_->retain_auto_connect()); |
| 2020 | |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2021 | // true -> false |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 2022 | service_->SetAutoConnect(true); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2023 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(1); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 2024 | SetAutoConnectFull(false, &error); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2025 | EXPECT_TRUE(error.IsSuccess()); |
| 2026 | EXPECT_FALSE(service_->auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2027 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2028 | EXPECT_TRUE(service_->retain_auto_connect()); |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 2029 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2030 | } |
| 2031 | |
Prathmesh Prabhu | 765d5df | 2014-04-22 16:43:15 -0700 | [diff] [blame] | 2032 | TEST_F(ServiceTest, SetAutoConnectFullUserUpdatePersists) { |
| 2033 | // If the user sets the kAutoConnectProperty explicitly, the preference must |
| 2034 | // be persisted, even if the property was not changed. |
| 2035 | Error error; |
Prathmesh Prabhu | 765d5df | 2014-04-22 16:43:15 -0700 | [diff] [blame] | 2036 | MockProfileRefPtr mock_profile( |
| 2037 | new MockProfile(control_interface(), metrics(), &mock_manager_)); |
| 2038 | NiceMock<MockStore> storage; |
| 2039 | service_->set_profile(mock_profile); |
| 2040 | service_->SetAutoConnect(true); |
| 2041 | |
| 2042 | EXPECT_CALL(*mock_profile, UpdateService(_)); |
| 2043 | EXPECT_CALL(*mock_profile, GetConstStorage()) |
| 2044 | .WillOnce(Return(&storage)); |
Paul Stewart | f286034 | 2014-05-09 14:29:16 -0700 | [diff] [blame] | 2045 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(IsRefPtrTo(service_))) |
Prathmesh Prabhu | 765d5df | 2014-04-22 16:43:15 -0700 | [diff] [blame] | 2046 | .WillOnce(Return(false)); |
| 2047 | EXPECT_FALSE(service_->retain_auto_connect()); |
| 2048 | SetAutoConnectFull(true, &error); |
| 2049 | EXPECT_TRUE(error.IsSuccess()); |
| 2050 | EXPECT_TRUE(service_->auto_connect()); |
| 2051 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 2052 | } |
| 2053 | |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2054 | TEST_F(ServiceTest, ClearAutoConnect) { |
| 2055 | EXPECT_FALSE(service_->auto_connect()); |
| 2056 | Error error; |
| 2057 | EXPECT_FALSE(GetAutoConnect(&error)); |
| 2058 | EXPECT_TRUE(error.IsSuccess()); |
| 2059 | |
| 2060 | // unset -> false |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2061 | EXPECT_FALSE(service_->retain_auto_connect()); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2062 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
| 2063 | ClearAutoConnect(&error); |
| 2064 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2065 | EXPECT_FALSE(service_->retain_auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2066 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2067 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2068 | |
| 2069 | // false -> false |
| 2070 | SetAutoConnectFull(false, &error); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2071 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2072 | EXPECT_TRUE(service_->retain_auto_connect()); |
| 2073 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2074 | ClearAutoConnect(&error); |
| 2075 | EXPECT_TRUE(error.IsSuccess()); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2076 | EXPECT_FALSE(service_->retain_auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2077 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2078 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2079 | |
| 2080 | // true -> false |
| 2081 | SetAutoConnectFull(true, &error); |
| 2082 | EXPECT_TRUE(error.IsSuccess()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2083 | EXPECT_TRUE(GetAutoConnect(nullptr)); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2084 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(1); |
| 2085 | ClearAutoConnect(&error); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 2086 | EXPECT_FALSE(service_->retain_auto_connect()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 2087 | EXPECT_FALSE(GetAutoConnect(nullptr)); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 2088 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2089 | } |
| 2090 | |
mukesh agrawal | e37ad32 | 2013-10-08 16:33:56 -0700 | [diff] [blame] | 2091 | TEST_F(ServiceTest, UniqueAttributes) { |
| 2092 | EXPECT_NE(service_->serial_number_, service2_->serial_number_); |
| 2093 | EXPECT_NE(service_->unique_name(), service2_->unique_name()); |
| 2094 | } |
| 2095 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 2096 | TEST_F(ServiceTest, PropertyChanges) { |
| 2097 | TestCommonPropertyChanges(service_, GetAdaptor()); |
| 2098 | TestAutoConnectPropertyChange(service_, GetAdaptor()); |
| 2099 | } |
| 2100 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 2101 | // Custom property setters should return false, and make no changes, if |
| 2102 | // the new value is the same as the old value. |
| 2103 | TEST_F(ServiceTest, CustomSetterNoopChange) { |
| 2104 | TestCustomSetterNoopChange(service_, &mock_manager_); |
| 2105 | } |
| 2106 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 2107 | TEST_F(ServiceTest, GetTethering) { |
| 2108 | Error error; |
| 2109 | EXPECT_EQ("", service_->GetTethering(&error)); |
| 2110 | EXPECT_EQ(Error::kNotSupported, error.type()); |
| 2111 | } |
| 2112 | |
Paul Stewart | 836a937 | 2014-04-23 19:57:15 -0700 | [diff] [blame] | 2113 | class ServiceWithMockOnPropertyChanged : public ServiceUnderTest { |
| 2114 | public: |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 2115 | ServiceWithMockOnPropertyChanged(ControlInterface* control_interface, |
| 2116 | EventDispatcher* dispatcher, |
| 2117 | Metrics* metrics, |
| 2118 | Manager* manager) |
Paul Stewart | 836a937 | 2014-04-23 19:57:15 -0700 | [diff] [blame] | 2119 | : ServiceUnderTest(control_interface, dispatcher, metrics, manager) {} |
Paul Stewart | 3b30ca5 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 2120 | MOCK_METHOD1(OnPropertyChanged, void(const string& property)); |
Paul Stewart | 836a937 | 2014-04-23 19:57:15 -0700 | [diff] [blame] | 2121 | }; |
| 2122 | |
| 2123 | TEST_F(ServiceTest, ConfigureServiceTriggersOnPropertyChanged) { |
| 2124 | auto service(make_scoped_refptr( |
| 2125 | new ServiceWithMockOnPropertyChanged(control_interface(), |
| 2126 | dispatcher(), |
| 2127 | metrics(), |
| 2128 | &mock_manager_))); |
| 2129 | KeyValueStore args; |
| 2130 | args.SetString(kUIDataProperty, "terpsichorean ejectamenta"); |
| 2131 | args.SetBool(kSaveCredentialsProperty, false); |
| 2132 | |
| 2133 | // Calling Configure with different values from before triggers a single |
| 2134 | // OnPropertyChanged call per property. |
| 2135 | EXPECT_CALL(*service, OnPropertyChanged(kUIDataProperty)).Times(1); |
| 2136 | EXPECT_CALL(*service, OnPropertyChanged(kSaveCredentialsProperty)).Times(1); |
| 2137 | { |
| 2138 | Error error; |
| 2139 | service->Configure(args, &error); |
| 2140 | EXPECT_TRUE(error.IsSuccess()); |
| 2141 | } |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 2142 | Mock::VerifyAndClearExpectations(service.get()); |
Paul Stewart | 836a937 | 2014-04-23 19:57:15 -0700 | [diff] [blame] | 2143 | |
| 2144 | // Calling Configure with the same values as before should not trigger |
| 2145 | // OnPropertyChanged(). |
| 2146 | EXPECT_CALL(*service, OnPropertyChanged(_)).Times(0); |
| 2147 | { |
| 2148 | Error error; |
| 2149 | service->Configure(args, &error); |
| 2150 | EXPECT_TRUE(error.IsSuccess()); |
| 2151 | } |
| 2152 | } |
| 2153 | |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 2154 | TEST_F(ServiceTest, ClearExplicitlyDisconnected) { |
| 2155 | EXPECT_FALSE(GetExplicitlyDisconnected()); |
| 2156 | EXPECT_CALL(mock_manager_, UpdateService(_)).Times(0); |
| 2157 | service_->ClearExplicitlyDisconnected(); |
| 2158 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2159 | |
| 2160 | SetExplicitlyDisconnected(true); |
| 2161 | EXPECT_CALL(mock_manager_, UpdateService(IsRefPtrTo(service_))); |
| 2162 | service_->ClearExplicitlyDisconnected(); |
| 2163 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2164 | EXPECT_FALSE(GetExplicitlyDisconnected()); |
| 2165 | } |
| 2166 | |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 2167 | TEST_F(ServiceTest, Compare) { |
| 2168 | // Construct our Services so that the string comparison of |
| 2169 | // unique_name_ differs from the numerical comparison of |
| 2170 | // serial_number_. |
| 2171 | vector<scoped_refptr<MockService>> mock_services; |
| 2172 | for (size_t i = 0; i < 11; ++i) { |
| 2173 | mock_services.push_back( |
| 2174 | new NiceMock<MockService>(control_interface(), |
| 2175 | dispatcher(), |
| 2176 | metrics(), |
| 2177 | manager())); |
| 2178 | } |
| 2179 | scoped_refptr<MockService> service2 = mock_services[2]; |
| 2180 | scoped_refptr<MockService> service10 = mock_services[10]; |
| 2181 | mock_services.clear(); |
| 2182 | |
| 2183 | // Services should already be sorted by |serial_number_|. |
| 2184 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2185 | |
| 2186 | // Two otherwise equal services should be reordered by strength |
| 2187 | service10->SetStrength(1); |
| 2188 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2189 | |
| 2190 | scoped_refptr<MockProfile> profile2( |
| 2191 | new MockProfile(control_interface(), metrics(), manager(), "")); |
| 2192 | scoped_refptr<MockProfile> profile10( |
| 2193 | new MockProfile(control_interface(), metrics(), manager(), "")); |
| 2194 | |
| 2195 | service2->set_profile(profile2); |
| 2196 | service10->set_profile(profile10); |
| 2197 | |
| 2198 | // When comparing two services with different profiles, prefer the one |
| 2199 | // that is not ephemeral. |
| 2200 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(IsRefPtrTo(service2))) |
| 2201 | .WillRepeatedly(Return(false)); |
| 2202 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(IsRefPtrTo(service10))) |
| 2203 | .WillRepeatedly(Return(true)); |
| 2204 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2205 | Mock::VerifyAndClearExpectations(&mock_manager_); |
| 2206 | |
| 2207 | // Prefer the service with the more recently applied profile if neither |
| 2208 | // service is ephemeral. |
| 2209 | EXPECT_CALL(mock_manager_, IsServiceEphemeral(_)) |
| 2210 | .WillRepeatedly(Return(false)); |
| 2211 | EXPECT_CALL(mock_manager_, IsProfileBefore(IsRefPtrTo(profile2), |
| 2212 | IsRefPtrTo(profile10))) |
| 2213 | .WillRepeatedly(Return(true)); |
| 2214 | EXPECT_CALL(mock_manager_, IsProfileBefore(IsRefPtrTo(profile10), |
| 2215 | IsRefPtrTo(profile2))) |
| 2216 | .WillRepeatedly(Return(false)); |
| 2217 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2218 | |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 2219 | // Security. |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 2220 | service2->SetSecurity(Service::kCryptoAes, true, true); |
| 2221 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2222 | |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 2223 | // PriorityWithinTechnology. |
| 2224 | service10->SetPriorityWithinTechnology(1, nullptr); |
| 2225 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2226 | service2->SetPriorityWithinTechnology(2, nullptr); |
| 2227 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2228 | |
| 2229 | // Technology. |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 2230 | EXPECT_CALL(*service2.get(), technology()) |
| 2231 | .WillRepeatedly(Return((Technology::kWifi))); |
| 2232 | EXPECT_CALL(*service10.get(), technology()) |
| 2233 | .WillRepeatedly(Return(Technology::kEthernet)); |
| 2234 | |
| 2235 | technology_order_for_sorting_ = {Technology::kEthernet, Technology::kWifi}; |
| 2236 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2237 | |
| 2238 | technology_order_for_sorting_ = {Technology::kWifi, Technology::kEthernet}; |
| 2239 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2240 | |
| 2241 | // Priority. |
| 2242 | service2->SetPriority(1, nullptr); |
| 2243 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 2244 | service10->SetPriority(2, nullptr); |
| 2245 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 2246 | |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 2247 | // A service that has been connected before should be considered |
| 2248 | // above a service that neither been connected to before nor has |
| 2249 | // has managed credentials. |
| 2250 | service2->has_ever_connected_ = true; |
| 2251 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2252 | |
| 2253 | // If one service has been connected to before, and the other is managed |
| 2254 | // by Chrome they should rank same, so the priority will be considered |
| 2255 | // instead. |
| 2256 | service10->managed_credentials_ = true; |
| 2257 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2258 | service2->SetPriority(3, nullptr); |
| 2259 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2260 | |
| 2261 | // A service with managed credentials should be considered above one that |
| 2262 | // has neither been connected to before nor has managed credentials. |
| 2263 | service2->has_ever_connected_ = false; |
Paul Stewart | 22ce765 | 2014-10-15 21:26:44 -0700 | [diff] [blame] | 2264 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2265 | |
| 2266 | // Auto-connect. |
| 2267 | service2->SetAutoConnect(true); |
| 2268 | service10->SetAutoConnect(false); |
| 2269 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2270 | |
| 2271 | // Test is-dependent-on. |
| 2272 | EXPECT_CALL(*service10.get(), |
| 2273 | IsDependentOn(IsRefPtrTo(service2.get()))) |
| 2274 | .WillOnce(Return(true)) |
| 2275 | .WillOnce(Return(false)); |
| 2276 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2277 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2278 | |
| 2279 | // It doesn't make sense to have is-dependent-on ranking comparison in any of |
| 2280 | // the remaining subtests below. Reset to the default. |
| 2281 | EXPECT_CALL(*service10.get(), IsDependentOn(_)).WillRepeatedly(Return(false)); |
| 2282 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2283 | |
| 2284 | // Connectable. |
| 2285 | service10->SetConnectable(true); |
| 2286 | service2->SetConnectable(false); |
| 2287 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2288 | |
| 2289 | // IsFailed. |
| 2290 | EXPECT_CALL(*service2.get(), state()) |
| 2291 | .WillRepeatedly(Return(Service::kStateIdle)); |
| 2292 | EXPECT_CALL(*service2.get(), IsFailed()) |
| 2293 | .WillRepeatedly(Return(false)); |
| 2294 | EXPECT_CALL(*service10.get(), state()) |
| 2295 | .WillRepeatedly(Return(Service::kStateFailure)); |
| 2296 | EXPECT_CALL(*service10.get(), IsFailed()) |
| 2297 | .WillRepeatedly(Return(true)); |
| 2298 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2299 | |
| 2300 | // Connecting. |
| 2301 | EXPECT_CALL(*service10.get(), state()) |
| 2302 | .WillRepeatedly(Return(Service::kStateAssociating)); |
| 2303 | EXPECT_CALL(*service10.get(), IsConnecting()) |
| 2304 | .WillRepeatedly(Return(true)); |
| 2305 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2306 | |
| 2307 | // Connected-but-portalled preferred over unconnected. |
| 2308 | EXPECT_CALL(*service2.get(), state()) |
| 2309 | .WillRepeatedly(Return(Service::kStatePortal)); |
| 2310 | EXPECT_CALL(*service2.get(), IsConnected()) |
| 2311 | .WillRepeatedly(Return(true)); |
| 2312 | EXPECT_TRUE(DefaultSortingOrderIs(service2, service10)); |
| 2313 | |
| 2314 | // Connected preferred over connected-but-portalled. |
| 2315 | service10->SetConnectable(false); |
| 2316 | service2->SetConnectable(true); |
| 2317 | EXPECT_CALL(*service10.get(), state()) |
| 2318 | .WillRepeatedly(Return(Service::kStateConnected)); |
| 2319 | EXPECT_CALL(*service10.get(), IsConnected()) |
| 2320 | .WillRepeatedly(Return(true)); |
| 2321 | EXPECT_TRUE(DefaultSortingOrderIs(service10, service2)); |
| 2322 | |
| 2323 | // Connectivity state ignored if this is specified. |
| 2324 | const bool kDoNotCompareConnectivityState = false; |
| 2325 | EXPECT_TRUE(SortingOrderIs(service2, service10, |
| 2326 | kDoNotCompareConnectivityState)); |
| 2327 | } |
| 2328 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 2329 | } // namespace shill |