mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -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/wifi.h" |
| 6 | |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 7 | #include <netinet/ether.h> |
| 8 | #include <linux/if.h> |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 9 | #include <sys/socket.h> |
| 10 | #include <linux/netlink.h> // Needs typedefs from sys/socket.h. |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 11 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 12 | #include <map> |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 13 | #include <set> |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 17 | #include <base/memory/ref_counted.h> |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 18 | #include <base/memory/scoped_ptr.h> |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 19 | #include <base/stringprintf.h> |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 20 | #include <base/string_number_conversions.h> |
| 21 | #include <base/string_util.h> |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 22 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 23 | #include <dbus-c++/dbus.h> |
Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 24 | #include <gmock/gmock.h> |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 26 | |
| 27 | #include "shill/dbus_adaptor.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 28 | #include "shill/event_dispatcher.h" |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 29 | #include "shill/ieee80211.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 30 | #include "shill/key_value_store.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 31 | #include "shill/manager.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 32 | #include "shill/mock_device.h" |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 33 | #include "shill/mock_device_info.h" |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 34 | #include "shill/mock_dhcp_config.h" |
| 35 | #include "shill/mock_dhcp_provider.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 36 | #include "shill/mock_manager.h" |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 37 | #include "shill/mock_metrics.h" |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 38 | #include "shill/mock_power_manager.h" |
| 39 | #include "shill/mock_power_manager_proxy.h" |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 40 | #include "shill/mock_profile.h" |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 41 | #include "shill/mock_rtnl_handler.h" |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 42 | #include "shill/mock_store.h" |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 43 | #include "shill/mock_supplicant_bss_proxy.h" |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 44 | #include "shill/mock_supplicant_interface_proxy.h" |
| 45 | #include "shill/mock_supplicant_process_proxy.h" |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 46 | #include "shill/mock_time.h" |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 47 | #include "shill/mock_wifi_service.h" |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 48 | #include "shill/nice_mock_control.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 49 | #include "shill/property_store_unittest.h" |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 50 | #include "shill/proxy_factory.h" |
| 51 | #include "shill/wifi_endpoint.h" |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 52 | #include "shill/wifi_service.h" |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 53 | #include "shill/wpa_supplicant.h" |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 54 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 55 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 56 | using std::map; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 57 | using std::set; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 58 | using std::string; |
| 59 | using std::vector; |
| 60 | using ::testing::_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 61 | using ::testing::AnyNumber; |
| 62 | using ::testing::DefaultValue; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 63 | using ::testing::DoAll; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 64 | using ::testing::InSequence; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 65 | using ::testing::Invoke; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 66 | using ::testing::Mock; |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 67 | using ::testing::NiceMock; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 68 | using ::testing::Return; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 69 | using ::testing::SaveArg; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 70 | using ::testing::SetArgumentPointee; |
| 71 | using ::testing::StrEq; |
| 72 | using ::testing::StrictMock; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 73 | using ::testing::Test; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 74 | using ::testing::Throw; |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 75 | using ::testing::Values; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 76 | |
| 77 | namespace shill { |
| 78 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 79 | class WiFiPropertyTest : public PropertyStoreTest { |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 80 | public: |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 81 | WiFiPropertyTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 82 | : device_(new WiFi(control_interface(), |
| 83 | NULL, NULL, NULL, "wifi", "", 0)) { |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 84 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 85 | virtual ~WiFiPropertyTest() {} |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 86 | |
| 87 | protected: |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 88 | WiFiRefPtr device_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 91 | TEST_F(WiFiPropertyTest, Contains) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 92 | EXPECT_TRUE(device_->store().Contains(flimflam::kNameProperty)); |
| 93 | EXPECT_FALSE(device_->store().Contains("")); |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 94 | } |
| 95 | |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 96 | TEST_F(WiFiPropertyTest, SetProperty) { |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 97 | { |
| 98 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 99 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 100 | device_->mutable_store(), |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 101 | flimflam::kBgscanSignalThresholdProperty, |
| 102 | PropertyStoreTest::kInt32V, |
| 103 | &error)); |
| 104 | } |
| 105 | { |
| 106 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 107 | EXPECT_TRUE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 108 | flimflam::kScanIntervalProperty, |
| 109 | PropertyStoreTest::kUint16V, |
| 110 | &error)); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 111 | } |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 112 | // 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] | 113 | { |
| 114 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 115 | EXPECT_FALSE(DBusAdaptor::SetProperty(device_->mutable_store(), |
| 116 | flimflam::kScanningProperty, |
| 117 | PropertyStoreTest::kBoolV, |
| 118 | &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 119 | EXPECT_EQ(invalid_args(), error.name()); |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 120 | } |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 121 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 122 | { |
| 123 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 124 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 125 | device_->mutable_store(), |
| 126 | flimflam::kBgscanMethodProperty, |
| 127 | DBusAdaptor::StringToVariant( |
| 128 | wpa_supplicant::kNetworkBgscanMethodSimple), |
| 129 | &error)); |
| 130 | } |
| 131 | |
| 132 | { |
| 133 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 134 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 135 | device_->mutable_store(), |
| 136 | flimflam::kBgscanMethodProperty, |
| 137 | DBusAdaptor::StringToVariant("not a real scan method"), |
| 138 | &error)); |
| 139 | } |
| 140 | } |
| 141 | |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 142 | TEST_F(WiFiPropertyTest, ClearDerivedProperty) { |
| 143 | EXPECT_NE(wpa_supplicant::kNetworkBgscanMethodLearn, |
| 144 | WiFi::kDefaultBgscanMethod); |
| 145 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, device_->bgscan_method_); |
| 146 | |
| 147 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 148 | EXPECT_TRUE(DBusAdaptor::SetProperty( |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 149 | device_->mutable_store(), |
| 150 | flimflam::kBgscanMethodProperty, |
| 151 | DBusAdaptor::StringToVariant( |
| 152 | wpa_supplicant::kNetworkBgscanMethodLearn), |
| 153 | &error)); |
| 154 | EXPECT_EQ(wpa_supplicant::kNetworkBgscanMethodLearn, device_->bgscan_method_); |
| 155 | |
| 156 | EXPECT_TRUE(DBusAdaptor::ClearProperty( |
| 157 | device_->mutable_store(), flimflam::kBgscanMethodProperty, &error)); |
| 158 | EXPECT_EQ(WiFi::kDefaultBgscanMethod, device_->bgscan_method_); |
| 159 | } |
| 160 | |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 161 | class WiFiMainTest : public ::testing::TestWithParam<string> { |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 162 | public: |
| 163 | WiFiMainTest() |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 164 | : manager_(&control_interface_, NULL, &metrics_, &glib_), |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 165 | device_info_(&control_interface_, &dispatcher_, &metrics_, &manager_), |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 166 | wifi_(new WiFi(&control_interface_, |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 167 | &dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 168 | &metrics_, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 169 | &manager_, |
| 170 | kDeviceName, |
| 171 | kDeviceAddress, |
| 172 | 0)), |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 173 | supplicant_process_proxy_(new NiceMock<MockSupplicantProcessProxy>()), |
| 174 | supplicant_interface_proxy_( |
| 175 | new NiceMock<MockSupplicantInterfaceProxy>(wifi_)), |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 176 | supplicant_bss_proxy_( |
| 177 | new NiceMock<MockSupplicantBSSProxy>()), |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 178 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
| 179 | &dispatcher_, |
| 180 | &dhcp_provider_, |
| 181 | kDeviceName, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 182 | kHostName, |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 183 | &glib_)), |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 184 | proxy_factory_(this), |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 185 | power_manager_(new MockPowerManager(&proxy_factory_)) { |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 186 | ::testing::DefaultValue< ::DBus::Path>::Set("/default/path"); |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 187 | // Except for WiFiServices created via WiFi::GetService, we expect |
| 188 | // that any WiFiService has been registered with the Manager. So |
| 189 | // default Manager.HasService to true, to make the common case |
| 190 | // easy. |
| 191 | ON_CALL(manager_, HasService(_)). |
| 192 | WillByDefault(Return(true)); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 193 | |
| 194 | ON_CALL(dhcp_provider_, CreateConfig(_, _)). |
| 195 | WillByDefault(Return(dhcp_config_)); |
| 196 | ON_CALL(*dhcp_config_.get(), RequestIP()). |
| 197 | WillByDefault(Return(true)); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 198 | |
| 199 | // |manager_| takes ownership of |power_manager_|. |
| 200 | manager_.set_power_manager(power_manager_); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 201 | |
| 202 | wifi_->time_ = &time_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 203 | } |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 204 | |
| 205 | virtual void SetUp() { |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 206 | wifi_->proxy_factory_ = &proxy_factory_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 207 | static_cast<Device *>(wifi_)->rtnl_handler_ = &rtnl_handler_; |
| 208 | wifi_->set_dhcp_provider(&dhcp_provider_); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 209 | ON_CALL(manager_, device_info()). |
| 210 | WillByDefault(Return(&device_info_)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 211 | EXPECT_CALL(manager_, DeregisterService(_)).Times(AnyNumber()); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 212 | EXPECT_CALL(*supplicant_bss_proxy_, Die()).Times(AnyNumber()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | virtual void TearDown() { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 216 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
Gary Morain | 9100112 | 2012-02-29 16:22:26 -0800 | [diff] [blame] | 217 | EXPECT_CALL(*power_manager_, RemoveStateChangeCallback(wifi_->UniqueName())) |
| 218 | .Times(AnyNumber()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 219 | wifi_->SelectService(NULL); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 220 | if (supplicant_bss_proxy_.get()) { |
| 221 | EXPECT_CALL(*supplicant_bss_proxy_, Die()); |
| 222 | } |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 223 | wifi_->proxy_factory_ = NULL; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 224 | // must Stop WiFi instance, to clear its list of services. |
| 225 | // otherwise, the WiFi instance will not be deleted. (because |
| 226 | // services reference a WiFi instance, creating a cycle.) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 227 | wifi_->Stop(NULL, ResultCallback()); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 228 | wifi_->set_dhcp_provider(NULL); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 229 | } |
| 230 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 231 | protected: |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 232 | typedef scoped_refptr<MockWiFiService> MockWiFiServiceRefPtr; |
| 233 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 234 | class TestProxyFactory : public ProxyFactory { |
| 235 | public: |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 236 | explicit TestProxyFactory(WiFiMainTest *test); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 237 | |
| 238 | virtual SupplicantProcessProxyInterface *CreateSupplicantProcessProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 239 | const char */*dbus_path*/, const char */*dbus_addr*/) { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 240 | return test_->supplicant_process_proxy_.release(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | virtual SupplicantInterfaceProxyInterface *CreateSupplicantInterfaceProxy( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 244 | const WiFiRefPtr &/*wifi*/, |
| 245 | const DBus::Path &/*object_path*/, |
| 246 | const char */*dbus_addr*/) { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 247 | return test_->supplicant_interface_proxy_.release(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 248 | } |
| 249 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 250 | MOCK_METHOD3(CreateSupplicantBSSProxy, |
| 251 | SupplicantBSSProxyInterface *( |
| 252 | WiFiEndpoint *wifi_endpoint, |
| 253 | const DBus::Path &object_path, |
| 254 | const char *dbus_addr)); |
| 255 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 256 | virtual PowerManagerProxyInterface *CreatePowerManagerProxy( |
| 257 | PowerManagerProxyDelegate */*delegate*/) { |
| 258 | return new MockPowerManagerProxy(); |
| 259 | } |
| 260 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 261 | private: |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 262 | SupplicantBSSProxyInterface *CreateSupplicantBSSProxyInternal( |
| 263 | WiFiEndpoint */*wifi_endpoint*/, |
| 264 | const DBus::Path &/*object_path*/, |
| 265 | const char */*dbus_addr*/) { |
| 266 | return test_->supplicant_bss_proxy_.release(); |
| 267 | } |
| 268 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 269 | WiFiMainTest *test_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 272 | WiFiServiceRefPtr CreateServiceForEndpoint(const WiFiEndpoint &endpoint) { |
| 273 | bool hidden_ssid = false; |
| 274 | return wifi_->CreateServiceForEndpoint(endpoint, hidden_ssid); |
| 275 | } |
| 276 | const WiFiServiceRefPtr &GetCurrentService() { |
| 277 | return wifi_->current_service_; |
| 278 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 279 | const WiFi::EndpointMap &GetEndpointMap() { |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 280 | return wifi_->endpoint_by_rpcid_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 281 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 282 | const WiFiServiceRefPtr &GetPendingService() { |
| 283 | return wifi_->pending_service_; |
| 284 | } |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 285 | const vector<WiFiServiceRefPtr> &GetServices() { |
| 286 | return wifi_->services_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 287 | } |
| 288 | // note: the tests need the proxies referenced by WiFi (not the |
| 289 | // proxies instantiated by WiFiMainTest), to ensure that WiFi |
| 290 | // sets up its proxies correctly. |
| 291 | SupplicantProcessProxyInterface *GetSupplicantProcessProxy() { |
| 292 | return wifi_->supplicant_process_proxy_.get(); |
| 293 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 294 | MockSupplicantInterfaceProxy *GetSupplicantInterfaceProxy() { |
| 295 | return dynamic_cast<MockSupplicantInterfaceProxy *>( |
| 296 | wifi_->supplicant_interface_proxy_.get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 297 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 298 | const string &GetSupplicantState() { |
| 299 | return wifi_->supplicant_state_; |
| 300 | } |
| 301 | void InitiateConnect(WiFiServiceRefPtr service) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 302 | map<string, ::DBus::Variant> params; |
| 303 | wifi_->ConnectTo(service, params); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 304 | } |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 305 | void InitiateDisconnect(WiFiServiceRefPtr service) { |
| 306 | wifi_->DisconnectFrom(service); |
| 307 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 308 | WiFiEndpointRefPtr MakeEndpoint(const string &ssid, const string &bssid) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 309 | return WiFiEndpoint::MakeOpenEndpoint( |
| 310 | &proxy_factory_, NULL, ssid, bssid, 0, 0); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 311 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 312 | MockWiFiServiceRefPtr MakeMockService() { |
| 313 | vector<uint8_t> ssid(1, 'a'); |
| 314 | return new MockWiFiService( |
| 315 | &control_interface_, |
| 316 | &dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 317 | &metrics_, |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 318 | &manager_, |
| 319 | wifi_, |
| 320 | ssid, |
| 321 | flimflam::kModeManaged, |
| 322 | flimflam::kSecurityNone, |
| 323 | false); |
| 324 | } |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 325 | void RemoveBSS(const ::DBus::Path &bss_path); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 326 | void ReportBSS(const ::DBus::Path &bss_path, |
| 327 | const string &ssid, |
| 328 | const string &bssid, |
| 329 | int16_t signal_strength, |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 330 | uint16 frequency, |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 331 | const char *mode); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 332 | void ClearCachedCredentials() { |
| 333 | wifi_->ClearCachedCredentials(); |
| 334 | } |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 335 | void ReportIPConfigComplete() { |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 336 | wifi_->OnIPConfigUpdated(dhcp_config_, true); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 337 | } |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 338 | void ReportLinkUp() { |
| 339 | wifi_->LinkEvent(IFF_LOWER_UP, IFF_LOWER_UP); |
| 340 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 341 | void ReportScanDone() { |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 342 | wifi_->ScanDoneTask(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 343 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 344 | void ReportCurrentBSSChanged(const string &new_bss) { |
| 345 | wifi_->CurrentBSSChanged(new_bss); |
| 346 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 347 | void ReportStateChanged(const string &new_state) { |
| 348 | wifi_->StateChanged(new_state); |
| 349 | } |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 350 | void StartWiFi() { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 351 | EXPECT_CALL(*power_manager_, AddStateChangeCallback(wifi_->UniqueName(), _)) |
| 352 | .WillOnce(SaveArg<1>(&power_state_callback_)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 353 | wifi_->Start(NULL, ResultCallback()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 354 | } |
| 355 | void StopWiFi() { |
Gary Morain | 9100112 | 2012-02-29 16:22:26 -0800 | [diff] [blame] | 356 | EXPECT_CALL(*power_manager_, |
| 357 | RemoveStateChangeCallback(wifi_->UniqueName())); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 358 | wifi_->Stop(NULL, ResultCallback()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 359 | } |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 360 | void GetOpenService(const char *service_type, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 361 | const char *ssid, |
| 362 | const char *mode, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 363 | Error *result) { |
| 364 | GetServiceInner(service_type, ssid, mode, NULL, NULL, false, result); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 365 | } |
| 366 | void GetService(const char *service_type, |
| 367 | const char *ssid, |
| 368 | const char *mode, |
| 369 | const char *security, |
| 370 | const char *passphrase, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 371 | Error *result) { |
| 372 | GetServiceInner(service_type, ssid, mode, security, passphrase, false, |
| 373 | result); |
| 374 | } |
| 375 | WiFiServiceRefPtr GetServiceInner(const char *service_type, |
| 376 | const char *ssid, |
| 377 | const char *mode, |
| 378 | const char *security, |
| 379 | const char *passphrase, |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 380 | bool allow_hidden, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 381 | Error *result) { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 382 | map<string, ::DBus::Variant> args; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 383 | // in general, we want to avoid D-Bus specific code for any RPCs |
| 384 | // that come in via adaptors. we make an exception here, because |
| 385 | // calls to GetWifiService are rerouted from the Manager object to |
| 386 | // the Wifi class. |
| 387 | if (service_type != NULL) |
| 388 | args[flimflam::kTypeProperty].writer().append_string(service_type); |
| 389 | if (ssid != NULL) |
| 390 | args[flimflam::kSSIDProperty].writer().append_string(ssid); |
| 391 | if (mode != NULL) |
| 392 | args[flimflam::kModeProperty].writer().append_string(mode); |
| 393 | if (security != NULL) |
| 394 | args[flimflam::kSecurityProperty].writer().append_string(security); |
| 395 | if (passphrase != NULL) |
| 396 | args[flimflam::kPassphraseProperty].writer().append_string(passphrase); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 397 | if (!allow_hidden) |
| 398 | args[flimflam::kWifiHiddenSsid].writer().append_bool(false); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 399 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 400 | Error e; |
| 401 | KeyValueStore args_kv; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 402 | DBusAdaptor::ArgsToKeyValueStore(args, &args_kv, &e); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 403 | return wifi_->GetService(args_kv, result); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 404 | } |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 405 | |
| 406 | WiFiServiceRefPtr GetServiceWithKeyValues(const KeyValueStore &args, |
| 407 | Error *result) { |
| 408 | return wifi_->GetService(args, result); |
| 409 | } |
| 410 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 411 | WiFiServiceRefPtr FindService(const vector<uint8_t> &ssid, |
| 412 | const string &mode, |
| 413 | const string &security) { |
| 414 | return wifi_->FindService(ssid, mode, security); |
| 415 | } |
| 416 | bool LoadHiddenServices(StoreInterface *storage) { |
| 417 | return wifi_->LoadHiddenServices(storage); |
| 418 | } |
| 419 | void SetupHiddenStorage(MockStore *storage, const string &ssid, string *id) { |
| 420 | const string hex_ssid = base::HexEncode(ssid.data(), ssid.size()); |
| 421 | *id = StringToLowerASCII(base::StringPrintf("%s_%s_%s_%s_%s", |
| 422 | flimflam::kTypeWifi, |
| 423 | kDeviceAddress, |
| 424 | hex_ssid.c_str(), |
| 425 | flimflam::kModeManaged, |
| 426 | flimflam::kSecurityNone)); |
| 427 | const char *groups[] = { id->c_str() }; |
| 428 | EXPECT_CALL(*storage, GetGroupsWithKey(flimflam::kWifiHiddenSsid)) |
| 429 | .WillRepeatedly(Return(set<string>(groups, groups + 1))); |
| 430 | EXPECT_CALL(*storage, GetBool(StrEq(*id), flimflam::kWifiHiddenSsid, _)) |
| 431 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(true), Return(true))); |
| 432 | EXPECT_CALL(*storage, GetString(StrEq(*id), flimflam::kSSIDProperty, _)) |
| 433 | .WillRepeatedly(DoAll(SetArgumentPointee<2>(hex_ssid), Return(true))); |
| 434 | } |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 435 | |
| 436 | NiceMockControl *control_interface() { |
| 437 | return &control_interface_; |
| 438 | } |
| 439 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 440 | MockManager *manager() { |
| 441 | return &manager_; |
| 442 | } |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 443 | |
| 444 | MockDeviceInfo *device_info() { |
| 445 | return &device_info_; |
| 446 | } |
| 447 | |
| 448 | MockDHCPProvider *dhcp_provider() { |
| 449 | return &dhcp_provider_; |
| 450 | } |
| 451 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 452 | const PowerManager::PowerStateCallback &power_state_callback() const { |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 453 | return power_state_callback_; |
| 454 | } |
| 455 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 456 | const WiFiConstRefPtr wifi() const { |
| 457 | return wifi_; |
| 458 | } |
| 459 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 460 | TestProxyFactory *proxy_factory() { |
| 461 | return &proxy_factory_; |
| 462 | } |
| 463 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 464 | EventDispatcher dispatcher_; |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 465 | NiceMock<MockRTNLHandler> rtnl_handler_; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 466 | MockTime time_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 467 | |
| 468 | private: |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 469 | NiceMockControl control_interface_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 470 | MockMetrics metrics_; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 471 | MockGLib glib_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 472 | MockManager manager_; |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 473 | MockDeviceInfo device_info_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 474 | WiFiRefPtr wifi_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 475 | |
| 476 | // protected fields interspersed between private fields, due to |
| 477 | // initialization order |
| 478 | protected: |
| 479 | static const char kDeviceName[]; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 480 | static const char kDeviceAddress[]; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 481 | static const char kHostName[]; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 482 | static const char kNetworkModeAdHoc[]; |
| 483 | static const char kNetworkModeInfrastructure[]; |
| 484 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 485 | scoped_ptr<MockSupplicantProcessProxy> supplicant_process_proxy_; |
| 486 | scoped_ptr<MockSupplicantInterfaceProxy> supplicant_interface_proxy_; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 487 | scoped_ptr<MockSupplicantBSSProxy> supplicant_bss_proxy_; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 488 | MockDHCPProvider dhcp_provider_; |
| 489 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 490 | |
| 491 | private: |
| 492 | TestProxyFactory proxy_factory_; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 493 | MockPowerManager *power_manager_; |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 494 | PowerManager::PowerStateCallback power_state_callback_; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | const char WiFiMainTest::kDeviceName[] = "wlan0"; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 498 | const char WiFiMainTest::kDeviceAddress[] = "000102030405"; |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 499 | const char WiFiMainTest::kHostName[] = "hostname"; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 500 | const char WiFiMainTest::kNetworkModeAdHoc[] = "ad-hoc"; |
| 501 | const char WiFiMainTest::kNetworkModeInfrastructure[] = "infrastructure"; |
| 502 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 503 | void WiFiMainTest::RemoveBSS(const ::DBus::Path &bss_path) { |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 504 | wifi_->BSSRemovedTask(bss_path); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 505 | } |
| 506 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 507 | void WiFiMainTest::ReportBSS(const ::DBus::Path &bss_path, |
| 508 | const string &ssid, |
| 509 | const string &bssid, |
| 510 | int16_t signal_strength, |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 511 | uint16 frequency, |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 512 | const char *mode) { |
| 513 | map<string, ::DBus::Variant> bss_properties; |
| 514 | |
| 515 | { |
| 516 | DBus::MessageIter writer(bss_properties["SSID"].writer()); |
| 517 | writer << vector<uint8_t>(ssid.begin(), ssid.end()); |
| 518 | } |
| 519 | { |
| 520 | string bssid_nosep; |
| 521 | vector<uint8_t> bssid_bytes; |
| 522 | RemoveChars(bssid, ":", &bssid_nosep); |
| 523 | base::HexStringToBytes(bssid_nosep, &bssid_bytes); |
| 524 | |
| 525 | DBus::MessageIter writer(bss_properties["BSSID"].writer()); |
| 526 | writer << bssid_bytes; |
| 527 | } |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 528 | bss_properties[wpa_supplicant::kBSSPropertySignal].writer(). |
| 529 | append_int16(signal_strength); |
| 530 | bss_properties[wpa_supplicant::kBSSPropertyFrequency].writer(). |
| 531 | append_uint16(frequency); |
| 532 | bss_properties[wpa_supplicant::kBSSPropertyMode].writer().append_string(mode); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 533 | wifi_->BSSAddedTask(bss_path, bss_properties); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 534 | } |
| 535 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 536 | WiFiMainTest::TestProxyFactory::TestProxyFactory(WiFiMainTest *test) |
| 537 | : test_(test) { |
| 538 | EXPECT_CALL(*this, CreateSupplicantBSSProxy(_, _, _)).Times(AnyNumber()); |
| 539 | ON_CALL(*this, CreateSupplicantBSSProxy(_, _, _)) |
| 540 | .WillByDefault( |
| 541 | Invoke(this, (&TestProxyFactory::CreateSupplicantBSSProxyInternal))); |
| 542 | } |
| 543 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 544 | TEST_F(WiFiMainTest, ProxiesSetUpDuringStart) { |
| 545 | EXPECT_TRUE(GetSupplicantProcessProxy() == NULL); |
| 546 | EXPECT_TRUE(GetSupplicantInterfaceProxy() == NULL); |
| 547 | |
| 548 | StartWiFi(); |
| 549 | EXPECT_FALSE(GetSupplicantProcessProxy() == NULL); |
| 550 | EXPECT_FALSE(GetSupplicantInterfaceProxy() == NULL); |
| 551 | } |
| 552 | |
| 553 | TEST_F(WiFiMainTest, CleanStart) { |
| 554 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)); |
| 555 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)) |
| 556 | .Times(AnyNumber()) |
| 557 | .WillRepeatedly(Throw( |
| 558 | DBus::Error( |
| 559 | "fi.w1.wpa_supplicant1.InterfaceUnknown", |
| 560 | "test threw fi.w1.wpa_supplicant1.InterfaceUnknown"))); |
| 561 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 562 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 563 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | TEST_F(WiFiMainTest, Restart) { |
| 567 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)) |
| 568 | .Times(AnyNumber()) |
| 569 | .WillRepeatedly(Throw( |
| 570 | DBus::Error( |
| 571 | "fi.w1.wpa_supplicant1.InterfaceExists", |
| 572 | "test thew fi.w1.wpa_supplicant1.InterfaceExists"))); |
| 573 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)); |
| 574 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 575 | StartWiFi(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 576 | dispatcher_.DispatchPendingEvents(); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | TEST_F(WiFiMainTest, StartClearsState) { |
| 580 | EXPECT_CALL(*supplicant_interface_proxy_, RemoveAllNetworks()); |
| 581 | EXPECT_CALL(*supplicant_interface_proxy_, FlushBSS(_)); |
| 582 | StartWiFi(); |
| 583 | } |
| 584 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 585 | TEST_F(WiFiMainTest, PowerChangeToResumeStartsScanWhenIdle) { |
| 586 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 587 | StartWiFi(); |
| 588 | dispatcher_.DispatchPendingEvents(); |
| 589 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 590 | ReportScanDone(); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 591 | ASSERT_FALSE(power_state_callback().is_null()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 592 | ASSERT_TRUE(wifi()->IsIdle()); |
| 593 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 594 | power_state_callback().Run(PowerManagerProxyDelegate::kOn); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 595 | dispatcher_.DispatchPendingEvents(); |
| 596 | } |
| 597 | |
| 598 | TEST_F(WiFiMainTest, PowerChangeToSuspendDoesNotStartScan) { |
| 599 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 600 | StartWiFi(); |
| 601 | dispatcher_.DispatchPendingEvents(); |
| 602 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 603 | ASSERT_FALSE(power_state_callback().is_null()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 604 | ASSERT_TRUE(wifi()->IsIdle()); |
| 605 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 606 | power_state_callback().Run(PowerManagerProxyDelegate::kStandby); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 607 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 608 | power_state_callback().Run(PowerManagerProxyDelegate::kMem); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 609 | dispatcher_.DispatchPendingEvents(); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 610 | power_state_callback().Run(PowerManagerProxyDelegate::kDisk); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 611 | dispatcher_.DispatchPendingEvents(); |
| 612 | } |
| 613 | |
| 614 | TEST_F(WiFiMainTest, PowerChangeDoesNotStartScanWhenNotIdle) { |
| 615 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(_)); |
| 616 | StartWiFi(); |
| 617 | |
| 618 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 619 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 620 | Error error; |
| 621 | service->AddEndpoint(ap); |
| 622 | service->AutoConnect(); |
| 623 | EXPECT_FALSE(wifi()->IsIdle()); |
| 624 | dispatcher_.DispatchPendingEvents(); |
| 625 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy_); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 626 | ASSERT_FALSE(power_state_callback().is_null()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 627 | ASSERT_FALSE(wifi()->IsIdle()); |
| 628 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Scan(_)).Times(0); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 629 | power_state_callback().Run(PowerManagerProxyDelegate::kOn); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 630 | dispatcher_.DispatchPendingEvents(); |
| 631 | } |
| 632 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 633 | TEST_F(WiFiMainTest, ScanResults) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 634 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 635 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 636 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 637 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 638 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 639 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 640 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 641 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 642 | "bss3", "ssid3", "00:00:00:00:00:03", 3, 0, kNetworkModeInfrastructure); |
| 643 | const uint16 frequency = 2412; |
| 644 | ReportBSS("bss4", "ssid4", "00:00:00:00:00:04", 4, frequency, |
| 645 | kNetworkModeAdHoc); |
| 646 | |
| 647 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 648 | EXPECT_EQ(5, endpoints_by_rpcid.size()); |
| 649 | |
| 650 | WiFi::EndpointMap::const_iterator i; |
| 651 | WiFiEndpointRefPtr endpoint; |
| 652 | for (i = endpoints_by_rpcid.begin(); |
| 653 | i != endpoints_by_rpcid.end(); |
| 654 | ++i) { |
| 655 | if (i->second->bssid_string() == "00:00:00:00:00:04") |
| 656 | break; |
| 657 | } |
| 658 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 659 | EXPECT_EQ(4, i->second->signal_strength()); |
| 660 | EXPECT_EQ(frequency, i->second->frequency()); |
| 661 | EXPECT_EQ("adhoc", i->second->network_mode()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | TEST_F(WiFiMainTest, ScanResultsWithUpdates) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 665 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 666 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 667 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 668 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 669 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 670 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 671 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 672 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 673 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 674 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 675 | "bss1", "ssid1", "00:00:00:00:00:01", 3, 0, kNetworkModeInfrastructure); |
| 676 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 4, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 677 | |
| 678 | const WiFi::EndpointMap &endpoints_by_rpcid = GetEndpointMap(); |
| 679 | EXPECT_EQ(3, endpoints_by_rpcid.size()); |
| 680 | |
| 681 | WiFi::EndpointMap::const_iterator i; |
| 682 | WiFiEndpointRefPtr endpoint; |
| 683 | for (i = endpoints_by_rpcid.begin(); |
| 684 | i != endpoints_by_rpcid.end(); |
| 685 | ++i) { |
| 686 | if (i->second->bssid_string() == "00:00:00:00:00:00") |
| 687 | break; |
| 688 | } |
| 689 | ASSERT_TRUE(i != endpoints_by_rpcid.end()); |
| 690 | EXPECT_EQ(4, i->second->signal_strength()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | TEST_F(WiFiMainTest, ScanCompleted) { |
| 694 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 695 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 696 | .Times(3); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 697 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 698 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 699 | "bss1", "ssid1", "00:00:00:00:00:01", 1, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 700 | ReportBSS( |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 701 | "bss2", "ssid2", "00:00:00:00:00:02", 2, 0, kNetworkModeInfrastructure); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 702 | ReportScanDone(); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 703 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 704 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 705 | // BSSes with SSIDs that start with NULL should be filtered. |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 706 | ReportBSS("bss3", string(1, 0), "00:00:00:00:00:03", 3, 0, kNetworkModeAdHoc); |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 707 | EXPECT_EQ(3, GetEndpointMap().size()); |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 708 | EXPECT_EQ(3, GetServices().size()); |
| 709 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 710 | // BSSes with empty SSIDs should be filtered. |
| 711 | ReportBSS("bss3", string(), "00:00:00:00:00:03", 3, 0, kNetworkModeAdHoc); |
| 712 | EXPECT_EQ(3, GetEndpointMap().size()); |
| 713 | EXPECT_EQ(3, GetServices().size()); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | TEST_F(WiFiMainTest, EndpointGroupingTogether) { |
| 717 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 718 | |
| 719 | InSequence s; |
| 720 | EXPECT_CALL(*manager(), RegisterService(_)); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 721 | EXPECT_CALL(*manager(), HasService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 722 | EXPECT_CALL(*manager(), UpdateService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 723 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 724 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 725 | ReportScanDone(); |
| 726 | EXPECT_EQ(1, GetServices().size()); |
| 727 | } |
| 728 | |
| 729 | TEST_F(WiFiMainTest, EndpointGroupingDifferentSSID) { |
| 730 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 731 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 732 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 733 | ReportBSS("bss0", "ssid1", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 734 | ReportBSS("bss1", "ssid2", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 735 | ReportScanDone(); |
| 736 | EXPECT_EQ(2, GetServices().size()); |
| 737 | } |
| 738 | |
| 739 | TEST_F(WiFiMainTest, EndpointGroupingDifferentMode) { |
| 740 | StartWiFi(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 741 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 742 | .Times(2); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 743 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 744 | ReportBSS("bss1", "ssid", "00:00:00:00:00:01", 0, 0, |
| 745 | kNetworkModeInfrastructure); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 746 | ReportScanDone(); |
| 747 | EXPECT_EQ(2, GetServices().size()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 748 | } |
| 749 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 750 | TEST_F(WiFiMainTest, NonExistentBSSRemoved) { |
| 751 | // Removal of non-existent BSS should not cause a crash. |
| 752 | StartWiFi(); |
| 753 | RemoveBSS("bss0"); |
| 754 | EXPECT_EQ(0, GetServices().size()); |
| 755 | } |
| 756 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 757 | TEST_F(WiFiMainTest, BSSWithEmptySSIDRemoved) { |
| 758 | // Removal of BSS with an empty SSID should not cause a crash. |
| 759 | ReportBSS("bss", string(), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 760 | StartWiFi(); |
| 761 | RemoveBSS("bss"); |
| 762 | EXPECT_EQ(0, GetServices().size()); |
| 763 | } |
| 764 | |
| 765 | TEST_F(WiFiMainTest, BSSWithNullSSIDRemoved) { |
| 766 | // Removal of BSS with a NULL SSID should not cause a crash. |
| 767 | ReportBSS("bss", string(1, 0), "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
| 768 | StartWiFi(); |
| 769 | RemoveBSS("bss"); |
| 770 | EXPECT_EQ(0, GetServices().size()); |
| 771 | } |
| 772 | |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 773 | TEST_F(WiFiMainTest, LoneBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 774 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 775 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 776 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 777 | ReportScanDone(); |
| 778 | EXPECT_EQ(1, GetServices().size()); |
| 779 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 780 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 781 | EXPECT_CALL(*manager(), DeregisterService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 782 | RemoveBSS("bss0"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 783 | EXPECT_TRUE(GetServices().empty()); |
| 784 | } |
| 785 | |
| 786 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 787 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 788 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 789 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 790 | ReportScanDone(); |
| 791 | ReportCurrentBSSChanged("bss0"); |
| 792 | |
| 793 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 794 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 795 | RemoveBSS("bss0"); |
| 796 | EXPECT_TRUE(GetServices().empty()); |
| 797 | } |
| 798 | |
| 799 | TEST_F(WiFiMainTest, LoneBSSRemovedWhileConnectedToHidden) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 800 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 801 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 802 | StartWiFi(); |
| 803 | |
| 804 | Error e; |
| 805 | WiFiServiceRefPtr service = |
| 806 | GetServiceInner(flimflam::kTypeWifi, "ssid", flimflam::kModeManaged, |
| 807 | NULL, NULL, true, &e); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 808 | EXPECT_EQ(1, GetServices().size()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 809 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 810 | ReportBSS("bss", "ssid", "00:00:00:00:00:01", 0, 0, |
| 811 | kNetworkModeInfrastructure); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 812 | ReportScanDone(); |
| 813 | ReportCurrentBSSChanged("bss"); |
| 814 | EXPECT_EQ(1, GetServices().size()); |
| 815 | |
| 816 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 817 | RemoveBSS("bss"); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 818 | EXPECT_EQ(1, GetServices().size()); |
| 819 | // Verify expectations now, because WiFi may call UpdateService when |
| 820 | // WiFi is Stop()-ed (during TearDown()). |
| 821 | Mock::VerifyAndClearExpectations(manager()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 822 | EXPECT_CALL(*manager(), DeregisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | TEST_F(WiFiMainTest, NonSolitaryBSSRemoved) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 826 | EXPECT_CALL(*manager(), RegisterService(_)); |
| 827 | EXPECT_CALL(*manager(), HasService(_)); |
| 828 | EXPECT_CALL(*manager(), UpdateService(_)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 829 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 830 | ReportBSS("bss0", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 831 | ReportBSS("bss1", "ssid", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 832 | ReportScanDone(); |
| 833 | EXPECT_EQ(1, GetServices().size()); |
| 834 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 835 | |
| 836 | EXPECT_CALL(*manager(), UpdateService(_)); |
| 837 | RemoveBSS("bss0"); |
| 838 | EXPECT_TRUE(GetServices().front()->IsVisible()); |
| 839 | EXPECT_EQ(1, GetServices().size()); |
| 840 | } |
| 841 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 842 | TEST_F(WiFiMainTest, Connect) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 843 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 844 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 845 | *supplicant_interface_proxy_; |
| 846 | |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 847 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 848 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 849 | ReportScanDone(); |
| 850 | |
| 851 | { |
| 852 | InSequence s; |
| 853 | DBus::Path fake_path("/fake/path"); |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 854 | WiFiService *service(GetServices().begin()->get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 855 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 856 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(_)) |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 857 | .WillOnce(Return(fake_path)); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 858 | EXPECT_CALL(supplicant_interface_proxy, SelectNetwork(fake_path)); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 859 | InitiateConnect(service); |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 860 | EXPECT_EQ(static_cast<Service *>(service), |
| 861 | wifi()->selected_service_.get()); |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 865 | TEST_F(WiFiMainTest, DisconnectPendingService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 866 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 867 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 868 | *supplicant_interface_proxy_; |
| 869 | |
| 870 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 871 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 872 | WiFiService *service(GetServices().begin()->get()); |
| 873 | InitiateConnect(service); |
| 874 | |
| 875 | EXPECT_FALSE(GetPendingService() == NULL); |
| 876 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 877 | InitiateDisconnect(service); |
| 878 | |
| 879 | EXPECT_TRUE(GetPendingService() == NULL); |
| 880 | } |
| 881 | |
| 882 | TEST_F(WiFiMainTest, DisconnectPendingServiceWithCurrent) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 883 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 884 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 885 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 886 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 887 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 888 | *supplicant_interface_proxy_; |
| 889 | |
| 890 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 891 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 892 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 893 | WiFiService *service0(GetServices()[0].get()); |
| 894 | WiFiService *service1(GetServices()[1].get()); |
| 895 | |
| 896 | InitiateConnect(service0); |
| 897 | ReportCurrentBSSChanged("bss0"); |
| 898 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 899 | InitiateConnect(service1); |
| 900 | |
| 901 | EXPECT_EQ(service0, GetCurrentService()); |
| 902 | EXPECT_EQ(service1, GetPendingService()); |
| 903 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 904 | InitiateDisconnect(service1); |
| 905 | |
| 906 | // |current_service_| will be unchanged until supplicant signals |
| 907 | // that CurrentBSS has changed. |
| 908 | EXPECT_EQ(service0, GetCurrentService()); |
| 909 | // |pending_service_| is updated immediately. |
| 910 | EXPECT_TRUE(GetPendingService() == NULL); |
| 911 | } |
| 912 | |
| 913 | TEST_F(WiFiMainTest, DisconnectCurrentService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 914 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 915 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 916 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 917 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 918 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 919 | *supplicant_interface_proxy_; |
| 920 | |
| 921 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 922 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 923 | WiFiService *service(GetServices().begin()->get()); |
| 924 | InitiateConnect(service); |
| 925 | ReportCurrentBSSChanged("bss0"); |
| 926 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 927 | |
| 928 | EXPECT_EQ(service, GetCurrentService()); |
| 929 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()); |
| 930 | InitiateDisconnect(service); |
| 931 | |
| 932 | // |current_service_| should not change until supplicant reports |
| 933 | // a BSS change. |
| 934 | EXPECT_EQ(service, GetCurrentService()); |
| 935 | } |
| 936 | |
| 937 | TEST_F(WiFiMainTest, DisconnectCurrentServiceWithPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 938 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 939 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 940 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 941 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 942 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 943 | *supplicant_interface_proxy_; |
| 944 | |
| 945 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 946 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 947 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 948 | WiFiService *service0(GetServices()[0].get()); |
| 949 | WiFiService *service1(GetServices()[1].get()); |
| 950 | |
| 951 | InitiateConnect(service0); |
| 952 | ReportCurrentBSSChanged("bss0"); |
| 953 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 954 | InitiateConnect(service1); |
| 955 | |
| 956 | EXPECT_EQ(service0, GetCurrentService()); |
| 957 | EXPECT_EQ(service1, GetPendingService()); |
| 958 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 959 | .Times(0); |
| 960 | InitiateDisconnect(service0); |
| 961 | |
| 962 | EXPECT_EQ(service0, GetCurrentService()); |
| 963 | EXPECT_EQ(service1, GetPendingService()); |
| 964 | } |
| 965 | |
| 966 | TEST_F(WiFiMainTest, DisconnectInvalidService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 967 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 968 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 969 | *supplicant_interface_proxy_; |
| 970 | |
| 971 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 972 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 973 | WiFiService *service(GetServices().begin()->get()); |
| 974 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 975 | .Times(0); |
| 976 | InitiateDisconnect(service); |
| 977 | } |
| 978 | |
| 979 | TEST_F(WiFiMainTest, DisconnectCurrentServiceFailure) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 980 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 981 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 982 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 983 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 984 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 985 | *supplicant_interface_proxy_; |
| 986 | |
| 987 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 988 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 989 | |
| 990 | WiFiService *service(GetServices().begin()->get()); |
| 991 | DBus::Path fake_path("/fake/path"); |
| 992 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(_)) |
| 993 | .WillOnce(Return(fake_path)); |
| 994 | InitiateConnect(service); |
| 995 | ReportCurrentBSSChanged("bss0"); |
| 996 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 997 | |
| 998 | EXPECT_EQ(service, GetCurrentService()); |
| 999 | EXPECT_CALL(supplicant_interface_proxy, Disconnect()) |
| 1000 | .WillRepeatedly(Throw( |
| 1001 | DBus::Error( |
| 1002 | "fi.w1.wpa_supplicant1.NotConnected", |
| 1003 | "test threw fi.w1.wpa_supplicant1.NotConnected"))); |
| 1004 | EXPECT_CALL(supplicant_interface_proxy, RemoveNetwork(fake_path)); |
| 1005 | InitiateDisconnect(service); |
| 1006 | |
| 1007 | EXPECT_TRUE(GetCurrentService() == NULL); |
| 1008 | } |
| 1009 | |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1010 | TEST_F(WiFiMainTest, Stop) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1011 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1012 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1013 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1014 | ReportScanDone(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1015 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1016 | EXPECT_CALL(*manager(), DeregisterService(_)); |
| 1017 | StopWiFi(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1020 | TEST_F(WiFiMainTest, GetWifiServiceOpen) { |
| 1021 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1022 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1023 | EXPECT_TRUE(e.IsSuccess()); |
| 1024 | } |
| 1025 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1026 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoSSID) { |
| 1027 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1028 | GetOpenService(flimflam::kTypeWifi, NULL, flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1029 | EXPECT_EQ(Error::kInvalidArguments, e.type()); |
| 1030 | EXPECT_EQ("must specify SSID", e.message()); |
| 1031 | } |
| 1032 | |
| 1033 | TEST_F(WiFiMainTest, GetWifiServiceOpenLongSSID) { |
| 1034 | Error e; |
| 1035 | GetOpenService( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1036 | flimflam::kTypeWifi, "123456789012345678901234567890123", |
| 1037 | flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1038 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1039 | EXPECT_EQ("SSID is too long", e.message()); |
| 1040 | } |
| 1041 | |
| 1042 | TEST_F(WiFiMainTest, GetWifiServiceOpenShortSSID) { |
| 1043 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1044 | GetOpenService(flimflam::kTypeWifi, "", flimflam::kModeManaged, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1045 | EXPECT_EQ(Error::kInvalidNetworkName, e.type()); |
| 1046 | EXPECT_EQ("SSID is too short", e.message()); |
| 1047 | } |
| 1048 | |
| 1049 | TEST_F(WiFiMainTest, GetWifiServiceOpenBadMode) { |
| 1050 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1051 | GetOpenService(flimflam::kTypeWifi, "an_ssid", "ad-hoc", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1052 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1053 | EXPECT_EQ("service mode is unsupported", e.message()); |
| 1054 | } |
| 1055 | |
| 1056 | TEST_F(WiFiMainTest, GetWifiServiceOpenNoMode) { |
| 1057 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1058 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1059 | EXPECT_TRUE(e.IsSuccess()); |
| 1060 | } |
| 1061 | |
| 1062 | TEST_F(WiFiMainTest, GetWifiServiceRSN) { |
| 1063 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1064 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1065 | flimflam::kSecurityRsn, "secure password", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1066 | EXPECT_TRUE(e.IsSuccess()); |
| 1067 | } |
| 1068 | |
| 1069 | TEST_F(WiFiMainTest, GetWifiServiceRSNNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1070 | // When configuring hidden networks, Chrome expects to be able to |
| 1071 | // GetService w/o a password, and supply the password with |
| 1072 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1073 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1074 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1075 | flimflam::kSecurityRsn, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1076 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | TEST_F(WiFiMainTest, GetWifiServiceBadSecurity) { |
| 1080 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1081 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, "rot-13", |
| 1082 | NULL, &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1083 | EXPECT_EQ(Error::kNotSupported, e.type()); |
| 1084 | EXPECT_EQ("security mode is unsupported", e.message()); |
| 1085 | } |
| 1086 | |
| 1087 | TEST_F(WiFiMainTest, GetWifiServiceWEPNoPassword) { |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1088 | // When configuring hidden networks, Chrome expects to be able to |
| 1089 | // GetService w/o a password, and supply the password with |
| 1090 | // SetProperty afterwards. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1091 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1092 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1093 | flimflam::kSecurityWep, NULL, &e); |
mukesh agrawal | b172e4a | 2012-04-25 18:15:30 -0700 | [diff] [blame] | 1094 | EXPECT_TRUE(e.IsSuccess()); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | TEST_F(WiFiMainTest, GetWifiServiceWEPEmptyPassword) { |
| 1098 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1099 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1100 | flimflam::kSecurityWep, "", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1101 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1102 | } |
| 1103 | |
| 1104 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCII) { |
| 1105 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1106 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1107 | flimflam::kSecurityWep, "abcde", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1108 | EXPECT_TRUE(e.IsSuccess()); |
| 1109 | } |
| 1110 | |
| 1111 | TEST_F(WiFiMainTest, GetWifiServiceWEP104ASCII) { |
| 1112 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1113 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1114 | flimflam::kSecurityWep, "abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1115 | EXPECT_TRUE(e.IsSuccess()); |
| 1116 | } |
| 1117 | |
| 1118 | TEST_F(WiFiMainTest, GetWifiServiceWEP40ASCIIWithKeyIndex) { |
| 1119 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1120 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1121 | flimflam::kSecurityWep, "0:abcdefghijklm", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1122 | EXPECT_TRUE(e.IsSuccess()); |
| 1123 | } |
| 1124 | |
| 1125 | TEST_F(WiFiMainTest, GetWifiServiceWEP40Hex) { |
| 1126 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1127 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1128 | flimflam::kSecurityWep, "0102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1129 | EXPECT_TRUE(e.IsSuccess()); |
| 1130 | } |
| 1131 | |
| 1132 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexBadPassphrase) { |
| 1133 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1134 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1135 | flimflam::kSecurityWep, "O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1136 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1137 | } |
| 1138 | |
| 1139 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexBadPassphrase) { |
| 1140 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1141 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1142 | flimflam::kSecurityWep, "1:O102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1143 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1144 | } |
| 1145 | |
| 1146 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithKeyIndexAndBaseBadPassphrase) { |
| 1147 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1148 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1149 | flimflam::kSecurityWep, "1:0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1150 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1151 | } |
| 1152 | |
| 1153 | TEST_F(WiFiMainTest, GetWifiServiceWEP40HexWithBaseBadPassphrase) { |
| 1154 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1155 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1156 | flimflam::kSecurityWep, "0xO102030405", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1157 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1158 | } |
| 1159 | |
| 1160 | TEST_F(WiFiMainTest, GetWifiServiceWEP104Hex) { |
| 1161 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1162 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1163 | flimflam::kSecurityWep, "0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1164 | EXPECT_TRUE(e.IsSuccess()); |
| 1165 | } |
| 1166 | |
| 1167 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexUppercase) { |
| 1168 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1169 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1170 | flimflam::kSecurityWep, "0102030405060708090A0B0C0D", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1171 | EXPECT_TRUE(e.IsSuccess()); |
| 1172 | } |
| 1173 | |
| 1174 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndex) { |
| 1175 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1176 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1177 | flimflam::kSecurityWep, "0:0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1178 | EXPECT_TRUE(e.IsSuccess()); |
| 1179 | } |
| 1180 | |
| 1181 | TEST_F(WiFiMainTest, GetWifiServiceWEP104HexWithKeyIndexAndBase) { |
| 1182 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1183 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1184 | flimflam::kSecurityWep, "0:0x0102030405060708090a0b0c0d", &e); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1185 | EXPECT_TRUE(e.IsSuccess()); |
| 1186 | } |
| 1187 | |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1188 | class WiFiGetServiceSuccessTest : public WiFiMainTest {}; |
| 1189 | class WiFiGetServiceFailureTest : public WiFiMainTest {}; |
| 1190 | |
| 1191 | TEST_P(WiFiGetServiceSuccessTest, Passphrase) { |
| 1192 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1193 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1194 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1195 | EXPECT_TRUE(e.IsSuccess()); |
| 1196 | } |
| 1197 | |
| 1198 | TEST_P(WiFiGetServiceFailureTest, Passphrase) { |
| 1199 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1200 | GetService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, |
| 1201 | flimflam::kSecurityWpa, GetParam().c_str(), &e); |
mukesh agrawal | 8ede052 | 2011-10-03 14:57:44 -0700 | [diff] [blame] | 1202 | EXPECT_EQ(Error::kInvalidPassphrase, e.type()); |
| 1203 | } |
| 1204 | |
| 1205 | INSTANTIATE_TEST_CASE_P( |
| 1206 | WiFiGetServiceSuccessTestInstance, |
| 1207 | WiFiGetServiceSuccessTest, |
| 1208 | Values( |
| 1209 | string(IEEE_80211::kWPAAsciiMinLen, 'Z'), |
| 1210 | string(IEEE_80211::kWPAAsciiMaxLen, 'Z'), |
| 1211 | // subtle: invalid length for hex key, but valid as ascii passphrase |
| 1212 | string(IEEE_80211::kWPAHexLen-1, '1'), |
| 1213 | string(IEEE_80211::kWPAHexLen, '1'))); |
| 1214 | |
| 1215 | INSTANTIATE_TEST_CASE_P( |
| 1216 | WiFiGetServiceFailureTestInstance, |
| 1217 | WiFiGetServiceFailureTest, |
| 1218 | Values( |
| 1219 | string(IEEE_80211::kWPAAsciiMinLen-1, 'Z'), |
| 1220 | string(IEEE_80211::kWPAAsciiMaxLen+1, 'Z'), |
| 1221 | string(IEEE_80211::kWPAHexLen+1, '1'))); |
| 1222 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1223 | TEST_F(WiFiMainTest, FindServiceWEP) { |
| 1224 | const string ssid("an_ssid"); |
| 1225 | { |
| 1226 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1227 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1228 | flimflam::kSecurityWep, "abcde", &e); |
| 1229 | EXPECT_TRUE(e.IsSuccess()); |
| 1230 | } |
| 1231 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1232 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1233 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1234 | flimflam::kSecurityWep).get()); |
| 1235 | EXPECT_FALSE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1236 | flimflam::kSecurityWpa).get()); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | TEST_F(WiFiMainTest, FindServiceWPA) { |
| 1240 | const string ssid("an_ssid"); |
| 1241 | { |
| 1242 | Error e; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1243 | GetService(flimflam::kTypeWifi, ssid.c_str(), flimflam::kModeManaged, |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1244 | flimflam::kSecurityRsn, "abcdefgh", &e); |
| 1245 | EXPECT_TRUE(e.IsSuccess()); |
| 1246 | } |
| 1247 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1248 | WiFiServiceRefPtr wpa_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1249 | flimflam::kSecurityWpa)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1250 | EXPECT_TRUE(wpa_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1251 | WiFiServiceRefPtr rsn_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1252 | flimflam::kSecurityRsn)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1253 | EXPECT_TRUE(rsn_service.get()); |
| 1254 | EXPECT_EQ(wpa_service.get(), rsn_service.get()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1255 | WiFiServiceRefPtr psk_service(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1256 | flimflam::kSecurityPsk)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1257 | EXPECT_EQ(wpa_service.get(), psk_service.get()); |
| 1258 | // Indirectly test FindService by doing a GetService on something that |
| 1259 | // already exists. |
| 1260 | { |
| 1261 | Error e; |
| 1262 | WiFiServiceRefPtr wpa_service2( |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1263 | GetServiceInner(flimflam::kTypeWifi, ssid.c_str(), |
| 1264 | flimflam::kModeManaged, flimflam::kSecurityWpa, |
| 1265 | "abcdefgh", false, &e)); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1266 | EXPECT_TRUE(e.IsSuccess()); |
| 1267 | EXPECT_EQ(wpa_service.get(), wpa_service2.get()); |
| 1268 | } |
| 1269 | } |
| 1270 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1271 | TEST_F(WiFiMainTest, GetServiceWithGUID) { |
| 1272 | // Perform a GetService that also configures properties in the base Service |
| 1273 | // class using Service::Configure(). |
| 1274 | KeyValueStore args; |
| 1275 | args.SetString(flimflam::kTypeProperty, flimflam::kTypeWifi); |
| 1276 | args.SetString(flimflam::kSSIDProperty, "ssid"); |
| 1277 | args.SetString(flimflam::kSecurityProperty, flimflam::kSecurityNone); |
| 1278 | const string kGUID = "aguid"; // Stored as a registered Service property. |
| 1279 | args.SetString(flimflam::kGuidProperty, kGUID); |
| 1280 | Error e; |
| 1281 | WiFiServiceRefPtr service = GetServiceWithKeyValues(args, &e); |
| 1282 | EXPECT_TRUE(e.IsSuccess()); |
| 1283 | EXPECT_EQ(kGUID, service->guid()); |
| 1284 | } |
| 1285 | |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1286 | MATCHER_P(HasHiddenSSID, ssid, "") { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1287 | map<string, DBus::Variant>::const_iterator it = |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1288 | arg.find(wpa_supplicant::kPropertyScanSSIDs); |
| 1289 | if (it == arg.end()) { |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | const DBus::Variant &ssids_variant = it->second; |
| 1294 | EXPECT_TRUE(DBusAdaptor::IsByteArrays(ssids_variant.signature())); |
| 1295 | const ByteArrays &ssids = it->second.operator ByteArrays(); |
| 1296 | // A valid Scan containing a single hidden SSID should contain |
| 1297 | // two SSID entries: one containing the SSID we are looking for, |
| 1298 | // and an empty entry, signifying that we also want to do a |
| 1299 | // broadcast probe request for all non-hidden APs as well. |
| 1300 | return ssids.size() == 2 && |
| 1301 | string(ssids[0].begin(), ssids[0].end()) == ssid && |
| 1302 | ssids[1].empty(); |
| 1303 | } |
| 1304 | |
| 1305 | TEST_F(WiFiMainTest, ScanHidden) { |
| 1306 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_)); |
| 1307 | EXPECT_CALL(*supplicant_process_proxy_, GetInterface(_)) |
| 1308 | .Times(AnyNumber()) |
| 1309 | .WillRepeatedly(Throw( |
| 1310 | DBus::Error( |
| 1311 | "fi.w1.wpa_supplicant1.InterfaceUnknown", |
| 1312 | "test threw fi.w1.wpa_supplicant1.InterfaceUnknown"))); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1313 | scoped_refptr<MockProfile> profile( |
| 1314 | new NiceMock<MockProfile>(control_interface(), manager(), "")); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1315 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1316 | // Create a hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1317 | Error e; |
| 1318 | WiFiServiceRefPtr service = |
| 1319 | GetServiceInner(flimflam::kTypeWifi, "ssid0", flimflam::kModeManaged, |
| 1320 | NULL, NULL, true, &e); |
| 1321 | EXPECT_TRUE(e.IsSuccess()); |
| 1322 | EXPECT_TRUE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1323 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1324 | } |
| 1325 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1326 | // Create a hidden service without an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1327 | Error e; |
| 1328 | WiFiServiceRefPtr service = |
| 1329 | GetServiceInner(flimflam::kTypeWifi, "ssid1", flimflam::kModeManaged, |
| 1330 | NULL, NULL, true, &e); |
| 1331 | EXPECT_TRUE(e.IsSuccess()); |
| 1332 | EXPECT_TRUE(service->hidden_ssid()); |
| 1333 | } |
| 1334 | { |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1335 | // Create a non-hidden service with an associated profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1336 | Error e; |
| 1337 | WiFiServiceRefPtr service = |
| 1338 | GetServiceInner(flimflam::kTypeWifi, "ssid2", flimflam::kModeManaged, |
| 1339 | NULL, NULL, false, &e); |
| 1340 | EXPECT_TRUE(e.IsSuccess()); |
| 1341 | EXPECT_FALSE(service->hidden_ssid()); |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1342 | service->set_profile(profile); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1343 | } |
| 1344 | EXPECT_CALL(*supplicant_interface_proxy_, Scan(HasHiddenSSID("ssid0"))); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1345 | StartWiFi(); |
| 1346 | dispatcher_.DispatchPendingEvents(); |
| 1347 | } |
| 1348 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1349 | TEST_F(WiFiMainTest, InitialSupplicantState) { |
| 1350 | EXPECT_EQ(WiFi::kInterfaceStateUnknown, GetSupplicantState()); |
| 1351 | } |
| 1352 | |
| 1353 | TEST_F(WiFiMainTest, StateChangeNoService) { |
| 1354 | // State change should succeed even if there is no pending Service. |
| 1355 | ReportStateChanged(wpa_supplicant::kInterfaceStateScanning); |
| 1356 | EXPECT_EQ(wpa_supplicant::kInterfaceStateScanning, GetSupplicantState()); |
| 1357 | } |
| 1358 | |
| 1359 | TEST_F(WiFiMainTest, StateChangeWithService) { |
| 1360 | // Forward transition should trigger a Service state change. |
| 1361 | StartWiFi(); |
| 1362 | dispatcher_.DispatchPendingEvents(); |
| 1363 | MockWiFiServiceRefPtr service = MakeMockService(); |
| 1364 | InitiateConnect(service); |
| 1365 | EXPECT_CALL(*service.get(), SetState(Service::kStateAssociating)); |
| 1366 | ReportStateChanged(wpa_supplicant::kInterfaceStateAssociated); |
| 1367 | // Verify expectations now, because WiFi may report other state changes |
| 1368 | // when WiFi is Stop()-ed (during TearDown()). |
| 1369 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1370 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | TEST_F(WiFiMainTest, StateChangeBackwardsWithService) { |
| 1374 | // Some backwards transitions should not trigger a Service state change. |
| 1375 | // Supplicant state should still be updated, however. |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1376 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1377 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1378 | StartWiFi(); |
| 1379 | dispatcher_.DispatchPendingEvents(); |
| 1380 | MockWiFiServiceRefPtr service = MakeMockService(); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1381 | EXPECT_CALL(*service.get(), SetState(Service::kStateConfiguring)); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1382 | InitiateConnect(service); |
| 1383 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1384 | ReportStateChanged(wpa_supplicant::kInterfaceStateAuthenticating); |
| 1385 | EXPECT_EQ(wpa_supplicant::kInterfaceStateAuthenticating, |
| 1386 | GetSupplicantState()); |
| 1387 | // Verify expectations now, because WiFi may report other state changes |
| 1388 | // when WiFi is Stop()-ed (during TearDown()). |
| 1389 | Mock::VerifyAndClearExpectations(service.get()); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1390 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1393 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithNoGroups) { |
| 1394 | StrictMock<MockStore> storage; |
| 1395 | EXPECT_CALL(storage, GetGroupsWithKey(flimflam::kWifiHiddenSsid)) |
| 1396 | .WillOnce(Return(set<string>())); |
| 1397 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1398 | } |
| 1399 | |
| 1400 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingHidden) { |
| 1401 | string id; |
| 1402 | StrictMock<MockStore> storage; |
| 1403 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1404 | // Missing "Hidden" property. |
| 1405 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1406 | .WillOnce(Return(false)); |
| 1407 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1408 | } |
| 1409 | |
| 1410 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFalseHidden) { |
| 1411 | string id; |
| 1412 | StrictMock<MockStore> storage; |
| 1413 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1414 | // "Hidden" property set to "false". |
| 1415 | EXPECT_CALL(storage, GetBool(StrEq(id), flimflam::kWifiHiddenSsid, _)) |
| 1416 | .WillOnce(DoAll(SetArgumentPointee<2>(true), Return(false))); |
| 1417 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1418 | } |
| 1419 | |
| 1420 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithMissingSSID) { |
| 1421 | string id; |
| 1422 | StrictMock<MockStore> storage; |
| 1423 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1424 | // Missing "SSID" property. |
| 1425 | EXPECT_CALL(storage, GetString(StrEq(id), flimflam::kSSIDProperty, _)) |
| 1426 | .WillOnce(Return(false)); |
| 1427 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | TEST_F(WiFiMainTest, LoadHiddenServicesFailWithFoundService) { |
| 1432 | StrictMock<MockStore> storage; |
| 1433 | string id; |
| 1434 | SetupHiddenStorage(&storage, "an_ssid", &id); |
| 1435 | Error e; |
| 1436 | GetOpenService(flimflam::kTypeWifi, "an_ssid", NULL, &e); |
| 1437 | ASSERT_TRUE(e.IsSuccess()); |
| 1438 | EXPECT_FALSE(LoadHiddenServices(&storage)); |
| 1439 | } |
| 1440 | |
| 1441 | TEST_F(WiFiMainTest, LoadHiddenServicesSuccess) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1442 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1443 | StrictMock<MockStore> storage; |
| 1444 | string ssid("an_ssid"); |
| 1445 | string id; |
| 1446 | SetupHiddenStorage(&storage, ssid, &id); |
| 1447 | EXPECT_TRUE(LoadHiddenServices(&storage)); |
| 1448 | vector<uint8_t> ssid_bytes(ssid.begin(), ssid.end()); |
| 1449 | EXPECT_TRUE(FindService(ssid_bytes, flimflam::kModeManaged, |
| 1450 | flimflam::kSecurityNone).get()); |
| 1451 | } |
| 1452 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1453 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToDisconnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1454 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1455 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1456 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1457 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1458 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1459 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1460 | |
| 1461 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1462 | // intended to reflect the format used by supplicant. It's just |
| 1463 | // convenient for testing. |
| 1464 | |
| 1465 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1466 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1467 | kNetworkModeInfrastructure); |
| 1468 | InitiateConnect(service); |
| 1469 | EXPECT_EQ(service, GetPendingService().get()); |
| 1470 | |
| 1471 | ReportCurrentBSSChanged("an_ap"); |
| 1472 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1473 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1474 | EXPECT_EQ(service, GetCurrentService().get()); |
| 1475 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1476 | |
| 1477 | ReportCurrentBSSChanged(wpa_supplicant::kCurrentBSSNull); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 1478 | EXPECT_EQ(Service::kStateIdle, service->state()); |
| 1479 | EXPECT_TRUE(service->IsFailed()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1480 | EXPECT_EQ(NULL, GetCurrentService().get()); |
| 1481 | EXPECT_EQ(NULL, GetPendingService().get()); |
| 1482 | } |
| 1483 | |
| 1484 | TEST_F(WiFiMainTest, CurrentBSSChangeConnectedToConnectedNewService) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1485 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1486 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1487 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
| 1488 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1489 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1490 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1491 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1492 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1493 | |
| 1494 | // Note that the BSS handles used in this test ("ap1", "ap2") are |
| 1495 | // not intended to reflect the format used by supplicant. They're |
| 1496 | // just convenient for testing. |
| 1497 | |
| 1498 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1499 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1500 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1501 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1502 | kNetworkModeInfrastructure); |
| 1503 | InitiateConnect(service1); |
| 1504 | ReportCurrentBSSChanged("ap1"); |
| 1505 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1506 | EXPECT_EQ(service1.get(), GetCurrentService().get()); |
| 1507 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1508 | // Note that we deliberately omit intermediate supplicant states |
| 1509 | // (e.g. kInterfaceStateAssociating), on the theory that they are |
| 1510 | // unreliable. Specifically, they may be quashed if the association |
| 1511 | // completes before supplicant flushes its changed properties. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1512 | ReportCurrentBSSChanged("ap2"); |
| 1513 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1514 | EXPECT_EQ(service2.get(), GetCurrentService().get()); |
| 1515 | EXPECT_EQ(Service::kStateIdle, service1->state()); |
| 1516 | EXPECT_EQ(Service::kStateConfiguring, service2->state()); |
| 1517 | } |
| 1518 | |
| 1519 | TEST_F(WiFiMainTest, CurrentBSSChangeDisconnectedToConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1520 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1521 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1522 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1523 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(AnyNumber()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1524 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1525 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1526 | |
| 1527 | // Note that the BSS handle used in this test ("an_ap") is not |
| 1528 | // intended to reflect the format used by supplicant. It's just |
| 1529 | // convenient for testing. |
| 1530 | |
| 1531 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1532 | ReportBSS("an_ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1533 | kNetworkModeInfrastructure); |
| 1534 | InitiateConnect(service); |
| 1535 | ReportCurrentBSSChanged("an_ap"); |
| 1536 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1537 | EXPECT_EQ(service.get(), GetCurrentService().get()); |
| 1538 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1539 | } |
| 1540 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1541 | TEST_F(WiFiMainTest, CurrentBSSChangedUpdateServiceEndpoint) { |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 1542 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1543 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1544 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1545 | |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1546 | const uint16 frequency1 = 2412; |
| 1547 | const uint16 frequency2 = 2442; |
| 1548 | StartWiFi(); |
| 1549 | ReportBSS("bss1", "ssid1", "00:00:00:00:00:01", 1, frequency1, |
| 1550 | kNetworkModeInfrastructure); |
| 1551 | ReportBSS("bss2", "ssid1", "00:00:00:00:00:02", 1, frequency2, |
| 1552 | kNetworkModeInfrastructure); |
| 1553 | EXPECT_EQ(1, GetServices().size()); |
| 1554 | WiFiService *service(GetServices()[0].get()); |
| 1555 | InitiateConnect(service); |
| 1556 | ReportCurrentBSSChanged("bss1"); |
| 1557 | EXPECT_EQ(frequency1, service->frequency_); |
| 1558 | ReportCurrentBSSChanged("bss2"); |
| 1559 | EXPECT_EQ(frequency2, service->frequency_); |
| 1560 | } |
| 1561 | |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1562 | TEST_F(WiFiMainTest, ConfiguredServiceRegistration) { |
| 1563 | Error e; |
| 1564 | EXPECT_CALL(*manager(), RegisterService(_)) |
| 1565 | .Times(0); |
| 1566 | EXPECT_CALL(*manager(), HasService(_)) |
| 1567 | .WillOnce(Return(false)); |
| 1568 | GetOpenService(flimflam::kTypeWifi, "an_ssid", flimflam::kModeManaged, &e); |
| 1569 | EXPECT_CALL(*manager(), RegisterService(_)); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1570 | ReportBSS("ap0", "an_ssid", "00:00:00:00:00:00", 0, 0, |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 1571 | kNetworkModeInfrastructure); |
| 1572 | } |
| 1573 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1574 | TEST_F(WiFiMainTest, NewConnectPreemptsPending) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1575 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
| 1576 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1577 | WiFiEndpointRefPtr ap1 = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1578 | WiFiEndpointRefPtr ap2 = MakeEndpoint("another_ssid", "01:02:03:04:05:06"); |
| 1579 | WiFiServiceRefPtr service1 = CreateServiceForEndpoint(*ap1); |
| 1580 | WiFiServiceRefPtr service2 = CreateServiceForEndpoint(*ap2); |
| 1581 | |
| 1582 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1583 | ReportBSS("ap1", ap1->ssid_string(), ap1->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1584 | kNetworkModeInfrastructure); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1585 | ReportBSS("ap2", ap2->ssid_string(), ap2->bssid_string(), 0, 0, |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1586 | kNetworkModeInfrastructure); |
| 1587 | InitiateConnect(service1); |
| 1588 | EXPECT_EQ(service1.get(), GetPendingService().get()); |
| 1589 | |
| 1590 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), Disconnect()); |
| 1591 | EXPECT_CALL(*GetSupplicantInterfaceProxy(), AddNetwork(_)); |
| 1592 | InitiateConnect(service2); |
| 1593 | EXPECT_EQ(service2.get(), GetPendingService().get()); |
| 1594 | } |
| 1595 | |
| 1596 | TEST_F(WiFiMainTest, IsIdle) { |
| 1597 | StartWiFi(); |
| 1598 | EXPECT_TRUE(wifi()->IsIdle()); |
| 1599 | |
| 1600 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1601 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1602 | Error error; |
| 1603 | service->AddEndpoint(ap); |
| 1604 | service->AutoConnect(); |
| 1605 | EXPECT_FALSE(wifi()->IsIdle()); |
| 1606 | } |
| 1607 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1608 | MATCHER(WiFiAddedArgs, "") { |
| 1609 | return ContainsKey(arg, wpa_supplicant::kNetworkPropertyScanSSID) && |
| 1610 | ContainsKey(arg, wpa_supplicant::kNetworkPropertyBgscan); |
| 1611 | } |
| 1612 | |
| 1613 | TEST_F(WiFiMainTest, AddNetworkArgs) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1614 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1615 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1616 | *supplicant_interface_proxy_; |
| 1617 | |
| 1618 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1619 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1620 | WiFiService *service(GetServices().begin()->get()); |
| 1621 | EXPECT_CALL(supplicant_interface_proxy, AddNetwork(WiFiAddedArgs())); |
| 1622 | InitiateConnect(service); |
| 1623 | } |
| 1624 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1625 | TEST_F(WiFiMainTest, StateAndIPIgnoreLinkEvent) { |
| 1626 | StartWiFi(); |
| 1627 | MockWiFiServiceRefPtr service = MakeMockService(); |
| 1628 | InitiateConnect(service); |
| 1629 | EXPECT_CALL(*service.get(), SetState(_)).Times(0); |
| 1630 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
| 1631 | ReportLinkUp(); |
| 1632 | |
| 1633 | // Verify expectations now, because WiFi may cause |service| state |
| 1634 | // changes during TearDown(). |
| 1635 | Mock::VerifyAndClearExpectations(service); |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1636 | EXPECT_CALL(*service.get(), SetState(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | TEST_F(WiFiMainTest, SupplicantCompleted) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1640 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1641 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1642 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1643 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1644 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1645 | |
| 1646 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1647 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1648 | kNetworkModeInfrastructure); |
| 1649 | InitiateConnect(service); |
| 1650 | |
| 1651 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 1652 | ReportCurrentBSSChanged("ap"); |
| 1653 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1654 | EXPECT_EQ(Service::kStateConfiguring, service->state()); |
| 1655 | } |
| 1656 | |
| 1657 | TEST_F(WiFiMainTest, SupplicantCompletedAlreadyConnected) { |
Gary Morain | d9f893f | 2012-02-06 10:03:40 -0800 | [diff] [blame] | 1658 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()); |
| 1659 | EXPECT_CALL(*manager(), UpdateService(_)).Times(AnyNumber()); |
| 1660 | EXPECT_CALL(*device_info(), FlushAddresses(_)).Times(AnyNumber()); |
| 1661 | EXPECT_CALL(*manager(), device_info()).Times(AnyNumber()); |
| 1662 | EXPECT_CALL(*dhcp_provider(), CreateConfig(_, _)).Times(AnyNumber()); |
| 1663 | EXPECT_CALL(*manager(), HasService(_)).Times(AnyNumber()); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 1664 | EXPECT_CALL(*manager(), IsPortalDetectionEnabled(_)).Times(AnyNumber()); |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1665 | WiFiEndpointRefPtr ap = MakeEndpoint("an_ssid", "00:01:02:03:04:05"); |
| 1666 | WiFiServiceRefPtr service = CreateServiceForEndpoint(*ap); |
| 1667 | |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1668 | StartWiFi(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1669 | ReportBSS("ap", ap->ssid_string(), ap->bssid_string(), 0, 0, |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1670 | kNetworkModeInfrastructure); |
| 1671 | InitiateConnect(service); |
| 1672 | ReportCurrentBSSChanged("ap"); |
| 1673 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1674 | ReportIPConfigComplete(); |
| 1675 | Mock::VerifyAndClearExpectations(service); |
| 1676 | |
| 1677 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
| 1678 | ReportStateChanged(wpa_supplicant::kInterfaceStateCompleted); |
| 1679 | } |
| 1680 | |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 1681 | TEST_F(WiFiMainTest, ClearCachedCredentials) { |
| 1682 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1683 | *supplicant_interface_proxy_; |
| 1684 | |
| 1685 | StartWiFi(); |
| 1686 | |
| 1687 | // Ensure call to the proxy is deferred. |
| 1688 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 1689 | .Times(0); |
| 1690 | ClearCachedCredentials(); |
| 1691 | |
| 1692 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 1693 | |
| 1694 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 1695 | .Times(1); |
| 1696 | dispatcher_.DispatchPendingEvents(); |
| 1697 | |
| 1698 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 1699 | |
| 1700 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 1701 | .Times(0); |
| 1702 | ClearCachedCredentials(); |
| 1703 | ClearCachedCredentials(); |
| 1704 | |
| 1705 | Mock::VerifyAndClearExpectations(&supplicant_interface_proxy); |
| 1706 | |
| 1707 | // Ensure multiple calls to ClearCachedCredentials() results in only |
| 1708 | // one call to the proxy. |
| 1709 | EXPECT_CALL(supplicant_interface_proxy, ClearCachedCredentials()) |
| 1710 | .Times(1); |
| 1711 | dispatcher_.DispatchPendingEvents(); |
| 1712 | } |
| 1713 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 1714 | TEST_F(WiFiMainTest, BSSAddedCreatesBSSProxy) { |
| 1715 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1716 | // TODO(quiche): Consider using a factory for WiFiEndpoints, so that |
| 1717 | // we can test the interaction between WiFi and WiFiEndpoint. (Right |
| 1718 | // now, we're testing across multiple layers.) |
| 1719 | EXPECT_CALL(*supplicant_bss_proxy_, Die()).Times(AnyNumber()); |
| 1720 | EXPECT_CALL(*proxy_factory(), CreateSupplicantBSSProxy(_, _, _)); |
| 1721 | StartWiFi(); |
| 1722 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1723 | } |
| 1724 | |
| 1725 | TEST_F(WiFiMainTest, BSSRemovedDestroysBSSProxy) { |
| 1726 | // TODO(quiche): As for BSSAddedCreatesBSSProxy, consider using a |
| 1727 | // factory for WiFiEndpoints. |
| 1728 | EXPECT_CALL(*manager(), RegisterService(_)).Times(AnyNumber()); |
| 1729 | |
| 1730 | // Get the pointer before we transfer ownership. |
| 1731 | MockSupplicantBSSProxy *proxy = supplicant_bss_proxy_.get(); |
| 1732 | EXPECT_CALL(*proxy, Die()); |
| 1733 | StartWiFi(); |
| 1734 | ReportBSS("bss0", "ssid0", "00:00:00:00:00:00", 0, 0, kNetworkModeAdHoc); |
| 1735 | RemoveBSS("bss0"); |
| 1736 | // Check this now, to make sure RemoveBSS killed the proxy (rather |
| 1737 | // than TearDown). |
| 1738 | Mock::VerifyAndClearExpectations(proxy); |
| 1739 | } |
| 1740 | |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 1741 | TEST_F(WiFiMainTest, FlushBSSOnResume) { |
| 1742 | const struct timeval resume_time = {1, 0}; |
| 1743 | const struct timeval scan_done_time = {6, 0}; |
| 1744 | MockSupplicantInterfaceProxy &supplicant_interface_proxy = |
| 1745 | *supplicant_interface_proxy_; |
| 1746 | |
| 1747 | StartWiFi(); |
| 1748 | |
| 1749 | EXPECT_CALL(time_, GetTimeMonotonic(_)) |
| 1750 | .WillOnce(DoAll(SetArgumentPointee<0>(resume_time), Return(0))) |
| 1751 | .WillOnce(DoAll(SetArgumentPointee<0>(scan_done_time), Return(0))); |
| 1752 | EXPECT_CALL(supplicant_interface_proxy, |
| 1753 | FlushBSS(WiFi::kMaxBSSResumeAgeSeconds + 5)); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 1754 | power_state_callback().Run(PowerManagerProxyDelegate::kOn); |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 1755 | ReportScanDone(); |
| 1756 | } |
| 1757 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 1758 | } // namespace shill |